mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-17 19:15:24 +00:00
Improve/refactoring (#15)
* Improve the code * Code improve in binnie.core.utils package * Code improve in binnie.core.triggers package * Code improve in binnie.core.resource package * Code improve in binnie.core.proxy package * Code improve readability in binnie.core package * Add missed constructors * Some improve code readabilty * Expand import with * * Revert "Expand import with *" This reverts commit 3bb4a44f3b69a8559bd5753337e0f6793ad18dc4. * Fix using fully qualified names in imports * Fix missed unnessesary "this." * Removed binnie.craftgui package Optimised imports and removed unnessesary "this." * Some refactoring code in binnie.core.craftgui package * Merge from master1.7.10 * Improve code readability in binnie.core.craftgui.database package * Improve code readability in binnie.core.craftgui.events package * Improve code readability in binnie.core.craftgui.geometry package * Improve code readability in binnie.core.craftgui.* package
This commit is contained in:
1 parent
a3c2360ba6
commit
f402cb155f
428 files changed
+9515
-10103
No files matched your search
@@ -5,9 +5,9 @@
|
||||
package binnie.botany.core;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import binnie.craftgui.botany.WindowBotanistDatabase;
|
||||
import binnie.botany.craftgui.WindowBotanistDatabase;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import binnie.craftgui.minecraft.Window;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
+9
-9
@@ -2,16 +2,16 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import binnie.craftgui.core.Tooltip;
|
||||
import binnie.craftgui.core.CraftGUI;
|
||||
import binnie.craftgui.core.Attribute;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.core.ITooltip;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.craftgui.controls.core.IControlValue;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
|
||||
public class ControlColourDisplay extends Control implements IControlValue<IFlowerColour>, ITooltip
|
||||
{
|
||||
@@ -19,7 +19,7 @@ public class ControlColourDisplay extends Control implements IControlValue<IFlow
|
||||
|
||||
public ControlColourDisplay(final IWidget parent, final float x, final float y) {
|
||||
super(parent, x, y, 16.0f, 16.0f);
|
||||
this.addAttribute(Attribute.MouseOver);
|
||||
this.addAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
|
||||
@Override
|
||||
+5
-5
@@ -2,13 +2,13 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import binnie.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.craftgui.controls.listbox.ControlList;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.core.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.botany.api.IColourMix;
|
||||
import binnie.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
|
||||
public class ControlColourMixBox extends ControlListBox<IColourMix>
|
||||
{
|
||||
+4
-4
@@ -2,13 +2,13 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import binnie.craftgui.mod.database.WindowAbstractDatabase;
|
||||
import binnie.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.database.WindowAbstractDatabase;
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.botany.api.IColourMix;
|
||||
import binnie.craftgui.controls.listbox.ControlOption;
|
||||
import binnie.core.craftgui.controls.listbox.ControlOption;
|
||||
|
||||
public class ControlColourMixItem extends ControlOption<IColourMix>
|
||||
{
|
||||
+13
-13
@@ -2,19 +2,19 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import binnie.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.craftgui.resource.minecraft.CraftGUITextureSheet;
|
||||
import binnie.craftgui.core.Tooltip;
|
||||
import binnie.craftgui.core.Attribute;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.core.geometry.IPoint;
|
||||
import binnie.craftgui.core.CraftGUI;
|
||||
import binnie.core.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITextureSheet;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.botany.api.IColourMix;
|
||||
import binnie.craftgui.resource.Texture;
|
||||
import binnie.craftgui.core.ITooltip;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.resource.Texture;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
|
||||
public class ControlColourMixSymbol extends Control implements ITooltip
|
||||
{
|
||||
@@ -38,12 +38,12 @@ public class ControlColourMixSymbol extends Control implements ITooltip
|
||||
super(parent, x, y, 16 + type * 16, 16.0f);
|
||||
this.value = null;
|
||||
this.type = type;
|
||||
this.addAttribute(Attribute.MouseOver);
|
||||
this.addAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
|
||||
public void setValue(final IColourMix value) {
|
||||
this.value = value;
|
||||
this.setColour(16777215);
|
||||
this.setColor(16777215);
|
||||
}
|
||||
|
||||
@Override
|
||||
+8
-8
@@ -2,15 +2,15 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import binnie.craftgui.core.CraftGUI;
|
||||
import binnie.craftgui.core.geometry.CraftGUIUtil;
|
||||
import binnie.craftgui.core.Attribute;
|
||||
import binnie.craftgui.controls.listbox.ControlList;
|
||||
import binnie.craftgui.core.geometry.IPoint;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.geometry.CraftGUIUtil;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.craftgui.controls.listbox.ControlTextOption;
|
||||
import binnie.core.craftgui.controls.listbox.ControlTextOption;
|
||||
|
||||
public class ControlColourOption extends ControlTextOption<IFlowerColour>
|
||||
{
|
||||
@@ -21,7 +21,7 @@ public class ControlColourOption extends ControlTextOption<IFlowerColour>
|
||||
super(controlList, option, option.getName(), y);
|
||||
this.setSize(new IPoint(this.getSize().x(), 20.0f));
|
||||
(this.controlBee = new ControlColourDisplay(this, 2.0f, 2.0f)).setValue(option);
|
||||
this.addAttribute(Attribute.MouseOver);
|
||||
this.addAttribute(WidgetAttribute.MouseOver);
|
||||
CraftGUIUtil.moveWidget(this.textWidget, new IPoint(22.0f, 0.0f));
|
||||
this.textWidget.setSize(this.textWidget.getSize().sub(new IPoint(24.0f, 0.0f)));
|
||||
final int th = (int) CraftGUI.Render.textHeight(this.textWidget.getValue(), this.textWidget.getSize().x());
|
||||
+6
-6
@@ -2,18 +2,18 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import java.util.List;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.api.IColourMix;
|
||||
import java.util.ArrayList;
|
||||
import binnie.craftgui.controls.ControlTextCentered;
|
||||
import binnie.craftgui.mod.database.DatabaseTab;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import binnie.core.craftgui.database.DatabaseTab;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.craftgui.mod.database.PageAbstract;
|
||||
import binnie.core.craftgui.database.PageAbstract;
|
||||
|
||||
public class PageColourMix extends PageAbstract<IFlowerColour>
|
||||
{
|
||||
+6
-6
@@ -2,18 +2,18 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import java.util.List;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import binnie.botany.api.IColourMix;
|
||||
import java.util.ArrayList;
|
||||
import binnie.craftgui.controls.ControlTextCentered;
|
||||
import binnie.craftgui.mod.database.DatabaseTab;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import binnie.core.craftgui.database.DatabaseTab;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.craftgui.mod.database.PageAbstract;
|
||||
import binnie.core.craftgui.database.PageAbstract;
|
||||
|
||||
public class PageColourMixResultant extends PageAbstract<IFlowerColour>
|
||||
{
|
||||
+11
-12
@@ -2,30 +2,29 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import binnie.botany.api.IAlleleFlowerSpecies;
|
||||
import binnie.botany.api.IFlowerGenome;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import binnie.craftgui.core.geometry.IPoint;
|
||||
import binnie.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import binnie.botany.api.EnumFlowerStage;
|
||||
import binnie.botany.api.IFlower;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import binnie.botany.core.BotanyCore;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import binnie.botany.api.EnumFlowerChromosome;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
import binnie.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.craftgui.core.geometry.TextJustification;
|
||||
import binnie.craftgui.core.geometry.IArea;
|
||||
import binnie.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.Binnie;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import binnie.craftgui.mod.database.DatabaseTab;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.mod.database.PageSpecies;
|
||||
import binnie.core.craftgui.database.DatabaseTab;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.database.PageSpecies;
|
||||
|
||||
public class PageSpeciesFlowerGenome extends PageSpecies
|
||||
{
|
||||
+24
-23
@@ -2,33 +2,34 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.botany;
|
||||
package binnie.botany.craftgui;
|
||||
|
||||
import binnie.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.craftgui.mod.database.PageBreeder;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import binnie.craftgui.controls.listbox.ControlList;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.craftgui.core.geometry.IArea;
|
||||
import binnie.craftgui.mod.database.PageBranchSpecies;
|
||||
import binnie.craftgui.mod.database.PageBranchOverview;
|
||||
import binnie.craftgui.mod.database.PageSpeciesMutations;
|
||||
import binnie.craftgui.mod.database.PageSpeciesResultant;
|
||||
import binnie.craftgui.mod.database.PageSpeciesClassification;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.core.AbstractMod;
|
||||
import binnie.craftgui.mod.database.DatabaseTab;
|
||||
import binnie.botany.Botany;
|
||||
import binnie.craftgui.mod.database.IDatabaseMode;
|
||||
import binnie.craftgui.mod.database.PageSpeciesOverview;
|
||||
import binnie.craftgui.minecraft.Window;
|
||||
import binnie.Binnie;
|
||||
import binnie.botany.Botany;
|
||||
import binnie.botany.api.IFlowerColour;
|
||||
import binnie.botany.genetics.EnumFlowerColor;
|
||||
import binnie.core.AbstractMod;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.core.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.core.craftgui.database.DatabaseTab;
|
||||
import binnie.core.craftgui.database.IDatabaseMode;
|
||||
import binnie.core.craftgui.database.PageBranchOverview;
|
||||
import binnie.core.craftgui.database.PageBranchSpecies;
|
||||
import binnie.core.craftgui.database.PageBreeder;
|
||||
import binnie.core.craftgui.database.PageSpeciesClassification;
|
||||
import binnie.core.craftgui.database.PageSpeciesMutations;
|
||||
import binnie.core.craftgui.database.PageSpeciesOverview;
|
||||
import binnie.core.craftgui.database.PageSpeciesResultant;
|
||||
import binnie.core.craftgui.database.WindowAbstractDatabase;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import binnie.botany.genetics.EnumFlowerColor;
|
||||
import binnie.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.craftgui.mod.database.WindowAbstractDatabase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WindowBotanistDatabase extends WindowAbstractDatabase
|
||||
{
|
||||
@@ -25,8 +25,8 @@ public abstract class AbstractMod implements IPacketProvider, IInitializable {
|
||||
protected List<IInitializable> modules;
|
||||
|
||||
public AbstractMod() {
|
||||
this.fields = new LinkedHashSet<>();
|
||||
this.modules = new ArrayList<>();
|
||||
fields = new LinkedHashSet<>();
|
||||
modules = new ArrayList<>();
|
||||
BinnieCore.registerMod(this);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public abstract class AbstractMod implements IPacketProvider, IInitializable {
|
||||
for (IInitializable module : modules) {
|
||||
Collections.addAll(fields, module.getClass().getFields());
|
||||
}
|
||||
for (Field field4 : this.fields) {
|
||||
for (Field field4 : fields) {
|
||||
try {
|
||||
FieldParser.preInitParse(field4, this);
|
||||
} catch (Exception e) {
|
||||
@@ -100,14 +100,14 @@ public abstract class AbstractMod implements IPacketProvider, IInitializable {
|
||||
}
|
||||
getProxy().init();
|
||||
|
||||
wrapper = NetworkRegistry.INSTANCE.newSimpleChannel(this.getChannel());
|
||||
wrapper = NetworkRegistry.INSTANCE.newSimpleChannel(getChannel());
|
||||
wrapper.registerMessage(getPacketHandler(), MessageBinnie.class, 1, Side.CLIENT);
|
||||
wrapper.registerMessage(getPacketHandler(), MessageBinnie.class, 1, Side.SERVER);
|
||||
for (IInitializable module : this.modules) {
|
||||
for (IInitializable module : modules) {
|
||||
module.init();
|
||||
}
|
||||
|
||||
for (Field field : this.fields) {
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
FieldParser.initParse(field, this);
|
||||
} catch (Exception e) {
|
||||
@@ -123,11 +123,11 @@ public abstract class AbstractMod implements IPacketProvider, IInitializable {
|
||||
}
|
||||
|
||||
getProxy().postInit();
|
||||
for (IInitializable module : this.modules) {
|
||||
for (IInitializable module : modules) {
|
||||
module.postInit();
|
||||
}
|
||||
|
||||
for (Field field : this.fields) {
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
FieldParser.postInitParse(field, this);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package binnie.core;
|
||||
import binnie.Binnie;
|
||||
import binnie.core.block.MultipassBlockRenderer;
|
||||
import binnie.core.block.TileEntityMetadata;
|
||||
import binnie.core.craftgui.minecraft.ModuleCraftGUI;
|
||||
import binnie.core.gui.BinnieCoreGUI;
|
||||
import binnie.core.gui.BinnieGUIHandler;
|
||||
import binnie.core.gui.IBinnieGUID;
|
||||
@@ -23,7 +24,6 @@ import binnie.core.network.IPacketID;
|
||||
import binnie.core.proxy.BinnieProxy;
|
||||
import binnie.core.proxy.IBinnieProxy;
|
||||
import binnie.core.triggers.ModuleTrigger;
|
||||
import binnie.craftgui.minecraft.ModuleCraftGUI;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
|
||||
@@ -60,27 +60,27 @@ public class Mods {
|
||||
}
|
||||
|
||||
public Item item(String name) {
|
||||
return findItem(this.id, name);
|
||||
return findItem(id, name);
|
||||
}
|
||||
|
||||
public Block block(String name) {
|
||||
return findBlock(this.id, name);
|
||||
return findBlock(id, name);
|
||||
}
|
||||
|
||||
public ItemStack stack(String name, int stackSize) {
|
||||
return findItemStack(this.id, name, stackSize);
|
||||
return findItemStack(id, name, stackSize);
|
||||
}
|
||||
|
||||
public ItemStack stack(String name) {
|
||||
return this.stack(name, 1);
|
||||
return stack(name, 1);
|
||||
}
|
||||
|
||||
public ItemStack stack(String string, int i, int j) {
|
||||
return new ItemStack(this.item(string), i, j);
|
||||
return new ItemStack(item(string), i, j);
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
return Loader.isModLoaded(this.id);
|
||||
return Loader.isModLoaded(id);
|
||||
}
|
||||
|
||||
public boolean dev() {
|
||||
|
||||
@@ -52,7 +52,7 @@ public class BlockMetadata extends BlockContainer implements IBlockMetadata {
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess block, int x, int y, int z, int par5) {
|
||||
int metadata = TileEntityMetadata.getTileMetadata(block, x, y, z);
|
||||
return this.getIcon(par5, metadata);
|
||||
return getIcon(par5, metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,7 +105,7 @@ public class BlockMetadata extends BlockContainer implements IBlockMetadata {
|
||||
|
||||
@Override
|
||||
public void dropAsStack(World world, int x, int y, int z, ItemStack itemStack) {
|
||||
this.dropBlockAsItem(world, x, y, z, itemStack);
|
||||
dropBlockAsItem(world, x, y, z, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.core.craftgui.renderer.Renderer;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUIResourceManager;
|
||||
|
||||
public class CraftGUI {
|
||||
public static CraftGUIResourceManager ResourceManager;
|
||||
public static Renderer Render;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
public interface ITooltip {
|
||||
void getTooltip(Tooltip tooltip);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
public interface ITooltipHelp {
|
||||
void getHelpTooltip(Tooltip tooltip);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
|
||||
public interface ITopLevelWidget extends IWidget {
|
||||
void setMousePosition(int x, int y);
|
||||
|
||||
IPoint getAbsoluteMousePosition();
|
||||
|
||||
IWidget getFocusedWidget();
|
||||
|
||||
IWidget getMousedOverWidget();
|
||||
|
||||
IWidget getDraggedWidget();
|
||||
|
||||
boolean isFocused(IWidget widget);
|
||||
|
||||
boolean isMouseOver(IWidget widget);
|
||||
|
||||
boolean isDragged(IWidget widget);
|
||||
|
||||
void updateTopLevel();
|
||||
|
||||
void widgetDeleted(IWidget widget);
|
||||
|
||||
IPoint getDragDistance();
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.core.craftgui.events.Event;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IWidget {
|
||||
IWidget getParent();
|
||||
|
||||
void deleteChild(IWidget child);
|
||||
|
||||
void deleteAllChildren();
|
||||
|
||||
ITopLevelWidget getSuperParent();
|
||||
|
||||
boolean isTopLevel();
|
||||
|
||||
IPoint getPosition();
|
||||
|
||||
IPoint pos();
|
||||
|
||||
void setPosition(IPoint position);
|
||||
|
||||
IPoint getSize();
|
||||
|
||||
IPoint size();
|
||||
|
||||
void setSize(IPoint size);
|
||||
|
||||
IPoint getOriginalPosition();
|
||||
|
||||
IPoint getAbsolutePosition();
|
||||
|
||||
IPoint getOriginalAbsolutePosition();
|
||||
|
||||
IPoint getOffset();
|
||||
|
||||
IArea getArea();
|
||||
|
||||
IArea area();
|
||||
|
||||
void setOffset(IPoint offset);
|
||||
|
||||
IPoint getMousePosition();
|
||||
|
||||
IPoint getRelativeMousePosition();
|
||||
|
||||
void setColor(int color);
|
||||
|
||||
int getColor();
|
||||
|
||||
void render();
|
||||
|
||||
void updateClient();
|
||||
|
||||
void enable();
|
||||
|
||||
void disable();
|
||||
|
||||
void show();
|
||||
|
||||
void hide();
|
||||
|
||||
boolean calculateIsMouseOver();
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
boolean isVisible();
|
||||
|
||||
boolean isFocused();
|
||||
|
||||
boolean isMouseOver();
|
||||
|
||||
boolean isDragged();
|
||||
|
||||
boolean isChildVisible(IWidget child);
|
||||
|
||||
boolean isChildEnabled(IWidget child);
|
||||
|
||||
boolean canMouseOver();
|
||||
|
||||
boolean canFocus();
|
||||
|
||||
IWidget addWidget(IWidget widget);
|
||||
|
||||
List<IWidget> getWidgets();
|
||||
|
||||
void callEvent(Event event);
|
||||
|
||||
void recieveEvent(Event event);
|
||||
|
||||
void onUpdateClient();
|
||||
|
||||
void delete();
|
||||
|
||||
void onDelete();
|
||||
|
||||
<T> T getWidget(Class<T> p0);
|
||||
|
||||
IArea getCroppedZone();
|
||||
|
||||
void setCroppedZone(IWidget relative, IArea area);
|
||||
|
||||
boolean isCroppedWidet();
|
||||
|
||||
IWidget getCropWidget();
|
||||
|
||||
boolean isMouseOverWidget(IPoint p0);
|
||||
|
||||
int getLevel();
|
||||
|
||||
boolean isDescendant(IWidget widget);
|
||||
|
||||
List<WidgetAttribute> getAttributes();
|
||||
|
||||
boolean hasAttribute(WidgetAttribute attribute);
|
||||
|
||||
boolean addAttribute(WidgetAttribute attribute);
|
||||
|
||||
<E extends Event> void addEventHandler(EventHandler<E> handler);
|
||||
|
||||
<E extends Event> void addSelfEventHandler(EventHandler<E> handler);
|
||||
|
||||
boolean contains(IPoint p0);
|
||||
|
||||
float x();
|
||||
|
||||
float y();
|
||||
|
||||
float w();
|
||||
|
||||
float h();
|
||||
|
||||
void onRender(RenderStage stage);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
public enum RenderStage {
|
||||
PreChildren,
|
||||
PostChildren,
|
||||
PostSiblings
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Tooltip {
|
||||
public int maxWidth;
|
||||
|
||||
protected List<String> tooltip;
|
||||
protected ITooltipType type;
|
||||
|
||||
public Tooltip() {
|
||||
tooltip = new ArrayList<>();
|
||||
type = Type.Standard;
|
||||
maxWidth = 256;
|
||||
}
|
||||
|
||||
public void add(String string) {
|
||||
tooltip.add(string);
|
||||
}
|
||||
|
||||
public void add(ItemStack item, String string) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
item.writeToNBT(nbt);
|
||||
nbt.setByte("nbt-type", (byte) 105);
|
||||
add("~~~" + nbt.toString() + "~~~" + string);
|
||||
}
|
||||
|
||||
public void add(FluidStack item, String string) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
item.writeToNBT(nbt);
|
||||
nbt.setByte("nbt-type", (byte) 102);
|
||||
add("~~~" + nbt.toString() + "~~~" + string);
|
||||
}
|
||||
|
||||
public boolean exists() {
|
||||
return tooltip.size() > 0;
|
||||
}
|
||||
|
||||
public String getLine(int index) {
|
||||
String string = getList().get(index);
|
||||
return string;
|
||||
}
|
||||
|
||||
public void add(List list) {
|
||||
for (Object obj : list) {
|
||||
tooltip.add((String) obj);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getList() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
public void setType(ITooltipType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setMaxWidth(int w) {
|
||||
maxWidth = w;
|
||||
}
|
||||
|
||||
public ITooltipType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public enum Type implements ITooltipType {
|
||||
Standard,
|
||||
Help,
|
||||
Information,
|
||||
User,
|
||||
Power
|
||||
}
|
||||
|
||||
public interface ITooltipType {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventWidget;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public abstract class TopLevelWidget extends Widget implements ITopLevelWidget {
|
||||
protected IWidget mousedOverWidget;
|
||||
protected IWidget draggedWidget;
|
||||
protected IWidget focusedWidget;
|
||||
protected IPoint mousePosition;
|
||||
protected IPoint dragStart;
|
||||
|
||||
public TopLevelWidget() {
|
||||
super(null);
|
||||
mousePosition = new IPoint(0.0f, 0.0f);
|
||||
dragStart = IPoint.ZERO;
|
||||
|
||||
addEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
setDraggedWidget(mousedOverWidget, event.getButton());
|
||||
setFocusedWidget(mousedOverWidget);
|
||||
}
|
||||
});
|
||||
|
||||
addEventHandler(new EventMouse.Up.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Up event) {
|
||||
setDraggedWidget(null);
|
||||
}
|
||||
});
|
||||
|
||||
addEventHandler(new EventWidget.StartDrag.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventWidget.StartDrag event) {
|
||||
dragStart = getRelativeMousePosition();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setMousedOverWidget(IWidget widget) {
|
||||
if (mousedOverWidget == widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mousedOverWidget != null) {
|
||||
callEvent(new EventWidget.EndMouseOver(mousedOverWidget));
|
||||
}
|
||||
|
||||
mousedOverWidget = widget;
|
||||
if (mousedOverWidget != null) {
|
||||
callEvent(new EventWidget.StartMouseOver(mousedOverWidget));
|
||||
}
|
||||
}
|
||||
|
||||
public void setDraggedWidget(IWidget widget) {
|
||||
setDraggedWidget(widget, -1);
|
||||
}
|
||||
|
||||
public void setDraggedWidget(IWidget widget, int button) {
|
||||
if (draggedWidget == widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (draggedWidget != null) {
|
||||
callEvent(new EventWidget.EndDrag(draggedWidget));
|
||||
}
|
||||
|
||||
draggedWidget = widget;
|
||||
if (draggedWidget != null) {
|
||||
callEvent(new EventWidget.StartDrag(draggedWidget, button));
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocusedWidget(IWidget widget) {
|
||||
IWidget newWidget = widget;
|
||||
if (focusedWidget == newWidget) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newWidget != null && !newWidget.canFocus()) {
|
||||
newWidget = null;
|
||||
}
|
||||
if (focusedWidget != null) {
|
||||
callEvent(new EventWidget.LoseFocus(focusedWidget));
|
||||
}
|
||||
|
||||
focusedWidget = newWidget;
|
||||
if (focusedWidget != null) {
|
||||
callEvent(new EventWidget.GainFocus(focusedWidget));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidget getMousedOverWidget() {
|
||||
return mousedOverWidget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidget getDraggedWidget() {
|
||||
return draggedWidget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidget getFocusedWidget() {
|
||||
return focusedWidget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(IWidget widget) {
|
||||
return getMousedOverWidget() == widget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDragged(IWidget widget) {
|
||||
return getDraggedWidget() == widget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFocused(IWidget widget) {
|
||||
return getFocusedWidget() == widget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTopLevel() {
|
||||
setMousedOverWidget(calculateMousedOverWidget());
|
||||
if (getFocusedWidget() != null && (!getFocusedWidget().isVisible() || !getFocusedWidget().isEnabled())) {
|
||||
setFocusedWidget(null);
|
||||
}
|
||||
|
||||
if (!Mouse.isButtonDown(0)) {
|
||||
if (draggedWidget != null) {
|
||||
setDraggedWidget(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IWidget calculateMousedOverWidget() {
|
||||
Deque<IWidget> queue = calculateMousedOverWidgets();
|
||||
while (!queue.isEmpty()) {
|
||||
IWidget widget = queue.removeFirst();
|
||||
if (widget.isEnabled() && widget.isVisible()) {
|
||||
if (!widget.canMouseOver()) {
|
||||
continue;
|
||||
}
|
||||
if (widget.isEnabled() && widget.isVisible() && widget.canMouseOver() && widget.calculateIsMouseOver()) {
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Deque<IWidget> calculateMousedOverWidgets() {
|
||||
Deque<IWidget> list = new ArrayDeque<>();
|
||||
for (IWidget widget : getQueuedWidgets(this)) {
|
||||
if (widget.calculateIsMouseOver()) {
|
||||
list.addLast(widget);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Collection<IWidget> getQueuedWidgets(IWidget widget) {
|
||||
List<IWidget> widgets = new ArrayList<>();
|
||||
boolean addChildren = true;
|
||||
if (widget.isCroppedWidet()) {
|
||||
addChildren = widget.getCroppedZone().contains(widget.getCropWidget().getRelativeMousePosition());
|
||||
}
|
||||
|
||||
if (addChildren) {
|
||||
ListIterator<IWidget> li = widget.getWidgets().listIterator(widget.getWidgets().size());
|
||||
while (li.hasPrevious()) {
|
||||
IWidget child = li.previous();
|
||||
widgets.addAll(getQueuedWidgets(child));
|
||||
}
|
||||
}
|
||||
widgets.add(widget);
|
||||
return widgets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMousePosition(int x, int y) {
|
||||
float dx = x - mousePosition.x();
|
||||
float dy = y - mousePosition.y();
|
||||
if (dx != 0.0f || dy != 0.0f) {
|
||||
if (getDraggedWidget() != null) {
|
||||
callEvent(new EventMouse.Drag(getDraggedWidget(), dx, dy));
|
||||
} else {
|
||||
callEvent(new EventMouse.Move(this, dx, dy));
|
||||
}
|
||||
}
|
||||
|
||||
if (mousePosition.x() != x || mousePosition.y() != y) {
|
||||
mousePosition = new IPoint(x, y);
|
||||
setMousedOverWidget(calculateMousedOverWidget());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getAbsoluteMousePosition() {
|
||||
return mousePosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDeleted(IWidget widget) {
|
||||
if (isMouseOver(widget)) {
|
||||
setMousedOverWidget(null);
|
||||
}
|
||||
if (isDragged(widget)) {
|
||||
setDraggedWidget(null);
|
||||
}
|
||||
if (isFocused(widget)) {
|
||||
setFocusedWidget(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getDragDistance() {
|
||||
return getRelativeMousePosition().sub(dragStart);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,522 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.core.craftgui.events.Event;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventWidget;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.List;
|
||||
|
||||
public class Widget implements IWidget {
|
||||
protected IArea cropArea;
|
||||
protected IWidget cropWidget;
|
||||
protected boolean cropped;
|
||||
protected int color;
|
||||
|
||||
private IWidget parent;
|
||||
private List<IWidget> subWidgets;
|
||||
private List<WidgetAttribute> attributes;
|
||||
private IPoint position;
|
||||
private IPoint size;
|
||||
private IPoint offset;
|
||||
private Collection<EventHandler> globalEventHandlers;
|
||||
private boolean enabled;
|
||||
private boolean visible;
|
||||
|
||||
public Widget(IWidget parent) {
|
||||
this.parent = null;
|
||||
subWidgets = new ArrayList<>();
|
||||
attributes = new ArrayList<>();
|
||||
position = new IPoint(0.0f, 0.0f);
|
||||
size = new IPoint(0.0f, 0.0f);
|
||||
offset = new IPoint(0.0f, 0.0f);
|
||||
cropped = false;
|
||||
color = 0xffffff;
|
||||
globalEventHandlers = new ArrayList<>();
|
||||
enabled = true;
|
||||
visible = true;
|
||||
|
||||
this.parent = parent;
|
||||
if (parent != null) {
|
||||
parent.addWidget(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WidgetAttribute> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAttribute(WidgetAttribute attribute) {
|
||||
return attributes.contains(attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAttribute(WidgetAttribute attribute) {
|
||||
return attributes.add(attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteChild(IWidget child) {
|
||||
if (child == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
child.delete();
|
||||
subWidgets.remove(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllChildren() {
|
||||
while (!subWidgets.isEmpty()) {
|
||||
deleteChild(subWidgets.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidget getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITopLevelWidget getSuperParent() {
|
||||
return (ITopLevelWidget) (isTopLevel() ? this : parent.getSuperParent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidget addWidget(IWidget widget) {
|
||||
if (subWidgets.size() != 0 && subWidgets.get(subWidgets.size() - 1).hasAttribute(WidgetAttribute.AlwaysOnTop)) {
|
||||
subWidgets.add(subWidgets.size() - 1, widget);
|
||||
} else {
|
||||
subWidgets.add(widget);
|
||||
}
|
||||
onAddChild(widget);
|
||||
return widget;
|
||||
}
|
||||
|
||||
protected void onAddChild(IWidget widget) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IWidget> getWidgets() {
|
||||
return subWidgets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTopLevel() {
|
||||
return this instanceof ITopLevelWidget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint pos() {
|
||||
return position.add(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArea area() {
|
||||
return getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getPosition() {
|
||||
return pos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArea getArea() {
|
||||
return new IArea(IPoint.ZERO, size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getOriginalPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArea getCroppedZone() {
|
||||
return cropArea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCroppedZone(IWidget relative, IArea area) {
|
||||
cropArea = area;
|
||||
cropped = true;
|
||||
cropWidget = relative;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getAbsolutePosition() {
|
||||
return isTopLevel() ? getPosition() : getParent().getAbsolutePosition().add(getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getOriginalAbsolutePosition() {
|
||||
return isTopLevel() ? getOriginalPosition() : getParent().getOriginalPosition().sub(getOriginalPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getSize() {
|
||||
return size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(IPoint position) {
|
||||
if (!position.equals(this.position)) {
|
||||
this.position = new IPoint(position);
|
||||
callEvent(new EventWidget.ChangePosition(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(IPoint size) {
|
||||
if (!size.equals(this.size)) {
|
||||
this.size = new IPoint(size);
|
||||
callEvent(new EventWidget.ChangeSize(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOffset(IPoint offset) {
|
||||
if (offset != this.offset) {
|
||||
this.offset = new IPoint(offset);
|
||||
callEvent(new EventWidget.ChangeOffset(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(int color) {
|
||||
if (this.color != color) {
|
||||
this.color = color;
|
||||
callEvent(new EventWidget.ChangeColour(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMouseOver() {
|
||||
return hasAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFocus() {
|
||||
return hasAttribute(WidgetAttribute.CanFocus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEventHandler(EventHandler handler) {
|
||||
globalEventHandlers.add(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSelfEventHandler(EventHandler handler) {
|
||||
addEventHandler(handler.setOrigin(EventHandler.Origin.Self, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callEvent(Event event) {
|
||||
getSuperParent().recieveEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveEvent(Event event) {
|
||||
for (EventHandler handler : globalEventHandlers) {
|
||||
if (handler.handles(event)) {
|
||||
handler.onEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (IWidget child : getWidgets()) {
|
||||
child.recieveEvent(event);
|
||||
}
|
||||
} catch (ConcurrentModificationException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getMousePosition() {
|
||||
return getSuperParent().getAbsoluteMousePosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPoint getRelativeMousePosition() {
|
||||
return isTopLevel() ? getMousePosition() : getParent().getRelativeMousePosition().sub(getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCroppedWidet() {
|
||||
return cropped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWidget getCropWidget() {
|
||||
return (cropWidget == null) ? this : cropWidget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if (isVisible()) {
|
||||
CraftGUI.Render.preRender(this);
|
||||
onRender(RenderStage.PreChildren);
|
||||
|
||||
for (IWidget widget : getWidgets()) {
|
||||
widget.render();
|
||||
}
|
||||
|
||||
for (IWidget widget : getWidgets()) {
|
||||
CraftGUI.Render.preRender(widget);
|
||||
widget.onRender(RenderStage.PostSiblings);
|
||||
CraftGUI.Render.postRender(widget);
|
||||
}
|
||||
|
||||
onRender(RenderStage.PostChildren);
|
||||
CraftGUI.Render.postRender(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClient() {
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getSuperParent() == this) {
|
||||
((ITopLevelWidget) this).updateTopLevel();
|
||||
}
|
||||
|
||||
onUpdateClient();
|
||||
List<IWidget> deletedWidgets = new ArrayList<IWidget>();
|
||||
for (IWidget widget : getWidgets()) {
|
||||
if (widget.hasAttribute(WidgetAttribute.NeedsDeletion)) {
|
||||
deletedWidgets.add(widget);
|
||||
} else {
|
||||
widget.updateClient();
|
||||
}
|
||||
}
|
||||
|
||||
for (IWidget widget : deletedWidgets) {
|
||||
deleteChild(widget);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean calculateIsMouseOver() {
|
||||
IPoint mouse = getRelativeMousePosition();
|
||||
if (!cropped) {
|
||||
return isMouseOverWidget(mouse);
|
||||
}
|
||||
|
||||
IWidget cropRelative = (cropWidget != null) ? cropWidget : this;
|
||||
IPoint pos = IPoint.sub(cropRelative.getAbsolutePosition(), getAbsolutePosition());
|
||||
IPoint size = new IPoint(cropArea.size().x(), cropArea.size().y());
|
||||
return mouse.x() > pos.x()
|
||||
&& mouse.y() > pos.y()
|
||||
&& mouse.x() < pos.x() + size.x()
|
||||
&& mouse.y() < pos.y() + size.y()
|
||||
&& isMouseOverWidget(mouse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOverWidget(IPoint relativeMouse) {
|
||||
return getArea().contains(relativeMouse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
enabled = true;
|
||||
callEvent(new EventWidget.Enable(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
callEvent(new EventWidget.Disable(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
visible = true;
|
||||
callEvent(new EventWidget.Show(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
visible = false;
|
||||
callEvent(new EventWidget.Hide(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if (!enabled) {
|
||||
return false;
|
||||
}
|
||||
if (isTopLevel()) {
|
||||
return true;
|
||||
}
|
||||
return getParent().isEnabled() && getParent().isChildEnabled(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
if (!visible) {
|
||||
return false;
|
||||
}
|
||||
if (isTopLevel()) {
|
||||
return true;
|
||||
}
|
||||
return getParent().isVisible() && getParent().isChildVisible(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFocused() {
|
||||
return getSuperParent().isFocused(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDragged() {
|
||||
return getSuperParent().isDragged(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver() {
|
||||
return getSuperParent().isMouseOver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildVisible(IWidget child) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildEnabled(IWidget child) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRender(RenderStage stage) {
|
||||
if (stage == RenderStage.PreChildren) {
|
||||
onRenderBackground();
|
||||
}
|
||||
if (stage == RenderStage.PostChildren) {
|
||||
onRenderForeground();
|
||||
}
|
||||
if (stage == RenderStage.PostSiblings) {
|
||||
onRenderOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRenderBackground() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void onRenderForeground() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void onRenderOverlay() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
getSuperParent().widgetDeleted(this);
|
||||
onDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDelete() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getWidget(Class<T> x) {
|
||||
for (IWidget child : getWidgets()) {
|
||||
if (x.isInstance(child)) {
|
||||
return (T) child;
|
||||
}
|
||||
|
||||
T found = child.getWidget(x);
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IPoint position) {
|
||||
return getArea().contains(position);
|
||||
}
|
||||
|
||||
public void scheduleDeletion() {
|
||||
addAttribute(WidgetAttribute.NeedsDeletion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
int level = (getParent() == null) ? 0 : getParent().getLevel();
|
||||
int index = (getParent() == null) ? 0 : getParent().getWidgets().indexOf(this);
|
||||
return level + index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDescendant(IWidget widget) {
|
||||
IWidget clss = this;
|
||||
while (clss != widget) {
|
||||
clss = clss.getParent();
|
||||
if (clss == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float x() {
|
||||
return pos().x();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float y() {
|
||||
return pos().y();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float w() {
|
||||
return size().x();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float h() {
|
||||
return size().y();
|
||||
}
|
||||
|
||||
public IWidget getWidget() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
public enum WidgetAttribute {
|
||||
MouseOver,
|
||||
CanFocus,
|
||||
NeedsDeletion,
|
||||
AlwaysOnTop,
|
||||
BlockTooltip
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.AbstractMod;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
import binnie.core.craftgui.minecraft.InventoryType;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.craftgui.minecraft.control.ControlImage;
|
||||
import binnie.core.craftgui.minecraft.control.ControlPlayerInventory;
|
||||
import binnie.core.craftgui.minecraft.control.ControlSlot;
|
||||
import binnie.core.craftgui.resource.StyleSheet;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
import binnie.core.craftgui.resource.minecraft.PaddedTexture;
|
||||
import binnie.core.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.core.machines.inventory.SlotValidator;
|
||||
import binnie.extrabees.core.ExtraBeeTexture;
|
||||
import binnie.extrabees.gui.punnett.ExtraBeeGUITexture;
|
||||
import binnie.genetics.gui.ControlChromosome;
|
||||
import binnie.genetics.machine.Analyser;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class WindowFieldKit extends Window {
|
||||
private float glassOffsetX;
|
||||
private float glassOffsetY;
|
||||
private float glassVX;
|
||||
private float glassVY;
|
||||
private Random glassRand;
|
||||
private Control GlassControl;
|
||||
private ControlChromosome chromo;
|
||||
private ControlText text;
|
||||
private float analyseProgress;
|
||||
private boolean isAnalysing;
|
||||
private Map<IChromosomeType, String> info;
|
||||
private ItemStack prev;
|
||||
|
||||
public WindowFieldKit(EntityPlayer player, IInventory inventory, Side side) {
|
||||
super(280.0f, 230.0f, player, inventory, side);
|
||||
glassOffsetX = 0.0f;
|
||||
glassOffsetY = 0.0f;
|
||||
glassVX = 0.0f;
|
||||
glassVY = 0.0f;
|
||||
glassRand = new Random();
|
||||
analyseProgress = 1.0f;
|
||||
isAnalysing = false;
|
||||
info = new HashMap<>();
|
||||
prev = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractMod getMod() {
|
||||
return BinnieCore.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Field Kit";
|
||||
}
|
||||
|
||||
private void setupValidators() {
|
||||
getWindowInventory().setValidator(0, new SlotValidator(null) {
|
||||
@Override
|
||||
public boolean isValid(ItemStack object) {
|
||||
return AlleleManager.alleleRegistry.isIndividual(object)
|
||||
|| Binnie.Genetics.getConversion(object) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Individual";
|
||||
}
|
||||
});
|
||||
|
||||
getWindowInventory().setValidator(1, new SlotValidator(null) {
|
||||
@Override
|
||||
public boolean isValid(ItemStack object) {
|
||||
return object.getItem() == Items.paper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "Paper";
|
||||
}
|
||||
});
|
||||
getWindowInventory().disableAutoDispense(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseClient() {
|
||||
setTitle("Field Kit");
|
||||
CraftGUI.Render.stylesheet(new StyleSheetPunnett());
|
||||
getWindowInventory().createSlot(0);
|
||||
getWindowInventory().createSlot(1);
|
||||
setupValidators();
|
||||
new ControlPlayerInventory(this);
|
||||
IPoint handGlass = new IPoint(16.0f, 32.0f);
|
||||
GlassControl = new ControlImage(this, handGlass.x(), handGlass.y(), new StandardTexture(0, 160, 96, 96, ExtraBeeTexture.GUIPunnett));
|
||||
new ControlSlot(this, handGlass.x() + 54.0f, handGlass.y() + 26.0f).assign(InventoryType.Window, 0);
|
||||
new ControlSlot(this, 208.0f, 8.0f).assign(InventoryType.Window, 1);
|
||||
(text = new ControlText(this, new IPoint(232.0f, 13.0f), "Paper")).setColor(2236962);
|
||||
(text = new ControlText(this, new IArea(0.0f, 120.0f, w(), 24.0f), "", TextJustification.MiddleCenter)).setColor(2236962);
|
||||
chromo = new ControlChromosome(this, 150.0f, 24.0f);
|
||||
|
||||
addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
IChromosomeType type = (IChromosomeType) event.getValue();
|
||||
if (type != null && info.containsKey(type)) {
|
||||
String t = info.get(type);
|
||||
text.setValue(t);
|
||||
} else {
|
||||
text.setValue("");
|
||||
}
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.DirectChild, chromo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseServer() {
|
||||
ItemStack kit = getPlayer().getHeldItem();
|
||||
int sheets = 64 - kit.getItemDamage();
|
||||
if (sheets != 0) {
|
||||
getWindowInventory().setInventorySlotContents(1, new ItemStack(Items.paper, sheets));
|
||||
}
|
||||
setupValidators();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
super.onUpdateClient();
|
||||
if (isAnalysing) {
|
||||
analyseProgress += 0.01f;
|
||||
if (analyseProgress >= 1.0f) {
|
||||
isAnalysing = false;
|
||||
analyseProgress = 1.0f;
|
||||
ItemStack stack = getWindowInventory().getStackInSlot(0);
|
||||
if (stack != null) {
|
||||
sendClientAction("analyse", new NBTTagCompound());
|
||||
}
|
||||
refreshSpecies();
|
||||
}
|
||||
}
|
||||
|
||||
glassVX += glassRand.nextFloat() - 0.5f - glassOffsetX * 0.2f;
|
||||
glassVY += glassRand.nextFloat() - 0.5f - glassOffsetY * 0.2f;
|
||||
glassOffsetX += glassVX;
|
||||
glassOffsetX *= 1.0f - analyseProgress;
|
||||
glassOffsetY += glassVY;
|
||||
glassOffsetY *= 1.0f - analyseProgress;
|
||||
GlassControl.setOffset(new IPoint(glassOffsetX, glassOffsetY));
|
||||
}
|
||||
|
||||
private void refreshSpecies() {
|
||||
ItemStack item = getWindowInventory().getStackInSlot(0);
|
||||
if (item == null || !AlleleManager.alleleRegistry.isIndividual(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IIndividual ind = AlleleManager.alleleRegistry.getIndividual(item);
|
||||
if (ind == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(item);
|
||||
chromo.setRoot(root);
|
||||
Random rand = new Random();
|
||||
info.clear();
|
||||
for (IChromosomeType type : root.getKaryotype()) {
|
||||
if (!Binnie.Genetics.isInvalidChromosome(type)) {
|
||||
IAllele allele = ind.getGenome().getActiveAllele(type);
|
||||
List<String> infos = new ArrayList<>();
|
||||
|
||||
int i = 0;
|
||||
for (String pref = root.getUID() + ".fieldkit." + type.getName().toLowerCase() + "."; Binnie.Language.canLocalise(pref + i); ++i) {
|
||||
infos.add(Binnie.Language.localise(pref + i));
|
||||
}
|
||||
|
||||
String text = Binnie.Genetics.getSystem(root).getAlleleName(type, allele);
|
||||
if (!infos.isEmpty()) {
|
||||
text = infos.get(rand.nextInt(infos.size()));
|
||||
}
|
||||
|
||||
info.put(type, text);
|
||||
chromo.setRoot(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowInventoryChanged() {
|
||||
super.onWindowInventoryChanged();
|
||||
if (isServer()) {
|
||||
ItemStack kit = getPlayer().getHeldItem();
|
||||
int sheets = 64 - kit.getItemDamage();
|
||||
int size = (getWindowInventory().getStackInSlot(1) == null) ? 0 : getWindowInventory().getStackInSlot(1).stackSize;
|
||||
if (sheets != size) {
|
||||
kit.setItemDamage(64 - size);
|
||||
}
|
||||
((EntityPlayerMP) getPlayer()).updateHeldItem();
|
||||
}
|
||||
|
||||
if (isClient()) {
|
||||
ItemStack item = getWindowInventory().getStackInSlot(0);
|
||||
prev = item;
|
||||
text.setValue("");
|
||||
if (item != null && !Analyser.isAnalysed(item)) {
|
||||
if (getWindowInventory().getStackInSlot(1) == null) {
|
||||
text.setValue("No Paper!");
|
||||
isAnalysing = false;
|
||||
analyseProgress = 1.0f;
|
||||
} else {
|
||||
startAnalysing();
|
||||
chromo.setRoot(null);
|
||||
}
|
||||
} else if (item != null) {
|
||||
isAnalysing = false;
|
||||
analyseProgress = 1.0f;
|
||||
refreshSpecies();
|
||||
} else {
|
||||
isAnalysing = false;
|
||||
analyseProgress = 1.0f;
|
||||
chromo.setRoot(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startAnalysing() {
|
||||
glassVX = 0.0f;
|
||||
glassVY = 0.0f;
|
||||
glassOffsetX = 0.0f;
|
||||
glassOffsetY = 0.0f;
|
||||
isAnalysing = true;
|
||||
analyseProgress = 0.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showHelpButton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String showInfoButton() {
|
||||
return "The Field Kit analyses bees, trees, flowers and butterflies. All that is required is a piece of paper to jot notes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveGuiNBT(Side side, EntityPlayer player, String name, NBTTagCompound nbt) {
|
||||
super.recieveGuiNBT(side, player, name, nbt);
|
||||
if (side == Side.SERVER && name.equals("analyse")) {
|
||||
getWindowInventory().setInventorySlotContents(0, Analyser.analyse(getWindowInventory().getStackInSlot(0)));
|
||||
getWindowInventory().decrStackSize(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static class StyleSheetPunnett extends StyleSheet {
|
||||
public StyleSheetPunnett() {
|
||||
textures.put(CraftGUITexture.Window, new PaddedTexture(0, 0, 160, 160, 0, ExtraBeeTexture.GUIPunnett, 32, 32, 32, 32));
|
||||
textures.put(CraftGUITexture.Slot, new StandardTexture(160, 0, 18, 18, 0, ExtraBeeTexture.GUIPunnett));
|
||||
textures.put(ExtraBeeGUITexture.Chromosome, new StandardTexture(160, 36, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
|
||||
textures.put(ExtraBeeGUITexture.Chromosome2, new StandardTexture(160, 52, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
|
||||
textures.put(CraftGUITexture.HelpButton, new StandardTexture(178, 0, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
|
||||
textures.put(CraftGUITexture.InfoButton, new StandardTexture(178, 16, 16, 16, 0, ExtraBeeTexture.GUIPunnett));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package binnie.core.craftgui;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.AbstractMod;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.core.craftgui.controls.listbox.ControlTextOption;
|
||||
import binnie.core.craftgui.controls.tab.ControlTab;
|
||||
import binnie.core.craftgui.controls.tab.ControlTabBar;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.Position;
|
||||
import binnie.core.craftgui.minecraft.MinecraftGUI;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import binnie.core.craftgui.minecraft.control.ControlPlayerInventory;
|
||||
import binnie.core.craftgui.minecraft.control.ControlTabIcon;
|
||||
import binnie.core.craftgui.window.Panel;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import binnie.core.genetics.Gene;
|
||||
import binnie.genetics.gui.ControlGenesisOption;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WindowGenesis extends Window {
|
||||
private ISpeciesRoot root;
|
||||
private IAllele[] template;
|
||||
private ControlListBox<Gene> geneList;
|
||||
private ControlListBox<Gene> geneOptions;
|
||||
private Panel panelPickup;
|
||||
|
||||
public WindowGenesis(EntityPlayer player, IInventory inventory, Side side) {
|
||||
super(342.0f, 228.0f, player, inventory, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractMod getMod() {
|
||||
return BinnieCore.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName() {
|
||||
return "Genesis";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseClient() {
|
||||
new ControlPlayerInventory(this);
|
||||
setTitle("Genesis");
|
||||
ControlTabBar<BreedingSystem> tabSystems = new ControlTabBar<BreedingSystem>(this, 8.0f, 28.0f, 23.0f, 100.0f, Position.Left) {
|
||||
@Override
|
||||
public ControlTab<BreedingSystem> createTab(float x, float y, float w, float h, BreedingSystem value) {
|
||||
return new ControlTabIcon<BreedingSystem>(this, x, y, w, h, value) {
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
int type = value.getDefaultType();
|
||||
IIndividual ind = value.getDefaultIndividual();
|
||||
return value.getSpeciesRoot().getMemberStack(ind, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutlineColour() {
|
||||
return value.getColour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOutline() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
tabSystems.setValues(Binnie.Genetics.getActiveSystems());
|
||||
root = Binnie.Genetics.getActiveSystems().iterator().next().getSpeciesRoot();
|
||||
template = root.getDefaultTemplate();
|
||||
IArea one = new IArea(32.0f, 28.0f, 170.0f, 100.0f);
|
||||
IArea two = new IArea(214.0f, 28.0f, 100.0f, 100.0f);
|
||||
new Panel(this, one.outset(1), MinecraftGUI.PanelType.Black);
|
||||
new Panel(this, two.outset(1), MinecraftGUI.PanelType.Black);
|
||||
|
||||
geneList = new ControlListBox<Gene>(this, one.x(), one.y(), one.w(), one.h(), 10.0f) {
|
||||
@Override
|
||||
public IWidget createOption(Gene value, int y) {
|
||||
return new ControlGenesisOption(getContent(), value, y);
|
||||
}
|
||||
};
|
||||
|
||||
geneOptions = new ControlListBox<Gene>(this, two.x(), two.y(), two.w(), two.h(), 10.0f) {
|
||||
@Override
|
||||
public IWidget createOption(Gene value, int y) {
|
||||
return new ControlTextOption<>(getContent(), value, y);
|
||||
}
|
||||
};
|
||||
|
||||
tabSystems.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
root = ((BreedingSystem) event.getValue()).getSpeciesRoot();
|
||||
template = root.getDefaultTemplate();
|
||||
refreshTemplate(null);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, tabSystems));
|
||||
|
||||
geneList.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
Map<IChromosomeType, List<IAllele>> map = Binnie.Genetics.getChromosomeMap(root);
|
||||
List<Gene> opts = new ArrayList<>();
|
||||
IChromosomeType chromo = event.value != null ? ((Gene) event.value).getChromosome() : null;
|
||||
if (chromo != null) {// fix NPE
|
||||
for (IAllele allele : map.get(chromo)) {
|
||||
opts.add(new Gene(allele, chromo, root));
|
||||
}
|
||||
}
|
||||
geneOptions.setOptions(opts);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, geneList));
|
||||
|
||||
geneOptions.addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
if (event.value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
IChromosomeType chromo = ((Gene) event.value).getChromosome();
|
||||
template[chromo.ordinal()] = ((Gene) event.value).getAllele();
|
||||
if (chromo == ((Gene) event.value).getSpeciesRoot().getKaryotypeKey()) {
|
||||
template = ((Gene) event.value).getSpeciesRoot().getTemplate(((Gene) event.value).getAllele().getUID());
|
||||
}
|
||||
refreshTemplate(chromo);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, geneOptions));
|
||||
panelPickup = new Panel(this, 16.0f, 140.0f, 60.0f, 42.0f, MinecraftGUI.PanelType.Black);
|
||||
refreshTemplate(null);
|
||||
}
|
||||
|
||||
private void refreshTemplate(IChromosomeType selection) {
|
||||
List<Gene> genes = new ArrayList<>();
|
||||
IChromosomeType[] chromos = Binnie.Genetics.getChromosomeMap(root).keySet().toArray(new IChromosomeType[0]);
|
||||
|
||||
for (IChromosomeType type : chromos) {
|
||||
IAllele allele = template[type.ordinal()];
|
||||
if (allele == null) {
|
||||
throw new NullPointerException("Allele missing for Chromosome " + type.getName());
|
||||
}
|
||||
genes.add(new Gene(allele, type, root));
|
||||
}
|
||||
|
||||
Map<IChromosomeType, List<IAllele>> map = Binnie.Genetics.getChromosomeMap(root);
|
||||
geneList.setOptions(genes);
|
||||
if (selection != null) {
|
||||
geneList.setValue(new Gene(template[selection.ordinal()], selection, root));
|
||||
} else {
|
||||
geneOptions.setOptions(new ArrayList<>());
|
||||
}
|
||||
refreshPickup();
|
||||
}
|
||||
|
||||
private void refreshPickup() {
|
||||
panelPickup.deleteAllChildren();
|
||||
int i = 0;
|
||||
for (int type : Binnie.Genetics.getSystem(root).getActiveTypes()) {
|
||||
IIndividual ind = root.templateAsIndividual(template);
|
||||
ind.analyze();
|
||||
ItemStack stack = root.getMemberStack(ind, type);
|
||||
ControlItemDisplay display = new ControlItemDisplay(panelPickup, 4 + i % 3 * 18, 4 + i / 3 * 18);
|
||||
display.setItemStack(stack);
|
||||
display.setTooltip();
|
||||
display.addEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
stack.writeToNBT(nbt);
|
||||
Window.get(event.getOrigin()).sendClientAction("genesis", nbt);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, display));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recieveGuiNBT(Side side, EntityPlayer player, String name, NBTTagCompound nbt) {
|
||||
super.recieveGuiNBT(side, player, name, nbt);
|
||||
if (side == Side.SERVER && name.equals("genesis")) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt);
|
||||
InventoryPlayer playerInv = player.inventory;
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playerInv.getItemStack() == null) {
|
||||
playerInv.setItemStack(stack);
|
||||
} else if (playerInv.getItemStack().isItemEqual(stack) && ItemStack.areItemStackTagsEqual(playerInv.getItemStack(), stack)) {
|
||||
int fit = stack.getMaxStackSize() - (stack.stackSize + playerInv.getItemStack().stackSize);
|
||||
if (fit >= 0) {
|
||||
ItemStack itemStack;
|
||||
ItemStack rec = itemStack = stack;
|
||||
itemStack.stackSize += playerInv.getItemStack().stackSize;
|
||||
playerInv.setItemStack(rec);
|
||||
}
|
||||
}
|
||||
|
||||
player.openContainer.detectAndSendChanges();
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).updateHeldItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package binnie.core.craftgui.controls;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
|
||||
public class ControlCheckbox extends Control implements IControlValue<Boolean> {
|
||||
boolean value;
|
||||
String text;
|
||||
|
||||
public ControlCheckbox(IWidget parent, float x, float y, boolean bool) {
|
||||
this(parent, x, y, 0.0f, "", bool);
|
||||
}
|
||||
|
||||
public ControlCheckbox(IWidget parent, float x, float y, float w, String text, boolean bool) {
|
||||
super(parent, x, y, (w > 16.0f) ? w : 16.0f, 16.0f);
|
||||
this.text = text;
|
||||
value = bool;
|
||||
if (w > 16.0f) {
|
||||
new ControlText(this, new IArea(16.0f, 1.0f, w - 16.0f, 16.0f), text, TextJustification.MiddleCenter).setColor(4473924);
|
||||
}
|
||||
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
addEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
toggleValue();
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
Object texture = getValue() ? CraftGUITexture.CheckboxChecked : CraftGUITexture.Checkbox;
|
||||
if (isMouseOver()) {
|
||||
texture = (getValue() ? CraftGUITexture.CheckboxCheckedHighlighted : CraftGUITexture.CheckboxHighlighted);
|
||||
}
|
||||
CraftGUI.Render.texture(texture, IPoint.ZERO);
|
||||
}
|
||||
|
||||
protected void onValueChanged(boolean value) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void toggleValue() {
|
||||
setValue(!getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Boolean value) {
|
||||
this.value = value;
|
||||
onValueChanged(value);
|
||||
callEvent(new EventValueChanged<Object>(this, value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package binnie.core.craftgui.controls;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
|
||||
public class ControlText extends Control implements IControlValue<String> {
|
||||
private String text;
|
||||
private TextJustification align;
|
||||
|
||||
public ControlText(IWidget parent, IPoint pos, String text) {
|
||||
this(parent, new IArea(pos, new IPoint(500.0f, 0.0f)), text, TextJustification.TopLeft);
|
||||
}
|
||||
|
||||
public ControlText(IWidget parent, String text, TextJustification align) {
|
||||
this(parent, parent.getArea(), text, align);
|
||||
}
|
||||
|
||||
public ControlText(IWidget parent, IArea area, String text, TextJustification align) {
|
||||
super(parent, area.pos().x(), area.pos().y(), area.size().x(), area.size().y());
|
||||
setValue(text);
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
CraftGUI.Render.text(getArea(), align, text, getColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package binnie.core.craftgui.controls;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
|
||||
public class ControlTextCentered extends ControlText {
|
||||
public ControlTextCentered(IWidget parent, float y, String text) {
|
||||
super(parent, new IArea(new IPoint(0.0f, y), new IPoint(parent.size().x(), 0.0f)), text, TextJustification.TopCenter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package binnie.core.craftgui.controls;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventKey;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventTextEdit;
|
||||
import binnie.core.craftgui.events.EventWidget;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class ControlTextEdit extends Control implements IControlValue<String> {
|
||||
GuiTextField field;
|
||||
private String cachedValue;
|
||||
|
||||
public ControlTextEdit(IWidget parent, float x, float y, float width, float height) {
|
||||
super(parent, x, y, width, height);
|
||||
cachedValue = "";
|
||||
field = new GuiTextField(getWindow().getGui().getFontRenderer(), 0, 0, 10, 10);
|
||||
addAttribute(WidgetAttribute.CanFocus);
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
field.setEnableBackgroundDrawing(false);
|
||||
|
||||
addEventHandler(new EventKey.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventKey.Down event) {
|
||||
field.textboxKeyTyped(event.getCharacter(), event.getKey());
|
||||
String text = getValue();
|
||||
if (!text.equals(cachedValue)) {
|
||||
cachedValue = text;
|
||||
callEvent(new EventTextEdit(ControlTextEdit.this, cachedValue));
|
||||
onTextEdit(cachedValue);
|
||||
}
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this));
|
||||
|
||||
addEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
field.mouseClicked((int) getRelativeMousePosition().x(), (int) getRelativeMousePosition().y(), event.getButton());
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this));
|
||||
|
||||
addEventHandler(new EventWidget.GainFocus.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventWidget.GainFocus event) {
|
||||
field.setFocused(true);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this));
|
||||
|
||||
addEventHandler(new EventWidget.LoseFocus.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventWidget.LoseFocus event) {
|
||||
field.setFocused(false);
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Self, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
protected void onTextEdit(String value) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
CraftGUI.Render.texture(CraftGUITexture.Slot, getArea());
|
||||
renderTextField();
|
||||
}
|
||||
|
||||
protected void renderTextField() {
|
||||
field.width = (int) w();
|
||||
field.height = (int) h();
|
||||
field.xPosition = (int) ((h() - 8.0f) / 2.0f);
|
||||
field.yPosition = (int) ((h() - 8.0f) / 2.0f);
|
||||
field.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return (field.getText() == null) ? "" : field.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
if (!getValue().equals(value)) {
|
||||
field.setText(value);
|
||||
field.setCursorPosition(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package binnie.core.craftgui.controls;
|
||||
|
||||
// TODO unused interface?
|
||||
public interface IControlSelection<T> {
|
||||
T getSelectedValue();
|
||||
|
||||
void setSelectedValue(T p0);
|
||||
|
||||
boolean isSelected(IControlSelectionOption<T> p0);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package binnie.core.craftgui.controls;
|
||||
|
||||
public interface IControlSelectionOption<T> {
|
||||
T getValue();
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package binnie.core.craftgui.controls.button;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.events.EventButtonClicked;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
|
||||
public class ControlButton extends Control {
|
||||
private ControlText textWidget;
|
||||
private String text;
|
||||
|
||||
public ControlButton(IWidget parent, float x, float y, float width, float height) {
|
||||
super(parent, x, y, width, height);
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
|
||||
mouseHandler.setOrigin(EventHandler.Origin.Self, this);
|
||||
addEventHandler(mouseHandler);
|
||||
}
|
||||
|
||||
public ControlButton(IWidget parent, float x, float y, float width, float height, String text) {
|
||||
this(parent, x, y, width, height);
|
||||
this.text = text;
|
||||
textWidget = new ControlText(this, getArea(), text, TextJustification.MiddleCenter);
|
||||
}
|
||||
|
||||
private EventMouse.Down.Handler mouseHandler = new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
callEvent(new EventButtonClicked(getWidget()));
|
||||
onMouseClick(event);
|
||||
}
|
||||
};
|
||||
|
||||
protected void onMouseClick(EventMouse.Down event) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
if (textWidget != null) {
|
||||
textWidget.setValue(getText());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
Object texture = CraftGUITexture.ButtonDisabled;
|
||||
if (isMouseOver()) {
|
||||
texture = CraftGUITexture.ButtonHighlighted;
|
||||
} else if (isEnabled()) {
|
||||
texture = CraftGUITexture.Button;
|
||||
}
|
||||
CraftGUI.Render.texture(texture, getArea());
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package binnie.core.craftgui.controls.button;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
// TODO unused class?
|
||||
public class ControlEnumButton<T> extends ControlButton implements IControlValue<T> {
|
||||
public static String eventEnumChanged = "eventEnumButtonChanged";
|
||||
private T currentSelection;
|
||||
private List<T> enumConstants;
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return currentSelection.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseClick(EventMouse.Down event) {
|
||||
int index = enumConstants.indexOf(currentSelection);
|
||||
if (index < enumConstants.size() - 1) {
|
||||
index++;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
T newEnum = enumConstants.get(index);
|
||||
setValue(newEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T selection) {
|
||||
if (currentSelection != selection) {
|
||||
currentSelection = selection;
|
||||
callEvent(new EventValueChanged<Object>(this, getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public ControlEnumButton(IWidget parent, float x, float y, float width, float height, T[] values) {
|
||||
super(parent, x, y, width, height, "");
|
||||
enumConstants = new ArrayList<T>();
|
||||
Collections.addAll(enumConstants, values);
|
||||
if (values.length > 0) {
|
||||
currentSelection = values[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return currentSelection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package binnie.core.craftgui.controls.button;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventToggleButtonClicked;
|
||||
|
||||
// TODO unused class?
|
||||
public class ControlToggleButton extends ControlButton {
|
||||
boolean toggled;
|
||||
|
||||
@Override
|
||||
public void onMouseClick(EventMouse.Down event) {
|
||||
callEvent(new EventToggleButtonClicked(this, toggled));
|
||||
}
|
||||
|
||||
public ControlToggleButton(IWidget parent, int x, int y, int width, int height) {
|
||||
super(parent, x, y, width, height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package binnie.core.craftgui.controls.core;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.core.craftgui.ITooltipHelp;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.Widget;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Control extends Widget implements ITooltipHelp, ITooltip {
|
||||
public int extraLevel;
|
||||
|
||||
protected List<String> helpStrings;
|
||||
protected List<String> tooltipStrings;
|
||||
|
||||
public Control(IWidget parent, float x, float y, float w, float h) {
|
||||
super(parent);
|
||||
helpStrings = new ArrayList<>();
|
||||
tooltipStrings = new ArrayList<>();
|
||||
extraLevel = 0;
|
||||
setPosition(new IPoint(x, y));
|
||||
setSize(new IPoint(w, h));
|
||||
initialise();
|
||||
}
|
||||
|
||||
public Control(IWidget parent, IArea area) {
|
||||
this(parent, area.x(), area.y(), area.w(), area.h());
|
||||
}
|
||||
|
||||
protected void initialise() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
public void addHelp(String string) {
|
||||
helpStrings.add(string);
|
||||
}
|
||||
|
||||
public void addHelp(String[] strings) {
|
||||
for (String string : strings) {
|
||||
addHelp(string);
|
||||
}
|
||||
}
|
||||
|
||||
public void addTooltip(String string) {
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
tooltipStrings.add(string);
|
||||
}
|
||||
|
||||
public void addTooltip(String[] strings) {
|
||||
for (String string : strings) {
|
||||
addTooltip(string);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLevel() {
|
||||
return extraLevel + super.getLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHelpTooltip(Tooltip tooltip) {
|
||||
tooltip.add(helpStrings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(Tooltip tooltip) {
|
||||
tooltip.add(tooltipStrings);
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
return (Window) getSuperParent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package binnie.core.craftgui.controls.core;
|
||||
|
||||
// TODO unused interface?
|
||||
public interface IControlIndexed {
|
||||
int getIndex();
|
||||
|
||||
void setIndex(int index);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package binnie.core.craftgui.controls.core;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public interface IControlValue<T> extends IWidget {
|
||||
T getValue();
|
||||
|
||||
void setValue(T value);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package binnie.core.craftgui.controls.core;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface IControlValues<T> extends IControlValue<T> {
|
||||
Collection<T> getValues();
|
||||
|
||||
void setValues(Collection<T> values);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package binnie.core.craftgui.controls.listbox;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.util.IValidator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ControlList<T> extends Control implements IControlValue<T> {
|
||||
protected ControlListBox<T> parent;
|
||||
protected T value;
|
||||
protected Map<T, IWidget> allOptions = new LinkedHashMap<>();
|
||||
protected Map<T, IWidget> optionWidgets = new LinkedHashMap<>();
|
||||
protected boolean creating;
|
||||
protected IValidator<IWidget> validator;
|
||||
|
||||
protected ControlList(ControlListBox<T> parent, float x, float y, float w, float h) {
|
||||
super(parent, x, y, w, h);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
if (value == this.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.value = value;
|
||||
if (value != null && optionWidgets.containsKey(value)) {
|
||||
IWidget child = optionWidgets.get(value);
|
||||
parent.ensureVisible(child.y(), child.y() + child.h(), h());
|
||||
}
|
||||
getParent().callEvent(new EventValueChanged<Object>(getParent(), value));
|
||||
}
|
||||
|
||||
public void setOptions(Collection<T> options) {
|
||||
deleteAllChildren();
|
||||
allOptions.clear();
|
||||
|
||||
for (T option : options) {
|
||||
IWidget optionWidget = ((ControlListBox) getParent()).createOption(option, 0);
|
||||
if (optionWidget != null) {
|
||||
allOptions.put(option, optionWidget);
|
||||
}
|
||||
}
|
||||
filterOptions();
|
||||
}
|
||||
|
||||
public void filterOptions() {
|
||||
int height = 0;
|
||||
optionWidgets.clear();
|
||||
|
||||
for (Map.Entry<T, IWidget> entry : allOptions.entrySet()) {
|
||||
if (isValidOption(entry.getValue())) {
|
||||
entry.getValue().show();
|
||||
optionWidgets.put(entry.getKey(), entry.getValue());
|
||||
entry.getValue().setPosition(new IPoint(0.0f, height));
|
||||
height += (int) entry.getValue().getSize().y();
|
||||
} else {
|
||||
entry.getValue().hide();
|
||||
}
|
||||
}
|
||||
|
||||
creating = true;
|
||||
setValue(getValue());
|
||||
setSize(new IPoint(getSize().x(), height));
|
||||
}
|
||||
|
||||
public Collection<T> getOptions() {
|
||||
return optionWidgets.keySet();
|
||||
}
|
||||
|
||||
public Collection<T> getAllOptions() {
|
||||
return allOptions.keySet();
|
||||
}
|
||||
|
||||
public int getIndexOf(T value) {
|
||||
int index = 0;
|
||||
for (T option : getOptions()) {
|
||||
if (option.equals(value)) {
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getCurrentIndex() {
|
||||
return getIndexOf(getValue());
|
||||
}
|
||||
|
||||
public void setIndex(int currentIndex) {
|
||||
int index = 0;
|
||||
for (T option : getOptions()) {
|
||||
if (index == currentIndex) {
|
||||
setValue(option);
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
setValue(null);
|
||||
}
|
||||
|
||||
private boolean isValidOption(IWidget widget) {
|
||||
return validator == null || validator.isValid(widget);
|
||||
}
|
||||
|
||||
public void setValidator(IValidator<IWidget> validator) {
|
||||
if (this.validator != validator) {
|
||||
this.validator = validator;
|
||||
filterOptions();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package binnie.core.craftgui.controls.listbox;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.controls.scroll.ControlScrollableContent;
|
||||
import binnie.core.craftgui.events.EventKey;
|
||||
import binnie.core.util.IValidator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ControlListBox<T> extends ControlScrollableContent<ControlList<T>> implements IControlValue<T> {
|
||||
public ControlListBox(IWidget parent, float x, float y, float w, float h, float scrollBarSize) {
|
||||
super(parent, x, y, w, h, scrollBarSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialise() {
|
||||
setScrollableContent(new ControlList<T>(this, 1.0f, 1.0f, w() - 2.0f - scrollBarSize, h() - 2.0f));
|
||||
addEventHandler(new EventKey.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventKey.Down event) {
|
||||
if (calculateIsMouseOver()) {
|
||||
int currentIndex = getContent().getCurrentIndex();
|
||||
if (event.getKey() == 208) {
|
||||
if (++currentIndex >= getContent().getOptions().size()) {
|
||||
currentIndex = 0;
|
||||
}
|
||||
} else if (event.getKey() == 200 && --currentIndex < 0) {
|
||||
currentIndex = getContent().getOptions().size() - 1;
|
||||
}
|
||||
getContent().setIndex(currentIndex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public IWidget createOption(T value, int y) {
|
||||
return new ControlOption<>(getContent(), value, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return getContent().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
getContent().setValue(value);
|
||||
}
|
||||
|
||||
public void setOptions(Collection<T> options) {
|
||||
getContent().setOptions(options);
|
||||
}
|
||||
|
||||
public void setValidator(IValidator<IWidget> validator) {
|
||||
getContent().setValidator(validator);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package binnie.core.craftgui.controls.listbox;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
|
||||
public class ControlOption<T> extends Control implements IControlValue<T> {
|
||||
protected T value;
|
||||
|
||||
public ControlOption(ControlList<T> controlList, T option) {
|
||||
this(controlList, option, 16);
|
||||
}
|
||||
|
||||
public ControlOption(ControlList<T> controlList, T option, int height) {
|
||||
super(controlList, 0.0f, height, controlList.getSize().x(), 20.0f);
|
||||
value = option;
|
||||
if (value != null) {
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
addSelfEventHandler(mouseHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
if (getValue() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int color = 0xa0a0a0;
|
||||
if (isCurrentSelection()) {
|
||||
color = 0xffffff;
|
||||
}
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
private EventMouse.Down.Handler mouseHandler = new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
((IControlValue) getParent()).setValue(getValue());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onRenderForeground() {
|
||||
if (isCurrentSelection()) {
|
||||
CraftGUI.Render.texture(CraftGUITexture.Outline, getArea());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isCurrentSelection() {
|
||||
return getValue() != null
|
||||
&& getValue().equals(((IControlValue) getParent()).getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package binnie.core.craftgui.controls.listbox;
|
||||
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventWidget;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
|
||||
public class ControlTextOption<T> extends ControlOption<T> {
|
||||
protected ControlText textWidget;
|
||||
|
||||
public ControlTextOption(ControlList<T> controlList, T option, String optionName, int y) {
|
||||
super(controlList, option, y);
|
||||
textWidget = null;
|
||||
textWidget = new ControlText(this, getArea(), optionName, TextJustification.MiddleCenter);
|
||||
|
||||
mouseHandler.setOrigin(EventHandler.Origin.Self, this);
|
||||
addEventHandler(mouseHandler);
|
||||
}
|
||||
|
||||
public ControlTextOption(ControlList<T> controlList, T option, int y) {
|
||||
this(controlList, option, option.toString(), y);
|
||||
}
|
||||
|
||||
private EventWidget.ChangeColour.Handler mouseHandler = new EventWidget.ChangeColour.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventWidget.ChangeColour event) {
|
||||
textWidget.setColor(getColor());
|
||||
}
|
||||
};
|
||||
|
||||
public String getText() {
|
||||
return textWidget.getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package binnie.core.craftgui.controls.page;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
|
||||
public class ControlPage<T> extends Control implements IControlValue<T> {
|
||||
protected T value;
|
||||
|
||||
public ControlPage(IWidget parent, T value) {
|
||||
this(parent, 0.0f, 0.0f, parent.w(), parent.h(), value);
|
||||
}
|
||||
|
||||
public ControlPage(IWidget parent, float x, float y, float w, float h, T value) {
|
||||
super(parent, x, y, w, h);
|
||||
setValue(value);
|
||||
if (parent instanceof IControlValue && ((IControlValue) parent).getValue() == null) {
|
||||
((IControlValue) parent).setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package binnie.core.craftgui.controls.page;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.controls.core.IControlValues;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ControlPages<T> extends Control implements IControlValues<T>, IControlValue<T> {
|
||||
protected T value;
|
||||
|
||||
public ControlPages(IWidget parent, float x, float y, float w, float h) {
|
||||
super(parent, x, y, w, h);
|
||||
value = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddChild(IWidget widget) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
if (this.value != value) {
|
||||
this.value = value;
|
||||
callEvent(new EventValueChanged<Object>(this, value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> getValues() {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (IWidget child : getWidgets()) {
|
||||
list.add((T) ((IControlValue) child).getValue());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValues(Collection<T> values) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildVisible(IWidget child) {
|
||||
return child != null && value == ((IControlValue) child).getValue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package binnie.core.craftgui.controls.scroll;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
|
||||
public class ControlScroll extends Control {
|
||||
private IControlScrollable scrollWidget;
|
||||
|
||||
public ControlScroll(IWidget parent, float x, float y, float width, float height, IControlScrollable scrollWidget) {
|
||||
super(parent, x, y, width, height);
|
||||
this.scrollWidget = scrollWidget;
|
||||
new ControlScrollBar(this);
|
||||
}
|
||||
|
||||
public IControlScrollable getScrollableWidget() {
|
||||
return scrollWidget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package binnie.core.craftgui.controls.scroll;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
|
||||
public class ControlScrollBar extends Control {
|
||||
protected IControlScrollable scrollable;
|
||||
|
||||
public ControlScrollBar(ControlScroll parent) {
|
||||
this(parent, 0.0f, 0.0f, parent.getSize().x(), parent.getSize().y(), parent.getScrollableWidget());
|
||||
}
|
||||
|
||||
public ControlScrollBar(IWidget parent, float x, float y, float w, float h, IControlScrollable scrollable2) {
|
||||
super(parent, x, y, w, h);
|
||||
scrollable = scrollable2;
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
addSelfEventHandler(new EventMouse.Drag.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Drag event) {
|
||||
scrollable.movePercentage(event.getDy() / (h() - getBarHeight()));
|
||||
}
|
||||
});
|
||||
addSelfEventHandler(mouseDownHandler);
|
||||
}
|
||||
|
||||
private EventMouse.Down.Handler mouseDownHandler = new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
float shownPercentage = scrollable.getPercentageShown();
|
||||
float percentageIndex = scrollable.getPercentageIndex();
|
||||
float minPercent = (1.0f - shownPercentage) * percentageIndex;
|
||||
float maxPercent = minPercent + shownPercentage;
|
||||
float clickedPercentage = getRelativeMousePosition().y() / (h() - 2.0f);
|
||||
clickedPercentage = Math.max(Math.min(clickedPercentage, 1.0f), 0.0f);
|
||||
|
||||
if (clickedPercentage > maxPercent) {
|
||||
scrollable.setPercentageIndex((clickedPercentage - shownPercentage) / (1.0f - shownPercentage));
|
||||
}
|
||||
if (clickedPercentage < minPercent) {
|
||||
scrollable.setPercentageIndex(clickedPercentage / (1.0f - shownPercentage));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
// ignored
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
IArea renderArea = getRenderArea();
|
||||
Object texture = CraftGUITexture.ScrollDisabled;
|
||||
if (isMouseOver()) {
|
||||
texture = CraftGUITexture.ScrollHighlighted;
|
||||
} else if (isEnabled()) {
|
||||
texture = CraftGUITexture.Scroll;
|
||||
}
|
||||
CraftGUI.Render.texture(texture, renderArea);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return scrollable.getPercentageShown() < 0.99f;
|
||||
}
|
||||
|
||||
public float getBarHeight() {
|
||||
return h() * scrollable.getPercentageShown();
|
||||
}
|
||||
|
||||
protected IArea getRenderArea() {
|
||||
float height = getBarHeight();
|
||||
if (height < 6.0f) {
|
||||
height = 6.0f;
|
||||
}
|
||||
|
||||
float yOffset = ((int) h() - (int) getBarHeight()) * scrollable.getPercentageIndex();
|
||||
return new IArea(0.0f, yOffset, getSize().x(), height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package binnie.core.craftgui.controls.scroll;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventWidget;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
|
||||
public class ControlScrollableContent<T extends IWidget> extends Control implements IControlScrollable {
|
||||
protected T controlChild;
|
||||
protected float scrollBarSize;
|
||||
protected float percentageIndex;
|
||||
|
||||
public ControlScrollableContent(IWidget parent, float x, float y, float w, float h, float scrollBarSize) {
|
||||
super(parent, x, y, w, h);
|
||||
this.scrollBarSize = scrollBarSize;
|
||||
if (scrollBarSize != 0.0f) {
|
||||
new ControlScroll(this, getSize().x() - scrollBarSize, 0.0f, scrollBarSize, getSize().y(), this);
|
||||
}
|
||||
|
||||
percentageIndex = 0.0f;
|
||||
addEventHandler(mouseWheelHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
setPercentageIndex(getPercentageIndex());
|
||||
}
|
||||
|
||||
private EventMouse.Wheel.Handler mouseWheelHandler = new EventMouse.Wheel.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Wheel event) {
|
||||
IPoint mousePos = getRelativeMousePosition();
|
||||
if (mousePos.x() > 0.0f && mousePos.y() > 0.0f && mousePos.x() < getSize().x() && mousePos.y() < getSize().y()) {
|
||||
if (getMovementRange() == 0.0f) {
|
||||
return;
|
||||
}
|
||||
float percentageMove = 0.8f / getMovementRange();
|
||||
movePercentage(percentageMove * -event.getDWheel());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void setScrollableContent(T child) {
|
||||
controlChild = child;
|
||||
if (child == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
child.setCroppedZone(this, new IArea(1.0F, 1.0F, getSize().x() - 2.0F - scrollBarSize, getSize().y() - 2.0F));
|
||||
child.addSelfEventHandler(new EventWidget.ChangeSize.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventWidget.ChangeSize event) {
|
||||
controlChild.setOffset(new IPoint(0.0f, -percentageIndex * getMovementRange()));
|
||||
if (getMovementRange() == 0.0f) {
|
||||
percentageIndex = 0.0f;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public T getContent() {
|
||||
return controlChild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPercentageShown() {
|
||||
if (controlChild == null || controlChild.getSize().y() == 0.0f) {
|
||||
return 1.0f;
|
||||
}
|
||||
float shown = getSize().y() / controlChild.getSize().y();
|
||||
return Math.min(shown, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPercentageIndex() {
|
||||
return percentageIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePercentage(float percentage) {
|
||||
if (controlChild == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
percentageIndex += percentage;
|
||||
if (percentageIndex > 1.0f) {
|
||||
percentageIndex = 1.0f;
|
||||
} else if (percentageIndex < 0.0f) {
|
||||
percentageIndex = 0.0f;
|
||||
}
|
||||
|
||||
if (getMovementRange() == 0.0f) {
|
||||
percentageIndex = 0.0f;
|
||||
}
|
||||
controlChild.setOffset(new IPoint(0.0f, -percentageIndex * getMovementRange()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPercentageIndex(float index) {
|
||||
movePercentage(index - percentageIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMovementRange() {
|
||||
if (controlChild == null) {
|
||||
return 0.0f;
|
||||
}
|
||||
float range = controlChild.getSize().y() - getSize().y();
|
||||
return Math.max(range, 0.0f);
|
||||
}
|
||||
|
||||
public void ensureVisible(float minY, float maxY, float totalY) {
|
||||
minY /= totalY;
|
||||
maxY /= totalY;
|
||||
float shownPercentage = getPercentageShown();
|
||||
float percentageIndex = getPercentageIndex();
|
||||
float minPercent = (1.0f - shownPercentage) * percentageIndex;
|
||||
float maxPercent = minPercent + shownPercentage;
|
||||
|
||||
if (maxY > maxPercent) {
|
||||
setPercentageIndex((maxY - shownPercentage) / (1.0f - shownPercentage));
|
||||
}
|
||||
if (minY < minPercent) {
|
||||
setPercentageIndex(minY / (1.0f - shownPercentage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package binnie.core.craftgui.controls.scroll;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public interface IControlScrollable extends IWidget {
|
||||
float getPercentageShown();
|
||||
|
||||
float getPercentageIndex();
|
||||
|
||||
void movePercentage(float percentage);
|
||||
|
||||
void setPercentageIndex(float index);
|
||||
|
||||
float getMovementRange();
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package binnie.core.craftgui.controls.tab;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.Position;
|
||||
import binnie.core.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import binnie.core.craftgui.minecraft.control.ControlTabIcon;
|
||||
import binnie.core.craftgui.resource.Texture;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
|
||||
public class ControlTab<T> extends Control implements ITooltip, IControlValue<T> {
|
||||
protected T value;
|
||||
|
||||
private ControlTabBar<T> tabBar;
|
||||
|
||||
public ControlTab(ControlTabBar<T> parent, float x, float y, float w, float h, T value) {
|
||||
super(parent, x, y, w, h);
|
||||
setValue(value);
|
||||
tabBar = parent;
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
addSelfEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
callEvent(new EventValueChanged<Object>(getWidget(), getValue()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
Object texture = CraftGUITexture.TabDisabled;
|
||||
if (isMouseOver()) {
|
||||
texture = CraftGUITexture.TabHighlighted;
|
||||
} else if (isCurrentSelection()) {
|
||||
texture = CraftGUITexture.Tab;
|
||||
}
|
||||
|
||||
Texture lTexture = CraftGUI.Render.getTexture(texture);
|
||||
Position position = getTabPosition();
|
||||
Texture iTexture = lTexture.crop(position, 8.0f);
|
||||
IArea area = getArea();
|
||||
if (texture == CraftGUITexture.TabDisabled) {
|
||||
if (position == Position.Top || position == Position.Left) {
|
||||
area.setPosition(area.getPosition().sub(new IPoint(4 * position.x(), 4 * position.y())));
|
||||
area.setSize(area.getSize().add(new IPoint(4 * position.x(), 4 * position.y())));
|
||||
} else {
|
||||
area.setSize(area.getSize().sub(new IPoint(4 * position.x(), 4 * position.y())));
|
||||
}
|
||||
}
|
||||
|
||||
CraftGUI.Render.texture(iTexture, area);
|
||||
if (this instanceof ControlTabIcon) {
|
||||
ControlTabIcon icon = (ControlTabIcon) this;
|
||||
ControlItemDisplay item = (ControlItemDisplay) getWidgets().get(0);
|
||||
if (texture == CraftGUITexture.TabDisabled) {
|
||||
item.setColor(0xaaaaaaaa);
|
||||
} else {
|
||||
item.setColor(0xffffffff);
|
||||
}
|
||||
|
||||
if (icon.hasOutline()) {
|
||||
iTexture = CraftGUI.Render.getTexture(CraftGUITexture.TabOutline);
|
||||
iTexture = iTexture.crop(position, 8.0f);
|
||||
CraftGUI.Render.colour(icon.getOutlineColour());
|
||||
CraftGUI.Render.texture(iTexture, area.inset(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(Tooltip tooltip) {
|
||||
String name = getName();
|
||||
if (name != null && !name.isEmpty()) {
|
||||
tooltip.add(getName());
|
||||
}
|
||||
if (value instanceof ITooltip) {
|
||||
((ITooltip) value).getTooltip(tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Position getTabPosition() {
|
||||
return tabBar.position;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
public boolean isCurrentSelection() {
|
||||
return getValue() != null && getValue().equals(tabBar.getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package binnie.core.craftgui.controls.tab;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.Position;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ControlTabBar<T> extends Control implements IControlValue<T> {
|
||||
protected T value;
|
||||
protected Position position;
|
||||
|
||||
public ControlTabBar(IWidget parent, float x, float y, float width, float height, Position position) {
|
||||
super(parent, x, y, width, height);
|
||||
this.position = position;
|
||||
addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
setValue((T) event.getValue());
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.DirectChild, this));
|
||||
}
|
||||
|
||||
public ControlTab<T> createTab(float x, float y, float w, float h, T value) {
|
||||
return new ControlTab<>(this, x, y, w, h, value);
|
||||
}
|
||||
|
||||
public void setValues(Collection<T> values) {
|
||||
int i = 0;
|
||||
while (i < getWidgets().size()) {
|
||||
deleteChild(getWidgets().get(0));
|
||||
}
|
||||
|
||||
float length = values.size();
|
||||
int tabDimension = (int) (getSize().y() / length);
|
||||
if (position == Position.Top || position == Position.Bottom) {
|
||||
tabDimension = (int) (getSize().x() / length);
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (T value : values) {
|
||||
if (position == Position.Top || position == Position.Bottom) {
|
||||
createTab(j * tabDimension, 0.0f, tabDimension, getSize().y(), value);
|
||||
} else {
|
||||
createTab(0.0f, j * tabDimension, getSize().x(), tabDimension, value);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
||||
if (value == null && !values.isEmpty()) {
|
||||
setValue(values.iterator().next());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(T value) {
|
||||
boolean change = this.value != value;
|
||||
this.value = value;
|
||||
if (change) {
|
||||
callEvent(new EventValueChanged<Object>(this, value));
|
||||
}
|
||||
}
|
||||
|
||||
public Position getDirection() {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
import forestry.api.genetics.IClassification;
|
||||
|
||||
class ControlBranchBox extends ControlListBox<IClassification> {
|
||||
@Override
|
||||
public IWidget createOption(IClassification value, int y) {
|
||||
return new ControlBranchBoxOption(getContent(), value, y);
|
||||
}
|
||||
|
||||
public ControlBranchBox(IWidget parent, float x, float y, float width, float height) {
|
||||
super(parent, x, y, width, height, 12.0f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.controls.listbox.ControlTextOption;
|
||||
import forestry.api.genetics.IClassification;
|
||||
|
||||
class ControlBranchBoxOption extends ControlTextOption<IClassification> {
|
||||
public ControlBranchBoxOption(ControlList<IClassification> controlList, IClassification option, int y) {
|
||||
super(controlList, option, (option.getName() == null) ? option.getScientific() : (option.getName().contains(".") ? option.getScientific() : option.getName()), y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.resource.Texture;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITextureSheet;
|
||||
import binnie.core.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
|
||||
class ControlBreedingProgress extends Control {
|
||||
private static Texture Progress = new StandardTexture(80, 22, 4, 4, CraftGUITextureSheet.Controls2);
|
||||
private float percentage;
|
||||
private int colour;
|
||||
|
||||
public ControlBreedingProgress(IWidget parent, int x, int y, int width, int height, BreedingSystem system, float percentage) {
|
||||
super(parent, x, y, width, height);
|
||||
this.percentage = percentage;
|
||||
colour = system.getColour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
CraftGUI.Render.texture(CraftGUITexture.PanelBlack, getArea());
|
||||
IArea area = getArea().inset(1);
|
||||
area.setSize(new IPoint(area.size().x() * percentage, area.size().y()));
|
||||
CraftGUI.Render.colour(colour);
|
||||
CraftGUI.Render.texture(ControlBreedingProgress.Progress, area);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class ControlDatabaseIndividualDisplay extends ControlItemDisplay implements ITooltip {
|
||||
protected EnumDiscoveryState discovered;
|
||||
|
||||
private IAlleleSpecies species;
|
||||
|
||||
public void setSpecies(IAlleleSpecies species) {
|
||||
setSpecies(species, EnumDiscoveryState.Show);
|
||||
}
|
||||
|
||||
public void setSpecies(IAlleleSpecies species, EnumDiscoveryState state) {
|
||||
ISpeciesRoot speciesRoot = Binnie.Genetics.getSpeciesRoot(species);
|
||||
BreedingSystem system = Binnie.Genetics.getSystem(speciesRoot.getUID());
|
||||
IIndividual ind = system.getSpeciesRoot().templateAsIndividual(system.getSpeciesRoot().getTemplate(species.getUID()));
|
||||
super.setItemStack(system.getSpeciesRoot().getMemberStack(ind, system.getDefaultType()));
|
||||
this.species = species;
|
||||
GameProfile username = Window.get(this).getUsername();
|
||||
if (state == EnumDiscoveryState.Undetermined) {
|
||||
state = (system.isSpeciesDiscovered(species, Window.get(this).getWorld(), username) ? EnumDiscoveryState.Discovered : EnumDiscoveryState.Undiscovered);
|
||||
}
|
||||
if (Window.get(this) instanceof WindowAbstractDatabase && ((WindowAbstractDatabase) Window.get(this)).isNEI) {
|
||||
state = EnumDiscoveryState.Show;
|
||||
}
|
||||
discovered = state;
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
|
||||
public ControlDatabaseIndividualDisplay(IWidget parent, float x, float y) {
|
||||
this(parent, x, y, 16.0f);
|
||||
}
|
||||
|
||||
public ControlDatabaseIndividualDisplay(IWidget parent, float x, float y, float size) {
|
||||
super(parent, x, y, size);
|
||||
species = null;
|
||||
discovered = EnumDiscoveryState.Show;
|
||||
addSelfEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
if (event.getButton() == 0 && species != null && EnumDiscoveryState.Show == discovered) {
|
||||
((WindowAbstractDatabase) getSuperParent()).gotoSpeciesDelayed(species);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderForeground() {
|
||||
IIcon icon = null;
|
||||
if (species == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BreedingSystem system = Binnie.Genetics.getSystem(species.getRoot());
|
||||
switch (discovered) {
|
||||
case Show:
|
||||
super.onRenderForeground();
|
||||
return;
|
||||
|
||||
case Discovered:
|
||||
icon = system.getDiscoveredIcon();
|
||||
break;
|
||||
|
||||
case Undiscovered:
|
||||
icon = system.getUndiscoveredIcon();
|
||||
break;
|
||||
}
|
||||
if (icon != null) {
|
||||
CraftGUI.Render.iconItem(IPoint.ZERO, icon);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(Tooltip tooltip) {
|
||||
if (species == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (discovered) {
|
||||
case Show:
|
||||
tooltip.add(species.getName());
|
||||
break;
|
||||
|
||||
case Discovered:
|
||||
tooltip.add("Discovered Species");
|
||||
break;
|
||||
|
||||
case Undiscovered:
|
||||
tooltip.add("Undiscovered Species");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.controls.listbox.ControlTextOption;
|
||||
import binnie.core.craftgui.geometry.CraftGUIUtil;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.minecraft.control.ControlItemDisplay;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ControlItemStackOption extends ControlTextOption<ItemStack> {
|
||||
private ControlItemDisplay controlBee;
|
||||
|
||||
public ControlItemStackOption(ControlList<ItemStack> controlList, ItemStack option, int y) {
|
||||
super(controlList, option, option.getDisplayName(), y);
|
||||
setSize(new IPoint(getSize().x(), 20.0f));
|
||||
(controlBee = new ControlItemDisplay(this, 2.0f, 2.0f)).setItemStack(option);
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
CraftGUIUtil.moveWidget(textWidget, new IPoint(22.0f, 0.0f));
|
||||
textWidget.setSize(textWidget.getSize().sub(new IPoint(24.0f, 0.0f)));
|
||||
int th = (int) CraftGUI.Render.textHeight(textWidget.getValue(), textWidget.getSize().x());
|
||||
int height = Math.max(20, th + 6);
|
||||
setSize(new IPoint(size().x(), height));
|
||||
textWidget.setSize(new IPoint(textWidget.getSize().x(), height));
|
||||
controlBee.setPosition(new IPoint(controlBee.pos().x(), (height - 18) / 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IMutation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class ControlMutationBox extends ControlListBox<IMutation> {
|
||||
private int index;
|
||||
private Type type;
|
||||
private IAlleleSpecies species;
|
||||
|
||||
@Override
|
||||
public IWidget createOption(IMutation value, int y) {
|
||||
return new ControlMutationItem(getContent(), value, species, y);
|
||||
}
|
||||
|
||||
public ControlMutationBox(IWidget parent, int x, int y, int width, int height, Type type) {
|
||||
super(parent, x, y, width, height, 12.0f);
|
||||
species = null;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setSpecies(IAlleleSpecies species) {
|
||||
if (species != this.species) {
|
||||
this.species = species;
|
||||
index = 0;
|
||||
movePercentage(-100.0f);
|
||||
BreedingSystem system = ((WindowAbstractDatabase) getSuperParent()).getBreedingSystem();
|
||||
List<IMutation> discovered = system.getDiscoveredMutations(Window.get(this).getWorld(), Window.get(this).getUsername());
|
||||
|
||||
if (species == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == Type.Resultant) {
|
||||
setOptions(system.getResultantMutations(species));
|
||||
} else {
|
||||
List<IMutation> mutations = system.getFurtherMutations(species);
|
||||
int i = 0;
|
||||
while (i < mutations.size()) {
|
||||
IMutation mutation = mutations.get(i);
|
||||
if (!discovered.contains(mutations) && !((IAlleleSpecies) mutation.getTemplate()[0]).isCounted()) {
|
||||
mutations.remove(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
setOptions(mutations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Type {
|
||||
Resultant,
|
||||
Further
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.controls.listbox.ControlOption;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IMutation;
|
||||
|
||||
class ControlMutationItem extends ControlOption<IMutation> {
|
||||
private ControlDatabaseIndividualDisplay itemWidget1;
|
||||
private ControlDatabaseIndividualDisplay itemWidget2;
|
||||
private ControlDatabaseIndividualDisplay itemWidget3;
|
||||
private ControlMutationSymbol addSymbol;
|
||||
private ControlMutationSymbol arrowSymbol;
|
||||
|
||||
public ControlMutationItem(ControlList<IMutation> controlList, IMutation option, IAlleleSpecies species, int y) {
|
||||
super(controlList, option, y);
|
||||
itemWidget1 = new ControlDatabaseIndividualDisplay(this, 4.0f, 4.0f);
|
||||
itemWidget2 = new ControlDatabaseIndividualDisplay(this, 44.0f, 4.0f);
|
||||
itemWidget3 = new ControlDatabaseIndividualDisplay(this, 104.0f, 4.0f);
|
||||
addSymbol = new ControlMutationSymbol(this, 24, 4, 0);
|
||||
arrowSymbol = new ControlMutationSymbol(this, 64, 4, 1);
|
||||
boolean isNEI = ((WindowAbstractDatabase) getSuperParent()).isNEI();
|
||||
BreedingSystem system = ((WindowAbstractDatabase) getSuperParent()).getBreedingSystem();
|
||||
|
||||
if (getValue() != null) {
|
||||
boolean isMutationDiscovered = system.isMutationDiscovered(getValue(), Window.get(this).getWorld(), Window.get(this).getUsername());
|
||||
IAlleleSpecies allele;
|
||||
EnumDiscoveryState state;
|
||||
allele = getValue().getAllele0();
|
||||
state = ((isNEI || isMutationDiscovered) ? EnumDiscoveryState.Show : ((species == allele) ? EnumDiscoveryState.Show : EnumDiscoveryState.Undetermined));
|
||||
itemWidget1.setSpecies(allele, state);
|
||||
allele = getValue().getAllele1();
|
||||
state = ((isNEI || isMutationDiscovered) ? EnumDiscoveryState.Show : ((species == allele) ? EnumDiscoveryState.Show : EnumDiscoveryState.Undetermined));
|
||||
itemWidget2.setSpecies(allele, state);
|
||||
allele = (IAlleleSpecies) getValue().getTemplate()[0];
|
||||
state = ((isNEI || isMutationDiscovered) ? EnumDiscoveryState.Show : ((species == allele) ? EnumDiscoveryState.Show : EnumDiscoveryState.Undetermined));
|
||||
itemWidget3.setSpecies(allele, state);
|
||||
addSymbol.setValue(getValue());
|
||||
arrowSymbol.setValue(getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.ITooltip;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.craftgui.resource.Texture;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITextureSheet;
|
||||
import binnie.core.craftgui.resource.minecraft.StandardTexture;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IMutation;
|
||||
|
||||
class ControlMutationSymbol extends Control implements ITooltip {
|
||||
private static Texture MutationPlus = new StandardTexture(2, 94, 16, 16, CraftGUITextureSheet.Controls2);
|
||||
private static Texture MutationArrow = new StandardTexture(20, 94, 32, 16, CraftGUITextureSheet.Controls2);
|
||||
private IMutation value;
|
||||
private boolean discovered;
|
||||
private int type;
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
super.onRenderBackground();
|
||||
if (type == 0) {
|
||||
CraftGUI.Render.texture(ControlMutationSymbol.MutationPlus, IPoint.ZERO);
|
||||
} else {
|
||||
CraftGUI.Render.texture(ControlMutationSymbol.MutationArrow, IPoint.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
protected ControlMutationSymbol(IWidget parent, int x, int y, int type) {
|
||||
super(parent, x, y, 16 + type * 16, 16.0f);
|
||||
value = null;
|
||||
this.type = type;
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
|
||||
public void setValue(IMutation value) {
|
||||
this.value = value;
|
||||
boolean isNEI = ((WindowAbstractDatabase) getSuperParent()).isNEI();
|
||||
BreedingSystem system = ((WindowAbstractDatabase) getSuperParent()).getBreedingSystem();
|
||||
discovered = (isNEI || system.isMutationDiscovered(value, Window.get(this).getWorld(), Window.get(this).getUsername()));
|
||||
if (discovered) {
|
||||
setColor(0xffffff);
|
||||
} else {
|
||||
setColor(0x777777);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTooltip(Tooltip tooltip) {
|
||||
if (type != 1 || !discovered) {
|
||||
return;
|
||||
}
|
||||
|
||||
IAllele species1 = value.getAllele0();
|
||||
IAllele species2 = value.getAllele1();
|
||||
BreedingSystem system = ((WindowAbstractDatabase) getSuperParent()).getBreedingSystem();
|
||||
float chance = system.getChance(value, Window.get(this).getPlayer(), species1, species2);
|
||||
tooltip.add("Current Chance - " + chance + "%");
|
||||
if (value.getSpecialConditions() != null) {
|
||||
for (String string : value.getSpecialConditions()) {
|
||||
tooltip.add(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IClassification;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ControlSpeciesBox extends ControlListBox<IAlleleSpecies>
|
||||
{
|
||||
private IClassification branch;
|
||||
|
||||
@Override
|
||||
public IWidget createOption(IAlleleSpecies value, int y) {
|
||||
return new ControlSpeciexBoxOption(this.getContent(), value, y);
|
||||
}
|
||||
|
||||
public ControlSpeciesBox(IWidget parent, float x, float y, float width, float height) {
|
||||
super(parent, x, y, width, height, 12.0f);
|
||||
branch = null;
|
||||
}
|
||||
|
||||
public void setBranch(IClassification branch) {
|
||||
if (branch == this.branch) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.branch = branch;
|
||||
List<IAlleleSpecies> speciesList2 = new ArrayList<>();
|
||||
movePercentage(-100.0f);
|
||||
setOptions(speciesList2);
|
||||
|
||||
EntityPlayer player = Window.get(this).getPlayer();
|
||||
GameProfile playerName = Window.get(this).getUsername();
|
||||
WindowAbstractDatabase db = Window.get(this);
|
||||
Collection<IAlleleSpecies> speciesList3 = db.isNEI ? db.getBreedingSystem().getAllSpecies() : db.getBreedingSystem().getDiscoveredSpecies(db.getWorld(), playerName);
|
||||
if (branch != null) {
|
||||
for (IAlleleSpecies species : branch.getMemberSpecies()) {
|
||||
if (speciesList3.contains(species)) {
|
||||
speciesList2.add(species);
|
||||
}
|
||||
}
|
||||
}
|
||||
setOptions(speciesList2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.controls.listbox.ControlList;
|
||||
import binnie.core.craftgui.controls.listbox.ControlTextOption;
|
||||
import binnie.core.craftgui.geometry.CraftGUIUtil;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
|
||||
class ControlSpeciexBoxOption extends ControlTextOption<IAlleleSpecies> {
|
||||
private ControlDatabaseIndividualDisplay controlBee;
|
||||
|
||||
public ControlSpeciexBoxOption(ControlList<IAlleleSpecies> controlList, IAlleleSpecies option, int y) {
|
||||
super(controlList, option, option.getName(), y);
|
||||
setSize(new IPoint(getSize().x(), 20.0f));
|
||||
(controlBee = new ControlDatabaseIndividualDisplay(this, 2.0f, 2.0f)).setSpecies(getValue(), EnumDiscoveryState.Undetermined);
|
||||
if (controlBee.discovered == EnumDiscoveryState.Discovered) {
|
||||
controlBee.discovered = EnumDiscoveryState.Show;
|
||||
}
|
||||
|
||||
textWidget.setValue((controlBee.discovered == EnumDiscoveryState.Show) ? option.getName() : "Undiscovered");
|
||||
if (controlBee.discovered == EnumDiscoveryState.Show) {
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
}
|
||||
|
||||
CraftGUIUtil.moveWidget(textWidget, new IPoint(22.0f, 0.0f));
|
||||
textWidget.setSize(textWidget.getSize().sub(new IPoint(24.0f, 0.0f)));
|
||||
int th = (int) CraftGUI.Render.textHeight(textWidget.getValue(), textWidget.getSize().x());
|
||||
int height = Math.max(20, th + 6);
|
||||
setSize(new IPoint(size().x(), height));
|
||||
textWidget.setSize(new IPoint(textWidget.getSize().x(), height));
|
||||
controlBee.setPosition(new IPoint(controlBee.pos().x(), (height - 18) / 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.AbstractMod;
|
||||
import binnie.core.craftgui.ITooltipHelp;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
|
||||
public class DatabaseTab implements ITooltipHelp {
|
||||
private AbstractMod mod;
|
||||
private String unloc;
|
||||
private int colour;
|
||||
|
||||
public DatabaseTab(AbstractMod mod, String unloc, int colour) {
|
||||
this.mod = mod;
|
||||
this.unloc = unloc;
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Binnie.Language.localise(mod, "gui.database.tab." + unloc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getHelpTooltip(Tooltip tooltip) {
|
||||
tooltip.add(Binnie.Language.localiseOrBlank(mod, "gui.database.tab." + unloc + ".help"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
public enum EnumDiscoveryState {
|
||||
Show,
|
||||
Undetermined,
|
||||
Discovered,
|
||||
Undiscovered
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
public interface IDatabaseMode {
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.page.ControlPage;
|
||||
|
||||
public abstract class PageAbstract<T> extends ControlPage<DatabaseTab> {
|
||||
public PageAbstract(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, 0.0f, 0.0f, parent.getSize().x(), parent.getSize().y(), tab);
|
||||
}
|
||||
|
||||
public abstract void onValueChanged(T value);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import forestry.api.genetics.IClassification;
|
||||
|
||||
abstract class PageBranch extends PageAbstract<IClassification> {
|
||||
public PageBranch(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import forestry.api.genetics.IClassification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PageBranchOverview extends PageBranch {
|
||||
private ControlText pageBranchOverview_branchName;
|
||||
private ControlText pageBranchOverview_branchScientific;
|
||||
private ControlText pageBranchOverview_branchAuthority;
|
||||
private List<ControlText> pageBranchOverview_branchDescription;
|
||||
|
||||
public PageBranchOverview(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
pageBranchOverview_branchDescription = new ArrayList<>();
|
||||
pageBranchOverview_branchName = new ControlTextCentered(this, 8.0f, "");
|
||||
pageBranchOverview_branchScientific = new ControlTextCentered(this, 32.0f, "");
|
||||
pageBranchOverview_branchAuthority = new ControlTextCentered(this, 44.0f, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(IClassification branch) {
|
||||
pageBranchOverview_branchName.setValue("§n" + branch.getName() + " Branch§r");
|
||||
pageBranchOverview_branchScientific.setValue("§oApidae " + branch.getScientific() + "§r");
|
||||
pageBranchOverview_branchAuthority.setValue("Discovered by §l" + branch.getMemberSpecies()[0].getAuthority() + "§r");
|
||||
for (IWidget widget : pageBranchOverview_branchDescription) {
|
||||
deleteChild(widget);
|
||||
}
|
||||
|
||||
pageBranchOverview_branchDescription.clear();
|
||||
String desc = branch.getDescription();
|
||||
if (desc == null || desc == "") {
|
||||
desc = "No Description Provided.";
|
||||
}
|
||||
|
||||
String line = "";
|
||||
List<String> descLines = new ArrayList<String>();
|
||||
for (String str : desc.split(" ")) {
|
||||
if (CraftGUI.Render.textWidth(line + " " + str) > 134) {
|
||||
descLines.add("§o" + line + "§r");
|
||||
line = "";
|
||||
}
|
||||
line = line + " " + str;
|
||||
}
|
||||
|
||||
descLines.add(line);
|
||||
int i = 0;
|
||||
for (String dLine : descLines) {
|
||||
pageBranchOverview_branchDescription.add(new ControlTextCentered(this, 84 + 12 * i++, dLine));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IClassification;
|
||||
|
||||
public class PageBranchSpecies extends PageBranch {
|
||||
private ControlText pageBranchSpecies_title;
|
||||
private ControlSpeciesBox pageBranchSpecies_speciesList;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onHandleEvent(EventValueChanged<IAlleleSpecies> event) {
|
||||
// ignored
|
||||
}
|
||||
|
||||
public PageBranchSpecies(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
pageBranchSpecies_title = new ControlTextCentered(this, 8.0f, "Species");
|
||||
addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
if (event.isOrigin(pageBranchSpecies_speciesList)) {
|
||||
((WindowAbstractDatabase) getSuperParent()).gotoSpecies((IAlleleSpecies) event.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
pageBranchSpecies_speciesList = new ControlSpeciesBox(this, 4.0f, 20.0f, 136.0f, 152.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(IClassification branch) {
|
||||
pageBranchSpecies_speciesList.setBranch(branch);
|
||||
}
|
||||
}
|
||||
+15
-18
@@ -1,41 +1,38 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.mod.database;
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import binnie.core.craftgui.controls.page.ControlPage;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import binnie.craftgui.controls.ControlTextCentered;
|
||||
import binnie.craftgui.minecraft.Window;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import binnie.craftgui.controls.page.ControlPage;
|
||||
|
||||
public class PageBreeder extends ControlPage<DatabaseTab>
|
||||
{
|
||||
public class PageBreeder extends ControlPage<DatabaseTab> {
|
||||
private GameProfile player;
|
||||
|
||||
public PageBreeder(final IWidget parent, final GameProfile player, final DatabaseTab tab) {
|
||||
public PageBreeder(IWidget parent, GameProfile player, DatabaseTab tab) {
|
||||
super(parent, 0.0f, 0.0f, parent.getSize().x(), parent.getSize().y(), tab);
|
||||
this.player = player;
|
||||
this.onPageRefresh();
|
||||
onPageRefresh();
|
||||
}
|
||||
|
||||
public void onPageRefresh() {
|
||||
while (this.getWidgets().size() > 0) {
|
||||
this.deleteChild(this.getWidgets().get(0));
|
||||
while (getWidgets().size() > 0) {
|
||||
deleteChild(getWidgets().get(0));
|
||||
}
|
||||
final BreedingSystem system = ((WindowAbstractDatabase) Window.get(this)).getBreedingSystem();
|
||||
final String descriptor = system.getDescriptor();
|
||||
|
||||
BreedingSystem system = ((WindowAbstractDatabase) Window.get(this)).getBreedingSystem();
|
||||
String descriptor = system.getDescriptor();
|
||||
new ControlTextCentered(this, 8.0f, "§n" + system.getDescriptor() + " Profile§r");
|
||||
new ControlTextCentered(this, 75.0f, "" + system.discoveredSpeciesCount + "/" + system.totalSpeciesCount + " Species");
|
||||
new ControlBreedingProgress(this, 20, 87, 102, 14, system, system.discoveredSpeciesPercentage);
|
||||
new ControlTextCentered(this, 115.0f, "" + system.discoveredBranchCount + "/" + system.totalBranchCount + " Branches");
|
||||
new ControlBreedingProgress(this, 20, 127, 102, 14, system, system.discoveredBranchPercentage);
|
||||
|
||||
if (system.discoveredSecretCount > 0) {
|
||||
new ControlTextCentered(this, 155.0f, "" + system.discoveredSecretCount + "/" + system.totalSecretCount + " Secret Species");
|
||||
}
|
||||
new ControlTextCentered(this, 32.0f, this.player.getName());
|
||||
new ControlTextCentered(this, 32.0f, player.getName());
|
||||
new ControlTextCentered(this, 44.0f, "§o" + system.getEpitome() + "§r");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
|
||||
// TODO unused class?
|
||||
public class PageBreederStats extends Control {
|
||||
String player;
|
||||
|
||||
public PageBreederStats(IWidget parent, int w, int h, String player) {
|
||||
super(parent, 0.0f, 0.0f, w, h);
|
||||
this.player = player;
|
||||
ControlText pageBranchOverview_branchName = new ControlTextCentered(this, 8.0f, "§nStats§r");
|
||||
BreedingSystem system = ((WindowAbstractDatabase) getSuperParent()).getBreedingSystem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
|
||||
public abstract class PageSpecies extends PageAbstract<IAlleleSpecies> {
|
||||
public PageSpecies(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IClassification;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PageSpeciesClassification extends PageSpecies {
|
||||
private Map<IClassification.EnumClassLevel, ControlText> levels;
|
||||
private ControlText genus;
|
||||
|
||||
public PageSpeciesClassification(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
levels = new LinkedHashMap<>();
|
||||
int y = 16;
|
||||
for (IClassification.EnumClassLevel level : IClassification.EnumClassLevel.values()) {
|
||||
ControlText text = new ControlTextCentered(this, y, "");
|
||||
text.setColor(level.getColour());
|
||||
levels.put(level, text);
|
||||
y += 12;
|
||||
}
|
||||
|
||||
genus = new ControlTextCentered(this, y, "");
|
||||
genus.setColor(0xffba77);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(IAlleleSpecies species) {
|
||||
if (species == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ControlText text : levels.values()) {
|
||||
text.setValue("- - -");
|
||||
}
|
||||
|
||||
genus.setValue(species.getBinomial());
|
||||
for (IClassification classification = species.getBranch(); classification != null; classification = classification.getParent()) {
|
||||
IClassification.EnumClassLevel level = classification.getLevel();
|
||||
String text2 = "";
|
||||
text2 += classification.getScientific();
|
||||
levels.get(level).setValue(text2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
|
||||
public class PageSpeciesMutations extends PageSpecies {
|
||||
private ControlText pageSpeciesFurtherTitle;
|
||||
private ControlMutationBox pageSpeciesFurtherList;
|
||||
|
||||
public PageSpeciesMutations(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
pageSpeciesFurtherTitle = new ControlTextCentered(this, 8.0f, "Further Mutations");
|
||||
pageSpeciesFurtherList = new ControlMutationBox(this, 4, 20, 136, 152, ControlMutationBox.Type.Further);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(IAlleleSpecies species) {
|
||||
pageSpeciesFurtherList.setSpecies(species);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.TextJustification;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
|
||||
public class PageSpeciesOverview extends PageSpecies {
|
||||
private ControlText controlName;
|
||||
private ControlText controlScientific;
|
||||
private ControlText controlAuthority;
|
||||
private ControlText controlComplexity;
|
||||
private ControlText controlDescription;
|
||||
private ControlText controlSignature;
|
||||
private ControlDatabaseIndividualDisplay controlInd1;
|
||||
private ControlDatabaseIndividualDisplay controlInd2;
|
||||
|
||||
public PageSpeciesOverview(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
controlInd1 = new ControlDatabaseIndividualDisplay(this, 5.0f, 5.0f);
|
||||
controlInd2 = new ControlDatabaseIndividualDisplay(this, 123.0f, 5.0f);
|
||||
controlName = new ControlTextCentered(this, 8.0f, "");
|
||||
controlScientific = new ControlTextCentered(this, 32.0f, "");
|
||||
controlAuthority = new ControlTextCentered(this, 44.0f, "");
|
||||
controlComplexity = new ControlTextCentered(this, 56.0f, "");
|
||||
controlDescription = new ControlText(this, new IArea(8.0f, 84.0f, getSize().x() - 16.0f, 0.0f), "", TextJustification.MiddleCenter);
|
||||
controlSignature = new ControlText(this, new IArea(8.0f, 84.0f, getSize().x() - 16.0f, 0.0f), "", TextJustification.BottomRight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(IAlleleSpecies species) {
|
||||
controlInd1.setSpecies(species, EnumDiscoveryState.Show);
|
||||
controlInd2.setSpecies(species, EnumDiscoveryState.Show);
|
||||
String branchBinomial = (species.getBranch() != null) ? species.getBranch().getScientific() : "<Unknown>";
|
||||
String branchName = (species.getBranch() != null) ? species.getBranch().getName() : "Unknown";
|
||||
controlName.setValue("§n" + species.getName() + "§r");
|
||||
controlScientific.setValue("§o" + branchBinomial + " " + species.getBinomial() + "§r");
|
||||
controlAuthority.setValue("Discovered by §l" + species.getAuthority() + "§r");
|
||||
controlComplexity.setValue("Complexity: " + species.getComplexity());
|
||||
String desc = species.getDescription();
|
||||
String descBody = "§o";
|
||||
String descSig = "";
|
||||
|
||||
if (desc == null || desc == "") {
|
||||
descBody += "No Description Provided.";
|
||||
} else {
|
||||
String[] descStrings = desc.split("\\|");
|
||||
descBody += descStrings[0];
|
||||
for (int i = 1; i < descStrings.length - 1; ++i) {
|
||||
descBody = descBody + " " + descStrings[i];
|
||||
}
|
||||
if (descStrings.length > 1) {
|
||||
descSig += descStrings[descStrings.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
controlDescription.setValue(descBody + "§r");
|
||||
controlSignature.setValue(descSig + "§r");
|
||||
float descHeight = CraftGUI.Render.textHeight(controlDescription.getValue(), controlDescription.getSize().x());
|
||||
controlSignature.setPosition(new IPoint(controlSignature.pos().x(), controlDescription.getPosition().y() + descHeight + 10.0f));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlText;
|
||||
import binnie.core.craftgui.controls.ControlTextCentered;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
|
||||
public class PageSpeciesResultant extends PageSpecies {
|
||||
private ControlText pageSpeciesResultantTitle;
|
||||
private ControlMutationBox pageSpeciesResultantList;
|
||||
|
||||
public PageSpeciesResultant(IWidget parent, DatabaseTab tab) {
|
||||
super(parent, tab);
|
||||
pageSpeciesResultantTitle = new ControlTextCentered(this, 8.0f, "Resultant Mutations");
|
||||
pageSpeciesResultantList = new ControlMutationBox(this, 4, 20, 136, 152, ControlMutationBox.Type.Resultant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(IAlleleSpecies species) {
|
||||
pageSpeciesResultantList.setSpecies(species);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package binnie.core.craftgui.database;
|
||||
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.ControlTextEdit;
|
||||
import binnie.core.craftgui.controls.listbox.ControlListBox;
|
||||
import binnie.core.craftgui.controls.listbox.ControlTextOption;
|
||||
import binnie.core.craftgui.controls.page.ControlPage;
|
||||
import binnie.core.craftgui.controls.page.ControlPages;
|
||||
import binnie.core.craftgui.controls.tab.ControlTab;
|
||||
import binnie.core.craftgui.controls.tab.ControlTabBar;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventTextEdit;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
import binnie.core.craftgui.geometry.CraftGUIUtil;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.geometry.Position;
|
||||
import binnie.core.craftgui.minecraft.MinecraftGUI;
|
||||
import binnie.core.craftgui.minecraft.Window;
|
||||
import binnie.core.craftgui.minecraft.control.ControlHelp;
|
||||
import binnie.core.craftgui.window.Panel;
|
||||
import binnie.core.genetics.BreedingSystem;
|
||||
import binnie.core.util.IValidator;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IClassification;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class WindowAbstractDatabase extends Window {
|
||||
protected boolean isNEI;
|
||||
|
||||
private float selectionBoxWidth;
|
||||
private float infoBoxWidth = 144.0f;
|
||||
private float infoBoxHeight = 176.0f;
|
||||
private float infoTabWidth = 16.0f;
|
||||
private float modeTabWidth = 22.0f;
|
||||
private float searchBoxHeight = 16.0f;
|
||||
private Map<IDatabaseMode, ModeWidgets> modes;
|
||||
private BreedingSystem system;
|
||||
private Panel panelInformation;
|
||||
private Panel panelSearch;
|
||||
private ControlPages<IDatabaseMode> modePages;
|
||||
private IAlleleSpecies gotoSpecies;
|
||||
|
||||
public void changeMode(IDatabaseMode mode) {
|
||||
modePages.setValue(mode);
|
||||
}
|
||||
|
||||
public WindowAbstractDatabase(EntityPlayer player, Side side, boolean nei, BreedingSystem system, float wid) {
|
||||
super(100.0f, 192.0f, player, null, side);
|
||||
selectionBoxWidth = 95.0f;
|
||||
modes = new HashMap<>();
|
||||
isNEI = nei;
|
||||
this.system = system;
|
||||
selectionBoxWidth = wid;
|
||||
}
|
||||
|
||||
public ControlPages<DatabaseTab> getInfoPages(IDatabaseMode mode) {
|
||||
return modes.get(mode).infoPages;
|
||||
}
|
||||
|
||||
public boolean isNEI() {
|
||||
return isNEI;
|
||||
}
|
||||
|
||||
public BreedingSystem getBreedingSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
public WindowAbstractDatabase(EntityPlayer player, Side side, boolean nei, BreedingSystem system) {
|
||||
this(player, side, nei, system, 95.0f);
|
||||
}
|
||||
|
||||
protected ModeWidgets createMode(IDatabaseMode mode, ModeWidgets widgets) {
|
||||
modes.put(mode, widgets);
|
||||
return widgets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseClient() {
|
||||
setSize(new IPoint(176.0f + selectionBoxWidth + 22.0f + 8.0f, 208.0f));
|
||||
addEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
if (!(event.getOrigin().getParent() instanceof ControlPage)) {
|
||||
return;
|
||||
} else if ((event.getValue() instanceof DatabaseTab)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ControlPage parent = (ControlPage) event.getOrigin().getParent();
|
||||
if (!(parent.getValue() instanceof IDatabaseMode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (IWidget widget : parent.getWidgets()) {
|
||||
if (widget instanceof ControlPages) {
|
||||
if (event.getValue() == null) {
|
||||
widget.hide();
|
||||
} else {
|
||||
widget.show();
|
||||
for (IWidget widget2 : widget.getWidgets()) {
|
||||
if (widget2 instanceof PageAbstract) {
|
||||
((PageAbstract) widget2).onValueChanged(event.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addEventHandler(new EventTextEdit.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventTextEdit event) {
|
||||
for (ModeWidgets widgets : modes.values()) {
|
||||
widgets.listBox.setValidator(new IValidator<IWidget>() {
|
||||
@Override
|
||||
public boolean isValid(IWidget object) {
|
||||
return event.getValue() == "" || ((ControlTextOption) object).getText().toLowerCase().contains(event.getValue().toLowerCase());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.DirectChild, this));
|
||||
|
||||
new ControlHelp(this, 4.0f, 4.0f);
|
||||
(panelInformation = new Panel(this, 24.0f, 24.0f, 144.0f, 176.0f, MinecraftGUI.PanelType.Black)).setColor(860416);
|
||||
(panelSearch = new Panel(this, 176.0f, 24.0f, selectionBoxWidth, 160.0f, MinecraftGUI.PanelType.Black)).setColor(860416);
|
||||
modePages = new ControlPages<>(this, 0.0f, 0.0f, getSize().x(), getSize().y());
|
||||
new ControlTextEdit(this, 176.0f, 184.0f, selectionBoxWidth, 16.0f);
|
||||
|
||||
createMode(Mode.Species, new ModeWidgets(Mode.Species, this) {
|
||||
@Override
|
||||
public void createListBox(IArea area) {
|
||||
GameProfile playerName = getUsername();
|
||||
Collection<IAlleleSpecies> speciesList = database.isNEI ? database.system.getAllSpecies() : database.system.getDiscoveredSpecies(database.getWorld(), playerName);
|
||||
(listBox = new ControlSpeciesBox(modePage, area.x(), area.y(), area.w(), area.h())).setOptions(speciesList);
|
||||
}
|
||||
});
|
||||
|
||||
createMode(Mode.Branches, new ModeWidgets(Mode.Branches, this) {
|
||||
@Override
|
||||
public void createListBox(IArea area) {
|
||||
EntityPlayer player = database.getPlayer();
|
||||
GameProfile playerName = getUsername();
|
||||
Collection<IClassification> speciesList = database.isNEI ? database.system.getAllBranches() : database.system.getDiscoveredBranches(database.getWorld(), playerName);
|
||||
(listBox = new ControlBranchBox(modePage, area.x(), area.y(), area.w(), area.h())).setOptions(speciesList);
|
||||
}
|
||||
});
|
||||
|
||||
createMode(Mode.Breeder, new ModeWidgets(Mode.Breeder, this) {
|
||||
@Override
|
||||
public void createListBox(IArea area) {
|
||||
listBox = new ControlListBox(modePage, area.x(), area.y(), area.w(), area.h(), 12.0f);
|
||||
}
|
||||
});
|
||||
|
||||
addTabs();
|
||||
ControlTabBar<IDatabaseMode> tab = new ControlTabBar<IDatabaseMode>(this, 176.0f + selectionBoxWidth, 24.0f, 22.0f, 176.0f, Position.Right) {
|
||||
@Override
|
||||
public ControlTab<IDatabaseMode> createTab(float x, float y, float w, float h, IDatabaseMode value) {
|
||||
return new ControlTab<IDatabaseMode>(this, x, y, w, h, value) {
|
||||
@Override
|
||||
public String getName() {
|
||||
return value.getName();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
tab.setValues(modePages.getValues());
|
||||
CraftGUIUtil.linkWidgets(tab, modePages);
|
||||
changeMode(Mode.Species);
|
||||
for (IDatabaseMode mode : modes.keySet()) {
|
||||
modes.get(mode).infoTabs = new ControlTabBar(modes.get(mode).modePage, 8.0f, 24.0f, 16.0f, 176.0f, Position.Left);
|
||||
modes.get(mode).infoTabs.setValues(modes.get(mode).infoPages.getValues());
|
||||
CraftGUIUtil.linkWidgets(modes.get(mode).infoTabs, modes.get(mode).infoPages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialiseServer() {
|
||||
IBreedingTracker tracker = system.getSpeciesRoot().getBreedingTracker(getWorld(), getUsername());
|
||||
if (tracker != null) {
|
||||
tracker.synchToPlayer(getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTabs() {
|
||||
// ignoreds
|
||||
}
|
||||
|
||||
public void gotoSpecies(IAlleleSpecies value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
modePages.setValue(Mode.Species);
|
||||
changeMode(Mode.Species);
|
||||
modes.get(modePages.getValue()).listBox.setValue(value);
|
||||
}
|
||||
|
||||
public void gotoSpeciesDelayed(IAlleleSpecies species) {
|
||||
gotoSpecies = species;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
super.onUpdateClient();
|
||||
if (gotoSpecies == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
((WindowAbstractDatabase) getSuperParent()).gotoSpecies(gotoSpecies);
|
||||
gotoSpecies = null;
|
||||
}
|
||||
|
||||
public enum Mode implements IDatabaseMode {
|
||||
Species,
|
||||
Branches,
|
||||
Breeder;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return BinnieCore.proxy.localise("gui.database.mode." + name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class ModeWidgets {
|
||||
public WindowAbstractDatabase database;
|
||||
public ControlPage<IDatabaseMode> modePage;
|
||||
private ControlPages<DatabaseTab> infoPages;
|
||||
public ControlListBox listBox;
|
||||
private ControlTabBar<DatabaseTab> infoTabs;
|
||||
|
||||
public ModeWidgets(IDatabaseMode mode, WindowAbstractDatabase database) {
|
||||
this.database = database;
|
||||
modePage = new ControlPage<>(database.modePages, 0.0f, 0.0f, database.getSize().x(), database.getSize().y(), mode);
|
||||
IArea listBoxArea = database.panelSearch.area().inset(2);
|
||||
createListBox(listBoxArea);
|
||||
CraftGUIUtil.alignToWidget(listBox, database.panelSearch);
|
||||
CraftGUIUtil.moveWidget(listBox, new IPoint(2.0f, 2.0f));
|
||||
CraftGUIUtil.alignToWidget(infoPages = new ControlPages<>(modePage, 0.0f, 0.0f, 144.0f, 176.0f), database.panelInformation);
|
||||
}
|
||||
|
||||
public abstract void createListBox(IArea p0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class Event {
|
||||
IWidget origin;
|
||||
|
||||
public Event(IWidget origin) {
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
public IWidget getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
public boolean isOrigin(IWidget widget) {
|
||||
return origin == widget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class EventButtonClicked extends Event {
|
||||
public EventButtonClicked(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<EventButtonClicked> {
|
||||
public Handler() {
|
||||
super(EventButtonClicked.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class EventCycleChanged extends Event {
|
||||
public int value;
|
||||
|
||||
public EventCycleChanged(IWidget origin, int value) {
|
||||
super(origin);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public abstract class EventHandler<E extends Event> {
|
||||
Class<E> eventClass;
|
||||
Origin origin;
|
||||
IWidget relative;
|
||||
|
||||
public EventHandler(Class<E> eventClass) {
|
||||
this.eventClass = eventClass;
|
||||
origin = Origin.Any;
|
||||
}
|
||||
|
||||
public EventHandler setOrigin(Origin origin, IWidget relative) {
|
||||
this.origin = origin;
|
||||
this.relative = relative;
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract void onEvent(E event);
|
||||
|
||||
public boolean handles(Event e) {
|
||||
return eventClass.isInstance(e) && origin.isOrigin(e.getOrigin(), relative);
|
||||
}
|
||||
|
||||
public enum Origin {
|
||||
Any,
|
||||
Self,
|
||||
Parent,
|
||||
DirectChild;
|
||||
|
||||
public boolean isOrigin(IWidget origin, IWidget test) {
|
||||
switch (this) {
|
||||
case Any:
|
||||
return true;
|
||||
|
||||
case DirectChild:
|
||||
return test.getWidgets().contains(origin);
|
||||
|
||||
case Parent:
|
||||
return test.getParent() == origin;
|
||||
|
||||
case Self:
|
||||
return test == origin;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public abstract class EventKey extends Event {
|
||||
char character;
|
||||
int key;
|
||||
|
||||
public EventKey(IWidget origin, char character, int key) {
|
||||
super(origin);
|
||||
this.character = character;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public char getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
public int getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public static class Down extends EventKey {
|
||||
public Down(IWidget origin, char character, int key) {
|
||||
super(origin, character, key);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Down> {
|
||||
public Handler() {
|
||||
super(Down.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO unused class?
|
||||
public static class Up extends EventKey {
|
||||
public Up(IWidget origin, char character, int key) {
|
||||
super(origin, character, key);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Up> {
|
||||
public Handler() {
|
||||
super(Up.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public abstract class EventMouse extends Event {
|
||||
public EventMouse(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public static class Button extends EventMouse {
|
||||
protected int x;
|
||||
protected int y;
|
||||
protected int button;
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
public Button(IWidget currentMousedOverWidget, int x, int y, int button) {
|
||||
super(currentMousedOverWidget);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Down extends Button {
|
||||
public Down(IWidget currentMousedOverWidget, int x, int y, int button) {
|
||||
super(currentMousedOverWidget, x, y, button);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Down> {
|
||||
public Handler() {
|
||||
super(Down.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Up extends Button {
|
||||
public Up(IWidget currentMousedOverWidget, int x, int y, int button) {
|
||||
super(currentMousedOverWidget, x, y, button);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Up> {
|
||||
public Handler() {
|
||||
super(Up.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Move extends EventMouse {
|
||||
protected float dx;
|
||||
protected float dy;
|
||||
|
||||
public float getDx() {
|
||||
return dx;
|
||||
}
|
||||
|
||||
public float getDy() {
|
||||
return dy;
|
||||
}
|
||||
|
||||
public Move(IWidget origin, float dx, float dy) {
|
||||
super(origin);
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Move> {
|
||||
public Handler() {
|
||||
super(Move.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Drag extends Move {
|
||||
public Drag(IWidget draggedWidget, float dx, float dy) {
|
||||
super(draggedWidget, dx, dy);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Drag> {
|
||||
public Handler() {
|
||||
super(Drag.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Wheel extends EventMouse {
|
||||
protected int dWheel;
|
||||
|
||||
public Wheel(IWidget origin, int dWheel) {
|
||||
super(origin);
|
||||
this.dWheel = 0;
|
||||
this.dWheel = dWheel / 28;
|
||||
}
|
||||
|
||||
public int getDWheel() {
|
||||
return dWheel;
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Wheel> {
|
||||
public Handler() {
|
||||
super(Wheel.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class EventTextEdit extends EventValueChanged<String> {
|
||||
public EventTextEdit(IWidget origin, String text) {
|
||||
super(origin, text);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<EventTextEdit> {
|
||||
public Handler() {
|
||||
super(EventTextEdit.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class EventToggleButtonClicked extends Event {
|
||||
protected boolean toggled;
|
||||
|
||||
public EventToggleButtonClicked(IWidget origin, boolean toggled) {
|
||||
super(origin);
|
||||
this.toggled = toggled;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return toggled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class EventValueChanged<T> extends Event {
|
||||
public T value;
|
||||
|
||||
public EventValueChanged(IWidget origin, T value) {
|
||||
super(origin);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<EventValueChanged> {
|
||||
public Handler() {
|
||||
super(EventValueChanged.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
public class EventValuesChanged<T> extends Event {
|
||||
public T[] values;
|
||||
|
||||
public EventValuesChanged(IWidget origin, T[] values) {
|
||||
super(origin);
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public T[] getValues() {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
+48
-81
@@ -1,214 +1,181 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
package binnie.core.craftgui.events;
|
||||
|
||||
package binnie.craftgui.events;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
|
||||
import binnie.craftgui.core.IWidget;
|
||||
|
||||
public class EventWidget extends Event
|
||||
{
|
||||
public EventWidget(final IWidget origin) {
|
||||
public class EventWidget extends Event {
|
||||
public EventWidget(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public static class Enable extends EventWidget
|
||||
{
|
||||
public Enable(final IWidget origin) {
|
||||
public static class Enable extends EventWidget {
|
||||
public Enable(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Enable>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<Enable> {
|
||||
public Handler() {
|
||||
super(Enable.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Disable extends EventWidget
|
||||
{
|
||||
public Disable(final IWidget origin) {
|
||||
public static class Disable extends EventWidget {
|
||||
public Disable(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Disable>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<Disable> {
|
||||
public Handler() {
|
||||
super(Disable.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Show extends EventWidget
|
||||
{
|
||||
public Show(final IWidget origin) {
|
||||
public static class Show extends EventWidget {
|
||||
public Show(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Show>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<Show> {
|
||||
public Handler() {
|
||||
super(Show.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Hide extends EventWidget
|
||||
{
|
||||
public Hide(final IWidget origin) {
|
||||
public static class Hide extends EventWidget {
|
||||
public Hide(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<Hide>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<Hide> {
|
||||
public Handler() {
|
||||
super(Hide.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangePosition extends EventWidget
|
||||
{
|
||||
public ChangePosition(final IWidget origin) {
|
||||
public static class ChangePosition extends EventWidget {
|
||||
public ChangePosition(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<ChangePosition>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<ChangePosition> {
|
||||
public Handler() {
|
||||
super(ChangePosition.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangeSize extends EventWidget
|
||||
{
|
||||
public ChangeSize(final IWidget origin) {
|
||||
public static class ChangeSize extends EventWidget {
|
||||
public ChangeSize(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<ChangeSize>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<ChangeSize> {
|
||||
public Handler() {
|
||||
super(ChangeSize.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangeOffset extends EventWidget
|
||||
{
|
||||
public ChangeOffset(final IWidget origin) {
|
||||
public static class ChangeOffset extends EventWidget {
|
||||
public ChangeOffset(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<ChangeOffset>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<ChangeOffset> {
|
||||
public Handler() {
|
||||
super(ChangeOffset.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChangeColour extends EventWidget
|
||||
{
|
||||
public ChangeColour(final IWidget origin) {
|
||||
public static class ChangeColour extends EventWidget {
|
||||
public ChangeColour(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<ChangeColour>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<ChangeColour> {
|
||||
public Handler() {
|
||||
super(ChangeColour.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StartMouseOver extends EventWidget
|
||||
{
|
||||
public StartMouseOver(final IWidget origin) {
|
||||
public static class StartMouseOver extends EventWidget {
|
||||
public StartMouseOver(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<StartMouseOver>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<StartMouseOver> {
|
||||
public Handler() {
|
||||
super(StartMouseOver.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EndMouseOver extends EventWidget
|
||||
{
|
||||
public EndMouseOver(final IWidget origin) {
|
||||
public static class EndMouseOver extends EventWidget {
|
||||
public EndMouseOver(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<EndMouseOver>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<EndMouseOver> {
|
||||
public Handler() {
|
||||
super(EndMouseOver.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StartDrag extends EventWidget
|
||||
{
|
||||
int button;
|
||||
public static class StartDrag extends EventWidget {
|
||||
protected int button;
|
||||
|
||||
public StartDrag(final IWidget origin, final int button) {
|
||||
public StartDrag(IWidget origin, int button) {
|
||||
super(origin);
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
public int getButton() {
|
||||
return this.button;
|
||||
return button;
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<StartDrag>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<StartDrag> {
|
||||
public Handler() {
|
||||
super(StartDrag.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EndDrag extends EventWidget
|
||||
{
|
||||
public EndDrag(final IWidget origin) {
|
||||
public static class EndDrag extends EventWidget {
|
||||
public EndDrag(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<EndDrag>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<EndDrag> {
|
||||
public Handler() {
|
||||
super(EndDrag.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class GainFocus extends EventWidget
|
||||
{
|
||||
public GainFocus(final IWidget origin) {
|
||||
public static class GainFocus extends EventWidget {
|
||||
public GainFocus(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<GainFocus>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<GainFocus> {
|
||||
public Handler() {
|
||||
super(GainFocus.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoseFocus extends EventWidget
|
||||
{
|
||||
public LoseFocus(final IWidget origin) {
|
||||
public static class LoseFocus extends EventWidget {
|
||||
public LoseFocus(IWidget origin) {
|
||||
super(origin);
|
||||
}
|
||||
|
||||
public abstract static class Handler extends EventHandler<LoseFocus>
|
||||
{
|
||||
public abstract static class Handler extends EventHandler<LoseFocus> {
|
||||
public Handler() {
|
||||
super(LoseFocus.class);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package binnie.core.craftgui.geometry;
|
||||
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.IControlValue;
|
||||
import binnie.core.craftgui.events.EventValueChanged;
|
||||
|
||||
public class CraftGUIUtil {
|
||||
public static void alignToWidget(IWidget target, IWidget relativeTo) {
|
||||
IPoint startPos = target.getAbsolutePosition();
|
||||
IPoint endPos = relativeTo.getAbsolutePosition();
|
||||
moveWidget(target, endPos.sub(startPos));
|
||||
}
|
||||
|
||||
public static void moveWidget(IWidget target, IPoint movement) {
|
||||
target.setPosition(target.getPosition().add(movement));
|
||||
}
|
||||
|
||||
public static void horizontalGrid(float px, float py, IWidget... widgets) {
|
||||
horizontalGrid(px, py, TextJustification.MiddleCenter, 0.0f, widgets);
|
||||
}
|
||||
|
||||
public static void horizontalGrid(float px, float py, TextJustification just, float spacing, IWidget... widgets) {
|
||||
float x = 0.0f;
|
||||
float h = 0.0f;
|
||||
for (IWidget widget : widgets) {
|
||||
h = Math.max(h, widget.getSize().y());
|
||||
}
|
||||
for (IWidget widget : widgets) {
|
||||
widget.setPosition(new IPoint(px + x, py + (h - widget.getSize().y()) * just.yOffset));
|
||||
x += widget.getSize().x() + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
public static void verticalGrid(float px, float py, IWidget... widgets) {
|
||||
horizontalGrid(px, py, TextJustification.MiddleCenter, 0.0f, widgets);
|
||||
}
|
||||
|
||||
public static void verticalGrid(float px, float py, TextJustification just, float spacing, IWidget... widgets) {
|
||||
float y = 0.0f;
|
||||
float w = 0.0f;
|
||||
for (IWidget widget : widgets) {
|
||||
w = Math.max(w, widget.getSize().x());
|
||||
}
|
||||
for (IWidget widget : widgets) {
|
||||
widget.setPosition(new IPoint(px + (w - widget.getSize().x()) * just.xOffset, py + y));
|
||||
y += widget.getSize().y() + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void linkWidgets(IControlValue<T> tab, IControlValue<T> target) {
|
||||
tab.addSelfEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
target.setValue((T) event.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
target.addSelfEventHandler(new EventValueChanged.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventValueChanged event) {
|
||||
tab.setValue((T) event.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package binnie.core.craftgui.geometry;
|
||||
|
||||
public class IArea {
|
||||
private IPoint pos;
|
||||
private IPoint size;
|
||||
|
||||
public IArea(IArea area) {
|
||||
this(area.pos().x(), area.pos().y(), area.size().x(), area.size().y());
|
||||
}
|
||||
|
||||
public IArea(IPoint pos, IPoint size) {
|
||||
this(pos.x(), pos.y(), size.x(), size.y());
|
||||
}
|
||||
|
||||
public IArea(float xywh) {
|
||||
this(xywh, xywh, xywh, xywh);
|
||||
}
|
||||
|
||||
public IArea(float xy, float wh) {
|
||||
this(xy, xy, wh, wh);
|
||||
}
|
||||
|
||||
public IArea(float x, float y, float wh) {
|
||||
this(x, y, wh, wh);
|
||||
}
|
||||
|
||||
public IArea(float x, float y, float w, float h) {
|
||||
setPosition(new IPoint(x, y));
|
||||
setSize(new IPoint(w, h));
|
||||
}
|
||||
|
||||
public IPoint pos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public IPoint getPosition() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void setPosition(IPoint position) {
|
||||
pos = position.copy();
|
||||
}
|
||||
|
||||
public IPoint size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public IPoint getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(IPoint size) {
|
||||
this.size = size.copy();
|
||||
}
|
||||
|
||||
public boolean contains(IPoint position) {
|
||||
return position.x() >= pos().x()
|
||||
&& position.y() >= pos.y()
|
||||
&& position.x() <= pos().x() + size().x()
|
||||
&& position.y() <= pos().y() + size().y();
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return pos().x();
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return pos().y();
|
||||
}
|
||||
|
||||
public float w() {
|
||||
return size().x();
|
||||
}
|
||||
|
||||
public float h() {
|
||||
return size().y();
|
||||
}
|
||||
|
||||
public float x(float n) {
|
||||
return pos.x(n);
|
||||
}
|
||||
|
||||
public float y(float n) {
|
||||
return pos.y(n);
|
||||
}
|
||||
|
||||
public float w(float n) {
|
||||
return size.x(n);
|
||||
}
|
||||
|
||||
public float h(float n) {
|
||||
return size.y(n);
|
||||
}
|
||||
|
||||
public IArea inset(IBorder border) {
|
||||
return new IArea(
|
||||
x() + border.l(),
|
||||
y() + border.t(),
|
||||
w() - border.l() - border.r(),
|
||||
h() - border.t() - border.b()
|
||||
);
|
||||
}
|
||||
|
||||
public IArea outset(int outset) {
|
||||
return outset(new IBorder(outset));
|
||||
}
|
||||
|
||||
public IArea outset(IBorder border) {
|
||||
return new IArea(
|
||||
x() - border.l(),
|
||||
y() - border.t(),
|
||||
w() + border.l() + border.r(),
|
||||
h() + border.t() + border.b()
|
||||
);
|
||||
}
|
||||
|
||||
public IArea inset(int inset) {
|
||||
return inset(new IBorder(inset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return w() + "x" + h() + "@" + x() + "," + y();
|
||||
}
|
||||
|
||||
public IArea shift(float dx, float f) {
|
||||
return new IArea(x() + dx, y() + f, w(), h());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package binnie.core.craftgui.geometry;
|
||||
|
||||
public class IBorder {
|
||||
public static IBorder ZERO = new IBorder(0.0f);
|
||||
|
||||
protected float t;
|
||||
protected float b;
|
||||
protected float l;
|
||||
protected float r;
|
||||
|
||||
public IBorder(float pad) {
|
||||
this(pad, pad, pad, pad);
|
||||
}
|
||||
|
||||
public IBorder(float tb, float rl) {
|
||||
this(tb, rl, tb, rl);
|
||||
}
|
||||
|
||||
public IBorder(float t, float rl, float b) {
|
||||
this(t, rl, b, rl);
|
||||
}
|
||||
|
||||
public IBorder(float t, float r, float b, float l) {
|
||||
this.t = t;
|
||||
this.b = b;
|
||||
this.l = l;
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public IBorder(Position edge, float n) {
|
||||
this((edge == Position.Top) ? n : 0.0f, (edge == Position.Right) ? n : 0.0f, (edge == Position.Bottom) ? n : 0.0f, (edge == Position.Left) ? n : 0.0f);
|
||||
}
|
||||
|
||||
public IBorder(IBorder padding) {
|
||||
this(padding.t(), padding.r(), padding.b(), padding.l());
|
||||
}
|
||||
|
||||
public float t() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public float b() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public float l() {
|
||||
return l;
|
||||
}
|
||||
|
||||
public float r() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public float t(float n) {
|
||||
return t = n;
|
||||
}
|
||||
|
||||
public float b(float n) {
|
||||
return b = n;
|
||||
}
|
||||
|
||||
public float l(float n) {
|
||||
return l = n;
|
||||
}
|
||||
|
||||
public float r(float n) {
|
||||
return r = n;
|
||||
}
|
||||
|
||||
public boolean isNonZero() {
|
||||
return t != 0.0f || r != 0.0f || l != 0.0f || b != 0.0f;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IPoint tl() {
|
||||
return new IPoint(l(), t());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IPoint tr() {
|
||||
return new IPoint(r(), t());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IPoint bl() {
|
||||
return new IPoint(l(), b());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public IPoint br() {
|
||||
return new IPoint(r(), b());
|
||||
}
|
||||
|
||||
public IBorder add(IBorder o) {
|
||||
return new IBorder(t() + o.t(), r() + o.r(), b() + o.b(), l() + o.l());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return t() + "-" + r() + "-" + b() + "-" + l();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package binnie.core.craftgui.geometry;
|
||||
|
||||
public class IPoint {
|
||||
public static IPoint ZERO = new IPoint(0.0f, 0.0f);
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
|
||||
public IPoint(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public IPoint(IPoint o) {
|
||||
x = o.x();
|
||||
y = o.y();
|
||||
}
|
||||
|
||||
public static IPoint add(IPoint a, IPoint b) {
|
||||
return new IPoint(a.x() + b.x(), a.y() + b.y());
|
||||
}
|
||||
|
||||
public static IPoint sub(IPoint a, IPoint b) {
|
||||
return new IPoint(a.x() - b.x(), a.y() - b.y());
|
||||
}
|
||||
|
||||
public IPoint sub(IPoint a) {
|
||||
return sub(this, a);
|
||||
}
|
||||
|
||||
public IPoint add(IPoint other) {
|
||||
return add(this, other);
|
||||
}
|
||||
|
||||
public IPoint add(float dx, float dy) {
|
||||
return add(this, new IPoint(dx, dy));
|
||||
}
|
||||
|
||||
public IPoint copy() {
|
||||
return new IPoint(this);
|
||||
}
|
||||
|
||||
public float x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void xy(float x, float y) {
|
||||
x(x);
|
||||
y(y);
|
||||
}
|
||||
|
||||
public float x(float x) {
|
||||
return this.x = x;
|
||||
}
|
||||
|
||||
public float y(float y) {
|
||||
return this.y = y;
|
||||
}
|
||||
|
||||
public boolean equals(IPoint other) {
|
||||
return x() == other.x() && y() == other.y();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package binnie.core.craftgui.geometry;
|
||||
|
||||
public enum Position {
|
||||
Top(0, -1),
|
||||
Bottom(0, 1),
|
||||
Left(-1, 0),
|
||||
Right(1, 0);
|
||||
|
||||
protected int x;
|
||||
protected int y;
|
||||
|
||||
Position(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public Position opposite() {
|
||||
switch (this) {
|
||||
case Bottom:
|
||||
return Position.Top;
|
||||
|
||||
case Left:
|
||||
return Position.Right;
|
||||
|
||||
case Right:
|
||||
return Position.Left;
|
||||
|
||||
case Top:
|
||||
return Position.Bottom;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -1,11 +1,6 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
package binnie.core.craftgui.geometry;
|
||||
|
||||
package binnie.craftgui.core.geometry;
|
||||
|
||||
public enum TextJustification
|
||||
{
|
||||
public enum TextJustification {
|
||||
TopLeft(0.0f, 0.0f),
|
||||
TopCenter(0.5f, 0.0f),
|
||||
TopRight(1.0f, 0.0f),
|
||||
@@ -16,19 +11,19 @@ public enum TextJustification
|
||||
BottomCenter(0.5f, 1.0f),
|
||||
BottomRight(1.0f, 1.0f);
|
||||
|
||||
float xOffset;
|
||||
float yOffset;
|
||||
protected float xOffset;
|
||||
protected float yOffset;
|
||||
|
||||
private TextJustification(final float xOffset, final float yOffset) {
|
||||
TextJustification(float xOffset, float yOffset) {
|
||||
this.xOffset = xOffset;
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public float getXOffset() {
|
||||
return this.xOffset;
|
||||
return xOffset;
|
||||
}
|
||||
|
||||
public float getYOffset() {
|
||||
return this.yOffset;
|
||||
return yOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,482 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.craftgui.minecraft.control.ControlSlot;
|
||||
import binnie.core.craftgui.minecraft.control.EnumHighlighting;
|
||||
import binnie.core.machines.IMachine;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.network.INetwork;
|
||||
import binnie.core.machines.power.ErrorState;
|
||||
import binnie.core.machines.power.IErrorStateSource;
|
||||
import binnie.core.machines.power.IPoweredMachine;
|
||||
import binnie.core.machines.power.IProcess;
|
||||
import binnie.core.machines.power.ITankMachine;
|
||||
import binnie.core.machines.power.PowerInfo;
|
||||
import binnie.core.machines.power.ProcessInfo;
|
||||
import binnie.core.machines.power.TankInfo;
|
||||
import binnie.core.machines.transfer.TransferRequest;
|
||||
import binnie.core.network.packet.MessageContainerUpdate;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ContainerCraftGUI extends Container
|
||||
{
|
||||
private Window window;
|
||||
private Map<String, NBTTagCompound> syncedNBT;
|
||||
private Map<String, NBTTagCompound> sentNBT;
|
||||
private Map<Integer, TankInfo> syncedTanks;
|
||||
private PowerInfo syncedPower;
|
||||
private ProcessInfo syncedProcess;
|
||||
private int errorType;
|
||||
private ErrorState error;
|
||||
private int mousedOverSlotNumber;
|
||||
|
||||
public ContainerCraftGUI(Window window) {
|
||||
syncedNBT = new HashMap<String, NBTTagCompound>();
|
||||
sentNBT = new HashMap<String, NBTTagCompound>();
|
||||
syncedTanks = new HashMap<Integer, TankInfo>();
|
||||
syncedPower = new PowerInfo();
|
||||
syncedProcess = new ProcessInfo();
|
||||
errorType = 0;
|
||||
error = null;
|
||||
mousedOverSlotNumber = -1;
|
||||
this.window = window;
|
||||
IMachine machine = Machine.getMachine(window.getInventory());
|
||||
if (getSide() == Side.SERVER) {
|
||||
inventoryItemStacks = new ListMap();
|
||||
inventorySlots = new ListMap();
|
||||
if (machine != null) {
|
||||
GameProfile user = machine.getOwner();
|
||||
if (user != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("username", user.getName());
|
||||
sendNBTToClient("username", nbt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Slot addSlotToContainer(Slot slot) {
|
||||
return super.addSlotToContainer(slot);
|
||||
}
|
||||
|
||||
private Side getSide() {
|
||||
return window.isServer() ? Side.SERVER : Side.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slot getSlot(int par1) {
|
||||
if (par1 < 0 || par1 >= inventorySlots.size()) {
|
||||
return null;
|
||||
}
|
||||
return (Slot) inventorySlots.get(par1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStackInSlot(int par1, ItemStack par2ItemStack) {
|
||||
if (getSlot(par1) != null) {
|
||||
getSlot(par1).putStack(par2ItemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack) {
|
||||
for (int i = 0; i < par1ArrayOfItemStack.length; ++i) {
|
||||
if (getSlot(i) != null) {
|
||||
getSlot(i).putStack(par1ArrayOfItemStack[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
|
||||
super.onContainerClosed(par1EntityPlayer);
|
||||
WindowInventory inventory = window.getWindowInventory();
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
if (inventory.dispenseOnClose(i)) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack != null) {
|
||||
stack = new TransferRequest(stack, par1EntityPlayer.inventory).transfer(true);
|
||||
if (stack != null) {
|
||||
par1EntityPlayer.dropPlayerItemWithRandomChoice(stack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotNum, int mouseButton, int modifier, EntityPlayer player) {
|
||||
Slot slot = getSlot(slotNum);
|
||||
if (slot instanceof CustomSlot && ((CustomSlot) slot).handleClick()) {
|
||||
((CustomSlot) slot).onSlotClick(this, mouseButton, modifier, player);
|
||||
return player.inventory.getItemStack();
|
||||
}
|
||||
ItemStack stack = super.slotClick(slotNum, mouseButton, modifier, player);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public void sendNBTToClient(String key, NBTTagCompound nbt) {
|
||||
syncedNBT.put(key, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer var1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotID) {
|
||||
return shiftClick(player, slotID);
|
||||
}
|
||||
|
||||
private ItemStack shiftClick(EntityPlayer player, int slotnumber) {
|
||||
TransferRequest request = getShiftClickRequest(player, slotnumber);
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack itemstack = request.transfer(true);
|
||||
Slot shiftClickedSlot = (Slot) inventorySlots.get(slotnumber);
|
||||
shiftClickedSlot.putStack(itemstack);
|
||||
shiftClickedSlot.onSlotChanged();
|
||||
return null;
|
||||
}
|
||||
|
||||
private TransferRequest getShiftClickRequest(EntityPlayer player, int slotnumber) {
|
||||
if (slotnumber < 0) {
|
||||
return null;
|
||||
}
|
||||
Slot shiftClickedSlot = (Slot) inventorySlots.get(slotnumber);
|
||||
ItemStack itemstack = null;
|
||||
if (shiftClickedSlot.getHasStack()) {
|
||||
itemstack = shiftClickedSlot.getStack().copy();
|
||||
}
|
||||
IInventory playerInventory = player.inventory;
|
||||
IInventory containerInventory = window.getInventory();
|
||||
IInventory windowInventory = window.getWindowInventory();
|
||||
IInventory fromPlayer = (containerInventory == null) ? windowInventory : containerInventory;
|
||||
int[] target = new int[36];
|
||||
for (int i = 0; i < 36; ++i) {
|
||||
target[i] = i;
|
||||
}
|
||||
TransferRequest request;
|
||||
if (shiftClickedSlot.inventory == playerInventory) {
|
||||
request = new TransferRequest(itemstack, fromPlayer).setOrigin(shiftClickedSlot.inventory);
|
||||
}
|
||||
else {
|
||||
request = new TransferRequest(itemstack, playerInventory).setOrigin(shiftClickedSlot.inventory).setTargetSlots(target);
|
||||
}
|
||||
if (window instanceof IWindowAffectsShiftClick) {
|
||||
((IWindowAffectsShiftClick) window).alterRequest(request);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public ItemStack tankClick(EntityPlayer player, int slotID) {
|
||||
if (player.inventory.getItemStack() == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack heldItem = player.inventory.getItemStack().copy();
|
||||
heldItem = new TransferRequest(heldItem, window.getInventory()).setOrigin(player.inventory).setTargetSlots(new int[0]).setTargetTanks(new int[] { slotID }).transfer(true);
|
||||
player.inventory.setItemStack(heldItem);
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
((EntityPlayerMP) player).updateHeldItem();
|
||||
}
|
||||
return heldItem;
|
||||
}
|
||||
|
||||
public boolean handleNBT(Side side, EntityPlayer player, String name, NBTTagCompound action) {
|
||||
if (side == Side.SERVER) {
|
||||
if (name.equals("tank-click")) {
|
||||
tankClick(player, action.getByte("id"));
|
||||
}
|
||||
if (name.equals("slot-reg")) {
|
||||
int type = action.getByte("t");
|
||||
int index = action.getShort("i");
|
||||
int slotNumber = action.getShort("n");
|
||||
getOrCreateSlot(InventoryType.values()[type % 4], index, slotNumber);
|
||||
}
|
||||
}
|
||||
if (name.contains("tank-update")) {
|
||||
onTankUpdate(action);
|
||||
}
|
||||
else if (name.equals("power-update")) {
|
||||
onPowerUpdate(action);
|
||||
}
|
||||
else if (name.equals("process-update")) {
|
||||
onProcessUpdate(action);
|
||||
}
|
||||
else if (name.equals("error-update")) {
|
||||
onErrorUpdate(action);
|
||||
}
|
||||
else if (name.equals("mouse-over-slot")) {
|
||||
onMouseOverSlot(player, action);
|
||||
}
|
||||
else if (name.equals("shift-click-info")) {
|
||||
onRecieveShiftClickHighlights(player, action);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
ITankMachine tanks = Machine.getInterface(ITankMachine.class, window.getInventory());
|
||||
IPoweredMachine powered = Machine.getInterface(IPoweredMachine.class, window.getInventory());
|
||||
IErrorStateSource error = Machine.getInterface(IErrorStateSource.class, window.getInventory());
|
||||
IProcess process = Machine.getInterface(IProcess.class, window.getInventory());
|
||||
if (tanks != null && window.isServer()) {
|
||||
for (int i = 0; i < tanks.getTankInfos().length; ++i) {
|
||||
TankInfo tank = tanks.getTankInfos()[i];
|
||||
if (!getTankInfo(i).equals(tank)) {
|
||||
syncedNBT.put("tank-update-" + i, createTankNBT(i, tank));
|
||||
syncedTanks.put(i, tank);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (powered != null && window.isServer()) {
|
||||
syncedNBT.put("power-update", createPowerNBT(powered.getPowerInfo()));
|
||||
}
|
||||
if (process != null && window.isServer()) {
|
||||
syncedNBT.put("process-update", createProcessNBT(process.getInfo()));
|
||||
}
|
||||
if (error != null && window.isServer()) {
|
||||
syncedNBT.put("error-update", createErrorNBT(error));
|
||||
}
|
||||
INetwork.SendGuiNBT machineSync = Machine.getInterface(INetwork.SendGuiNBT.class, window.getInventory());
|
||||
if (machineSync != null) {
|
||||
machineSync.sendGuiNBT(syncedNBT);
|
||||
}
|
||||
Map<String, NBTTagCompound> sentThisTime = new HashMap<String, NBTTagCompound>();
|
||||
for (Map.Entry<String, NBTTagCompound> nbt : syncedNBT.entrySet()) {
|
||||
nbt.getValue().setString("type", nbt.getKey());
|
||||
boolean shouldSend = true;
|
||||
NBTTagCompound lastSent = sentNBT.get(nbt.getKey());
|
||||
if (lastSent != null) {
|
||||
shouldSend = !lastSent.equals(nbt.getValue());
|
||||
}
|
||||
if (shouldSend) {
|
||||
for (int j = 0; j < crafters.size(); ++j) {
|
||||
if (crafters.get(j) instanceof EntityPlayerMP) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) crafters.get(j);
|
||||
BinnieCore.proxy.sendToPlayer(new MessageContainerUpdate(nbt.getValue()), player);
|
||||
}
|
||||
}
|
||||
sentThisTime.put(nbt.getKey(), nbt.getValue());
|
||||
}
|
||||
}
|
||||
sentNBT.putAll(sentThisTime);
|
||||
syncedNBT.clear();
|
||||
}
|
||||
|
||||
private NBTTagCompound createErrorNBT(IErrorStateSource error) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
ErrorState state = null;
|
||||
if (error.canWork() != null) {
|
||||
nbt.setByte("type", (byte) 0);
|
||||
state = error.canWork();
|
||||
}
|
||||
else if (error.canProgress() != null) {
|
||||
nbt.setByte("type", (byte) 1);
|
||||
state = error.canProgress();
|
||||
}
|
||||
if (state != null) {
|
||||
state.writeToNBT(nbt);
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public NBTTagCompound createPowerNBT(PowerInfo powerInfo) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
powerInfo.writeToNBT(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public NBTTagCompound createProcessNBT(ProcessInfo powerInfo) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
powerInfo.writeToNBT(nbt);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public NBTTagCompound createTankNBT(int tank, TankInfo tankInfo) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
tankInfo.writeToNBT(nbt);
|
||||
nbt.setByte("tank", (byte) tank);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void onTankUpdate(NBTTagCompound nbt) {
|
||||
int tankID = nbt.getByte("tank");
|
||||
TankInfo tank = new TankInfo();
|
||||
tank.readFromNBT(nbt);
|
||||
syncedTanks.put(tankID, tank);
|
||||
}
|
||||
|
||||
public void onProcessUpdate(NBTTagCompound nbt) {
|
||||
(syncedProcess = new ProcessInfo()).readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public void onPowerUpdate(NBTTagCompound nbt) {
|
||||
(syncedPower = new PowerInfo()).readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public PowerInfo getPowerInfo() {
|
||||
return syncedPower;
|
||||
}
|
||||
|
||||
public ProcessInfo getProcessInfo() {
|
||||
return syncedProcess;
|
||||
}
|
||||
|
||||
public TankInfo getTankInfo(int tank) {
|
||||
return syncedTanks.containsKey(tank) ? syncedTanks.get(tank) : new TankInfo();
|
||||
}
|
||||
|
||||
public void onErrorUpdate(NBTTagCompound nbt) {
|
||||
errorType = nbt.getByte("type");
|
||||
if (nbt.hasKey("name")) {
|
||||
(error = new ErrorState("", "")).readFromNBT(nbt);
|
||||
}
|
||||
else {
|
||||
error = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ErrorState getErrorState() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public int getErrorType() {
|
||||
return errorType;
|
||||
}
|
||||
|
||||
public CustomSlot[] getCustomSlots() {
|
||||
List<CustomSlot> slots = new ArrayList<CustomSlot>();
|
||||
for (Object object : inventorySlots) {
|
||||
if (object instanceof CustomSlot) {
|
||||
slots.add((CustomSlot) object);
|
||||
}
|
||||
}
|
||||
return slots.toArray(new CustomSlot[0]);
|
||||
}
|
||||
|
||||
public void setMouseOverSlot(Slot slot) {
|
||||
if (slot.slotNumber != mousedOverSlotNumber) {
|
||||
mousedOverSlotNumber = slot.slotNumber;
|
||||
ControlSlot.highlighting.get(EnumHighlighting.ShiftClick).clear();
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setShort("slot", (short) slot.slotNumber);
|
||||
window.sendClientAction("mouse-over-slot", nbt);
|
||||
}
|
||||
}
|
||||
|
||||
private void onMouseOverSlot(EntityPlayer player, NBTTagCompound data) {
|
||||
int slotnumber = data.getShort("slot");
|
||||
TransferRequest request = getShiftClickRequest(player, slotnumber);
|
||||
if (request == null) {
|
||||
return;
|
||||
}
|
||||
request.transfer(false);
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
List<Integer> slots = new ArrayList<Integer>();
|
||||
for (TransferRequest.TransferSlot tslot : request.getInsertedSlots()) {
|
||||
Slot slot = getSlot(tslot.inventory, tslot.id);
|
||||
if (slot != null) {
|
||||
slots.add(slot.slotNumber);
|
||||
}
|
||||
}
|
||||
int[] array = new int[slots.size()];
|
||||
for (int i = 0; i < slots.size(); ++i) {
|
||||
array[i] = slots.get(i);
|
||||
}
|
||||
nbt.setIntArray("slots", array);
|
||||
nbt.setShort("origin", (short) slotnumber);
|
||||
syncedNBT.put("shift-click-info", nbt);
|
||||
}
|
||||
|
||||
private void onRecieveShiftClickHighlights(EntityPlayer player, NBTTagCompound data) {
|
||||
ControlSlot.highlighting.get(EnumHighlighting.ShiftClick).clear();
|
||||
for (int slotnumber : data.getIntArray("slots")) {
|
||||
ControlSlot.highlighting.get(EnumHighlighting.ShiftClick).add(slotnumber);
|
||||
}
|
||||
}
|
||||
|
||||
private CustomSlot getSlot(IInventory inventory, int id) {
|
||||
for (Object o : inventorySlots) {
|
||||
CustomSlot slot = (CustomSlot) o;
|
||||
if (slot.inventory == inventory && slot.getSlotIndex() == id) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void recieveNBT(Side side, EntityPlayer player, NBTTagCompound action) {
|
||||
String name = action.getString("type");
|
||||
if (handleNBT(side, player, name, action)) {
|
||||
return;
|
||||
}
|
||||
window.recieveGuiNBT(getSide(), player, name, action);
|
||||
INetwork.RecieveGuiNBT machine = Machine.getInterface(INetwork.RecieveGuiNBT.class, window.getInventory());
|
||||
if (machine != null) {
|
||||
machine.recieveGuiNBT(getSide(), player, name, action);
|
||||
}
|
||||
}
|
||||
|
||||
public Slot getOrCreateSlot(InventoryType type, int index) {
|
||||
IInventory inventory = getInventory(type);
|
||||
Slot slot = getSlot(inventory, index);
|
||||
if (slot == null) {
|
||||
slot = new CustomSlot(inventory, index);
|
||||
addSlotToContainer(slot);
|
||||
}
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setByte("t", (byte) type.ordinal());
|
||||
nbt.setShort("i", (short) index);
|
||||
nbt.setShort("n", (short) slot.slotNumber);
|
||||
window.sendClientAction("slot-reg", nbt);
|
||||
return slot;
|
||||
}
|
||||
|
||||
protected IInventory getInventory(InventoryType type) {
|
||||
if (type == InventoryType.Machine) {
|
||||
return window.getInventory();
|
||||
}
|
||||
if (type == InventoryType.Player) {
|
||||
return window.getPlayer().inventory;
|
||||
}
|
||||
if (type == InventoryType.Window) {
|
||||
return window.getWindowInventory();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Slot getOrCreateSlot(InventoryType type, int index, int slotNumber) {
|
||||
IInventory inventory = getInventory(type);
|
||||
if (inventorySlots.get(slotNumber) != null) {
|
||||
return null;
|
||||
}
|
||||
Slot slot = new CustomSlot(inventory, index);
|
||||
slot.slotNumber = slotNumber;
|
||||
inventorySlots.add(slotNumber, slot);
|
||||
inventoryItemStacks.add(slotNumber, null);
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -2,49 +2,49 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.minecraft;
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.inventory.IInventorySlots;
|
||||
import binnie.core.machines.inventory.InventorySlot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class CustomSlot extends Slot
|
||||
{
|
||||
@Override
|
||||
public boolean isItemValid(final ItemStack par1ItemStack) {
|
||||
return this.inventory.isItemValidForSlot(this.getSlotIndex(), par1ItemStack);
|
||||
public boolean isItemValid(ItemStack par1ItemStack) {
|
||||
return inventory.isItemValidForSlot(getSlotIndex(), par1ItemStack);
|
||||
}
|
||||
|
||||
public CustomSlot(final IInventory inventory, final int index) {
|
||||
public CustomSlot(IInventory inventory, int index) {
|
||||
super(inventory, index, 0, 0);
|
||||
}
|
||||
|
||||
public InventorySlot getInventorySlot() {
|
||||
final IInventorySlots slots = Machine.getInterface(IInventorySlots.class, this.inventory);
|
||||
IInventorySlots slots = Machine.getInterface(IInventorySlots.class, inventory);
|
||||
if (slots != null) {
|
||||
return slots.getSlot(this.getSlotIndex());
|
||||
return slots.getSlot(getSlotIndex());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean handleClick() {
|
||||
final InventorySlot slot = this.getInventorySlot();
|
||||
InventorySlot slot = getInventorySlot();
|
||||
return slot != null && slot.isRecipe();
|
||||
}
|
||||
|
||||
public void onSlotClick(final ContainerCraftGUI container, final int mouseButton, final int modifier, final EntityPlayer player) {
|
||||
public void onSlotClick(ContainerCraftGUI container, int mouseButton, int modifier, EntityPlayer player) {
|
||||
ItemStack stack = player.inventory.getItemStack();
|
||||
if (stack == null || mouseButton == 2) {
|
||||
this.putStack((ItemStack) null);
|
||||
putStack(null);
|
||||
}
|
||||
else {
|
||||
stack = stack.copy();
|
||||
stack.stackSize = 1;
|
||||
this.putStack(stack);
|
||||
putStack(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
import binnie.core.craftgui.WidgetAttribute;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.controls.core.Control;
|
||||
import binnie.core.craftgui.events.EventHandler;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import binnie.core.craftgui.resource.minecraft.CraftGUITexture;
|
||||
|
||||
public abstract class Dialog extends Control
|
||||
{
|
||||
public Dialog(IWidget parent, float w, float h) {
|
||||
super(parent, (parent.w() - w) / 2.0f, (parent.h() - h) / 2.0f, w, h);
|
||||
addAttribute(WidgetAttribute.MouseOver);
|
||||
addAttribute(WidgetAttribute.AlwaysOnTop);
|
||||
addAttribute(WidgetAttribute.BlockTooltip);
|
||||
initialise();
|
||||
addEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(EventMouse.Down event) {
|
||||
if (!getArea().contains(getRelativeMousePosition())) {
|
||||
onClose();
|
||||
getParent().deleteChild(Dialog.this);
|
||||
}
|
||||
}
|
||||
}.setOrigin(EventHandler.Origin.Any, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void initialise();
|
||||
|
||||
public abstract void onClose();
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
CraftGUI.Render.gradientRect(getArea().outset(400), -1442840576, -1442840576);
|
||||
CraftGUI.Render.texture(CraftGUITexture.Window, getArea());
|
||||
CraftGUI.Render.texture(CraftGUITexture.TabOutline, getArea().inset(4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOverWidget(IPoint relativeMouse) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -2,7 +2,7 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.minecraft;
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
public enum EnumColor
|
||||
{
|
||||
@@ -27,22 +27,22 @@ public enum EnumColor
|
||||
String name;
|
||||
char code;
|
||||
|
||||
private EnumColor(final String name, final int colour, final char code) {
|
||||
EnumColor(String name, int colour, char code) {
|
||||
this.name = name;
|
||||
this.colour = colour;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getColour() {
|
||||
return this.colour;
|
||||
return colour;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return "§" + this.code;
|
||||
return "§" + code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -2,12 +2,12 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.minecraft;
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
import net.minecraft.util.IIcon;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.Binnie;
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.resource.BinnieIcon;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public enum GUIIcon
|
||||
{
|
||||
@@ -27,15 +27,15 @@ public enum GUIIcon
|
||||
String path;
|
||||
BinnieIcon icon;
|
||||
|
||||
private GUIIcon(final String path) {
|
||||
GUIIcon(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public void register() {
|
||||
this.icon = Binnie.Resource.getItemIcon(BinnieCore.instance, "gui/" + this.path);
|
||||
icon = Binnie.Resource.getItemIcon(BinnieCore.instance, "gui/" + path);
|
||||
}
|
||||
|
||||
public IIcon getIcon() {
|
||||
return this.icon.getIcon();
|
||||
return icon.getIcon();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,488 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
import binnie.core.BinnieCore;
|
||||
import binnie.core.craftgui.CraftGUI;
|
||||
import binnie.core.craftgui.IWidget;
|
||||
import binnie.core.craftgui.Tooltip;
|
||||
import binnie.core.craftgui.events.EventKey;
|
||||
import binnie.core.craftgui.events.EventMouse;
|
||||
import binnie.core.craftgui.geometry.IArea;
|
||||
import binnie.core.craftgui.geometry.IBorder;
|
||||
import binnie.core.craftgui.geometry.IPoint;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiCraftGUI extends GuiContainer
|
||||
{
|
||||
IPoint mousePos;
|
||||
private Window window;
|
||||
private ItemStack draggedItem;
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
window.updateClient();
|
||||
}
|
||||
|
||||
public Minecraft getMinecraft() {
|
||||
return mc;
|
||||
}
|
||||
|
||||
public GuiCraftGUI(Window window) {
|
||||
super(window.getContainer());
|
||||
mousePos = new IPoint(0.0f, 0.0f);
|
||||
this.window = window;
|
||||
resize(window.getSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
mc.thePlayer.openContainer = inventorySlots;
|
||||
guiLeft = (width - xSize) / 2;
|
||||
guiTop = (height - ySize) / 2;
|
||||
window.setSize(new IPoint(xSize, ySize));
|
||||
window.setPosition(new IPoint(guiLeft, guiTop));
|
||||
window.initGui();
|
||||
}
|
||||
|
||||
public ItemStack getDraggedItem() {
|
||||
return draggedItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float par3) {
|
||||
window.setMousePosition(mouseX - (int) window.getPosition().x(), mouseY - (int) window.getPosition().y());
|
||||
drawDefaultBackground();
|
||||
|
||||
GL11.glDisable(32826);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(2896);
|
||||
GL11.glDisable(2929);
|
||||
zLevel = 10.0f;
|
||||
GuiScreen.itemRender.zLevel = zLevel;
|
||||
|
||||
window.render();
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(32826);
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
|
||||
InventoryPlayer playerInventory = mc.thePlayer.inventory;
|
||||
draggedItem = playerInventory.getItemStack();
|
||||
if (draggedItem != null) {
|
||||
renderItem(new IPoint(mouseX - 8, mouseY - 8), draggedItem, 200, false);
|
||||
renderItem(new IPoint(mouseX - 8, mouseY - 8), draggedItem, 200, false);
|
||||
}
|
||||
GL11.glDisable(32826);
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(2896);
|
||||
GL11.glDisable(2929);
|
||||
MinecraftTooltip tooltip = new MinecraftTooltip();
|
||||
if (isHelpMode()) {
|
||||
tooltip.setType(Tooltip.Type.Help);
|
||||
window.getHelpTooltip(tooltip);
|
||||
}
|
||||
else {
|
||||
tooltip.setType(Tooltip.Type.Standard);
|
||||
window.getTooltip(tooltip);
|
||||
}
|
||||
if (tooltip.exists()) {
|
||||
renderTooltip(new IPoint(mouseX, mouseY), tooltip);
|
||||
}
|
||||
zLevel = 0.0f;
|
||||
GL11.glEnable(2896);
|
||||
GL11.glEnable(2929);
|
||||
}
|
||||
|
||||
public void renderTooltip(IPoint mousePosition, MinecraftTooltip tooltip) {
|
||||
int mouseX = (int) mousePosition.x();
|
||||
int mouseY = (int) mousePosition.y();
|
||||
FontRenderer font = getFontRenderer();
|
||||
GL11.glDisable(32826);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(2896);
|
||||
GL11.glDisable(2929);
|
||||
int k = 0;
|
||||
List<String> strings = new ArrayList<String>();
|
||||
for (String string : tooltip.getList()) {
|
||||
if (string != null) {
|
||||
if (!string.contains("~~~")) {
|
||||
strings.addAll(font.listFormattedStringToWidth(string, tooltip.maxWidth));
|
||||
}
|
||||
else {
|
||||
strings.add(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String s : strings) {
|
||||
int l = font.getStringWidth(s);
|
||||
if (s.contains("~~~")) {
|
||||
l = 12 + font.getStringWidth(s.replaceAll("~~~(.*?)~~~", ""));
|
||||
}
|
||||
if (l > k) {
|
||||
k = l;
|
||||
}
|
||||
}
|
||||
int i1 = mouseX + 12;
|
||||
int j1 = mouseY - 12;
|
||||
int k2 = 8;
|
||||
if (strings.size() > 1) {
|
||||
k2 += 2 + (strings.size() - 1) * 10;
|
||||
}
|
||||
if (i1 + k > width) {
|
||||
i1 -= 28 + k;
|
||||
}
|
||||
if (j1 + k2 + 6 > height) {
|
||||
j1 = height - k2 - 6;
|
||||
}
|
||||
zLevel = 300.0f;
|
||||
GuiScreen.itemRender.zLevel = 300.0f;
|
||||
int l2 = -267386864;
|
||||
int j2;
|
||||
int i2 = j2 = 1342177280 + MinecraftTooltip.getOutline(tooltip.getType());
|
||||
drawGradientRect(i1 - 3, j1 - 4, i1 + k + 3, j1 - 3, l2, l2);
|
||||
drawGradientRect(i1 - 3, j1 + k2 + 3, i1 + k + 3, j1 + k2 + 4, l2, l2);
|
||||
drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 + k2 + 3, l2, l2);
|
||||
drawGradientRect(i1 - 4, j1 - 3, i1 - 3, j1 + k2 + 3, l2, l2);
|
||||
drawGradientRect(i1 + k + 3, j1 - 3, i1 + k + 4, j1 + k2 + 3, l2, l2);
|
||||
drawGradientRect(i1 - 3, j1 - 3 + 1, i1 - 3 + 1, j1 + k2 + 3 - 1, i2, j2);
|
||||
drawGradientRect(i1 + k + 2, j1 - 3 + 1, i1 + k + 3, j1 + k2 + 3 - 1, i2, j2);
|
||||
drawGradientRect(i1 - 3, j1 - 3, i1 + k + 3, j1 - 3 + 1, i2, i2);
|
||||
drawGradientRect(i1 - 3, j1 + k2 + 2, i1 + k + 3, j1 + k2 + 3, j2, j2);
|
||||
for (int k3 = 0; k3 < strings.size(); ++k3) {
|
||||
String s2 = strings.get(k3);
|
||||
if (k3 == 0) {
|
||||
s2 = MinecraftTooltip.getTitle(tooltip.getType()) + s2;
|
||||
}
|
||||
else {
|
||||
s2 = MinecraftTooltip.getBody(tooltip.getType()) + s2;
|
||||
}
|
||||
if (s2.contains("~~~")) {
|
||||
String split = s2.split("~~~")[1];
|
||||
try {
|
||||
NBTTagCompound nbt = (NBTTagCompound) JsonToNBT.func_150315_a(split);
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(i1, j1 - 1.5f, 0.0f);
|
||||
GL11.glScalef(0.6f, 0.6f, 1.0f);
|
||||
renderItem(new IPoint(0.0f, 0.0f), stack, false);
|
||||
GL11.glPopMatrix();
|
||||
} catch (NBTException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
s2 = " " + s2.replaceAll("~~~(.*?)~~~", "");
|
||||
}
|
||||
font.drawStringWithShadow(s2, i1, j1, -1);
|
||||
if (k3 == 0) {
|
||||
j1 += 2;
|
||||
}
|
||||
j1 += 10;
|
||||
}
|
||||
zLevel = 0.0f;
|
||||
GuiScreen.itemRender.zLevel = 0.0f;
|
||||
GL11.glEnable(2896);
|
||||
GL11.glEnable(2929);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(32826);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int x, int y, int button) {
|
||||
IWidget origin = window;
|
||||
if (window.getMousedOverWidget() != null) {
|
||||
origin = window.getMousedOverWidget();
|
||||
}
|
||||
window.callEvent(new EventMouse.Down(origin, x, y, button));
|
||||
}
|
||||
|
||||
public boolean isShiftDown() {
|
||||
return Keyboard.isKeyDown(mc.gameSettings.keyBindSneak.getKeyCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int key) {
|
||||
if (key == 1 || (key == mc.gameSettings.keyBindInventory.getKeyCode() && window.getFocusedWidget() == null)) {
|
||||
mc.thePlayer.closeScreen();
|
||||
}
|
||||
IWidget origin = (window.getFocusedWidget() == null) ? window : window.getFocusedWidget();
|
||||
window.callEvent(new EventKey.Down(origin, c, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int x, int y, int button) {
|
||||
IWidget origin = (window.getMousedOverWidget() == null) ? window : window.getMousedOverWidget();
|
||||
if (button == -1) {
|
||||
float dx = Mouse.getEventDX() * width / (float) mc.displayWidth;
|
||||
float dy = -(Mouse.getEventDY() * height / (float) mc.displayHeight);
|
||||
}
|
||||
else {
|
||||
window.callEvent(new EventMouse.Up(origin, x, y, button));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
int dWheel = Mouse.getDWheel();
|
||||
IWidget origin = (window.getFocusedWidget() == null) ? window : window.getFocusedWidget();
|
||||
if (dWheel != 0) {
|
||||
window.callEvent(new EventMouse.Wheel(window, dWheel));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
window.onClose();
|
||||
}
|
||||
|
||||
public void renderTexturedRect(float x, float y, float u, float v, float w, float h) {
|
||||
drawTexturedModalRect((int) x, (int) y, (int) u, (int) v, (int) w, (int) h);
|
||||
}
|
||||
|
||||
public void renderTexture(IPoint position, IArea textureArea) {
|
||||
drawTexturedModalRect((int) position.x(), (int) position.y(), (int) textureArea.pos().x(), (int) textureArea.pos().y(), (int) textureArea.size().x(), (int) textureArea.size().y());
|
||||
}
|
||||
|
||||
private void renderTexturedRect(IArea area, IPoint uv) {
|
||||
renderTexturedRect(area.pos().x(), area.pos().y(), uv.x(), uv.y(), area.size().x(), area.size().y());
|
||||
}
|
||||
|
||||
public void renderTexturePadded(IArea area, IArea texture, IBorder padding) {
|
||||
int borderLeft = (int) padding.l();
|
||||
int borderRight = (int) padding.r();
|
||||
int borderTop = (int) padding.t();
|
||||
int borderBottom = (int) padding.b();
|
||||
int posX = (int) area.pos().x();
|
||||
int posY = (int) area.pos().y();
|
||||
int width = (int) area.size().x();
|
||||
int height = (int) area.size().y();
|
||||
int textWidth = (int) texture.w();
|
||||
int textHeight = (int) texture.h();
|
||||
int u = (int) texture.x();
|
||||
int v = (int) texture.y();
|
||||
if (borderTop + borderBottom > height) {
|
||||
borderTop = height / 2;
|
||||
borderBottom = height / 2;
|
||||
}
|
||||
if (borderLeft + borderRight > width) {
|
||||
borderLeft = width / 2;
|
||||
borderRight = width / 2;
|
||||
}
|
||||
IPoint origin = area.pos();
|
||||
drawTexturedModalRect(posX, posY, u, v, borderLeft, borderTop);
|
||||
drawTexturedModalRect(posX + width - borderRight, posY, u + textWidth - borderRight, v, borderRight, borderTop);
|
||||
drawTexturedModalRect(posX, posY + height - borderBottom, u, v + textHeight - borderBottom, borderLeft, borderBottom);
|
||||
drawTexturedModalRect(posX + width - borderRight, posY + height - borderBottom, u + textWidth - borderRight, v + textHeight - borderBottom, borderRight, borderBottom);
|
||||
int texturingWidth;
|
||||
for (int currentXPos = borderLeft; currentXPos < width - borderRight; currentXPos += texturingWidth) {
|
||||
int distanceXRemaining = width - borderRight - currentXPos;
|
||||
texturingWidth = textWidth - borderLeft - borderRight;
|
||||
if (texturingWidth > distanceXRemaining) {
|
||||
texturingWidth = distanceXRemaining;
|
||||
}
|
||||
if (texturingWidth <= 0) {
|
||||
break;
|
||||
}
|
||||
drawTexturedModalRect(posX + currentXPos, posY, u + borderLeft, v, texturingWidth, borderTop);
|
||||
drawTexturedModalRect(posX + currentXPos, posY + height - borderBottom, u + borderLeft, v + textHeight - borderBottom, texturingWidth, borderBottom);
|
||||
int texturingHeight;
|
||||
for (int currentYPos = borderTop; currentYPos < height - borderBottom; currentYPos += texturingHeight) {
|
||||
int distanceYRemaining = height - borderBottom - currentYPos;
|
||||
texturingHeight = textHeight - borderTop - borderBottom;
|
||||
if (texturingHeight > distanceYRemaining) {
|
||||
texturingHeight = distanceYRemaining;
|
||||
}
|
||||
if (texturingHeight <= 0) {
|
||||
break;
|
||||
}
|
||||
drawTexturedModalRect(posX + currentXPos, posY + currentYPos, u + borderLeft, v + borderTop, texturingWidth, texturingHeight);
|
||||
}
|
||||
}
|
||||
int texturingHeight2;
|
||||
for (int currentYPos2 = borderTop; currentYPos2 < height - borderBottom; currentYPos2 += texturingHeight2) {
|
||||
int distanceYRemaining2 = height - borderBottom - currentYPos2;
|
||||
texturingHeight2 = textHeight - borderTop - borderBottom;
|
||||
if (texturingHeight2 > distanceYRemaining2) {
|
||||
texturingHeight2 = distanceYRemaining2;
|
||||
}
|
||||
if (texturingHeight2 <= 0) {
|
||||
break;
|
||||
}
|
||||
drawTexturedModalRect(posX, posY + currentYPos2, u, v + borderTop, borderLeft, texturingHeight2);
|
||||
drawTexturedModalRect(posX + width - borderRight, posY + currentYPos2, u + textWidth - borderRight, v + borderTop, borderRight, texturingHeight2);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawGradientArea(float p_73733_1_, float p_73733_2_, float p_73733_3_, float p_73733_4_, int p_73733_5_, int p_73733_6_) {
|
||||
float f = (p_73733_5_ >> 24 & 0xFF) / 255.0f;
|
||||
float f2 = (p_73733_5_ >> 16 & 0xFF) / 255.0f;
|
||||
float f3 = (p_73733_5_ >> 8 & 0xFF) / 255.0f;
|
||||
float f4 = (p_73733_5_ & 0xFF) / 255.0f;
|
||||
float f5 = (p_73733_6_ >> 24 & 0xFF) / 255.0f;
|
||||
float f6 = (p_73733_6_ >> 16 & 0xFF) / 255.0f;
|
||||
float f7 = (p_73733_6_ >> 8 & 0xFF) / 255.0f;
|
||||
float f8 = (p_73733_6_ & 0xFF) / 255.0f;
|
||||
GL11.glDisable(3553);
|
||||
GL11.glEnable(3042);
|
||||
GL11.glDisable(3008);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
GL11.glShadeModel(7425);
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(f2, f3, f4, f);
|
||||
tessellator.addVertex(p_73733_3_, p_73733_2_, zLevel);
|
||||
tessellator.addVertex(p_73733_1_, p_73733_2_, zLevel);
|
||||
tessellator.setColorRGBA_F(f6, f7, f8, f5);
|
||||
tessellator.addVertex(p_73733_1_, p_73733_4_, zLevel);
|
||||
tessellator.addVertex(p_73733_3_, p_73733_4_, zLevel);
|
||||
tessellator.draw();
|
||||
GL11.glShadeModel(7424);
|
||||
GL11.glDisable(3042);
|
||||
GL11.glEnable(3008);
|
||||
GL11.glEnable(3553);
|
||||
}
|
||||
|
||||
public void renderItem(IPoint pos, ItemStack item, boolean rotating) {
|
||||
renderItem(pos, item, (int) zLevel + 3, rotating);
|
||||
}
|
||||
|
||||
private void renderItem(IPoint pos, ItemStack item, int zLevel, boolean rotating) {
|
||||
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
|
||||
GL11.glPushMatrix();
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(32826);
|
||||
GL11.glEnable(2929);
|
||||
FontRenderer font = item.getItem().getFontRenderer(item);
|
||||
if (font == null) {
|
||||
font = getFontRenderer();
|
||||
}
|
||||
if (item != null) {
|
||||
BinnieCore.proxy.getMinecraftInstance();
|
||||
float phase = Minecraft.getSystemTime() / 20.0f;
|
||||
GL11.glPushMatrix();
|
||||
if (rotating) {
|
||||
GL11.glTranslatef(8.0f, 8.0f, 0.0f);
|
||||
GL11.glRotatef(phase, 0.0f, -0.866f, 0.5f);
|
||||
GL11.glTranslatef(-8.0f, -8.0f, -67.1f);
|
||||
}
|
||||
GuiScreen.itemRender.renderItemAndEffectIntoGUI(font, mc.renderEngine, item, (int) pos.x(), (int) pos.y());
|
||||
GL11.glPopMatrix();
|
||||
GuiScreen.itemRender.renderItemOverlayIntoGUI(font, mc.renderEngine, item, (int) pos.x(), (int) pos.y(), null);
|
||||
}
|
||||
GL11.glClear(256);
|
||||
GL11.glEnable(3042);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
CraftGUI.Render.colour(-1);
|
||||
GL11.glEnable(32826);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public void renderIcon(IPoint pos, IIcon icon, ResourceLocation map) {
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
GL11.glPushMatrix();
|
||||
GL11.glEnable(32826);
|
||||
BinnieCore.proxy.bindTexture(map);
|
||||
GuiScreen.itemRender.zLevel = zLevel;
|
||||
GuiScreen.itemRender.renderIcon((int) pos.x(), (int) pos.y(), icon, 16, 16);
|
||||
GL11.glEnable(32826);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
public boolean isHelpMode() {
|
||||
return Keyboard.isKeyDown(15);
|
||||
}
|
||||
|
||||
public FontRenderer getFontRenderer() {
|
||||
return fontRendererObj;
|
||||
}
|
||||
|
||||
public void resize(IPoint size) {
|
||||
xSize = (int) size.x();
|
||||
ySize = (int) size.y();
|
||||
guiLeft = (width - xSize) / 2;
|
||||
guiTop = (height - ySize) / 2;
|
||||
window.setPosition(new IPoint(guiLeft, guiTop));
|
||||
}
|
||||
|
||||
public void limitArea(IArea area) {
|
||||
float x = area.pos().x();
|
||||
float y = area.pos().y();
|
||||
float w = area.size().x();
|
||||
float h = area.size().y();
|
||||
y = height - (y + h);
|
||||
float k = xSize;
|
||||
float scaleX = width / (float) mc.displayWidth;
|
||||
float scaleY = height / (float) mc.displayHeight;
|
||||
x += 0.0f;
|
||||
y += 0.0f;
|
||||
w += 0.0f;
|
||||
h += 0.0f;
|
||||
GL11.glScissor((int) (x / scaleX), (int) (y / scaleY), (int) (w / scaleX), (int) (h / scaleY));
|
||||
}
|
||||
|
||||
public int getZLevel() {
|
||||
return (int) zLevel;
|
||||
}
|
||||
|
||||
public void drawRect(float p_73734_0_, float p_73734_1_, float p_73734_2_, float p_73734_3_, int p_73734_4_) {
|
||||
if (p_73734_0_ < p_73734_2_) {
|
||||
float j1 = p_73734_0_;
|
||||
p_73734_0_ = p_73734_2_;
|
||||
p_73734_2_ = j1;
|
||||
}
|
||||
if (p_73734_1_ < p_73734_3_) {
|
||||
float j1 = p_73734_1_;
|
||||
p_73734_1_ = p_73734_3_;
|
||||
p_73734_3_ = j1;
|
||||
}
|
||||
float f3 = (p_73734_4_ >> 24 & 0xFF) / 255.0f;
|
||||
float f4 = (p_73734_4_ >> 16 & 0xFF) / 255.0f;
|
||||
float f5 = (p_73734_4_ >> 8 & 0xFF) / 255.0f;
|
||||
float f6 = (p_73734_4_ & 0xFF) / 255.0f;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
GL11.glEnable(3042);
|
||||
GL11.glDisable(3553);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
GL11.glColor4f(f4, f5, f6, f3);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertex(p_73734_0_, p_73734_3_, 0.0);
|
||||
tessellator.addVertex(p_73734_2_, p_73734_3_, 0.0);
|
||||
tessellator.addVertex(p_73734_2_, p_73734_1_, 0.0);
|
||||
tessellator.addVertex(p_73734_0_, p_73734_1_, 0.0);
|
||||
tessellator.draw();
|
||||
GL11.glEnable(3553);
|
||||
GL11.glDisable(3042);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.minecraft;
|
||||
package binnie.core.craftgui.minecraft;
|
||||
|
||||
public interface IMachineInformation
|
||||
{
|
||||
Loaded 100 of 428 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user