Removed the IActionable interface

This commit is contained in:
Sollace 2019-02-20 19:10:45 +02:00
parent ac14170a12
commit f149191908
7 changed files with 51 additions and 34 deletions

View file

@ -5,7 +5,7 @@ import java.util.List;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
public class Button extends GuiButton implements IActionable, IGuiTooltipped<Button> { public class Button extends GuiButton implements IGuiTooltipped<Button> {
private int tipX = 0; private int tipX = 0;
private int tipY = 0; private int tipY = 0;
@ -14,13 +14,16 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped<But
private List<String> tooltip = null; private List<String> tooltip = null;
public Button(int x, int y, String label, IGuiAction<? extends Button> callback) {
this(x, y, 200, 20, label, callback);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Button(int x, int y, int width, int height, String label, IGuiAction<? extends Button> callback) { public Button(int x, int y, int width, int height, String label, IGuiAction<? extends Button> callback) {
super(5000, x, y, width, height, GameGui.format(label)); super(5000, x, y, width, height, GameGui.format(label));
action = (IGuiAction<Button>)callback; action = (IGuiAction<Button>)callback;
} }
@Override
public void perform() { public void perform() {
action.perform(this); action.perform(this);
} }
@ -55,4 +58,15 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped<But
tipY = y; tipY = y;
return this; return this;
} }
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if (super.mousePressed(mc, mouseX, mouseY)) {
perform();
return true;
}
return false;
}
} }

View file

@ -13,7 +13,7 @@ import net.minecraft.client.resources.I18n;
* @author Sollace * @author Sollace
* *
*/ */
public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped<Checkbox> { public class Checkbox extends GuiCheckbox implements IGuiTooltipped<Checkbox> {
private int tipX = 0; private int tipX = 0;
private int tipY = 0; private int tipY = 0;
@ -28,7 +28,6 @@ public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped
checked = value; checked = value;
} }
@Override
public void perform() { public void perform() {
checked = action.perform(!checked); checked = action.perform(!checked);
} }
@ -52,4 +51,15 @@ public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped
tipY = y; tipY = y;
return this; return this;
} }
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if (super.mousePressed(mc, mouseX, mouseY)) {
perform();
return false;
}
return false;
}
} }

View file

@ -7,20 +7,12 @@ import java.util.List;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
public abstract class GameGui extends GuiScreen { public abstract class GameGui extends GuiScreen {
@Override
protected void actionPerformed(GuiButton button) {
if (button instanceof IActionable) {
((IActionable)button).perform();
}
}
protected static String format(String string, Object... pars) { protected static String format(String string, Object... pars) {
return string == null ? null : I18n.format(string, pars); return string == null ? null : I18n.format(string, pars);
} }

View file

@ -1,12 +0,0 @@
package com.minelittlepony.gui;
/**
* An element that can perform an action.
*/
@FunctionalInterface
public interface IActionable {
/**
* Does whatever.
*/
void perform();
}

View file

@ -6,15 +6,37 @@ import com.google.common.base.Splitter;
import java.util.List; import java.util.List;
/**
* Interface element that renders a tooltip when hovered.
*
* @author Sollace
*
* @param <T> The subclass element.
*/
public interface IGuiTooltipped<T extends IGuiTooltipped<T>> { public interface IGuiTooltipped<T extends IGuiTooltipped<T>> {
/**
* Sets the tooltip text with a multi-line value.
*/
T setTooltip(List<String> tooltip); T setTooltip(List<String> tooltip);
/**
* Sets the tooltip offset from the original mouse position.
*/
T setTooltipOffset(int x, int y); T setTooltipOffset(int x, int y);
/**
* Sets the tooltip. The passed in value will be automatically
* translated and split into separate lines.
*
* @param tooltip A tooltip translation string.
*/
default T setTooltip(String tooltip) { default T setTooltip(String tooltip) {
return setTooltip(Splitter.onPattern("\r?\n|\\\\n").splitToList(GameGui.format(tooltip))); return setTooltip(Splitter.onPattern("\r?\n|\\\\n").splitToList(GameGui.format(tooltip)));
} }
/**
* Draws this element's tooltip.
*/
void renderToolTip(Minecraft mc, int mouseX, int mouseY); void renderToolTip(Minecraft mc, int mouseX, int mouseY);
} }

View file

@ -264,7 +264,7 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
} }
@Override @Override
protected void actionPerformed(GuiButton guiButton) { protected void actionPerformed(GuiButton guiButton) throws IOException {
if (canTakeEvents()) { if (canTakeEvents()) {
super.actionPerformed(guiButton); super.actionPerformed(guiButton);
} }

View file

@ -1,10 +1,8 @@
package com.voxelmodpack.hdskins.mixin; package com.voxelmodpack.hdskins.mixin;
import com.minelittlepony.gui.IconicButton; import com.minelittlepony.gui.IconicButton;
import com.minelittlepony.gui.IActionable;
import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu; import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.init.Items; import net.minecraft.init.Items;
@ -23,11 +21,4 @@ public class MixinGuiMainMenu extends GuiScreen {
mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui()); mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
}).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb)); }).setIcon(new ItemStack(Items.LEATHER_LEGGINGS), 0x3c5dcb));
} }
@Inject(method = "actionPerformed(Lnet/minecraft/client/gui/GuiButton;)V", at = @At("RETURN"))
private void onActionPerformed(GuiButton button, CallbackInfo ci) {
if (button instanceof IActionable) {
((IActionable)button).perform();
}
}
} }