package game.gui.character; import game.entity.npc.SpeciesInfo; 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.init.EntityRegistry; import game.init.SpeciesRegistry; import game.packet.CPacketAction; import game.renderer.Drawing; public class GuiSpecies extends GuiList implements ActButton.Callback { protected class SpeciesEntry implements ListEntry { private final SpeciesInfo species; protected SpeciesEntry(SpeciesInfo species) { this.species = species; } public void draw(int x, int y, int mouseX, int mouseY, boolean hovered) { if(GuiSpecies.this.gm.thePlayer != null && this.species == GuiSpecies.this.gm.thePlayer.getSpecies()) Drawing.drawRect(x, y, 1, 44, 0xffaf0000); Drawing.drawText(this.species.name, x + 3, y, 0xff000000 | this.species.color1 | this.species.color2); if(this.species.classEnum != null) Drawing.drawText(this.species.classEnum.getEnumConstants().length + " Klassen", x + 3, y + 18, 0xffc0c0c0); } public void select(boolean dclick, int mx, int my) { if((GuiSpecies.this.selectButton.enabled = GuiSpecies.this.gm.thePlayer == null || this.species != GuiSpecies.this.gm.thePlayer.getSpecies()) && dclick) GuiSpecies.this.use(GuiSpecies.this.selectButton, Mode.PRIMARY); } } public static final GuiSpecies INSTANCE = new GuiSpecies(); private ActButton selectButton; private GuiSpecies() { } public void init(int width, int height) { super.init(width, height); this.setDimensions(400, height, 32, height - 32); this.elements.clear(); for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) { this.elements.add(new SpeciesEntry(species)); } this.add(new NavButton(width - 198 * 2, height - 28, 194, 24, GuiChar.INSTANCE, "Zurück")); this.selectButton = this.add(new ActButton(width - 198, height - 28, 194, 24, this, "Spezies ändern")); } public String getTitle() { return "Spezies wählen"; } public int getListWidth() { return 400 - 20; } public int getSlotHeight() { return 44 + 4; } public void use(ActButton elem, Mode action) { SpeciesEntry entry = this.getSelected(); if(entry != null && GuiSpecies.this.gm.thePlayer != null) GuiSpecies.this.gm.thePlayer.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_SPECIES, EntityRegistry.getEntityID(entry.species.clazz))); } }