Skip to content

Commit b3fe4e9

Browse files
author
karpov.evgeniy
committed
правки в интерфейсе
1 parent e36c295 commit b3fe4e9

8 files changed

Lines changed: 239 additions & 63 deletions

File tree

.run/Minecraft Client.run.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<configuration default="false" name="Minecraft Client" type="Application" factoryName="Application" singleton="false">
33
<option name="MAIN_CLASS_NAME" value="GradleStart" />
44
<module name="XRay-Mod.main" />
5+
<option name="PROGRAM_PARAMETERS" value="--username Johnson" />
56
<option name="VM_PARAMETERS" value="-Xincgc -Xmx1024M -Xms1024M" />
67
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/eclipse" />
78
<RunnerSettings RunnerId="Run" />
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package io.github.relvl.schematicaadvancement;
2+
3+
import java.util.Arrays;
4+
import java.util.function.Consumer;
5+
6+
import cpw.mods.fml.common.eventhandler.EventPriority;
7+
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
8+
import cpw.mods.fml.relauncher.Side;
9+
import cpw.mods.fml.relauncher.SideOnly;
10+
import io.github.relvl.schematicaadvancement.client.gui.GuiScreenBlockEdit;
11+
import io.github.relvl.schematicaadvancement.client.gui.GuiSlider;
12+
import io.github.relvl.schematicaadvancement.config.ConfigHandler;
13+
import net.minecraft.client.Minecraft;
14+
import net.minecraftforge.client.event.GuiScreenEvent;
15+
16+
/** @author karpov-em on 14.02.2022 */
17+
public class ClientActionHandler {
18+
19+
@SideOnly(Side.CLIENT)
20+
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
21+
public void onButtonAction(GuiScreenEvent.ActionPerformedEvent.Post event) {
22+
Action.of(event.button.id).getAction().accept(event);
23+
}
24+
25+
public enum Action {
26+
DISTANCE_CHANGED("", event -> {
27+
GuiSlider slider = (GuiSlider)event.button;
28+
ConfigHandler.setRadiusIndex(slider.sliderValue);
29+
}),
30+
ADD_BLOCK("Add new block", event -> {
31+
Minecraft.getMinecraft().displayGuiScreen(new GuiScreenBlockEdit());
32+
}),
33+
XRAY_SWITCH("Enables or disables X-Ray function", event -> {
34+
ConfigHandler.globalEnabled = !ConfigHandler.globalEnabled;
35+
event.gui.initGui();
36+
}),
37+
38+
NONE("", event -> {});
39+
40+
private final Consumer<GuiScreenEvent.ActionPerformedEvent.Post> action;
41+
private final String tooltip;
42+
43+
Action(String tooltip, Consumer<GuiScreenEvent.ActionPerformedEvent.Post> action) {
44+
this.action = action;
45+
this.tooltip = tooltip;
46+
}
47+
48+
public int getId() {
49+
return -this.ordinal() - 50;
50+
}
51+
52+
public String getTooltip() {
53+
return tooltip;
54+
}
55+
56+
public static Action of(int id) {
57+
return Arrays.stream(values()).filter(it -> it.getId() == id).findFirst().orElse(NONE);
58+
}
59+
60+
public Consumer<GuiScreenEvent.ActionPerformedEvent.Post> getAction() {
61+
return action;
62+
}
63+
}
64+
}

src/main/java/io/github/relvl/schematicaadvancement/ModInstance.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import org.lwjgl.input.Keyboard;
44

