split char gui
This commit is contained in:
parent
1b9ef61599
commit
5e20c6f90d
10 changed files with 105 additions and 29 deletions
697
java/src/game/gui/character/GuiChar.java
Executable file
697
java/src/game/gui/character/GuiChar.java
Executable file
|
@ -0,0 +1,697 @@
|
|||
package game.gui.character;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import game.Game;
|
||||
import game.Game.FileMode;
|
||||
import game.dimension.DimType;
|
||||
import game.dimension.Dimension;
|
||||
import game.entity.npc.Alignment;
|
||||
import game.entity.npc.CharacterInfo;
|
||||
import game.entity.npc.EntityHuman;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.npc.SpeciesInfo;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
import game.gui.element.Element;
|
||||
import game.gui.element.GuiList;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.ListEntry;
|
||||
import game.gui.element.NavButton;
|
||||
import game.gui.element.Slider;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.TransparentBox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.init.EntityEggInfo;
|
||||
import game.init.EntityRegistry;
|
||||
import game.init.SpeciesRegistry;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.init.SpeciesRegistry.ModelType;
|
||||
import game.log.Log;
|
||||
import game.network.Player;
|
||||
import game.packet.CPacketAction;
|
||||
import game.packet.CPacketMessage;
|
||||
import game.packet.CPacketSkin;
|
||||
import game.renderer.Drawing;
|
||||
import game.renderer.GlState;
|
||||
import game.renderer.ItemRenderer;
|
||||
import game.renderer.entity.RenderManager;
|
||||
import game.renderer.texture.EntityTexManager;
|
||||
import game.renderer.texture.TextureUtil;
|
||||
import game.rng.Random;
|
||||
import game.util.FileCallback;
|
||||
import game.util.FileUtils;
|
||||
import game.util.SkinConverter;
|
||||
import game.util.Util;
|
||||
import game.window.Button;
|
||||
|
||||
public class GuiChar extends GuiList<GuiChar.SkinEntry>
|
||||
{
|
||||
protected class SkinEntry implements ListEntry
|
||||
{
|
||||
private final File skinFile;
|
||||
private final String id;
|
||||
private final ModelType model;
|
||||
private final CharacterInfo charinfo;
|
||||
private final BufferedImage skinImage;
|
||||
// private final String icon;
|
||||
// private DynamicTexture dyntex;
|
||||
private final int dynId;
|
||||
|
||||
protected SkinEntry(String id, File file, CharacterInfo charinfo, BufferedImage image, ModelType model)
|
||||
{
|
||||
// this.owner = parent;
|
||||
this.skinFile = file;
|
||||
this.charinfo = charinfo;
|
||||
this.id = id;
|
||||
this.model = model;
|
||||
// this.gm = Game.getGame();
|
||||
if(this.skinFile != null) // {
|
||||
this.skinImage = image;
|
||||
// this.skin = skin.getName().substring(0, skin.getName().length() - 4);
|
||||
// }
|
||||
else // {
|
||||
this.skinImage = null;
|
||||
// this.skin = null;
|
||||
// }
|
||||
if(this.skinImage != null) {
|
||||
int w = this.skinImage.getWidth();
|
||||
int h = this.skinImage.getHeight();
|
||||
int[] data = new int[w * h];
|
||||
this.skinImage.getRGB(0, 0, w, h, data, 0, w);
|
||||
this.dynId = 0xffff0000 + GuiChar.this.elements.size();
|
||||
EntityTexManager.setTexture(this.dynId, EntityTexManager.imageToComp(data, model), model);
|
||||
}
|
||||
else {
|
||||
this.dynId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
|
||||
{
|
||||
// FontRenderer.drawString(this.skin == null ? "---" : this.skin, x + 32 + 3, y + 1, 16777215);
|
||||
String str = // List<String> list = FontRenderer.listFormattedStringToWidth(
|
||||
(this.skinFile != null ? this.skinFile.getName()
|
||||
: (this.charinfo == null ? "Standard" : (
|
||||
(this.charinfo.species.prefix && this.charinfo.spclass != null && this.charinfo.spclass.type != null ?
|
||||
this.charinfo.spclass.type.toString() :
|
||||
EntityRegistry.getEntityName(this.charinfo.species.id))
|
||||
+ (this.charinfo.name.isEmpty() ? "" : (" " + this.charinfo.name)))));
|
||||
// + TextColor.LIGHT_GRAY + " (" + TextColor.GREEN +
|
||||
// this.model.display + TextColor.LIGHT_GRAY +")"
|
||||
// , listWidth - 16 - 2);
|
||||
//
|
||||
// for (int i = 0; i < Math.min(list.size(), 2); ++i)
|
||||
// {
|
||||
Drawing.drawText(str, x + 64 + 3, y, 0xff000000 | (this.charinfo == null ?
|
||||
(this.skinFile != null ? 0xffffff : 0xc0c0c0) : this.charinfo.color1 | this.charinfo.color2));
|
||||
if(this.skinFile == null && this.charinfo != null)
|
||||
Drawing.drawText(this.charinfo.skin, x + 64 + 3, y + 18, 0xffc0c0c0);
|
||||
// }
|
||||
|
||||
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
// if(this.model != ModelType.HUMANOID) {
|
||||
// this.drawTextureAt(x, y, EntitySkinManager.HEAD_DEF);
|
||||
// }
|
||||
|
||||
if (/* this.gm.touchscreen || */ hovered)
|
||||
{
|
||||
// GuiSkin.this.gm.getTextureManager().bindTexture(SKINS_BUTTONS);
|
||||
Drawing.drawRect(x, y, 64, 64, -1601138544);
|
||||
// GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
// int k1 = mouseX - x;
|
||||
// int l1 = mouseY - y;
|
||||
//
|
||||
// if (k1 < 16 && k1 > 0)
|
||||
// {
|
||||
// Gui.drawScaledCustomSizeModalRect(x, y, 0.0F, 32.0F, 32, 32, 16, 16, 256.0F, 256.0F);
|
||||
// }
|
||||
}
|
||||
|
||||
if (this.dynId != -1)
|
||||
{
|
||||
this.drawTextureAt(x, y, EntityTexManager.getSkin(this.dynId, this.model));
|
||||
}
|
||||
else if(this.charinfo == null)
|
||||
{
|
||||
this.drawTextureAt(x, y, EntityTexManager.getDefault(this.model));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.drawTextureAt(x, y, EntityTexManager.getNpcSkin(this.charinfo.skin, this.model));
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawTextureAt(int x, int y, String tex)
|
||||
{
|
||||
// GuiSkin.this.gm.getTextureManager().bindTexture(tex);
|
||||
GlState.enableBlend();
|
||||
GlState.enableDepth();
|
||||
boolean flag = GuiChar.this.gm.cameraUsed;
|
||||
GuiChar.this.gm.cameraUsed = true;
|
||||
EntityTexManager.altTexture = tex;
|
||||
EntityTexManager.altLayer = this.dynId;
|
||||
EntityTexManager.altNpcLayer = this.dynId == -1 && this.charinfo != null ? this.charinfo.skin : null;
|
||||
drawEntity(x + 32, y + 60, 28.0f
|
||||
/* / GuiChar.this.gm.thePlayer.getHeight() */ * Math.min(1.8f / GuiChar.this.gm.thePlayer.height, 1.5f / GuiChar.this.gm.thePlayer.width), -45.0f, -20.0f, GuiChar.this.gm.thePlayer);
|
||||
GuiChar.this.gm.cameraUsed = flag;
|
||||
EntityTexManager.altTexture = null;
|
||||
EntityTexManager.altLayer = -1;
|
||||
EntityTexManager.altNpcLayer = null;
|
||||
// GuiSkin.this.gm.getRenderManager().getRenderObject(this.model).renderHead(x, y, this.model.texWidth, this.model.texHeight, 2);
|
||||
GlState.disableBlend();
|
||||
GlState.disableDepth();
|
||||
}
|
||||
|
||||
public void deleteTexture() {
|
||||
if(this.dynId != -1) {
|
||||
EntityTexManager.setTexture(this.dynId, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void select(boolean dclick, int mx, int my)
|
||||
{
|
||||
// if(GuiSkin.this.adjust.dragging)
|
||||
// return;
|
||||
// if (dclick)
|
||||
// {
|
||||
// GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
BufferedImage img = this.skinImage;
|
||||
// boolean slim = false;
|
||||
if(this.charinfo != null) {
|
||||
try {
|
||||
img = TextureUtil.readImage(FileUtils.getResource(
|
||||
EntityNPC.getSkinTexture(this.charinfo.skin)));
|
||||
}
|
||||
catch(IOException e) {
|
||||
if(e instanceof FileNotFoundException)
|
||||
Log.JNI.warn("Textur für Skin ist nicht vorhanden: " +
|
||||
EntityNPC.getSkinTexture(this.charinfo.skin));
|
||||
else
|
||||
Log.JNI.error(e, "Konnte Textur nicht laden");
|
||||
return;
|
||||
}
|
||||
// slim = this.charinfo.skin.startsWith("~");
|
||||
}
|
||||
// else if(this.skinFile != null) {
|
||||
// slim = this.skinFile.getName().startsWith("slim_");
|
||||
// }
|
||||
// GuiSkin.this.selectEntry(slotIndex, slim);
|
||||
// GuiChar.this.convertButton1.enabled = this.canConvert();
|
||||
// GuiChar.this.convertButton2.enabled = this.canConvert();
|
||||
GuiChar.this.templateButton.enabled = this.canCopy();
|
||||
GuiChar.this.selectSkin(img, this.model);
|
||||
// if(mx < 16 && mx > 0)
|
||||
// GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
public File getFile()
|
||||
{
|
||||
return this.skinFile;
|
||||
}
|
||||
|
||||
// public boolean canConvert()
|
||||
// {
|
||||
// return this.skinFile != null && this.model == ModelType.HUMANOID;
|
||||
// }
|
||||
|
||||
public String getLocation()
|
||||
{
|
||||
return this.charinfo == null ? null : this.charinfo.skin;
|
||||
}
|
||||
|
||||
public boolean canCopy()
|
||||
{
|
||||
return this.charinfo != null;
|
||||
}
|
||||
}
|
||||
|
||||
private class DragAdjust extends Element {
|
||||
private int mouseX;
|
||||
private int mouseY;
|
||||
private float yawOffset;
|
||||
private float pitchOffset;
|
||||
// public boolean dragging;
|
||||
|
||||
public DragAdjust(int x, int y, int w, int h) {
|
||||
super(x, y, w, h, null);
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
// if(this.dragging) {
|
||||
//
|
||||
// }
|
||||
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x20ffffff);
|
||||
}
|
||||
|
||||
protected void drawForeground(int x1, int y1, int x2, int y2) {
|
||||
}
|
||||
|
||||
public void drag(int x, int y) {
|
||||
GuiChar.this.yaw = this.yawOffset + (this.mouseX - x) * 2.0f;
|
||||
GuiChar.this.pitch = this.pitchOffset + (this.mouseY - y) * 2.0f;
|
||||
}
|
||||
|
||||
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
|
||||
this.mouseX = x;
|
||||
this.mouseY = y;
|
||||
this.yawOffset = GuiChar.this.yaw;
|
||||
this.pitchOffset = GuiChar.this.pitch;
|
||||
// this.dragging = true;
|
||||
}
|
||||
|
||||
// public void mouserel() {
|
||||
// this.dragging = false;
|
||||
// }
|
||||
|
||||
public boolean canHover() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final GuiChar INSTANCE = new GuiChar();
|
||||
|
||||
// private ActButton convertButton1;
|
||||
// private ActButton convertButton2;
|
||||
private ActButton templateButton;
|
||||
private DragAdjust adjust;
|
||||
private ActButton dimButton;
|
||||
private TransparentBox descLines;
|
||||
private float yaw = -15.0f;
|
||||
private float pitch = -15.0f;
|
||||
private boolean waiting = true;
|
||||
private int dimension;
|
||||
|
||||
private GuiChar() {
|
||||
}
|
||||
|
||||
public void init(int width, int height)
|
||||
{
|
||||
super.init(width, height);
|
||||
this.waiting = true;
|
||||
this.setDimensions(400, height, 32, height - 32);
|
||||
if(this.gm.getRenderManager().gm == null) {
|
||||
this.unload();
|
||||
this.adjust = null;
|
||||
return;
|
||||
}
|
||||
this.load(null, this.gm.thePlayer == null ? ModelType.HUMANOID : this.gm.thePlayer.getModel());
|
||||
this.add(new ActButton(4, 4, 194, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren", new File("skins"), new FileCallback() {
|
||||
public void selected(File file) {
|
||||
if(SkinConverter.convertSkin(file, new File("skins"), false))
|
||||
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "Importieren: Standard"));
|
||||
this.add(new ActButton(202, 4, 194, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
GuiChar.this.gm.showFileDialog(FileMode.FILE_LOAD_MULTI, "Skin konvertieren (schlank)", new File("skins"), new FileCallback() {
|
||||
public void selected(File file) {
|
||||
if(SkinConverter.convertSkin(file, new File("skins"), true))
|
||||
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "Importieren: Schlank"));
|
||||
this.add(new ActButton(4, height - 28, 194, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
|
||||
}
|
||||
}, "Neu laden"));
|
||||
this.templateButton = this.add(new ActButton(202, height - 28, 194, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
SkinEntry skin = GuiChar.this.getSelected();
|
||||
if(skin != null && skin.getLocation() != null) {
|
||||
String loc = skin.getLocation();
|
||||
File file = new File(new File("skins"), loc + ".png");
|
||||
int z = 1;
|
||||
while(file.exists()) {
|
||||
file = new File(new File("skins"), loc + "_" + (++z) + ".png");
|
||||
}
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = FileUtils.getResource(EntityNPC.getSkinTexture(loc));
|
||||
Files.copy(in, file.toPath());
|
||||
}
|
||||
catch(Exception e) {
|
||||
if(e instanceof FileNotFoundException)
|
||||
Log.JNI.warn("Textur ist nicht zum Kopieren vorhanden: " + EntityNPC.getSkinTexture(loc));
|
||||
else
|
||||
Log.JNI.error(e, "Konnte Textur nicht kopieren");
|
||||
}
|
||||
finally {
|
||||
if(in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch(Throwable e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
GuiChar.this.gm.displayGuiScreen(GuiChar.this);
|
||||
}
|
||||
}
|
||||
}, "Vorlage kopieren"));
|
||||
this.adjust = this.add(new DragAdjust(width / 2 - 230, height - 64 - 640, 460, 640));
|
||||
|
||||
this.add(new NavButton(width - 396, 36, 392, 24, GuiSpecies.INSTANCE, "Spezies ändern"));
|
||||
// for(int z = 0; z < SpeciesRegistry.SPECIMEN.size(); z++) {
|
||||
// final SpeciesInfo species = SpeciesRegistry.SPECIMEN.get(z);
|
||||
// this.add(new ActButton(width - 396 + (z % 2) * 198, 36 + 28 * (z / 2), 194, 24, new ActButton.Callback() {
|
||||
// }, EntityRegistry.getEntityName(EntityRegistry.getEntityString(species.clazz)))) // ;
|
||||
// .enabled = this.gm.thePlayer == null || this.gm.thePlayer.getClass() != species.clazz;
|
||||
// }
|
||||
|
||||
final ActButton[] alignBtns = new ActButton[Alignment.values().length];
|
||||
for (int z = 0; z < Alignment.values().length; z++)
|
||||
{
|
||||
final Alignment align = Alignment.values()[z];
|
||||
alignBtns[z] = this.add(new ActButton(width - 396 + (z % 3) * 132, height - 32 - 28 * 3 + 28 * (z / 3), 128, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiChar.this.gm.thePlayer != null) {
|
||||
GuiChar.this.waiting = false;
|
||||
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal()));
|
||||
for(ActButton btn : alignBtns) {
|
||||
btn.enabled = btn != elem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, align.color + align.display));
|
||||
alignBtns[z].enabled = this.gm.thePlayer == null || this.gm.thePlayer.getAlignment() != align;
|
||||
}
|
||||
this.add(new Slider(width / 2 - 200, height - 28, 400, 24, 1, this.gm.thePlayer == null ? 120 : this.gm.thePlayer.getMinSize(), this.gm.thePlayer == null ? 320 : this.gm.thePlayer.getMaxSize(), this.gm.thePlayer == null ? 180 : this.gm.thePlayer.getDefaultSize(), this.gm.thePlayer == null ? 180 : this.gm.thePlayer.getCurrentSize(), new Slider.Callback() {
|
||||
public void use(Slider elem, int value) {
|
||||
if(GuiChar.this.gm.thePlayer != null) {
|
||||
GuiChar.this.waiting = false;
|
||||
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_HEIGHT, value));
|
||||
}
|
||||
}
|
||||
}, "Spieler-Größe", "cm")).enabled = this.gm.thePlayer == null || this.gm.thePlayer.getMinSize() != this.gm.thePlayer.getMaxSize();
|
||||
this.add(new Label(width / 2 - 200, 36, 400, 20, "Name", true));
|
||||
this.add(new Label(width - 396, height - 384, 392, 20, "Beschreibung", true));
|
||||
final Textbox descField = this.add(new Textbox(width - 396, height - 364, 392, 130, Player.MAX_INFO_LENGTH, new Textbox.Callback() {
|
||||
public void use(Textbox elem, Action value) {
|
||||
}
|
||||
}, ""));
|
||||
this.add(new ActButton(width - 198, height - 28, 194, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiChar.this.gm.thePlayer != null) {
|
||||
GuiChar.this.gm.waitForServer();
|
||||
Dimension dim = // GuiChar.this.dimension == Integer.MAX_VALUE ? Space.INSTANCE :
|
||||
UniverseRegistry.getBaseDimensions().get(GuiChar.this.dimension);
|
||||
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.INFO, descField.getText()));
|
||||
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR, dim.getDimensionId()));
|
||||
}
|
||||
}
|
||||
}, "Charakter erstellen"));
|
||||
this.add(new Textbox(width / 2 - 200, 36 + 20, 400, 24, Player.MAX_NICK_LENGTH, true, new Textbox.Callback() {
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.SEND || value == Action.UNFOCUS) {
|
||||
String name = elem.getText();
|
||||
if(name.isEmpty())
|
||||
elem.setText(GuiChar.this.gm.thePlayer == null ? "..." : GuiChar.this.gm.thePlayer.getCustomNameTag());
|
||||
else if(GuiChar.this.gm.thePlayer != null) {
|
||||
GuiChar.this.waiting = false;
|
||||
GuiChar.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.DISPLAY, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Player.VALID_NICK, this.gm.thePlayer == null ? "" : this.gm.thePlayer.getCustomNameTag()));
|
||||
// this.convertButton1.enabled = false;
|
||||
// this.convertButton2.enabled = false;
|
||||
this.templateButton.enabled = false;
|
||||
this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size());
|
||||
EntityEggInfo egg = EntityRegistry.SPAWN_EGGS.get(this.gm.thePlayer == null ? EntityRegistry.getEntityString(EntityHuman.class) : EntityRegistry.getEntityString(this.gm.thePlayer));
|
||||
if(egg != null && egg.origin != null) {
|
||||
Dimension dim = UniverseRegistry.getDimension(egg.origin);
|
||||
if(dim != null) {
|
||||
for(int z = 0; z < UniverseRegistry.getBaseDimensions().size(); z++) {
|
||||
if(UniverseRegistry.getBaseDimensions().get(z).getDimensionId() == dim.getDimensionId()) {
|
||||
this.dimension = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.dimButton = this.add(new ActButton(width - 396, height - 220, 392, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode mode) {
|
||||
if(mode == Mode.TERTIARY) {
|
||||
GuiChar.this.dimension = new Random().zrange(UniverseRegistry.getBaseDimensions().size());
|
||||
}
|
||||
// else if(GuiChar.this.dimension == Integer.MAX_VALUE) {
|
||||
// GuiChar.this.dimension = mode == Mode.SECONDARY ? UniverseRegistry.getBaseDimensions().size() - 1 : 0;
|
||||
// }
|
||||
// else {
|
||||
if(mode == Mode.SECONDARY) {
|
||||
if(--GuiChar.this.dimension < 0)
|
||||
GuiChar.this.dimension = UniverseRegistry.getBaseDimensions().size() - 1;
|
||||
}
|
||||
else {
|
||||
if(++GuiChar.this.dimension >= UniverseRegistry.getBaseDimensions().size())
|
||||
GuiChar.this.dimension = 0;
|
||||
}
|
||||
// }
|
||||
GuiChar.this.setDimButton();
|
||||
}
|
||||
}, ""));
|
||||
this.descLines = this.add(new TransparentBox(width - 396, height - 220 + 24, 392, 66, "", false));
|
||||
this.setDimButton();
|
||||
}
|
||||
|
||||
public void selectSkin(BufferedImage img, ModelType model)
|
||||
{
|
||||
this.gm.getNetHandler().addToSendQueue(new CPacketSkin(img, model));
|
||||
}
|
||||
|
||||
private void setDimButton() {
|
||||
Dimension dim = /* this.dimension == Integer.MAX_VALUE ? Space.INSTANCE : */ UniverseRegistry.getBaseDimensions().get(this.dimension);
|
||||
this.dimButton.setText( // (dim == Space.INSTANCE ? "" :
|
||||
// ((dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ?
|
||||
/* "Vorlage" : */ (dim.getType() == DimType.PLANET ? "Heimplanet" : "Heimdimension") + ": " +
|
||||
// (dim.getDimensionId() >= UniverseRegistry.MORE_DIM_ID ? dim.getCustomName() :
|
||||
dim.getFormattedName(false));
|
||||
String name = dim.getFormattedName(true);
|
||||
int index = name.indexOf(" / ");
|
||||
this.descLines.setText(index >= 0 ? Util.buildLines(name.substring(index + " / ".length()).split(" / ")) : "");
|
||||
}
|
||||
|
||||
public void onGuiClosed()
|
||||
{
|
||||
this.unload();
|
||||
}
|
||||
|
||||
public void drawOverlays()
|
||||
{
|
||||
if(this.adjust != null) {
|
||||
float factor = this.gm.thePlayer.width > 2.15f ? 2.15f / this.gm.thePlayer.width : 1.0f;
|
||||
factor = this.gm.thePlayer.height > 3.0f && 3.0f / this.gm.thePlayer.height < factor ? 3.0f / this.gm.thePlayer.height : factor;
|
||||
drawEntity(400 + (this.gm.fb_x - 400 - 400) / 2, this.gm.fb_y - 160, 160.0f * factor
|
||||
/* / this.gm.thePlayer.getHeight() */, this.yaw, this.pitch, this.gm.thePlayer);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
if(this.adjust == null && this.gm.getRenderManager().gm != null)
|
||||
this.gm.displayGuiScreen(this);
|
||||
}
|
||||
|
||||
public void checkReopen() {
|
||||
if(this.adjust != null && this.waiting) {
|
||||
this.waiting = false;
|
||||
this.gm.displayGuiScreen(this);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Charakter anpassen";
|
||||
}
|
||||
|
||||
public static BufferedImage loadSkin(File file)
|
||||
{
|
||||
BufferedImage img = null;
|
||||
try {
|
||||
img = ImageIO.read(file);
|
||||
}
|
||||
catch(IOException e) {
|
||||
return null;
|
||||
}
|
||||
if(img == null) {
|
||||
return null;
|
||||
}
|
||||
// if(img.getWidth() != 64 || img.getHeight() != 64) { // || img.getType() != BufferedImage.TYPE_INT_ARGB) {
|
||||
// return null;
|
||||
// }
|
||||
return img;
|
||||
}
|
||||
|
||||
public void load(String currentSkin, ModelType model)
|
||||
{
|
||||
this.unload();
|
||||
File[] files = new File("skins").listFiles(new FileFilter() {
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.isFile() && pathname.getName().endsWith(".png");
|
||||
}
|
||||
});
|
||||
int pos = 0;
|
||||
// for(ModelType model : ModelType.values()) {
|
||||
this.elements.add(new SkinEntry("default", null, null, null, model));
|
||||
if("default".equals(currentSkin))
|
||||
this.setSelected(pos);
|
||||
pos++;
|
||||
// }
|
||||
if(files != null) {
|
||||
Arrays.sort(files);
|
||||
for(File file : files)
|
||||
{
|
||||
BufferedImage img = loadSkin(file);
|
||||
if(img != null) {
|
||||
// for(ModelType model : ModelType.values()) {
|
||||
if(img.getWidth() == model.texWidth && img.getHeight() == model.texHeight) {
|
||||
this.elements.add(new SkinEntry(file.getName(), file, null, img, model));
|
||||
if(file.getName().equals(currentSkin))
|
||||
this.setSelected(pos);
|
||||
pos++;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) {
|
||||
for(CharacterInfo charinfo : species.chars) {
|
||||
if(charinfo.species.renderer == model) {
|
||||
// for(Entry<String, ModelType> entry : SpeciesRegistry.SKINS.entrySet()) {
|
||||
this.elements.add(new SkinEntry(charinfo.skin, null, charinfo, null, charinfo.species.renderer));
|
||||
if(charinfo.skin.equals(currentSkin))
|
||||
this.setSelected(pos);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unload()
|
||||
{
|
||||
for (SkinEntry entry : this.elements)
|
||||
{
|
||||
entry.deleteTexture();
|
||||
}
|
||||
|
||||
this.elements.clear();
|
||||
}
|
||||
|
||||
public int getListWidth()
|
||||
{
|
||||
return 400 - 20;
|
||||
}
|
||||
|
||||
public int getSlotHeight()
|
||||
{
|
||||
return 64 + 4;
|
||||
}
|
||||
|
||||
|
||||
// public static void drawEntityOnScreen(int posX, int posY, float scale, float mouseX, float mouseY, EntityLiving ent)
|
||||
// {
|
||||
// GlState.enableColorMaterial();
|
||||
// SKC.glPushMatrix();
|
||||
// SKC.glTranslatef((float)posX, (float)posY, 50.0F);
|
||||
// SKC.glScalef(-scale, scale, scale);
|
||||
// SKC.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
|
||||
// float f = ent.yawOffset;
|
||||
// float f1 = ent.rotYaw;
|
||||
// float f2 = ent.rotPitch;
|
||||
// float f3 = ent.prevHeadYaw;
|
||||
// float f4 = ent.headYaw;
|
||||
// SKC.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
|
||||
// ItemRenderer.enableStandardItemLighting();
|
||||
// SKC.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
|
||||
// SKC.glRotatef(-((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
|
||||
// ent.yawOffset = (float)Math.atan((double)(mouseX / 40.0F)) * 20.0F;
|
||||
// ent.rotYaw = (float)Math.atan((double)(mouseX / 40.0F)) * 40.0F;
|
||||
// ent.rotPitch = -((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F;
|
||||
// ent.headYaw = ent.rotYaw;
|
||||
// ent.prevHeadYaw = ent.rotYaw;
|
||||
// SKC.glTranslatef(0.0F, 0.0F, 0.0F);
|
||||
// RenderManager rendermanager = Game.getGame().getRenderManager();
|
||||
// rendermanager.setPlayerViewY(180.0F);
|
||||
//// rendermanager.setRenderShadow(false);
|
||||
// rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 1.0F);
|
||||
//// rendermanager.setRenderShadow(true);
|
||||
// ent.yawOffset = f;
|
||||
// ent.rotYaw = f1;
|
||||
// ent.rotPitch = f2;
|
||||
// ent.prevHeadYaw = f3;
|
||||
// ent.headYaw = f4;
|
||||
// SKC.glPopMatrix();
|
||||
// ItemRenderer.disableStandardItemLighting();
|
||||
// GlState.disableRescaleNormal();
|
||||
// GlState.setActiveTexture(SKC.GL_TEXTURE1);
|
||||
// GlState.disableTexture2D();
|
||||
// GlState.setActiveTexture(SKC.GL_TEXTURE0);
|
||||
// }
|
||||
|
||||
public static void drawEntity(int posX, int posY, float scale, float yaw, float pitch, EntityLiving ent)
|
||||
{
|
||||
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlState.enableDepth();
|
||||
GlState.enableColorMaterial();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float)posX, (float)posY, 200.0F);
|
||||
GL11.glScalef(-scale, scale, scale);
|
||||
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
|
||||
float f = ent.yawOffset;
|
||||
float f1 = ent.rotYaw;
|
||||
float f2 = ent.rotPitch;
|
||||
float f3 = ent.prevHeadYaw;
|
||||
float f4 = ent.headYaw;
|
||||
GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
|
||||
ItemRenderer.enableStandardItemLighting();
|
||||
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glTranslatef(0.0F, ent.height / 2, 0.0F);
|
||||
GL11.glRotatef(-pitch, 1.0F, 0.0F, 0.0F);
|
||||
ent.yawOffset = yaw;
|
||||
ent.rotYaw = yaw;
|
||||
ent.rotPitch = 0.0f;
|
||||
ent.headYaw = ent.rotYaw;
|
||||
ent.prevHeadYaw = ent.rotYaw;
|
||||
GL11.glTranslatef(0.0F, -(ent.height / 2), 0.0F);
|
||||
RenderManager rendermanager = Game.getGame().getRenderManager();
|
||||
rendermanager.setPlayerViewY(180.0F);
|
||||
rendermanager.renderEntity(ent, 0.0D, 0.0D, 0.0D, 1.0F);
|
||||
// GL11.glTranslatef(0.0F, 0.0F, 0.0F);
|
||||
ent.yawOffset = f;
|
||||
ent.rotYaw = f1;
|
||||
ent.rotPitch = f2;
|
||||
ent.prevHeadYaw = f3;
|
||||
ent.headYaw = f4;
|
||||
GL11.glPopMatrix();
|
||||
ItemRenderer.disableStandardItemLighting();
|
||||
GlState.disableRescaleNormal();
|
||||
GlState.setActiveTexture(GL13.GL_TEXTURE1);
|
||||
GlState.disableTexture2D();
|
||||
GlState.setActiveTexture(GL13.GL_TEXTURE0);
|
||||
GlState.disableDepth();
|
||||
}
|
||||
}
|
||||
|
122
java/src/game/gui/character/GuiCharacters.java
Normal file
122
java/src/game/gui/character/GuiCharacters.java
Normal file
|
@ -0,0 +1,122 @@
|
|||
package game.gui.character;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.PlayerCharacter;
|
||||
import game.gui.GuiConfirm;
|
||||
import game.gui.GuiMenu;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
import game.gui.element.GuiList;
|
||||
import game.gui.element.ListEntry;
|
||||
import game.gui.element.NavButton;
|
||||
import game.gui.element.TransparentBox;
|
||||
import game.packet.CPacketAction;
|
||||
import game.renderer.Drawing;
|
||||
|
||||
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ActButton.Callback
|
||||
{
|
||||
protected class CharacterEntry implements ListEntry
|
||||
{
|
||||
private final PlayerCharacter character;
|
||||
private final boolean initial;
|
||||
|
||||
protected CharacterEntry(PlayerCharacter character, boolean initial)
|
||||
{
|
||||
this.character = character;
|
||||
this.initial = initial;
|
||||
}
|
||||
|
||||
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
|
||||
{
|
||||
if(this.initial)
|
||||
Drawing.drawRect(x, y, 1, 36, 0xffaf0000);
|
||||
String str = this.character == null ? TextColor.BLUE + "[" + TextColor.CYAN + "+" + TextColor.BLUE + "]" :
|
||||
String.format(TextColor.GREEN + "Level " + TextColor.DGREEN + "%d " + TextColor.YELLOW + "%s " + TextColor.VIOLET + "%s" + TextColor.GRAY + " [%s%s" + TextColor.GRAY + "]",
|
||||
character.level, character.type, character.name, character.align.color, character.align.display);
|
||||
String pos = this.character == null ? TextColor.BROWN + "Neuen Charakter erstellen" :
|
||||
String.format(TextColor.NEON + "%s " + TextColor.GRAY + "bei " + TextColor.ACID + "%d" + TextColor.GRAY + ", " + TextColor.ACID + "%d" + TextColor.GRAY + ", " + TextColor.ACID + "%d",
|
||||
character.dim, character.pos.getX(), character.pos.getY(), character.pos.getZ());
|
||||
Drawing.drawText(str, x + 3, y, 0xffffffff);
|
||||
Drawing.drawText(pos, x + 3, y + 16, 0xffffffff);
|
||||
}
|
||||
|
||||
public void select(boolean dclick, int mx, int my)
|
||||
{
|
||||
if(dclick)
|
||||
GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY);
|
||||
GuiCharacters.this.updateButtons();
|
||||
}
|
||||
}
|
||||
|
||||
public static final GuiCharacters INSTANCE = new GuiCharacters();
|
||||
|
||||
private TransparentBox descField;
|
||||
private ActButton actionButtom;
|
||||
private ActButton deleteButtom;
|
||||
|
||||
private GuiCharacters() {
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
CharacterEntry entry = this.getSelected();
|
||||
this.descField.setText(entry == null ? "" : (entry.character == null ? "*neuer Charakter*" : (entry.character.info == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info)));
|
||||
this.actionButtom.setText(entry != null && entry.character == null ? "Charakter erstellen" : "Charakter spielen");
|
||||
this.actionButtom.enabled = entry != null && !entry.initial;
|
||||
this.deleteButtom.enabled = entry != null && entry.character != null && !entry.initial;
|
||||
}
|
||||
|
||||
public void init(int width, int height)
|
||||
{
|
||||
super.init(width, height);
|
||||
this.setDimensions(600, height, 32, height - 32);
|
||||
this.elements.clear();
|
||||
if(this.gm.getNetHandler() != null) {
|
||||
int initialSelection = this.gm.getNetHandler().getSelectedCharacter();
|
||||
for(PlayerCharacter character : this.gm.getNetHandler().getCharacterList()) {
|
||||
this.elements.add(new CharacterEntry(initialSelection == this.elements.size() ? new PlayerCharacter(character.name, character.info, character.align, this.gm.thePlayer.worldObj.dimension.getFormattedName(false), this.gm.thePlayer.getPosition(), character.type, this.gm.thePlayer.experienceLevel) : character, initialSelection == this.elements.size()));
|
||||
}
|
||||
this.elements.add(new CharacterEntry(null, false));
|
||||
this.setSelected(initialSelection);
|
||||
}
|
||||
this.descField = this.add(new TransparentBox(width - 390, 62, 380, height - 124, "", false));
|
||||
this.deleteButtom = this.add(new ActButton(width / 2 - 304, height - 28, 200, 24, this, "Charakter löschen"));
|
||||
this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 28, 200, 24, this, ""));
|
||||
this.add(new NavButton(width / 2 + 104, height - 28, 200, 24, GuiMenu.INSTANCE, "Abbrechen"));
|
||||
this.updateButtons();
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Charakter anpassen";
|
||||
}
|
||||
|
||||
public int getListWidth()
|
||||
{
|
||||
return 560;
|
||||
}
|
||||
|
||||
public int getSlotHeight()
|
||||
{
|
||||
return 36 + 4;
|
||||
}
|
||||
|
||||
public void use(ActButton elem, Mode action) {
|
||||
CharacterEntry entry = GuiCharacters.this.getSelected();
|
||||
if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) {
|
||||
if(elem == this.actionButtom) {
|
||||
if(entry.character == null)
|
||||
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR));
|
||||
else
|
||||
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, this.selectedElement));
|
||||
}
|
||||
else if(elem == this.deleteButtom && entry.character != null) {
|
||||
this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() {
|
||||
public void confirm(boolean confirmed) {
|
||||
if(confirmed)
|
||||
GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.DELETE_CHARACTER, GuiCharacters.this.selectedElement));
|
||||
GuiCharacters.this.gm.displayGuiScreen(GuiCharacters.this);
|
||||
}
|
||||
}, "Möchtest du diesen Charakter wirklich löschen?", "Der Fortschritt, die Gegenstände und die Historie von \"" + entry.character.name + "\" werden für imer verloren sein!", "Löschen", "Abbrechen"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
java/src/game/gui/character/GuiSpecies.java
Normal file
77
java/src/game/gui/character/GuiSpecies.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package game.gui.character;
|
||||
|
||||
import game.entity.npc.SpeciesInfo;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.ActButton.Mode;
|
||||
import game.gui.element.GuiList;
|
||||
import game.gui.element.ListEntry;
|
||||
import game.gui.element.NavButton;
|
||||
import game.init.EntityRegistry;
|
||||
import game.init.SpeciesRegistry;
|
||||
import game.packet.CPacketAction;
|
||||
import game.renderer.Drawing;
|
||||
|
||||
public class GuiSpecies extends GuiList<GuiSpecies.SkinEntry> implements ActButton.Callback
|
||||
{
|
||||
protected class SkinEntry implements ListEntry
|
||||
{
|
||||
private final SpeciesInfo species;
|
||||
|
||||
protected SkinEntry(SpeciesInfo species)
|
||||
{
|
||||
this.species = species;
|
||||
}
|
||||
|
||||
public void draw(int x, int y, int mouseX, int mouseY, boolean hovered)
|
||||
{
|
||||
if(GuiSpecies.this.gm.thePlayer != null && this.species == GuiSpecies.this.gm.thePlayer.getSpecies())
|
||||
Drawing.drawRect(x, y, 1, 44, 0xffaf0000);
|
||||
Drawing.drawText(this.species.name, x + 3, y, 0xff000000 | this.species.color1 | this.species.color2);
|
||||
}
|
||||
|
||||
public void select(boolean dclick, int mx, int my)
|
||||
{
|
||||
if((GuiSpecies.this.selectButton.enabled = GuiSpecies.this.gm.thePlayer == null || this.species != GuiSpecies.this.gm.thePlayer.getSpecies()) && dclick)
|
||||
GuiSpecies.this.use(GuiSpecies.this.selectButton, Mode.PRIMARY);
|
||||
}
|
||||
}
|
||||
|
||||
public static final GuiSpecies INSTANCE = new GuiSpecies();
|
||||
|
||||
private ActButton selectButton;
|
||||
|
||||
private GuiSpecies() {
|
||||
}
|
||||
|
||||
public void init(int width, int height)
|
||||
{
|
||||
super.init(width, height);
|
||||
this.setDimensions(400, height, 32, height - 32);
|
||||
this.elements.clear();
|
||||
for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) {
|
||||
this.elements.add(new SkinEntry(species));
|
||||
}
|
||||
this.add(new NavButton(width - 198 * 2, height - 28, 194, 24, GuiChar.INSTANCE, "Zurück"));
|
||||
this.selectButton = this.add(new ActButton(width - 198, height - 28, 194, 24, this, "Spezies ändern"));
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return "Spezies wählen";
|
||||
}
|
||||
|
||||
public int getListWidth()
|
||||
{
|
||||
return 400 - 20;
|
||||
}
|
||||
|
||||
public int getSlotHeight()
|
||||
{
|
||||
return 44 + 4;
|
||||
}
|
||||
|
||||
public void use(ActButton elem, Mode action) {
|
||||
SkinEntry entry = this.getSelected();
|
||||
if(entry != null && GuiSpecies.this.gm.thePlayer != null)
|
||||
GuiSpecies.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(entry.species.clazz)));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue