allow cancelling character creation

This commit is contained in:
Sen 2025-06-13 00:27:03 +02:00
parent 58163db658
commit 53a4f5f1a8
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
3 changed files with 21 additions and 10 deletions

View file

@ -391,10 +391,8 @@ public class GuiChar extends GuiList<GuiChar.SkinEntry>
}, "Charakter erstellen")); }, "Charakter erstellen"));
this.cancelButton = this.add(new ActButton(width - 390, height - 30, 193, 0, new ButtonCallback() { this.cancelButton = this.add(new ActButton(width - 390, height - 30, 193, 0, new ButtonCallback() {
public void use(ActButton elem, PressType action) { public void use(ActButton elem, PressType action) {
if(GuiChar.this.gm.player != null) { if(GuiChar.this.gm.player != null)
GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ...")); GuiChar.this.gm.displayGuiScreen(GuiCharacters.INSTANCE);
GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CANCEL_EDITOR));
}
} }
}, "Abbrechen")); }, "Abbrechen"));
this.setCharsAvailable(); this.setCharsAvailable();

View file

@ -14,6 +14,7 @@ import client.renderer.Drawing;
import common.color.TextColor; import common.color.TextColor;
import common.entity.npc.PlayerCharacter; import common.entity.npc.PlayerCharacter;
import common.packet.CPacketAction; import common.packet.CPacketAction;
import common.packet.CPacketAction.Action;
import common.util.ExtMath; import common.util.ExtMath;
public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ButtonCallback public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> implements ButtonCallback
@ -65,7 +66,7 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> impleme
this.descField.setText(entry == null ? "" : (entry.character == null ? "*neuer Charakter*" : String.format(TextColor.GRAY + "[%s%s" + TextColor.GRAY + "]\n" + TextColor.RESET + "%s", entry.character.align().color, entry.character.align().display, entry.character.info() == null ? "*keine Beschreibung vorhanden*" : this.getSelected().character.info()))); this.descField.setText(entry == null ? "" : (entry.character == null ? "*neuer Charakter*" : String.format(TextColor.GRAY + "[%s%s" + TextColor.GRAY + "]\n" + TextColor.RESET + "%s", entry.character.align().color, entry.character.align().display, 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.setText(entry != null && entry.character == null ? "Charakter erstellen" : "Charakter spielen");
this.actionButtom.enabled = entry != null && !entry.initial; this.actionButtom.enabled = entry != null && !entry.initial;
this.deleteButtom.enabled = entry != null && entry.character != null && !entry.initial; this.deleteButtom.enabled = !this.gm.charEditor && entry != null && entry.character != null && !entry.initial;
} }
public void init(int width, int height) public void init(int width, int height)
@ -77,17 +78,18 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> impleme
for(PlayerCharacter character : this.gm.characterList) { for(PlayerCharacter character : this.gm.characterList) {
this.elements.add(new CharacterEntry(selected == this.elements.size() ? new PlayerCharacter(character.name(), character.info(), character.align(), this.gm.player.worldObj.dimension.getFormattedName(false), this.gm.player.getPosition(), character.type(), this.gm.player.experienceLevel) : character, selected == this.elements.size())); this.elements.add(new CharacterEntry(selected == this.elements.size() ? new PlayerCharacter(character.name(), character.info(), character.align(), this.gm.player.worldObj.dimension.getFormattedName(false), this.gm.player.getPosition(), character.type(), this.gm.player.experienceLevel) : character, selected == this.elements.size()));
} }
this.elements.add(new CharacterEntry(null, false)); if(!this.gm.charEditor)
this.elements.add(new CharacterEntry(null, false));
this.setSelected(ExtMath.clampi(selected, -1, this.elements.size() - 1)); this.setSelected(ExtMath.clampi(selected, -1, this.elements.size() - 1));
this.descField = this.add(new Area(width - 300, 32, 300, height - 64, "")); this.descField = this.add(new Area(width - 300, 32, 300, height - 64, ""));
this.deleteButtom = this.add(new ActButton(width / 2 - 302, height - 30, 200, 0, this, "Charakter löschen")); this.deleteButtom = this.add(new ActButton(width / 2 - 302, height - 30, 200, 0, this, "Charakter löschen"));
this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 30, 200, 0, this, "")); this.actionButtom = this.add(new ActButton(width / 2 - 100, height - 30, 200, 0, this, ""));
this.add(new NavButton(width / 2 + 102, height - 30, 200, 0, GuiMenu.INSTANCE, "Abbrechen")); this.add(new NavButton(width / 2 + 102, height - 30, 200, 0, this.gm.charEditor ? GuiChar.INSTANCE : GuiMenu.INSTANCE, this.gm.charEditor ? "Zurück" : "Abbrechen"));
this.updateButtons(); this.updateButtons();
} }
public String getTitle() { public String getTitle() {
return "Charakter anpassen"; return "Charakter auswählen";
} }
public int getSlotHeight() public int getSlotHeight()
@ -102,7 +104,7 @@ public class GuiCharacters extends GuiList<GuiCharacters.CharacterEntry> impleme
if(entry.character == null) if(entry.character == null)
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR)); this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.OPEN_EDITOR));
else else
this.gm.getNetHandler().addToSendQueue(new CPacketAction(CPacketAction.Action.SELECT_CHARACTER, this.selectedElement)); this.gm.getNetHandler().addToSendQueue(new CPacketAction(GuiCharacters.this.gm.charEditor ? Action.CANCEL_EDITOR : CPacketAction.Action.SELECT_CHARACTER, this.selectedElement));
} }
else if(elem == this.deleteButtom && entry.character != null) { else if(elem == this.deleteButtom && entry.character != null) {
this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() { this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() {

View file

@ -2427,7 +2427,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer
NetHandler.checkThread(packetIn, this, this.server); NetHandler.checkThread(packetIn, this, this.server);
CPacketAction.Action action = packetIn.getAction(); CPacketAction.Action action = packetIn.getAction();
if(this.charEditor != (action == Action.SET_ALIGN || action == Action.SET_SPECIES || action == Action.SET_CLASS || action == Action.SET_HEIGHT || action == Action.CLOSE_EDITOR)) // { if(this.charEditor != (action == Action.SET_ALIGN || action == Action.SET_SPECIES || action == Action.SET_CLASS || action == Action.SET_HEIGHT || action == Action.CLOSE_EDITOR || action == Action.CANCEL_EDITOR)) // {
// if(this.local && action == Action.CLOSE_EDITOR) // if(this.local && action == Action.CLOSE_EDITOR)
// this.server.setDone(); // this.server.setDone();
return; return;
@ -2464,6 +2464,17 @@ public class Player extends User implements ICrafting, Executor, IPlayer
// this.server.setDone(); // this.server.setDone();
break; break;
} }
case CANCEL_EDITOR: {
int index = packetIn.getAuxData();
if(index >= this.characters.size() || index < 0)
return;
this.charEditor = false;
this.server.swapPlayer(this, this.characters.get(index), null);
this.selected = index;
this.sendPacket(new SPacketCharacterList(this.selected));
break;
}
case SELECT_CHARACTER: { case SELECT_CHARACTER: {
int index = packetIn.getAuxData(); int index = packetIn.getAuxData();