Add custom usercontent loading from json and javascript files alongside bugfixes for page list, refactorings and documentation

This commit is contained in:
Marcel Konrad
2019-11-02 18:41:15 +01:00
parent 677f899661
commit fc70c82545
126 changed files with 3664 additions and 656 deletions

View File

@@ -11,7 +11,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class GuiButtonIcon extends GuiButtonTooltip
{
private EnumIcon icon;
private final EnumIcon icon;
public GuiButtonIcon(int x, int y, int widthIn, int heightIn, EnumIcon icon, String tooltip, ActionHandler actionHandler)
{

View File

@@ -24,6 +24,12 @@ public class GuiButtonList<T> extends GuiButtonTooltip
this.items = items;
this.logic = logic;
this.persistence = container.getContent().getPersistence(this.logic.getId(), Persistence::new);
this.init();
}
private void init()
{
this.logic.onInit(this.items.get(this.persistence.getIndex()));
this.updateMessage();
}
@@ -43,7 +49,7 @@ public class GuiButtonList<T> extends GuiButtonTooltip
int maxWidth = Math.max(0, this.width - fontRenderer.getStringWidth("< >"));
int spaceWidth = fontRenderer.getStringWidth(" ");
String display = exopandora.worldhandler.text.TextFormatting.shortenString(this.getMessage(), maxWidth, fontRenderer);
String display = exopandora.worldhandler.util.TextFormatting.shortenString(this.getMessage(), maxWidth, fontRenderer);
int yPos = this.y + (this.height - 8) / 2;
this.drawCenteredString(fontRenderer, display, this.x + this.width / 2, yPos, this.getFGColor());
@@ -71,7 +77,7 @@ public class GuiButtonList<T> extends GuiButtonTooltip
{
if(index < 10)
{
this.persistence.setIndex(max - (9 - index));
this.persistence.setIndex((index - 9 + max) % max);
}
else
{
@@ -96,7 +102,7 @@ public class GuiButtonList<T> extends GuiButtonTooltip
{
if(index > max - 10)
{
this.persistence.setIndex(9 - (max - index));
this.persistence.setIndex((index + 9 - max) % max);
}
else
{

View File

@@ -22,7 +22,7 @@ public class GuiButtonTooltip extends GuiButtonBase
public void renderTooltip(int mouseX, int mouseY)
{
if(this.isHovered() && this.tooltip != null)
if(this.isHovered() && this.tooltip != null && !this.tooltip.isEmpty())
{
List<String> list = Arrays.asList(this.tooltip.split("\n"));

View File

@@ -7,7 +7,7 @@ import com.mojang.blaze3d.platform.GlStateManager;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.logic.ILogic;
import exopandora.worldhandler.text.TextFormatting;
import exopandora.worldhandler.util.TextFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraftforge.api.distmarker.Dist;

View File

@@ -27,15 +27,20 @@ public class Categories
SCOREBOARD = Categories.getRegisteredCategory("scoreboard");
}
private static Category getRegisteredCategory(String name)
public static Category getRegisteredCategory(String name)
{
Category category = Category.REGISTRY.getValue(new ResourceLocation(Main.MODID, name));
if(category == null)
{
throw new IllegalStateException("Invalid Category requested: " + name);
throw new IllegalStateException("Requested missing category: " + name);
}
return category;
}
public static boolean isRegistered(String name)
{
return Category.REGISTRY.containsKey(new ResourceLocation(Main.MODID, name));
}
}

View File

@@ -11,6 +11,9 @@ import com.google.common.collect.Lists;
import exopandora.worldhandler.Main;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.helper.RegistryHelper;
import exopandora.worldhandler.usercontent.UsercontentConfig;
import exopandora.worldhandler.usercontent.UsercontentLoader;
import exopandora.worldhandler.usercontent.model.JsonTab;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -48,15 +51,15 @@ public class Category extends ForgeRegistryEntry<Category>
this(Arrays.stream(keys).map(key -> new ResourceLocation(Main.MODID, key)).collect(Collectors.toList()));
}
public Category add(ResourceLocation content)
public Category add(int index, ResourceLocation content)
{
this.contents.add(content);
this.contents.add(Math.min(index, this.getSize()), content);
return this;
}
public Category add(String key)
public Category add(int index, String key)
{
return this.add(new ResourceLocation(Main.MODID, key));
return this.add(index, new ResourceLocation(Main.MODID, key));
}
public List<ResourceLocation> getContents()
@@ -96,5 +99,28 @@ public class Category extends ForgeRegistryEntry<Category>
RegistryHelper.register(event.getRegistry(), "world", new Category("world", "gamerules"));
RegistryHelper.register(event.getRegistry(), "player", new Category("player", "experience", "advancements"));
RegistryHelper.register(event.getRegistry(), "scoreboard", new Category("scoreboard_objectives", "scoreboard_teams", "scoreboard_players"));
for(UsercontentConfig config : UsercontentLoader.CONFIGS)
{
if(config.getContent().getGui() != null && config.getContent().getGui().getTab() != null)
{
Category.registerCategory(event.getRegistry(), config.getId(), config.getContent().getGui().getTab());
}
}
}
private static void registerCategory(IForgeRegistry<Category> registry, String id, JsonTab tab)
{
if(tab.getCategory() != null && !tab.getCategory().isEmpty())
{
if(!Categories.isRegistered(tab.getCategory()))
{
RegistryHelper.register(registry, tab.getCategory(), new Category(id));
}
else
{
Categories.getRegisteredCategory(tab.getCategory()).add(tab.getCategoryIndex(), id);
}
}
}
}

View File

@@ -3,8 +3,8 @@ package exopandora.worldhandler.gui.container;
import java.util.ArrayList;
import java.util.List;
import exopandora.worldhandler.gui.content.element.Element;
import exopandora.worldhandler.gui.content.element.IElement;
import exopandora.worldhandler.gui.element.Element;
import exopandora.worldhandler.gui.element.IElement;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.Widget;

View File

@@ -1,7 +1,7 @@
package exopandora.worldhandler.gui.container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.element.Element;
import exopandora.worldhandler.gui.element.Element;
import net.minecraft.client.gui.widget.Widget;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

View File

@@ -23,10 +23,10 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.IContent;
import exopandora.worldhandler.gui.content.element.IElement;
import exopandora.worldhandler.gui.element.IElement;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.ResourceHelper;
import exopandora.worldhandler.text.TextFormatting;
import exopandora.worldhandler.util.TextFormatting;
import exopandora.worldhandler.util.UtilRender;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.Widget;
@@ -139,32 +139,33 @@ public class GuiWorldHandler extends Container
});
this.updateNameField();
final int backgroundX = this.getBackgroundX();
final int backgroundY = this.getBackgroundY();
this.forEachTab((index, xOffset) ->
{
IContent tab = this.content.getCategory().getContent(index);
if(!this.content.getActiveContent().equals(tab))
{
this.finalButtons.add(new GuiButtonTab((int) (backgroundX + xOffset), backgroundY - 20, (int) this.tabWidth + (int) Math.ceil(this.tabEpsilon / this.tabSize), 21, tab.getTabTitle())
{
@Override
public void onPress()
{
ActionHelper.changeTab(GuiWorldHandler.this.content, index);
}
});
}
});
//BUTTONS
this.forEachTab(this::addTabButtons);
this.initButtons();
});
}
private void addTabButtons(int index, double xOffset)
{
final int backgroundX = this.getBackgroundX();
final int backgroundY = this.getBackgroundY();
IContent tab = this.content.getCategory().getContent(index);
if(!tab.equals(this.content.getActiveContent()))
{
this.finalButtons.add(new GuiButtonTab((int) (backgroundX + xOffset), backgroundY - 20, (int) this.tabWidth + (int) Math.ceil(this.tabEpsilon / this.tabSize), 21, tab.getTabTitle())
{
@Override
public void onPress()
{
ActionHelper.changeTab(GuiWorldHandler.this.content, index);
}
});
}
}
public void initButtons()
{
this.buttons.clear();
@@ -374,118 +375,7 @@ public class GuiWorldHandler extends Container
//TABS
this.forEachTab((index, xOffset) ->
{
IContent tab = this.content.getCategory().getContent(index);
int yOffset;
int fHeight;
int color;
if(this.content.getActiveContent().equals(tab))
{
yOffset = -22;
fHeight = 25;
color = 0xFFFFFF;
this.defaultColor();
}
else
{
yOffset = -20;
fHeight = 20;
color = 0xE0E0E0;
this.darkColor();
}
this.bindBackground();
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset), 0, 0, (int) Math.ceil(this.tabHalf), fHeight);
this.blit((int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY + yOffset), this.bgTextureWidth - (int) Math.ceil(this.tabHalf), 0, (int) Math.ceil(this.tabHalf), fHeight);
if(!Config.getSkin().sharpEdges())
{
if(this.content.getActiveContent().equals(tab))
{
//RIGHT TAB CURVATURE
if(index < this.tabSize - 1 || this.tabSize == 1)
{
int factor = 2;
for(int x = 0; x < factor; x++)
{
this.blit((int) (backgroundX + this.tabWidth + xOffset - x - 1), (int) (backgroundY + x + 1), (int) (this.tabWidth - x - 1), x + 1, x + 1, 1);
}
}
//LEFT TAB CURVATURE
if(index > 0)
{
int factor = 2;
for(int x = 0; x < factor; x++)
{
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + x + 1), xOffset.intValue(), x + 1, x + 1, 1);
}
}
int width = (int)(this.tabWidth - 3);
int interval = 5;
//LEFT GRADIENT
if(index == 0)
{
for(int x = 0; x < width; x += interval)
{
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset + fHeight + x / interval), 0, fHeight, width - x, 1);
}
}
//RIGHT GRADIENT
if(index == this.tabSize - 1 && this.tabSize > 1)
{
int offset = 3;
for(int x = 0; x < width; x += interval)
{
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
this.blit((int) (backgroundX + Math.ceil(xOffset) + x + offset), (int) (backgroundY + yOffset + fHeight + x / interval), this.bgTextureWidth - width + x, fHeight, width - x, 1);
}
}
}
else
{
//LEFT CORNER FILLER
if(index == 0)
{
int factor = 2;
for(int x = 0; x < factor; x++)
{
this.blit(backgroundX, backgroundY + x, 0, fHeight, factor - x, 1);
}
}
//RIGHT CORNER FILLER
if(index == this.tabSize - 1)
{
int factor = 3;
for(int x = 0; x < factor + 1; x++)
{
this.blit(backgroundX + this.bgTextureWidth - x, backgroundY + factor - x, this.bgTextureWidth - x, fHeight, x, 1);
}
}
}
}
this.drawCenteredString(this.font, net.minecraft.util.text.TextFormatting.UNDERLINE + tab.getTabTitle(), (int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY - 13), color);
});
this.forEachTab(this::drawTab);
this.defaultColor();
//VERSION LABEL
@@ -608,6 +498,122 @@ public class GuiWorldHandler extends Container
});
}
private void drawTab(int index, Double xOffset)
{
final IContent tab = this.content.getCategory().getContent(index);
final int backgroundX = this.getBackgroundX();
final int backgroundY = this.getBackgroundY();
int yOffset;
int fHeight;
int color;
if(this.content.getActiveContent().equals(tab))
{
yOffset = -22;
fHeight = 25;
color = 0xFFFFFF;
this.defaultColor();
}
else
{
yOffset = -20;
fHeight = 20;
color = 0xE0E0E0;
this.darkColor();
}
this.bindBackground();
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset), 0, 0, (int) Math.ceil(this.tabHalf), fHeight);
this.blit((int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY + yOffset), this.bgTextureWidth - (int) Math.floor(this.tabHalf + 1), 0, (int) Math.floor(this.tabHalf + 1), fHeight);
if(!Config.getSkin().sharpEdges())
{
if(this.content.getActiveContent().equals(tab))
{
//RIGHT TAB CURVATURE
if(index < this.tabSize - 1 || this.tabSize == 1)
{
int factor = 2;
for(int x = 0; x < factor; x++)
{
this.blit((int) (backgroundX + xOffset - x - 1 + Math.floor(this.tabHalf + 1) + this.tabHalf), (int) (backgroundY + x + 1), (int) (this.tabWidth - x - 1), x + 1, x + 1, 1);
}
}
//LEFT TAB CURVATURE
if(index > 0)
{
int factor = 2;
for(int x = 0; x < factor; x++)
{
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + x + 1), xOffset.intValue(), x + 1, x + 1, 1);
}
}
int width = (int)(this.tabWidth - 3);
int interval = 5;
//LEFT GRADIENT
if(index == 0)
{
for(int x = 0; x < width; x += interval)
{
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset + fHeight + x / interval), 0, fHeight, width - x, 1);
}
}
//RIGHT GRADIENT
if(index == this.tabSize - 1 && this.tabSize > 1)
{
int offset = 3;
for(int x = 0; x < width; x += interval)
{
this.defaultColor(1.0F - (x / (width + 5.0F * interval)));
this.blit((int) (backgroundX + Math.ceil(xOffset) + x + offset), (int) (backgroundY + yOffset + fHeight + x / interval), this.bgTextureWidth - width + x, fHeight, width - x, 1);
}
}
}
else
{
//LEFT CORNER FILLER
if(index == 0)
{
int factor = 2;
for(int x = 0; x < factor; x++)
{
this.blit(backgroundX, backgroundY + x, 0, fHeight, factor - x, 1);
}
}
//RIGHT CORNER FILLER
if(index == this.tabSize - 1)
{
int factor = 3;
for(int x = 0; x < factor + 1; x++)
{
this.blit(backgroundX + this.bgTextureWidth - x, backgroundY + factor - x, this.bgTextureWidth - x, fHeight, x, 1);
}
}
}
}
this.drawCenteredString(this.font, TextFormatting.shortenString(net.minecraft.util.text.TextFormatting.UNDERLINE + tab.getTabTitle(), (int) this.tabWidth, this.font), (int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY - 13), color);
}
@Override
public boolean charTyped(char charTyped, int keyCode)
{

View File

@@ -28,8 +28,11 @@ import exopandora.worldhandler.gui.content.impl.ContentScoreboardTeams;
import exopandora.worldhandler.gui.content.impl.ContentSettings;
import exopandora.worldhandler.gui.content.impl.ContentSignEditor;
import exopandora.worldhandler.gui.content.impl.ContentSummon;
import exopandora.worldhandler.gui.content.impl.ContentUsercontent;
import exopandora.worldhandler.gui.content.impl.ContentWorldInfo;
import exopandora.worldhandler.helper.RegistryHelper;
import exopandora.worldhandler.usercontent.UsercontentConfig;
import exopandora.worldhandler.usercontent.UsercontentLoader;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -100,6 +103,21 @@ public abstract class Content extends ForgeRegistryEntry<Content> implements ICo
RegistryHelper.register(event.getRegistry(), "butcher", new ContentButcher());
RegistryHelper.register(event.getRegistry(), "butcher_settings", new ContentButcherSettings());
RegistryHelper.register(event.getRegistry(), "settings", new ContentSettings());
//USERCONTENT
UsercontentLoader.CONFIGS.forEach(config -> Content.registerContent(event.getRegistry(), config));
}
private static void registerContent(IForgeRegistry<Content> registry, UsercontentConfig config)
{
try
{
RegistryHelper.register(registry, config.getId(), new ContentUsercontent(config));
}
catch(Exception e)
{
throw new RuntimeException("Error loading js for usercontent: " + config.getId(), e);
}
}
private Map<String, Object> persistence;

