Skip to content

Commit c2bb1c3

Browse files
authored
Allowed controlling the position and visibility of accounts and proxies button (#6336)
1 parent 2768fcf commit c2bb1c3

2 files changed

Lines changed: 102 additions & 12 deletions

File tree

src/main/java/meteordevelopment/meteorclient/mixin/MultiplayerScreenMixin.java

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package meteordevelopment.meteorclient.mixin;
77

88
import meteordevelopment.meteorclient.gui.GuiThemes;
9+
import meteordevelopment.meteorclient.systems.config.Config;
910
import meteordevelopment.meteorclient.systems.modules.Modules;
1011
import meteordevelopment.meteorclient.systems.modules.player.NameProtect;
1112
import meteordevelopment.meteorclient.systems.proxies.Proxies;
@@ -42,6 +43,15 @@ public abstract class MultiplayerScreenMixin extends Screen {
4243
@Unique
4344
private ButtonWidget proxies;
4445

46+
@Unique
47+
private static final int BUTTON_WIDTH = 75;
48+
@Unique
49+
private static final int BUTTON_HEIGHT = 20;
50+
@Unique
51+
private static final int MARGIN = 3;
52+
@Unique
53+
private static final int GAP = 2;
54+
4555
public MultiplayerScreenMixin(Text title) {
4656
super(title);
4757
}
@@ -57,34 +67,78 @@ private void onInit(CallbackInfo info) {
5767
if (accounts == null) {
5868
accounts = addDrawableChild(
5969
new ButtonWidget.Builder(Text.literal("Accounts"), button -> client.setScreen(GuiThemes.get().accountsScreen()))
60-
.size(75, 20)
70+
.size(BUTTON_WIDTH, BUTTON_HEIGHT)
6171
.build()
6272
);
6373
}
64-
accounts.setPosition(this.width - 75 - 3, 3);
6574

6675
if (proxies == null) {
6776
proxies = addDrawableChild(
68-
new ButtonWidget.Builder(Text.literal("Proxies"), button -> client.setScreen(GuiThemes.get().proxiesScreen()))
69-
.size(75, 20)
70-
.build()
71-
);
77+
new ButtonWidget.Builder(Text.literal("Proxies"), button -> client.setScreen(GuiThemes.get().proxiesScreen()))
78+
.size(BUTTON_WIDTH, BUTTON_HEIGHT)
79+
.build()
80+
);
81+
}
82+
83+
Config config = Config.get();
84+
Config.ButtonPosition accountPos = config.accountButtonAnchor.get();
85+
Config.ButtonPosition proxiesPos = config.proxiesButtonAnchor.get();
86+
boolean accountsVisible = accountPos != Config.ButtonPosition.Hidden;
87+
boolean proxiesVisible = proxiesPos != Config.ButtonPosition.Hidden;
88+
89+
accounts.visible = accountsVisible;
90+
proxies.visible = proxiesVisible;
91+
92+
positionButton(accounts, accountPos, proxiesVisible && proxiesPos == accountPos, true);
93+
positionButton(proxies, proxiesPos, accountsVisible && accountPos == proxiesPos, false);
94+
}
95+
96+
@Unique
97+
private void positionButton(ButtonWidget button, Config.ButtonPosition anchor, boolean sharingCorner, boolean isAccounts) {
98+
int leftOffset = sharingCorner && isAccounts ? BUTTON_WIDTH + GAP : 0;
99+
int rightOffset = sharingCorner && !isAccounts ? BUTTON_WIDTH + GAP : 0;
100+
101+
switch (anchor) {
102+
case TopRight -> button.setPosition(this.width - MARGIN - BUTTON_WIDTH - rightOffset, MARGIN);
103+
case TopLeft -> button.setPosition(MARGIN + leftOffset, MARGIN);
104+
case BottomLeft -> button.setPosition(MARGIN + leftOffset, this.height - MARGIN - BUTTON_HEIGHT);
105+
case BottomRight -> button.setPosition(this.width - MARGIN - BUTTON_WIDTH - rightOffset, this.height - MARGIN - BUTTON_HEIGHT);
106+
default -> button.setPosition(this.width - MARGIN - BUTTON_WIDTH - rightOffset, MARGIN); // Top right
72107
}
73-
proxies.setPosition(this.width - 75 - 3 - 75 - 2, 3);
74108
}
75109

76110
@Override
77111
public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) {
78112
super.render(context, mouseX, mouseY, deltaTicks);
79113

80-
int x = 3;
81-
int y = 3;
114+
Config config = Config.get();
115+
116+
if (!config.showAccountStatus.get() && !config.showProxiesStatus.get()) {
117+
return;
118+
}
119+
120+
// Shifts the top left account and proxy text to right if buttons are also top left
121+
int x = MARGIN;
122+
if (config.proxiesButtonAnchor.get() != Config.ButtonPosition.Hidden && config.proxiesButtonAnchor.get() == Config.ButtonPosition.TopLeft) {
123+
x += BUTTON_WIDTH + GAP;
124+
}
125+
if (config.accountButtonAnchor.get() != Config.ButtonPosition.Hidden && config.accountButtonAnchor.get() == Config.ButtonPosition.TopLeft) {
126+
x += BUTTON_WIDTH + GAP;
127+
}
128+
129+
int y = MARGIN;
82130

83131
// Logged in as
84-
context.drawTextWithShadow(mc.textRenderer, loggedInAs, x, y, textColor1);
85-
context.drawTextWithShadow(mc.textRenderer, Modules.get().get(NameProtect.class).getName(client.getSession().getUsername()), x + loggedInAsLength, y, textColor2);
132+
if (config.showAccountStatus.get()) {
133+
context.drawTextWithShadow(mc.textRenderer, loggedInAs, x, y, textColor1);
134+
context.drawTextWithShadow(mc.textRenderer, Modules.get().get(NameProtect.class).getName(client.getSession().getUsername()), x + loggedInAsLength, y, textColor2);
86135

87-
y += textRenderer.fontHeight + 2;
136+
y += textRenderer.fontHeight + 2;
137+
}
138+
139+
if (!config.showProxiesStatus.get()) {
140+
return;
141+
}
88142

89143
// Proxy
90144
Proxy proxy = Proxies.get().getEnabled();

src/main/java/meteordevelopment/meteorclient/systems/config/Config.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,34 @@ public class Config extends System<Config> {
103103
.build()
104104
);
105105

106+
public final Setting<ButtonPosition> accountButtonAnchor = sgVisual.add(new EnumSetting.Builder<ButtonPosition>()
107+
.name("accounts-button")
108+
.description("Controls the position and visibility of the accounts button in the multiplayer screen.")
109+
.defaultValue(ButtonPosition.TopRight)
110+
.build()
111+
);
112+
113+
public final Setting<Boolean> showAccountStatus = sgVisual.add(new BoolSetting.Builder()
114+
.name("account-status")
115+
.description("Shows information about the current account in the multiplayer screen.")
116+
.defaultValue(true)
117+
.build()
118+
);
119+
120+
public final Setting<ButtonPosition> proxiesButtonAnchor = sgVisual.add(new EnumSetting.Builder<ButtonPosition>()
121+
.name("proxies-button")
122+
.description("Controls the position and visibility of the proxies button in the multiplayer screen.")
123+
.defaultValue(ButtonPosition.TopRight)
124+
.build()
125+
);
126+
127+
public final Setting<Boolean> showProxiesStatus = sgVisual.add(new BoolSetting.Builder()
128+
.name("proxy-status")
129+
.description("Shows information about the current proxy in the multiplayer screen.")
130+
.defaultValue(true)
131+
.build()
132+
);
133+
106134
// Modules
107135

108136
public final Setting<List<Module>> hiddenModules = sgModules.add(new ModuleListSetting.Builder()
@@ -206,4 +234,12 @@ private List<String> listFromTag(NbtCompound tag, String key) {
206234
for (NbtElement item : tag.getListOrEmpty(key)) list.add(item.asString().orElse(""));
207235
return list;
208236
}
237+
238+
public enum ButtonPosition {
239+
TopLeft,
240+
TopRight,
241+
BottomLeft,
242+
BottomRight,
243+
Hidden,
244+
}
209245
}

0 commit comments

Comments
 (0)