Skip to content

Commit

Permalink
Separate ListEditEntryButtonType from WidgetVec3iListEditEntry
Browse files Browse the repository at this point in the history
and use our i18n text

Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Sep 19, 2024
1 parent 6b6e507 commit 2bccdb8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package top.hendrixshen.magiclib.impl.malilib.config.gui.button;

import fi.dy.masa.malilib.gui.MaLiLibIcons;
import lombok.AllArgsConstructor;
import lombok.Getter;
import top.hendrixshen.magiclib.api.i18n.I18n;

@AllArgsConstructor
public enum ListEditEntryButtonType {
ADD(MaLiLibIcons.PLUS, "magiclib.config.gui.button.hover_text.add"),
REMOVE(MaLiLibIcons.MINUS, "magiclib.config.gui.button.hover_text.remove"),
MOVE_UP(MaLiLibIcons.ARROW_UP, "magiclib.config.gui.button.hover_text.move_up"),
MOVE_DOWN(MaLiLibIcons.ARROW_DOWN, "magiclib.config.gui.button.hover_text.move_down");

@Getter
private final MaLiLibIcons icon;
private final String hoverTextTrKey;

public String getDisplayName() {
return I18n.tr(this.hoverTextTrKey);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package top.hendrixshen.magiclib.impl.malilib.config.gui.widget;

import fi.dy.masa.malilib.gui.GuiTextFieldGeneric;
import fi.dy.masa.malilib.gui.MaLiLibIcons;
import fi.dy.masa.malilib.gui.button.ButtonBase;
import fi.dy.masa.malilib.gui.button.ButtonGeneric;
import fi.dy.masa.malilib.gui.button.IButtonActionListener;
import fi.dy.masa.malilib.gui.widgets.WidgetConfigOptionBase;
import fi.dy.masa.malilib.render.RenderUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.core.Vec3i;
import top.hendrixshen.magiclib.api.i18n.I18n;
import top.hendrixshen.magiclib.api.malilib.config.option.ConfigVec3iList;
import top.hendrixshen.magiclib.impl.malilib.config.gui.button.ListEditEntryButtonType;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -49,31 +47,31 @@ public WidgetVec3iListEditEntry(int x, int y, int width, int height, int listInd
this.vec3iEntry = new WidgetVec3iEntry(x, y, vec3iWidth, height, initialValue, defaultValue);
this.vec3iEntry.getTextFields().forEach(this.parent::addTextField);
x += vec3iWidth + 2;
this.addListActionButton(x, iy, ButtonType.ADD);
this.addListActionButton(x, iy, ListEditEntryButtonType.ADD);
x += 18;
this.addListActionButton(x, iy, ButtonType.REMOVE);
this.addListActionButton(x, iy, ListEditEntryButtonType.REMOVE);
x += 18;

if (this.canBeMoved(true)) {
this.addListActionButton(x, iy, ButtonType.MOVE_DOWN);
this.addListActionButton(x, iy, ListEditEntryButtonType.MOVE_DOWN);
}

x += 18;

if (this.canBeMoved(false)) {
this.addListActionButton(x, iy, ButtonType.MOVE_UP);
this.addListActionButton(x, iy, ListEditEntryButtonType.MOVE_UP);
}
} else {
this.vec3iEntry = null;
this.addListActionButton(x, y + 3, ButtonType.ADD);
this.addListActionButton(x, y + 3, ListEditEntryButtonType.ADD);
}
}

protected boolean isDummy() {
return this.listIndex < 0;
}

protected void addListActionButton(int x, int y, ButtonType type) {
protected void addListActionButton(int x, int y, ListEditEntryButtonType type) {
ButtonGeneric button = new ButtonGeneric(x, y, type.getIcon(), type.getDisplayName());
ListenerListActions listener = new ListenerListActions(type, this);
this.addButton(button, listener);
Expand Down Expand Up @@ -237,34 +235,18 @@ protected boolean onCharTypedImpl(char charIn, int modifiers) {
return this.vec3iEntry.onCharTypedImpl(charIn, modifiers);
}

@AllArgsConstructor
private enum ButtonType {
ADD(MaLiLibIcons.PLUS, "malilib.gui.button.hovertext.add"),
REMOVE(MaLiLibIcons.MINUS, "malilib.gui.button.hovertext.remove"),
MOVE_UP(MaLiLibIcons.ARROW_UP, "malilib.gui.button.hovertext.move_up"),
MOVE_DOWN(MaLiLibIcons.ARROW_DOWN, "malilib.gui.button.hovertext.move_down");

@Getter
private final MaLiLibIcons icon;
private final String hoverTextTrKey;

public String getDisplayName() {
return I18n.tr(this.hoverTextTrKey);
}
}

@AllArgsConstructor
private static class ListenerListActions implements IButtonActionListener {
private final WidgetVec3iListEditEntry.ButtonType type;
private final ListEditEntryButtonType type;
private final WidgetVec3iListEditEntry parent;

public void actionPerformedWithButton(ButtonBase button, int mouseButton) {
if (this.type == WidgetVec3iListEditEntry.ButtonType.ADD) {
if (this.type == ListEditEntryButtonType.ADD) {
this.parent.insertEntryBefore();
} else if (this.type == WidgetVec3iListEditEntry.ButtonType.REMOVE) {
} else if (this.type == ListEditEntryButtonType.REMOVE) {
this.parent.removeEntry();
} else {
this.parent.moveEntry(this.type == WidgetVec3iListEditEntry.ButtonType.MOVE_DOWN);
this.parent.moveEntry(this.type == ListEditEntryButtonType.MOVE_DOWN);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ magiclib:
gui:
bottom_line:
stat: "Total: %1$s (Available: %2$s + Unavailable: %3$s), Modified: %4$s"
button:
hover_text:
add: Add
remove: Remove
move_up: MoveUp
move_down: MoveDown
dependencies_footer: "Dependencies:"
element:
config_button_boolean_switch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ magiclib:
gui:
bottom_line:
stat: "总计: %1$s (可用: %2$s + 不可用: %3$s), 已修改: %4$s"
button:
hover_text:
add: 添加
remove: 移除
move_up: 上移
move_down: 下移
dependencies_footer: "依赖:"
element:
config_button_boolean_switch:
Expand Down

0 comments on commit 2bccdb8

Please sign in to comment.