Changeset 205f525 in advance-wars


Ignore:
Timestamp:
Jan 30, 2011, 8:26:19 PM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
26a9fd6, a0f5455
Parents:
90838a1
Message:

Added some buttons to the main menu. Added a new package to the project to make gui creation easier.

Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • res/values/strings.xml

    r90838a1 r205f525  
    22<resources>
    33    <string name="hello">Hello World, advancewars!</string>
    4     <string name="app_name"></string>
     4    <string name="app_name">Advance Wars</string>
    55    <string name="menu_exit">Exit</string>
    66</resources>
  • src/com/example/advancewars/Game.java

    r90838a1 r205f525  
    5252                this.finish();
    5353                break;
    54             case MENU_NEW:
    55                 break;
    5654        }
    5755
     
    6765    @Override
    6866    protected void onCreate(Bundle savedInstanceState) {
    69         Log.w("Blackjack", "We're inside onCreate");
     67        Log.w("AdvanceWars", "We're inside onCreate");
    7068       
    7169        super.onCreate(savedInstanceState);
    7270       
    73         Log.w("Blackjack", "the super constructor was called successfully");
     71        Log.w("AdvanceWars", "the super constructor was called successfully");
    7472
    7573        // turn off the window's title bar
     
    8179        mGameView = (GameView) findViewById(R.id.lunar);
    8280        mThread = mGameView.getThread();
     81        mGameView.mGame = this;
    8382
    8483        mGameView.setTextView((TextView) findViewById(R.id.text));
    8584
    8685        if (savedInstanceState == null) {       // we were just launched: set up a new game
    87                 Log.w("Blackjack", "SIS is null");
     86                Log.w("AdvanceWars", "SIS is null");
    8887               
    8988                mThread.setState(AppState.RUNNING);
    9089        } else {
    91             Log.w("Blackjack", "SIS is nonnull");
     90            Log.w("AdvanceWars", "SIS is nonnull");
    9291           
    9392            mThread.setState(AppState.RUNNING);
  • src/com/example/advancewars/GameView.java

    r90838a1 r205f525  
    22
    33import java.util.*;
     4
     5import com.example.gui.*;
    46
    57import android.content.Context;
     
    5759        private SurfaceHolder mSurfaceHolder;
    5860       
    59         public DrawingThread(SurfaceHolder surfaceHolder, Context context,
    60                 Handler handler) {
     61        private Hashtable<String, GUIObject> drawableObjects;
     62       
     63        public DrawingThread(SurfaceHolder surfaceHolder, Context context, Handler handler) {
    6164            // get handles to some important objects
    6265            mSurfaceHolder = surfaceHolder;
     
    7275            mTextPaint.setARGB(255, 255, 255, 255);
    7376            mTextPaint.setTextSize(12);
     77            mTextPaint.setTextAlign(Paint.Align.CENTER);
    7478           
    7579            mButtonPaint = new Paint();
     
    8690            mTilePaint2.setAntiAlias(true);
    8791            mTilePaint2.setARGB(255, 0, 0, 255);
     92           
     93            drawableObjects = new Hashtable<String, GUIObject>();
     94           
     95            drawableObjects.put("txtTitle", new Text("Main Menu", 100, 30, 120, 20, mTextPaint));
     96            drawableObjects.put("btnNewGame", new Button("New Game", 100, 90, 120, 20, mLinePaint, mButtonPaint));
     97            drawableObjects.put("btnLoadGame", new Button("Load Game", 100, 125, 120, 20, mLinePaint, mButtonPaint));
     98            drawableObjects.put("btnMapEditor", new Button("Map Editor", 100, 160, 120, 20, mLinePaint, mButtonPaint));
     99            drawableObjects.put("btnQuit", new Button("Quit", 100, 195, 120, 20, mLinePaint, mButtonPaint));
    88100           
    89101            Tile grassTile = new Tile(mTilePaint1);
     
    116128                mLastTime = System.currentTimeMillis() + 100;
    117129                setState(AppState.RUNNING);
    118                 Log.i("Blackjack", "Player's turn starting now");
     130                Log.i("AdvanceWars", "Player's turn starting now");
    119131                mGameState = GameState.MAIN_MENU;
    120132            }
     
    234246                mCanvasHeight = height;
    235247               
    236                 Log.i("Blackjack", "width: "+mCanvasWidth+", height: "+mCanvasHeight);
     248                Log.i("AdvanceWars", "width: "+mCanvasWidth+", height: "+mCanvasHeight);
    237249            }
    238250        }
     
    319331                switch(mGameState) {
    320332                case MAIN_MENU:
    321                         text = "Main Menu";
    322                 canvas.drawText(text, 0, 450-(metrics.ascent+metrics.descent)/2, mTextPaint);
     333                for (GUIObject o : drawableObjects.values()) {
     334                        o.draw(canvas);
     335                }
    323336                        break;
    324337                case BATTLE_MAP:
     
    360373    /** The thread that actually draws the animation */
    361374    private DrawingThread thread;
     375   
     376    public Game mGame;
    362377
    363378    public GameView(Context context, AttributeSet attrs) {
     
    381396
    382397    @Override public boolean onTouchEvent(MotionEvent event) {
    383         Log.i("Blackjack", "Detected touch event");
     398        Log.i("AdvanceWars", "Detected touch event");
    384399       
    385400        if(event.getAction() == MotionEvent.ACTION_UP) {
    386                 Log.i("Blackjack", "Detected UP touch action");
     401                Log.i("AdvanceWars", "Detected UP touch action");
    387402                switch(thread.mGameState) {
    388403                case MAIN_MENU:
    389                         Log.i("Blackjack", "Switching to battle map");
    390                         thread.mGameState = GameState.BATTLE_MAP;
     404                        Log.i("AdvanceWars", "Switching to battle map");
     405                        if(thread.drawableObjects.get("btnNewGame").isClicked(event.getX(), event.getY())) {
     406                                thread.mGameState = GameState.BATTLE_MAP;
     407                        }else if(thread.drawableObjects.get("btnLoadGame").isClicked(event.getX(), event.getY())) {
     408                                thread.mGameState = GameState.BATTLE_MAP;
     409                        }else if(thread.drawableObjects.get("btnQuit").isClicked(event.getX(), event.getY())) {
     410                                mGame.finish();
     411                        }
    391412                        break;
    392413                case BATTLE_MAP:
    393                         Log.i("Blackjack", "Touch event detected on battle map");
     414                        Log.i("AdvanceWars", "Touch event detected on battle map");
     415                        thread.mGameState = GameState.MAIN_MENU;
    394416                        break;
    395417                }
Note: See TracChangeset for help on using the changeset viewer.