public void handle(Player player, int hash, int dyn, ExtendedOption option) { if (player.actionsBlocked()) { return; } int widgetId = Widget.getWidgetId(hash); int child = Widget.getComponentId(hash); System.out.println( "button - parent: " + widgetId + " " + ", child: " + child + ", dyn: " + dyn + ", option: " + option); // Check for correct interfaces open in the handler! WindowHandler wHandler = windowHandlers.get(widgetId); if (wHandler != null) { if (wHandler.handle(player, widgetId, child, option, dyn)) { return; } } // TODO convert all of these switched ones to the new WindowHandler switch (widgetId) { case 271: player.getPrayers().toggle(Prayer.forId(child)); break; case 387: if (child == 55) { Equipment.showEquipmentInterface(player); } break; case 771: player.getAppearance().handle(child); break; default: /* Fetch the handler list for the specified hash */ List<ButtonHandler> list = handlerLists.get(hash); /* Check if the list is valid */ if (list == null) { return; } for (ButtonHandler handler : list) { /* If the handler option is equal to the option, handle it */ if (handler.getOption() == option) { handler.handle(player, dyn); } } break; } }
public void bind(ButtonHandler handler) { /* Calculate the hash for the widget */ int hash = Widget.getHash(handler.getParent(), handler.getChild()); List<ButtonHandler> list = handlerLists.get(hash); /* Create and store the list if it does not exist */ if (list == null) { list = new LinkedList<>(); handlerLists.put(hash, list); } /* Add the handler to the list */ list.add(handler); }
public void update() { if (!isValid()) { recalculateBoundsSize(text); recalculateBounds(); validate(); } colorTransition.update(GlobalTime.getDelta()); libgdxPointer.update(); pressed = false; released = false; boolean inside = MathUtils2.inside(bounds, libgdxPointer.getPosition()); if (wasInside && !inside) colorTransition.start(0.25f, notOverColor); if (!wasInside && inside) colorTransition.start(0.25f, overColor); wasInside = inside; if (libgdxPointer.wasPressed) pressed = MathUtils2.inside(bounds, libgdxPointer.getPressedPosition()); if (libgdxPointer.wasReleased) released = MathUtils2.inside(bounds, libgdxPointer.getReleasedPosition()); if (pressed) buttonHandler.onPressed(this); if (released) buttonHandler.onReleased(this); // NOTE: for now the button could be released while it was never pressed before }