aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorolim <bobq4582@gmail.com>2024-02-22 15:31:44 +0000
committerolim <bobq4582@gmail.com>2024-02-22 15:31:44 +0000
commitae28951650980bb563542ad62c13b71ce991d7e3 (patch)
treec90c9c82726cac24ce35c19a3957c5969f9d6ae8 /src/main
parent4a1026b088dbd0f6c4621999ac94a55de97d16ac (diff)
downloadSkyblocker-ae28951650980bb563542ad62c13b71ce991d7e3.tar.gz
Skyblocker-ae28951650980bb563542ad62c13b71ce991d7e3.tar.bz2
Skyblocker-ae28951650980bb563542ad62c13b71ce991d7e3.zip
fix problems
fix text errors. and make buttons shrink when the width is too small so it should always fit on screen
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java54
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java2
-rw-r--r--src/main/resources/assets/skyblocker/lang/en_us.json6
3 files changed, 39 insertions, 23 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java
index 9b91d4a8..c99aeed8 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRuleConfigScreen.java
@@ -33,6 +33,8 @@ public class ChatRuleConfigScreen extends Screen {
entry(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.anvil"), SoundEvents.BLOCK_ANVIL_LAND)
);
+ private int buttonWidth = 75;
+
private final int chatRuleIndex;
private final ChatRule chatRule;
private TextFieldWidget nameInput;
@@ -94,7 +96,8 @@ public class ChatRuleConfigScreen extends Screen {
super.init();
if (client == null) return;
//start centered on the X and 1/3 down on the Y
- IntIntPair currentPos = IntIntPair.of((this.width - getMaxUsedWidth()) / 2, (int)((this.height -getMaxUsedHeight()) * 0.33));
+ calculateMaxButtonWidth();
+ IntIntPair currentPos = IntIntPair.of((this.width - getMaxUsedWidth()) / 2,(int)((this.height - getMaxUsedHeight()) * 0.33));
int lineXOffset;
nameLabelTextPos = currentPos;
@@ -123,29 +126,29 @@ public class ChatRuleConfigScreen extends Screen {
partialMatchToggle.setMessage(enabledButtonText(chatRule.getPartialMatch()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch.@Tooltip")))
.build();
- lineXOffset += 75 + SPACER_X;
- regexTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
+ lineXOffset += buttonWidth + SPACER_X;
+ regexTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex")) + SPACER_X;
regexToggle = ButtonWidget.builder(enabledButtonText(chatRule.getRegex()), a -> {
chatRule.setRegex(!chatRule.getRegex());
regexToggle.setMessage(enabledButtonText(chatRule.getRegex()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.regex.@Tooltip")))
.build();
- lineXOffset += 75 + SPACER_X;
- ignoreCaseTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
+ lineXOffset += buttonWidth + SPACER_X;
+ ignoreCaseTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase")) + SPACER_X;
ignoreCaseToggle = ButtonWidget.builder(enabledButtonText(chatRule.getIgnoreCase()), a -> {
chatRule.setIgnoreCase(!chatRule.getIgnoreCase());
ignoreCaseToggle.setMessage(enabledButtonText(chatRule.getIgnoreCase()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.ignoreCase.@Tooltip")))
.build();
currentPos = IntIntPair.of(currentPos.leftInt(), currentPos.rightInt() + SPACER_Y);
@@ -170,18 +173,18 @@ public class ChatRuleConfigScreen extends Screen {
hideMessageToggle.setMessage(enabledButtonText(chatRule.getHideMessage()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.hideMessage.@Tooltip")))
.build();
- lineXOffset += 75 + SPACER_X;
- actionBarTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
+ lineXOffset += buttonWidth + SPACER_X;
+ actionBarTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar")) + SPACER_X;
actionBarToggle = ButtonWidget.builder(enabledButtonText(chatRule.getShowActionBar()), a -> {
chatRule.setShowActionBar(!chatRule.getShowActionBar());
actionBarToggle.setMessage(enabledButtonText(chatRule.getShowActionBar()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.actionBar.@Tooltip")))
.build();
lineXOffset = 0;
@@ -194,11 +197,11 @@ public class ChatRuleConfigScreen extends Screen {
announcementToggle.setMessage(enabledButtonText(chatRule.getShowAnnouncement()));
})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(75, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement.@Tooltip")))
.build();
- lineXOffset += 75 + SPACER_X;
- customSoundLabelTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset, currentPos.rightInt());
+ lineXOffset += buttonWidth + SPACER_X;
+ customSoundLabelTextPos = IntIntPair.of(currentPos.leftInt() + lineXOffset,currentPos.rightInt());
lineXOffset += client.textRenderer.getWidth(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds")) + SPACER_X;
soundsToggle = ButtonWidget.builder(getSoundName(), a -> {
currentSoundIndex += 1;
@@ -213,7 +216,7 @@ public class ChatRuleConfigScreen extends Screen {
client.player.playSound(sound, 100f, 0.1f);
}})
.position(currentPos.leftInt() + lineXOffset, currentPos.rightInt())
- .size(100, 20)
+ .size(buttonWidth,20)
.tooltip(Tooltip.of(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.@Tooltip")))
.build();
currentPos = IntIntPair.of(currentPos.leftInt(), currentPos.rightInt() + SPACER_Y);
@@ -226,8 +229,8 @@ public class ChatRuleConfigScreen extends Screen {
replaceMessageInput.setText(chatRule.getReplaceMessage());
ButtonWidget finishButton = ButtonWidget.builder(Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.finish"), a -> close())
- .position(this.width - 75 - SPACER_Y, this.height - SPACER_Y)
- .size(75, 20)
+ .position(this.width - buttonWidth - SPACER_Y, this.height - SPACER_Y)
+ .size(buttonWidth, 20)
.build();
addDrawableChild(nameInput);
@@ -245,6 +248,18 @@ public class ChatRuleConfigScreen extends Screen {
}
/**
+ * if the maxUsedWidth is above the available width decrease the button width to fix this
+ */
+ private void calculateMaxButtonWidth() {
+ if (client == null || client.currentScreen == null) return;
+ buttonWidth = 75;
+ int available = client.currentScreen.width - getMaxUsedWidth() - SPACER_X * 2;
+ if (available >= 0) return; //keep the largest size if room
+ buttonWidth += available / 3; //remove the needed width from the width of the total 3 buttons
+ buttonWidth = Math.max(10,buttonWidth); //do not let the width go below 10
+ }
+
+ /**
* Works out the width of the maximum line
* @return the max used width
*/
@@ -257,8 +272,7 @@ public class ChatRuleConfigScreen extends Screen {
//space
total += SPACER_X * 6;
//button width
- total += 75 * 3;
-
+ total += buttonWidth * 3;
return total;
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java
index aecfa88d..a1b9317a 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/chat/ChatRulesConfigListWidget.java
@@ -125,7 +125,7 @@ public class ChatRulesConfigListWidget extends ElementListWidget<ChatRulesConfig
deleteButton = ButtonWidget.builder(Text.translatable("selectServer.delete"), a -> {
oldScrollAmount = getScrollAmount();
- client.setScreen(new ConfirmScreen(this::deleteEntry, Text.translatable("skyblocker.shortcuts.deleteQuestion"), Text.translatable("skyblocker.shortcuts.deleteWarning", chatRule.getName()), Text.translatable("selectServer.deleteButton"), ScreenTexts.CANCEL));
+ client.setScreen(new ConfirmScreen(this::deleteEntry, Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.deleteQuestion"), Text.translatable("text.autoconfig.skyblocker.option.messages.chatRules.screen.deleteWarning", chatRule.getName()), Text.translatable("selectServer.deleteButton"), ScreenTexts.CANCEL));
})
.size(50, 20)
.position(width / 2 + 105, 5)
diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json
index 9bb62378..8e63e7aa 100644
--- a/src/main/resources/assets/skyblocker/lang/en_us.json
+++ b/src/main/resources/assets/skyblocker/lang/en_us.json
@@ -380,13 +380,15 @@
"text.autoconfig.skyblocker.option.messages.chatRules.screen.modify": "Modify",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.editRule": "Edit",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.editRule.@Tooltip": "Open config for rule.",
+ "text.autoconfig.skyblocker.option.messages.chatRules.screen.deleteQuestion": "Are you sure you want to remove this rule?",
+ "text.autoconfig.skyblocker.option.messages.chatRules.screen.deleteWarning": "Rule '%s' will be lost forever! (A long time!)",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen": "Chat Rule Config...",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.true": "True",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.false": "False",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.inputs": "Inputs:",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name": "Name:",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.name.@Tooltip": "The name of the rule.",
- "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter": "ChatFilter:",
+ "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter": "Filter:",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.filter.@Tooltip": "The string/regex to match a chat message to.",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch": "Allow Partial Match:",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.partialMatch.@Tooltip": "If the filter can match part of the chat message.",
@@ -405,7 +407,7 @@
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.announcement.@Tooltip": "Show the message in the middle of the screen.",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace": "Replace Message With:",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.replace.@Tooltip": "Input a new message to output (can be formatted using minecraft color codes).",
- "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.finish": "finish",
+ "text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.finish": "Finish",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds": "Play Sound:",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.@Tooltip": "Play a sound when the message is sent.",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.none": "None",