View File

@@ -1,8 +1,8 @@
package exopandora.worldhandler.gui.content;
import exopandora.worldhandler.Main;
import exopandora.worldhandler.gui.content.impl.ContentChild;
import exopandora.worldhandler.gui.content.impl.ContentContinue;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -79,15 +79,20 @@ public class Contents
SETTINGS = (ContentChild) Contents.getRegisteredContent("settings");
}
private static Content getRegisteredContent(String name)
public static Content getRegisteredContent(String name)
{
Content content = Content.REGISTRY.getValue(new ResourceLocation(Main.MODID, name));
if(content == null)
{
throw new IllegalStateException("Invalid Content requested: " + name);
throw new IllegalStateException("Requested missing content: " + name);
}
return content;
}
public static boolean isRegistered(String name)
{
return Content.REGISTRY.containsKey(new ResourceLocation(Main.MODID, name));
}
}

View File

@@ -17,7 +17,7 @@ import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicMapped;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.helper.ActionHelper;

View File

@@ -8,7 +8,6 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;
import net.minecraft.client.Minecraft;

View File

@@ -7,8 +7,7 @@ import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.util.ActionHandler;

View File

@@ -2,7 +2,6 @@ package exopandora.worldhandler.gui.content.impl;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import exopandora.worldhandler.helper.ActionHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.ConnectingScreen;

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.impl.abstr;
package exopandora.worldhandler.gui.content.impl;
import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.content.Content;

