📄 gameselection.java
字号:
// -----------------------------------------------------------------
private class DownloadSelectorListener implements SelectorListener
{ public void itemSelected(int idx,int key)
{ if(getGameAction(key)==GAME_A)
{ if(state==LOADED_CAT)
{ if(SudokuME.selectedOnlineCatalogueDir.parent!=null)
{ // -----Inside a sub directory (but not root directory)
SudokuME.selectedOnlineCatalogueDir=SudokuME.selectedOnlineCatalogueDir.parent;
downloadSelector.reset();
}
}
else if(state==LOADED_BUN)
{ // -----Inside a bundle
SudokuME.selectedBundle=null;
downloadSelector.setModel(new DownloadSelectorModelCat());
state=LOADED_CAT;
}
repaint();
}
// -----Only FIRE actions from this point on...
if(getGameAction(key)!=FIRE) return;
if(state==LOADED_CAT) // Catalogue menu?
{ // -----Get selected entry in current directory of catalogue
Object obj = SudokuME.selectedOnlineCatalogueDir.array[idx];
if(obj instanceof OnlineDirectory) // Selected a sub-directory in catalogue?
{ // -----Selected a sub directory
SudokuME.selectedOnlineCatalogueDir=(OnlineDirectory)obj;
downloadSelector.reset();
repaint();
}
else if(obj instanceof OnlineEntry) // Selected a bundle?
{ // -----Selected a bundle
synchronized(this) // Race cond: 'state'
{ if(state!=LOADING_BUN)
{ state=LOADING_BUN;
//SudokuME.selectedBundle=SudokuME.onlineCatalogue[idx];
SudokuME.selectedBundle=(OnlineEntry)SudokuME.selectedOnlineCatalogueDir.array[idx];
downloadSelector.setModel(new DownloadSelectorModelBun());
new Thread()
{ public void run()
{ try
{ SudokuME.selectedBundle.load();
state=LOADED_BUN; // Finished loading
repaint();
}
finally
{ // -----ALWAYS tell the model's thread to exit
downloadSelector.quitFlag=true;
}
}
}.start();
}
}
}
}
else if(state==LOADED_BUN) // Bundle menu?
{ // -----Bundle menu ?
byte[][] g = SudokuME.selectedBundle.gameGrids[idx];
String title = SudokuME.selectedBundle.gameTitles[idx];
listener.gameSelected(new GameData(g.length,g,title));
}
}
}
private class DownloadSelectorModelCat implements SelectorModel
{ public String itemAt(int i)
{ return (SudokuME.selectedOnlineCatalogueDir==null) ? null : SudokuME.selectedOnlineCatalogueDir.toString(i) ;
}
public int length()
{ return (SudokuME.selectedOnlineCatalogueDir==null) ? 0 : SudokuME.selectedOnlineCatalogueDir.array.length ;
}
public int loaded()
{ return OnlineEntry.catalogueLoadToGo;
}
public String loadingErrorMessage()
{ return OnlineEntry.catalogueLoadError;
}
}
private class DownloadSelectorModelBun implements SelectorModel
{ public String itemAt(int i)
{ return (SudokuME.selectedBundle.gameTitles==null) ? null : SudokuME.selectedBundle.gameTitles[i] ;
}
public int length()
{ return (SudokuME.selectedBundle.gameGrids==null) ? 0 : SudokuME.selectedBundle.gameGrids.length ;
}
public int loaded()
{ return SudokuME.selectedBundle.bundleLoadToGo;
}
public String loadingErrorMessage()
{ return SudokuME.selectedBundle.bundleLoadError;
}
}
// -----------------------------------------------------------------
// Redraw display
// -----------------------------------------------------------------
public void paint(Graphics g)
{ // -----See footnote 1 at bottom of "SudokuME,java" and footnote 1
// -----at the bottom of this file.
if(destroyed) return;
int w=getWidth() , h=getHeight();
int fh=Font.getDefaultFont().getHeight();
// -----Clear
g.setColor(0xff,0xff,0xff);
g.fillRect(0,0,w,h);
_drawTab(g,"Load",LOAD_TAB,TABS,(tab==LOAD_TAB));
_drawTab(g,"New",NEW_TAB,TABS,(tab==NEW_TAB));
_drawTab(g,"Online",DOWNLOAD_TAB,TABS,(tab==DOWNLOAD_TAB));
if(tab==LOAD_TAB && recordCatalogue!=null && recordCatalogue.length>0)
{ // -----Load game from record store
loadSelector.paint(g);
}
else if(tab==NEW_TAB)
{ // -----New game menu options
newSelector.paint(g);
}
else if(tab==DOWNLOAD_TAB)
{ // -----First time here? Start loading catalogue
synchronized(this) // Race cond: 'state'
{ if(state==UNLOADED)
{ state=LOADING_CAT;
downloadSelector.setModel(new DownloadSelectorModelCat());
new Thread()
{ public void run()
{ try
{ SudokuME.onlineCatalogue=OnlineEntry.catalogue();
SudokuME.selectedOnlineCatalogueDir = SudokuME.onlineCatalogue;
state=LOADED_CAT; // Finished loading
repaint();
}
finally
{ // -----ALWAYS tell the model's thread to exit
downloadSelector.quitFlag=true;
}
}
}.start();
}
}
// -----Download options/etc
downloadSelector.paint(g);
}
}
private void _drawTab(Graphics g,String s,int pos,int count,boolean selected)
{ int fh=Font.getDefaultFont().getHeight();
int w=getWidth()/count , h=fh+4;
g.translate(w*pos,2);
if(selected)
{ g.setColor(0xcc,0xcc,0xff);
g.fillRect(5,2 , w-10+1,fh+1);
}
g.setColor(0x00,0x00,0x00);
g.drawLine(0,h,5,0); // /
g.drawLine(5,0,w-5,0); // ^^^^
g.drawLine(w-5,0,w,h); // \
if(!selected) g.drawLine(0,h,w,h); // ____
if(!selected) g.setColor(0xaa,0xaa,0xaa); // Unseleted text colour
g.drawString(s,w/2,2,CENTERED);
g.translate(0-g.getTranslateX() , -2);
}
// -----------------------------------------------------------------
// Key press handler
// -----------------------------------------------------------------
public void keyPressed(int keyCode)
{ switch(tab)
{ case LOAD_TAB : loadSelector.keyPressed(keyCode); break;
case NEW_TAB : newSelector.keyPressed(keyCode); break;
case DOWNLOAD_TAB : downloadSelector.keyPressed(keyCode); break;
}
repaint();
}
public void keyRepeated(int keyCode)
{ switch(getGameAction(keyCode))
{ case UP :
case DOWN :
case LEFT :
case RIGHT :
case FIRE :
keyPressed(keyCode);
break;
}
}
// -----------------------------------------------------------------
// Soft key handler
// -----------------------------------------------------------------
public void commandAction(Command c,Displayable d)
{ if(c==prevCommand) tab=(tab-1+TABS)%TABS;
else if(c==nextCommand) tab=(tab+1+TABS)%TABS;
repaint();
}
}
// Footnote [1]
// Once the MIDlet is resumed, paint() is called on the 'old' Displayable
// which LCDUI has held onto. Naturally much of the data members in this
// object will, by then, be set to null (to allow them to be garbage
// collected, thereby reducing the memory footprint of the paused
// MIDlet) which will cause NullPointerException's to be thrown.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -