char list delete ...

This commit is contained in:
Sen 2025-03-28 19:45:12 +01:00
parent 5843594ba3
commit dd72e2d367
7 changed files with 93 additions and 44 deletions

View file

@ -11,7 +11,7 @@ import game.gui.element.TransparentBox;
import game.packet.CPacketAction;
import game.renderer.Drawing;
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ActButton.Callback
{
protected class CharacterEntry implements ListEntry
{
@ -40,6 +40,8 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
public void select(boolean dclick, int mx, int my)
{
if(dclick)
GuiCharacters.this.use(GuiCharacters.this.actionButtom, Mode.PRIMARY);
GuiCharacters.this.updateButtons();
}
}
@ -48,15 +50,17 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
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 == null || entry.character.info == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info));
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;
this.actionButtom.enabled = entry != null && !entry.initial;
this.deleteButtom.enabled = entry != null && entry.character != null && !entry.initial;
}
public void init(int width, int height)
@ -73,18 +77,9 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
this.setSelected(initialSelection);
}
this.descField = this.add(new TransparentBox(width - 390, 62, 380, height - 124, "", false));
this.actionButtom = this.add(new ActButton(width / 2 - 200, height - 28, 198, 24, 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 / 2 + 2, height - 28, 198, 24, GuiMenu.INSTANCE, "Abbrechen"));
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();
}
@ -101,4 +96,25 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry>
{
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"));
}
}
}
}