class GuiButton { String msg[]; String flags[]; boolean hot, down; float x, y; int s; boolean old; int id; Transition action; GuiButton(String m, float x, float y, int s) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = -1; this.flags = null; } GuiButton(String m, float x, float y, int s, int id, boolean old) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = id; this.old = old; this.flags = null; } GuiButton(String m, float x, float y, int s, Transition action) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = id; this.old = false; this.action = action; this.flags = null; } GuiButton(String m, float x, float y, int s, Transition action, String[] flags) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = id; this.old = false; this.action = action; this.flags = flags; } boolean allFlagsSet() { if (flags == null) return true; for (int i = 0; i < flags.length; i++) { if (!globalflags.contains(flags[i])) { return false; } } return true; } boolean isMouseOver() { for (int i = 0; i < msg.length; i++) { float yy = y + i * (font.h+1) * s; if (mouseX-x>=-s && mouseX-x<=msg[i].length()*font.w*s+s && mouseY-yy>=-s && mouseY-yy<=font.h*s+s) { return true; } } return false; } // returns true if button was clicked boolean Update() { if (allFlagsSet()) { boolean mouseOver = isMouseOver(); if (hot && down) { if (!(mousePressed)) { if (mouseOver) { down = false; return true; } else { down = false; hot = mouseOver; } } } else if (!down) { hot = mouseOver && !(wasMousePressed); if (hot) { if (mousePressed) down = true; } } } return false; } void Draw() { if (allFlagsSet()) { if (!hot && !down) { if (!old) font.Draw(x,y,msg,s); else fontGray.Draw(x,y,msg,s); } else if ((hot && !down)) { fontGray.Draw(x,y,msg,s); } else { if (isMouseOver()) fontGray.Draw(x+s,y+s,msg,s); else { if (!old) font.Draw(x+s,y+s,msg,s); else fontGray.Draw(x+s,y+s,msg,s); } } } } }