Ejemplo n.º 1
0
  protected CommandForm getGameOptionsForm() {
    AllBinaryGameLayerManager layerManager = this.createGameLayerManager();

    return GameOptionsFormFactory.getInstance()
        .init(
            this,
            "Game Options",
            layerManager.getBackgroundBasicColor(),
            layerManager.getForegroundBasicColor());
    // return GameOptionsForm.getInstance();
    // return gameOptionsForm;
  }
Ejemplo n.º 2
0
  public synchronized void commandAction(Command command, Displayable displayable) {
    try {
      String displayableAsString = NO_DISPLAYABLE;
      if (displayable != null) {
        displayableAsString = displayable.toString();
      }

      String label = NO_COMMAND;
      if (command != null) {
        label = command.getLabel();
      }

      PreLogUtil.put(
          new StringMaker()
              .append(COMMAND_NAME)
              .append(label)
              .append(DISPLAYABLE)
              .append(displayableAsString)
              .toString(),
          this,
          this.COMMAND_ACTION);

      GameCommandsFactory gameCommandsFactory = GameCommandsFactory.getInstance();

      if (command == gameCommandsFactory.SHOW_GAME_CANVAS) {
        // TWB - If progress concurrency is a problem then this is probably the cause
        if (this.getDisplay().getCurrent() != this.allbinaryGameCanvasRunnableInterface) {
          this.setDisplay((Displayable) this.allbinaryGameCanvasRunnableInterface);
        }

        this.unPauseAppBackground(false);
      } else if (command == gameCommandsFactory.CLOSE_AND_SHOW_GAME_CANVAS) {
        // this.closeMenuListener();
        MenuListener menuListener = (MenuListener) displayable;
        menuListener.close();

        this.setDisplay((Displayable) this.allbinaryGameCanvasRunnableInterface);
        this.unPauseAppBackground(false);
      } else if (command == gameCommandsFactory.EXIT_COMMAND) {
        // TWB - Handle exit for android differently
        if (GameMidletEventHandler.getInstance().getEventListenerInterfaceList().size() == 0) {
          this.exit(true);
        }

        GameMidletEventHandler.getInstance().fireEvent(null);
      } else if (command == gameCommandsFactory.EXIT_WITHOUT_PROGRESS_COMMAND) {
        this.exit(false);
      } else if (command == gameCommandsFactory.START_COMMAND
          || command == gameCommandsFactory.RESTART_COMMAND
          || command == gameCommandsFactory.CONTINUE_COMMAND) {
        // GameState gameState = GameStateFactory.getInstance(command);
        if (gameMidletStateFactory.getCurrentGameState() != GameState.PLAYING_GAME_STATE
            || command == gameCommandsFactory.RESTART_COMMAND) {
          if (this.gameStartTimeHelper.isTime()) {
            this.createGame();
            gameMidletStateFactory.setCurrentGameState(GameState.PLAYING_GAME_STATE);
          } else {
            LogUtil.put(
                LogFactory.getInstance(
                    "Starting Game Too Often", this, MidletStrings.getInstance().COMMAND_ACTION));
          }

        } else {
          LogUtil.put(LogFactory.getInstance("Already in playing state", this, COMMAND_ACTION));
        }

      } else if (command == gameCommandsFactory.BUY_COMMAND) {
        InApplicationPurchaseFactory inApplicationPurchaseFactory =
            InApplicationPurchaseFactory.getInstance();

        final BasicArrayList list = LockableFeatureFactory.getInstance().getList();
        LockableFeature lockableFeature = (LockableFeature) list.get(0);

        if (list.size() > 0 && !inApplicationPurchaseFactory.isPurchased(lockableFeature)) {
          inApplicationPurchaseFactory.purchase(lockableFeature);
          // TextNotificationUtil.getInstance().fireSuccess("In Application Purchase Request");
        } else {
          TextNotificationUtil.getInstance().fireSuccess("Already Purchased");
        }
      } else if (command == gameCommandsFactory.QUIT_COMMAND) {
        if (this.gameStartTimeHelper.isTime()) {
          this.stopGameCanvasRunnableInterface();
          gameMidletStateFactory.setCurrentGameState(GameState.NO_GAME_STATE);
          this.setDemo();
        }
      } else if (command == MyCommandsFactory.getInstance().RESUME_COMMAND) {
        this.unPauseAppBackground(false);
      } else if (command == MyCommandsFactory.getInstance().PAUSE_COMMAND) {
        this.pauseAppBackground(false);
      } else if (command == MyCommandsFactory.getInstance().SET_DISPLAYABLE) {
        this.pauseAppBackground(false);

        this.setDisplay(displayable);
      } else if (command == gameCommandsFactory.SET_MENU_DISPLAYABLE) {
        this.pauseAppBackground(false);

        MenuListener menuListener = (MenuListener) displayable;
        menuListener.open();

        this.setDisplay(displayable);
      } else if (command == gameCommandsFactory.START_TRACE) {
        this.debugInterface.start();
        ((AllBinaryGameCanvas) this.allbinaryGameCanvasRunnableInterface)
            .addCommand(gameCommandsFactory.STOP_TRACE);
        ((AllBinaryGameCanvas) this.allbinaryGameCanvasRunnableInterface)
            .removeCommand(gameCommandsFactory.START_TRACE);
      } else if (command == gameCommandsFactory.STOP_TRACE) {
        this.pauseAppBackground(false);
        this.debugInterface.stop();
        this.unPauseAppBackground(false);
        ((AllBinaryGameCanvas) this.allbinaryGameCanvasRunnableInterface)
            .addCommand(gameCommandsFactory.START_TRACE);
        ((AllBinaryGameCanvas) this.allbinaryGameCanvasRunnableInterface)
            .removeCommand(gameCommandsFactory.STOP_TRACE);
      } else if (command == gameCommandsFactory.DEFAULT_OPTIONS) {
        Displayable tempDisplayable = displayable;
        if (tempDisplayable instanceof GameOptionsForm) {
          GameFeatureFormUtil.getInstance().setDefault((CommandForm) tempDisplayable);
        }
      } else if (command == GameInputMappingInstructionsCanvas.DISPLAY) {
        Displayable tempDisplayable = displayable;
        if (tempDisplayable instanceof GameInputMappingCanvas) {
          GameInputMappingCanvas gameInputMappingCanvas = (GameInputMappingCanvas) tempDisplayable;
          gameInputMappingCanvas.update();
        }

        this.commandAction(
            gameCommandsFactory.SET_MENU_DISPLAYABLE, this.getInputMappingInstructionsCanvas());

        // this.setDisplay((Displayable) this.getInputMappingInstructionsCanvas());
      } else if (HighScoreCommandsFactory.getInstance().isHighScoreCommand(command)) {
        Displayable tempDisplayable = displayable;
        if (tempDisplayable instanceof HighScoresCanvas) {
          HighScoresCanvas highScoresCanvas = (HighScoresCanvas) tempDisplayable;

          highScoresCanvas.updateCommand(command);
        }
      } else if (command == HighScoreCommands.getInstance().DISPLAY) {
        this.commandAction(gameCommandsFactory.SET_MENU_DISPLAYABLE, this.createHighScoresCanvas());
      } else if (command == GameInputMappingInstructionsCanvas.CLOSE) {
        MenuListener menuListener = (MenuListener) displayable;
        menuListener.close();

        this.commandAction(GameInputMappingCanvas.DISPLAY, null);
      } else if (command == GameInputMappingCanvas.DISPLAY) {
        // TWB - Called for HTML5 but not others?
        Features features = Features.getInstance();

        if (features.isDefault(HTMLFeatureFactory.getInstance().HTML)) {
          this.pauseAppBackground(false);
        }

        this.commandAction(gameCommandsFactory.SET_MENU_DISPLAYABLE, this.getInputMappingCanvas());

        // this.setDisplay((Displayable) this.getInputMappingCanvas());
      } else if (command == GameInputMappingCanvas.DEFAULT) {
        Displayable tempDisplayable = displayable;
        if (tempDisplayable instanceof GameInputMappingCanvas) {
          GameInputMappingCanvas gameInputMappingCanvas = (GameInputMappingCanvas) tempDisplayable;
          gameInputMappingCanvas.setDefault();
        }
      } else if (command == InGameOptionsForm.DISPLAY) {
        this.pauseAppBackground(false);

        ProgressCanvas progressCanvas = ProgressCanvasFactory.getInstance();

        progressCanvas.addPortion(50, "In Game Options");

        AllBinaryGameLayerManager layerManager = this.createGameLayerManager();

        InGameOptionsFormFactory.init(
            this,
            new InGameFeatures(),
            "Options In Game",
            layerManager.getBackgroundBasicColor(),
            layerManager.getForegroundBasicColor());

        InGameOptionsForm inGameOptionsForm = InGameOptionsFormFactory.getInstance();

        inGameOptionsForm.setItemStateListener(this.allbinaryGameCanvasRunnableInterface);

        this.commandAction(gameCommandsFactory.SET_MENU_DISPLAYABLE, inGameOptionsForm);
      } else if (command == InGameOptionsForm.DEFAULT) {
        GameFeatureFormUtil.getInstance().setDefault(InGameOptionsFormFactory.getInstance());
      } else if (command == gameCommandsFactory.DISPLAY_OPTIONS) {
        AllBinaryMediaManager.setMuted(true);
        this.stopAll();

        MainFeatureFactory mainFeatureFactory = MainFeatureFactory.getInstance();
        Features features = Features.getInstance();

        isFullScreen = features.isFeature(mainFeatureFactory.FULL_SCREEN);

        // PreLogUtil.put("Open isFullScreen: " + isFullScreen, this,
        // MidletStrings.getInstance().COMMAND_ACTION);

        ResizableListenerHandler.getInstance().fireEvent(true);

        this.setResized(false);

        this.commandAction(gameCommandsFactory.SET_MENU_DISPLAYABLE, this.getGameOptionsForm());
      } else if (command == gameCommandsFactory.CLOSE_OPTIONS) {
        // PreLogUtil.put("Close", this, MidletStrings.getInstance().COMMAND_ACTION);
        ResizableListenerHandler.getInstance().fireEvent(false);

        this.commandAction(gameCommandsFactory.CLOSE_AND_SHOW_GAME_CANVAS, displayable);

        StringMaker stringBuffer = new StringMaker();
        stringBuffer.append("Close isFullScreen/change: ");
        stringBuffer.append(isFullScreen);
        stringBuffer.append(FullScreenUtil.isScreenChange(isFullScreen));
        stringBuffer.append(" isResized: ");
        stringBuffer.append(this.isResized());

        PreLogUtil.put(stringBuffer.toString(), this, COMMAND_ACTION);

        // Restart canvas if screen change
        if (this.isResized() || FullScreenUtil.isScreenChange(isFullScreen)) {
          // PreLogUtil.put("Resized/Changed", this, MidletStrings.getInstance().COMMAND_ACTION);

          this.updateFullScreen();
        }

        AllBinaryMediaManager.setMuted(false);
      } else if (command == gameCommandsFactory.DISPLAY_LOAD_FORM) {
        this.pauseAppBackground(false);

        KeyValuePersistance keyValuePersistance = GamePersistanceSingleton.getInstance();

        keyValuePersistance.clear();
        keyValuePersistance.loadAll();

        if (this.getLoadGameForm() == null) {
          AllBinaryGameLayerManager layerManager = this.createGameLayerManager();

          this.setLoadGameForm(
              new LoadGameForm(
                  this,
                  "Load Game",
                  layerManager.getBackgroundBasicColor(),
                  layerManager.getForegroundBasicColor()));
        } else {
          this.getLoadGameForm().update();
        }

        this.commandAction(gameCommandsFactory.SET_MENU_DISPLAYABLE, this.getLoadGameForm());

        // this.setDisplay((Displayable) this.getLoadGameForm());
      } else if (command == gameCommandsFactory.LOAD_FILE) {
        int index = this.getLoadGameForm().getSelectedId();

        if (index != -1) {
          KeyValuePersistance keyValuePersistance = GamePersistanceSingleton.getInstance();

          this.setStartStateHashtable(keyValuePersistance.get(index));

          MenuListener menuListener = this.getLoadGameForm();
          menuListener.close();

          PreLogUtil.put(BasicMotionGesturesHandler.getInstance().toString(), this, COMMAND_ACTION);

          this.commandAction(gameCommandsFactory.START_COMMAND, null);

          PreLogUtil.put(BasicMotionGesturesHandler.getInstance().toString(), this, COMMAND_ACTION);
        }
      } else if (command == gameCommandsFactory.DELETE_FILE) {
        int index = this.getLoadGameForm().getSelectedText();

        if (index != -1) {
          KeyValuePersistance keyValuePersistance = GamePersistanceSingleton.getInstance();

          keyValuePersistance.delete(index);
          keyValuePersistance.clear();
          keyValuePersistance.loadAll(1);
          this.getLoadGameForm().update();
        }
      }
      /*
      else if (command == GameCommands.DISPLAY_SAVE_FORM)
      {
      this.pauseApp();
      this.setDisplay((Displayable) this.getSaveGameForm());
      }*/
      else if (command == gameCommandsFactory.SAVE) {
        KeyValuePersistance keyValuePersistance = GamePersistanceSingleton.getInstance();

        this.pauseAppBackground(false);
        // String name = ((SaveGameForm) this.getSaveGameForm()).getText();
        keyValuePersistance.save(this.getCurrentStateHashtable());

        // this.setDisplay((Displayable) allbinaryGameCanvasRunnableInterface);

        this.unPauseAppBackground(false);
      } else if (command == HighScoreTextBox.SUBMIT_TEXTBOX_COMMAND) {
        LogUtil.put(LogFactory.getInstance("Submitted Score", this, COMMAND_ACTION));

        this.allbinaryGameCanvasRunnableInterface.setHighScoreSubmitted(true);

        this.commandAction(gameCommandsFactory.CLOSE_AND_SHOW_GAME_CANVAS, displayable);
      } else if (command == gameCommandsFactory.DISPLAY_ABOUT) {
        this.commandAction(gameCommandsFactory.SET_MENU_DISPLAYABLE, this.getAboutCanvas());
      } else if (command == gameCommandsFactory.TOGGLE_KEYBOARD) {
        VirtualKeyboardEventHandler virtualKeyboardEventHandler =
            VirtualKeyboardEventHandler.getInstance();

        virtualKeyboardEventHandler.fireEvent(virtualKeyboardEventHandler.SHOW_EVENT);
      } else if (command.getLabel().compareTo(gameCommandsFactory.TOGGLE_FULLSCREEN.getLabel())
          == 0) {
        MainFeatureFactory mainFeatureFactory = MainFeatureFactory.getInstance();

        Features features = Features.getInstance();

        boolean isFullScreen = features.isFeature(mainFeatureFactory.FULL_SCREEN);

        if (isFullScreen) {
          features.removeDefault(mainFeatureFactory.FULL_SCREEN);
        } else {
          features.addDefault(mainFeatureFactory.FULL_SCREEN);
        }

        this.updateFullScreen();
      }

      // no else
      // if (command != gameCommandsFactory.START_COMMAND && command !=
      // gameCommandsFactory.RESTART_COMMAND)
      // {
      // gameMidletStateFactory.setCurrentGameState(GameState.NO_GAME_STATE);
      // }

    } catch (Exception e) {
      LogUtil.put(
          LogFactory.getInstance(
              CommonStrings.getInstance().EXCEPTION,
              this,
              MidletStrings.getInstance().COMMAND_ACTION,
              e));
      if (command != GameCommandsFactory.getInstance().EXIT_COMMAND) {
        this.exit(false);
      }
    }
  }