mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-29 15:37:59 +01:00
Move the gui stuff to a common sourceset so I can use it in HDSkins
This commit is contained in:
parent
05bd9b0ac3
commit
2de216842f
11 changed files with 80 additions and 27 deletions
|
@ -38,12 +38,17 @@ minecraft {
|
|||
sourceSets {
|
||||
hdskins {
|
||||
compileClasspath += main.compileClasspath
|
||||
compileClasspath += common.compileClasspath
|
||||
ext.refMap = 'hdskins.mixin.refmap.json'
|
||||
}
|
||||
main {
|
||||
compileClasspath += hdskins.output
|
||||
compileClasspath += common.output
|
||||
ext.refMap = 'minelp.mixin.refmap.json'
|
||||
}
|
||||
common {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
19
src/common/java/com/minelittlepony/gui/Button.java
Normal file
19
src/common/java/com/minelittlepony/gui/Button.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
public class Button extends GuiButton implements IActionable {
|
||||
|
||||
private IGUIAction<Button> action;
|
||||
|
||||
public Button(int x, int y, int width, int height, String label, IGUIAction<Button> callback) {
|
||||
super(0, x, y, width, height, GameGui.translate(label));
|
||||
action = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
action.perform(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,12 @@ import com.mumfrey.liteloader.client.gui.GuiCheckbox;
|
|||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
/**
|
||||
* Checkbox that supports a gui action when it changes.
|
||||
*
|
||||
* @author Sollace
|
||||
*
|
||||
*/
|
||||
public class Checkbox extends GuiCheckbox implements IActionable {
|
||||
|
||||
private final IGUIAction<Boolean> action;
|
21
src/common/java/com/minelittlepony/gui/GameGui.java
Normal file
21
src/common/java/com/minelittlepony/gui/GameGui.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public abstract class GameGui extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if (button instanceof IActionable) {
|
||||
((IActionable)button).perform();
|
||||
}
|
||||
}
|
||||
|
||||
protected static String translate(String string) {
|
||||
return I18n.format(string);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,12 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
/**
|
||||
* A simple label for drawing text to a gui screen.
|
||||
*
|
||||
* @author Sollace
|
||||
*
|
||||
*/
|
||||
public class Label extends GuiButton {
|
||||
|
||||
private boolean center;
|
|
@ -7,18 +7,20 @@ import com.mumfrey.liteloader.modconfig.ConfigPanelHost;
|
|||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
|
||||
/**
|
||||
* Boilerplate because LiteLoader has to be such a 'special flower' -_-
|
||||
* A GuiScreen that doubles as a liteloader panel. What is this madness!?
|
||||
*/
|
||||
public class PonySettingsPanel extends GuiPonySettings implements ConfigPanel {
|
||||
public abstract class SettingsPanel extends GameGui implements ConfigPanel {
|
||||
|
||||
private boolean isInPanel = false;
|
||||
|
||||
private int contentHeight;
|
||||
|
||||
@Override
|
||||
public String getPanelTitle() {
|
||||
return I18n.format(getTitle());
|
||||
return translate(getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +42,7 @@ public class PonySettingsPanel extends GuiPonySettings implements ConfigPanel {
|
|||
width = host.getWidth();
|
||||
buttonList.clear();
|
||||
initGui();
|
||||
isInPanel = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +54,7 @@ public class PonySettingsPanel extends GuiPonySettings implements ConfigPanel {
|
|||
|
||||
@Override
|
||||
public void onPanelHidden() {
|
||||
isInPanel = false;
|
||||
onGuiClosed();
|
||||
}
|
||||
|
||||
|
@ -94,11 +98,14 @@ public class PonySettingsPanel extends GuiPonySettings implements ConfigPanel {
|
|||
|
||||
@Override
|
||||
public void drawWorldBackground(int tint) {
|
||||
|
||||
if (!isInPanel) {
|
||||
super.drawWorldBackground(tint);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean mustScroll() {
|
||||
return true;
|
||||
return isInPanel;
|
||||
}
|
||||
|
||||
protected abstract String getTitle();
|
||||
}
|
|
@ -3,6 +3,12 @@ package com.minelittlepony.gui;
|
|||
import net.minecraft.client.gui.GuiSlider;
|
||||
import net.minecraft.client.gui.GuiPageButtonList.GuiResponder;
|
||||
|
||||
/**
|
||||
* A slider for sliding.
|
||||
*
|
||||
* @author Sollace
|
||||
*
|
||||
*/
|
||||
public class Slider extends GuiSlider {
|
||||
|
||||
private static Responder callback;
|
|
@ -1,6 +1,6 @@
|
|||
package com.minelittlepony;
|
||||
|
||||
import com.minelittlepony.gui.PonySettingsPanel;
|
||||
import com.minelittlepony.gui.GuiPonySettings;
|
||||
import com.mumfrey.liteloader.Configurable;
|
||||
import com.mumfrey.liteloader.InitCompleteListener;
|
||||
import com.mumfrey.liteloader.Tickable;
|
||||
|
@ -46,6 +46,6 @@ public class LiteModMineLittlePony implements InitCompleteListener, Tickable, Co
|
|||
|
||||
@Override
|
||||
public Class<? extends ConfigPanel> getConfigPanelClass() {
|
||||
return PonySettingsPanel.class;
|
||||
return GuiPonySettings.class;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.minelittlepony.MineLittlePony;
|
||||
import com.minelittlepony.PonyConfig;
|
||||
import com.minelittlepony.PonyConfig.PonySettings;
|
||||
|
@ -9,15 +7,11 @@ import com.minelittlepony.pony.data.PonyLevel;
|
|||
import com.minelittlepony.render.ponies.MobRenderers;
|
||||
import com.mumfrey.liteloader.core.LiteLoader;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
/**
|
||||
* In-Game options menu.
|
||||
*
|
||||
*/
|
||||
public class GuiPonySettings extends GuiScreen {
|
||||
public class GuiPonySettings extends SettingsPanel {
|
||||
|
||||
private static final String OPTIONS_PREFIX = "minelp.options.";
|
||||
|
||||
|
@ -44,7 +38,7 @@ public class GuiPonySettings extends GuiScreen {
|
|||
|
||||
addButton(new Label(LEFT, row += 15, PONY_LEVEL, -1));
|
||||
addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal(), (int id, String name, float value) -> {
|
||||
return I18n.format(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
|
||||
return translate(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
|
||||
}, v -> {
|
||||
PonyLevel level = PonyLevel.valueFor(v);
|
||||
config.setPonyLevel(level);
|
||||
|
@ -69,13 +63,6 @@ public class GuiPonySettings extends GuiScreen {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if (button instanceof IActionable) {
|
||||
((IActionable)button).perform();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
|
@ -90,8 +77,4 @@ public class GuiPonySettings extends GuiScreen {
|
|||
protected String getTitle() {
|
||||
return OPTIONS_PREFIX + "title";
|
||||
}
|
||||
|
||||
protected boolean mustScroll() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue