123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- void initUI() {
- i_uiX = 0;
- i_uiY = 420;
- 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, 230);
- rect(i_uiX, i_uiY, i_uiW, i_uiH);
-
-
- fill(0);
- textSize(30);
- textAlign(LEFT);
- text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
-
- textSize(15);
- text("FPS: " + int(frameRate), 10, i_uiY + 15);
- }
-
- 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 {
- }
- }
- if (mouseButton == CENTER) {
- b_mouseChangeMapOffset = true;
- i_mapOffsetStartX = mouseX - i_mapOffsetX;
- i_mapOffsetStartY = mouseY - i_mapOffsetY;
- }
- if (mouseButton == RIGHT) {
- if (b_mapZoom)
- citizen[0].goTo(constrain((mouseX-i_mapOffsetX)*2, 0, pg_map.width), constrain((mouseY-i_mapOffsetY)*2, 0, pg_map.height));
- else
- citizen[0].goTo(constrain(mouseX-i_mapOffsetX, 0, pg_map.width), constrain(mouseY-i_mapOffsetY, 0, pg_map.height));
- }
- }
- 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;
- }
- }
|