5-
import io.github.relvl.schematicaadvancement.client.ClientTick;
6-
import io.github.relvl.schematicaadvancement.client.KeyBindingHandler;
7-
import io.github.relvl.schematicaadvancement.client.RenderTick;
8-
import io.github.relvl.schematicaadvancement.config.ConfigHandler;
95
import cpw.mods.fml.client.registry.ClientRegistry;
106
import cpw.mods.fml.common.FMLCommonHandler;
117
import cpw.mods.fml.common.Mod;
128
import cpw.mods.fml.common.Mod.EventHandler;
139
import cpw.mods.fml.common.event.FMLInitializationEvent;
1410
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
11+
import io.github.relvl.schematicaadvancement.client.ClientTick;
12+
import io.github.relvl.schematicaadvancement.client.KeyBindingHandler;
13+
import io.github.relvl.schematicaadvancement.client.RenderTick;
14+
import io.github.relvl.schematicaadvancement.config.ConfigHandler;
1515
import net.minecraft.client.Minecraft;
1616
import net.minecraft.client.settings.KeyBinding;
1717
import net.minecraft.util.ChatComponentText;
@@ -36,6 +36,7 @@ public void load(FMLInitializationEvent event) {
3636

3737
FMLCommonHandler.instance().bus().register(new KeyBindingHandler());
3838
FMLCommonHandler.instance().bus().register(new ClientTick());
39+
MinecraftForge.EVENT_BUS.register(new ClientActionHandler());
3940
MinecraftForge.EVENT_BUS.register(new RenderTick());
4041
}
4142

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package io.github.relvl.schematicaadvancement.client.gui;
2+
3+
import java.util.function.Function;
4+
5+
import org.lwjgl.opengl.GL11;
6+
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.client.gui.GuiButton;
9+
10+
public class GuiColourSlider extends GuiButton {
11+
private final float sliderMaxValue;
12+
private final String label;
13+
public float sliderValue;
14+
private boolean dragging;
15+
private final Function<Integer, String> valueTransformator;
16+
17+
public GuiColourSlider(int id, int x, int y, String label, float startingValue, float maxValue) {
18+
this(id, x, y, 150, label, startingValue, maxValue, Object::toString);
19+
}
20+
21+
public GuiColourSlider(int id, int x, int y, int width, String label, float startingValue, float maxValue, Function<Integer, String> valueTransformator) {
22+
super(id, x, y, width, 20, label);
23+
this.label = label;
24+
this.sliderValue = startingValue;
25+
this.sliderMaxValue = maxValue;
26+
this.valueTransformator = valueTransformator;
27+
}
28+
29+
@Override
30+
public int getHoverState(boolean par1) {
31+
return 0;
32+
}
33+
34+
@Override
35+
protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {
36+
if (this.dragging) {
37+
this.sliderValue = (float)(par2 - (this.xPosition + 4)) / (float)(this.width - 8);
38+
if (this.sliderValue < 0.0F) {
39+
this.sliderValue = 0.0F;
40+
}
41+
if (this.sliderValue > 1.0F) {
42+
this.sliderValue = 1.0F;
43+
}
44+
}
45+
46+
this.displayString = label + ": " + valueTransformator.apply((int)(sliderValue * sliderMaxValue));
47+
48+
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
49+
this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)), this.yPosition, 0, 66, 4, 20);
50+
this.drawTexturedModalRect(this.xPosition + (int)(this.sliderValue * (float)(this.width - 8)) + 4, this.yPosition, 196, 66, 4, 20);
51+
}
52+
53+
@Override
54+
public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) {
55+
if (super.mousePressed(par1Minecraft, par2, par3)) {
56+
this.sliderValue = (float)(par2 - (this.xPosition + 4)) / (float)(this.width - 8);
57+
if (this.sliderValue < 0.0F) {
58+
this.sliderValue = 0.0F;
59+
}
60+
if (this.sliderValue > 1.0F) {
61+
this.sliderValue = 1.0F;
62+
}
63+
this.dragging = true;
64+
return true;
65+
}
66+
else {
67+
return false;
68+
}
69+
}
70+
71+
@Override
72+
public void mouseReleased(int par1, int par2) {
73+
this.dragging = false;
74+
}
75+
}