View File

@@ -6,7 +6,6 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.container.impl.GuiWorldHandler;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;
import net.minecraft.client.Minecraft;

View File

@@ -9,8 +9,8 @@ import com.google.common.base.Predicates;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.builder.impl.BuilderCustomItem;
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiSlider;
@@ -20,8 +20,8 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementColorMenu;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.element.impl.ElementColorMenu;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.gui.logic.LogicSliderAttribute;
import exopandora.worldhandler.gui.logic.LogicSliderSimple;

View File

@@ -12,7 +12,7 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
import exopandora.worldhandler.helper.ActionHelper;

View File

@@ -18,7 +18,7 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;

View File

@@ -11,8 +11,7 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
import exopandora.worldhandler.gui.button.GuiSlider;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
import exopandora.worldhandler.helper.ActionHelper;

View File

@@ -13,7 +13,7 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.impl.abstr;
package exopandora.worldhandler.gui.content.impl;
import exopandora.worldhandler.gui.category.Categories;
import exopandora.worldhandler.gui.category.Category;

View File

@@ -15,8 +15,7 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementMultiButtonList;
import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard;
import exopandora.worldhandler.gui.element.impl.ElementMultiButtonList;
import exopandora.worldhandler.gui.logic.ILogicClickList;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;

View File

