Commit 10a436e98aa90a7b587c28d72c81b2dbae8e6b23
1 parent
3e896077
LiteLoader 1.6.4_02 - experimental - added basic mod list gui and enable/disable mod functionality
Showing
9 changed files
with
1146 additions
and
11 deletions
java/com/mumfrey/liteloader/core/EnabledModsList.java
| ... | ... | @@ -40,6 +40,11 @@ public class EnabledModsList |
| 40 | 40 | private transient Boolean defaultEnabledValue = Boolean.TRUE; |
| 41 | 41 | private transient boolean allowSave = true; |
| 42 | 42 | |
| 43 | + /** | |
| 44 | + * JSON file containing the list of enabled/disabled mods by profile | |
| 45 | + */ | |
| 46 | + private transient File enabledModsFile = null; | |
| 47 | + | |
| 43 | 48 | private EnabledModsList() |
| 44 | 49 | { |
| 45 | 50 | // Private because we are always instanced by the static createFrom() method below |
| ... | ... | @@ -151,6 +156,7 @@ public class EnabledModsList |
| 151 | 156 | { |
| 152 | 157 | reader = new FileReader(file); |
| 153 | 158 | EnabledModsList instance = gson.fromJson(reader, EnabledModsList.class); |
| 159 | + instance.setEnabledModsFile(file); | |
| 154 | 160 | return instance; |
| 155 | 161 | } |
| 156 | 162 | catch (Exception ex) |
| ... | ... | @@ -171,7 +177,9 @@ public class EnabledModsList |
| 171 | 177 | } |
| 172 | 178 | } |
| 173 | 179 | |
| 174 | - return new EnabledModsList(); | |
| 180 | + EnabledModsList instance = new EnabledModsList(); | |
| 181 | + instance.setEnabledModsFile(file); | |
| 182 | + return instance; | |
| 175 | 183 | } |
| 176 | 184 | |
| 177 | 185 | /** |
| ... | ... | @@ -207,4 +215,33 @@ public class EnabledModsList |
| 207 | 215 | } |
| 208 | 216 | } |
| 209 | 217 | } |
| 218 | + | |
| 219 | + /** | |
| 220 | + * Save to the file we were loaded from | |
| 221 | + */ | |
| 222 | + public void save() | |
| 223 | + { | |
| 224 | + if (this.enabledModsFile != null) | |
| 225 | + { | |
| 226 | + this.saveTo(this.enabledModsFile); | |
| 227 | + } | |
| 228 | + } | |
| 229 | + | |
| 230 | + /** | |
| 231 | + * Get whether saving this list is allowed | |
| 232 | + */ | |
| 233 | + public boolean saveAllowed() | |
| 234 | + { | |
| 235 | + return this.allowSave; | |
| 236 | + } | |
| 237 | + | |
| 238 | + public File getEnabledModsFile() | |
| 239 | + { | |
| 240 | + return this.enabledModsFile; | |
| 241 | + } | |
| 242 | + | |
| 243 | + public void setEnabledModsFile(File enabledModsFile) | |
| 244 | + { | |
| 245 | + this.enabledModsFile = enabledModsFile; | |
| 246 | + } | |
| 210 | 247 | } | ... | ... |
java/com/mumfrey/liteloader/core/Events.java
| ... | ... | @@ -3,6 +3,8 @@ package com.mumfrey.liteloader.core; |
| 3 | 3 | import java.util.LinkedList; |
| 4 | 4 | import java.util.logging.Level; |
| 5 | 5 | |
| 6 | +import org.lwjgl.input.Mouse; | |
| 7 | + | |
| 6 | 8 | import net.minecraft.src.*; |
| 7 | 9 | |
| 8 | 10 | import com.mumfrey.liteloader.*; |
| ... | ... | @@ -223,7 +225,6 @@ public class Events implements IPlayerUsage |
| 223 | 225 | this.pluginChannels.addPluginChannelListener((PluginChannelListener)listener); |
| 224 | 226 | } |
| 225 | 227 | } |
| 226 | - | |
| 227 | 228 | |
| 228 | 229 | /** |
| 229 | 230 | * Initialise mod hooks |
| ... | ... | @@ -448,6 +449,10 @@ public class Events implements IPlayerUsage |
| 448 | 449 | */ |
| 449 | 450 | public void onRender() |
| 450 | 451 | { |
| 452 | + this.currentResolution = new ScaledResolution(this.minecraft.gameSettings, this.minecraft.displayWidth, this.minecraft.displayHeight); | |
| 453 | + this.screenWidth = this.currentResolution.getScaledWidth(); | |
| 454 | + this.screenHeight = this.currentResolution.getScaledHeight(); | |
| 455 | + | |
| 451 | 456 | this.loader.onRender(); |
| 452 | 457 | |
| 453 | 458 | for (RenderListener renderListener : this.renderListeners) |
| ... | ... | @@ -521,10 +526,6 @@ public class Events implements IPlayerUsage |
| 521 | 526 | */ |
| 522 | 527 | public void onRenderHUD() |
| 523 | 528 | { |
| 524 | - this.currentResolution = new ScaledResolution(this.minecraft.gameSettings, this.minecraft.displayWidth, this.minecraft.displayHeight); | |
| 525 | - this.screenWidth = this.currentResolution.getScaledWidth(); | |
| 526 | - this.screenHeight = this.currentResolution.getScaledHeight(); | |
| 527 | - | |
| 528 | 529 | if (!this.minecraft.gameSettings.hideGUI || this.minecraft.currentScreen != null) |
| 529 | 530 | { |
| 530 | 531 | for (HUDRenderListener hudRenderListener : this.hudRenderListeners) |
| ... | ... | @@ -583,6 +584,10 @@ public class Events implements IPlayerUsage |
| 583 | 584 | { |
| 584 | 585 | this.loader.onTick(partialTicks, inGame); |
| 585 | 586 | } |
| 587 | + | |
| 588 | + int mouseX = Mouse.getX() * this.screenWidth / this.minecraft.displayWidth; | |
| 589 | + int mouseY = this.screenHeight - Mouse.getY() * this.screenHeight / this.minecraft.displayHeight - 1; | |
| 590 | + this.loader.postRender(mouseX, mouseY, partialTicks); | |
| 586 | 591 | |
| 587 | 592 | // Iterate tickable mods |
| 588 | 593 | for (Tickable tickable : this.tickListeners) | ... | ... |
java/com/mumfrey/liteloader/core/LiteLoader.java
| ... | ... | @@ -19,9 +19,12 @@ import java.util.logging.Logger; |
| 19 | 19 | |
| 20 | 20 | import javax.activity.InvalidActivityException; |
| 21 | 21 | |
| 22 | +import org.lwjgl.input.Keyboard; | |
| 23 | + | |
| 22 | 24 | import net.minecraft.launchwrapper.LaunchClassLoader; |
| 23 | 25 | import net.minecraft.src.CrashReport; |
| 24 | 26 | import net.minecraft.src.GuiControls; |
| 27 | +import net.minecraft.src.GuiMainMenu; | |
| 25 | 28 | import net.minecraft.src.GuiScreen; |
| 26 | 29 | import net.minecraft.src.KeyBinding; |
| 27 | 30 | import net.minecraft.src.Minecraft; |
| ... | ... | @@ -35,6 +38,7 @@ import com.mumfrey.liteloader.*; |
| 35 | 38 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderBrand; |
| 36 | 39 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderMods; |
| 37 | 40 | import com.mumfrey.liteloader.gui.GuiControlsPaginated; |
| 41 | +import com.mumfrey.liteloader.gui.GuiScreenModInfo; | |
| 38 | 42 | import com.mumfrey.liteloader.permissions.PermissionsManagerClient; |
| 39 | 43 | import com.mumfrey.liteloader.util.PrivateFields; |
| 40 | 44 | |
| ... | ... | @@ -196,6 +200,23 @@ public final class LiteLoader |
| 196 | 200 | private Map<KeyBinding, Integer> storedModKeyBindings = new HashMap<KeyBinding, Integer>(); |
| 197 | 201 | |
| 198 | 202 | /** |
| 203 | + * Setting which determines whether we show the "mod info" screen tab in the main menu | |
| 204 | + */ | |
| 205 | + private boolean displayModInfoScreenTab = true; | |
| 206 | + | |
| 207 | + /** | |
| 208 | + * Override for the "mod info" tab setting, so that mods which want to handle the mod info themselves | |
| 209 | + * can temporarily disable the function without having to change the underlying property | |
| 210 | + */ | |
| 211 | + private boolean hideModInfoScreenTab = false; | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * Active "mod info" screen, drawn as an overlay when in the main menu and made the active screen if | |
| 215 | + * the user clicks the tab | |
| 216 | + */ | |
| 217 | + private GuiScreenModInfo modInfoScreen; | |
| 218 | + | |
| 219 | + /** | |
| 199 | 220 | * Pre-init routine, called using reflection by the tweaker |
| 200 | 221 | * |
| 201 | 222 | * @param gameDirectory Game directory passed to the tweaker |
| ... | ... | @@ -295,6 +316,7 @@ public final class LiteLoader |
| 295 | 316 | |
| 296 | 317 | this.paginateControls = this.bootstrap.getAndStoreBooleanProperty("controls.pages", true); |
| 297 | 318 | this.inhibitSoundManagerReload = this.bootstrap.getAndStoreBooleanProperty("soundManagerFix", true); |
| 319 | + this.displayModInfoScreenTab = this.bootstrap.getAndStoreBooleanProperty("modInfoScreen", true); | |
| 298 | 320 | |
| 299 | 321 | this.enumerator.discoverModClasses(); |
| 300 | 322 | } |
| ... | ... | @@ -328,7 +350,7 @@ public final class LiteLoader |
| 328 | 350 | this.events.initHooks(); |
| 329 | 351 | this.startupComplete = true; |
| 330 | 352 | |
| 331 | - this.enabledModsList.saveTo(this.enabledModsFile); | |
| 353 | + this.enabledModsList.save(); | |
| 332 | 354 | this.bootstrap.writeProperties(); |
| 333 | 355 | } |
| 334 | 356 | |
| ... | ... | @@ -880,6 +902,33 @@ public final class LiteLoader |
| 880 | 902 | } |
| 881 | 903 | } |
| 882 | 904 | } |
| 905 | + | |
| 906 | + /** | |
| 907 | + * @param partialTicks | |
| 908 | + */ | |
| 909 | + void postRender(int mouseX, int mouseY, float partialTicks) | |
| 910 | + { | |
| 911 | + if (this.minecraft.currentScreen instanceof GuiMainMenu && this.displayModInfoScreenTab && !this.hideModInfoScreenTab) | |
| 912 | + { | |
| 913 | + // If we're at the main menu, prepare the overlay | |
| 914 | + if (this.modInfoScreen == null || this.modInfoScreen.getMenu() != this.minecraft.currentScreen) | |
| 915 | + { | |
| 916 | + this.modInfoScreen = new GuiScreenModInfo(this.minecraft, (GuiMainMenu)this.minecraft.currentScreen, this, this.enabledModsList); | |
| 917 | + } | |
| 918 | + | |
| 919 | + this.modInfoScreen.drawScreen(mouseX, mouseY, partialTicks); | |
| 920 | + } | |
| 921 | + else if (this.minecraft.currentScreen != this.modInfoScreen && this.modInfoScreen != null) | |
| 922 | + { | |
| 923 | + // If we're in any other screen, kill the overlay | |
| 924 | + this.modInfoScreen.release(); | |
| 925 | + this.modInfoScreen = null; | |
| 926 | + } | |
| 927 | + else if (this.minecraft.currentScreen instanceof GuiMainMenu && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && Keyboard.isKeyDown(Keyboard.KEY_TAB)) | |
| 928 | + { | |
| 929 | + this.minecraft.displayGuiScreen(new GuiScreenModInfo(this.minecraft, (GuiMainMenu)this.minecraft.currentScreen, this, this.enabledModsList)); | |
| 930 | + } | |
| 931 | + } | |
| 883 | 932 | |
| 884 | 933 | /** |
| 885 | 934 | * @param partialTicks |
| ... | ... | @@ -891,6 +940,11 @@ public final class LiteLoader |
| 891 | 940 | this.permissionsManager.onTick(this.minecraft, partialTicks, inGame); |
| 892 | 941 | |
| 893 | 942 | this.checkAndStoreKeyBindings(); |
| 943 | + | |
| 944 | + if (this.modInfoScreen != null && this.minecraft.currentScreen != this.modInfoScreen) | |
| 945 | + { | |
| 946 | + this.modInfoScreen.updateScreen(); | |
| 947 | + } | |
| 894 | 948 | } |
| 895 | 949 | |
| 896 | 950 | /** |
| ... | ... | @@ -963,16 +1017,40 @@ public final class LiteLoader |
| 963 | 1017 | } |
| 964 | 1018 | catch (IOException ex) {} |
| 965 | 1019 | } |
| 966 | - | |
| 1020 | + | |
| 1021 | + /** | |
| 1022 | + * Set the "mod info" screen tab to hidden, regardless of the property setting | |
| 1023 | + */ | |
| 1024 | + public void hideModInfoScreenTab() | |
| 1025 | + { | |
| 1026 | + this.hideModInfoScreenTab = true; | |
| 1027 | + } | |
| 1028 | + | |
| 1029 | + /** | |
| 1030 | + * Set whether the "mod info" screen tab should be shown in the main menu | |
| 1031 | + */ | |
| 1032 | + public void setDisplayModInfoScreenTab(boolean show) | |
| 1033 | + { | |
| 1034 | + this.displayModInfoScreenTab = show; | |
| 1035 | + this.bootstrap.setBooleanProperty("modInfoScreen", show); | |
| 1036 | + this.bootstrap.writeProperties(); | |
| 1037 | + } | |
| 1038 | + | |
| 1039 | + /** | |
| 1040 | + * Get whether the "mod info" screen tab is shown in the main menu | |
| 1041 | + */ | |
| 1042 | + public boolean getDisplayModInfoScreenTab() | |
| 1043 | + { | |
| 1044 | + return this.displayModInfoScreenTab; | |
| 1045 | + } | |
| 1046 | + | |
| 967 | 1047 | private static void logInfo(String string, Object... args) |
| 968 | 1048 | { |
| 969 | -// System.out.println("<INFO> " + String.format(string, args)); | |
| 970 | 1049 | LiteLoader.logger.info(String.format(string, args)); |
| 971 | 1050 | } |
| 972 | 1051 | |
| 973 | 1052 | private static void logWarning(String string, Object... args) |
| 974 | 1053 | { |
| 975 | -// System.out.println("<WARN> " + String.format(string, args)); | |
| 976 | 1054 | LiteLoader.logger.warning(String.format(string, args)); |
| 977 | 1055 | } |
| 978 | 1056 | ... | ... |
java/com/mumfrey/liteloader/core/LiteLoaderBootstrap.java
| ... | ... | @@ -40,7 +40,7 @@ class LiteLoaderBootstrap implements ILoaderBootstrap |
| 40 | 40 | /** |
| 41 | 41 | * Liteloader version |
| 42 | 42 | */ |
| 43 | - public static final LiteLoaderVersion VERSION = LiteLoaderVersion.MC_1_6_4_R1; | |
| 43 | + public static final LiteLoaderVersion VERSION = LiteLoaderVersion.MC_1_6_4_R2; | |
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Local logger reference | ... | ... |
java/com/mumfrey/liteloader/gui/GuiCheckbox.java
0 → 100644
| 1 | +package com.mumfrey.liteloader.gui; | |
| 2 | + | |
| 3 | +import static org.lwjgl.opengl.GL11.*; | |
| 4 | + | |
| 5 | +import net.minecraft.src.GuiButton; | |
| 6 | +import net.minecraft.src.Minecraft; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Super-simple implementation of a checkbox control | |
| 10 | + * | |
| 11 | + * @author Adam Mummery-Smith | |
| 12 | + */ | |
| 13 | +public class GuiCheckbox extends GuiButton | |
| 14 | +{ | |
| 15 | + public boolean checked; | |
| 16 | + | |
| 17 | + public GuiCheckbox(int controlId, int xPosition, int yPosition, String displayString) | |
| 18 | + { | |
| 19 | + super(controlId, xPosition, yPosition, 200, 12, displayString); | |
| 20 | + } | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public void drawButton(Minecraft minecraft, int mouseX, int mouseY) | |
| 24 | + { | |
| 25 | + if (this.drawButton) | |
| 26 | + { | |
| 27 | + minecraft.getTextureManager().bindTexture(GuiScreenModInfo.aboutTextureResource); | |
| 28 | + glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | |
| 29 | + this.field_82253_i = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; | |
| 30 | + | |
| 31 | + this.drawTexturedModalRect(this.xPosition, this.yPosition, this.checked ? 134 : 122, 80, 12, 12); | |
| 32 | + this.mouseDragged(minecraft, mouseX, mouseY); | |
| 33 | + | |
| 34 | + int colour = 0xE0E0E0; | |
| 35 | + if (!this.enabled) colour = 0xA0A0A0; | |
| 36 | + else if (this.field_82253_i) colour = 0xFFFFA0; | |
| 37 | + | |
| 38 | + this.drawString(minecraft.fontRenderer, this.displayString, this.xPosition + 16, this.yPosition + 2, colour); | |
| 39 | + } | |
| 40 | + } | |
| 41 | +} | ... | ... |
java/com/mumfrey/liteloader/gui/GuiModListEntry.java
0 → 100644
| 1 | +package com.mumfrey.liteloader.gui; | |
| 2 | + | |
| 3 | +import com.mumfrey.liteloader.LiteMod; | |
| 4 | +import com.mumfrey.liteloader.core.ClassPathMod; | |
| 5 | +import com.mumfrey.liteloader.core.EnabledModsList; | |
| 6 | +import com.mumfrey.liteloader.core.LiteLoader; | |
| 7 | +import com.mumfrey.liteloader.core.ModFile; | |
| 8 | + | |
| 9 | +import net.minecraft.src.FontRenderer; | |
| 10 | +import net.minecraft.src.Gui; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Represents a mod in the mod info screen, keeps track of mod information and provides methods | |
| 14 | + * for displaying the mod in the mod list and drawing the selected mod info | |
| 15 | + * | |
| 16 | + * @author Adam Mummery-Smith | |
| 17 | + */ | |
| 18 | +public class GuiModListEntry extends Gui | |
| 19 | +{ | |
| 20 | + private static final int PANEL_HEIGHT = 32; | |
| 21 | + private static final int PANEL_SPACING = 4; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Enabled mods list, keep a reference so that we can toggle mod enablement when required | |
| 25 | + */ | |
| 26 | + private EnabledModsList enabledModsList; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * For text display | |
| 30 | + */ | |
| 31 | + private FontRenderer fontRenderer; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * The metadata name (id) of the mod, used as the enablement/disablement key | |
| 35 | + */ | |
| 36 | + private String metaName; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Display name of the mod, disabled mods use the file/folder name | |
| 40 | + */ | |
| 41 | + private String name; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Mod version string | |
| 45 | + */ | |
| 46 | + private String version; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Mod author, from the metadata | |
| 50 | + */ | |
| 51 | + private String author; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Mod URL, from the metadata | |
| 55 | + */ | |
| 56 | + private String url; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Mod description, from metadata | |
| 60 | + */ | |
| 61 | + private String description; | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Whether the mod is currently active | |
| 65 | + */ | |
| 66 | + private boolean enabled; | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Whether the mod can be toggled, not all mods support this, eg. internal mods | |
| 70 | + */ | |
| 71 | + private boolean canBeToggled; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Whether the mod WILL be enabled on the next startup, if the mod is active and has been disabled this | |
| 75 | + * will be false, and if it's currently disabled by has been toggled then it will be true | |
| 76 | + */ | |
| 77 | + private boolean willBeEnabled; | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * True if the mouse was over this mod on the last render | |
| 81 | + */ | |
| 82 | + private boolean mouseOver; | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Mod list entry for an ACTIVE mod | |
| 86 | + * | |
| 87 | + * @param loader | |
| 88 | + * @param enabledMods | |
| 89 | + * @param fontRenderer | |
| 90 | + * @param mod | |
| 91 | + */ | |
| 92 | + GuiModListEntry(LiteLoader loader, EnabledModsList enabledMods, FontRenderer fontRenderer, LiteMod mod) | |
| 93 | + { | |
| 94 | + this.enabledModsList = enabledMods; | |
| 95 | + this.fontRenderer = fontRenderer; | |
| 96 | + this.metaName = loader.getModMetaName(mod.getClass()); | |
| 97 | + this.name = mod.getName(); | |
| 98 | + this.version = mod.getVersion(); | |
| 99 | + this.author = loader.getModMetaData(mod.getClass(), "author", "Unknown"); | |
| 100 | + this.url = loader.getModMetaData(mod.getClass(), "url", null); | |
| 101 | + this.description = loader.getModMetaData(mod.getClass(), "description", ""); | |
| 102 | + this.enabled = true; | |
| 103 | + this.canBeToggled = this.metaName != null && this.enabledModsList.saveAllowed(); | |
| 104 | + this.willBeEnabled = true; | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Mod list entry for a currently disabled mod | |
| 109 | + * | |
| 110 | + * @param loader | |
| 111 | + * @param enabledMods | |
| 112 | + * @param fontRenderer | |
| 113 | + * @param file | |
| 114 | + */ | |
| 115 | + GuiModListEntry(LiteLoader loader, EnabledModsList enabledMods, FontRenderer fontRenderer, ModFile file) | |
| 116 | + { | |
| 117 | + this.enabledModsList = enabledMods; | |
| 118 | + this.fontRenderer = fontRenderer; | |
| 119 | + this.metaName = file.getModName().toLowerCase(); | |
| 120 | + this.name = file instanceof ClassPathMod ? file.getModName() : file.getName(); | |
| 121 | + this.version = file.getVersion(); | |
| 122 | + this.author = file.getMetaValue("author", "Unknown"); | |
| 123 | + this.url = file.getMetaValue("url", null); | |
| 124 | + this.description = file.getMetaValue("description", ""); | |
| 125 | + this.enabled = false; | |
| 126 | + this.canBeToggled = this.enabledModsList.saveAllowed(); | |
| 127 | + this.willBeEnabled = enabledMods.isEnabled(loader.getProfile(), this.metaName); | |
| 128 | + } | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Draw this list entry as a list item | |
| 132 | + * | |
| 133 | + * @param mouseX | |
| 134 | + * @param mouseY | |
| 135 | + * @param partialTicks | |
| 136 | + * @param xPosition | |
| 137 | + * @param yPosition | |
| 138 | + * @param width | |
| 139 | + * @param selected | |
| 140 | + * @return | |
| 141 | + */ | |
| 142 | + public int drawListEntry(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width, boolean selected) | |
| 143 | + { | |
| 144 | + int colour1 = selected ? 0xB04785D1 : 0xB0000000; | |
| 145 | + drawGradientRect(xPosition, yPosition, xPosition + width, yPosition + PANEL_HEIGHT, colour1, 0xB0333333); | |
| 146 | + | |
| 147 | + this.fontRenderer.drawString(this.name, xPosition + 5, yPosition + 2, this.enabled ? 0xFFFFFFFF : 0xFF999999); | |
| 148 | + this.fontRenderer.drawString("Version " + this.version, xPosition + 5, yPosition + 12, 0xFF999999); | |
| 149 | + | |
| 150 | + String status = "Active"; | |
| 151 | + | |
| 152 | + if (this.canBeToggled) | |
| 153 | + { | |
| 154 | + if (!this.enabled && !this.willBeEnabled) status = "\2477Disabled"; | |
| 155 | + if (!this.enabled && this.willBeEnabled) status = "\247aEnabled on next startup"; | |
| 156 | + if ( this.enabled && !this.willBeEnabled) status = "\247cDisabled on next startup"; | |
| 157 | + } | |
| 158 | + | |
| 159 | + this.fontRenderer.drawString(status, xPosition + 5, yPosition + 22, 0xFF4785D1); | |
| 160 | + | |
| 161 | + this.mouseOver = mouseX > xPosition && mouseX < xPosition + width && mouseY > yPosition && mouseY < yPosition + PANEL_HEIGHT; | |
| 162 | + drawRect(xPosition, yPosition, xPosition + 1, yPosition + PANEL_HEIGHT, this.mouseOver ? 0xFFFFFFFF : 0xFF999999); | |
| 163 | + | |
| 164 | + return PANEL_HEIGHT + PANEL_SPACING; | |
| 165 | + } | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Draw this entry as the info page | |
| 169 | + * | |
| 170 | + * @param mouseX | |
| 171 | + * @param mouseY | |
| 172 | + * @param partialTicks | |
| 173 | + * @param xPosition | |
| 174 | + * @param yPosition | |
| 175 | + * @param width | |
| 176 | + */ | |
| 177 | + public void drawInfo(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width) | |
| 178 | + { | |
| 179 | + yPosition += 2; | |
| 180 | + | |
| 181 | + this.fontRenderer.drawString(this.name, xPosition + 5, yPosition, 0xFFFFFFFF); yPosition += 10; | |
| 182 | + this.fontRenderer.drawString("Version " + this.version, xPosition + 5, yPosition, 0xFF999999); yPosition += 10; | |
| 183 | + | |
| 184 | + drawRect(xPosition + 5, yPosition, xPosition + width, yPosition + 1, 0xFF999999); yPosition += 4; | |
| 185 | + | |
| 186 | + this.fontRenderer.drawString("Authors: \2477" + this.author, xPosition + 5, yPosition, 0xFFFFFFFF); yPosition += 10; | |
| 187 | + if (this.url != null) | |
| 188 | + { | |
| 189 | + this.fontRenderer.drawString(this.url, xPosition + 5, yPosition, 0xB04785D1); yPosition += 10; | |
| 190 | + } | |
| 191 | + | |
| 192 | + drawRect(xPosition + 5, yPosition, xPosition + width, yPosition + 1, 0xFF999999); yPosition += 4; | |
| 193 | + | |
| 194 | + this.fontRenderer.drawSplitString(this.description, xPosition + 5, yPosition, width - 5, 0xFFFFFFFF); | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * Toggle the enablement status of this mod, if supported | |
| 199 | + */ | |
| 200 | + public void toggleEnabled() | |
| 201 | + { | |
| 202 | + if (this.canBeToggled) | |
| 203 | + { | |
| 204 | + this.willBeEnabled = !this.willBeEnabled; | |
| 205 | + this.enabledModsList.setEnabled(LiteLoader.getProfile(), this.metaName, this.willBeEnabled); | |
| 206 | + this.enabledModsList.save(); | |
| 207 | + } | |
| 208 | + } | |
| 209 | + | |
| 210 | + public String getKey() | |
| 211 | + { | |
| 212 | + return this.metaName + Integer.toHexString(this.hashCode()); | |
| 213 | + } | |
| 214 | + | |
| 215 | + public String getName() | |
| 216 | + { | |
| 217 | + return this.name; | |
| 218 | + } | |
| 219 | + | |
| 220 | + public String getVersion() | |
| 221 | + { | |
| 222 | + return this.version; | |
| 223 | + } | |
| 224 | + | |
| 225 | + public String getAuthor() | |
| 226 | + { | |
| 227 | + return this.author; | |
| 228 | + } | |
| 229 | + | |
| 230 | + public String getDescription() | |
| 231 | + { | |
| 232 | + return this.description; | |
| 233 | + } | |
| 234 | + | |
| 235 | + public boolean isEnabled() | |
| 236 | + { | |
| 237 | + return this.enabled; | |
| 238 | + } | |
| 239 | + | |
| 240 | + public boolean canBeToggled() | |
| 241 | + { | |
| 242 | + return this.canBeToggled; | |
| 243 | + } | |
| 244 | + | |
| 245 | + public boolean willBeEnabled() | |
| 246 | + { | |
| 247 | + return this.willBeEnabled; | |
| 248 | + } | |
| 249 | + | |
| 250 | + public boolean mouseWasOver() | |
| 251 | + { | |
| 252 | + return this.mouseOver; | |
| 253 | + } | |
| 254 | +} | ... | ... |
java/com/mumfrey/liteloader/gui/GuiScreenModInfo.java
0 → 100644
| 1 | +package com.mumfrey.liteloader.gui; | |
| 2 | + | |
| 3 | +import static org.lwjgl.opengl.GL11.*; | |
| 4 | + | |
| 5 | +import java.awt.image.BufferedImage; | |
| 6 | +import java.nio.DoubleBuffer; | |
| 7 | +import java.util.ArrayList; | |
| 8 | +import java.util.List; | |
| 9 | +import java.util.Map; | |
| 10 | +import java.util.TreeMap; | |
| 11 | + | |
| 12 | +import javax.imageio.ImageIO; | |
| 13 | + | |
| 14 | +import org.lwjgl.BufferUtils; | |
| 15 | +import org.lwjgl.input.Keyboard; | |
| 16 | +import org.lwjgl.input.Mouse; | |
| 17 | + | |
| 18 | +import com.mumfrey.liteloader.LiteMod; | |
| 19 | +import com.mumfrey.liteloader.core.EnabledModsList; | |
| 20 | +import com.mumfrey.liteloader.core.LiteLoader; | |
| 21 | +import com.mumfrey.liteloader.core.ModFile; | |
| 22 | + | |
| 23 | +import net.minecraft.src.DynamicTexture; | |
| 24 | +import net.minecraft.src.GuiButton; | |
| 25 | +import net.minecraft.src.GuiMainMenu; | |
| 26 | +import net.minecraft.src.GuiScreen; | |
| 27 | +import net.minecraft.src.Minecraft; | |
| 28 | +import net.minecraft.src.ResourceLocation; | |
| 29 | +import net.minecraft.src.Tessellator; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * GUI screen which displays info about loaded mods and also allows them to be enabled and | |
| 33 | + * disabled. An instance of this class is created every time the main menu is displayed and is | |
| 34 | + * drawn as an overlay until the tab is clicked, at which point it becomes the active GUI screen | |
| 35 | + * and draws the parent main menu screen as its background to give the appearance of being | |
| 36 | + * overlaid on the main menu. | |
| 37 | + * | |
| 38 | + * @author Adam Mummery-Smith | |
| 39 | + */ | |
| 40 | +public class GuiScreenModInfo extends GuiScreen | |
| 41 | +{ | |
| 42 | + private static final int LEFT_EDGE = 80; | |
| 43 | + private static final int TAB_WIDTH = 20; | |
| 44 | + private static final int TAB_HEIGHT = 40; | |
| 45 | + private static final int TAB_TOP = 20; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Used for clipping | |
| 49 | + */ | |
| 50 | + private static DoubleBuffer doubleBuffer = BufferUtils.createByteBuffer(64).asDoubleBuffer(); | |
| 51 | + | |
| 52 | + public static ResourceLocation aboutTextureResource; | |
| 53 | + private static DynamicTexture aboutTexture; | |
| 54 | + | |
| 55 | + private GuiMainMenu mainMenu; | |
| 56 | + | |
| 57 | + private long tickNumber; | |
| 58 | + | |
| 59 | + private double lastTick; | |
| 60 | + | |
| 61 | + private double tweenAmount = 0.0, tweenRate = 0.08; | |
| 62 | + | |
| 63 | + private boolean mouseDown, toggled; | |
| 64 | + | |
| 65 | + private float tabOpacity = 0.0F; | |
| 66 | + | |
| 67 | + private List<GuiModListEntry> mods = new ArrayList<GuiModListEntry>(); | |
| 68 | + | |
| 69 | + private GuiModListEntry selectedMod = null; | |
| 70 | + | |
| 71 | + private String activeModText = "0 mod(s) loaded"; | |
| 72 | + | |
| 73 | + private int listHeight; | |
| 74 | + | |
| 75 | + private GuiSimpleScrollBar scrollBar = new GuiSimpleScrollBar(); | |
| 76 | + | |
| 77 | + private GuiButton btnToggle; | |
| 78 | + | |
| 79 | + private GuiCheckbox chkEnabled; | |
| 80 | + | |
| 81 | + public GuiScreenModInfo(Minecraft minecraft, GuiMainMenu mainMenu, LiteLoader loader, EnabledModsList enabledModsList) | |
| 82 | + { | |
| 83 | + this.mc = minecraft; | |
| 84 | + this.mainMenu = mainMenu; | |
| 85 | + | |
| 86 | + if (aboutTexture == null) | |
| 87 | + { | |
| 88 | + try | |
| 89 | + { | |
| 90 | + BufferedImage aboutImage = ImageIO.read(GuiScreenModInfo.class.getResourceAsStream("/assets/liteloader/textures/gui/about.png")); | |
| 91 | + aboutTexture = new DynamicTexture(aboutImage); | |
| 92 | + aboutTextureResource = minecraft.getTextureManager().getDynamicTextureLocation("about_assets", aboutTexture); | |
| 93 | + } | |
| 94 | + catch (Exception ex) {} | |
| 95 | + } | |
| 96 | + | |
| 97 | + this.enumerateMods(loader, enabledModsList); | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Populate the mods list | |
| 102 | + * | |
| 103 | + * @param loader | |
| 104 | + * @param enabledModsList | |
| 105 | + */ | |
| 106 | + private void enumerateMods(LiteLoader loader, EnabledModsList enabledModsList) | |
| 107 | + { | |
| 108 | + this.activeModText = String.format("%d mod(s) loaded", loader.getLoadedMods().size()); | |
| 109 | + | |
| 110 | + Map<String, GuiModListEntry> sortedMods = new TreeMap<String, GuiModListEntry>(); | |
| 111 | + | |
| 112 | + for (LiteMod mod : loader.getLoadedMods()) | |
| 113 | + { | |
| 114 | + GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, mod); | |
| 115 | + sortedMods.put(modListEntry.getKey(), modListEntry); | |
| 116 | + } | |
| 117 | + | |
| 118 | + for (ModFile disabledMod : loader.getDisabledMods()) | |
| 119 | + { | |
| 120 | + GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, disabledMod); | |
| 121 | + sortedMods.put(modListEntry.getKey(), modListEntry); | |
| 122 | + } | |
| 123 | + | |
| 124 | + this.mods.addAll(sortedMods.values()); | |
| 125 | + | |
| 126 | + if (this.mods.size() > 0) | |
| 127 | + { | |
| 128 | + this.selectedMod = this.mods.get(0); | |
| 129 | + } | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * Release references prior to being disposed | |
| 134 | + */ | |
| 135 | + public void release() | |
| 136 | + { | |
| 137 | + this.mainMenu = null; | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * Get the parent menu | |
| 142 | + */ | |
| 143 | + public GuiMainMenu getMenu() | |
| 144 | + { | |
| 145 | + return this.mainMenu; | |
| 146 | + } | |
| 147 | + | |
| 148 | + /* (non-Javadoc) | |
| 149 | + * @see net.minecraft.src.GuiScreen#initGui() | |
| 150 | + */ | |
| 151 | + @SuppressWarnings("unchecked") | |
| 152 | + @Override | |
| 153 | + public void initGui() | |
| 154 | + { | |
| 155 | + int left = LEFT_EDGE + 16 + (this.width - LEFT_EDGE - 28) / 2; | |
| 156 | + | |
| 157 | + this.buttonList.clear(); | |
| 158 | + this.buttonList.add(this.btnToggle = new GuiButton(0, left, this.height - 50, 100, 20, "Enable mod")); | |
| 159 | + this.buttonList.add(this.chkEnabled = new GuiCheckbox(1, LEFT_EDGE + 12, this.height - 17, "Show LiteLoader tab on main menu")); | |
| 160 | + | |
| 161 | + this.selectMod(this.selectedMod); | |
| 162 | + } | |
| 163 | + | |
| 164 | + /* (non-Javadoc) | |
| 165 | + * @see net.minecraft.src.GuiScreen#setWorldAndResolution(net.minecraft.src.Minecraft, int, int) | |
| 166 | + */ | |
| 167 | + @Override | |
| 168 | + public void setWorldAndResolution(Minecraft minecraft, int width, int height) | |
| 169 | + { | |
| 170 | + if (this.mc.currentScreen == this) | |
| 171 | + { | |
| 172 | + // Set res in parent screen if we are the active GUI | |
| 173 | + this.mainMenu.setWorldAndResolution(minecraft, width, height); | |
| 174 | + } | |
| 175 | + | |
| 176 | + super.setWorldAndResolution(minecraft, width, height); | |
| 177 | + } | |
| 178 | + | |
| 179 | + /* (non-Javadoc) | |
| 180 | + * @see net.minecraft.src.GuiScreen#updateScreen() | |
| 181 | + */ | |
| 182 | + @Override | |
| 183 | + public void updateScreen() | |
| 184 | + { | |
| 185 | + this.tickNumber++; | |
| 186 | + | |
| 187 | + if (this.mc.currentScreen == this) | |
| 188 | + { | |
| 189 | + this.mainMenu.updateScreen(); | |
| 190 | + this.chkEnabled.checked = LiteLoader.getInstance().getDisplayModInfoScreenTab(); | |
| 191 | + } | |
| 192 | + | |
| 193 | + if (this.toggled) | |
| 194 | + { | |
| 195 | + this.onToggled(); | |
| 196 | + } | |
| 197 | + } | |
| 198 | + | |
| 199 | + /* (non-Javadoc) | |
| 200 | + * @see net.minecraft.src.GuiScreen#drawScreen(int, int, float) | |
| 201 | + */ | |
| 202 | + @Override | |
| 203 | + public void drawScreen(int mouseX, int mouseY, float partialTicks) | |
| 204 | + { | |
| 205 | + boolean active = this.mc.currentScreen == this; | |
| 206 | + | |
| 207 | + this.width = this.mainMenu.width; | |
| 208 | + this.height = this.mainMenu.height; | |
| 209 | + | |
| 210 | + if (active) | |
| 211 | + { | |
| 212 | + glClear(GL_DEPTH_BUFFER_BIT); | |
| 213 | + this.mainMenu.drawScreen(-10, -10, partialTicks); | |
| 214 | + glClear(GL_DEPTH_BUFFER_BIT); | |
| 215 | + } | |
| 216 | + | |
| 217 | + float xOffset = (this.width - LEFT_EDGE) * this.calcTween(partialTicks, active) + 16.0F + (this.tabOpacity * -32.0F); | |
| 218 | + mouseX -= (int)xOffset; | |
| 219 | + | |
| 220 | + boolean mouseOverTab = mouseX > LEFT_EDGE - TAB_WIDTH && mouseX < LEFT_EDGE && mouseY > TAB_TOP && mouseY < TAB_TOP + TAB_HEIGHT; | |
| 221 | + this.handleMouseClick(mouseX, mouseY, partialTicks, active, mouseOverTab); | |
| 222 | + | |
| 223 | + this.tabOpacity = mouseOverTab || this.tweenAmount > 0.0 ? 0.5F : Math.max(0.0F, this.tabOpacity - partialTicks * 0.1F); | |
| 224 | + this.drawPanel(mouseX, mouseY, partialTicks, active, xOffset); | |
| 225 | + } | |
| 226 | + | |
| 227 | + /** | |
| 228 | + * @param mouseX | |
| 229 | + * @param mouseY | |
| 230 | + * @param partialTicks | |
| 231 | + * @param active | |
| 232 | + * @param xOffset | |
| 233 | + */ | |
| 234 | + private void drawPanel(int mouseX, int mouseY, float partialTicks, boolean active, float xOffset) | |
| 235 | + { | |
| 236 | + glPushMatrix(); | |
| 237 | + glTranslatef(xOffset, 0.0F, 0.0F); | |
| 238 | + | |
| 239 | + drawRect(LEFT_EDGE, 0, this.width, this.height, 0xB0000000); | |
| 240 | + drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, 0xFFFFFFFF); | |
| 241 | + drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, 0xFFFFFFFF); | |
| 242 | + | |
| 243 | + this.mc.getTextureManager().bindTexture(aboutTextureResource); | |
| 244 | + glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH, TAB_TOP, TAB_WIDTH + 1, TAB_HEIGHT, 80, 80, 122, 160, 0.5F + this.tabOpacity); | |
| 245 | + | |
| 246 | + if (this.tweenAmount > 0.0) | |
| 247 | + { | |
| 248 | + glDrawTexturedRect(LEFT_EDGE + 12, 12, 128, 40, 0, 0, 256, 80, 1.0F); | |
| 249 | + glDrawTexturedRect(this.width - 32 - 12, 12, 32, 45, 0, 80, 64, 170, 1.0F); | |
| 250 | + | |
| 251 | + this.fontRenderer.drawString("Version " + LiteLoader.getVersion(), LEFT_EDGE + 12 + 38, 50, 0xFFFFFFFF); | |
| 252 | + this.fontRenderer.drawString(this.activeModText, LEFT_EDGE + 12 + 38, 60, 0xFFAAAAAA); | |
| 253 | + | |
| 254 | + drawRect(LEFT_EDGE + 12, 80, this.width - 12, 81, 0xFF999999); | |
| 255 | + drawRect(LEFT_EDGE + 12, this.height - 24, this.width - 12, this.height - 23, 0xFF999999); | |
| 256 | + | |
| 257 | + int panelTop = 83; | |
| 258 | + int innerWidth = this.width - LEFT_EDGE - 24 - 4; | |
| 259 | + int listWidth = innerWidth / 2; | |
| 260 | + | |
| 261 | + this.drawModsList(mouseX, mouseY, partialTicks, panelTop, listWidth); | |
| 262 | + this.drawSelectedMod(mouseX, mouseY, partialTicks, panelTop, listWidth); | |
| 263 | + | |
| 264 | + super.drawScreen(mouseX, mouseY, partialTicks); | |
| 265 | + } | |
| 266 | + | |
| 267 | + glPopMatrix(); | |
| 268 | + } | |
| 269 | + | |
| 270 | + /** | |
| 271 | + * @param mouseX | |
| 272 | + * @param mouseY | |
| 273 | + * @param partialTicks | |
| 274 | + * @param panelWidth | |
| 275 | + */ | |
| 276 | + public void drawModsList(int mouseX, int mouseY, float partialTicks, int panelTop, int panelWidth) | |
| 277 | + { | |
| 278 | + int panelHeight = this.height - 26 - panelTop; | |
| 279 | + this.scrollBar.drawScrollBar(mouseX, mouseY, partialTicks, LEFT_EDGE + 12 + panelWidth - 5, panelTop, 5, panelHeight, this.listHeight); | |
| 280 | + | |
| 281 | + glEnableClipping(LEFT_EDGE + 12, LEFT_EDGE + 12 + panelWidth - 6, panelTop, this.height - 26); | |
| 282 | + | |
| 283 | + glPushMatrix(); | |
| 284 | + glTranslatef(0.0F, panelTop - this.scrollBar.getValue(), 0.0F); | |
| 285 | + | |
| 286 | + mouseY -= (panelTop - this.scrollBar.getValue()); | |
| 287 | + | |
| 288 | + int yPos = 0; | |
| 289 | + for (GuiModListEntry mod : this.mods) | |
| 290 | + { | |
| 291 | + yPos += mod.drawListEntry(mouseX, mouseY, partialTicks, LEFT_EDGE + 12, yPos, panelWidth - 6, mod == this.selectedMod); | |
| 292 | + } | |
| 293 | + | |
| 294 | + glPopMatrix(); | |
| 295 | + glDisableClipping(); | |
| 296 | + | |
| 297 | + this.listHeight = yPos; | |
| 298 | + this.scrollBar.setMaxValue(this.listHeight - panelHeight); | |
| 299 | + } | |
| 300 | + | |
| 301 | + /** | |
| 302 | + * @param mouseX | |
| 303 | + * @param mouseY | |
| 304 | + * @param partialTicks | |
| 305 | + * @param panelTop | |
| 306 | + * @param listWidth | |
| 307 | + */ | |
| 308 | + public void drawSelectedMod(int mouseX, int mouseY, float partialTicks, int panelTop, int listWidth) | |
| 309 | + { | |
| 310 | + if (this.selectedMod != null) | |
| 311 | + { | |
| 312 | + int left = LEFT_EDGE + 12 + listWidth; | |
| 313 | + int right = this.width - 12; | |
| 314 | + | |
| 315 | + glEnableClipping(left, right, panelTop, this.height - 54); | |
| 316 | + this.selectedMod.drawInfo(mouseX, mouseY, partialTicks, left, panelTop, right - left); | |
| 317 | + glDisableClipping(); | |
| 318 | + } | |
| 319 | + } | |
| 320 | + | |
| 321 | + /** | |
| 322 | + * @param mod | |
| 323 | + * @return | |
| 324 | + */ | |
| 325 | + public void selectMod(GuiModListEntry mod) | |
| 326 | + { | |
| 327 | + this.selectedMod = mod; | |
| 328 | + this.btnToggle.drawButton = false; | |
| 329 | + | |
| 330 | + if (this.selectedMod != null && this.selectedMod.canBeToggled()) | |
| 331 | + { | |
| 332 | + this.btnToggle.drawButton = true; | |
| 333 | + this.btnToggle.displayString = this.selectedMod.willBeEnabled() ? "Disable mod" : "Enable mod"; | |
| 334 | + } | |
| 335 | + } | |
| 336 | + | |
| 337 | + /* (non-Javadoc) | |
| 338 | + * @see net.minecraft.src.GuiScreen#actionPerformed(net.minecraft.src.GuiButton) | |
| 339 | + */ | |
| 340 | + @Override | |
| 341 | + protected void actionPerformed(GuiButton button) | |
| 342 | + { | |
| 343 | + if (button.id == 0 && this.selectedMod != null) | |
| 344 | + { | |
| 345 | + this.selectedMod.toggleEnabled(); | |
| 346 | + this.selectMod(this.selectedMod); | |
| 347 | + } | |
| 348 | + | |
| 349 | + if (button.id == 1) | |
| 350 | + { | |
| 351 | + this.chkEnabled.checked = !this.chkEnabled.checked; | |
| 352 | + LiteLoader.getInstance().setDisplayModInfoScreenTab(this.chkEnabled.checked); | |
| 353 | + | |
| 354 | + if (!this.chkEnabled.checked) | |
| 355 | + { | |
| 356 | + this.chkEnabled.displayString = "Show LiteLoader tab on main menu \247e(use \2479CTRL\247e+\2479SHIFT\247e+\2479TAB\247e)"; | |
| 357 | + } | |
| 358 | + } | |
| 359 | + } | |
| 360 | + | |
| 361 | + /* (non-Javadoc) | |
| 362 | + * @see net.minecraft.src.GuiScreen#keyTyped(char, int) | |
| 363 | + */ | |
| 364 | + @Override | |
| 365 | + protected void keyTyped(char keyChar, int keyCode) | |
| 366 | + { | |
| 367 | + if (keyCode == Keyboard.KEY_ESCAPE) | |
| 368 | + { | |
| 369 | + this.onToggled(); | |
| 370 | + return; | |
| 371 | + } | |
| 372 | + } | |
| 373 | + | |
| 374 | + /* (non-Javadoc) | |
| 375 | + * @see net.minecraft.src.GuiScreen#mouseClicked(int, int, int) | |
| 376 | + */ | |
| 377 | + @Override | |
| 378 | + protected void mouseClicked(int mouseX, int mouseY, int button) | |
| 379 | + { | |
| 380 | + if (button == 0) | |
| 381 | + { | |
| 382 | + if (this.scrollBar.wasMouseOver()) | |
| 383 | + { | |
| 384 | + this.scrollBar.setDragging(true); | |
| 385 | + } | |
| 386 | + | |
| 387 | + if (mouseY > 83 && mouseY < this.height - 26) | |
| 388 | + { | |
| 389 | + for (GuiModListEntry mod : this.mods) | |
| 390 | + { | |
| 391 | + if (mod.mouseWasOver()) this.selectMod(mod); | |
| 392 | + } | |
| 393 | + } | |
| 394 | + } | |
| 395 | + | |
| 396 | + super.mouseClicked(mouseX, mouseY, button); | |
| 397 | + } | |
| 398 | + | |
| 399 | + /* (non-Javadoc) | |
| 400 | + * @see net.minecraft.src.GuiScreen#mouseMovedOrUp(int, int, int) | |
| 401 | + */ | |
| 402 | + @Override | |
| 403 | + protected void mouseMovedOrUp(int mouseX, int mouseY, int button) | |
| 404 | + { | |
| 405 | + if (button == 0) | |
| 406 | + { | |
| 407 | + this.scrollBar.setDragging(false); | |
| 408 | + } | |
| 409 | + | |
| 410 | + super.mouseMovedOrUp(mouseX, mouseY, button); | |
| 411 | + } | |
| 412 | + | |
| 413 | + /* (non-Javadoc) | |
| 414 | + * @see net.minecraft.src.GuiScreen#handleMouseInput() | |
| 415 | + */ | |
| 416 | + @Override | |
| 417 | + public void handleMouseInput() | |
| 418 | + { | |
| 419 | + int mouseWheelDelta = Mouse.getEventDWheel(); | |
| 420 | + | |
| 421 | + if (mouseWheelDelta != 0) | |
| 422 | + { | |
| 423 | + this.scrollBar.offsetValue(-mouseWheelDelta / 8); | |
| 424 | + } | |
| 425 | + | |
| 426 | + super.handleMouseInput(); | |
| 427 | + } | |
| 428 | + | |
| 429 | + /** | |
| 430 | + * @param mouseX | |
| 431 | + * @param active | |
| 432 | + * @param mouseOverTab | |
| 433 | + */ | |
| 434 | + public void handleMouseClick(int mouseX, int mouseY, float partialTicks, boolean active, boolean mouseOverTab) | |
| 435 | + { | |
| 436 | + boolean mouseDown = Mouse.isButtonDown(0); | |
| 437 | + if (((active && mouseX < LEFT_EDGE) || mouseOverTab) && !this.mouseDown && mouseDown) | |
| 438 | + { | |
| 439 | + this.mouseDown = true; | |
| 440 | + this.toggled = true; | |
| 441 | + } | |
| 442 | + else if (this.mouseDown && !mouseDown) | |
| 443 | + { | |
| 444 | + this.mouseDown = false; | |
| 445 | + } | |
| 446 | + } | |
| 447 | + | |
| 448 | + /** | |
| 449 | + * @param partialTicks | |
| 450 | + * @param active | |
| 451 | + * @return | |
| 452 | + */ | |
| 453 | + private float calcTween(float partialTicks, boolean active) | |
| 454 | + { | |
| 455 | + double tickValue = this.tickNumber + partialTicks; | |
| 456 | + | |
| 457 | + if (active && this.tweenAmount < 1.0) | |
| 458 | + { | |
| 459 | + this.tweenAmount = Math.min(1.0, this.tweenAmount + ((tickValue - this.lastTick) * this.tweenRate)); | |
| 460 | + } | |
| 461 | + else if (!active && this.tweenAmount > 0.0) | |
| 462 | + { | |
| 463 | + this.tweenAmount = Math.max(0.0, this.tweenAmount - ((tickValue - this.lastTick) * this.tweenRate)); | |
| 464 | + } | |
| 465 | + | |
| 466 | + this.lastTick = tickValue; | |
| 467 | + return 1.0F - (float)Math.sin(this.tweenAmount * 0.5 * Math.PI); | |
| 468 | + } | |
| 469 | + | |
| 470 | + /** | |
| 471 | + * Called when the tab is clicked | |
| 472 | + */ | |
| 473 | + private void onToggled() | |
| 474 | + { | |
| 475 | + this.toggled = false; | |
| 476 | + this.mc.displayGuiScreen(this.mc.currentScreen == this ? this.mainMenu : this); | |
| 477 | + } | |
| 478 | + | |
| 479 | + /** | |
| 480 | + * @param x | |
| 481 | + * @param y | |
| 482 | + * @param width | |
| 483 | + * @param height | |
| 484 | + * @param u | |
| 485 | + * @param v | |
| 486 | + * @param u2 | |
| 487 | + * @param v2 | |
| 488 | + * @param alpha | |
| 489 | + */ | |
| 490 | + private static void glDrawTexturedRect(int x, int y, int width, int height, int u, int v, int u2, int v2, float alpha) | |
| 491 | + { | |
| 492 | + glDisable(GL_LIGHTING); | |
| 493 | + glEnable(GL_BLEND); | |
| 494 | + glAlphaFunc(GL_GREATER, 0.0F); | |
| 495 | + glEnable(GL_TEXTURE_2D); | |
| 496 | + glColor4f(1.0F, 1.0F, 1.0F, alpha); | |
| 497 | + | |
| 498 | + float texMapScale = 0.00390625F; // 256px | |
| 499 | + | |
| 500 | + Tessellator tessellator = Tessellator.instance; | |
| 501 | + tessellator.startDrawingQuads(); | |
| 502 | + tessellator.addVertexWithUV(x + 0, y + height, 0, u * texMapScale, v2 * texMapScale); | |
| 503 | + tessellator.addVertexWithUV(x + width, y + height, 0, u2 * texMapScale, v2 * texMapScale); | |
| 504 | + tessellator.addVertexWithUV(x + width, y + 0, 0, u2 * texMapScale, v * texMapScale); | |
| 505 | + tessellator.addVertexWithUV(x + 0, y + 0, 0, u * texMapScale, v * texMapScale); | |
| 506 | + tessellator.draw(); | |
| 507 | + | |
| 508 | + glDisable(GL_BLEND); | |
| 509 | + glAlphaFunc(GL_GREATER, 0.01F); | |
| 510 | + } | |
| 511 | + | |
| 512 | + /** | |
| 513 | + * Enable OpenGL clipping planes (uses planes 2, 3, 4 and 5) | |
| 514 | + * | |
| 515 | + * @param xLeft Left edge clip or -1 to not use this plane | |
| 516 | + * @param xRight Right edge clip or -1 to not use this plane | |
| 517 | + * @param yTop Top edge clip or -1 to not use this plane | |
| 518 | + * @param yBottom Bottom edge clip or -1 to not use this plane | |
| 519 | + */ | |
| 520 | + private final static void glEnableClipping(int xLeft, int xRight, int yTop, int yBottom) | |
| 521 | + { | |
| 522 | + // Apply left edge clipping if specified | |
| 523 | + if (xLeft != -1) | |
| 524 | + { | |
| 525 | + doubleBuffer.clear(); | |
| 526 | + doubleBuffer.put(1).put(0).put(0).put(-xLeft).flip(); | |
| 527 | + glClipPlane(GL_CLIP_PLANE2, doubleBuffer); | |
| 528 | + glEnable(GL_CLIP_PLANE2); | |
| 529 | + } | |
| 530 | + | |
| 531 | + // Apply right edge clipping if specified | |
| 532 | + if (xRight != -1) | |
| 533 | + { | |
| 534 | + doubleBuffer.clear(); | |
| 535 | + doubleBuffer.put(-1).put(0).put(0).put(xRight).flip(); | |
| 536 | + glClipPlane(GL_CLIP_PLANE3, doubleBuffer); | |
| 537 | + glEnable(GL_CLIP_PLANE3); | |
| 538 | + } | |
| 539 | + | |
| 540 | + // Apply top edge clipping if specified | |
| 541 | + if (yTop != -1) | |
| 542 | + { | |
| 543 | + doubleBuffer.clear(); | |
| 544 | + doubleBuffer.put(0).put(1).put(0).put(-yTop).flip(); | |
| 545 | + glClipPlane(GL_CLIP_PLANE4, doubleBuffer); | |
| 546 | + glEnable(GL_CLIP_PLANE4); | |
| 547 | + } | |
| 548 | + | |
| 549 | + // Apply bottom edge clipping if specified | |
| 550 | + if (yBottom != -1) | |
| 551 | + { | |
| 552 | + doubleBuffer.clear(); | |
| 553 | + doubleBuffer.put(0).put(-1).put(0).put(yBottom).flip(); | |
| 554 | + glClipPlane(GL_CLIP_PLANE5, doubleBuffer); | |
| 555 | + glEnable(GL_CLIP_PLANE5); | |
| 556 | + } | |
| 557 | + } | |
| 558 | + | |
| 559 | + /** | |
| 560 | + * Disable OpenGL clipping planes (uses planes 2, 3, 4 and 5) | |
| 561 | + */ | |
| 562 | + private final static void glDisableClipping() | |
| 563 | + { | |
| 564 | + glDisable(GL_CLIP_PLANE5); | |
| 565 | + glDisable(GL_CLIP_PLANE4); | |
| 566 | + glDisable(GL_CLIP_PLANE3); | |
| 567 | + glDisable(GL_CLIP_PLANE2); | |
| 568 | + } | |
| 569 | +} | |
| 0 | 570 | \ No newline at end of file | ... | ... |
java/com/mumfrey/liteloader/gui/GuiSimpleScrollBar.java
0 → 100644
| 1 | +package com.mumfrey.liteloader.gui; | |
| 2 | + | |
| 3 | +import net.minecraft.src.Gui; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Extremely simple scrollbar implementation | |
| 7 | + * | |
| 8 | + * @author Adam Mummery-Smith | |
| 9 | + */ | |
| 10 | +public class GuiSimpleScrollBar extends Gui | |
| 11 | +{ | |
| 12 | + /** | |
| 13 | + * Current value | |
| 14 | + */ | |
| 15 | + private int value = 0; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Current maximum value | |
| 19 | + */ | |
| 20 | + private int maxValue = 100; | |
| 21 | + | |
| 22 | + private int backColour = 0x44FFFFFF; | |
| 23 | + private int foreColour = 0xFFFFFFFF; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * True if mouse was over the drag bar when last drawn | |
| 27 | + */ | |
| 28 | + private boolean mouseOver = false; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * True if currently dragging the scroll bar | |
| 32 | + */ | |
| 33 | + private boolean dragging = false; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Value prior to starting to drag | |
| 37 | + */ | |
| 38 | + private int mouseDownValue = 0; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * mouse Y coordinate prior to starting to drag | |
| 42 | + */ | |
| 43 | + private int mouseDownY = 0; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Get the current scroll value | |
| 47 | + */ | |
| 48 | + public int getValue() | |
| 49 | + { | |
| 50 | + return this.value; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Set the scroll value, the value is clamped between 0 and the current max value | |
| 55 | + */ | |
| 56 | + public void setValue(int value) | |
| 57 | + { | |
| 58 | + this.value = Math.min(Math.max(value, 0), this.maxValue); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Offset the scroll value by the specified amount, the value is clamped between 0 and the current max value | |
| 63 | + */ | |
| 64 | + public void offsetValue(int offset) | |
| 65 | + { | |
| 66 | + this.setValue(this.value + offset); | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Get the current max value | |
| 71 | + */ | |
| 72 | + public int getMaxValue() | |
| 73 | + { | |
| 74 | + return this.maxValue; | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * Sets the current max value | |
| 79 | + */ | |
| 80 | + public void setMaxValue(int maxValue) | |
| 81 | + { | |
| 82 | + this.maxValue = Math.max(0, maxValue); | |
| 83 | + this.value = Math.min(this.value, this.maxValue); | |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Returns true if the mouse was over the drag bar on the last render | |
| 88 | + */ | |
| 89 | + public boolean wasMouseOver() | |
| 90 | + { | |
| 91 | + return this.mouseOver; | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Set the current dragging state | |
| 96 | + */ | |
| 97 | + public void setDragging(boolean dragging) | |
| 98 | + { | |
| 99 | + this.dragging = dragging; | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Draw the scroll bar | |
| 104 | + * | |
| 105 | + * @param mouseX | |
| 106 | + * @param mouseY | |
| 107 | + * @param partialTicks | |
| 108 | + * @param xPosition | |
| 109 | + * @param yPosition | |
| 110 | + * @param width | |
| 111 | + * @param height | |
| 112 | + * @param totalHeight | |
| 113 | + */ | |
| 114 | + public void drawScrollBar(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width, int height, int totalHeight) | |
| 115 | + { | |
| 116 | + drawRect(xPosition, yPosition, xPosition + width, yPosition + height, this.backColour); | |
| 117 | + | |
| 118 | + if (totalHeight > 0) | |
| 119 | + { | |
| 120 | + int slideHeight = height - 2; | |
| 121 | + float pct = Math.min(1.0F, (float)slideHeight / (float)totalHeight); | |
| 122 | + int barHeight = (int)(pct * slideHeight); | |
| 123 | + int barTravel = slideHeight - barHeight; | |
| 124 | + int barPosition = this.maxValue > 0 ? yPosition + 1 + (int)((this.value / (float)this.maxValue) * barTravel) : 0; | |
| 125 | + | |
| 126 | + drawRect(xPosition + 1, barPosition, xPosition + width - 1, barPosition + barHeight, this.foreColour); | |
| 127 | + | |
| 128 | + this.mouseOver = mouseX > xPosition && mouseX < xPosition + width && mouseY > barPosition && mouseY < barPosition + barHeight; | |
| 129 | + this.handleDrag(mouseY, barTravel); | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * @param mouseY | |
| 135 | + * @param barTravel | |
| 136 | + */ | |
| 137 | + public void handleDrag(int mouseY, int barTravel) | |
| 138 | + { | |
| 139 | + if (this.dragging) | |
| 140 | + { | |
| 141 | + // Convert pixel delta to value delta | |
| 142 | + float valuePerPixel = (float)this.maxValue / barTravel; | |
| 143 | + this.setValue((int)(this.mouseDownValue + ((mouseY - this.mouseDownY) * valuePerPixel))); | |
| 144 | + } | |
| 145 | + else | |
| 146 | + { | |
| 147 | + this.mouseDownY = mouseY; | |
| 148 | + this.mouseDownValue = this.value; | |
| 149 | + } | |
| 150 | + } | |
| 151 | +} | ... | ... |
res/assets/liteloader/textures/gui/about.png
0 → 100644
27.2 KB