diff options
-rw-r--r-- | lang/english.txt | 4 | ||||
-rw-r--r-- | main_gui.c | 4 | ||||
-rw-r--r-- | settings.c | 2 | ||||
-rw-r--r-- | settings_gui.c | 41 | ||||
-rw-r--r-- | variables.h | 2 | ||||
-rw-r--r-- | window.c | 31 | ||||
-rw-r--r-- | window.h | 1 |
7 files changed, 73 insertions, 12 deletions
diff --git a/lang/english.txt b/lang/english.txt index 25b8cf8e9..3d525d678 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -1000,6 +1000,10 @@ STR_CONFIG_PATCHES_COLORED_NEWS_DATE :{LTBLUE}Coloured news appears in: {ORANGE} STR_CONFIG_PATCHES_STARTING_DATE :{LTBLUE}Starting date: {ORANGE}{STRING} STR_CONFIG_PATCHES_SMOOTH_ECONOMY :{LTBLUE}Enable smooth economy (more, smaller changes) STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY :{LTBLUE}When dragging place signals every: {ORANGE}{STRING} tile(s) +STR_CONFIG_PATCHES_TOOLBAR_POS :{LTBLUE}Position of maintoolbar: {ORANGE}{STRING} +STR_CONFIG_PATCHES_TOOLBAR_POS_LEFT :Left +STR_CONFIG_PATCHES_TOOLBAR_POS_CENTER :Center +STR_CONFIG_PATCHES_TOOLBAR_POS_RIGHT :Right STR_CONFIG_PATCHES_GUI :{BLACK}Interface STR_CONFIG_PATCHES_CONSTRUCTION :{BLACK}Construction diff --git a/main_gui.c b/main_gui.c index f6bae51c1..4e80b4b9e 100644 --- a/main_gui.c +++ b/main_gui.c @@ -2207,6 +2207,8 @@ void SetupColorsAndInitialWindow() w = AllocateWindowDesc(&_toolb_normal_desc); w->disabled_state = 1 << 17; w->flags4 &= ~WF_WHITE_BORDER_MASK; + + PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_normal_desc) _main_status_desc.top = height - 12; w = AllocateWindowDesc(&_main_status_desc); @@ -2222,6 +2224,8 @@ void SetupColorsAndInitialWindow() w = AllocateWindowDesc(&_toolb_scen_desc); w->disabled_state = 1 << 9; w->flags4 &= ~WF_WHITE_BORDER_MASK; + + PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_scen_desc) break; default: NOT_REACHED(); diff --git a/settings.c b/settings.c index d58f07c78..8e5ef88aa 100644 --- a/settings.c +++ b/settings.c @@ -826,6 +826,8 @@ static const SettingDesc patch_settings[] = { {"nonuniform_stations", SDT_BOOL, (void*)false, (void*)offsetof(Patches, nonuniform_stations)}, {"always_small_airport", SDT_BOOL, (void*)false, (void*)offsetof(Patches, always_small_airport)}, {"realistic_acceleration", SDT_BOOL, (void*)false, (void*)offsetof(Patches, realistic_acceleration)}, + + {"toolbar_pos", SDT_UINT8, (void*)0, (void*)offsetof(Patches, toolbar_pos)}, {"max_trains", SDT_UINT8, (void*)80,(void*)offsetof(Patches, max_trains)}, {"max_roadveh", SDT_UINT8, (void*)80,(void*)offsetof(Patches, max_roadveh)}, diff --git a/settings_gui.c b/settings_gui.c index 578fe264e..48eaa5b83 100644 --- a/settings_gui.c +++ b/settings_gui.c @@ -661,13 +661,28 @@ void ShowHighscoreTable(int tbl) ShowInfoF("ShowHighscoreTable(%d) not implemented", tbl); } +// virtual PositionMainToolbar function, calls the right one. +int32 v_PositionMainToolbar(int32 p1) +{ + if (_game_mode != GM_MENU) + PositionMainToolbar(NULL); + + return 0; +} + +typedef int32 PatchButtonClick(int32); +static PatchButtonClick * const _patch_button_proc[] = { + &v_PositionMainToolbar, +}; + typedef struct PatchEntry { - byte type; // type of selector - byte flags; // selector flags - StringID str; // string with descriptive text - void *variable; // pointer to the variable - int32 min,max; // range for spinbox setting - uint32 step; // step for spinbox + byte type; // type of selector + byte flags; // selector flags + StringID str; // string with descriptive text + void *variable; // pointer to the variable + int32 min,max; // range for spinbox setting + uint32 step; // step for spinbox + PatchButtonClick *click_proc; // callback procedure } PatchEntry; enum { @@ -691,6 +706,7 @@ static const PatchEntry _patches_ui[] = { {PE_UINT8, 0, STR_CONFIG_PATCHES_ERRMSG_DURATION, &_patches.errmsg_duration, 0, 20, 1}, + {PE_UINT8, PF_MULTISTRING, STR_CONFIG_PATCHES_TOOLBAR_POS, &_patches.toolbar_pos, 0, 2, 1, &v_PositionMainToolbar}, }; static const PatchEntry _patches_construction[] = { @@ -927,7 +943,7 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) x = e->click.pt.x - 5; if (x < 0) return; - if (x < 21) { + if (x < 21) { // clicked on the icon on the left side. Either scroller or bool on/off int32 val = ReadPE(pe), oval = val; switch(pe->type) { @@ -972,9 +988,12 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) if (val != oval) { WritePE(pe, val); SetWindowDirty(w); + + if (pe->click_proc != NULL) // call callback function + pe->click_proc(val); } } else { - if (pe->type != PE_BOOL) { + if (pe->type != PE_BOOL && !(pe->flags & PF_MULTISTRING)) { // do not open editbox WP(w,def_d).data_3 = btn; SET_DPARAM32(0, ReadPE(pe)); ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, WC_GAME_OPTIONS, 0); @@ -999,8 +1018,12 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) case WE_ON_EDIT_TEXT: { if (*e->edittext.str) { const PatchPage *page = &_patches_page[WP(w,def_d).data_1]; - WritePE(&page->entries[WP(w,def_d).data_3], atoi(e->edittext.str)); + const PatchEntry *pe = &page->entries[WP(w,def_d).data_3]; + WritePE(pe, atoi(e->edittext.str)); SetWindowDirty(w); + + if (pe->click_proc != NULL) // call callback function + pe->click_proc(*(int32*)pe->variable); } break; } diff --git a/variables.h b/variables.h index 9efd25bca..cc8b6acc9 100644 --- a/variables.h +++ b/variables.h @@ -109,6 +109,8 @@ typedef struct Patches { bool nonuniform_stations;// allow nonuniform train stations bool always_small_airport; // always allow small airports bool realistic_acceleration; // realistic acceleration for trains + + uint8 toolbar_pos; // position of toolbars, 0=left, 1=center, 2=right byte max_trains; //max trains in game per player (these are 8bit because the unitnumber field can't hold more) byte max_roadveh; //max trucks in game per player @@ -531,6 +531,16 @@ Window *AllocateWindowDesc(const WindowDesc *desc) if (pt.x > _screen.width + 10 - desc->width) pt.x = (_screen.width + 10 - desc->width) - 20; pt.y = w->top + 10; + // open Build Toolbars and Terraforming Toolbar aligned + } else if (desc->cls == WC_BUILD_TOOLBAR || desc->cls == WC_SCEN_LAND_GEN) { + /* Override the position if a toolbar is opened according to the place of the maintoolbar + * The main toolbar (WC_MAIN_TOOLBAR) is 640px in width */ + switch (_patches.toolbar_pos) { + case 1: pt.x = ((_screen.width + 640) >> 1) - desc->width; break; + case 2: pt.x = _screen.width - desc->width; break; + default: pt.x = 640 - desc->width; + } + pt.y = desc->top; } else { pt.x = desc->left; pt.y = desc->top; @@ -1013,7 +1023,7 @@ void MouseLoop() } if (click == 1) { - DEBUG(misc, 1) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); + //DEBUG(misc, 1) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); if (_thd.place_mode != 0 && // query button and place sign button work in pause mode !(_cursor.sprite == 0x2CF || _cursor.sprite == 0x2D2) && @@ -1164,6 +1174,22 @@ void DeleteNonVitalWindows() } } +int PositionMainToolbar(Window *w) +{ + //DEBUG(misc, 1) ("Repositioning Main Toolbar..."); + + if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) + w = FindWindowById(WC_MAIN_TOOLBAR, 0); + + switch (_patches.toolbar_pos) { + case 1: w->left = (_screen.width - w->width) >> 1; break; + case 2: w->left = _screen.width - w->width; break; + default: w->left = 0; + } + SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part + return w->left; +} + void RelocateAllWindows(int neww, int newh) { Window *w; @@ -1182,7 +1208,7 @@ void RelocateAllWindows(int neww, int newh) if (w->window_class == WC_MAIN_TOOLBAR) { top = w->top; - left = (neww - w->width) >> 1; + left = PositionMainToolbar(w); // changes toolbar orientation } else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){ top = (newh - w->height) >> 1; left = (neww - w->width) >> 1; @@ -1208,4 +1234,3 @@ void RelocateAllWindows(int neww, int newh) w->top = top; } } - @@ -408,6 +408,7 @@ void GuiShowTooltips(uint16 string_id); void UnclickWindowButtons(Window *w); void UnclickSomeWindowButtons(Window *w, uint32 mask); void RelocateAllWindows(int neww, int newh); +int32 PositionMainToolbar(Window *w); /* widget.c */ int GetWidgetFromPos(Window *w, int x, int y); |