diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-10-25 20:30:56 +0200 |
---|---|---|
committer | HacktheTime <l4bg0jb7@duck.com> | 2023-10-25 20:30:56 +0200 |
commit | 229c0892f283275b57ed0d45ad401413543f218c (patch) | |
tree | 6d16a30705b2c3753d6daf0bbea865b957f86131 /fabric/src/main/java/de/hype/bbsentials | |
parent | 80ffe4a632c9d1cc2c7021b990939916fd0155e0 (diff) | |
download | BBsentials-229c0892f283275b57ed0d45ad401413543f218c.tar.gz BBsentials-229c0892f283275b57ed0d45ad401413543f218c.tar.bz2 BBsentials-229c0892f283275b57ed0d45ad401413543f218c.zip |
added pages too the numpad config
eased up the closing of the connection to be fully internal.
updatet the fabric version
fixed some bugs
Diffstat (limited to 'fabric/src/main/java/de/hype/bbsentials')
-rw-r--r-- | fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java | 1 | ||||
-rw-r--r-- | fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java | 54 |
2 files changed, 49 insertions, 6 deletions
diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java index 2a9ce01..8a81934 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java @@ -81,6 +81,7 @@ public class ModInitialiser implements ClientModInitializer { .then(ClientCommandManager.literal("disconnect") .executes((context) -> { connection.close(); + Chat.sendPrivateMessageToSelfInfo("Disconnected"); return 1; })) .then(ClientCommandManager.literal("reconnect-stable-server") diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java index 37df8ca..eb70e5b 100644 --- a/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/numpad/NumPadConfigScreen.java @@ -12,7 +12,13 @@ public class NumPadConfigScreen extends Screen { public List<NumCode> hiddenNumCodes = new ArrayList<>(); ButtonWidget addButton; ButtonWidget okButton; + + ButtonWidget firstPage; + ButtonWidget lastPage; + ButtonWidget nextPage; + ButtonWidget previosPage; NumPadCodes codes; + int page = 0; private List<NumCodeInputField> codeTextFields; private List<TextFieldWidget> commandTextFields; private List<ButtonWidget> removeButtonFields; @@ -35,6 +41,10 @@ public class NumPadConfigScreen extends Screen { addButton = new ButtonWidget.Builder(Text.of("+"), button -> { addNewRow(); }).build(); + firstPage = new ButtonWidget.Builder(Text.of("First"), button -> setPage(0)).build(); + lastPage = new ButtonWidget.Builder(Text.of("Last"), button -> setPage(-2)).build(); + nextPage = new ButtonWidget.Builder(Text.of("Next"), button -> setPage(page + 1)).build(); + previosPage = new ButtonWidget.Builder(Text.of("Previous"), button -> setPage(page - 1)).build(); } else { hiddenNumCodes.add(numCode); @@ -53,6 +63,14 @@ public class NumPadConfigScreen extends Screen { } + public void setPage(int newPage) { + int max = commandTextFields.size() / ((height - 100) / 30); + if (newPage < 0) newPage = 0; + if (newPage > max) newPage = max; + page = newPage; + updateFields(); + } + private void addRow(String code, String command) { NumCodeInputField textField2 = new NumCodeInputField(textRenderer, width / 3, 20, Text.of(("")), this); textField2.setText(code); @@ -72,9 +90,9 @@ public class NumPadConfigScreen extends Screen { private void removeRow(int i) { if (!codeTextFields.isEmpty()) { - TextFieldWidget removedCodeField = codeTextFields.remove(i - 1); - TextFieldWidget removedCommandField = commandTextFields.remove(i - 1); - ButtonWidget removeButton = removeButtonFields.remove(i - 1); + TextFieldWidget removedCodeField = codeTextFields.remove(i - 2); + TextFieldWidget removedCommandField = commandTextFields.remove(i - 2); + ButtonWidget removeButton = removeButtonFields.remove(i - 2); remove(removeButton); remove(removedCodeField); remove(removedCommandField); @@ -88,8 +106,8 @@ public class NumPadConfigScreen extends Screen { clearChildren(); - for (int i = 0; i < codeTextFields.size(); i++) { - int hight = 60 + i * 30; + for (int i = getMinimumEntry(); i < getHighestEntry(); i++) { + int hight = 60 + (i - getMinimumEntry()) * 30; // Set the positions for codeTextFields codeTextFields.get(i).setX(leftX); @@ -105,16 +123,40 @@ public class NumPadConfigScreen extends Screen { removeButtonFields.get(i).setWidth(width / 12); removeButtonFields.get(i).setX(rightX + width / 3 + width / 18 - removeButtonFields.get(i).getWidth() / 2); // Place the remove button to the right removeButtonFields.get(i).setY(hight); - + firstPage.setPosition(0, 20); + lastPage.setPosition(0, height - 10 - lastPage.getHeight()); + nextPage.setPosition(0, firstPage.getHeight() + firstPage.getY() + 10); + previosPage.setPosition(0, lastPage.getY() - lastPage.getHeight() - 10); + nextPage.setWidth(width / 12); + previosPage.setWidth(width / 12); + lastPage.setWidth(width / 12); + firstPage.setWidth(width / 12); addDrawableChild(codeTextFields.get(i)); addDrawableChild(commandTextFields.get(i)); addDrawableChild(removeButtonFields.get(i)); + addDrawableChild(nextPage); + addDrawableChild(previosPage); + addDrawableChild(lastPage); + addDrawableChild(firstPage); } addDrawableChild(addButton); addDrawableChild(okButton); } + public int getMinimumEntry() { + return Math.min(entriesPerPage() * page, commandTextFields.size()); + } + + public int entriesPerPage() { + return Math.min((height - 100) / 30, commandTextFields.size()); + } + + public int getHighestEntry() { + int max = Math.min(entriesPerPage() * (page + 1) - 1, commandTextFields.size()); + return max; + } + public void updateCodes() { List<NumCode> newCodes = new ArrayList<>(hiddenNumCodes); for (int i = 0; i < commandTextFields.size(); i++) { |