Bit more work on gui framework
This commit is contained in:
parent
b5c246e65a
commit
3dd11bbf7c
|
@ -8,6 +8,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ import java.util.*;
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public abstract class GuiBase extends GuiContainer {
|
public abstract class GuiBase extends GuiContainer {
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
protected ResourceLocation texture;
|
protected ResourceLocation texture;
|
||||||
protected Map<String, GuiComponent> guiComponentMap = new TreeMap<String, GuiComponent>();
|
protected Map<String, GuiComponent> guiComponentMap = new TreeMap<String, GuiComponent>();
|
||||||
protected String title;
|
protected String title;
|
||||||
|
@ -229,6 +231,66 @@ public abstract class GuiBase extends GuiContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keyboard
|
||||||
|
@Override
|
||||||
|
protected void keyTyped(char characterTyped, int keyPressed) {
|
||||||
|
for (GuiComponent guiComponent : getGuiComponents()) {
|
||||||
|
if (guiComponent.onKeyPress(characterTyped, keyPressed)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.keyTyped(characterTyped, keyPressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse
|
||||||
|
@Override
|
||||||
|
public void handleMouseInput() {
|
||||||
|
// TODO
|
||||||
|
super.handleMouseInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClicked(int rawMouseX, int rawMouseY, int mouseButton) {
|
||||||
|
// TODO
|
||||||
|
super.mouseClicked(rawMouseX, rawMouseY, mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseMovedOrUp(int rawMouseX, int rawMouseY, int mouseButton) {
|
||||||
|
// TODO
|
||||||
|
super.mouseMovedOrUp(rawMouseX, rawMouseY, mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClickMove(int rawMouseX, int rawMouseY, int mouseButton, long duration) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Slot getSlotAtPosition(int rawMouseX, int rawMouseY) {
|
||||||
|
|
||||||
|
Iterator iterator = this.inventorySlots.inventorySlots.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Slot slot = (Slot) iterator.next();
|
||||||
|
if (this.isMouseOverSlot(slot, rawMouseX, rawMouseY)) {
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseOverSlot(Slot slot, int rawMouseX, int rawMouseY) {
|
||||||
|
return this.isMouseOverSlot(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, rawMouseX, rawMouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected boolean isMouseOverSlot(int slotPositionX, int slotPositionY, int slotWidth, int slotHeight, int rawMouseX, int rawMouseY) {
|
||||||
|
rawMouseX -= getGuiPositionX();
|
||||||
|
rawMouseY -= getGuiPositionX();
|
||||||
|
return (rawMouseX >= slotPositionX - 1) && (rawMouseX < slotPositionX + slotWidth + 1) && (rawMouseY >= slotPositionY - 1) && (rawMouseY < slotPositionY + slotHeight + 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int rawMouseX, int rawMouseY, float partialTicks) {
|
public void drawScreen(int rawMouseX, int rawMouseY, float partialTicks) {
|
||||||
super.drawScreen(rawMouseX, rawMouseY, partialTicks);
|
super.drawScreen(rawMouseX, rawMouseY, partialTicks);
|
||||||
|
@ -244,7 +306,6 @@ public abstract class GuiBase extends GuiContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int rawMouseX, int rawMouseY) {
|
protected void drawGuiContainerForegroundLayer(int rawMouseX, int rawMouseY) {
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
if (shouldDrawTitle && title != null) {
|
if (shouldDrawTitle && title != null) {
|
||||||
getFontRenderer().drawString(StringHelper.localize(title), RenderUtils.getCenteredTextOffset(getFontRenderer(), StringHelper.localize(title), getGuiWidth()), 6, 0x404040);
|
getFontRenderer().drawString(StringHelper.localize(title), RenderUtils.getCenteredTextOffset(getFontRenderer(), StringHelper.localize(title), getGuiWidth()), 6, 0x404040);
|
||||||
|
@ -256,7 +317,6 @@ public abstract class GuiBase extends GuiContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int rawMouseX, int rawMouseY) {
|
protected void drawGuiContainerBackgroundLayer(float partialTicks, int rawMouseX, int rawMouseY) {
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
if (texture != null) {
|
if (texture != null) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.pahimar.ee3.client.gui.component;
|
package com.pahimar.ee3.client.gui.component;
|
||||||
|
|
||||||
import com.pahimar.ee3.client.gui.GuiBase;
|
import com.pahimar.ee3.client.gui.GuiBase;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -49,6 +51,7 @@ public abstract class GuiComponent implements Comparable<GuiComponent> {
|
||||||
};
|
};
|
||||||
protected final GuiBase parentGui;
|
protected final GuiBase parentGui;
|
||||||
protected final String id;
|
protected final String id;
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
protected ResourceLocation texture;
|
protected ResourceLocation texture;
|
||||||
protected int positionX, positionY, componentWidth, componentHeight, textureWidth, textureHeight;
|
protected int positionX, positionY, componentWidth, componentHeight, textureWidth, textureHeight;
|
||||||
protected int ordering = 0;
|
protected int ordering = 0;
|
||||||
|
@ -223,23 +226,53 @@ public abstract class GuiComponent implements Comparable<GuiComponent> {
|
||||||
return (xCoord >= this.positionX && xCoord <= this.positionX + this.componentWidth) && (yCoord >= this.positionY && yCoord <= this.positionY + this.componentHeight) && (zIndex == this.zIndex);
|
return (xCoord >= this.positionX && xCoord <= this.positionX + this.componentWidth) && (yCoord >= this.positionY && yCoord <= this.positionY + this.componentHeight) && (zIndex == this.zIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onMouseButtonClick(int mouseX, int mouseY, int mouseButton);
|
|
||||||
|
|
||||||
public abstract void onMouseButtonDown(int mouseX, int mouseY, int mouseButton);
|
/**
|
||||||
|
* @param rawMouseX
|
||||||
|
* @param rawMouseY
|
||||||
|
* @param mouseButton
|
||||||
|
*/
|
||||||
|
public abstract void onMouseButtonClicked(int rawMouseX, int rawMouseY, int mouseButton);
|
||||||
|
|
||||||
public abstract void onMouseButtonUp(int mouseX, int mouseY, int mouseButton);
|
/**
|
||||||
|
*
|
||||||
|
* @param rawMouseX
|
||||||
|
* @param rawMouseY
|
||||||
|
* @param mouseButton
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean onMouseButtonClick(int rawMouseX, int rawMouseY, int mouseButton) {
|
||||||
|
onMouseButtonClicked(rawMouseX, rawMouseY, mouseButton);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void onMouseButtonRelease(int mouseX, int mouseY, int mouseButton, long duration);
|
public abstract void onMouseButtonDown(int rawMouseX, int rawMouseY, int mouseButton);
|
||||||
|
|
||||||
public abstract void onMouseMove(int prevMouseX, int prevMouseY, int newMouseX, int newMouseY);
|
public abstract void onMouseButtonUp(int rawMouseX, int rawMouseY, int mouseButton);
|
||||||
|
|
||||||
public abstract void onMouseEnter(int mouseX, int mouseY);
|
public abstract void onMouseButtonRelease(int rawMouseX, int rawMouseY, int mouseButton, long duration);
|
||||||
|
|
||||||
public abstract void onMouseOver(int mouseX, int mouseY, float partialTicks);
|
public abstract void onMouseMove(int prevRawMouseX, int prevRawMouseY, int newRawMouseX, int newRawMouseY);
|
||||||
|
|
||||||
public abstract void onMouseLeave(int mouseX, int mouseY);
|
public abstract void onMouseEnter(int rawMouseX, int rawMouseY);
|
||||||
|
|
||||||
public abstract void onKeyPress(char characterTyped, int keyPressed);
|
public abstract void onMouseOver(int rawMouseX, int rawMouseY, float partialTicks);
|
||||||
|
|
||||||
|
public abstract void onMouseLeave(int rawMouseX, int rawMouseY);
|
||||||
|
|
||||||
|
public abstract void onMouseWheel(int rawMouseX, int rawMouseY, int change);
|
||||||
|
|
||||||
|
public abstract void onKeyPressed(char characterTyped, int keyPressed);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param characterTyped
|
||||||
|
* @param keyPressed
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean onKeyPress(char characterTyped, int keyPressed) {
|
||||||
|
onKeyPress(characterTyped, keyPressed);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void onFocusGain();
|
public abstract void onFocusGain();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue