Refactoring and fixes

This commit is contained in:
Marcel Konrad
2018-06-28 01:07:15 +02:00
parent 70c7419795
commit eb91ad9753
31 changed files with 245 additions and 79 deletions

View File

@@ -10,6 +10,7 @@ import exopandora.worldhandler.gui.content.Content;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -100,26 +101,57 @@ public class GuiButtonList<T> extends GuiButtonWorldHandler
public void actionPerformed(Container container, GuiButton button)
{
int max = this.logic.getMax() - 1;
int index = this.persistence.getIndex();
if(this.isHoveringLeft(this.mouseX, this.mouseY))
{
if(this.persistence.getIndex() > 0)
if(GuiScreen.isShiftKeyDown())
{
this.persistence.decrementIndex();
if(index < 10)
{
this.persistence.setIndex(max - (9 - index));
}
else
{
this.persistence.decrementIndex(10);
}
}
else
{
this.persistence.setIndex(this.logic.getMax() - 1);
if(index > 0)
{
this.persistence.decrementIndex();
}
else
{
this.persistence.setIndex(max);
}
}
}
else if(this.isHoveringRight(this.mouseX, this.mouseY))
{
if(this.persistence.getIndex() < this.logic.getMax() - 1)
if(GuiScreen.isShiftKeyDown())
{
this.persistence.incrementIndex();
if(index > max - 10)
{
this.persistence.setIndex(9 - (max - index));
}
else
{
this.persistence.incrementIndex(10);
}
}
else
{
this.persistence.setIndex(0);
if(index < max)
{
this.persistence.incrementIndex();
}
else
{
this.persistence.setIndex(0);
}
}
}

View File

@@ -24,7 +24,7 @@ public class ButtonValues<T>
this.index++;
}
public void incrementIndexBy(int amount)
public void incrementIndex(int amount)
{
this.index += amount;
}
@@ -34,7 +34,7 @@ public class ButtonValues<T>
this.index--;
}
public void decrementIndexBy(int amount)
public void decrementIndex(int amount)
{
this.index -= amount;
}

View File

@@ -64,7 +64,7 @@ public class Category
registerCategory(1, "entities", new Category(Contents.SUMMON, Contents.PLAYSOUND));
registerCategory(2, "items", new Category(Contents.CUSTOM_ITEM, Contents.ENCHANTMENT));
registerCategory(3, "blocks", new Category(Contents.EDIT_BLOCKS, Contents.SIGN_EDITOR, Contents.NOTE_EDITOR));
registerCategory(4, "world", new Category(Contents.WORLD_INFO, Contents.GAMERULES));
registerCategory(4, "world", new Category(Contents.WORLD_INFO, Contents.GAMERULES, Contents.RECIPES));
registerCategory(5, "player", new Category(Contents.PLAYER, Contents.EXPERIENCE, Contents.ADVANCEMENTS));
registerCategory(6, "scoreboard", new Category(Contents.SCOREBOARD_OBJECTIVES, Contents.SCOREBOARD_TEAMS, Contents.SCOREBOARD_PLAYERS));
}

View File

