@Override public void onPlay() { super.onPlay(); nifty.getScreen(screen).findElementById("text") .getRenderer(TextRenderer.class).setText(text); }
/** * find an element by name. * this method is deprecated, use findElementById() instead * * @param name the id to find * @return the element or null * @see Screen#findElementById(java.lang.String) */ @Nullable @Deprecated public Element findElementByName(final String name) { return findElementById(name); }
@Nullable public <T extends Controller> T findControl(final String elementName, @Nonnull final Class<T> requestedControlClass) { Element element = findElementById(elementName); if (element == null) { return null; } return element.getControl(requestedControlClass); }
public Element getGuiConstraint() { Element middle = nifty.getScreen(HUD_SCREEN_ID).findElementById("middle"); return middle; }
public Element getMessages() { return nifty.getScreen(HUD_SCREEN_ID).findElementById("systemMessages"); }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element elementParameter, @Nonnull final EffectProperties parameter) { String target = parameter.getProperty("target"); if (target != null) { Screen screen = nifty.getCurrentScreen(); if (screen == null) { log.severe("Can't activate the effect while there is no screen selected as current."); } else { targetElement = screen.findElementById(target); } } }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element elementParameter, @Nonnull final EffectProperties parameter) { String target = parameter.getProperty("target"); if (target != null) { Screen screen = nifty.getCurrentScreen(); if (screen == null) { log.severe("Can't activate the effect while there is no screen selected as current."); } else { targetElement = screen.findElementById(target); } } }
@Nullable public Element resolve(@Nullable final String id) { if (id == null) { return null; } if (id.startsWith(PARENT)) { return resolveParents(id, base.getParent()); } if (id.startsWith("#")) { return base.findElementById(id); } return screen.findElementById(id); }
private void bindToFocusHandler(final boolean isPopup) { if (!focusable) { return; } if (hasAncestorPopup() && !isPopup) { return; } if (screen == null) { log.severe("Trying to bind element [" + String.valueOf(getId()) + "] to focus handler while screen is not " + "bound."); } else { focusHandler.addElement(this, screen.findElementById(focusableInsertBeforeElementId)); } }
public void setPause(boolean paused) { nifty.getScreen(HUD_SCREEN_ID).findElementById("optionsMenu").setVisible(paused); }
/** * FIXME not applied when enter possession twice Focus active Action element * on GUI * * @param action */ protected void updatePossessionSelectedItem(PossessionInteractionState.Action action) { possessionAction = action; Element element = nifty.getScreen(POSSESSION_SCREEN_ID).findElementById("creature-" + possessionAction.toString().toLowerCase()); if (element != null) { element.setFocus(); } }
/** * Populates the player spells tab */ public void populateSpellTab() { Screen hud = nifty.getScreen(HUD_SCREEN_ID); FlowLayoutControl contentPanel = hud.findElementById("tab-spell-content").getControl(FlowLayoutControl.class); contentPanel.removeAll(); for (final Entry<KeeperSpell, PlayerSpell> entry : state.getSpellControl().getTypes().entrySet()) { contentPanel.addElement(createSpellIcon(entry.getValue())); } }
@Override public void restartCredits() { Element credits = screen.findElementById("creditList"); if (credits != null) { credits.resetEffects(); if (!credits.isEffectActive(EffectEventId.onActive)) { credits.startEffect(EffectEventId.onActive); } else { // Screen got changed credits.stopEffect(EffectEventId.onActive); } } }
@Nonnull private Element getHintLayer() { if (hintLayer != null) { return hintLayer; } if (screen == null || nifty == null) { throw new IllegalStateException("Can't create or retrieve hint layer while there is no active screen."); } hintLayer = screen.findElementById(HINT_LAYER_ID); if (hintLayer != null) { return hintLayer; } LayerBuilder builder = new LayerBuilder(HINT_LAYER_ID); builder.childLayout(ElementBuilder.ChildLayoutType.Absolute); builder.visible(false); hintLayer = builder.build(nifty, screen, screen.getRootElement()); hintLayer.setRenderOrder(Integer.MAX_VALUE); return hintLayer; }
protected void updateSelectedItem(PlayerInteractionState.InteractionState state) { if (selectedButton != null) { selectedButton.stopEffect(EffectEventId.onCustom); } String itemId = state.getType().toString().toLowerCase() + "_" + state.getItemId(); selectedButton = nifty.getScreen(HUD_SCREEN_ID).findElementById(itemId); if (selectedButton != null) { selectedButton.startEffect(EffectEventId.onCustom, null, "select"); } }
@Override public void pauseMenu() { boolean paused = !state.isPaused(); // Pause state state.setPaused(paused); // Set the menuButton Element menuButton = nifty.getScreen(HUD_SCREEN_ID).findElementById("menuButton"); if (paused) { menuButton.startEffect(EffectEventId.onCustom, null, "select"); } else { menuButton.stopEffect(EffectEventId.onCustom); } nifty.getScreen(HUD_SCREEN_ID).findElementById("optionsMenu").setVisible(paused); if (paused) { pauseMenuNavigate(PauseMenuState.MAIN.name(), null, null, null); } }
/** * Populates the player rooms tab */ public void populateRoomTab() { Screen hud = nifty.getScreen(HUD_SCREEN_ID); FlowLayoutControl contentPanel = hud.findElementById("tab-room-content").getControl(FlowLayoutControl.class); contentPanel.removeAll(); for (final Room room : state.getAvailableRoomsToBuild()) { contentPanel.addElement(createRoomIcon(room)); } }
@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); } } }
@NiftyEventSubscriber(id = PLAYER_LIST_ID) public void onPlayerListSelectionChanged(final String id, final ListBoxSelectionChangedEvent<PlayerTableRow> event) { List<PlayerTableRow> selection = event.getSelection(); Element element = screen.findElementById("changeAi"); if (selection.isEmpty() || !selection.get(0).getClientInfo().getKeeper().isAi()) { element.hide(); } else { TextRenderer textRenderer = element.getRenderer(TextRenderer.class); ResourceBundle rb = Utils.getMainTextResourceBundle(); String text = rb.getString("2121") + ": " + rb.getString(selection.get(0).getClientInfo().getKeeper().getAiType().getTranslationKey()); textRenderer.setText(text); element.setConstraintWidth(new SizeValue(textRenderer.getFont().getWidth(text) + "px")); element.show(); // Recalculate element.getParent().layoutElements(); } }
@Override public void togglePanel() { // FIXME work but not properly. Map should not move with other things. Need HUD redesign Element element = nifty.getScreen(HUD_SCREEN_ID).findElementById("bottomPanel"); if (!element.getUserDataKeys().contains("toggle")) { element.setUserData("toggle", false); } boolean toggled = element.getUserData("toggle"); if (toggled) { element.setMarginTop(new SizeValue(0, SizeValueType.Pixel)); } else { element.setMarginTop(new SizeValue(156, SizeValueType.Pixel)); } element.setUserData("toggle", !toggled); element.getParent().layoutElements(); }