Files
citizen/UI.pde
2019-01-15 02:36:01 +01:00

144 lines
3.9 KiB
Plaintext

int i_uiTransparency = 200;
void initUI() {
i_uiX = 0;
i_uiY = 520;
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);
String[] debug = {
"FPS: " + int(frameRate),
" ",
"Selected Citizen ID: " + i_selectedCitizen,
"Name: " + citizen[i_selectedCitizen].S_name,
"x: " + citizen[i_selectedCitizen].f_xPos + " y: " + citizen[i_selectedCitizen].f_yPos,
"Movement speed: " + citizen[i_selectedCitizen].f_movementSpeed,
"Velocity: ",
"Outside",
"Mood: "
};
int ts = i_debugTextSize;
textSize(ts);
int line = 0;
int maxLinesPerColumn = i_uiH/ts;
if (maxLinesPerColumn > 0) {
int requiredColumns = (debug.length/maxLinesPerColumn)+1;
for (int i = 0; i < requiredColumns; i++) {
while (((line-(maxLinesPerColumn*i)) * ts + ts)+i_uiY<height && line < debug.length) {
text(debug[line], 10+(150*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);
}
}
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) {
b_mouseChangeUiHeight = true;
i_uiOffsetStartY = mouseY;
i_initUiY = i_uiY;
} else {
int selectedCitizen = i_selectedCitizen;
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) {
b_mouseChangeMapOffset = true;
i_mapOffsetStartX = mouseX - i_mapOffsetX;
i_mapOffsetStartY = mouseY - i_mapOffsetY;
}
if (mouseButton == RIGHT) {
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;
}
}