Home | History | Annotate | Download | only in replicaisland
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17  package com.replica.replicaisland;
     18 
     19 import android.content.Context;
     20 
     21 public class GameFlowEvent implements Runnable {
     22 	public static final int EVENT_INVALID = -1;
     23     public static final int EVENT_RESTART_LEVEL = 0;
     24     public static final int EVENT_END_GAME = 1;
     25     public static final int EVENT_GO_TO_NEXT_LEVEL = 2;
     26 
     27     public static final int EVENT_SHOW_DIARY = 3;
     28     public static final int EVENT_SHOW_DIALOG_CHARACTER1 = 4;
     29     public static final int EVENT_SHOW_DIALOG_CHARACTER2 = 5;
     30 	public static final int EVENT_SHOW_ANIMATION = 6;
     31 
     32     private int mEventCode;
     33     private int mDataIndex;
     34     private AndouKun mMainActivity;
     35 
     36     public void post(int event, int index, Context context) {
     37         if (context instanceof AndouKun) {
     38         	DebugLog.d("GameFlowEvent", "Post Game Flow Event: " + event + ", " + index);
     39             mEventCode = event;
     40             mDataIndex = index;
     41             mMainActivity = (AndouKun)context;
     42             mMainActivity.runOnUiThread(this);
     43         }
     44     }
     45 
     46     public void postImmediate(int event, int index, Context context) {
     47         if (context instanceof AndouKun) {
     48         	DebugLog.d("GameFlowEvent", "Execute Immediate Game Flow Event: " + event + ", " + index);
     49             mEventCode = event;
     50             mDataIndex = index;
     51             mMainActivity = (AndouKun)context;
     52             mMainActivity.onGameFlowEvent(mEventCode, mDataIndex);
     53         }
     54     }
     55 
     56     public void run() {
     57         if (mMainActivity != null) {
     58         	DebugLog.d("GameFlowEvent", "Execute Game Flow Event: " + mEventCode + ", " + mDataIndex);
     59             mMainActivity.onGameFlowEvent(mEventCode, mDataIndex);
     60             mMainActivity = null;
     61         }
     62     }
     63 
     64 }
     65