@@ -16,7 +16,6 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard;
import exopandora.worldhandler.gui.logic.LogicSliderSimple;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;

View File

@@ -13,8 +13,7 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementMultiButtonList;
import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard;
import exopandora.worldhandler.gui.element.impl.ElementMultiButtonList;
import exopandora.worldhandler.gui.logic.ILogicClickList;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.CommandHelper;

View File

@@ -10,10 +10,9 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonTooltip;
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.BooleanSetting;
import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.IntegerSetting;
import exopandora.worldhandler.gui.content.impl.abstr.ContentChild;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.util.ActionHandler;

View File

@@ -15,7 +15,7 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementColorMenu;
import exopandora.worldhandler.gui.element.impl.ElementColorMenu;
import exopandora.worldhandler.gui.logic.ILogicColorMenu;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.helper.BlockHelper;

View File

@@ -11,8 +11,8 @@ import com.google.common.base.Predicates;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.builder.impl.BuilderSummon;
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonItem;
@@ -23,7 +23,7 @@ import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.gui.content.element.impl.ElementPageList;
import exopandora.worldhandler.gui.element.impl.ElementPageList;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.gui.logic.LogicSliderAttribute;
import exopandora.worldhandler.gui.logic.LogicSliderSimple;

View File

@@ -0,0 +1,261 @@
package exopandora.worldhandler.gui.content.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import exopandora.worldhandler.Main;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.ICommandBuilder;
import exopandora.worldhandler.builder.impl.BuilderMultiCommand;
import exopandora.worldhandler.builder.impl.BuilderUsercontent;
import exopandora.worldhandler.gui.category.Categories;
import exopandora.worldhandler.gui.category.Category;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.usercontent.ScriptEngineAdapter;
import exopandora.worldhandler.usercontent.UsercontentAPI;
import exopandora.worldhandler.usercontent.UsercontentConfig;
import exopandora.worldhandler.usercontent.VisibleActiveObject;
import exopandora.worldhandler.usercontent.VisibleObject;
import exopandora.worldhandler.usercontent.factory.ActionHandlerFactory;
import exopandora.worldhandler.usercontent.factory.ButtonFactory;
import exopandora.worldhandler.usercontent.factory.ElementFactory;
import exopandora.worldhandler.usercontent.model.JsonButton;
import exopandora.worldhandler.usercontent.model.JsonCommand;
import exopandora.worldhandler.usercontent.model.JsonElement;
import exopandora.worldhandler.usercontent.model.JsonModel;
import exopandora.worldhandler.usercontent.model.JsonText;
import exopandora.worldhandler.usercontent.model.JsonUsercontent;
import exopandora.worldhandler.usercontent.model.JsonWidget;
import exopandora.worldhandler.util.TextFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.Widget;
import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class ContentUsercontent extends Content
{
private final String id;
private final JsonUsercontent content;
private final ScriptEngineAdapter engineAdapter;
private final List<VisibleObject<BuilderUsercontent>> builders;
private final Map<String, VisibleActiveObject<TextFieldWidget>> textfields = new HashMap<String, VisibleActiveObject<TextFieldWidget>>();
private final List<VisibleActiveObject<Widget>> buttons = new ArrayList<VisibleActiveObject<Widget>>();
private UsercontentAPI api;
private ButtonFactory buttonFactory;
private ElementFactory elementFactory;
public ContentUsercontent(UsercontentConfig config) throws Exception
{
this.id = config.getId();
this.content = config.getContent();
this.engineAdapter = new ScriptEngineAdapter(config.getScriptEngine());
this.builders = this.createBuilders(this.content.getModel());
this.api = new UsercontentAPI(this.builders.stream().map(VisibleObject::getObject).collect(Collectors.toList()));
ActionHandlerFactory actionHandlerFactory = new ActionHandlerFactory(this.api,this. builders, this.engineAdapter);
this.buttonFactory = new ButtonFactory(this.api, actionHandlerFactory);
this.elementFactory = new ElementFactory(this.api, actionHandlerFactory);
this.engineAdapter.addObject("api", this.api);
this.engineAdapter.eval(config.getJs());
}
@Override
public ICommandBuilder getCommandBuilder()
{
ICommandBuilder[] builders = this.builders.stream()
.filter(builder -> builder.isVisible(this.engineAdapter))
.map(VisibleObject::getObject)
.toArray(ICommandBuilder[]::new);
return builders.length > 0 ? new BuilderMultiCommand(builders) : null;
}
@Override
public void initGui(Container container, int x, int y)
{
this.textfields.clear();
this.buttons.clear();
for(JsonButton button : this.getWidgets(this.content.getGui().getButtons(), JsonWidget.Type.BUTTON))
{
Widget widget = this.buttonFactory.createButton(button, this, container, x, y);
if(JsonButton.Type.TEXTFIELD.equals(button.getType()))
{
VisibleActiveObject<TextFieldWidget> visObj = new VisibleActiveObject<TextFieldWidget>(button, (TextFieldWidget) widget);
this.textfields.put(button.getAttributes().getId(), visObj);
}
else
{
this.buttons.add(new VisibleActiveObject<Widget>(button, widget));
}
}
for(JsonElement element : this.getWidgets(this.content.getGui().getElements(), JsonWidget.Type.ELEMENT))
{
container.add(this.elementFactory.createElement(element, this, container, x, y));
}
this.updateTextfields();
this.updateButtons();
}
@Override
public void initButtons(Container container, int x, int y)
{
this.textfields.values().stream().map(VisibleObject::getObject).forEach(container::add);
this.buttons.stream().map(VisibleObject::getObject).forEach(container::add);
}
@Override
public void tick(Container container)
{
for(VisibleObject<TextFieldWidget> textfield : this.textfields.values())
{
if(textfield.isVisible(this.engineAdapter))
{
textfield.getObject().tick();
}
}
this.updateButtons();
this.updateTextfields();
}
@Override
public void drawScreen(Container container, int x, int y, int mouseX, int mouseY, float partialTicks)
{
for(VisibleObject<TextFieldWidget> textfield : this.textfields.values())
{
if(textfield.getObject().visible)
{
textfield.getObject().renderButton(mouseX, mouseY, partialTicks);
}
}
if(this.content.getGui() != null && this.content.getGui().getTexts() != null)
{
for(JsonText text : this.content.getGui().getTexts())
{
container.getMinecraft().fontRenderer.drawString(TextFormatting.formatNullable(text.getText()), text.getX() + x, text.getY() + y, text.getColor());
}
}
}
@Override
public Category getCategory()
{
return Categories.getRegisteredCategory(this.content.getGui().getTab().getCategory());
}
@Override
public String getTitle()
{
return TextFormatting.formatNullable(this.content.getGui().getTitle());
}
@Override
public String getTabTitle()
{
return TextFormatting.formatNullable(this.content.getGui().getTab().getTitle());
}
@Override
public Content getActiveContent()
{
if(this.content.getGui().getTab().getActiveContent() == null)
{
return this;
}
return Contents.getRegisteredContent(this.content.getGui().getTab().getActiveContent());
}
@Override
public void onPlayerNameChanged(String username)
{
for(VisibleObject<BuilderUsercontent> visObj : this.builders)
{
visObj.getObject().setPlayerName(username);
}
}
private List<VisibleObject<BuilderUsercontent>> createBuilders(JsonModel model)
{
List<VisibleObject<BuilderUsercontent>> builders = new ArrayList<VisibleObject<BuilderUsercontent>>();
if(model != null && model.getCommands() != null)
{
for(JsonCommand command : model.getCommands())
{
if(command.getName() != null && command.getSyntax() != null)
{
BuilderUsercontent builder = new BuilderUsercontent(command.getName(), new CommandSyntax(command.getSyntax()));
builders.add(new VisibleObject<BuilderUsercontent>(command.getVisible(), builder));
}
}
}
return builders;
}
private <T extends JsonWidget<?>> List<T> getWidgets(List<T> list, JsonWidget.Type type)
{
List<T> result = new ArrayList<T>();
if(list == null)
{
return result;
}
for(int x = 0; x < list.size(); x++)
{
T widget = list.get(x);
try
{
widget.validate();
result.add(widget);
}
catch(Exception e)
{
this.printError(type.toString().toLowerCase(), x, e);
}
}
return result;
}
private void printError(String type, int index, Throwable e)
{
ITextComponent message = new StringTextComponent(net.minecraft.util.text.TextFormatting.RED + "<" + Main.NAME + ":" + this.id + ":" + type + ":" + index + "> " + e.getMessage());
Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.CHAT, message);
}
private void updateTextfields()
{
for(VisibleActiveObject<TextFieldWidget> visObj : this.textfields.values())
{
visObj.getObject().setEnabled(visObj.isEnabled(this.engineAdapter));
visObj.getObject().visible = visObj.isVisible(this.engineAdapter);
}
}
private void updateButtons()
{
for(VisibleActiveObject<Widget> visObj : this.buttons)
{
visObj.getObject().active = visObj.isEnabled(this.engineAdapter);
visObj.getObject().visible = visObj.isVisible(this.engineAdapter);
}
}
}