@@ -21,6 +21,7 @@ import exopandora.worldhandler.gui.content.impl.ContentNoteEditor;
import exopandora.worldhandler.gui.content.impl.ContentPlayer;
import exopandora.worldhandler.gui.content.impl.ContentPlaysound;
import exopandora.worldhandler.gui.content.impl.ContentPotions;
import exopandora.worldhandler.gui.content.impl.ContentRecipes;
import exopandora.worldhandler.gui.content.impl.ContentScoreboardObjectives;
import exopandora.worldhandler.gui.content.impl.ContentScoreboardPlayers;
import exopandora.worldhandler.gui.content.impl.ContentScoreboardTeams;
@@ -60,24 +61,25 @@ public abstract class Content implements IContent
//WORLD
registerContent(9, "world", new ContentWorldInfo());
registerContent(10, "gamerules", new ContentGamerules());
registerContent(11, "recipes", new ContentRecipes());
//PLAYER
registerContent(11, "player", new ContentPlayer());
registerContent(12, "experience", new ContentExperience());
registerContent(13, "advancements", new ContentAdvancements());
registerContent(12, "player", new ContentPlayer());
registerContent(13, "experience", new ContentExperience());
registerContent(14, "advancements", new ContentAdvancements());
//SCOREBOARD
registerContent(14, "scoreboard_objectives", new ContentScoreboardObjectives());
registerContent(15, "scoreboard_teams", new ContentScoreboardTeams());
registerContent(16, "scoreboard_players", new ContentScoreboardPlayers());
registerContent(15, "scoreboard_objectives", new ContentScoreboardObjectives());
registerContent(16, "scoreboard_teams", new ContentScoreboardTeams());
registerContent(17, "scoreboard_players", new ContentScoreboardPlayers());
//MISC
registerContent(17, "change_world", new ContentChangeWorld());
registerContent(18, "continue", new ContentContinue());
registerContent(18, "change_world", new ContentChangeWorld());
registerContent(19, "continue", new ContentContinue());
//NO CATEGORY
registerContent(19, "potions", new ContentPotions());
registerContent(20, "butcher", new ContentButcher());
registerContent(20, "potions", new ContentPotions());
registerContent(21, "butcher", new ContentButcher());
}
private static void registerContent(int id, String textualID, Content content)

View File

@@ -14,10 +14,4 @@ public abstract class Element implements IElement
this.x = x;
this.y = y;
}
@Override
public void draw()
{
}
}

View File

