2022-11-09 22:15:45 +01:00
|
|
|
package icbm.zhapin.gui;
|
|
|
|
|
2022-11-13 15:51:36 +01:00
|
|
|
import icbm.zhapin.ICBMExplosion;
|
2022-11-09 22:15:45 +01:00
|
|
|
import icbm.zhapin.daodan.EMissile;
|
|
|
|
import icbm.zhapin.jiqi.BMachine;
|
2022-11-13 15:51:36 +01:00
|
|
|
import icbm.zhapin.jiqi.RadarTowerGuiPacket;
|
2022-11-09 22:15:45 +01:00
|
|
|
import icbm.zhapin.jiqi.TRadarTower;
|
|
|
|
import net.minecraft.client.gui.GuiTextField;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import org.lwjgl.input.Mouse;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
2022-12-10 12:08:47 +01:00
|
|
|
import universalelectricity.api.energy.UnitDisplay;
|
2022-11-09 22:15:45 +01:00
|
|
|
import universalelectricity.core.vector.Vector2;
|
|
|
|
import universalelectricity.prefab.GuiBase;
|
|
|
|
import universalelectricity.prefab.TranslationHelper;
|
|
|
|
import universalelectricity.prefab.vector.Region2;
|
|
|
|
|
|
|
|
public class GRadarTower extends GuiBase {
|
|
|
|
private TRadarTower tileEntity;
|
|
|
|
private int containerPosX;
|
|
|
|
private int containerPosY;
|
|
|
|
private GuiTextField textFieldAlarmRange;
|
|
|
|
private GuiTextField textFieldSafetyZone;
|
|
|
|
private Vector2 mouseOverCoords;
|
|
|
|
private Vector2 mousePosition;
|
|
|
|
private Vector2 radarCenter;
|
|
|
|
private float radarMapRadius;
|
|
|
|
private String info;
|
|
|
|
private String info2;
|
|
|
|
|
|
|
|
public GRadarTower(final TRadarTower tileEntity) {
|
|
|
|
this.mouseOverCoords = new Vector2();
|
|
|
|
this.mousePosition = new Vector2();
|
|
|
|
this.info = "";
|
|
|
|
this.tileEntity = tileEntity;
|
2022-11-09 22:16:55 +01:00
|
|
|
this.mouseOverCoords
|
|
|
|
= new Vector2(this.tileEntity.xCoord, this.tileEntity.zCoord);
|
2022-11-09 22:15:45 +01:00
|
|
|
super.xSize = 256;
|
2022-11-09 22:16:55 +01:00
|
|
|
this.radarCenter = new Vector2(
|
|
|
|
this.containerPosX + super.xSize / 3 - 14,
|
|
|
|
this.containerPosY + super.ySize / 2 + 4
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.radarMapRadius = 7.836991f;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui() {
|
|
|
|
super.initGui();
|
2022-11-09 22:16:55 +01:00
|
|
|
(this.textFieldSafetyZone
|
|
|
|
= new GuiTextField(this.fontRendererObj, 155, 83, 30, 12))
|
|
|
|
.setMaxStringLength(3);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.textFieldSafetyZone.setText(this.tileEntity.safetyRadius + "");
|
2022-11-09 22:16:55 +01:00
|
|
|
(this.textFieldAlarmRange
|
|
|
|
= new GuiTextField(this.fontRendererObj, 155, 110, 30, 12))
|
|
|
|
.setMaxStringLength(3);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.textFieldAlarmRange.setText(this.tileEntity.alarmRadius + "");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyTyped(final char par1, final int par2) {
|
|
|
|
super.keyTyped(par1, par2);
|
|
|
|
this.textFieldSafetyZone.textboxKeyTyped(par1, par2);
|
|
|
|
this.textFieldAlarmRange.textboxKeyTyped(par1, par2);
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
try {
|
|
|
|
final int newSafetyRadius = Math.min(
|
2022-11-09 22:16:55 +01:00
|
|
|
500, Math.max(0, Integer.parseInt(this.textFieldSafetyZone.getText()))
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.tileEntity.safetyRadius = newSafetyRadius;
|
2022-11-13 15:51:36 +01:00
|
|
|
ICBMExplosion.channel.sendToServer(new RadarTowerGuiPacket(this.tileEntity));
|
2022-11-09 22:16:55 +01:00
|
|
|
} catch (final NumberFormatException ex) {}
|
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
try {
|
|
|
|
final int newAlarmRadius = Math.min(
|
2022-11-09 22:16:55 +01:00
|
|
|
500, Math.max(0, Integer.parseInt(this.textFieldAlarmRange.getText()))
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.tileEntity.alarmRadius = newAlarmRadius;
|
2022-11-13 15:51:36 +01:00
|
|
|
ICBMExplosion.channel.sendToServer(new RadarTowerGuiPacket(this.tileEntity));
|
2022-11-09 22:16:55 +01:00
|
|
|
} catch (final NumberFormatException ex2) {}
|
2022-11-09 22:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseClicked(final int par1, final int par2, final int par3) {
|
|
|
|
super.mouseClicked(par1, par2, par3);
|
2022-11-09 22:16:55 +01:00
|
|
|
this.textFieldAlarmRange.mouseClicked(
|
|
|
|
par1 - this.containerPosX, par2 - this.containerPosY, par3
|
|
|
|
);
|
|
|
|
this.textFieldSafetyZone.mouseClicked(
|
|
|
|
par1 - this.containerPosX, par2 - this.containerPosY, par3
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-09 22:16:55 +01:00
|
|
|
protected void drawForegroundLayer(final int var2, final int var3, final float var1) {
|
2022-11-09 22:15:45 +01:00
|
|
|
this.fontRendererObj.drawString(
|
2022-11-09 22:16:55 +01:00
|
|
|
"§7" + TranslationHelper.getLocal("icbm.machine.9.name"),
|
|
|
|
super.xSize / 2 - 30,
|
|
|
|
6,
|
|
|
|
4210752
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.fontRendererObj.drawString("Coordinates:", 155, 18, 4210752);
|
|
|
|
this.fontRendererObj.drawString(
|
2022-11-09 22:16:55 +01:00
|
|
|
"X: " + (int) Math.round(this.mouseOverCoords.x)
|
|
|
|
+ " Z: " + (int) Math.round(this.mouseOverCoords.y),
|
|
|
|
155,
|
|
|
|
30,
|
|
|
|
4210752
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.fontRendererObj.drawString("§6" + this.info, 155, 42, 4210752);
|
|
|
|
this.fontRendererObj.drawString("§4" + this.info2, 155, 54, 4210752);
|
|
|
|
this.fontRendererObj.drawString("Safe Zone:", 155, 70, 4210752);
|
|
|
|
this.textFieldSafetyZone.drawTextBox();
|
|
|
|
this.fontRendererObj.drawString("Blocks", 190, 85, 4210752);
|
|
|
|
this.fontRendererObj.drawString("Alarm Range:", 155, 98, 4210752);
|
|
|
|
this.textFieldAlarmRange.drawTextBox();
|
|
|
|
this.fontRendererObj.drawString("Blocks", 190, 112, 4210752);
|
|
|
|
this.fontRendererObj.drawString(
|
2022-12-10 12:08:47 +01:00
|
|
|
UnitDisplay.getDisplay(
|
2022-11-09 22:16:55 +01:00
|
|
|
this.tileEntity.getRequest().getWatts() * 20.0,
|
2022-12-10 12:08:47 +01:00
|
|
|
UnitDisplay.Unit.WATT
|
2022-11-09 22:16:55 +01:00
|
|
|
),
|
|
|
|
155,
|
|
|
|
128,
|
|
|
|
4210752
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.fontRendererObj.drawString(
|
2022-12-10 12:08:47 +01:00
|
|
|
UnitDisplay.getDisplay(
|
|
|
|
this.tileEntity.getVoltage(), UnitDisplay.Unit.VOLTAGE
|
2022-11-09 22:16:55 +01:00
|
|
|
),
|
|
|
|
155,
|
|
|
|
138,
|
|
|
|
4210752
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
String color = "§4";
|
|
|
|
String status = "Idle";
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (this.tileEntity.isDisabled()) {
|
|
|
|
status = "Disabled!";
|
2022-11-11 23:10:52 +01:00
|
|
|
} else if (this.tileEntity.canRun()) {
|
2022-11-09 22:15:45 +01:00
|
|
|
color = "§2";
|
|
|
|
status = "Radar On!";
|
|
|
|
} else {
|
|
|
|
status = "No Electricity!";
|
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
this.fontRendererObj.drawString(color + status, 155, 150, 4210752);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-09 22:16:55 +01:00
|
|
|
protected void drawBackgroundLayer(final int var2, final int var3, final float var1) {
|
2022-11-09 22:15:45 +01:00
|
|
|
this.mc.renderEngine.bindTexture(
|
2022-11-09 22:16:55 +01:00
|
|
|
new ResourceLocation("icbm", "textures/gui/gui_radar.png")
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
this.containerPosX = (this.width - super.xSize) / 2;
|
|
|
|
this.containerPosY = (this.height - super.ySize) / 2;
|
2022-11-09 22:16:55 +01:00
|
|
|
this.drawTexturedModalRect(
|
|
|
|
this.containerPosX, this.containerPosY, 0, 0, super.xSize, super.ySize
|
|
|
|
);
|
|
|
|
this.radarCenter = new Vector2(
|
|
|
|
this.containerPosX + super.xSize / 3 - 10,
|
|
|
|
this.containerPosY + super.ySize / 2 + 4
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.radarMapRadius = 7.0422535f;
|
|
|
|
this.info = "";
|
|
|
|
this.info2 = "";
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-11 23:10:52 +01:00
|
|
|
if (this.tileEntity.canRun()) {
|
2022-11-09 22:15:45 +01:00
|
|
|
int range = 4;
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-11 23:10:52 +01:00
|
|
|
for (final Entity entity : this.tileEntity.entitiesInRange) {
|
2022-11-09 22:15:45 +01:00
|
|
|
final Vector2 position = new Vector2(
|
2022-11-09 22:16:55 +01:00
|
|
|
this.radarCenter.x
|
|
|
|
+ (entity.posX - this.tileEntity.xCoord) / this.radarMapRadius,
|
|
|
|
this.radarCenter.y
|
|
|
|
- (entity.posZ - this.tileEntity.zCoord) / this.radarMapRadius
|
|
|
|
);
|
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (entity instanceof EMissile) {
|
|
|
|
if (this.tileEntity.isWeiXianDaoDan((EMissile) entity)) {
|
|
|
|
this.mc.renderEngine.bindTexture(
|
2022-11-09 22:16:55 +01:00
|
|
|
new ResourceLocation("icbm", "textures/gui/reddot.png")
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
} else {
|
|
|
|
this.mc.renderEngine.bindTexture(
|
2022-11-09 22:16:55 +01:00
|
|
|
new ResourceLocation("icbm", "textures/gui/yellowdot.png")
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.mc.renderEngine.bindTexture(
|
2022-11-09 22:16:55 +01:00
|
|
|
new ResourceLocation("icbm", "textures/gui/yellowdot.png")
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
|
|
|
this.drawTexturedModalRect(position.intX(), position.intY(), 0, 0, 2, 2);
|
2022-11-09 22:15:45 +01:00
|
|
|
final Vector2 minPosition = position.clone();
|
|
|
|
minPosition.add(-range);
|
|
|
|
final Vector2 maxPosition = position.clone();
|
|
|
|
maxPosition.add(range);
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (new Region2(minPosition, maxPosition).isIn(this.mousePosition)) {
|
|
|
|
this.info = entity.getCommandSenderName();
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (entity instanceof EntityPlayer) {
|
|
|
|
this.info = "§1" + this.info;
|
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
|
|
|
if (!(entity instanceof EMissile)
|
|
|
|
|| ((EMissile) entity).target == null) {
|
2022-11-09 22:15:45 +01:00
|
|
|
continue;
|
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
|
|
|
this.info2 = "(" + ((EMissile) entity).target.intX() + ", "
|
|
|
|
+ ((EMissile) entity).target.intZ() + ")";
|
2022-11-09 22:15:45 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
range = 2;
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-11 23:10:52 +01:00
|
|
|
for (final TileEntity jiQi : this.tileEntity.tileEntitiesInRange) {
|
2022-11-09 22:15:45 +01:00
|
|
|
final Vector2 position = new Vector2(
|
2022-11-09 22:16:55 +01:00
|
|
|
this.radarCenter.x
|
|
|
|
+ (jiQi.xCoord - this.tileEntity.xCoord) / this.radarMapRadius,
|
|
|
|
this.radarCenter.y
|
|
|
|
- (jiQi.zCoord - this.tileEntity.zCoord) / this.radarMapRadius
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
this.mc.renderEngine.bindTexture(
|
2022-11-09 22:16:55 +01:00
|
|
|
new ResourceLocation("icbm", "textures/gui/whitedot.png")
|
|
|
|
);
|
|
|
|
this.drawTexturedModalRect(position.intX(), position.intY(), 0, 0, 2, 2);
|
2022-11-09 22:15:45 +01:00
|
|
|
final Vector2 minPosition = position.clone();
|
|
|
|
minPosition.add(-range);
|
|
|
|
final Vector2 maxPosition = position.clone();
|
|
|
|
maxPosition.add(range);
|
2022-11-09 22:16:55 +01:00
|
|
|
|
|
|
|
if (new Region2(minPosition, maxPosition).isIn(this.mousePosition)
|
|
|
|
&& jiQi.getBlockType() != null) {
|
2022-11-09 22:15:45 +01:00
|
|
|
if (jiQi.getBlockType() instanceof BMachine) {
|
|
|
|
this.info = BMachine.getMachineName(jiQi);
|
|
|
|
} else {
|
|
|
|
this.info = jiQi.getBlockType().getLocalizedName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateScreen() {
|
|
|
|
super.updateScreen();
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (Mouse.isInsideWindow() && Mouse.getEventButton() == -1) {
|
|
|
|
this.mousePosition = new Vector2(
|
2022-11-09 22:16:55 +01:00
|
|
|
Mouse.getEventX() * this.width / this.mc.displayWidth,
|
|
|
|
this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
final float difference = 500.0f / this.radarMapRadius;
|
2022-11-09 22:16:55 +01:00
|
|
|
|
|
|
|
if (this.mousePosition.x > this.radarCenter.x - difference
|
|
|
|
&& this.mousePosition
|
|
|
|
.x<this.radarCenter.x + difference&& this.mousePosition.y> this
|
|
|
|
.radarCenter.y
|
|
|
|
- difference
|
|
|
|
&& this.mousePosition.y < this.radarCenter.y + difference) {
|
2022-11-09 22:15:45 +01:00
|
|
|
final int xDifference = (int) (this.mousePosition.x - this.radarCenter.x);
|
|
|
|
final int yDifference = (int) (this.mousePosition.y - this.radarCenter.y);
|
|
|
|
final int xBlockDistance = (int) (xDifference * this.radarMapRadius);
|
|
|
|
final int yBlockDistance = (int) (yDifference * this.radarMapRadius);
|
2022-11-09 22:16:55 +01:00
|
|
|
this.mouseOverCoords = new Vector2(
|
|
|
|
this.tileEntity.xCoord + xBlockDistance,
|
|
|
|
this.tileEntity.zCoord - yBlockDistance
|
|
|
|
);
|
2022-11-09 22:15:45 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (!this.textFieldSafetyZone.isFocused()) {
|
|
|
|
this.textFieldSafetyZone.setText(this.tileEntity.safetyRadius + "");
|
|
|
|
}
|
2022-11-09 22:16:55 +01:00
|
|
|
|
2022-11-09 22:15:45 +01:00
|
|
|
if (!this.textFieldAlarmRange.isFocused()) {
|
|
|
|
this.textFieldAlarmRange.setText(this.tileEntity.alarmRadius + "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|