mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Added the ability to change between RF and Tesla display modes in machines
This commit is contained in:
parent
6cf525f6c5
commit
3df2868fe3
13 changed files with 127 additions and 9 deletions
|
@ -46,7 +46,7 @@ public class ClientEvents{
|
|||
private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY+" ";
|
||||
private static final String ADVANCED_INFO_HEADER_PRE = TextFormatting.GRAY+" -";
|
||||
|
||||
private static final EnergyDisplay ENERGY_DISPLAY = new EnergyDisplay(0, 0, null);
|
||||
private static EnergyDisplay energyDisplay;
|
||||
|
||||
public ClientEvents(){
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
@ -175,8 +175,13 @@ public class ClientEvents{
|
|||
IEnergyDisplay display = (IEnergyDisplay)tileHit;
|
||||
if(!display.needsHoldShift() || player.isSneaking()){
|
||||
profiler.startSection("EnergyDisplay");
|
||||
ENERGY_DISPLAY.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true);
|
||||
ENERGY_DISPLAY.draw();
|
||||
|
||||
if(energyDisplay == null){
|
||||
energyDisplay = new EnergyDisplay(0, 0, null);
|
||||
}
|
||||
energyDisplay.setData(2, event.getResolution().getScaledHeight()-96, display.getEnergyStorage(), true, true);
|
||||
energyDisplay.draw();
|
||||
|
||||
profiler.endSection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,20 @@
|
|||
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer;
|
||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EnergyDisplay extends Gui{
|
||||
|
||||
|
@ -26,6 +33,7 @@ public class EnergyDisplay extends Gui{
|
|||
private int y;
|
||||
private boolean outline;
|
||||
private boolean drawTextNextTo;
|
||||
private boolean displayTesla;
|
||||
|
||||
public EnergyDisplay(int x, int y, EnergyStorage rfReference, boolean outline, boolean drawTextNextTo){
|
||||
this.setData(x, y, rfReference, outline, drawTextNextTo);
|
||||
|
@ -41,6 +49,10 @@ public class EnergyDisplay extends Gui{
|
|||
this.rfReference = rfReference;
|
||||
this.outline = outline;
|
||||
this.drawTextNextTo = drawTextNextTo;
|
||||
|
||||
if(TileEntityBase.teslaLoaded){
|
||||
this.displayTesla = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().thePlayer).theCompound.getBoolean("DisplayTesla");
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
|
@ -49,6 +61,7 @@ public class EnergyDisplay extends Gui{
|
|||
|
||||
int barX = this.x;
|
||||
int barY = this.y;
|
||||
int vOffset = this.displayTesla ? 85 : 0;
|
||||
|
||||
if(this.outline){
|
||||
this.drawTexturedModalRect(this.x, this.y, 52, 163, 26, 93);
|
||||
|
@ -56,11 +69,11 @@ public class EnergyDisplay extends Gui{
|
|||
barX += 4;
|
||||
barY += 4;
|
||||
}
|
||||
this.drawTexturedModalRect(barX, barY, 18, 171, 18, 85);
|
||||
this.drawTexturedModalRect(barX, barY, 18, 171-vOffset, 18, 85);
|
||||
|
||||
if(this.rfReference.getEnergyStored() > 0){
|
||||
int i = this.rfReference.getEnergyStored()*83/this.rfReference.getMaxEnergyStored();
|
||||
this.drawTexturedModalRect(barX+1, barY+84-i, 36, 172, 16, i);
|
||||
this.drawTexturedModalRect(barX+1, barY+84-i, 36, 172-vOffset, 16, i);
|
||||
}
|
||||
|
||||
if(this.drawTextNextTo){
|
||||
|
@ -69,13 +82,44 @@ public class EnergyDisplay extends Gui{
|
|||
}
|
||||
|
||||
public void drawOverlay(int mouseX, int mouseY){
|
||||
if(mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85)){
|
||||
if(this.isMouseOver(mouseX, mouseY)){
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
GuiUtils.drawHoveringText(Collections.singletonList(this.getOverlayText()), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
|
||||
|
||||
List<String> text = new ArrayList<String>();
|
||||
text.add(this.getOverlayText());
|
||||
if(TileEntityBase.teslaLoaded){
|
||||
text.add(TextFormatting.GRAY+""+TextFormatting.ITALIC+"Click to change mode!");
|
||||
}
|
||||
GuiUtils.drawHoveringText(text, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
public void onMouseClick(int mouseX, int mouseY, int mouseButton){
|
||||
if(mouseButton == 0 && this.isMouseOver(mouseX, mouseY)){
|
||||
this.changeDisplayMode();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMouseOver(int mouseX, int mouseY){
|
||||
return mouseX >= this.x && mouseY >= this.y && mouseX < this.x+(this.outline ? 26 : 18) && mouseY < this.y+(this.outline ? 93 : 85);
|
||||
}
|
||||
|
||||
private String getOverlayText(){
|
||||
return this.rfReference.getEnergyStored()+"/"+this.rfReference.getMaxEnergyStored()+" RF";
|
||||
return this.rfReference.getEnergyStored()+"/"+this.rfReference.getMaxEnergyStored()+(this.displayTesla ? " Tesla" : " RF");
|
||||
}
|
||||
|
||||
private void changeDisplayMode(){
|
||||
if(TileEntityBase.teslaLoaded){
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
this.displayTesla = !this.displayTesla;
|
||||
data.setBoolean("DisplayTesla", this.displayTesla);
|
||||
|
||||
NBTTagCompound dataToSend = new NBTTagCompound();
|
||||
dataToSend.setTag("Data", data);
|
||||
dataToSend.setInteger("WorldID", Minecraft.getMinecraft().theWorld.provider.getDimension());
|
||||
dataToSend.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId());
|
||||
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -46,6 +47,11 @@ public class GuiCanolaPress extends GuiContainer{
|
|||
this.fluid = new FluidDisplay(this.guiLeft+116, this.guiTop+5, this.press.tank);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -43,6 +44,12 @@ public class GuiCoalGenerator extends GuiContainer{
|
|||
this.energy = new EnergyDisplay(this.guiLeft+42, this.guiTop+5, this.generator.storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -29,6 +29,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -55,6 +56,12 @@ public class GuiCoffeeMachine extends GuiContainer{
|
|||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -43,6 +44,12 @@ public class GuiDirectionalBreaker extends GuiContainer{
|
|||
this.energy = new EnergyDisplay(this.guiLeft+42, this.guiTop+5, this.breaker.storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -43,6 +44,12 @@ public class GuiEnergizer extends GuiContainer{
|
|||
this.energy = new EnergyDisplay(this.guiLeft+56, this.guiTop+5, this.energizer.storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -43,6 +44,12 @@ public class GuiEnervator extends GuiContainer{
|
|||
this.energy = new EnergyDisplay(this.guiLeft+56, this.guiTop+5, this.enervator.storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -43,6 +44,12 @@ public class GuiFurnaceDouble extends GuiContainer{
|
|||
this.energy.drawOverlay(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -50,6 +51,12 @@ public class GuiGrinder extends GuiContainer{
|
|||
this.energy = new EnergyDisplay(this.guiLeft+(this.isDouble ? 13 : 42), this.guiTop+5, this.tileGrinder.storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -47,6 +48,12 @@ public class GuiOilGenerator extends GuiContainer{
|
|||
this.fluid = new FluidDisplay(this.guiLeft+116, this.guiTop+5, this.generator.tank);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int x, int y, float f){
|
||||
super.drawScreen(x, y, f);
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -37,6 +38,12 @@ public class GuiRepairer extends GuiContainer{
|
|||
this.ySize = 93+86;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
||||
this.energy.onMouseClick(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui(){
|
||||
super.initGui();
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 6.4 KiB |
Loading…
Reference in a new issue