summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-21 17:41:04 +0000
committertruelight <truelight@openttd.org>2006-08-21 17:41:04 +0000
commitd95a3d9879726340cf271041bb3c78b049c90eec (patch)
treebf2bfe424cc78c0728f807566e4ac604ca593fe8
parent24d703808f916382ebb839f561d802aeb89125db (diff)
downloadopenttd-d95a3d9879726340cf271041bb3c78b049c90eec.tar.xz
(svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
-Add: when clicking twice in SmallMap on a position, it centers there (based on FS#54 by thomasdev) -Add: add a button in SmallMap that centers the SmallMap on your current position (based on FS#54 by thomasdev)
-rw-r--r--lang/english.txt2
-rw-r--r--smallmap_gui.c76
-rw-r--r--viewport.c16
3 files changed, 65 insertions, 29 deletions
diff --git a/lang/english.txt b/lang/english.txt
index 09f091d8e..c4ede5b9e 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -2954,6 +2954,8 @@ STR_FLAT_WORLD_HEIGHT_QUERY_CAPT :{WHITE}Change h
STR_FLAT_WORLD_HEIGHT :{BLACK}Height of flat land:
STR_FLAT_WORLD_HEIGHT_NUM :{NUM}
+STR_SMALLMAP_CENTER :{BLACK}Center the smallmap on the current position
+
########### String for new airports
STR_SMALL_AIRPORT :{BLACK}Small
STR_CITY_AIRPORT :{BLACK}City
diff --git a/smallmap_gui.c b/smallmap_gui.c
index de733d576..1491f0be9 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -36,7 +36,7 @@ static const Widget _smallmap_widgets[] = {
{ WWT_IMGBTN, RESIZE_LRTB, 13, 380, 401, 280, 301, SPR_IMG_SHOW_ROUTES, STR_0194_SHOW_TRANSPORT_ROUTES_ON},
{ WWT_IMGBTN, RESIZE_LRTB, 13, 402, 423, 280, 301, SPR_IMG_PLANTTREES, STR_0195_SHOW_VEGETATION_ON_MAP},
{ WWT_IMGBTN, RESIZE_LRTB, 13, 424, 445, 280, 301, SPR_IMG_COMPANY_GENERAL, STR_0196_SHOW_LAND_OWNERS_ON_MAP},
-{ WWT_IMGBTN, RESIZE_LRTB, 13, 358, 379, 258, 279, 0x0, STR_NULL},
+{ WWT_IMGBTN, RESIZE_LRTB, 13, 358, 379, 258, 279, SPR_IMG_SMALLMAP, STR_SMALLMAP_CENTER},
{ WWT_IMGBTN, RESIZE_LRTB, 13, 358, 379, 280, 301, SPR_IMG_TOWN, STR_0197_TOGGLE_TOWN_NAMES_ON_OFF},
{ WWT_IMGBTN, RESIZE_RTB, 13, 0, 357, 258, 301, 0x0, STR_NULL},
{ WWT_PANEL, RESIZE_RTB, 13, 0, 433, 302, 313, 0x0, STR_NULL},
@@ -792,6 +792,19 @@ skip_column:
_cur_dpi = old_dpi;
}
+void SmallMapCenterOnCurrentPos(Window *w)
+{
+ int x, y;
+ ViewPort *vp;
+ vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
+
+ x = ((vp->virtual_width - (w->widget[4].right - w->widget[4].left) * TILE_SIZE) / 2 + vp->virtual_left) / 4;
+ y = ((vp->virtual_height - (w->widget[4].bottom - w->widget[4].top ) * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2;
+ WP(w, smallmap_d).scroll_x = (y - x) & ~0xF;
+ WP(w, smallmap_d).scroll_y = (x + y) & ~0xF;
+ SetWindowDirty(w);
+}
+
static void SmallMapWindowProc(Window *w, WindowEvent *e)
{
switch (e->event) {
@@ -833,25 +846,32 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch (e->click.widget) {
- case 4: {/* Main wnd */
- Window *w2;
+ case 4: { // Map window
+ Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0);
Point pt;
+ int x, y;
- _left_button_clicked = false;
+ pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0);
+ x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1);
+ y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1);
- w2 = FindWindowById(WC_MAIN_WINDOW, 0);
+ /* If you press twice on a place in the smallmap, center there */
+ if (WP(w2, vp_d).scrollpos_x == x && WP(w2, vp_d).scrollpos_y == y) {
+ SmallMapCenterOnCurrentPos(w);
+ } else {
+ WP(w2, vp_d).scrollpos_x = x;
+ WP(w2, vp_d).scrollpos_y = y;
+ }
- pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0);
- WP(w2,vp_d).scrollpos_x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1);
- WP(w2,vp_d).scrollpos_y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1);
+ SetWindowDirty(w);
} break;
- case 5: /* Show land contours */
- case 6: /* Show vehicles */
- case 7: /* Show industries */
- case 8: /* Show transport routes */
- case 9: /* Show vegetation */
- case 10: /* Show land owners */
+ case 5: // Show land contours
+ case 6: // Show vehicles
+ case 7: // Show industries
+ case 8: // Show transport routes
+ case 9: // Show vegetation
+ case 10: // Show land owners
w->click_state &= ~(1<<5|1<<6|1<<7|1<<8|1<<9|1<<10);
w->click_state |= 1 << e->click.widget;
_smallmap_type = e->click.widget - 5;
@@ -860,9 +880,17 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e)
SndPlayFx(SND_15_BEEP);
break;
- case 12: /* toggle town names */
+ case 11: // Center the smallmap again
+ SmallMapCenterOnCurrentPos(w);
+
+ SetWindowDirty(w);
+ SndPlayFx(SND_15_BEEP);
+ break;
+
+ case 12: // Toggle town names
w->click_state ^= (1 << 12);
_smallmap_show_towns = (w->click_state >> 12) & 1;
+
SetWindowDirty(w);
SndPlayFx(SND_15_BEEP);
break;
@@ -957,23 +985,15 @@ static const WindowDesc _smallmap_desc = {
void ShowSmallMap(void)
{
Window *w;
- ViewPort *vp;
- int x,y;
w = AllocateWindowDescFront(&_smallmap_desc, 0);
- if (w != NULL) {
- w->click_state = ((1<<5) << _smallmap_type) | (_smallmap_show_towns << 12);
- w->resize.width = 350;
- w->resize.height = 250;
+ if (w == NULL) return;
- vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
+ w->click_state = ((1 << 5) << _smallmap_type) | (_smallmap_show_towns << 12);
+ w->resize.width = 350;
+ w->resize.height = 250;
- x = ((vp->virtual_width - 220 * 32) / 2 + vp->virtual_left) / 4;
- y = ((vp->virtual_height - 120 * 32) / 2 + vp->virtual_top ) / 2 - 32;
- WP(w,smallmap_d).scroll_x = (y - x) & ~0xF;
- WP(w,smallmap_d).scroll_y = (x + y) & ~0xF;
- WP(w,smallmap_d).subscroll = 0;
- }
+ SmallMapCenterOnCurrentPos(w);
}
/* Extra ViewPort Window Stuff */
diff --git a/viewport.c b/viewport.c
index ed22304ce..041d2b286 100644
--- a/viewport.c
+++ b/viewport.c
@@ -1788,7 +1788,21 @@ bool ScrollWindowTo(int x , int y, Window *w)
bool ScrollMainWindowTo(int x, int y)
{
- return ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
+ Window *w;
+ bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
+
+ /* If a user scrolls to a tile (via what way what so ever) and already is on
+ * that tile (e.g.: pressed twice), move the smallmap to that location,
+ * so you directly see where you are on the smallmap. */
+
+ if (res) return res;
+
+ w = FindWindowById(WC_SMALLMAP, 0);
+ if (w == NULL) return res;
+
+ SmallMapCenterOnCurrentPos(w);
+
+ return res;
}