From 53a4f5f1a8e3af601daa4032671317d60a86af50 Mon Sep 17 00:00:00 2001 From: Sen Date: Fri, 13 Jun 2025 00:27:03 +0200 Subject: [PATCH] allow cancelling character creation --- .../src/main/java/client/gui/character/GuiChar.java | 6 ++---- .../java/client/gui/character/GuiCharacters.java | 12 +++++++----- server/src/main/java/server/network/Player.java | 13 ++++++++++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/client/src/main/java/client/gui/character/GuiChar.java b/client/src/main/java/client/gui/character/GuiChar.java index aa8da07..33cc771 100755 --- a/client/src/main/java/client/gui/character/GuiChar.java +++ b/client/src/main/java/client/gui/character/GuiChar.java @@ -391,10 +391,8 @@ public class GuiChar extends GuiList }, "Charakter erstellen")); this.cancelButton = this.add(new ActButton(width - 390, height - 30, 193, 0, new ButtonCallback() { public void use(ActButton elem, PressType action) { - if(GuiChar.this.gm.player != null) { - GuiChar.this.gm.displayGuiScreen(GuiLoading.makeWaitTask("Lade Welt ...")); - GuiChar.this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CANCEL_EDITOR)); - } + if(GuiChar.this.gm.player != null) + GuiChar.this.gm.displayGuiScreen(GuiCharacters.INSTANCE); } }, "Abbrechen")); this.setCharsAvailable(); diff --git a/client/src/main/java/client/gui/character/GuiCharacters.java b/client/src/main/java/client/gui/character/GuiCharacters.java index 4e478f7..9d53d9e 100644 --- a/client/src/main/java/client/gui/character/GuiCharacters.java +++ b/client/src/main/java/client/gui/character/GuiCharacters.java @@ -14,6 +14,7 @@ import client.renderer.Drawing; import common.color.TextColor; import common.entity.npc.PlayerCharacter; import common.packet.CPacketAction; +import common.packet.CPacketAction.Action; import common.util.ExtMath; public class GuiCharacters extends GuiList implements ButtonCallback @@ -65,7 +66,7 @@ public class GuiCharacters extends GuiList 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.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; + this.deleteButtom.enabled = !this.gm.charEditor && entry != null && entry.character != null && !entry.initial; } public void init(int width, int height) @@ -77,17 +78,18 @@ public class GuiCharacters extends GuiList impleme 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(null, false)); + if(!this.gm.charEditor) + this.elements.add(new CharacterEntry(null, false)); this.setSelected(ExtMath.clampi(selected, -1, this.elements.size() - 1)); 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.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(); } public String getTitle() { - return "Charakter anpassen"; + return "Charakter auswählen"; } public int getSlotHeight() @@ -102,7 +104,7 @@ public class GuiCharacters extends GuiList impleme 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)); + 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) { this.gm.displayGuiScreen(new GuiConfirm(new GuiConfirm.Callback() { diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index c7ee6d3..85a2687 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -2427,7 +2427,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer NetHandler.checkThread(packetIn, this, this.server); 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) // this.server.setDone(); return; @@ -2464,6 +2464,17 @@ public class Player extends User implements ICrafting, Executor, IPlayer // this.server.setDone(); 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: { int index = packetIn.getAuxData();