@@ -21,31 +21,29 @@ import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ElementClickList extends Element
{
private final int buttonId;
private final int[] buttonIds;
private final List<Node> list;
private final ILogicClickList logic;
private final Content content;
private final ElementClickList parent;
private final int depth;
private final int maxDepth;
private GuiButtonList button;
private ElementClickList child;
public ElementClickList(int x, int y, List<Node> list, int buttonId, int maxDepth, Content content, ILogicClickList logic)
public ElementClickList(int x, int y, List<Node> list, int[] buttonIds, Content content, ILogicClickList logic)
{
this(x, y, list, buttonId, maxDepth, content, logic, null);
this(x, y, list, buttonIds, content, logic, null);
}
private ElementClickList(int x, int y, List<Node> list, int buttonId, int maxDepth, Content content, ILogicClickList logic, ElementClickList parent)
private ElementClickList(int x, int y, List<Node> list, int[] buttonIds, Content content, ILogicClickList logic, ElementClickList parent)
{
super(x, y);
this.list = list;
this.buttonId = buttonId;
this.buttonIds = buttonIds;
this.logic = logic;
this.content = content;
this.parent = parent;
this.maxDepth = maxDepth;
this.depth = this.parent != null ? this.parent.depth + 1 : 1;
}
@@ -58,7 +56,7 @@ public class ElementClickList extends Element
@Override
public void initButtons(Container container)
{
container.add(this.button = new GuiButtonList(this.buttonId, this.x, this.y, 114, 20, EnumTooltip.TOP_RIGHT, this.content, new IListButtonLogic<Node>()
container.add(this.button = new GuiButtonList(this.getButtonId(), 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)
@@ -108,28 +106,17 @@ public class ElementClickList extends Element
if(node.getEntries() != null)
{
this.child = new ElementClickList(this.x, this.y + 24, node.getEntries(), this.buttonId + 1, this.maxDepth, this.content, this.logic, this);
this.child = new ElementClickList(this.x, this.y + 24, node.getEntries(), this.buttonIds, this.content, this.logic, this);
this.child.initButtons(container);
}
else if(this.depth < this.maxDepth)
else if(this.depth < this.buttonIds.length)
{
GuiButtonWorldHandler button = new GuiButtonWorldHandler(this.buttonId + 1, this.x, this.y + 24, 114, 20, null);
GuiButtonWorldHandler button = new GuiButtonWorldHandler(this.getButtonId(), this.x, this.y + 24, 114, 20, null);
button.enabled = false;
container.add(button);
}
}
private String[] getKeys()
{
return this.getKeys(new String[this.depth]);
}
private String[] getKeys(String[] keys)
{
keys[this.depth - 1] = this.getValues().getObject().getKey();
return this.parent != null ? this.parent.getKeys(keys) : keys;
}
@Nullable
private ButtonValues<Node> getValues()
{
@@ -144,7 +131,7 @@ public class ElementClickList extends Element
@Override
public boolean actionPerformed(Container container, GuiButton button)
{
if(button.id == this.buttonId)
if(button.id == this.getButtonId())
{
this.button.actionPerformed(container, button);
return true;
@@ -156,4 +143,30 @@ public class ElementClickList extends Element
return false;
}
@Override
public void draw()
{
}
private int getButtonId()
{
return this.buttonIds[this.depth - 1];
}
private String[] getKeys()
{
return this.getKeys(new String[this.depth]);
}
private String[] getKeys(String[] keys)
{
if(keys != null && this.depth <= keys.length)
{
keys[this.depth - 1] = this.getValues().getObject().getKey();
}
return this.parent != null ? this.parent.getKeys(keys) : keys;
}
}

View File

@@ -12,6 +12,7 @@ import exopandora.worldhandler.gui.content.element.Element;
import exopandora.worldhandler.gui.content.element.logic.ILogicPageList;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -101,13 +102,33 @@ public class ElementPageList<T, K> extends Element
{
if(button.id == this.ids[0])
{
this.values.setObject(this.values.getObject() - 1);
int value = this.values.getObject();
if(GuiScreen.isShiftKeyDown())
{
this.values.setObject(value - Math.min(10, value));
}
else
{
this.values.setObject(value - 1);
}
container.initGui();
return true;
}
else if(button.id == this.ids[1])
{
this.values.setObject(this.values.getObject() + 1);
int value = this.values.getObject();
if(GuiScreen.isShiftKeyDown())
{
this.values.setObject(value + Math.min(10, this.getTotalPages() - 1 - value));
}
else
{
this.values.setObject(value + 1);
}
container.initGui();
return true;
}

View File

@@ -3,8 +3,8 @@ package exopandora.worldhandler.gui.content.impl;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import com.google.common.collect.Lists;
import com.mojang.realmsclient.gui.ChatFormatting;
import exopandora.worldhandler.WorldHandler;
@@ -43,7 +43,7 @@ public class ContentAdvancements extends Content
private GuiButtonList modeButton;
private final List<Advancement> advancements = StreamSupport.stream(new AdvancementManager(null).getAdvancements().spliterator(), true).filter(advancement -> advancement.getDisplay() != null).collect(Collectors.toList());
private final List<Advancement> advancements = Lists.newArrayList(new AdvancementManager(null).getAdvancements()).parallelStream().filter(advancement -> advancement.getDisplay() != null).collect(Collectors.toList());
@Override
public ICommandBuilder getCommandBuilder()

View File

@@ -48,7 +48,7 @@ public class ContentScoreboardObjectives extends ContentScoreboard
if(this.selectedObjective.equals("create"))
{
ElementClickList objectives = new ElementClickList(x + 118, y + 24, HELPER.getObjectives(), 7, 2, this, new ILogicClickList()
ElementClickList objectives = new ElementClickList(x + 118, y + 24, HELPER.getObjectives(), new int[] {7, 8}, this, new ILogicClickList()
{
@Override
public void consumeKey(String... keys)
@@ -116,7 +116,7 @@ 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, 2, this, new ILogicClickList()
ElementClickList slots = new ElementClickList(x + 118, y + 24 + (this.selectedObjective.equals("undisplay") ? -12 : 0), HELPER.getSlots(), new int[] {9, 10}, this, new ILogicClickList()
{
@Override
public String translate(String... keys)

View File

@@ -47,7 +47,7 @@ public class ContentScoreboardTeams extends ContentScoreboard
if(this.selectedTeam.equals("option"))
{
ElementClickList options = new ElementClickList(x + 118, y + 24, HELPER.getOptions(), 6, 2, this, new ILogicClickList()
ElementClickList options = new ElementClickList(x + 118, y + 24, HELPER.getOptions(), new int[] {6, 7}, this, new ILogicClickList()
{
@Override
public String translate(String... keys)