@Override @SuppressWarnings("unchecked") public void bind(Nifty nifty, Screen screen) { applyButton = screen.findNiftyControl("ApplyButton", Button.class); platformListBox = screen.findNiftyControl("PlatformListBox", ListBox.class); deviceListBox = screen.findNiftyControl("DeviceListBox", ListBox.class); infoLabel = screen.findNiftyControl("InfoLabel", Label.class); updateInfos(); platformListBox.clear(); for (Platform p : availabePlatforms) { platformListBox.addItem(p.getName()); } platformListBox.selectItem(selectedPlatform); changePlatform(selectedPlatform); }
/** * Get the dropdown selection for type * * @return the dropdown */ protected DropDown<ModelViewer.Types> getTypeControl() { DropDown<ModelViewer.Types> dropDown = (DropDown<ModelViewer.Types>) screen.findNiftyControl(ID_TYPES, DropDown.class); return dropDown; }
/** * Get the listbox holding the models * * @return the listbox */ protected ListBox getItemsControl() { ListBox<Object> listBox = (ListBox<Object>) screen.findNiftyControl(ID_ITEMS, ListBox.class); return listBox; }
public Label getTooltip() { if (tooltip == null) { tooltip = nifty.getScreen(HUD_SCREEN_ID).findNiftyControl("tooltip", Label.class); } return tooltip; }
public Console getConsole() { return nifty.getScreen(HUD_SCREEN_ID).findNiftyControl("console", Console.class); }
private void linkToRadioGroup(@Nullable final String groupId) { if (screen == null) { log.warning("Linking to radio group failed. Is the binding not done yet?"); } if (groupId == null) { radioGroup = null; return; } radioGroup = screen.findNiftyControl(groupId, RadioButtonGroupControl.class); if (radioGroup == null) { log.warning("No radio group with the id [" + groupId + "] found."); } else { radioGroup.registerRadioButton(this); } }
private void linkToRadioGroup(@Nullable final String groupId) { if (screen == null) { log.warning("Linking to radio group failed. Is the binding not done yet?"); } if (groupId == null) { radioGroup = null; return; } radioGroup = screen.findNiftyControl(groupId, RadioButtonGroupControl.class); if (radioGroup == null) { log.warning("No radio group with the id [" + groupId + "] found."); } else { radioGroup.registerRadioButton(this); } }
private void setCinematicText(String text) { Label label = nifty.getScreen(CINEMATIC_SCREEN_ID).findNiftyControl("speechText", Label.class); cinematicText = text; label.setText(cinematicText); }
@Override public void multiplayerCreate() { TextField player = screen.findNiftyControl("playerName", TextField.class); TextField game = screen.findNiftyControl("gameName", TextField.class); TextField port = screen.findNiftyControl("gamePort", TextField.class); state.multiplayerCreate(game.getRealText(), Integer.valueOf(port.getRealText()), player.getRealText()); // Overlay popupElement = nifty.createPopup("connectingLayer"); nifty.showPopup(nifty.getCurrentScreen(), popupElement.getId(), null); }
@Override public void mapSelected() { ListBox<TableRow> listBox = screen.findNiftyControl("mapsTable", ListBox.class); int selectedMapIndex = listBox.getSelectedIndices().get(0); state.getLobbyState().setMap(selectedMapIndex); nifty.gotoScreen("skirmishLobby"); }
@Override public void changeAI() { TableControl<PlayerTableRow> playersList = screen.findNiftyControl(PLAYER_LIST_ID, TableControl.class); if (playersList != null && !playersList.getSelection().isEmpty()) { ClientInfo clientInfo = playersList.getSelection().get(0).getClientInfo(); if (clientInfo.getKeeper() != null && clientInfo.getKeeper().isAi()) { // Get "next" List<AI.AIType> types = Arrays.asList(AI.AIType.values()); int index = types.indexOf(clientInfo.getKeeper().getAiType()); state.getLobbyState().getLobbyService().changeAIType(clientInfo, index + 1 == types.size() ? types.get(0) : types.get(index + 1)); } } }
@Override public void workersAmount(String uiState) { WorkerAmountControl.State controlState = WorkerAmountControl.State.valueOf(uiState.toUpperCase()); if (controlState != null) { Screen s = nifty.getScreen(HUD_SCREEN_ID); WorkerAmountControl cAmount = s.findNiftyControl("tab-workers", WorkerAmountControl.class); cAmount.setState(controlState); WorkerEqualControl cEqual = s.findNiftyControl("tab-workers-equal", WorkerEqualControl.class); cEqual.setState(controlState); Element e = s.findElementById("tab-creature-content"); for (Element element : e.getChildren()) { element.getControl(CreatureCardControl.class).setState(controlState); } } }
private void setControlSettingsToGUI() { ListBox<TableRow> listBox = screen.findNiftyControl("keyboardSetup", ListBox.class); int i = 0; int selected = 0; KeyNames kNames = new KeyNames(); listBox.clear(); List<Settings.Setting> settings = Settings.Setting.getSettings(Settings.SettingCategory.CONTROLS); for (Settings.Setting setting : settings) { String keys = ""; if (setting.getSpecialKey() != null) { keys = (kNames.getName(setting.getSpecialKey()) + " + ").replace("Left ", "").replace("Right ", ""); } keys += kNames.getName((int) setting.getDefaultValue()).replace("Left ", "").replace("Right ", ""); TableRow row = new TableRow(i++, String.format("${menu.%s}", setting.getTranslationKey()), keys); listBox.addItem(row); } listBox.selectItemByIndex(selected); screen.findNiftyControl("mouseSensitivity", Slider.class).setValue((float) Settings.Setting.MOUSE_SENSITIVITY.getDefaultValue()); screen.findNiftyControl("gameSpeed", Slider.class).setValue((float) Settings.Setting.GAME_SPEED.getDefaultValue()); screen.findNiftyControl("scrollSpeed", Slider.class).setValue((float) Settings.Setting.SCROLL_SPEED.getDefaultValue()); screen.findNiftyControl("invertMouse", CheckBox.class).setChecked((boolean) Settings.Setting.MOUSE_INVERT.getDefaultValue()); }
@NiftyEventSubscriber(id = "fullscreen") public void onFullscreenChanged(final String id, final CheckBoxStateChangedEvent event) { //Set the refresh dropdown DropDown refresh = screen.findNiftyControl("refreshRate", DropDown.class); if (event.isChecked()) { refresh.enable(); } else { refresh.disable(); } }
/** * Set ups a sub objective text * * @param id the element ID * @param caption the text * @return returns the element */ private Label setupSubObjectiveLabel(String id, String caption) { // Get the actual label and set the text Label label = screen.findNiftyControl(id, Label.class); label.setText(caption.isEmpty() ? "" : "- ".concat(caption)); // Measure the text height so that the element can be arranged to the the screen without overlapping the othe sub objectives TextRenderer renderer = label.getElement().getRenderer(TextRenderer.class); label.setHeight(new SizeValue(renderer.getTextHeight() + "px")); return label; }
@Override public void multiplayerConnect() { /* ListBox<TableRow> games = screen.findNiftyControl("multiplayerGamesTable", ListBox.class); if (games == null) { logger.warning("Element multiplayerGamesTable not found"); return; } TableRow row = games.getFocusItem(); String host = row.getData().get(1); String port = row.getData().get(2); */ TextField player = screen.findNiftyControl("playerName", TextField.class); TextField hostAddress = screen.findNiftyControl("hostAddress", TextField.class); if (player == null || player.getRealText().isEmpty() || hostAddress == null || hostAddress.getRealText().isEmpty()) { return; } state.multiplayerConnect(hostAddress.getRealText(), player.getRealText()); // Overlay popupElement = nifty.createPopup("connectingLayer"); nifty.showPopup(nifty.getCurrentScreen(), popupElement.getId(), null); }
@Override public void kickPlayer() { TableControl<PlayerTableRow> playersList = screen.findNiftyControl(PLAYER_LIST_ID, TableControl.class); if (playersList != null && !playersList.getSelection().isEmpty()) { ClientInfo clientInfo = playersList.getSelection().get(0).getClientInfo(); // See that we wont kick ourselves out if (state.getLobbyState().getLobbySession().getPlayerId() != clientInfo.getId()) { state.getLobbyState().getLobbyService().removePlayer(clientInfo); } } }
@NiftyEventSubscriber(id = "resolution") public void onResolutionChanged(final String id, final DropDownSelectionChangedEvent<MyDisplayMode> event) { //Set the refresh dropdown DropDown refresh = screen.findNiftyControl("refreshRate", DropDown.class); refresh.clear(); refresh.addAllItems(event.getSelection().refreshRate); refresh.selectItemByIndex(refresh.itemCount() - 1); }
/** * Populate the map selection with given maps */ private void populateMapSelection(final boolean selectMap) { ListBox<TableRow> listBox = screen.findNiftyControl("mapsTable", ListBox.class); int i = 0; listBox.clear(); for (MapSelector.GameMapContainer mapContainer : state.mapSelector.getMaps()) { String name = mapContainer.getMapName(); KwdFile kwd = mapContainer.getMap(); if (kwd.getGameLevel().getLvlFlags().contains(GameLevel.LevFlag.IS_MY_PET_DUNGEON_LEVEL)) { // the resource tables in all the other levels are completely wrong, so we just use it for custom mpd maps name = kwd.getGameLevel().getLevelName().isEmpty() ? kwd.getGameLevel().getName() : kwd.getGameLevel().getLevelName(); } listBox.addItem(new TableRow(i, name, String.valueOf(kwd.getGameLevel().getPlayerCount()), String.format("%s x %s", kwd.getMap().getWidth(), kwd.getMap().getHeight()))); if (selectMap && kwd.equals(state.mapSelector.getMap().getMap())) { listBox.selectItemByIndex(i); } i++; } }
private void populateSelectedMap(KwdFile map) { // The map title Label label = screen.findNiftyControl("mapNameTitle", Label.class); label.setText(map == null ? "No maps found from " + PathUtils.DKII_MAPS_FOLDER : map.getGameLevel().getName()); NiftyUtils.resetContraints(label); if (map != null) { // Player count label = screen.findNiftyControl("playerCount", Label.class); label.setText(": " + map.getGameLevel().getPlayerCount()); NiftyUtils.resetContraints(label); // Map image Element mapImage = screen.findElementById("mapImage"); NiftyImage img = nifty.createImage(state.getMapThumbnail(map), true); mapImage.getRenderer(ImageRenderer.class).setImage(img); mapImage.setConstraintWidth(new SizeValue(img.getWidth() + "px")); mapImage.setConstraintHeight(new SizeValue(img.getHeight() + "px")); } // Re-populate screen.layoutLayers(); }