190 lines
6.2 KiB
Plaintext
190 lines
6.2 KiB
Plaintext
|
|
int i_uiTransparency = 200;
|
|
void initUI() {
|
|
i_uiX = 0;
|
|
i_uiY = 518;
|
|
i_uiW = width;
|
|
i_uiH = height - i_uiY;
|
|
}
|
|
|
|
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) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
//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,
|
|
" ",
|
|
"Global",
|
|
" ",
|
|
"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++;
|
|
}
|
|
}
|
|
//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);
|
|
}
|
|
|
|
boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
|
|
boolean b_hoverUI;
|
|
|
|
void mousePressed() {
|
|
if (mouseButton == LEFT) {
|
|
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 {
|
|
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 (!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));
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|