character selector
This commit is contained in:
parent
0af8ca57d1
commit
74f730e450
24 changed files with 554 additions and 154 deletions
104
java/src/game/gui/GuiCharacters.java
Normal file
104
java/src/game/gui/GuiCharacters.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -170,9 +170,9 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
|||
int i = this.inputField.getNthCharFromPos();
|
||||
this.foundPlayerNames.clear();
|
||||
this.autocompleteIndex = 0;
|
||||
String s = this.inputField.getText().substring(i).toLowerCase();
|
||||
// String s = this.inputField.getText().substring(i).toLowerCase();
|
||||
String s1 = this.inputField.getText().substring(0, this.inputField.getCursorPosition());
|
||||
String[] localMatches = this.sendAutocompleteRequest(s1, s);
|
||||
String[] localMatches = this.sendAutocompleteRequest(s1);
|
||||
if(localMatches != null) {
|
||||
this.onAutocompleteResponse(localMatches);
|
||||
return;
|
||||
|
@ -236,7 +236,7 @@ public class GuiConsole extends Gui implements Textbox.Callback {
|
|||
// return Lists.newArrayList();
|
||||
}
|
||||
|
||||
private String[] sendAutocompleteRequest(String currentText, String newText)
|
||||
private String[] sendAutocompleteRequest(String currentText)
|
||||
{
|
||||
if (currentText.length() >= 1)
|
||||
{
|
||||
|
|
|
@ -107,9 +107,10 @@ public class GuiMenu extends Gui {
|
|||
this.pickSplash();
|
||||
}
|
||||
else {
|
||||
this.add(new NavButton(0, 0, 400, 24, null, "Zurück zum Spiel"));
|
||||
this.add(new NavButton(0, 28, 198, 24, GuiOptions.getPage(), "Einstellungen"));
|
||||
this.add(new NavButton(202, 28, 198, 24, GuiSkin.INSTANCE, "Charakter"));
|
||||
this.add(new NavButton(0, 0, 400, 24, this.gm.charEditor ? GuiSkin.INSTANCE : null, this.gm.charEditor ? "Zurück zum Charakter-Editor" : "Zurück zum Spiel"));
|
||||
this.add(new NavButton(0, 28, this.gm.charEditor ? 400 : 198, 24, GuiOptions.getPage(), "Einstellungen"));
|
||||
if(!this.gm.charEditor)
|
||||
this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter"));
|
||||
if(!this.gm.isRemote() && !this.gm.debugWorld) {
|
||||
this.add(new Textbox(0, 56, 96, 24, 5, true, new Textbox.Callback() {
|
||||
public void use(Textbox elem, Action value) {
|
||||
|
|
|
@ -25,7 +25,6 @@ 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.Textbox.Action;
|
||||
|
@ -174,43 +173,43 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
{
|
||||
// if(GuiSkin.this.adjust.dragging)
|
||||
// return;
|
||||
if (dclick)
|
||||
{
|
||||
GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
BufferedImage img = this.skinImage;
|
||||
// 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.startsWith("~") ? this.charinfo.skin.substring(1) :
|
||||
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.startsWith("~") ? this.charinfo.skin.substring(1) :
|
||||
this.charinfo.skin));
|
||||
else
|
||||
Log.JNI.error(e, "Konnte Textur nicht laden");
|
||||
return;
|
||||
}
|
||||
if(this.charinfo != null) {
|
||||
try {
|
||||
img = TextureUtil.readImage(FileUtils.getResource(
|
||||
EntityNPC.getSkinTexture(this.charinfo.skin.startsWith("~") ? this.charinfo.skin.substring(1) :
|
||||
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.startsWith("~") ? this.charinfo.skin.substring(1) :
|
||||
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);
|
||||
GuiSkin.this.convertButton1.enabled = this.canConvert();
|
||||
GuiSkin.this.convertButton2.enabled = this.canConvert();
|
||||
GuiSkin.this.templateButton.enabled = this.canCopy();
|
||||
GuiSkin.this.selectSkin(img, this.model);
|
||||
if(mx < 16 && mx > 0)
|
||||
GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
return;
|
||||
}
|
||||
GuiSkin.this.convertButton1.enabled = this.canConvert();
|
||||
GuiSkin.this.convertButton2.enabled = this.canConvert();
|
||||
GuiSkin.this.templateButton.enabled = this.canCopy();
|
||||
GuiSkin.this.selectSkin(img, this.model);
|
||||
// if(mx < 16 && mx > 0)
|
||||
// GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
|
||||
public File getFile()
|
||||
|
@ -285,6 +284,7 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
private DragAdjust adjust;
|
||||
private float yaw = -15.0f;
|
||||
private float pitch = -15.0f;
|
||||
private boolean waiting = true;
|
||||
|
||||
private GuiSkin() {
|
||||
}
|
||||
|
@ -292,7 +292,13 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
public void init(int width, int height)
|
||||
{
|
||||
super.init(width, height);
|
||||
this.waiting = true;
|
||||
this.setDimensions(400, height, 52, height - 52);
|
||||
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.convertButton1 = this.add(new ActButton(10, height - 48, 200, 20, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
|
@ -356,7 +362,7 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
this.add(new ActButton(width - 400 + (z % 2) * 196, 4 + 23 * (z / 2), 194, 20, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiSkin.this.gm.thePlayer != null) {
|
||||
GuiSkin.this.gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
GuiSkin.this.gm.displayGuiScreen(null);
|
||||
GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(species.clazz)));
|
||||
// for(ActButton btn : speciesBtns) {
|
||||
// btn.enabled = btn != elem;
|
||||
|
@ -375,6 +381,7 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
alignBtns[z] = this.add(new ActButton(width - 400 + (z % 3) * 131, height - 198 + 23 * (z / 3), 129, 20, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiSkin.this.gm.thePlayer != null) {
|
||||
GuiSkin.this.waiting = false;
|
||||
GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ALIGN, align.ordinal()));
|
||||
for(ActButton btn : alignBtns) {
|
||||
btn.enabled = btn != elem;
|
||||
|
@ -384,22 +391,31 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
}, align.color + align.display));
|
||||
alignBtns[z].enabled = this.gm.thePlayer == null || this.gm.thePlayer.getAlignment() != align;
|
||||
}
|
||||
this.add(new Slider(width - 400, height - 28 - 84, 390, 20, 1, 120, 320, 180, this.gm.thePlayer == null ? 180 : (int)(this.gm.thePlayer.getSpecies().size * this.gm.thePlayer.getHeight() * 100.0f + 0.5f), new Slider.Callback() {
|
||||
this.add(new Slider(width - 400, height - 28 - 84, 390, 20, 1, 120, 320, 180, this.gm.thePlayer == null ? 180 : (int)(this.gm.thePlayer.getSpecies().renderer.height * this.gm.thePlayer.getHeight() * 100.0f + 0.5f), new Slider.Callback() {
|
||||
public void use(Slider elem, int value) {
|
||||
if(GuiSkin.this.gm.thePlayer != null)
|
||||
if(GuiSkin.this.gm.thePlayer != null) {
|
||||
GuiSkin.this.waiting = false;
|
||||
GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_HEIGHT, value));
|
||||
}
|
||||
}
|
||||
}, "Spieler-Größe", "cm"));
|
||||
this.add(new Label(width - 400, height + 2 - 28 - 24 - 30, 390, 20, "Anzeigename", true));
|
||||
this.add(new NavButton(width - 274 + 154, height - 24, 264 - 154, 20, GuiMenu.INSTANCE, "Fertig"));
|
||||
this.add(new ActButton(width - 274 + 154, height - 24, 264 - 154, 20, new ActButton.Callback() {
|
||||
public void use(ActButton elem, Mode action) {
|
||||
if(GuiSkin.this.gm.thePlayer != null)
|
||||
GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.CLOSE_EDITOR));
|
||||
}
|
||||
}, "Fertig"));
|
||||
Textbox nameField = this.add(new Textbox(width - 400, height + 2 - 28 - 34, 390, 20, 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(GuiSkin.this.gm.thePlayer == null ? "..." : GuiSkin.this.gm.thePlayer.getCustomNameTag());
|
||||
else if(GuiSkin.this.gm.thePlayer != null)
|
||||
else if(GuiSkin.this.gm.thePlayer != null) {
|
||||
GuiSkin.this.waiting = false;
|
||||
GuiSkin.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketMessage(CPacketMessage.Type.DISPLAY, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, Player.VALID_NICK, this.gm.thePlayer == null ? "" : this.gm.thePlayer.getCustomNameTag()));
|
||||
|
@ -420,8 +436,21 @@ public class GuiSkin extends GuiList<GuiSkin.SkinEntry>
|
|||
|
||||
public void drawOverlays()
|
||||
{
|
||||
drawEntity(400 + (this.gm.fb_x - 400 - 400) / 2, this.gm.fb_y / 2 + 160, 160.0f
|
||||
/ this.gm.thePlayer.getHeight(), this.yaw, this.pitch, this.gm.thePlayer);
|
||||
if(this.adjust != null)
|
||||
drawEntity(400 + (this.gm.fb_x - 400 - 400) / 2, this.gm.fb_y / 2 + 160, 160.0f
|
||||
/ 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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue