button class, angle
This commit is contained in:
213
UI.pde
213
UI.pde
@@ -1,25 +1,23 @@
|
||||
|
||||
Button buttons[] = new Button[3];
|
||||
|
||||
|
||||
int i_uiTransparency = 200;
|
||||
void initUI() {
|
||||
i_uiX = 0;
|
||||
i_uiY = 518;
|
||||
i_uiW = width;
|
||||
i_uiH = height - i_uiY;
|
||||
|
||||
buttons[0] = new Button(15, 50, 100, i_debugTextSize, 5, "Autoplay", 0);
|
||||
buttons[1] = new Button(15, 70, 100, i_debugTextSize, 5, "Lock Camera", 1);
|
||||
buttons[2] = new Button(15, 90, 100, i_debugTextSize, 5, "Debug", 2);
|
||||
}
|
||||
|
||||
|
||||
int i_uiX, i_uiY, i_uiW, i_uiH;
|
||||
int i_uiOffsetX, i_uiOffsetY, i_uiOffsetStartX, i_uiOffsetStartY, i_initUiY;
|
||||
void drawUI() {
|
||||
strokeWeight(1);
|
||||
line(i_uiX, i_uiY, i_uiX+i_uiW, i_uiY);
|
||||
strokeWeight(0);
|
||||
fill(255, i_uiTransparency);
|
||||
rect(i_uiX, i_uiY, i_uiW, i_uiH);
|
||||
rect(6, 4, 140, 31, 6);
|
||||
fill(0);
|
||||
textSize(30);
|
||||
textAlign(LEFT);
|
||||
text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
|
||||
|
||||
//camera tracking
|
||||
if (b_cameraFollow) {
|
||||
@@ -32,78 +30,154 @@ void drawUI() {
|
||||
}
|
||||
}
|
||||
|
||||
//draw
|
||||
//buttons
|
||||
strokeWeight(0);
|
||||
textSize(i_debugTextSize);
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
buttons[i].display();
|
||||
}
|
||||
//clock
|
||||
fill(255, i_uiTransparency);
|
||||
rect(6, 4, 140, 31, 6);
|
||||
textSize(30);
|
||||
textAlign(LEFT);
|
||||
fill(0);
|
||||
text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
|
||||
|
||||
//debug
|
||||
String[] debug = {
|
||||
"FPS: " + int(frameRate),
|
||||
"Amount citizen: " + i_citizenAmount,
|
||||
"Females: " + i_femaleCount + " Males: " + str(i_citizenAmount-i_femaleCount),
|
||||
" ",
|
||||
"Selected Citizen ID: " + i_selectedCitizen,
|
||||
"Name: " + citizen[i_selectedCitizen].S_name,
|
||||
"Gender: " + citizen[i_selectedCitizen].S_gender,
|
||||
"Age: " + citizen[i_selectedCitizen].i_age,
|
||||
"x: " + int(citizen[i_selectedCitizen].f_xPos),
|
||||
"y: " + int(citizen[i_selectedCitizen].f_yPos),
|
||||
"Movement speed: " + round(citizen[i_selectedCitizen].f_movementSpeed*100),
|
||||
"Random Run: " + citizen[i_selectedCitizen].b_randomRun,
|
||||
" ",
|
||||
"Sunrise: " + S_sunrise,
|
||||
"Sunset: " + S_sunset,
|
||||
"Autoplay: " + b_autoPlayAfterSelect,
|
||||
"Locked Camera: " + b_cameraFollow,
|
||||
//"Velocity: ",
|
||||
//"Outside",
|
||||
//"Mood: "
|
||||
};
|
||||
int ts = i_debugTextSize;
|
||||
textSize(ts);
|
||||
int line = 0;
|
||||
int maxLinesPerColumn = i_uiH/ts;
|
||||
int columnWidth = 130;
|
||||
if (maxLinesPerColumn > 0) {
|
||||
int requiredColumns = (debug.length/maxLinesPerColumn)+1;
|
||||
for (int i = 0; i < requiredColumns; i++) {
|
||||
while (((line-(maxLinesPerColumn*i)) * ts + ts-1)+i_uiY<height && line < debug.length) {
|
||||
text(debug[line], 10+(columnWidth*i), i_uiY+(ts*((line-(maxLinesPerColumn*i))+1)));
|
||||
line++;
|
||||
if (b_debug) {
|
||||
//bottom
|
||||
fill(255, i_uiTransparency);
|
||||
strokeWeight(1);
|
||||
line(i_uiX, i_uiY, i_uiX+i_uiW, i_uiY);
|
||||
strokeWeight(0);
|
||||
rect(i_uiX, i_uiY, i_uiW, i_uiH);
|
||||
fill(0);
|
||||
|
||||
String[] debug = {
|
||||
"FPS: " + int(frameRate),
|
||||
"Amount citizen: " + i_citizenAmount,
|
||||
"Females: " + i_femaleCount + " Males: " + str(i_citizenAmount-i_femaleCount),
|
||||
" ",
|
||||
"Selected Citizen ID: " + i_selectedCitizen,
|
||||
"Name: " + citizen[i_selectedCitizen].S_name,
|
||||
"Gender: " + citizen[i_selectedCitizen].S_gender,
|
||||
"Age: " + citizen[i_selectedCitizen].i_age,
|
||||
"x: " + int(citizen[i_selectedCitizen].f_xPos),
|
||||
"y: " + int(citizen[i_selectedCitizen].f_yPos),
|
||||
"Angle: " + citizen[i_selectedCitizen].f_angle,
|
||||
"Movement speed: " + round(citizen[i_selectedCitizen].f_movementSpeed*100),
|
||||
"Random Run: " + citizen[i_selectedCitizen].b_randomRun,
|
||||
" ",
|
||||
"Sunrise: " + S_sunrise,
|
||||
"Sunset: " + S_sunset,
|
||||
"Autoplay: " + b_autoPlayAfterSelect,
|
||||
"Locked Camera: " + b_cameraFollow,
|
||||
"Debug Mode: " + b_debug,
|
||||
//"Velocity: ",
|
||||
//"Outside",
|
||||
//"Mood: "
|
||||
};
|
||||
textSize(i_debugTextSize);
|
||||
int line = 0;
|
||||
int maxLinesPerColumn = i_uiH/i_debugTextSize;
|
||||
int columnWidth = 130;
|
||||
if (maxLinesPerColumn > 0) {
|
||||
int requiredColumns = (debug.length/maxLinesPerColumn)+1;
|
||||
for (int i = 0; i < requiredColumns; i++) {
|
||||
while (((line-(maxLinesPerColumn*i)) * i_debugTextSize + i_debugTextSize -1)+i_uiY<height && line < debug.length) {
|
||||
text(debug[line], 10+(columnWidth*i), i_uiY+(i_debugTextSize*((line-(maxLinesPerColumn*i))+1)));
|
||||
line++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//text("FPS: " + int(frameRate), 10, i_uiY + 15);
|
||||
//text("Selected Citizen: " + i_selectedCitizen, 10, i_uiY + 30);
|
||||
}
|
||||
//buttons
|
||||
fill(150, 170, 250, 80);
|
||||
rect(i_uiX+i_uiW-135, i_uiY+ts/2, 120, ts, 5);
|
||||
fill(0);
|
||||
text("Autoplay", i_uiX+i_uiW-135, i_uiY+ts/2+ts);
|
||||
fill(150, 170, 250, 80);
|
||||
rect(i_uiX+i_uiW-135, i_uiY+ts/2+1.41*ts+ts/2, 120, ts, 5);
|
||||
fill(0);
|
||||
text("Lock Camera", i_uiX+i_uiW-135, i_uiY+ts/2+1.41*ts+ts+ts/2);
|
||||
}
|
||||
|
||||
|
||||
void buttonFunctions(int s) {
|
||||
switch (s) {
|
||||
case(0):
|
||||
citizen[i_selectedCitizen].b_moving = !citizen[i_selectedCitizen].b_moving;
|
||||
citizen[i_selectedCitizen].b_randomRun = !citizen[i_selectedCitizen].b_randomRun;
|
||||
b_autoPlayAfterSelect = !b_autoPlayAfterSelect;
|
||||
break;
|
||||
case(1):
|
||||
b_cameraFollow = !b_cameraFollow;
|
||||
break;
|
||||
case(2):
|
||||
b_debug = !b_debug;
|
||||
|
||||
//dirty
|
||||
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):
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
class Button {
|
||||
int i_x, i_y, i_w, i_h, i_c, i_f, i_tx;
|
||||
int i_margin = 5;
|
||||
String s_t;
|
||||
Button(int x, int y, int w, int h, int corner, String text, int function) {
|
||||
i_x = x;
|
||||
i_y = y;
|
||||
i_w = w;
|
||||
i_h = h;
|
||||
i_c = corner;
|
||||
i_f = function;
|
||||
s_t = text;
|
||||
i_tx = i_x + (i_w/2) - (int(textWidth(s_t) /2));
|
||||
}
|
||||
boolean hover() {
|
||||
if (mouseX > i_x - i_margin && mouseX < i_x+i_w + i_margin && mouseY > i_y - i_margin && mouseY < i_y+i_h + i_margin) return true;
|
||||
else return false;
|
||||
}
|
||||
void click() {
|
||||
buttonFunctions(i_f);
|
||||
}
|
||||
void display() {
|
||||
fill(150, 170, 250, 150);
|
||||
rect(i_x, i_y, i_w, i_h, i_c);
|
||||
fill(0);
|
||||
text(s_t, i_tx, i_y + i_debugTextSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
|
||||
boolean b_hoverUI;
|
||||
|
||||
void mousePressed() {
|
||||
if (mouseButton == LEFT) {
|
||||
boolean clickUI = false;
|
||||
|
||||
|
||||
if (mouseX >= i_uiX && mouseX <= i_uiX+i_uiW && mouseY >= i_uiY-10 && mouseY <= i_uiY+10) { //drag and drop debug window size
|
||||
b_mouseChangeUiHeight = true;
|
||||
i_uiOffsetStartY = mouseY;
|
||||
i_initUiY = i_uiY;
|
||||
} else if (mouseX >= i_uiX+i_uiW-135 && mouseX <= i_uiX+i_uiW-135+120 //autoplay button
|
||||
&& mouseY >= i_uiY+i_debugTextSize/2-5 && mouseY <= i_uiY+i_debugTextSize/2+i_debugTextSize+5) {
|
||||
//if (b_autoPlayAfterSelect) {
|
||||
// citizen[i_selectedCitizen].b_moving = false;
|
||||
// citizen[i_selectedCitizen].b_randomRun = false;
|
||||
//}
|
||||
citizen[i_selectedCitizen].b_moving = !citizen[i_selectedCitizen].b_moving;
|
||||
citizen[i_selectedCitizen].b_randomRun = !citizen[i_selectedCitizen].b_randomRun;
|
||||
b_autoPlayAfterSelect = !b_autoPlayAfterSelect;
|
||||
} else if (mouseX >= i_uiX+i_uiW-135 && mouseX <= i_uiX+i_uiW-135+120 //autoplay button
|
||||
&& mouseY >= i_uiY+i_debugTextSize/2+1.41*i_debugTextSize+i_debugTextSize/2-5 && mouseY <= i_uiY+i_debugTextSize/2+1.41*i_debugTextSize+i_debugTextSize/2+i_debugTextSize+5) {
|
||||
b_cameraFollow = !b_cameraFollow;
|
||||
} else {
|
||||
clickUI = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
if (buttons[i].hover()) {
|
||||
buttons[i].click();
|
||||
clickUI = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!clickUI) {
|
||||
int selectedCitizen = i_selectedCitizen; //leftclick select citizen
|
||||
for (int i = 0; i < citizen.length; i++) {
|
||||
if (selectedCitizen != i) {
|
||||
@@ -127,7 +201,7 @@ void mousePressed() {
|
||||
citizen[i_selectedCitizen].b_randomRun = false;
|
||||
citizen[i_selectedCitizen].b_moving = false;
|
||||
}
|
||||
citizen[i_selectedCitizen].goTo(constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height));
|
||||
citizen[i_selectedCitizen].goTo(constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height), 10);
|
||||
}
|
||||
}
|
||||
int i_mapViewToMap(int mouse, int offset) {
|
||||
@@ -144,6 +218,9 @@ void mouseDragged() {
|
||||
i_uiY = mouseY - i_uiOffsetStartY + i_initUiY;
|
||||
if (i_uiY > height) i_uiY = height;
|
||||
i_uiH = height - i_uiY;
|
||||
|
||||
|
||||
//hook buttons to ui panel
|
||||
}
|
||||
}
|
||||
void mouseReleased() {
|
||||
|
||||
Reference in New Issue
Block a user