Package com.drakulo.games.ais.ui.component

Examples of com.drakulo.games.ais.ui.component.ActionHandler


    final int buttonX = this.getOX() + this.width / 2
        - Button.DEFAULT_WIDTH / 2;
    final int buttonY = this.getOY() + this.height - Button.DEFAULT_HEIGHT
        - 5;
    this.closeButton = new TextButton(I18n.get("global.close"), buttonX, buttonY);
    this.closeButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        hide();
      }
View Full Code Here


    // Button for open the game menu
    label = FontHelper.firstToUpper(I18n.get("global.game_menu"));
    TextButton gameMenuButton = new TextButton(label, x, y);
    gameMenuButton.setSize(buttonWidth, buttonHeight);
    gameMenuButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        toggleGameMenu();
      }
    });
    add(gameMenuButton);

    // Load button
    y += vPadding;
    label = FontHelper.firstToUpper(I18n.get("global.load"));
    Button loadButton = new TextButton(label, x, y);
    loadButton.setSize(buttonWidth, buttonHeight);
    loadButton.disable();
    loadButton.hide();
    loadButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        // TODO
      }
    });
    gameMenuButtons.add(loadButton);
    add(loadButton);

    // Save button
    y += vPadding;
    label = FontHelper.firstToUpper(I18n.get("global.save"));
    Button saveButton = new TextButton(label, x, y);
    saveButton.hide();
    saveButton.setSize(buttonWidth, buttonHeight);
    saveButton.disable();
    saveButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        // TODO
      }
    });
    gameMenuButtons.add(saveButton);
    add(saveButton);

    // Settings button
    y += vPadding;
    label = FontHelper.firstToUpper(I18n.get("global.settings"));
    Button settingsButton = new TextButton(label, x, y);
    settingsButton.setSize(buttonWidth, buttonHeight);
    settingsButton.disable();
    settingsButton.hide();
    settingsButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        // TODO
      }
    });
    gameMenuButtons.add(settingsButton);
    add(settingsButton);

    // Main menu button
    y += vPadding;
    label = FontHelper.firstToUpper(I18n.get("global.main_menu"));
    Button mainMenu = new TextButton(label, x, y);
    mainMenu.setSize(buttonWidth, buttonHeight);
    mainMenu.hide();
    mainMenu.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        GameData.getGame().enterState(AloneInSpace.MAIN_MENU_STATE);
      }
    });
    gameMenuButtons.add(mainMenu);
    add(mainMenu);
   
    // Exit button
    y += vPadding;
    label = FontHelper.firstToUpper(I18n.get("global.exit"));
    Button exitButton = new TextButton(label, x, y);
    exitButton.setSize(buttonWidth, buttonHeight);
    exitButton.hide();
    exitButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        GameData.getGameContainer().exit();
      }
