Files
citizen/Buttons.pde
2019-02-01 10:19:13 +01:00

231 lines
6.2 KiB
Plaintext

int i_buttonCount = 7;
int i_debugButtonCount = 7;
int i_buttonId;
Button buttons[] = new Button[i_buttonCount];
DebugButton debugButtons[] = new DebugButton[i_debugButtonCount];
void initButtons() {
for (int i = 0; i < i_debugButtonCount; i++) {
debugButtons[i] = new DebugButton(i);
}
debugButtons[0].setLabel("Autoplay");
debugButtons[1].setLabel("Lock Camera");
debugButtons[2].setLabel("Debug");
debugButtons[3].setLabel("Control Eyes");
debugButtons[4].setLabel("Houses Texts");
debugButtons[5].setLabel("Pause Time");
debugButtons[6].setLabel("Draw Nodes");
//id assigned by order of instantiation; centroid x, centroid y, w, h, corner, label, textsize, color
buttons[0] = new Button(i_windowW/2, 75, 200, 50, i_debugButtonCorner, "Nacht überspringen >>", 15, color(255, i_uiTransparency));
buttons[1] = new Button(i_iconX, i_iconY, i_iconW, i_iconH, i_iconCorner, "", 1, color(255, 0)); //help
buttons[2] = new Button(2*i_iconX, i_iconY, i_iconW, i_iconH, i_iconCorner, "", 1, color(255, 0));//spectate
buttons[3] = new Button(2*i_iconX, i_iconY, i_iconW, i_iconH, i_iconCorner, "", 1, color(255, 0));//control
buttons[4] = new Button(3*i_iconX, i_iconY, i_iconW, i_iconH, i_iconCorner, "", 1, color(255, 0));//magplus
buttons[5] = new Button(3*i_iconX, i_iconY, i_iconW, i_iconH, i_iconCorner, "", 1, color(255, 0));//magminus
buttons[2].b_active = false;
buttons[5].b_active = false;
buttons[6] = new Button(i_windowW/2, i_windowH-180, 200, 50, i_debugButtonCorner, "Schließen", 15, color(190));
buttons[6].b_active = false;
}
boolean b_triggerButton;
void buttonFunctions(int functionID, boolean debug) {
if (!debug) {
switch (functionID) {
case(0):
if (i_flexibleTime >= getFlexTime(23, 00)) i_days++;
setTime(6, 0);
break;
case(1):
showHelp();
break;
case(2):
if (!b_triggerButton) {
buttons[2].b_active = false;
buttons[3].b_active = true;
spectate();
buttonFunctions(5,false);
}
b_triggerButton = true;
break;
case(3):
if (!b_triggerButton) {
buttons[3].b_active = false;
buttons[2].b_active = true;
control();
}
b_triggerButton = true;
break;
case(4):
if (!b_triggerButton) {
buttons[4].b_active = false;
buttons[5].b_active = true;
zoomIn();
if (i_selectedCitizen == 0) selectCitizen((int)random(0, citizen.length));
b_cameraLock = true;
}
b_triggerButton = true;
break;
case(5):
if (!b_triggerButton) {
buttons[4].b_active = true;
buttons[5].b_active = false;
zoomOut();
//if(!b_control) selectCitizen(0);
b_cameraLock = false;
}
b_triggerButton = true;
break;
case(6):
b_showingHelp = false;
buttons[6].b_active = false;
break;
default:
break;
}
} else {
switch (functionID) {
case(0):
b_autoPlay = !b_autoPlay;
if (b_autoPlay) {
for (int i = 0; i < citizen.length; i++) {
if (!citizen[i].b_moving) {
if (citizen[i].nextNode == 0) {
b_makeThemGo = true; //toggles one random goTo per frame per citizen, turns itself off when finished
} else {
citizen[i].b_moving = true;
}
}
if (!citizen[i].b_randomRun) {
citizen[i].b_randomRun = true;
}
}
} else {
for (int i = 0; i < citizen.length; i++) {
citizen[i].b_moving = false;
citizen[i].b_randomRun = false;
citizen[i].b_turning = false;
}
}
break;
case(1):
b_cameraLock = !b_cameraLock;
break;
case(2):
b_debug = !b_debug;
for (int i = 0; i < citizen.length; i++) {
citizen[i].c_stroke = color(int(!b_debug)*255);
}
for (int i = 0; i < interactables.length; i++) {
interactables[i].c_stroke = color(int(!b_debug)*255);
}
break;
case(3):
b_controlEyeWithMouse = !b_controlEyeWithMouse;
break;
case(4):
b_housesTexts = !b_housesTexts;
break;
case(5):
b_pauseTime = !b_pauseTime;
break;
case(6):
b_drawNodes = !b_drawNodes;
default:
break;
}
}
}
class DebugButton extends Button {
DebugButton(int id) {
i_id = id;
i_x = i_debugButtonMenuX + i_debugButtonMenuPadding;
i_y = i_debugButtonMenuY + i_debugButtonMenuPadding + (i_debugButtonPadding + i_debugButtonHeight) * i_id;
i_w = i_debugButtonWidth;
i_h = i_debugButtonHeight;
i_corner = i_debugButtonCorner;
i_textSize = i_debugTextSize;
i_debugButtonMenuButtonC++;
}
}
class Button {
int i_id, i_x, i_y, i_w, i_h, i_corner, i_labelX, i_labelY, i_textSize;
int i_clickMargin = 3;
String s_label;
color c_color = color(255, 155);
boolean b_active = true;
boolean hover() {
if (b_active) return (mouseX > i_x - i_clickMargin && mouseX < i_x+i_w + i_clickMargin && mouseY > i_y - i_clickMargin && mouseY < i_y+i_h + i_clickMargin) ? true : false;
else return false;
}
/*
static Button buttonKeeper;
void f(){
Button fuckGarbageCollection = new Button();
}
public void holyShit(){
buttonKeeper = this;
println("omg");
}
*/
Button() {
//f();
}
Button(int x, int y, int w, int h, int corner, String lab, int textsize, color col) {
i_id = i_buttonId;
i_buttonId++;
i_w = w;
i_h = h;
i_x = x - i_w/2;
i_y = y - i_h/2;
i_corner = corner;
i_textSize = textsize;
s_label = lab;
textSize(i_textSize);
i_labelX = i_x + i_w/2 - (int)(textWidth(s_label) /2);
c_color = col;
}
void setLabel(String lab) {
s_label = lab;
textSize(i_textSize);
i_labelX = i_x + (i_w/2) - (int)(textWidth(s_label) /2);
}
void click() {
if (b_active) {
buttonFunctions(i_id, this instanceof DebugButton);
}
}
//void keepAlive(){
//}
void display() {
if (b_active) {
fill(c_color);
rect(i_x, i_y, i_w, i_h, i_corner);
fill(0, 255);
textSize(i_textSize);
text(s_label, i_labelX, i_y + i_h/2 + i_textSize/2.5);
}
}
}