src/main/java/io/github/relvl/schematicaadvancement/client/gui/GuiScreenBlockEdit.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public class GuiScreenBlockEdit extends GuiScreen {
1919
private GuiTextField oreName;
2020
private GuiTextField oreIdent;
2121

22-
private GuiSlider rSlider;
23-
private GuiSlider gSlider;
24-
private GuiSlider bSlider;
22+
private GuiColourSlider rSlider;
23+
private GuiColourSlider gSlider;
24+
private GuiColourSlider bSlider;
2525
private GuiButton addButton;
2626

2727
private boolean oreNameCleared;
@@ -49,9 +49,9 @@ public void initGui() {
4949

5050
getScreenButtons().add(addButton = new GuiButton(98, width / 2 + 5, height / 2 + 58, 108, 20, saveButtonTitle));
5151
getScreenButtons().add(new GuiButton(99, width / 2 - 108, height / 2 + 58, 108, 20, "Cancel"));
52-
getScreenButtons().add(rSlider = new GuiSlider(1, width / 2 - 108, height / 2 - 63, "Red", 0, 255));
53-
getScreenButtons().add(gSlider = new GuiSlider(2, width / 2 - 108, height / 2 - 40, "Green", 0, 255));
54-
getScreenButtons().add(bSlider = new GuiSlider(3, width / 2 - 108, height / 2 - 17, "Blue", 0, 255));
52+
getScreenButtons().add(rSlider = new GuiColourSlider(1, width / 2 - 108, height / 2 - 63, "Red", 0, 255));
53+
getScreenButtons().add(gSlider = new GuiColourSlider(2, width / 2 - 108, height / 2 - 40, "Green", 0, 255));
54+
getScreenButtons().add(bSlider = new GuiColourSlider(3, width / 2 - 108, height / 2 - 17, "Blue", 0, 255));
5555

5656
oreName = new GuiTextField(fontRendererObj, width / 2 - 108, height / 2 + 8, 220, 20);
5757
oreIdent = new GuiTextField(fontRendererObj, width / 2 - 108, height / 2 + 32, 220, 20);

src/main/java/io/github/relvl/schematicaadvancement/client/gui/GuiScreenXRayMenu.java

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.Map;
77

8+
import io.github.relvl.schematicaadvancement.ClientActionHandler;
89
import io.github.relvl.schematicaadvancement.ModInstance;
910
import io.github.relvl.schematicaadvancement.config.ConfigHandler;
1011
import io.github.relvl.schematicaadvancement.reference.BlockInfo;
@@ -13,18 +14,14 @@
1314
import net.minecraft.client.renderer.Tessellator;
1415
import net.minecraft.util.ResourceLocation;
1516

16-
@SuppressWarnings("ParameterNameDiffersFromOverriddenParameter")
17+
@SuppressWarnings({"ParameterNameDiffersFromOverriddenParameter", "ClassHasNoToStringMethod"})
1718
public class GuiScreenXRayMenu extends GuiScreen {
1819
private static final int PAGE_SIZE = 14;
1920

20-
private final Map<Integer, GuiBlockButton> oreButtons = new HashMap<Integer, GuiBlockButton>();
21-
22-
private GuiButton aNextButton;
23-
private GuiButton aPrevButton;
21+
private final Map<Integer, GuiBlockButton> oreButtons = new HashMap<>();
2422

2523
private int pageCurrent;
2624
private int pageMax;
27-
public boolean called;
2825

2926
@Override
3027
public void initGui() {
@@ -54,10 +51,32 @@ public void initGui() {
5451
id++;
5552
}
5653

57-
getScreenButtons().add(new GuiButton(97, width / 2 - 67, height / 2 + 52, 55, 20, "Add Ore"));
58-
getScreenButtons().add(new GuiButton(98, width / 2 - 10, height / 2 + 52, 82, 20, "Distance: " + ConfigHandler.getDistanceTitle()));
59-
getScreenButtons().add(aNextButton = new GuiButton(-150, width / 2 + 75, height / 2 + 52, 30, 20, ">"));
60-
getScreenButtons().add(aPrevButton = new GuiButton(-151, width / 2 - 100, height / 2 + 52, 30, 20, "<"));
54+
int texWidth = 218;
55+
56+
getScreenButtons().add(new GuiButton(ClientActionHandler.Action.XRAY_SWITCH.getId(),
57+
width / 2 - texWidth / 2 - 30,
58+
height / 2 - 80,
59+
30,
60+
20,
61+
ConfigHandler.globalEnabled ? ModInstance.mcFormat("ON", "a") : ModInstance.mcFormat("OFF", "7")
62+
));
63+
getScreenButtons().add(new GuiButton(ClientActionHandler.Action.ADD_BLOCK.getId(), width / 2 - texWidth / 2 - 30, height / 2 - 100, 30, 20, "+"));
64+
65+
GuiButton aNextButton;
66+
GuiButton aPrevButton;
67+
68+
getScreenButtons().add(aPrevButton = new GuiButton(-151, width / 2 - texWidth / 2 - 30, height / 2 + 52, 30, 20, "<"));
69+
getScreenButtons().add(aNextButton = new GuiButton(-150, width / 2 + texWidth / 2 + 6, height / 2 + 52, 30, 20, ">"));
70+
71+
getScreenButtons().add(new GuiSlider(ClientActionHandler.Action.DISTANCE_CHANGED.getId(),
72+
width / 2 - 105,
73+
height / 2 + 80,
74+
texWidth - 2,
75+
"Distance",
76+
ConfigHandler.getRadiusIndex(),
77+
7,
78+
dis -> String.valueOf(ConfigHandler.getRadius())
79+
));
6180

6281
if (ConfigHandler.blocks.size() <= PAGE_SIZE) {
6382
aNextButton.enabled = false;
@@ -80,14 +99,6 @@ private List<GuiButton> getScreenButtons() {
8099
public void actionPerformed(GuiButton button) {
81100
// Called on left click of GuiButton
82101
switch (button.id) {
83-
case 98: // Distance
84-
ConfigHandler.changeDistance(+1);
85-
break;
86-
87-
case 97: // New Ore
88-
mc.displayGuiScreen(new GuiScreenBlockEdit());
89-
break;
90-
91102
case -150: // Next page
92103
if (pageCurrent < pageMax) {
93104
pageCurrent++;
@@ -105,7 +116,7 @@ public void actionPerformed(GuiButton button) {
105116
if (oreButton != null) {
106117
oreButton.toggleEnabled();
107118
}
108-
break;
119+
return;
109120
}
110121

111122
this.initGui();
@@ -156,11 +167,15 @@ public void drawScreen(int x, int y, float f) {
156167
this.func_146283_a(Arrays.asList("Previous page"), x, y);
157168
break;
158169
}
170+
171+
ClientActionHandler.Action action = ClientActionHandler.Action.of(button.id);
172+
if (action != null && !action.getTooltip().isEmpty()) {
173+
this.func_146283_a(Arrays.asList(action.getTooltip()), x, y);
174+
}
159175
}
160176
}
161177
else {
162-
this.func_146283_a(Arrays.asList(
163-
String.format("%s %s", oreButton.getInfo().name, ModInstance.mcFormat(oreButton.getInfo().getIdent().getIdentPair(), "3")),
178+
this.func_146283_a(Arrays.asList(String.format("%s %s", oreButton.getInfo().name, ModInstance.mcFormat(oreButton.getInfo().getIdent().getIdentPair(), "3")),
164179
ModInstance.mcFormat("LMB: Enable/Disable", "7"),
165180
ModInstance.mcFormat("RMB: Edit", "7"),
166181
ModInstance.mcFormat("Shift+RMB: Delete", "c")
@@ -178,13 +193,6 @@ public void mouseClicked(int x, int y, int mouse) {
178193
// Right clicked
179194
for (GuiButton button : getScreenButtons()) {
180195
if (button.func_146115_a()) { //func_146115_a() returns true if the button is being hovered
181-
182-
if (button.id == 98) { // distance
183-
ConfigHandler.changeDistance(-1);
184-
this.initGui();
185-
return;
186-
}
187-
188196
GuiBlockButton oreButton = oreButtons.get(button.id);
189197
if (oreButton != null) {
190198
if (isShiftKeyDown()) {

0 commit comments

Comments
 (0)