| 1 | /*
|
| 2 | * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
|
| 3 | * Copyright (c) Meteor Development.
|
| 4 | */
|
| 5 |
|
| 6 | package meteordevelopment.meteorclient.gui;
|
| 7 |
|
| 8 | import meteordevelopment.meteorclient.gui.renderer.packer.GuiTexture;
|
| 9 | import meteordevelopment.meteorclient.gui.screens.ModuleScreen;
|
| 10 | import meteordevelopment.meteorclient.gui.screens.ModulesScreen;
|
| 11 | import meteordevelopment.meteorclient.gui.screens.NotebotSongsScreen;
|
| 12 | import meteordevelopment.meteorclient.gui.screens.ProxiesScreen;
|
| 13 | import meteordevelopment.meteorclient.gui.screens.accounts.AccountsScreen;
|
| 14 | import meteordevelopment.meteorclient.gui.tabs.TabScreen;
|
| 15 | import meteordevelopment.meteorclient.gui.utils.CharFilter;
|
| 16 | import meteordevelopment.meteorclient.gui.utils.SettingsWidgetFactory;
|
| 17 | import meteordevelopment.meteorclient.gui.utils.WindowConfig;
|
| 18 | import meteordevelopment.meteorclient.gui.widgets.*;
|
| 19 | import meteordevelopment.meteorclient.gui.widgets.containers.*;
|
| 20 | import meteordevelopment.meteorclient.gui.widgets.input.*;
|
| 21 | import meteordevelopment.meteorclient.gui.widgets.pressable.*;
|
| 22 | import meteordevelopment.meteorclient.renderer.Texture;
|
| 23 | import meteordevelopment.meteorclient.renderer.text.TextRenderer;
|
| 24 | import meteordevelopment.meteorclient.settings.Settings;
|
| 25 | import meteordevelopment.meteorclient.systems.accounts.Account;
|
| 26 | import meteordevelopment.meteorclient.systems.modules.Module;
|
| 27 | import meteordevelopment.meteorclient.utils.misc.ISerializable;
|
| 28 | import meteordevelopment.meteorclient.utils.misc.Keybind;
|
| 29 | import meteordevelopment.meteorclient.utils.misc.Names;
|
| 30 | import meteordevelopment.meteorclient.utils.render.color.Color;
|
| 31 | import net.minecraft.client.gui.screens.Screen;
|
| 32 | import net.minecraft.core.BlockPos;
|
| 33 | import net.minecraft.nbt.CompoundTag;
|
| 34 | import net.minecraft.world.item.ItemStack;
|
| 35 |
|
| 36 | import java.util.HashMap;
|
| 37 | import java.util.Map;
|
| 38 |
|
| 39 | public abstract class GuiTheme implements ISerializable<GuiTheme> {
|
| 40 | public static final double TITLE_TEXT_SCALE = 1.25;
|
| 41 |
|
| 42 | public final String name;
|
| 43 | public final Settings settings = new Settings();
|
| 44 |
|
| 45 | public boolean disableHoverColor;
|
| 46 |
|
| 47 | protected SettingsWidgetFactory settingsFactory;
|
| 48 |
|
| 49 | protected final Map<String, WindowConfig> windowConfigs = new HashMap<>();
|
| 50 |
|
| 51 | public GuiTheme(String name) {
|
| 52 | this.name = name;
|
| 53 | }
|
| 54 |
|
| 55 | public void beforeRender() {
|
| 56 | disableHoverColor = false;
|
| 57 | }
|
| 58 |
|
| 59 | // Widgets
|
| 60 |
|
| 61 | public abstract WWindow window(WWidget icon, String title);
|
| 62 |
|
| 63 | public WWindow window(String title) {
|
| 64 | return window(null, title);
|
| 65 | }
|
| 66 |
|
| 67 | public abstract WLabel label(String text, boolean title, double maxWidth);
|
| 68 |
|
| 69 | public WLabel label(String text, boolean title) {
|
| 70 | return label(text, title, 0);
|
| 71 | }
|
| 72 |
|
| 73 | public WLabel label(String text, double maxWidth) {
|
| 74 | return label(text, false, maxWidth);
|
| 75 | }
|
| 76 |
|
| 77 | public WLabel label(String text) {
|
| 78 | return label(text, false);
|
| 79 | }
|
| 80 |
|
| 81 | public abstract WHorizontalSeparator horizontalSeparator(String text);
|
| 82 |
|
| 83 | public WHorizontalSeparator horizontalSeparator() {
|
| 84 | return horizontalSeparator(null);
|
| 85 | }
|
| 86 |
|
| 87 | public abstract WVerticalSeparator verticalSeparator();
|
| 88 |
|
| 89 | protected abstract WButton button(String text, GuiTexture texture);
|
| 90 |
|
| 91 | public WButton button(String text) {
|
| 92 | return button(text, null);
|
| 93 | }
|
| 94 |
|
| 95 | public WButton button(GuiTexture texture) {
|
| 96 | return button(null, texture);
|
| 97 | }
|
| 98 |
|
| 99 | protected abstract WConfirmedButton confirmedButton(String text, String confirmText, GuiTexture texture);
|
| 100 |
|
| 101 | public WConfirmedButton confirmedButton(String text, String confirmText) {
|
| 102 | return confirmedButton(text, confirmText, null);
|
| 103 | }
|
| 104 |
|
| 105 | public WConfirmedButton confirmedButton(GuiTexture texture) {
|
| 106 | return confirmedButton(null, null, texture);
|
| 107 | }
|
| 108 |
|
| 109 | public abstract WMinus minus();
|
| 110 |
|
| 111 | public abstract WConfirmedMinus confirmedMinus();
|
| 112 |
|
| 113 | public abstract WPlus plus();
|
| 114 |
|
| 115 | public abstract WCheckbox checkbox(boolean checked);
|
| 116 |
|
| 117 | public abstract WSlider slider(double value, double min, double max);
|
| 118 |
|
| 119 | public abstract WTextBox textBox(String text, String placeholder, CharFilter filter, Class<? extends WTextBox.Renderer> renderer);
|
| 120 |
|
| 121 | public WTextBox textBox(String text, CharFilter filter, Class<? extends WTextBox.Renderer> renderer) {
|
| 122 | return textBox(text, null, filter, renderer);
|
| 123 | }
|
| 124 |
|
| 125 | public WTextBox textBox(String text, String placeholder, CharFilter filter) {
|
| 126 | return textBox(text, placeholder, filter, null);
|
| 127 | }
|
| 128 |
|
| 129 | public WTextBox textBox(String text, CharFilter filter) {
|
| 130 | return textBox(text, filter, null);
|
| 131 | }
|
| 132 |
|
| 133 | public WTextBox textBox(String text, String placeholder) {
|
| 134 | return textBox(text, placeholder, (_, _) -> true, null);
|
| 135 | }
|
| 136 |
|
| 137 | public WTextBox textBox(String text) {
|
| 138 | return textBox(text, (_, _) -> true, null);
|
| 139 | }
|
| 140 |
|
| 141 | public abstract <T> WDropdown<T> dropdown(T[] values, T value);
|
| 142 |
|
| 143 | @SuppressWarnings("unchecked")
|
| 144 | public <T extends Enum<?>> WDropdown<T> dropdown(T value) {
|
| 145 | Class<?> klass = value.getDeclaringClass();
|
| 146 | T[] values = (T[]) klass.getEnumConstants();
|
| 147 | return dropdown(values, value);
|
| 148 | }
|
| 149 |
|
| 150 | public abstract WTriangle triangle();
|
| 151 |
|
| 152 | public abstract WTooltip tooltip(String text);
|
| 153 |
|
| 154 | public abstract WView view();
|
| 155 |
|
| 156 | public WVerticalList verticalList() {
|
| 157 | return w(new WVerticalList());
|
| 158 | }
|
| 159 |
|
| 160 | public WHorizontalList horizontalList() {
|
| 161 | return w(new WHorizontalList());
|
| 162 | }
|
| 163 |
|
| 164 | public WTable table() {
|
| 165 | return w(new WTable());
|
| 166 | }
|
| 167 |
|
| 168 | public abstract WSection section(String title, boolean expanded, WWidget headerWidget);
|
| 169 |
|
| 170 | public WSection section(String title, boolean expanded) {
|
| 171 | return section(title, expanded, null);
|
| 172 | }
|
| 173 |
|
| 174 | public WSection section(String title) {
|
| 175 | return section(title, true);
|
| 176 | }
|
| 177 |
|
| 178 | public abstract WAccount account(WidgetScreen screen, Account<?> account);
|
| 179 |
|
| 180 | public WWidget module(Module module) {
|
| 181 | return module(module, module.title);
|
| 182 | }
|
| 183 |
|
| 184 | public abstract WWidget module(Module module, String title);
|
| 185 |
|
| 186 | public abstract WQuad quad(Color color);
|
| 187 |
|
| 188 | public abstract WTopBar topBar();
|
| 189 |
|
| 190 | public abstract WFavorite favorite(boolean checked);
|
| 191 |
|
| 192 | public WItem item(ItemStack itemStack) {
|
| 193 | return w(new WItem(itemStack));
|
| 194 | }
|
| 195 |
|
| 196 | public WItemWithLabel itemWithLabel(ItemStack stack, String name) {
|
| 197 | return w(new WItemWithLabel(stack, name));
|
| 198 | }
|
| 199 |
|
| 200 | public WItemWithLabel itemWithLabel(ItemStack stack) {
|
| 201 | return itemWithLabel(stack, Names.get(stack.getItem()));
|
| 202 | }
|
| 203 |
|
| 204 | public WTexture texture(double width, double height, double rotation, Texture texture) {
|
| 205 | return w(new WTexture(width, height, rotation, texture));
|
| 206 | }
|
| 207 |
|
| 208 | public WIntEdit intEdit(int value, int min, int max, int sliderMin, int sliderMax, boolean noSlider) {
|
| 209 | return w(new WIntEdit(value, min, max, sliderMin, sliderMax, noSlider));
|
| 210 | }
|
| 211 |
|
| 212 | public WIntEdit intEdit(int value, int min, int max, int sliderMin, int sliderMax) {
|
| 213 | return w(new WIntEdit(value, min, max, sliderMin, sliderMax, false));
|
| 214 | }
|
| 215 |
|
| 216 | public WIntEdit intEdit(int value, int min, int max, boolean noSlider) {
|
| 217 | return w(new WIntEdit(value, min, max, 0, 0, noSlider));
|
| 218 | }
|
| 219 |
|
| 220 | public WDoubleEdit doubleEdit(double value, double min, double max, double sliderMin, double sliderMax, int decimalPlaces, boolean noSlider) {
|
| 221 | return w(new WDoubleEdit(value, min, max, sliderMin, sliderMax, decimalPlaces, noSlider));
|
| 222 | }
|
| 223 |
|
| 224 | public WDoubleEdit doubleEdit(double value, double min, double max, double sliderMin, double sliderMax) {
|
| 225 | return w(new WDoubleEdit(value, min, max, sliderMin, sliderMax, 3, false));
|
| 226 | }
|
| 227 |
|
| 228 | public WDoubleEdit doubleEdit(double value, double min, double max) {
|
| 229 | return w(new WDoubleEdit(value, min, max, 0, 10, 3, false));
|
| 230 | }
|
| 231 |
|
| 232 | public WBlockPosEdit blockPosEdit(BlockPos value) {
|
| 233 | return w(new WBlockPosEdit(value));
|
| 234 | }
|
| 235 |
|
| 236 | public WKeybind keybind(Keybind keybind) {
|
| 237 | return keybind(keybind, Keybind.none());
|
| 238 | }
|
| 239 |
|
| 240 | public WKeybind keybind(Keybind keybind, Keybind defaultValue) {
|
| 241 | return w(new WKeybind(keybind, defaultValue));
|
| 242 | }
|
| 243 |
|
| 244 | public WWidget settings(Settings settings, String filter) {
|
| 245 | return settingsFactory.create(this, settings, filter);
|
| 246 | }
|
| 247 |
|
| 248 | public WWidget settings(Settings settings) {
|
| 249 | return settings(settings, "");
|
| 250 | }
|
| 251 |
|
| 252 | // Screens
|
| 253 |
|
| 254 | public TabScreen modulesScreen() {
|
| 255 | return new ModulesScreen(this);
|
| 256 | }
|
| 257 |
|
| 258 | public boolean isModulesScreen(Screen screen) {
|
| 259 | return screen instanceof ModulesScreen;
|
| 260 | }
|
| 261 |
|
| 262 | public WidgetScreen moduleScreen(Module module) {
|
| 263 | return new ModuleScreen(this, module);
|
| 264 | }
|
| 265 |
|
| 266 | public WidgetScreen accountsScreen() {
|
| 267 | return new AccountsScreen(this);
|
| 268 | }
|
| 269 |
|
| 270 | public NotebotSongsScreen notebotSongs() {
|
| 271 | return new NotebotSongsScreen(this);
|
| 272 | }
|
| 273 |
|
| 274 | public WidgetScreen proxiesScreen() {
|
| 275 | return new ProxiesScreen(this);
|
| 276 | }
|
| 277 |
|
| 278 | // Colors
|
| 279 |
|
| 280 | public abstract Color textColor();
|
| 281 |
|
| 282 | public abstract Color textSecondaryColor();
|
| 283 |
|
| 284 | // Starscript
|
| 285 |
|
| 286 | public abstract Color starscriptTextColor();
|
| 287 |
|
| 288 | public abstract Color starscriptBraceColor();
|
| 289 |
|
| 290 | public abstract Color starscriptParenthesisColor();
|
| 291 |
|
| 292 | public abstract Color starscriptDotColor();
|
| 293 |
|
| 294 | public abstract Color starscriptCommaColor();
|
| 295 |
|
| 296 | public abstract Color starscriptOperatorColor();
|
| 297 |
|
| 298 | public abstract Color starscriptStringColor();
|
| 299 |
|
| 300 | public abstract Color starscriptNumberColor();
|
| 301 |
|
| 302 | public abstract Color starscriptKeywordColor();
|
| 303 |
|
| 304 | public abstract Color starscriptAccessedObjectColor();
|
| 305 |
|
| 306 | // Other
|
| 307 |
|
| 308 | public abstract TextRenderer textRenderer();
|
| 309 |
|
| 310 | public abstract double scale(double value);
|
| 311 |
|
| 312 | public abstract boolean categoryIcons();
|
| 313 |
|
| 314 | public abstract boolean modulesHelpText();
|
| 315 |
|
| 316 | public abstract boolean hideHUD();
|
| 317 |
|
| 318 | public double textWidth(String text, int length, boolean title) {
|
| 319 | return scale(textRenderer().getWidth(text, length, false) * (title ? TITLE_TEXT_SCALE : 1));
|
| 320 | }
|
| 321 |
|
| 322 | public double textWidth(String text) {
|
| 323 | return textWidth(text, text.length(), false);
|
| 324 | }
|
| 325 |
|
| 326 | public double textHeight(boolean title) {
|
| 327 | return scale(textRenderer().getHeight() * (title ? TITLE_TEXT_SCALE : 1));
|
| 328 | }
|
| 329 |
|
| 330 | public double textHeight() {
|
| 331 | return textHeight(false);
|
| 332 | }
|
| 333 |
|
| 334 | public double pad() {
|
| 335 | return scale(6);
|
| 336 | }
|
| 337 |
|
| 338 | public WindowConfig getWindowConfig(String id) {
|
| 339 | WindowConfig config = windowConfigs.get(id);
|
| 340 | if (config != null) return config;
|
| 341 |
|
| 342 | config = new WindowConfig();
|
| 343 | windowConfigs.put(id, config);
|
| 344 | return config;
|
| 345 | }
|
| 346 |
|
| 347 | public void clearWindowConfigs() {
|
| 348 | windowConfigs.clear();
|
| 349 | }
|
| 350 |
|
| 351 | protected <T extends WWidget> T w(T widget) {
|
| 352 | widget.theme = this;
|
| 353 | return widget;
|
| 354 | }
|
| 355 |
|
| 356 | // Saving / Loading
|
| 357 |
|
| 358 | @Override
|
| 359 | public CompoundTag toTag() {
|
| 360 | CompoundTag tag = new CompoundTag();
|
| 361 |
|
| 362 | tag.putString("name", name);
|
| 363 | tag.put("settings", settings.toTag());
|
| 364 |
|
| 365 | CompoundTag configs = new CompoundTag();
|
| 366 | for (var entry : windowConfigs.entrySet()) {
|
| 367 | configs.put(entry.getKey(), entry.getValue().toTag());
|
| 368 | }
|
| 369 | tag.put("windowConfigs", configs);
|
| 370 |
|
| 371 | return tag;
|
| 372 | }
|
| 373 |
|
| 374 | @Override
|
| 375 | public GuiTheme fromTag(CompoundTag tag) {
|
| 376 | tag.getCompound("settings").ifPresent(settings::fromTag);
|
| 377 |
|
| 378 | tag.getCompound("windowConfigs").ifPresent(configs -> {
|
| 379 | for (String id : configs.keySet()) {
|
| 380 | windowConfigs.put(id, new WindowConfig().fromTag(configs.getCompound(id).get()));
|
| 381 | }
|
| 382 | });
|
| 383 |
|
| 384 | return this;
|
| 385 | }
|
| 386 | }
|
| 387 |
|