View Full Code Here

    Button terrabotButton = new ImageButton("TERRABOT", x, y);
    terrabotButton.disable();
    // TODO why the terrabutton size is fucked?
    terrabotButton.setSize(ImageButton.IB_DEFAULT_SIZE,
        ImageButton.IB_DEFAULT_SIZE);
    terrabotButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        PreparationAction pa = BuildingHelper.create(GameData.getSelectedColony());
        BuildWindowOld.this.parent.setSelectedAction(pa);
        hide();
      }
    });
    terrabotButton.setHoverHandler(new ActionHandler() {

      @Override
      public void run() {
        initMaps();
        BuildWindowOld.this.name = "terrabot";
View Full Code Here

  }

  private Button createBuildingButton(String text, final BuildingType type) {
    ImageButton button = new ImageButton(type.toString());
    button.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        BuildingAction ba = BuildingHelper.createAction(GameData.getSelectedColony(), type,
            BuildWindowOld.this.cost);
        BuildWindowOld.this.parent.setSelectedAction(ba);
        hide();
      }
    });
    button.setHoverHandler(new ActionHandler() {

      @Override
      public void run() {
        displayBuildingData(type);
      }
View Full Code Here

    this.background = ImageManager.getGfx("space_background");

    this.exploreButton = new ImageButton("exploration");
    this.exploreButton.setTitle(I18n.get("planet.explore_sector"));
    this.exploreButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        if (PlanetState.this.selectedColony == null) {
          // TODO play error sound
        } else {
          startZoneSelectionForExploration();
        }
      }
    });
    exploreButton.setHoverHandler(new ActionHandler() {

      @Override
      public void run() {
        // Exploration = 2500 Gas
        Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
        costMap.put(Resource.GAS, BigDecimal.valueOf(2500));
        resources.setMap(costMap);
        resources.show();
      }
    });
    add(this.exploreButton);

    this.viewButton = new ImageButton("home");
    this.viewButton.setTitle(I18n.get("planet.go_to_colony"));
    this.viewButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        if (PlanetState.this.selectedColony == null) {
          // TODO play error sound

        } else {
          GameData.setSelectedColony(PlanetState.this.selectedColony);
          GameData.getGame().enterState(AloneInSpace.SECTOR_STATE);
        }
      }
    });
    add(this.viewButton);

    this.colonizeButton = new ImageButton("top_right_expand");
    this.colonizeButton.setTitle(I18n.get("planet.colonize"));
    this.colonizeButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        if (PlanetState.this.selectedColony == null) {
          // TODO play error sound

        } else {
          // TODO Externalize
          Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
          for (Resource r : Resource.values()) {
            costMap.put(r, BigDecimal.valueOf(10000));
          }
          if (ResourceHelper.enoughResourcesFor(costMap)) {
            startZoneSelectionForColonization();
          } else {
            // TODO Play error sound
          }
        }
      }
    });
    this.colonizeButton.setHoverHandler(new ActionHandler() {

      @Override
      public void run() {
        // Colonization = 10.000 each
        Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
        for (Resource r : Resource.values()) {
          costMap.put(r, BigDecimal.valueOf(10000));
        }
        resources.setMap(costMap);
        resources.show();
      }
    });
    add(this.colonizeButton);


    transferButton = new ImageButton("transfer");
    transferButton.setTitle(I18n.get("planet.transfer"));
    transferButton.setActionHandler(new ActionHandler() {
     
      @Override
      public void run() {
        transferWindow.show();
      }
    });
    add(transferButton);
   
    this.showNewColonyWindow = false;
    this.createColonyButton = new TextButton(I18n.get("global.ok"));
    this.createColonyButton.setWidth(80);
    this.createColonyButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        final Colony c = new Colony();
        c.setName(PlanetState.this.colonyNameField.getText());
        PlanetState.this.colonyNameField.setText("");
        try {
          c.setMap(new TiledMap("data/testmap.tmx"));
        } catch (SlickException e) {
          // TODO Handle TiledMap loading in a manager
          e.printStackTrace();
        }
        c.setResource(Resource.CRISTAL, BigDecimal.valueOf(1000));
        c.setResource(Resource.ENERGY, BigDecimal.valueOf(1000));
        c.setResource(Resource.FOOD, BigDecimal.valueOf(1000));
        c.setResource(Resource.GAS, BigDecimal.valueOf(1000));
        final int selectedIndex = PlanetState.this.map
            .getSelectedZone();

        final HexagonMapAction a = new HexagonMapAction(2,
            PlanetState.this.map, PlanetState.this.map
                .getSelectedZone());
        a.setExploration(false);
        a.setCallback(new Runnable() {

          @Override
          public void run() {
            GameData.putInPool(c);
            PlanetState.this.map.addColonyAt(c, selectedIndex);

            // Create the new selector
            PlanetState.this.colonies.add(new ColonySelector(c,
                getRootPane()));
          }
        });

        GameData.addHexagonMapAction(a);
        stopZoneSelection();
        PlanetState.this.showNewColonyWindow = false;
      }
    });
    createColonyButton.hide();
    add(createColonyButton);

    this.cancelColonyButton = new TextButton(I18n.get("global.cancel"));
    this.cancelColonyButton.setWidth(80);
    this.cancelColonyButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        PlanetState.this.showNewColonyWindow = false;
        PlanetState.this.colonizationSelection = false;
