2017-04-10 16:20:39 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2017 malte0811
|
|
|
|
*
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 17:14:05 +02:00
|
|
|
package malte0811.industrialWires.controlpanel;
|
2017-03-28 18:15:41 +02:00
|
|
|
|
2017-04-22 18:14:49 +02:00
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
2017-04-13 17:14:05 +02:00
|
|
|
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
|
2017-03-28 18:15:41 +02:00
|
|
|
import malte0811.industrialWires.client.RawQuad;
|
2017-04-13 17:14:05 +02:00
|
|
|
import malte0811.industrialWires.client.gui.GuiPanelCreator;
|
2017-03-28 18:15:41 +02:00
|
|
|
import malte0811.industrialWires.client.panelmodel.RawModelFontRenderer;
|
|
|
|
import net.minecraft.client.Minecraft;
|
2017-04-23 17:23:10 +02:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2017-05-08 17:20:04 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.nbt.NBTBase;
|
2017-03-28 18:15:41 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.nbt.NBTTagString;
|
2017-03-28 18:15:41 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
2017-04-22 18:14:49 +02:00
|
|
|
import javax.annotation.Nullable;
|
2017-03-28 18:15:41 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2017-04-22 18:14:49 +02:00
|
|
|
public class Label extends PanelComponent implements IConfigurableComponent {
|
2017-03-28 18:15:41 +02:00
|
|
|
private static final ResourceLocation font = new ResourceLocation("minecraft", "textures/font/ascii.png");
|
2017-04-13 17:14:05 +02:00
|
|
|
String text = "Test";
|
2017-04-01 17:33:58 +02:00
|
|
|
RawModelFontRenderer renderer;
|
2017-04-13 17:14:05 +02:00
|
|
|
int color = 0x808080;
|
2017-03-28 18:15:41 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
public Label(String text, int color) {
|
2017-03-28 18:15:41 +02:00
|
|
|
this();
|
|
|
|
this.text = text;
|
2017-04-01 17:33:58 +02:00
|
|
|
this.color = color;
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-03-28 18:15:41 +02:00
|
|
|
public Label() {
|
|
|
|
super("label");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-09 16:59:57 +02:00
|
|
|
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
2017-04-13 17:14:05 +02:00
|
|
|
nbt.setString(TEXT, text);
|
|
|
|
nbt.setInteger(COLOR, color);
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void readCustomNBT(NBTTagCompound nbt) {
|
2017-04-13 17:14:05 +02:00
|
|
|
text = nbt.getString(TEXT);
|
|
|
|
color = nbt.getInteger(COLOR);
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<RawQuad> getQuads() {
|
|
|
|
RawModelFontRenderer render = fontRenderer();
|
2017-05-11 16:39:20 +02:00
|
|
|
render.drawString(text, 0, 0, 0xff000000 | color);
|
2017-03-28 18:15:41 +02:00
|
|
|
return render.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public Label copyOf() {
|
2017-04-01 17:33:58 +02:00
|
|
|
Label ret = new Label(text, color);
|
2017-03-28 18:15:41 +02:00
|
|
|
ret.setX(x);
|
|
|
|
ret.setY(y);
|
2017-04-01 17:33:58 +02:00
|
|
|
ret.panelHeight = panelHeight;
|
2017-03-28 18:15:41 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-12 15:55:37 +02:00
|
|
|
@Nonnull
|
2017-03-28 18:15:41 +02:00
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getBlockRelativeAABB() {
|
2017-04-12 15:55:37 +02:00
|
|
|
if (aabb == null) {
|
|
|
|
RawModelFontRenderer fr = fontRenderer();
|
|
|
|
float width = fr.getStringWidth(text) * fr.scale;
|
|
|
|
float height = fr.FONT_HEIGHT * fr.scale;
|
|
|
|
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + width, 0, getY() + height);
|
|
|
|
}
|
|
|
|
return aabb;
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(TileEntityPanel tile) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-27 18:15:11 +02:00
|
|
|
@Override
|
|
|
|
public int getColor() {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2017-04-04 17:07:45 +02:00
|
|
|
@Override
|
|
|
|
public float getHeight() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-28 18:15:41 +02:00
|
|
|
private RawModelFontRenderer fontRenderer() {
|
2017-05-11 16:39:20 +02:00
|
|
|
if (renderer == null) {
|
2017-04-01 17:33:58 +02:00
|
|
|
renderer = new RawModelFontRenderer(Minecraft.getMinecraft().gameSettings, font, Minecraft.getMinecraft().getTextureManager(),
|
2017-05-11 16:39:20 +02:00
|
|
|
false, 1);
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
return renderer;
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 17:14:05 +02:00
|
|
|
@Override
|
|
|
|
public void renderInGUI(GuiPanelCreator gui) {
|
2017-05-11 16:39:20 +02:00
|
|
|
int left = (int) (gui.getX0() + getX() * gui.panelSize);
|
|
|
|
int top = (int) (gui.getY0() + getY() * gui.panelSize);
|
2017-04-23 17:23:10 +02:00
|
|
|
GlStateManager.pushMatrix();
|
2017-05-10 17:56:05 +02:00
|
|
|
float scale = gui.mc.fontRenderer.FONT_HEIGHT * gui.panelSize / (16F * 9F * 9F);
|
2017-04-23 17:23:10 +02:00
|
|
|
GlStateManager.translate(left, top, 0);
|
|
|
|
GlStateManager.scale(scale, scale, scale);
|
2017-05-10 17:56:05 +02:00
|
|
|
gui.mc.fontRenderer.drawString(text, 0, 0, 0xff000000 | color);
|
2017-04-23 17:23:10 +02:00
|
|
|
GlStateManager.popMatrix();
|
2017-04-13 17:14:05 +02:00
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
|
|
|
|
switch (type) {
|
|
|
|
case STRING:
|
2017-05-11 16:39:20 +02:00
|
|
|
text = ((NBTTagString) value).getString();
|
2017-04-22 18:14:49 +02:00
|
|
|
break;
|
|
|
|
case FLOAT:
|
|
|
|
color = PanelUtils.setColor(color, id, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public String fomatConfigName(ConfigType type, int id) {
|
|
|
|
switch (type) {
|
|
|
|
case FLOAT:
|
2017-05-11 16:39:20 +02:00
|
|
|
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
|
2017-04-22 18:14:49 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public String fomatConfigDescription(ConfigType type, int id) {
|
|
|
|
switch (type) {
|
|
|
|
case STRING:
|
2017-05-11 16:39:20 +02:00
|
|
|
return I18n.format(IndustrialWires.MODID + ".desc.label_text");
|
2017-04-22 18:14:49 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StringConfig[] getStringOptions() {
|
|
|
|
return new StringConfig[]{
|
|
|
|
new StringConfig("text", 0, 0, text)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FloatConfig[] getFloatOptions() {
|
|
|
|
float[] color = PanelUtils.getFloatColor(true, this.color);
|
|
|
|
return new FloatConfig[]{
|
2017-05-01 18:40:29 +02:00
|
|
|
new FloatConfig("red", 0, 30, color[0], 60),
|
|
|
|
new FloatConfig("green", 0, 50, color[1], 60),
|
|
|
|
new FloatConfig("blue", 0, 70, color[2], 60)
|
2017-04-22 18:14:49 +02:00
|
|
|
};
|
|
|
|
}
|
2017-03-28 18:15:41 +02:00
|
|
|
}
|