View File

@@ -10,7 +10,7 @@ import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.gui.content.Contents;
import exopandora.worldhandler.helper.ActionHelper;
import exopandora.worldhandler.text.TextFormatting;
import exopandora.worldhandler.util.TextFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.world.World;

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.element;
package exopandora.worldhandler.gui.element;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.element;
package exopandora.worldhandler.gui.element;
import exopandora.worldhandler.gui.container.Container;
import net.minecraftforge.api.distmarker.Dist;

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.element.impl;
package exopandora.worldhandler.gui.element.impl;
import java.util.ArrayList;
import java.util.List;
@@ -7,10 +7,10 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonList;
import exopandora.worldhandler.gui.button.GuiTextFieldTooltip;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.element.Element;
import exopandora.worldhandler.gui.element.Element;
import exopandora.worldhandler.gui.logic.ILogicColorMenu;
import exopandora.worldhandler.gui.logic.ILogicMapped;
import exopandora.worldhandler.text.MutableStringTextComponent;
import exopandora.worldhandler.util.MutableStringTextComponent;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.api.distmarker.Dist;

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.element.impl;
package exopandora.worldhandler.gui.element.impl;
import java.util.ArrayList;
import java.util.Collections;
@@ -11,7 +11,7 @@ import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.button.GuiButtonList;
import exopandora.worldhandler.gui.button.GuiButtonList.Persistence;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.element.Element;
import exopandora.worldhandler.gui.element.Element;
import exopandora.worldhandler.gui.logic.ILogicClickList;
import exopandora.worldhandler.gui.logic.ILogicMapped;
import exopandora.worldhandler.helper.Node;
@@ -75,7 +75,7 @@ public class ElementMultiButtonList extends Element
public void onClick(Node item)
{
ElementMultiButtonList.this.getPersistence(container, 1).setIndex(0);
container.initButtons();
container.init();
}
@Override

