mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Removed the IActionable interface
This commit is contained in:
parent
ac14170a12
commit
f149191908
7 changed files with 51 additions and 34 deletions
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||
import net.minecraft.client.Minecraft;
|
||||
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 tipY = 0;
|
||||
|
@ -14,13 +14,16 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped<But
|
|||
|
||||
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")
|
||||
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));
|
||||
action = (IGuiAction<Button>)callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
action.perform(this);
|
||||
}
|
||||
|
@ -55,4 +58,15 @@ public class Button extends GuiButton implements IActionable, IGuiTooltipped<But
|
|||
tipY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (super.mousePressed(mc, mouseX, mouseY)) {
|
||||
perform();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.client.resources.I18n;
|
|||
* @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 tipY = 0;
|
||||
|
@ -28,7 +28,6 @@ public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped
|
|||
checked = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
checked = action.perform(!checked);
|
||||
}
|
||||
|
@ -52,4 +51,15 @@ public class Checkbox extends GuiCheckbox implements IActionable, IGuiTooltipped
|
|||
tipY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (super.mousePressed(mc, mouseX, mouseY)) {
|
||||
perform();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,20 +7,12 @@ import java.util.List;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
|
||||
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) {
|
||||
return string == null ? null : I18n.format(string, pars);
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package com.minelittlepony.gui;
|
||||
|
||||
/**
|
||||
* An element that can perform an action.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IActionable {
|
||||
/**
|
||||
* Does whatever.
|
||||
*/
|
||||
void perform();
|
||||
}
|
|
@ -6,15 +6,37 @@ import com.google.common.base.Splitter;
|
|||
|
||||
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>> {
|
||||
|
||||
/**
|
||||
* Sets the tooltip text with a multi-line value.
|
||||
*/
|
||||
T setTooltip(List<String> tooltip);
|
||||
|
||||
/**
|
||||
* Sets the tooltip offset from the original mouse position.
|
||||
*/
|
||||
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) {
|
||||
return setTooltip(Splitter.onPattern("\r?\n|\\\\n").splitToList(GameGui.format(tooltip)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws this element's tooltip.
|
||||
*/
|
||||
void renderToolTip(Minecraft mc, int mouseX, int mouseY);
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guiButton) {
|
||||
protected void actionPerformed(GuiButton guiButton) throws IOException {
|
||||
if (canTakeEvents()) {
|
||||
super.actionPerformed(guiButton);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package com.voxelmodpack.hdskins.mixin;
|
||||
|
||||
import com.minelittlepony.gui.IconicButton;
|
||||
import com.minelittlepony.gui.IActionable;
|
||||
import com.voxelmodpack.hdskins.HDSkinManager;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -23,11 +21,4 @@ public class MixinGuiMainMenu extends GuiScreen {
|
|||
mc.displayGuiScreen(HDSkinManager.INSTANCE.createSkinsGui());
|
||||
}).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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue