Refactoring
This commit is contained in:
@@ -24,11 +24,21 @@ public class ButtonValues<T>
|
||||
this.index++;
|
||||
}
|
||||
|
||||
public void incrementIndexBy(int amount)
|
||||
{
|
||||
this.index += amount;
|
||||
}
|
||||
|
||||
public void decrementIndex()
|
||||
{
|
||||
this.index--;
|
||||
}
|
||||
|
||||
public void decrementIndexBy(int amount)
|
||||
{
|
||||
this.index -= amount;
|
||||
}
|
||||
|
||||
public T getObject()
|
||||
{
|
||||
return this.object;
|
||||
|
||||
@@ -6,6 +6,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.gui.button.EnumTooltip;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonList;
|
||||
import exopandora.worldhandler.gui.button.GuiButtonWorldHandler;
|
||||
import exopandora.worldhandler.gui.button.logic.IListButtonLogic;
|
||||
import exopandora.worldhandler.gui.button.persistence.ButtonValues;
|
||||
import exopandora.worldhandler.gui.container.Container;
|
||||
@@ -20,22 +21,32 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElementClickList extends Element
|
||||
{
|
||||
private final int buttonId1;
|
||||
private final int buttonId2;
|
||||
private final int buttonId;
|
||||
private final List<Node> list;
|
||||
private final ILogicClickList logic;
|
||||
private GuiButtonList button1;
|
||||
private GuiButtonList button2;
|
||||
private final Content content;
|
||||
private final ElementClickList parent;
|
||||
private final int depth;
|
||||
private final int maxDepth;
|
||||
|
||||
public ElementClickList(int x, int y, List<Node> list, int buttonId1, int buttonId2, Content content, ILogicClickList logic)
|
||||
private GuiButtonList button;
|
||||
private ElementClickList child;
|
||||
|
||||
public ElementClickList(int x, int y, List<Node> list, int buttonId, int maxDepth, Content content, ILogicClickList logic)
|
||||
{
|
||||
this(x, y, list, buttonId, maxDepth, content, logic, null);
|
||||
}
|
||||
|
||||
private ElementClickList(int x, int y, List<Node> list, int buttonId, int maxDepth, Content content, ILogicClickList logic, ElementClickList parent)
|
||||
{
|
||||
super(x, y);
|
||||
this.list = list;
|
||||
this.buttonId1 = buttonId1;
|
||||
this.buttonId2 = buttonId2;
|
||||
this.buttonId = buttonId;
|
||||
this.logic = logic;
|
||||
this.content = content;
|
||||
this.parent = parent;
|
||||
this.maxDepth = maxDepth;
|
||||
this.depth = this.parent != null ? this.parent.depth + 1 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,12 +58,12 @@ public class ElementClickList extends Element
|
||||
@Override
|
||||
public void initButtons(Container container)
|
||||
{
|
||||
container.add(this.button1 = new GuiButtonList(this.buttonId1, this.x, this.y, 114, 20, EnumTooltip.TOP_RIGHT, this.content, new IListButtonLogic<Node>()
|
||||
container.add(this.button = new GuiButtonList(this.buttonId, this.x, this.y, 114, 20, EnumTooltip.TOP_RIGHT, this.content, new IListButtonLogic<Node>()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(Container container, GuiButton button, ButtonValues<Node> values)
|
||||
{
|
||||
content.getPersistence(listButtonLogic2.getId()).setIndex(0);
|
||||
content.getPersistence(logic.getId() + (depth + 1)).setIndex(0);
|
||||
container.initButtons();
|
||||
}
|
||||
|
||||
@@ -67,11 +78,11 @@ public class ElementClickList extends Element
|
||||
{
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDisplayString(ButtonValues<Node> values)
|
||||
{
|
||||
return logic.translate1(values.getObject().getKey());
|
||||
return logic.translate(getKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,101 +99,43 @@ public class ElementClickList extends Element
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return logic.getId() + 1;
|
||||
return logic.getId() + depth;
|
||||
}
|
||||
}));
|
||||
|
||||
final Node node = this.getValues1().getObject();
|
||||
this.logic.consumeKey1(node.getKey());
|
||||
Node node = this.getValues().getObject();
|
||||
this.logic.consumeKey(this.getKeys());
|
||||
|
||||
if(node.getEntries() != null)
|
||||
{
|
||||
container.add(this.button2 = new GuiButtonList(this.buttonId2, this.x, this.y + 24, 114, 20, EnumTooltip.TOP_RIGHT, this.content, this.listButtonLogic2));
|
||||
this.logic.consumeKey2(node.getKey(), node.getEntries().get(this.getValues2().getIndex()).getKey());
|
||||
this.child = new ElementClickList(this.x, this.y + 24, node.getEntries(), this.buttonId + 1, this.maxDepth, this.content, this.logic, this);
|
||||
this.child.initButtons(container);
|
||||
}
|
||||
else
|
||||
else if(this.depth < this.maxDepth)
|
||||
{
|
||||
container.add(this.button2 = new GuiButtonList(this.buttonId2, this.x, this.y + 24, 114, 20, EnumTooltip.TOP_RIGHT, this.content, this.listButtonLogic2));
|
||||
this.button2.enabled = false;
|
||||
GuiButtonWorldHandler button = new GuiButtonWorldHandler(this.buttonId + 1, this.x, this.y + 24, 114, 20, null);
|
||||
button.enabled = false;
|
||||
container.add(button);
|
||||
}
|
||||
}
|
||||
|
||||
private final IListButtonLogic<Node> listButtonLogic2 = new IListButtonLogic<Node>()
|
||||
private String[] getKeys()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed(Container container, GuiButton button, ButtonValues<Node> values)
|
||||
{
|
||||
container.initButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMax()
|
||||
{
|
||||
if(getValues1().getObject() != null)
|
||||
{
|
||||
return getValues1().getObject().getEntries().size();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getObject(int index)
|
||||
{
|
||||
if(getValues1().getObject().getEntries() != null)
|
||||
{
|
||||
return getValues1().getObject().getEntries().get(index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayString(ButtonValues<Node> values)
|
||||
{
|
||||
if(values.getObject() != null)
|
||||
{
|
||||
return logic.translate2(getValues1().getObject().getKey(), values.getObject().getKey());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltipString(ButtonValues<Node> values)
|
||||
{
|
||||
if(getValues1().getObject().getEntries() != null)
|
||||
{
|
||||
return values.getObject().getKey() + " (" + (values.getIndex() + 1) + "/" + getValues1().getObject().getEntries().size() + ")";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return logic.getId() + 2;
|
||||
}
|
||||
};
|
||||
return this.getKeys(new String[this.depth]);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ButtonValues<Node> getValues1()
|
||||
private String[] getKeys(String[] keys)
|
||||
{
|
||||
if(this.button1 != null)
|
||||
{
|
||||
return this.content.<Node>getPersistence(this.button1.getLogic().getId());
|
||||
}
|
||||
|
||||
return null;
|
||||
keys[this.depth - 1] = this.getValues().getObject().getKey();
|
||||
return this.parent != null ? this.parent.getKeys(keys) : keys;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ButtonValues<Node> getValues2()
|
||||
private ButtonValues<Node> getValues()
|
||||
{
|
||||
if(this.button2 != null)
|
||||
if(this.button != null)
|
||||
{
|
||||
return this.content.<Node>getPersistence(this.button2.getLogic().getId());
|
||||
return this.content.<Node>getPersistence(this.button.getLogic().getId());
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -191,15 +144,14 @@ public class ElementClickList extends Element
|
||||
@Override
|
||||
public boolean actionPerformed(Container container, GuiButton button)
|
||||
{
|
||||
if(button.id == this.buttonId1)
|
||||
if(button.id == this.buttonId)
|
||||
{
|
||||
this.button1.actionPerformed(container, button);
|
||||
this.button.actionPerformed(container, button);
|
||||
return true;
|
||||
}
|
||||
else if(button.id == this.buttonId2)
|
||||
else if(this.child != null)
|
||||
{
|
||||
this.button2.actionPerformed(container, button);
|
||||
return true;
|
||||
return this.child.actionPerformed(container, button);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package exopandora.worldhandler.gui.content.element.logic;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ILogic
|
||||
{
|
||||
String getId();
|
||||
}
|
||||
@@ -4,21 +4,13 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ILogicClickList
|
||||
public interface ILogicClickList extends ILogic
|
||||
{
|
||||
void consumeKey1(String key);
|
||||
String translate(String... keys);
|
||||
void consumeKey(String... keys);
|
||||
|
||||
default void consumeKey2(String key1, String key2)
|
||||
default void consumeKeyImpl(String... keys)
|
||||
{
|
||||
this.consumeKey1(key1 + "." + key2);
|
||||
this.consumeKey(keys[0] + "." + keys[1]);
|
||||
}
|
||||
|
||||
String translate1(String key);
|
||||
|
||||
default String translate2(String key1, String key2)
|
||||
{
|
||||
return this.translate1(key2);
|
||||
}
|
||||
|
||||
String getId();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@ package exopandora.worldhandler.gui.content.element.logic;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
|
||||
public interface ILogicColorMenu
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ILogicColorMenu extends ILogic
|
||||
{
|
||||
default Predicate<String> getValidator()
|
||||
{
|
||||
@@ -20,6 +24,7 @@ public interface ILogicColorMenu
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
default String getId()
|
||||
{
|
||||
return "color";
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ILogicPageList<T, K>
|
||||
public interface ILogicPageList<T, K> extends ILogic
|
||||
{
|
||||
String translate(T key);
|
||||
String getRegistryName(T key);
|
||||
@@ -14,6 +14,4 @@ public interface ILogicPageList<T, K>
|
||||
void onRegister(int id, int x, int y, int width, int height, String display, String registryKey, boolean enabled, T value, Container container);
|
||||
|
||||
T convert(K object);
|
||||
|
||||
String getId();
|
||||
}
|
||||
@@ -48,47 +48,61 @@ public class ContentScoreboardObjectives extends ContentScoreboard
|
||||
|
||||
if(this.selectedObjective.equals("create"))
|
||||
{
|
||||
ElementClickList objectives = new ElementClickList(x + 118, y + 24, HELPER.getObjectives(), 7, 8, this, new ILogicClickList()
|
||||
ElementClickList objectives = new ElementClickList(x + 118, y + 24, HELPER.getObjectives(), 7, 2, this, new ILogicClickList()
|
||||
{
|
||||
@Override
|
||||
public void consumeKey1(String key)
|
||||
public void consumeKey(String... keys)
|
||||
{
|
||||
builderObjectives.setCriteria(key);
|
||||
if(keys.length > 1)
|
||||
{
|
||||
this.consumeKeyImpl(keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
builderObjectives.setCriteria(keys[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate1(String key)
|
||||
public String translate(String... keys)
|
||||
{
|
||||
String format = "gui.worldhandler.scoreboard.objectives.criteria." + key;
|
||||
String result = I18n.format(format);
|
||||
|
||||
if(result.equals(format))
|
||||
if(keys.length > 1)
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation(key);
|
||||
|
||||
if(Item.REGISTRY.containsKey(location))
|
||||
{
|
||||
result = I18n.format(Item.REGISTRY.getObject(location).getUnlocalizedName() + ".name");
|
||||
}
|
||||
else if(Block.REGISTRY.containsKey(location))
|
||||
{
|
||||
result = Block.REGISTRY.getObject(location).getLocalizedName();
|
||||
}
|
||||
else if(EntityHelper.doesExist(key))
|
||||
{
|
||||
result = I18n.format("entity." + key + ".name");
|
||||
}
|
||||
else if(Arrays.stream(EnumColor.values()).map(EnumColor::getFormat).anyMatch(Predicates.equalTo(key)))
|
||||
{
|
||||
result = I18n.format("gui.worldhandler.color." + key);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = I18n.format(key);
|
||||
}
|
||||
return this.translate(keys[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
String format = "gui.worldhandler.scoreboard.objectives.criteria." + keys[0];
|
||||
String result = I18n.format(format);
|
||||
|
||||
if(result.equals(format))
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation(keys[0]);
|
||||
|
||||
if(Item.REGISTRY.containsKey(location))
|
||||
{
|
||||
result = I18n.format(Item.REGISTRY.getObject(location).getUnlocalizedName() + ".name");
|
||||
}
|
||||
else if(Block.REGISTRY.containsKey(location))
|
||||
{
|
||||
result = Block.REGISTRY.getObject(location).getLocalizedName();
|
||||
}
|
||||
else if(EntityHelper.doesExist(keys[0]))
|
||||
{
|
||||
result = I18n.format("entity." + keys[0] + ".name");
|
||||
}
|
||||
else if(Arrays.stream(EnumColor.values()).map(EnumColor::getFormat).anyMatch(Predicates.equalTo(keys[0])))
|
||||
{
|
||||
result = I18n.format("gui.worldhandler.color." + keys[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = I18n.format(keys[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,24 +116,32 @@ public class ContentScoreboardObjectives extends ContentScoreboard
|
||||
}
|
||||
else if(this.selectedObjective.equals("display") || this.selectedObjective.equals("undisplay"))
|
||||
{
|
||||
ElementClickList slots = new ElementClickList(x + 118, y + 24 + (this.selectedObjective.equals("undisplay") ? -12 : 0), HELPER.getSlots(), 9, 10, this, new ILogicClickList()
|
||||
ElementClickList slots = new ElementClickList(x + 118, y + 24 + (this.selectedObjective.equals("undisplay") ? -12 : 0), HELPER.getSlots(), 9, 2, this, new ILogicClickList()
|
||||
{
|
||||
@Override
|
||||
public String translate1(String key)
|
||||
public String translate(String... keys)
|
||||
{
|
||||
return I18n.format("gui.worldhandler.scoreboard.slot." + key);
|
||||
if(keys.length > 1)
|
||||
{
|
||||
return I18n.format("gui.worldhandler.color." + keys[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return I18n.format("gui.worldhandler.scoreboard.slot." + keys[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate2(String key1, String key2)
|
||||
public void consumeKey(String... keys)
|
||||
{
|
||||
return I18n.format("gui.worldhandler.color." + key2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeKey1(String key)
|
||||
{
|
||||
builderObjectives.setSlot(key);
|
||||
if(keys.length > 1)
|
||||
{
|
||||
this.consumeKeyImpl(keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
builderObjectives.setSlot(keys[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,37 +47,39 @@ public class ContentScoreboardTeams extends ContentScoreboard
|
||||
|
||||
if(this.selectedTeam.equals("option"))
|
||||
{
|
||||
ElementClickList options = new ElementClickList(x + 118, y + 24, HELPER.getOptions(), 6, 7, this, new ILogicClickList()
|
||||
ElementClickList options = new ElementClickList(x + 118, y + 24, HELPER.getOptions(), 6, 2, this, new ILogicClickList()
|
||||
{
|
||||
@Override
|
||||
public String translate1(String key)
|
||||
public String translate(String... keys)
|
||||
{
|
||||
return I18n.format("gui.worldhandler.scoreboard.team.options." + key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate2(String key1, String key2)
|
||||
{
|
||||
if(Arrays.stream(EnumColor.values()).map(EnumColor::getFormat).anyMatch(Predicates.equalTo(key2)))
|
||||
if(keys.length > 1)
|
||||
{
|
||||
return I18n.format("gui.worldhandler.color." + key2);
|
||||
if(Arrays.stream(EnumColor.values()).map(EnumColor::getFormat).anyMatch(Predicates.equalTo(keys[1])))
|
||||
{
|
||||
return I18n.format("gui.worldhandler.color." + keys[1]);
|
||||
}
|
||||
|
||||
return I18n.format("gui.worldhandler.scoreboard.team.suboption." + keys[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return I18n.format("gui.worldhandler.scoreboard.team.options." + keys[0]);
|
||||
}
|
||||
|
||||
return I18n.format("gui.worldhandler.scoreboard.team.suboption." + key2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeKey1(String key)
|
||||
public void consumeKey(String... keys)
|
||||
{
|
||||
builderTeams.setRule(key);
|
||||
if(keys.length > 1)
|
||||
{
|
||||
builderTeams.setValue(keys[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
builderTeams.setRule(keys[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeKey2(String key1, String key2)
|
||||
{
|
||||
builderTeams.setValue(key2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user