View File

@@ -1,4 +1,4 @@
package exopandora.worldhandler.gui.content.element.impl;
package exopandora.worldhandler.gui.element.impl;
import java.util.List;
import java.util.Objects;
@@ -6,9 +6,9 @@ import java.util.Objects;
import exopandora.worldhandler.config.Config;
import exopandora.worldhandler.gui.button.GuiButtonBase;
import exopandora.worldhandler.gui.container.Container;
import exopandora.worldhandler.gui.content.element.Element;
import exopandora.worldhandler.gui.element.Element;
import exopandora.worldhandler.gui.logic.ILogicPageList;
import exopandora.worldhandler.text.TextFormatting;
import exopandora.worldhandler.util.TextFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraftforge.api.distmarker.Dist;
@@ -143,7 +143,7 @@ public class ElementPageList<T> extends Element
private int getTotalPages()
{
return (int) Math.ceil((float) this.items.size() / this.length);
return Math.max((int) Math.ceil((float) this.items.size() / this.length), 1);
}
@OnlyIn(Dist.CLIENT)

View File

@@ -22,4 +22,9 @@ public interface ILogicMapped<T> extends ILogic
}
void onClick(T item);
default void onInit(T item)
{
}
}

View File

@@ -2,7 +2,7 @@ package exopandora.worldhandler.gui.logic;
import java.util.function.Consumer;
import exopandora.worldhandler.builder.impl.abstr.EnumAttributes;
import exopandora.worldhandler.builder.impl.EnumAttributes;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;