📄 menucanvas.java
字号:
switch(id)
{
case ACTION_LOCAL_START:
Bluegammon.startLocalGame();
break;
case ACTION_LOCAL_RESUME:
Bluegammon.resumeSavedLocalGame();
break;
case ACTION_QUIT:
Bluegammon.shutdown();
break;
case ACTION_SCORE:
GameRecordPageItem grItem = (GameRecordPageItem)item;
String str =
new String(grItem.getOpponentNameChars()) + "\n\n" +
Resources.getString(Resources.TXT_SCORE_PLAYER) + ": " +
new String(grItem.getPlayerScoreChars()) + "\n" +
Resources.getString(Resources.TXT_SCORE_OPPONENT) + ": " +
new String(grItem.getOpponentScoreChars()) + "\n" +
Resources.getString(Resources.TXT_SCORE_GAMES) + ": " +
new String(grItem.getGamesChars()) + "\n" +
Resources.getString(Resources.TXT_SCORE_DATE) + ": " +
new String(grItem.getLastDateChars()) + "\n\n";
char[] text = str.toCharArray();
Bluegammon.showPopup(text, Popup.ALT_OK, 0, 0, 0, null);
break;
case ACTION_AUDIO:
if (RmsFacade.getBoolean(Bluegammon.AUDIO_OFF))
{
Audio.stopSound(Audio.MUSIC);
}
else
{
Audio.playSound(Audio.MUSIC);
}
break;
case ACTION_VIBRA:
if (!RmsFacade.getBoolean(Bluegammon.VIBRA_OFF))
{
Device.vibrate(100,100,3);
}
break;
case ACTION_ABOUT:
Bluegammon.showPopup(Resources.getChars(Resources.TXT_ABOUT), Popup.ALT_OK, 0, 0, 0, null);
break;
}
}
// Menulistener implementation
// See interface javadoc
public void newPage(MenuPage fromPage, MenuPage toPage, boolean back)
{
m_softButtons.enable(CMD_BACK, toPage != m_menu.getStartPage());
if (fromPage instanceof FocusablePage)
{
((FocusablePage)fromPage).onLeave();
}
if (toPage instanceof FocusablePage)
{
((FocusablePage)toPage).onEnter();
}
}
// See interface javadoc
public void itemSelected(MenuPage page, PageItem oldItem, PageItem newItem)
{
if (newItem != null)
{
Object helpTxt = newItem.getProperty(ITEM_HELP);
m_softButtons.enable(CMD_HELP, helpTxt != null);
}
}
// See interface javadoc
public void actionCalled(MenuPage page, PageItem item, ItemAction action) {}
// See interface javadoc
public void transitionStarted(MenuPage fromPage, MenuPage toPage, long delay,
int frames, boolean back) {}
// See interface javadoc
public void transitionStopped(MenuPage fromPage, MenuPage toPage) {}
/**
* Binary page item turning boolean flags in rms on and off.
* @author Peter Andersson
*/
class PersistenceFlagItem extends BinaryPageItem
{
protected int m_key;
public PersistenceFlagItem(int key, char[] label,
Image imageTrue, Image imageFalse, int id)
{
super(label, imageTrue, imageFalse, null, MenuCanvas.this, id);
m_key = key;
}
public boolean getBoolean()
{
return RmsFacade.getBoolean(m_key);
}
public void setBoolean(boolean value)
{
RmsFacade.setBoolean(m_key, value);
}
} // end of PersistenceFlagItem
/**
* Binary page item turning boolean rule-flags on and off.
* @author Peter Andersson
*/
class RuleFlagItem extends BinaryPageItem
{
protected int m_rule;
public RuleFlagItem(int rule, char[] label,
Image imageTrue, Image imageFalse, int id)
{
super(label, imageTrue, imageFalse, null, MenuCanvas.this, id);
m_rule = rule;
}
public boolean getBoolean()
{
return Rules.isSet(m_rule);
}
public void setBoolean(boolean value)
{
Rules.set(m_rule, value);
RmsFacade.setInt(Bluegammon.RULES_PREFERRED, Rules.getRuleFlags());
}
} // end of RuleFlagItem
/**
* Game record page item showing score status.
* @author Peter Andersson
*/
class GameRecordPageItem extends PageItem
{
protected GameRecord m_record = null;
protected char[] m_opponentNameChars;
protected char[] m_playerScoreChars;
protected char[] m_opponentScoreChars;
protected char[] m_gamesChars;
protected char[] m_lastDateChars;
public GameRecordPageItem(GameRecord rec)
{
super(null, null, MenuCanvas.this, null, ACTION_SCORE);
m_record = rec;
m_opponentNameChars = rec.getOpponentName();
m_playerScoreChars = Integer.toString(rec.getPlayerScore()).toCharArray();
m_opponentScoreChars = Integer.toString(rec.getOpponentScore()).toCharArray();
m_gamesChars = Integer.toString(rec.getGameCount()).toCharArray();
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(rec.getTimestamp()));
String lastGameDate = cal.get(Calendar.DAY_OF_MONTH) + " ";
int month = cal.get(Calendar.MONTH);
switch(month)
{
case Calendar.JANUARY:
lastGameDate += "Jan";
break;
case Calendar.FEBRUARY:
lastGameDate += "Feb";
break;
case Calendar.MARCH:
lastGameDate += "Mar";
break;
case Calendar.APRIL:
lastGameDate += "Apr";
break;
case Calendar.MAY:
lastGameDate += "May";
break;
case Calendar.JUNE:
lastGameDate += "Jun";
break;
case Calendar.JULY:
lastGameDate += "Jul";
break;
case Calendar.AUGUST:
lastGameDate += "Aug";
break;
case Calendar.SEPTEMBER:
lastGameDate += "Sep";
break;
case Calendar.OCTOBER:
lastGameDate += "Oct";
break;
case Calendar.NOVEMBER:
lastGameDate += "Nov";
break;
case Calendar.DECEMBER:
lastGameDate += "Dec";
break;
}
//lastGameDate += " " + cal.get(Calendar.YEAR);
int hour = cal.get(Calendar.HOUR_OF_DAY);
lastGameDate += (hour < 10 ? " 0" : " ") + hour;
int minute = cal.get(Calendar.MINUTE);
lastGameDate += (minute < 10 ? ":0" : ":") + minute;
m_lastDateChars = lastGameDate.toCharArray();
setLayout(LAYOUT_ALIGN_LEFT);
}
public char[] getGamesChars()
{
return m_gamesChars;
}
public char[] getLastDateChars()
{
return m_lastDateChars;
}
public char[] getOpponentNameChars()
{
return m_opponentNameChars;
}
public char[] getOpponentScoreChars()
{
return m_opponentScoreChars;
}
public char[] getPlayerScoreChars()
{
return m_playerScoreChars;
}
public GameRecord getRecord()
{
return m_record;
}
} // end of GameRecordPageItem
/**
* Special painter that also paints <code>GameRecordPageItem</code>s and
* adds special effects for selected items.
* @author Peter Andersson
*/
static class BackgammonMenuPainter extends DefaultMenuPainter
{
protected static final char[] SCORE_TXT = "9999".toCharArray();
protected int m_scoreWidth;
protected int[] m_rgbData;
protected int m_canvasWidth;
public BackgammonMenuPainter(int canvasWidth)
{
// Create selected item rgb buffer
m_canvasWidth = canvasWidth;
m_rgbData = new int[m_canvasWidth * 4];
int bgcol = 0x880000;
for (int i = 0; i < m_canvasWidth; i++)
{
double alpha = (double)Math.abs(i - m_canvasWidth / 2) /
(double)m_canvasWidth;
int col = bgcol | (128 - (int)(255 * alpha) << 24);
m_rgbData[i] = col;
m_rgbData[i + m_canvasWidth ] = col;
m_rgbData[i + m_canvasWidth * 2] = col;
m_rgbData[i + m_canvasWidth * 3] = col;
}
// Calculate maximum score text width
m_scoreWidth =
super.m_itemFont.charsWidth(SCORE_TXT, 0, SCORE_TXT.length);
}
// Extend PageItem.paintItem to handle GameRecordPageItems
protected void paintItem(Graphics g, PageItem item, boolean selected, int x,
int y, int w, int iMaxW, boolean to, boolean from)
{
if (selected)
{
int itemH = getItemHeight(item);
// draw transparent background on selected item
for (int by = y;
by < y + itemH;
by += 4)
{
g.drawRGB(m_rgbData, 0, m_canvasWidth, x - m_canvasWidth/2, by, m_canvasWidth,
Math.min(4, y + itemH - (by - y)), true);
}
}
if (item instanceof GameRecordPageItem)
{
g.setFont(super.m_itemFont);
GameRecordPageItem grItem = (GameRecordPageItem)item;
char[] opName = grItem.getOpponentNameChars();
char[] plScore = grItem.getPlayerScoreChars();
char[] opScore = grItem.getOpponentScoreChars();
if (!selected)
{
g.setColor(grItem.isEnabled() ? super.m_itemColor : super.m_itemColorDisabled);
}
else
{
g.setColor(super.m_selItemColor);
}
g.drawChars(opName, 0, opName.length,
x - iMaxW / 2, y,
Graphics.TOP | Graphics.LEFT);
g.drawChars(plScore, 0, plScore.length,
x - iMaxW / 2 + iMaxW - m_scoreWidth - super.m_imgPadding, y,
Graphics.TOP | Graphics.RIGHT);
g.drawChars(opScore, 0, opScore.length,
x - iMaxW / 2 + iMaxW, y,
Graphics.TOP | Graphics.RIGHT);
}
else
{
super.paintItem(g, item, selected, x, y, w, iMaxW, to, from);
}
}
// Extend PageItem.getItemWidth to handle GameRecordPageItems
protected int getItemWidth(PageItem item)
{
if (item instanceof GameRecordPageItem)
{
GameRecordPageItem grItem = (GameRecordPageItem)item;
int w =
super.m_itemFont.charsWidth(grItem.getOpponentNameChars(), 0,
grItem.getOpponentNameChars().length);
w += m_scoreWidth * 2;
w += super.m_imgPadding * 2;
return w;
}
else
{
return super.getItemWidth(item);
}
}
} // end of BackgammonMenuPainter
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -