|
| 1 | +package org.aoclient.engine.game; |
| 2 | + |
| 3 | +import imgui.ImGui; |
| 4 | +import org.aoclient.engine.game.console.Console; |
| 5 | +import org.aoclient.engine.game.console.FontStyle; |
| 6 | +import org.aoclient.engine.game.models.SMType; |
| 7 | +import org.aoclient.engine.renderer.RGBColor; |
| 8 | +import org.aoclient.engine.renderer.Texture; |
| 9 | +import org.aoclient.engine.renderer.TextureManager; |
| 10 | + |
| 11 | +import static org.aoclient.engine.audio.Sound.SND_CLICK; |
| 12 | +import static org.aoclient.engine.audio.Sound.playSound; |
| 13 | +import static org.aoclient.engine.gui.forms.Form.imageButtonRegion; |
| 14 | +import static org.aoclient.engine.gui.forms.Form.imageRegion; |
| 15 | +import static org.aoclient.engine.utils.GameData.grhData; |
| 16 | +import static org.aoclient.network.protocol.Protocol.resucitationToggle; |
| 17 | +import static org.aoclient.network.protocol.Protocol.safeToggle; |
| 18 | + |
| 19 | +// lo creamos en fMAIN |
| 20 | +public class SMSystem { |
| 21 | + private final int x, y, w, h; // posicion y size del boton |
| 22 | + private final SMType type; |
| 23 | + private boolean active; |
| 24 | + private Texture SMTex; |
| 25 | + |
| 26 | + public SMSystem(int x, int y, SMType type, boolean active) { |
| 27 | + this.x = x; |
| 28 | + this.y = y; |
| 29 | + this.w = 28; |
| 30 | + this.h = 30; |
| 31 | + |
| 32 | + this.type = type; |
| 33 | + this.active = active; |
| 34 | + |
| 35 | + // precargamos la textura |
| 36 | + TextureManager.requestTexture(type.getGrhIndexON()); |
| 37 | + TextureManager.requestTexture(type.getGrhIndexOFF()); |
| 38 | + |
| 39 | + if (active) { |
| 40 | + SMTex = TextureManager.getTexture(grhData[type.getGrhIndexON()].getFileNum()); |
| 41 | + } else { |
| 42 | + SMTex = TextureManager.getTexture(grhData[type.getGrhIndexOFF()].getFileNum()); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + // dibuajamos en imgui. |
| 47 | + public void draw() { |
| 48 | + // que grhindex tenemos que mostrar? |
| 49 | + final int currentGrh = active? type.getGrhIndexON() : type.getGrhIndexOFF(); |
| 50 | + |
| 51 | + // mostramos una imagen primero |
| 52 | + ImGui.setCursorPos(x, y); |
| 53 | + if (SMTex != null) { |
| 54 | + imageRegion(SMTex, grhData[currentGrh].getsX(), grhData[currentGrh].getsY(), w, h); |
| 55 | + } |
| 56 | + |
| 57 | + ImGui.setCursorPos(x, y); |
| 58 | + if (ImGui.invisibleButton(type.toString(), w, h)) { |
| 59 | + action(); |
| 60 | + } |
| 61 | + |
| 62 | + // update texture |
| 63 | + SMTex = TextureManager.getTexture(grhData[currentGrh].getFileNum()); |
| 64 | + |
| 65 | + updateToolTip(); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + private void updateToolTip() { |
| 71 | + switch (type) { |
| 72 | + case sResucitation: |
| 73 | + if (active){ |
| 74 | + if (ImGui.isItemHovered()) ImGui.setTooltip(Messages.get(Messages.MessageKey.SEGURO_RESU_ON)); |
| 75 | + } else { |
| 76 | + if (ImGui.isItemHovered()) ImGui.setTooltip(Messages.get(Messages.MessageKey.SEGURO_RESU_OFF)); |
| 77 | + } |
| 78 | + break; |
| 79 | + |
| 80 | + case sSafemode: |
| 81 | + if (active){ |
| 82 | + if (ImGui.isItemHovered()) ImGui.setTooltip(Messages.get(Messages.MessageKey.SEGURO_ACTIVADO)); |
| 83 | + } else { |
| 84 | + if (ImGui.isItemHovered()) ImGui.setTooltip(Messages.get(Messages.MessageKey.SEGURO_DESACTIVADO)); |
| 85 | + } |
| 86 | + break; |
| 87 | + |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + // accion segun el tipo que sea. |
| 92 | + private void action() { |
| 93 | + // sonido |
| 94 | + playSound(SND_CLICK); |
| 95 | + |
| 96 | + // accion segun el tipo |
| 97 | + switch (type){ |
| 98 | + case sResucitation: |
| 99 | + // el servidor ya devuelve mensaje. |
| 100 | + resucitationToggle(); |
| 101 | + break; |
| 102 | + |
| 103 | + case sSafemode: |
| 104 | + // el servidor ya devuelve mensaje. |
| 105 | + safeToggle(); |
| 106 | + break; |
| 107 | + |
| 108 | + // TODO: Agregar al sistema de internacionalizacion, no puede quedar hardcodeado esto. |
| 109 | + case mWork: |
| 110 | + if (active) { |
| 111 | + Console.INSTANCE.addMsgToConsole("Macro de trabajo desactivado.", FontStyle.BOLD, new RGBColor(1, 0, 0)); |
| 112 | + } else { |
| 113 | + Console.INSTANCE.addMsgToConsole("Macro de trabajo activado.", FontStyle.BOLD, new RGBColor(0, 1, 0)); |
| 114 | + } |
| 115 | + break; |
| 116 | + |
| 117 | + case mSpells: |
| 118 | + if (active) { |
| 119 | + Console.INSTANCE.addMsgToConsole("Macro de hechizos desactivado.", FontStyle.BOLD, new RGBColor(1, 0, 0)); |
| 120 | + } else { |
| 121 | + Console.INSTANCE.addMsgToConsole("Macro de hechizos activado.", FontStyle.BOLD, new RGBColor(0, 1, 0)); |
| 122 | + } |
| 123 | + break; |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | + active = !active; |
| 128 | + } |
| 129 | + |
| 130 | + public void setActive(boolean active) { |
| 131 | + this.active = active; |
| 132 | + } |
| 133 | +} |
0 commit comments