123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
-
- Button buttons[] = new Button[4];
-
-
- 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);
- buttons[3] = new Button(15, 110, 100, i_debugTextSize, 5, "Control Eyes", 3);
- }
-
-
- int i_uiX, i_uiY, i_uiW, i_uiH;
- int i_uiOffsetX, i_uiOffsetY, i_uiOffsetStartX, i_uiOffsetStartY, i_initUiY;
- void drawUI() {
-
- //camera tracking
- if (b_cameraFollow) {
- if (b_mapZoom) {
- i_mapOffsetX = width/2-int(citizen[i_selectedCitizen].f_xPos)/2;
- i_mapOffsetY = height/2-int(citizen[i_selectedCitizen].f_yPos)/2;
- } else {
- i_mapOffsetX = width/2-int(citizen[i_selectedCitizen].f_xPos);
- i_mapOffsetY = height/2-int(citizen[i_selectedCitizen].f_yPos);
- }
- }
-
- //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
- 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,
- "Turning: " + citizen[i_selectedCitizen].b_turning,
- " ",
- "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++;
- }
- }
- }
- }
- }
-
-
- 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):
- b_controlEyeWithMouse = !b_controlEyeWithMouse;
- 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;
- 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) {
- if (i_mapViewToMap(mouseX, i_mapOffsetX)+10 >= citizen[i].f_xPos - citizen[i].i_diameter/2 && i_mapViewToMap(mouseX, i_mapOffsetX)-10 <= citizen[i].f_xPos + citizen[i].i_diameter/2
- && i_mapViewToMap(mouseY, i_mapOffsetY)+10 >= citizen[i].f_yPos - citizen[i].i_diameter/2 && i_mapViewToMap(mouseY, i_mapOffsetY)-10 <= citizen[i].f_yPos + citizen[i].i_diameter/2) {
- selectCitizen(i);
- }
- }
- }
- }
- }
- if (mouseButton == CENTER) {
- if (!b_cameraFollow) {
- b_mouseChangeMapOffset = true;
- i_mapOffsetStartX = mouseX - i_mapOffsetX;
- i_mapOffsetStartY = mouseY - i_mapOffsetY;
- }
- }
- if (mouseButton == RIGHT) {
- // if(citizen[i_selectedCitizen].hover){
- //}
- if (!b_autoPlayAfterSelect) {
- 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), 10);
- citizen[i_selectedCitizen].turnTo(citizen[i_selectedCitizen].f_xPos-constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), citizen[i_selectedCitizen].f_yPos-constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height),4);
- }
- }
- int i_mapViewToMap(int mouse, int offset) {
- if (b_mapZoom) return (mouse-offset)*2;
- else return mouse-offset;
- }
-
- void mouseDragged() {
- if (b_mouseChangeMapOffset) {
- i_mapOffsetX = (mouseX - i_mapOffsetStartX);
- i_mapOffsetY = (mouseY - i_mapOffsetStartY);
- }
- if (b_mouseChangeUiHeight) {
- 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() {
- b_mouseChangeMapOffset = false;
- b_mouseChangeUiHeight = false;
- }
-
-
- //bad
- //int maxScale = 5;
- //float zoomFactor = 0.4;
- //int i_imgCenterX;
- //int i_imgCenterY;
- int i_mapScale = 1;
- boolean b_mapZoom;
- float e;
- void mouseWheel(MouseEvent event) {
- e = event.getAmount();
-
- if (e == -1) {
- i_mapScale+=1;
- }
- if (e == 1) {
- i_mapScale-=1;
- }
- constrain(i_mapScale, 0, 2);
- switch(int(e)) {
- case 1:
- if (!b_mapZoom) {
- i_mapW = pg_map.width/2;
- i_mapH = pg_map.height/2;
- i_mapOffsetX -= 3*i_mapOffsetX/4;
- i_mapOffsetY -= 3*i_mapOffsetY/4;
- b_mapZoom = true;
- }
- break;
- case -1:
- i_mapW = pg_map.width;
- i_mapH = pg_map.height;
- b_mapZoom = false;
- break;
- }
- }
|