From 4b6ad8fd0526f80298758f5b544341f95931313b Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Sat, 22 Sep 2018 14:04:17 +0200 Subject: [PATCH] only display 'play'-button in extensions view if its used --- src/main/extensions/Extension.java | 13 ++++++++++++- src/main/extensions/examples/AdminOnConnect.java | 8 ++++---- src/main/ui/extensions/ExtensionItemContainer.java | 6 ++++-- src/main/ui/extensions/GEarthExtension.java | 9 ++++++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/extensions/Extension.java b/src/main/extensions/Extension.java index 9c57b87..5aea3a3 100644 --- a/src/main/extensions/Extension.java +++ b/src/main/extensions/Extension.java @@ -86,7 +86,8 @@ public abstract class Extension { response.appendString(getTitle()) .appendString(getAuthor()) .appendString(getVersion()) - .appendString(getDescription()); + .appendString(getDescription()) + .appendBoolean(isOnClickMethodUsed()); writeToStream(response.toBytes()); } else if (packet.headerId() == Extensions.OUTGOING_MESSAGES_IDS.CONNECTIONSTART) { @@ -255,6 +256,16 @@ public abstract class Extension { } + private boolean isOnClickMethodUsed() { + + try { + return !getClass().getDeclaredMethod("onClick").getDeclaringClass().equals(Extension.class); + } catch (NoSuchMethodException e) { +// e.printStackTrace(); + } + return false; + } + /** * Gets called when a connection has been established with G-Earth. * This does not imply a connection with Habbo is setup. diff --git a/src/main/extensions/examples/AdminOnConnect.java b/src/main/extensions/examples/AdminOnConnect.java index 11f1dde..5ac4c53 100644 --- a/src/main/extensions/examples/AdminOnConnect.java +++ b/src/main/extensions/examples/AdminOnConnect.java @@ -40,10 +40,10 @@ public class AdminOnConnect extends Extension { done = false; } - @Override - protected void onClick() { - System.out.println("clicked"); - } +// @Override +// protected void onClick() { +// System.out.println("clicked"); +// } protected String getTitle() { return "Always admin!"; diff --git a/src/main/ui/extensions/ExtensionItemContainer.java b/src/main/ui/extensions/ExtensionItemContainer.java index 6dfd330..56f3263 100644 --- a/src/main/ui/extensions/ExtensionItemContainer.java +++ b/src/main/ui/extensions/ExtensionItemContainer.java @@ -69,11 +69,13 @@ public class ExtensionItemContainer extends GridPane { deleteButton.show(); deleteButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.isRemoveClickTrigger()); SimpleClickButton clickButton = new SimpleClickButton(); - clickButton.show(); + if (item.isFireButtonUsed()) { + clickButton.show(); + } clickButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.isClickTrigger()); HBox buttonsBox = new HBox(clickButton, deleteButton); - buttonsBox.setSpacing(10); + buttonsBox.setSpacing(item.isFireButtonUsed() ? 10 : 0); buttonsBox.setAlignment(Pos.CENTER); GridPane.setMargin(buttonsBox, new Insets(0, 5, 0, 5)); add(buttonsBox, 4, 0); diff --git a/src/main/ui/extensions/GEarthExtension.java b/src/main/ui/extensions/GEarthExtension.java index 90da825..9d88dda 100644 --- a/src/main/ui/extensions/GEarthExtension.java +++ b/src/main/ui/extensions/GEarthExtension.java @@ -23,6 +23,7 @@ public class GEarthExtension { private String author; private String version; private String description; + private boolean fireEventButtonVisible; private Socket connection; @@ -57,6 +58,7 @@ public class GEarthExtension { packet.readString(), packet.readString(), packet.readString(), + packet.readBoolean(), connection, onDisconnectedCallback ); @@ -70,11 +72,12 @@ public class GEarthExtension { } - private GEarthExtension(String title, String author, String version, String description, Socket connection, OnDisconnectedCallback onDisconnectedCallback) { + private GEarthExtension(String title, String author, String version, String description, boolean fireEventButtonVisible, Socket connection, OnDisconnectedCallback onDisconnectedCallback) { this.title = title; this.author = author; this.version = version; this.description = description; + this.fireEventButtonVisible = fireEventButtonVisible; this.connection = connection; GEarthExtension selff = this; @@ -139,6 +142,10 @@ public class GEarthExtension { return version; } + public boolean isFireButtonUsed() { + return fireEventButtonVisible; + } + public boolean closeConnection() {