Skip to content

Commit

Permalink
Paint Brush Scroll Menu
Browse files Browse the repository at this point in the history
-Added scrollable menu for the paintbrush GUI to allow for swifter selection of skin for models with copious amounts.
  • Loading branch information
broscolotos committed Dec 6, 2023
2 parents 23591f9 + 6bcc7eb commit 6f2940d
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 131 deletions.
12 changes: 12 additions & 0 deletions src/main/java/train/client/gui/GuiButtonPaintbrushMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void drawButton(Minecraft mc, int par2, int par3) {
RenderHelper.enableGUIStandardItemLighting();
GL11.glPushMatrix();
mc.renderEngine.bindTexture(new ResourceLocation(Info.resourceLocation, Info.guiPrefix + "gui_paintbrush_menu_buttons.png"));
if(this.type == Type.SKINS) {
mc.renderEngine.bindTexture(new ResourceLocation(Info.resourceLocation, Info.guiPrefix + "gui_paintbrush_menu_outlines.png"));
}
this.drawTexturedModalRect(this.xPosition, this.yPosition, u, v, TEXTURE_WIDTH, TEXTURE_HEIGHT);
RenderHelper.disableStandardItemLighting();
GL11.glPopMatrix();
Expand Down Expand Up @@ -154,6 +157,15 @@ else if (type == Type.RANDOM)
else
this.u = 110;
break;
case SKINS:
TEXTURE_WIDTH = 128;
TEXTURE_HEIGHT = 16;
this.u = 0;
if (texture == Texture.INACTIVE) {
this.v = 83;
} else {
this.v = 99;
}
}
}
}
Expand Down
152 changes: 120 additions & 32 deletions src/main/java/train/client/gui/GuiPaintbrushMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ebf.tim.utility.DebugUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -12,6 +11,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import train.client.render.RenderRollingStock;
import train.common.Traincraft;
Expand All @@ -26,7 +26,6 @@
import train.common.overlaytexture.OverlayTextureManager;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -73,9 +72,11 @@ public class GuiPaintbrushMenu extends GuiScreen {
private GuiButtonPaintbrushMenu applyButton;
private GuiButtonPaintbrushMenu descriptionArrowUp;
private GuiButtonPaintbrushMenu descriptionArrowDown;
private GuiButtonPaintbrushMenu skinListArrowUp;
private GuiButtonPaintbrushMenu skinListArrowDown;
private GuiButtonPaintbrushMenu skinListDropdown;

public HashMap<String, GuiButtonPaintbrushMenu> skinList;
public HashMap<Object, GuiButtonPaintbrushMenu> skinList;
private boolean renderModels;
private boolean disableLighting = true;
private boolean drawList;
Expand All @@ -95,10 +96,15 @@ public class GuiPaintbrushMenu extends GuiScreen {
private String currentDisplayTextureTitle;
private final int MAX_LINES_OF_DESCRIPTION = 5;

private final int MAX_LISTED_SKINS = 10;
private int topVisSkin;
private int lastNonSkins;

public GuiPaintbrushMenu(EntityPlayer editingPlayer, EntityRollingStock rollingStock) {
this.editingPlayer = editingPlayer;
this.rollingStock = rollingStock;
drawList = false;
topVisSkin = 0;
try {
renderEntity = rollingStock.getClass().getConstructor(new Class[]{ World.class }).newInstance(rollingStock.worldObj);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
Expand Down Expand Up @@ -147,11 +153,20 @@ public void initGui() {
this.buttonList.add(this.overlayControllerFixed = new GuiButtonPaintbrushOverlayController(13, GUI_ANCHOR_X + 264, GUI_ANCHOR_Y + 202, 29, 29, GuiButtonPaintbrushOverlayController.Type.FIXED));
this.buttonList.add(this.closeMenuButton = new GuiButtonPaintbrushMenu(14, GUI_ANCHOR_X + 382, GUI_ANCHOR_Y + 6, 22, 22, GuiButtonPaintbrushMenu.Type.CLOSE));
this.buttonList.add(this.playPauseButton = new GuiButtonPaintbrushMenu(15, GUI_ANCHOR_X + 4, GUI_ANCHOR_Y + MENU_TEXTURE_HEIGHT - 29, 22, 22, GuiButtonPaintbrushMenu.Type.PLAY));
this.buttonList.add(this.skinListDropdown = new GuiButtonPaintbrushMenu(17,GUI_ANCHOR_MID_X - ((int) (fontRendererObj.getStringWidth(currentDisplayTextureTitle) * 0.5)), GUI_ANCHOR_Y + 14,60,22,GuiButtonPaintbrushMenu.Type.SKINLISTDROPDOWN));
int yOffset = 22;
int entry = buttonList.size()+1;
for(int i=0;i<rollingStock.getSpec().getLiveries().size();i++) {
this.buttonList.add(new GuiButtonPaintbrushMenu(entry,GUI_ANCHOR_X + 80 + 64, GUI_ANCHOR_Y + 10+yOffset,60,22, GuiButtonPaintbrushMenu.Type.SKINS));
this.buttonList.add(this.skinListDropdown = new GuiButtonPaintbrushMenu(17,GUI_ANCHOR_X + 80, GUI_ANCHOR_Y + 6, 256, 22,GuiButtonPaintbrushMenu.Type.SKINLISTDROPDOWN));
this.buttonList.add(this.skinListArrowUp = new GuiButtonPaintbrushMenu(18, GUI_ANCHOR_X + 276, GUI_ANCHOR_Y + 34, 7, 22, GuiButtonPaintbrushMenu.Type.DESC_ARROW_UP));
this.buttonList.add(this.skinListArrowDown = new GuiButtonPaintbrushMenu(19, GUI_ANCHOR_X + 276, GUI_ANCHOR_Y + 60, 7, 22, GuiButtonPaintbrushMenu.Type.DESC_ARROW_DOWN));
int yOffset = 18;
this.lastNonSkins=buttonList.size();
int entry = lastNonSkins+2;
int amt = MAX_LISTED_SKINS;
if (amt > rollingStock.getSpec().getLiveries().size()) {
amt = rollingStock.getSpec().getLiveries().size();
}
for(int i=0;i<amt;i++) {
this.buttonList.add(new GuiButtonPaintbrushMenu(entry,GUI_ANCHOR_X + 80 + 64, GUI_ANCHOR_Y + 10+yOffset,128,16, GuiButtonPaintbrushMenu.Type.SKINS));
((GuiButtonPaintbrushMenu) this.buttonList.get(entry-2)).showButton=false;
((GuiButtonPaintbrushMenu) this.buttonList.get(entry-2)).visible=false;
entry++;
yOffset += 16;
}
Expand Down Expand Up @@ -183,7 +198,12 @@ private void updateButtons() {
this.descriptionArrowUp.showButton = descriptionScrollerIndex > 0;
this.descriptionArrowDown.visible = descriptionScrollerIndex + MAX_LINES_OF_DESCRIPTION < currentTextureDescription.size();
this.descriptionArrowDown.showButton = this.descriptionArrowDown.visible;

this.skinListArrowUp.visible = true;
this.skinListArrowUp.showButton = (this.drawList && topVisSkin > 0);
this.skinListArrowDown.visible = true;
this.skinListArrowDown.showButton = (this.drawList && topVisSkin+10 < rollingStock.getSpec().getLiveries().size());
this.skinListDropdown.showButton = true;
this.skinListDropdown.visible = true;
this.renderModelsButton.visible = true;
this.renderModelsButton.showButton = true;

Expand Down Expand Up @@ -224,14 +244,32 @@ private void updateButtons() {
this.overlayControllerFixed.showButton = false;
}
if(drawList) {
int yOffset = 22;
int entry = buttonList.size()+1;
for(String t:rollingStock.getSpec().getLiveries()) {
skinList.put(t,new GuiButtonPaintbrushMenu(entry,GUI_ANCHOR_X + 80 + 64, GUI_ANCHOR_Y + 10+yOffset,60,22, GuiButtonPaintbrushMenu.Type.SKINS));
entry++;
yOffset += 16;
int entry = this.lastNonSkins;
for(Object t:this.buttonList) {
if(t instanceof GuiButtonPaintbrushMenu) {
if((this.buttonList.indexOf(t) >= 3 && this.buttonList.indexOf(t) <= 5) || this.buttonList.indexOf(t) <= 1) {
((GuiButtonPaintbrushMenu) t).visible = false;
}
if(this.buttonList.indexOf(t) >= entry) {
((GuiButtonPaintbrushMenu) t).visible = true;
((GuiButtonPaintbrushMenu) t).showButton = true;
}
}
}
} else {
int entry = this.lastNonSkins;
for(Object t:this.buttonList) {
if(t instanceof GuiButtonPaintbrushMenu) {
if(this.buttonList.indexOf(t) >= 3 && this.buttonList.indexOf(t) <= 5) {
((GuiButtonPaintbrushMenu) t).visible = true;
((GuiButtonPaintbrushMenu) t).showButton = true;
}
if(this.buttonList.indexOf(t) >= entry) {
((GuiButtonPaintbrushMenu) t).visible = false;
((GuiButtonPaintbrushMenu) t).showButton = false;
}
}
}
this.buttonList.add(skinList.keySet());
}
}

Expand Down Expand Up @@ -307,21 +345,20 @@ public void drawScreen(int mouseX, int mouseY, float par3) {
// Draw Currently Displayed Texture Name and Tooltip
fontRendererObj.drawString(currentDisplayTextureTitle, GUI_ANCHOR_MID_X - ((int) (fontRendererObj.getStringWidth(currentDisplayTextureTitle) * 0.5)), GUI_ANCHOR_Y + 14, 0);
// Draw description.
int stringWidth;
for (int i = 0; i < Math.min(MAX_LINES_OF_DESCRIPTION, currentTextureDescription.size()); i++) {
stringWidth = fontRendererObj.getStringWidth(currentTextureDescription.get(i + descriptionScrollerIndex));
fontRendererObj.drawString(currentTextureDescription.get(i + descriptionScrollerIndex), GUI_ANCHOR_MID_X - ((int) (stringWidth * 0.5)) - 5, GUI_ANCHOR_Y + MENU_TEXTURE_HEIGHT - 60 + (i * fontRendererObj.FONT_HEIGHT), 0);
}

if (drawList == true) {
if(!drawList) {
int stringWidth;
for (int i = 0; i < Math.min(MAX_LINES_OF_DESCRIPTION, currentTextureDescription.size()); i++) {
stringWidth = fontRendererObj.getStringWidth(currentTextureDescription.get(i + descriptionScrollerIndex));
fontRendererObj.drawString(currentTextureDescription.get(i + descriptionScrollerIndex), GUI_ANCHOR_MID_X - ((int) (stringWidth * 0.5)) - 5, GUI_ANCHOR_Y + MENU_TEXTURE_HEIGHT - 60 + (i * fontRendererObj.FONT_HEIGHT), 0);
}
} else {
int yOffset = 22;
for (String t : rollingStock.getSpec().getLiveries()) {
super.drawScreen(mouseX, mouseY, par3);
mc.renderEngine.bindTexture(outlinesTexture);
this.drawTexturedModalRect(GUI_ANCHOR_X + 80 + 64, GUI_ANCHOR_Y + 6+yOffset, 0, 83, 128, 16);
fontRendererObj.drawString(t, GUI_ANCHOR_MID_X - ((int) (fontRendererObj.getStringWidth(t) * 0.5)),GUI_ANCHOR_Y + 10+yOffset,0);
yOffset += 16;

for (int i=0;i<MAX_LISTED_SKINS;i++) {
if(i+topVisSkin<rollingStock.getSpec().getLiveries().size()) {
String t = rollingStock.getSpec().getLiveries().get(i + topVisSkin);
fontRendererObj.drawString(t, GUI_ANCHOR_MID_X - ((int) (fontRendererObj.getStringWidth(t) * 0.5)), GUI_ANCHOR_Y + 10 + yOffset, 0);
yOffset += 16;
}
}
}

Expand Down Expand Up @@ -374,8 +411,15 @@ public void drawScreen(int mouseX, int mouseY, float par3) {
else
drawHoveringText(Collections.singletonList(StatCollector.translateToLocal("paintbrushmenu.Play.name")), mouseX, mouseY, fontRendererObj);
break;
case 16:
drawHoveringText(Collections.singletonList("paintbrushmenu.Dropdown.name"), mouseX, mouseY, fontRendererObj);
case 17: //dropdown
drawHoveringText(Collections.singletonList(StatCollector.translateToLocal("paintbrushmenu.List Skins.name")), mouseX, mouseY, fontRendererObj);
break;
case 18: //dropdown UP
drawHoveringText(Collections.singletonList(StatCollector.translateToLocal("paintbrushmenu.Scroll Up.name")), mouseX, mouseY, fontRendererObj);
break;
case 19: //dropdown DOWN
drawHoveringText(Collections.singletonList(StatCollector.translateToLocal("paintbrushmenu.Scroll Down.name")), mouseX, mouseY, fontRendererObj);
break;
}

RenderHelper.enableStandardItemLighting();
Expand Down Expand Up @@ -480,8 +524,27 @@ protected void actionPerformed(GuiButton clickedButton) {
break;
case 17:
drawList = !drawList;
renderModels = !renderModels;
updateButtons();
break;
case 18:
handleMenuScroll(1);
updateButtons();
break;
case 19:
handleMenuScroll(-1);
updateButtons();
break;
default:
if(clickedButton.id >= this.lastNonSkins && drawList) {
currentDisplayTexture = rollingStock.getSpec().getLiveries().indexOf(
rollingStock.getSpec().getLiveries().get(this.buttonList.indexOf(clickedButton)-this.lastNonSkins+topVisSkin));
drawList = !drawList;
renderModels = !renderModels;
updateSelectedTextureProperties();
updateButtons();
break;
}
}
}
}
Expand All @@ -491,6 +554,31 @@ public void onGuiClosed() {
super.onGuiClosed();
}

public void handleMenuScroll(int i) {
if (i>0){
if(topVisSkin > 0) {
topVisSkin--;
updateButtons();
}
} else {
if(topVisSkin+10 < rollingStock.getSpec().getLiveries().size()) {
topVisSkin++;
updateButtons();
}
}
}
@Override
public void handleMouseInput() {
int i = Mouse.getEventDWheel();
if(i!=0){
//handle scrolling through the dropdown
if(drawList) {
handleMenuScroll(i);
}
}
//desc box scroll here
super.handleMouseInput();
}
@Override
protected void keyTyped(char eventChar, int eventKey) {
if (eventKey == 1 || eventChar == 'e') { // If ESC...
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/train/common/Traincraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.VillagerRegistry;
import ebf.tim.utility.DebugUtil;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.launchwrapper.Launch;
Expand Down Expand Up @@ -108,7 +109,7 @@ public class Traincraft {

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
TraincraftUtil.dev = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
DebugUtil.dev = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
tcLog.info("Starting Traincraft " + Info.modVersion + "!");
/* Config handler */
configDirectory = event.getModConfigurationDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyProvider;
import cpw.mods.fml.common.FMLCommonHandler;
import ebf.tim.utility.DebugUtil;
import mods.railcraft.api.core.items.IToolCrowbar;
import mods.railcraft.api.electricity.IElectricGrid;
import mods.railcraft.api.tracks.ITrackPowered;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void updateEntity() {
if(this.updateTicks % 10 == 0) {
if (this.maxEnergy > this.RFChandler.getCharge()) {
if (this.getWorld().getTileEntity(this.getX(), this.getY() - 1, this.getZ()) instanceof IEnergyProvider) {
TraincraftUtil.println("found input and it gives " + ((IEnergyProvider)this.getWorld().getTileEntity(this.getX(), this.getY() - 1, this.getZ())).extractEnergy(ForgeDirection.UP, 100, true));
DebugUtil.println("found input and it gives " + ((IEnergyProvider)this.getWorld().getTileEntity(this.getX(), this.getY() - 1, this.getZ())).extractEnergy(ForgeDirection.UP, 100, true));
this.receiveEnergy(ForgeDirection.DOWN, ((IEnergyProvider) this.getWorld().getTileEntity(this.getX(), this.getY() - 1, this.getZ())).extractEnergy(ForgeDirection.UP, 100, false), false);
}
int x = this.getX();
Expand Down
Loading

0 comments on commit 6f2940d

Please sign in to comment.