View Full Code Here

    final int bwidth = 150;
    final int bheight = TextButton.DEFAULT_HEIGHT;
    newGameButton = new TextButton(I18n.getFirstToUpper("global.new_game"));
    newGameButton.setSize(bwidth, bheight);
    newGameButton.setActionHandler(new ActionHandler() {
      public void run() {
        game.enterState(AloneInSpace.SECTOR_STATE);
      }
    });
    getRootPane().add(newGameButton.getBindable());
    buttons.add(newGameButton);

    optionsButton = new TextButton(I18n.getFirstToUpper("global.settings"));
    optionsButton.setSize(bwidth, bheight);
    optionsButton.disable();
    optionsButton.setActionHandler(new ActionHandler() {
      public void run() {
        // TODO
      }
    });
    getRootPane().add(optionsButton.getBindable());
    buttons.add(optionsButton);

    exitButton = new TextButton(I18n.getFirstToUpper("global.exit"));
    exitButton.setSize(bwidth, bheight);
    exitButton.setActionHandler(new ActionHandler() {
      public void run() {
        container.exit();
      }
    });
    getRootPane().add(exitButton.getBindable());
View Full Code Here

    // Terrabot
    ImageButton terrabotButton = new ImageButton("terrabot", x, y);
    terrabotButton.setTitle(I18n.get("terrabot"));
    terrabotButton.disable();
    terrabotButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        PreparationAction pa = BuildingHelper.create(GameData
            .getSelectedColony());
        BuildWindow.this.parent.setSelectedAction(pa);
        hide();
      }
    });
    terrabotButton.setHoverHandler(new ActionHandler() {

      @Override
      public void run() {
        String desc = I18n.get("terrabot.desc");
        Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
View Full Code Here

    // Create the button
    ImageButton button = new ImageButton(type.toString());
    button.setTitle(I18n.get(type.getI18n()));
    // Set the build action
    button.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        BuildingAction ba = BuildingHelper.createAction(
            GameData.getSelectedColony(), type, costMap);
        parent.setSelectedAction(ba);
        hide();
      }
    });
    // Set the hover action
    button.setHoverHandler(new ActionHandler() {

      @Override
      public void run() {
        final String desc = I18n.get(type.getDescI18n());
        displayBuildingData(desc, costMap);
View Full Code Here

    this.backToSectorButton = new TextButton(
        I18n.get("research.back_to_sector"));
    this.backToSectorButton.setSize(BUTTON_WIDTH, bh);
    this.backToSectorButton.setPosition(x, y);
    this.backToSectorButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        GameData.getGame().enterState(AloneInSpace.SECTOR_STATE);
      }
    });
    add(backToSectorButton);

    x = this.backToSectorButton.getOX()
        + this.backToSectorButton.getWidth() + padding;
    this.homeButton = new TextButton(I18n.get("research.back_to_root"));
    this.homeButton.setSize(BUTTON_WIDTH, bh);
    this.homeButton.setPosition(x, y);
    this.homeButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        backToRoot = true;
        GameData.setLastViewedTechnology(null);
      }
    });
    add(homeButton);

    x = 600;
    y = Settings.HEIGHT - padding - ImageButton.IB_DEFAULT_SIZE;
    this.startResearchButton = new TextButton(I18n.get("research.start"));
    startResearchButton.setSize(190, 25);
    startResearchButton.hide();
   
    researchProgress.setMaxValue(BigDecimal.valueOf(100));
    this.startResearchButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        // First, verify the amount of resources needed
        Map<Resource, BigDecimal> cost = ResearchState.this.uiTechnology
            .getTechnology().getCost();
        Resource[] resources = Resource.values();
        for (Resource r : resources) {
          if (NumberHelper.inf(GameData.getSelectedColony()
              .getResource(r), cost.get(r))) {
            // Not enough resources
            // TODO Play an error sound
            return;
          }
        }

        // The research can start
        // Resoures are removed from the store
        for (Resource r : resources) {
          GameData.getSelectedColony().updateResource(r,
              cost.get(r).negate());
        }
        ResearchState.this.startResearchButton.disable();
        ResearchState.this.cancelResearchButton.enable();
        // TODO externalize research duration in technologies file
        ResearchAction action = new ResearchAction(
            ResearchState.this.uiTechnology.getTechnology(), 5);
        GameData.getSelectedColony().setResearch(action);
      }
    });
    add(startResearchButton);
    x += ImageButton.IB_DEFAULT_SIZE + padding;
    this.cancelResearchButton = new ImageButton("delete"); // TODO I18N
    this.cancelResearchButton.setPosition(x, y);
    this.cancelResearchButton.disable();
    this.cancelResearchButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        GameData.getSelectedColony().setResearch(null);
        ResearchState.this.startResearchButton.enable();
View Full Code Here

    int x = Settings.WIDTH / 2 - ImageButton.IB_DEFAULT_SIZE / 2;
    int y = Settings.HEIGHT - 116 - PADDING - ImageButton.IB_DEFAULT_SIZE
        - PADDING;
    this.developButton = new ImageButton("cog", x, y);
    developButton.setTitle(I18n.get("ui.build_panel"));
    this.developButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        showBuildWindow(!SectorState.this.showActionWindow);
      }
    });
    add(developButton);

    x -= PADDING + ImageButton.IB_DEFAULT_SIZE;
    this.researchVisionButton = new ImageButton("lightbulb", x, y);
    researchVisionButton.setTitle(I18n.get("vision.research"));
    this.researchVisionButton.disable();
    this.researchVisionButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        GameData.getGame().enterState(AloneInSpace.RESEARCH_STATE);
      }
    });
    add(researchVisionButton);

    x -= PADDING + ImageButton.IB_DEFAULT_SIZE;
    this.planetVisionButton = new ImageButton("globe_3", x, y);
    planetVisionButton.setTitle(I18n.get("vision.planet"));
    this.planetVisionButton.disable();
    this.planetVisionButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        SectorState.this.selectedAction = null;
        SectorState.this.selectedBuilding = null;
        GameData.getGame().enterState(AloneInSpace.PLANET_STATE);
      }
    });
    add(planetVisionButton);

    // Cancel button

    final int startX = Settings.WIDTH - Minimap.WIDTH.intValue() - PADDING
        + 10;
    final int startY = Settings.HEIGHT - Minimap.HEIGHT.intValue()
        - PADDING + 9;
    this.buildingButtons = new ImageButton[3][3];
    for (int col = 0; col < 3; col++) {
      for (int row = 0; row < 3; row++) {
        this.buildingButtons[col][row] = new ImageButton(null, startX
            + col * 46, startY + row * 46);
        this.buildingButtons[col][row].disable();
        this.buildingButtons[col][row].hide();

      }
    }

    this.cancelButton = this.buildingButtons[2][2];
    this.cancelButton.setImageRef("cancel");
    this.cancelButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        stopSelectedBuildingAction();
      }
    });

    this.buildingButtons[0][2].setImageRef("upgrade");
    this.buildingButtons[0][2].setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        hideUpgradeLabels();
        upgradeBuilding(SectorState.this.selectedBuilding);
      }
    });

    int width = TOP_BAR_WIDTH + TOGGLE_BUTTON_ZONE_WIDTH;
    x = Settings.WIDTH / 2 - width / 2 + 4;
    y = PADDING + 3;
    final TextButton resourceTogglerButton = new TextButton("+");
    resourceTogglerButton.setPosition(x, y);
    resourceTogglerButton.setSize(21, 21);
    resourceTogglerButton.setActionHandler(new ActionHandler() {

      @Override
      public void run() {
        SectorState.this.extendedResourceDisplay = !SectorState.this.extendedResourceDisplay;
        Resource[] resources = Resource.values();
View Full Code Here

TOP

Related Classes of com.drakulo.games.ais.ui.component.ActionHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.