402 lines
12 KiB
Plaintext
402 lines
12 KiB
Plaintext
int i_uiX, i_uiY, i_uiW, i_uiH;
|
|
int i_uiOffsetX, i_uiOffsetY, i_uiOffsetStartX, i_uiOffsetStartY, i_initUiY;
|
|
|
|
|
|
float f_mouseZoomEvent;
|
|
boolean b_mapZoom;
|
|
|
|
int i_debugTextSize = 10;
|
|
int i_debugButtonWidth = 100;
|
|
int i_debugButtonHeight = i_debugTextSize;
|
|
int i_debugButtonCorner = 5;
|
|
int i_debugButtonPadding = 10;
|
|
int i_debugButtonMenuPadding = 15;
|
|
int i_debugButtonMenuX = 15;
|
|
int i_debugButtonMenuY = 150;
|
|
int i_debugButtonMenuW = i_debugButtonWidth + 2 * i_debugButtonMenuPadding;
|
|
int i_debugButtonMenuH;
|
|
int i_debugButtonMenuButtonC;
|
|
|
|
float f_timeBoxCenterX;
|
|
float f_timeBoxX;
|
|
float f_timeBoxY;
|
|
float f_timeBoxW;
|
|
float f_timeBoxH = 34;
|
|
float f_timeBoxCorner = 6;
|
|
|
|
int i_iconX, i_iconY, i_iconW, i_iconH, i_iconCorner;
|
|
|
|
|
|
|
|
int i_uiTransparency = 200;
|
|
String s_timeString;
|
|
|
|
boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
|
|
boolean b_hoverUI;
|
|
int i_changeTimeMouseX;
|
|
boolean b_drag;
|
|
|
|
boolean b_selectCitizen; //?????
|
|
|
|
PImage img_help, img_spectate, img_control, img_magplus, img_magminus;
|
|
|
|
boolean b_control; //?????
|
|
|
|
int i_mapViewToMap(int mouse, int offset) {
|
|
if (b_mapZoom) return (mouse-offset)*2;
|
|
else return mouse-offset;
|
|
}
|
|
|
|
|
|
boolean b_showingHelp;
|
|
void showHelp() {
|
|
if (!b_showingHelp) {
|
|
b_showingHelp = true;
|
|
buttons[6].b_active = true;
|
|
if (buttons[2].b_active) buttons[2].click();
|
|
if (buttons[5].b_active) buttons[5].click();
|
|
selectCitizen(0);
|
|
}
|
|
}
|
|
|
|
|
|
void spectate() {
|
|
b_control = false;
|
|
b_controlEyeWithMouse = false;
|
|
citizen[i_selectedCitizen].b_randomRun = true;
|
|
citizen[i_selectedCitizen].b_moving = true;
|
|
citizen[i_selectedCitizen].goToRandom();
|
|
}
|
|
void control() {
|
|
b_control = true;
|
|
if (i_selectedCitizen == 0) selectCitizen((int)random(0, citizen.length));
|
|
b_cameraLock = true;
|
|
b_controlEyeWithMouse = true;
|
|
if(buttons[4].b_active) buttons[4].click();
|
|
zoomIn();
|
|
citizen[i_selectedCitizen].b_randomRun = false;
|
|
citizen[i_selectedCitizen].b_moving = false;
|
|
}
|
|
void zoomOut() {
|
|
if (!b_mapZoom) {
|
|
i_mapW = pg_map.width/2;
|
|
i_mapH = pg_map.height/2;
|
|
i_mapOffsetX = 0;
|
|
i_mapOffsetY = 0;
|
|
b_mapZoom = true;
|
|
}
|
|
}
|
|
void zoomIn() {
|
|
i_mapW = pg_map.width;
|
|
i_mapH = pg_map.height;
|
|
i_mapOffsetX -= 3*i_mapOffsetX/4;
|
|
i_mapOffsetY -= 3*i_mapOffsetY/4;
|
|
b_mapZoom = false;
|
|
}
|
|
|
|
|
|
void initUI() {
|
|
img_help = loadImage(dataPath("icons/icon_help.png"));
|
|
img_spectate = loadImage(dataPath("icons/icon_spectate.png"));
|
|
img_control = loadImage(dataPath("icons/icon_control.png"));
|
|
img_magplus = loadImage(dataPath("icons/icon_magplus.png"));
|
|
img_magminus = loadImage(dataPath("icons/icon_magminus.png"));
|
|
|
|
i_uiX = 0;
|
|
i_uiY = 518;
|
|
i_uiW = width;
|
|
i_uiH = height - i_uiY;
|
|
|
|
i_iconX = int(1.2*i_windowW/20);
|
|
i_iconY = 10+i_windowW/40;
|
|
i_iconW = i_windowW/20;
|
|
i_iconH = i_windowW/20;
|
|
i_iconCorner = i_windowW/40;
|
|
|
|
initButtons();
|
|
|
|
i_debugButtonMenuH = i_debugButtonMenuButtonC * i_debugButtonHeight + (i_debugButtonMenuButtonC - 1) * i_debugButtonPadding + 2 * i_debugButtonMenuPadding;
|
|
|
|
f_timeBoxY = 10;
|
|
f_timeBoxW = 191;
|
|
f_timeBoxCenterX = i_windowW/2;
|
|
f_timeBoxX = f_timeBoxCenterX-f_timeBoxW / 2;
|
|
}
|
|
|
|
|
|
|
|
void drawUI() {
|
|
//draw
|
|
//citizenInfo
|
|
if (i_selectedCitizen != 0) {
|
|
stroke(5);
|
|
fill(200, 220);
|
|
rect(60, 200, 250, 350);
|
|
strokeWeight(0);
|
|
fill(0);
|
|
textSize(40);
|
|
text(citizen[i_selectedCitizen].s_name, 80,250);
|
|
textSize(25);
|
|
text(citizen[i_selectedCitizen].s_gender, 80,290);
|
|
text("Alter: " + citizen[i_selectedCitizen].i_age, 80,320);
|
|
fill(citizen[i_selectedCitizen].c_color);
|
|
rect(100,350,175,175);
|
|
}
|
|
//help menu
|
|
if (b_showingHelp) {
|
|
|
|
rectMode(CENTER);
|
|
fill(255, 180);
|
|
rect(width/2, height/2, 570, 770, 20);
|
|
rectMode(CORNER);
|
|
imageMode(CENTER);
|
|
image(img_helptext, width/2, height/2);
|
|
imageMode(CORNER);
|
|
}
|
|
//debug button-menu
|
|
if (!b_rundgang) {
|
|
stroke(1);
|
|
fill(127, 127, 127, 127);
|
|
rect(i_debugButtonMenuX, i_debugButtonMenuY, i_debugButtonMenuW, i_debugButtonMenuH);
|
|
strokeWeight(0);
|
|
textSize(i_debugTextSize);
|
|
for (int i = 0; i < debugButtons.length; i++) {
|
|
debugButtons[i].display();
|
|
}
|
|
}
|
|
noStroke();
|
|
//normal buttons
|
|
for (int i = 0; i < buttons.length; i++) {
|
|
buttons[i].display();
|
|
}
|
|
//icons
|
|
imageMode(CENTER);
|
|
image(img_help, i_iconX, i_iconY, i_iconW, i_iconH);
|
|
if (buttons[2].b_active) image(img_spectate, 2* i_iconX, i_iconY, i_iconW, i_iconH);
|
|
if (buttons[3].b_active) image(img_control, 2* i_iconX, i_iconY, i_iconW, i_iconH);
|
|
if (buttons[4].b_active) image(img_magplus, 3* i_iconX, i_iconY, i_iconW, i_iconH);
|
|
if (buttons[5].b_active) image(img_magminus, 3* i_iconX, i_iconY, i_iconW, i_iconH);
|
|
|
|
imageMode(CORNER);
|
|
//camera tracking
|
|
if (b_cameraLock) {
|
|
if (i_selectedCitizen != 0) {
|
|
if (b_mapZoom) {
|
|
i_mapOffsetX = i_windowW/2-int(citizen[i_selectedCitizen].f_xPos)/2;
|
|
i_mapOffsetY = i_windowH/2-int(citizen[i_selectedCitizen].f_yPos)/2;
|
|
} else {
|
|
i_mapOffsetX = i_windowW/2-int(citizen[i_selectedCitizen].f_xPos);
|
|
i_mapOffsetY = i_windowH/2-int(citizen[i_selectedCitizen].f_yPos);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//buttons[buttons.length-1].display();
|
|
|
|
//clock
|
|
if (b_realTime) {
|
|
s_timeString = "Tag " + i_days + ", " + String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second());
|
|
} else {
|
|
s_timeString = "Tag " + i_days + ", " + nf(i_hours, 2, 0) + ":" + nf(i_minutes, 2, 0);
|
|
}
|
|
|
|
fill(255, i_uiTransparency);
|
|
rect(f_timeBoxX, f_timeBoxY, f_timeBoxW, f_timeBoxH, f_timeBoxCorner);
|
|
fill(0);
|
|
textSize(30);
|
|
text(s_timeString, f_timeBoxX+3, f_timeBoxY - 8 + f_timeBoxH);
|
|
|
|
//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,
|
|
"Loation: " + (citizen[i_selectedCitizen].i_location == 0 ? "home / heading home" : "outside"),
|
|
"x: " + int(citizen[i_selectedCitizen].f_xPos),
|
|
"y: " + int(citizen[i_selectedCitizen].f_yPos),
|
|
"Angle: " + citizen[i_selectedCitizen].f_angle,
|
|
"Moving: " + citizen[i_selectedCitizen].b_moving,
|
|
"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_autoPlay,
|
|
"Locked Camera: " + b_cameraLock,
|
|
"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<i_windowH && line < debug.length) {
|
|
text(debug[line], 10+(columnWidth*i), i_uiY+(i_debugTextSize*((line-(maxLinesPerColumn*i))+1)));
|
|
line++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void keyPressed() {
|
|
if (key == 'r') {
|
|
b_rundgang = !b_rundgang;
|
|
}
|
|
if (key == 's') {
|
|
save("screenshot.png" + str(millis()));
|
|
}
|
|
}
|
|
|
|
void mousePressed() {
|
|
if (mouseButton == LEFT) {
|
|
boolean clickUI = false;
|
|
// click buttons
|
|
|
|
b_triggerButton = false; //bad
|
|
for (int i = 0; i < buttons.length; i++) {
|
|
if (buttons[i].hover()) {
|
|
buttons[i].click();
|
|
clickUI = true;
|
|
}
|
|
}
|
|
if (!b_rundgang) {
|
|
for (int i = 0; i < debugButtons.length; i++) {
|
|
if (debugButtons[i].hover()) {
|
|
debugButtons[i].click();
|
|
clickUI = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
//drag and drop debug window size
|
|
if (mouseX >= i_uiX && mouseX <= i_uiX+i_uiW && mouseY >= i_uiY-10 && mouseY <= i_uiY+10) {
|
|
b_mouseChangeUiHeight = true;
|
|
i_uiOffsetStartY = mouseY;
|
|
i_initUiY = i_uiY;
|
|
clickUI = true;
|
|
}
|
|
|
|
if (!b_rundgang) {
|
|
if (mouseX > f_timeBoxX && mouseX < f_timeBoxX + f_timeBoxW && mouseY > f_timeBoxY && mouseY < f_timeBoxY + f_timeBoxH) { //drag time
|
|
clickUI = true;
|
|
i_changeTimeMouseX = mouseX;
|
|
b_changeTime = true;
|
|
}
|
|
}
|
|
|
|
if (!clickUI) {
|
|
if ( !b_control) {
|
|
int selectedCitizen = i_selectedCitizen; //leftclick select citizen
|
|
b_selectCitizen = false;
|
|
for (int i = 0; i < citizen.length; i++) {
|
|
if (selectedCitizen != i) {
|
|
if (i_mapViewToMap(mouseX, i_mapOffsetX)+30 >= citizen[i].f_xPos - citizen[i].i_diameter/2 && i_mapViewToMap(mouseX, i_mapOffsetX)-30 <= citizen[i].f_xPos + citizen[i].i_diameter/2
|
|
&& i_mapViewToMap(mouseY, i_mapOffsetY)+30 >= citizen[i].f_yPos - citizen[i].i_diameter/2 && i_mapViewToMap(mouseY, i_mapOffsetY)-30 <= citizen[i].f_yPos + citizen[i].i_diameter/2) {
|
|
b_selectCitizen = true;
|
|
selectCitizen(i);
|
|
//zoom in? no
|
|
}
|
|
}
|
|
}
|
|
if (!b_selectCitizen) {
|
|
//buttonFunctions(2, false);
|
|
selectCitizen(0);
|
|
}
|
|
if (!b_rundgang) {
|
|
if (!b_cameraLock || i_selectedCitizen == 0) {
|
|
b_mouseChangeMapOffset = true;
|
|
i_mapOffsetStartX = mouseX - i_mapOffsetX;
|
|
i_mapOffsetStartY = mouseY - i_mapOffsetY;
|
|
}
|
|
}
|
|
} else {
|
|
citizen[i_selectedCitizen].goTo(constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height));
|
|
}
|
|
}
|
|
}
|
|
if (mouseButton == CENTER) {
|
|
if (!b_rundgang) {
|
|
if (!b_cameraLock || i_selectedCitizen == 0) {
|
|
b_mouseChangeMapOffset = true;
|
|
i_mapOffsetStartX = mouseX - i_mapOffsetX;
|
|
i_mapOffsetStartY = mouseY - i_mapOffsetY;
|
|
}
|
|
}
|
|
}
|
|
if (mouseButton == RIGHT && !b_rundgang) {
|
|
if (!citizen[i_selectedCitizen].b_talking && i_selectedCitizen != 0) {
|
|
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].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);
|
|
}
|
|
}
|
|
}
|
|
|
|
void mouseDragged() {
|
|
b_drag = true;
|
|
if (!b_rundgang) {
|
|
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 = i_windowH;
|
|
i_uiH = i_windowH - i_uiY;
|
|
//hook buttons to ui panel
|
|
}
|
|
if (b_changeTime) {
|
|
i_flexibleTime += mouseX-i_changeTimeMouseX;
|
|
i_changeTimeMouseX = mouseX;
|
|
}
|
|
}
|
|
}
|
|
void mouseReleased() {
|
|
b_mouseChangeMapOffset = false;
|
|
b_mouseChangeUiHeight = false;
|
|
b_changeTime = false;
|
|
//if (i_mapOffsetStartX == mouseX-i_mapOffsetX && i_mapOffsetStartY == mouseY-i_mapOffsetY && !b_drag && !b_selectCitizen) {//only click, no drag
|
|
// selectCitizen(0);
|
|
//}
|
|
b_drag = false;
|
|
//b_selectCitizen = false;
|
|
}
|
|
|
|
void mouseWheel(MouseEvent event) {
|
|
if (!b_rundgang) {
|
|
f_mouseZoomEvent= event.getAmount();
|
|
|
|
|
|
switch((int)f_mouseZoomEvent) {
|
|
case 1:
|
|
zoomOut();
|
|
break;
|
|
case -1:
|
|
zoomIn();
|
|
break;
|
|
}
|
|
}
|
|
}
|