105 lines
4.2 KiB
Java
105 lines
4.2 KiB
Java
![]() |
package game.gui;
|
||
|
|
||
|
import game.color.TextColor;
|
||
|
import game.entity.npc.PlayerCharacter;
|
||
|
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>
|
||
|
{
|
||
|
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)
|
||
|
{
|
||
|
GuiCharacters.this.updateButtons();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static final GuiCharacters INSTANCE = new GuiCharacters();
|
||
|
|
||
|
private TransparentBox descField;
|
||
|
private ActButton actionButtom;
|
||
|
|
||
|
private GuiCharacters() {
|
||
|
}
|
||
|
|
||
|
private void updateButtons() {
|
||
|
CharacterEntry entry = this.getSelected();
|
||
|
this.descField.setText(entry != null && entry.character == null ? "*neuer Charakter*" : (entry == null || 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;
|
||
|
}
|
||
|
|
||
|
public void init(int width, int height)
|
||
|
{
|
||
|
super.init(width, height);
|
||
|
this.setDimensions(width - 400, height, 52, height - 52);
|
||
|
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(character, initialSelection == this.elements.size()));
|
||
|
}
|
||
|
this.elements.add(new CharacterEntry(null, false));
|
||
|
this.setSelected(initialSelection);
|
||
|
}
|
||
|
this.descField = this.add(new TransparentBox(width - 400, 0, 400, height - 28, ""));
|
||
|
this.actionButtom = this.add(new ActButton(width - 198 * 2, height - 24, 194, 20, new ActButton.Callback() {
|
||
|
public void use(ActButton elem, Mode action) {
|
||
|
CharacterEntry entry = GuiCharacters.this.getSelected();
|
||
|
if(entry != null && GuiCharacters.this.gm.getNetHandler() != null) {
|
||
|
if(entry.character == null)
|
||
|
GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR));
|
||
|
else
|
||
|
GuiCharacters.this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, GuiCharacters.this.selectedElement));
|
||
|
}
|
||
|
}
|
||
|
}, ""));
|
||
|
this.add(new NavButton(width - 198, height - 24, 194, 20, GuiMenu.INSTANCE, "Abbrechen"));
|
||
|
this.updateButtons();
|
||
|
}
|
||
|
|
||
|
public String getTitle() {
|
||
|
return "Charakter anpassen";
|
||
|
}
|
||
|
|
||
|
public int getListWidth()
|
||
|
{
|
||
|
return 560;
|
||
|
}
|
||
|
|
||
|
public int getSlotHeight()
|
||
|
{
|
||
|
return 36 + 4;
|
||
|
}
|
||
|
}
|