diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 0357e337ea..9d4a15e426 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -937,7 +937,10 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 Game::NewEvent(new ScriptEventCompanyBankrupt(c_index)); CompanyAdminRemove(c_index, (CompanyRemoveReason)reason); - if (StoryPage::GetNumItems() == 0 || Goal::GetNumItems() == 0) InvalidateWindowData(WC_MAIN_TOOLBAR, 0); + if (StoryPage::GetNumItems() == 0 || Goal::GetNumItems() == 0) { + InvalidateWindowData(WC_MAIN_TOOLBAR, 0); + InvalidateWindowData(WC_MAIN_TOOLBAR_RIGHT, 0); + } break; } diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 9d13deef66..113ce8a864 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -461,6 +461,7 @@ struct MainWindow : Window if (!gui_scope) return; /* Forward the message to the appropriate toolbar (ingame or scenario editor) */ InvalidateWindowData(WC_MAIN_TOOLBAR, 0, data, true); + InvalidateWindowData(WC_MAIN_TOOLBAR_RIGHT, 0, data, true); } static HotkeyList hotkeys; diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 680c3f2d85..e61fa1a532 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -135,6 +135,13 @@ public: */ WC_MAIN_TOOLBAR = ::WC_MAIN_TOOLBAR, + /** + * Main toolbar (the long bar at the top); %Window numbers: + * - 0 = #ToolbarNormalWidgets + * - 0 = #ToolbarEditorWidgets + */ + WC_MAIN_TOOLBAR_RIGHT = ::WC_MAIN_TOOLBAR_RIGHT, + /** * Statusbar (at the bottom of your screen); %Window numbers: * - 0 = #StatusbarWidgets diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index fde6ed284c..edacf68c64 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -58,6 +58,7 @@ RailType _last_built_railtype; RoadType _last_built_roadtype; static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm. +int _last_clicked_toolbar_idx = 0; /** Toobar modes */ enum ToolbarMode { @@ -170,7 +171,17 @@ public: */ static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def) { - ShowDropDownList(w, list, def, widget, 0, true, true); + if (!_settings_client.gui.vertical_toolbar) { + ShowDropDownList(w, list, def, widget, 0, true, true); + } else { + Rect wi_rect; + NWidgetCore *nwi = w->GetWidget(widget); + wi_rect.left = ((int)nwi->pos_x < _screen.width / 2) ? nwi->pos_x + nwi->current_x - 1 : nwi->pos_x - nwi->current_x; + wi_rect.right = ((int)nwi->pos_x < _screen.width / 2) ? nwi->pos_x + nwi->current_x * 2 : nwi->pos_x - 1; + wi_rect.top = nwi->pos_y; + wi_rect.bottom = nwi->pos_y + nwi->current_y - 1; + ShowDropDownListAt(w, list, def, widget, wi_rect, nwi->colour, true, true); + } if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); } @@ -1796,8 +1807,10 @@ enum MainToolbarHotkeys { /** Main toolbar. */ struct MainToolbarWindow : Window { CallBackFunction last_started_action; ///< Last started user action. + int *clickedFlag; + int clickedValue; - MainToolbarWindow(WindowDesc *desc) : Window(desc) + MainToolbarWindow(WindowDesc *desc, int *clickedFlag = NULL, int clickedValue = 0) : Window(desc), clickedFlag(clickedFlag), clickedValue(clickedValue) { this->InitNested(0); @@ -1829,11 +1842,15 @@ struct MainToolbarWindow : Window { virtual void OnClick(Point pt, int widget, int click_count) { + if (clickedFlag) + *clickedFlag = clickedValue; if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this); } virtual void OnDropdownSelect(int widget, int index) { + if (clickedFlag) + *clickedFlag = clickedValue; CallBackFunction cbf = _menu_clicked_procs[widget](index); if (cbf != CBF_NONE) this->last_started_action = cbf; } @@ -2425,9 +2442,9 @@ void AllocateToolbar() new ScenarioEditorToolbarWindow(&_toolb_scen_desc); } else { if (_settings_client.gui.vertical_toolbar) { - MainToolbarWindow *w = new MainToolbarWindow(&_toolb_vertical_left_desc); + MainToolbarWindow *w = new MainToolbarWindow(&_toolb_vertical_left_desc, &_last_clicked_toolbar_idx, 0); w->left = 0; - w = new MainToolbarWindow(&_toolb_vertical_right_desc); + w = new MainToolbarWindow(&_toolb_vertical_right_desc, &_last_clicked_toolbar_idx, 1); w->left = _screen.width - w->width; SetDirtyBlocks(0, w->top, _screen.width, w->top + w->height); } else { diff --git a/src/toolbar_gui.h b/src/toolbar_gui.h index acfe0ed418..3461c22902 100644 --- a/src/toolbar_gui.h +++ b/src/toolbar_gui.h @@ -18,4 +18,6 @@ void ToggleDirtyBlocks(); void ResetTabletWindow(); +extern int _last_clicked_toolbar_idx; + #endif /* TOOLBAR_GUI_H */ diff --git a/src/window.cpp b/src/window.cpp index 77a94da937..f7590fc25b 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1261,6 +1261,7 @@ static uint GetWindowZPriority(const Window *w) ++z_priority; case WC_MAIN_TOOLBAR: + case WC_MAIN_TOOLBAR_RIGHT: case WC_STATUS_BAR: ++z_priority; @@ -1475,6 +1476,10 @@ void Window::FindWindowPlacementAndResize(int def_width, int def_height) int enlarge_x = max(min(def_width - this->width, _screen.width - this->width), 0); int enlarge_y = max(min(def_height - this->height, free_height - this->height), 0); + if (wt && _settings_client.gui.vertical_toolbar && + enlarge_x > _screen.width - wt->width * 2) { + //enlarge_x = _screen.width - wt->width * 2; + } /* X and Y has to go by step.. calculate it. * The cast to int is necessary else x/y are implicitly casted to @@ -1525,7 +1530,11 @@ static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &po int bottom = height + top; const Window *main_toolbar = FindWindowByClass(WC_MAIN_TOOLBAR); - if (left < 0 || (main_toolbar != NULL && top < main_toolbar->height) || right > _screen.width || bottom > _screen.height) return false; + if (!_settings_client.gui.vertical_toolbar || !main_toolbar) { + if (left < 0 || (main_toolbar != NULL && top < main_toolbar->height) || right > _screen.width || bottom > _screen.height) return false; + } else { + if (left < main_toolbar->width || top < 0 || right > _screen.width - main_toolbar->width * 2 || bottom > _screen.height) return false; + } /* Make sure it is not obscured by any window. */ const Window *w; @@ -1636,6 +1645,10 @@ static Point GetAutoPlacePosition(int width, int height) * of (+5, +5) */ int left = 0, top = 24; + if (_settings_client.gui.vertical_toolbar) { + left = main_toolbar != NULL ? main_toolbar->width : 0; + top = 0; + } restart: FOR_ALL_WINDOWS_FROM_BACK(w) { @@ -1663,15 +1676,12 @@ Point GetToolbarAlignedWindowPosition(int window_width) assert(w != NULL); Point pt; if (_settings_client.gui.vertical_toolbar) { - pt.x = _current_text_dir == TD_RTL ? w->left + w->width : _screen.width - window_width - w->width; + // Retermine if the window was opened from the left or the right toolbar + pt.x = (_last_clicked_toolbar_idx == 0) ? w->left + w->width : _screen.width - w->width - window_width - 1; pt.y = w->top; } else { + pt.x = _current_text_dir == TD_RTL ? w->left : (w->left + w->width) - window_width; pt.y = w->top + w->height; - if (_settings_client.gui.touchscreen_mode != TSC_NONE) { - pt.x = _current_text_dir == TD_RTL ? 0 : (_screen.width - window_width); - } else { - pt.x = _current_text_dir == TD_RTL ? w->left : (w->left + w->width) - window_width; - } } return pt; } @@ -1705,13 +1715,9 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int (w = FindWindowById(desc->parent_cls, window_number)) != NULL && w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) { - if (_settings_client.gui.touchscreen_mode != TSC_NONE) { - pt.x = _current_text_dir == TD_RTL ? 0 : (_screen.width - default_width); - } else { - pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10); - if (pt.x > _screen.width + 10 - default_width) { - pt.x = (_screen.width + 10 - default_width) - 20; - } + pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10); + if (pt.x > _screen.width + 10 - default_width) { + pt.x = (_screen.width + 10 - default_width) - 20; } pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? w->height : 10); @@ -2064,6 +2070,7 @@ static void EnsureVisibleCaption(Window *w, int nx, int ny) /* Make sure the title bar isn't hidden behind the main tool bar or the status bar. */ PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR, 0), w->left, PHD_DOWN); + PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_MAIN_TOOLBAR_RIGHT, 0), w->left, PHD_DOWN); PreventHiding(&nx, &ny, caption_rect, FindWindowById(WC_STATUS_BAR, 0), w->left, PHD_UP); } @@ -2124,6 +2131,7 @@ void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen) */ int GetMainViewTop() { + if (_settings_client.gui.vertical_toolbar) return 0; Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); return (w == NULL) ? 0 : w->top + w->height; } @@ -3290,6 +3298,7 @@ restart_search: if (w->window_class != WC_MAIN_WINDOW && w->window_class != WC_SELECT_GAME && w->window_class != WC_MAIN_TOOLBAR && + w->window_class != WC_MAIN_TOOLBAR_RIGHT && w->window_class != WC_STATUS_BAR && w->window_class != WC_TOOLTIPS && (w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned' @@ -3506,6 +3515,7 @@ void RelocateAllWindows(int neww, int newh) continue; case WC_MAIN_TOOLBAR: + case WC_MAIN_TOOLBAR_RIGHT: ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false); top = w->top;