diff --git a/src/command.cpp b/src/command.cpp index 7dfc7529f2..fc827449f3 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -555,8 +555,6 @@ bool TouchCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCall if (text != NULL) ttd_strlcpy(_queued_command.text, text, 32 * MAX_CHAR_LENGTH); _my_cmd = my_cmd; _is_queued_command = true; - extern void UpdateTouchscreenBar(); - UpdateTouchscreenBar(); return true; } else { return DoCommandP(tile, p1, p2, cmd, callback, text, my_cmd); @@ -595,8 +593,6 @@ void EraseQueuedTouchCommand() { if (!IsQueuedTouchCommand()) return; _is_queued_command = false; - extern void UpdateTouchscreenBar(); - UpdateTouchscreenBar(); SetSelectionTilesDirty(); _thd.Reset(); } diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index f25359e344..dfccacf1b2 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -1180,6 +1180,9 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_MESSAGES, "WID_TN_MESSAGES"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_HELP, "WID_TN_HELP"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_SWITCH_BAR, "WID_TN_SWITCH_BAR"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_CTRL, "WID_TN_CTRL"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_SHIFT, "WID_TN_SHIFT"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_DELETE, "WID_TN_DELETE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TN_END, "WID_TN_END"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TE_PAUSE, "WID_TE_PAUSE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TE_FAST_FORWARD, "WID_TE_FAST_FORWARD"); @@ -1203,12 +1206,6 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TE_MUSIC_SOUND, "WID_TE_MUSIC_SOUND"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TE_HELP, "WID_TE_HELP"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TE_SWITCH_BAR, "WID_TE_SWITCH_BAR"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_X, "WID_TT_X"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_DELETE, "WID_TT_DELETE"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_SHIFT, "WID_TT_SHIFT"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_CTRL, "WID_TT_CTRL"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_MOVE, "WID_TT_MOVE"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_CONFIRM, "WID_TT_CONFIRM"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TD_SORT_ORDER, "WID_TD_SORT_ORDER"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TD_SORT_CRITERIA, "WID_TD_SORT_CRITERIA"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TD_LIST, "WID_TD_LIST"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 62570aa6fa..680c3f2d85 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -2375,6 +2375,9 @@ public: WID_TN_MESSAGES = ::WID_TN_MESSAGES, ///< Messages menu. WID_TN_HELP = ::WID_TN_HELP, ///< Help menu. WID_TN_SWITCH_BAR = ::WID_TN_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. + WID_TN_CTRL = ::WID_TN_CTRL, ///< On-screen Ctrl key + WID_TN_SHIFT = ::WID_TN_SHIFT, ///< On-screen Sgift key + WID_TN_DELETE = ::WID_TN_DELETE, ///< Close all windows WID_TN_END = ::WID_TN_END, ///< Helper for knowing the amount of widgets. }; @@ -2405,16 +2408,6 @@ public: WID_TE_SWITCH_BAR = ::WID_TE_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. }; - /** Widgets of the TabletToolbar class. */ - enum ToolbarTabletWidgets { - WID_TT_X = ::WID_TT_X, ///< Press X (toggle transparency). - WID_TT_DELETE = ::WID_TT_DELETE, ///< Press DELETE. - WID_TT_SHIFT = ::WID_TT_SHIFT, ///< Press SHIFT. - WID_TT_CTRL = ::WID_TT_CTRL, ///< Press CTRL. - WID_TT_MOVE = ::WID_TT_MOVE, ///< Click for moving around viewports. - WID_TT_CONFIRM = ::WID_TT_CONFIRM, ///< Confirm action. - }; - /* automatically generated from ../../widgets/town_widget.h */ /** Widgets of the #TownDirectoryWindow class. */ enum TownDirectoryWidgets { diff --git a/src/script/api/template/template_window.hpp.sq b/src/script/api/template/template_window.hpp.sq index 931c37d283..9f01e42d5a 100644 --- a/src/script/api/template/template_window.hpp.sq +++ b/src/script/api/template/template_window.hpp.sq @@ -223,8 +223,6 @@ namespace SQConvert { template <> inline int Return(HSQUIRRELVM vm, ScriptWindow::ToolbarNormalWidgets res) { sq_pushinteger(vm, (int32)res); return 1; } template <> inline ScriptWindow::ToolbarEditorWidgets GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::ToolbarEditorWidgets)tmp; } template <> inline int Return(HSQUIRRELVM vm, ScriptWindow::ToolbarEditorWidgets res) { sq_pushinteger(vm, (int32)res); return 1; } - template <> inline ScriptWindow::ToolbarTabletWidgets GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::ToolbarTabletWidgets)tmp; } - template <> inline int Return(HSQUIRRELVM vm, ScriptWindow::ToolbarTabletWidgets res) { sq_pushinteger(vm, (int32)res); return 1; } template <> inline ScriptWindow::TownDirectoryWidgets GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::TownDirectoryWidgets)tmp; } template <> inline int Return(HSQUIRRELVM vm, ScriptWindow::TownDirectoryWidgets res) { sq_pushinteger(vm, (int32)res); return 1; } template <> inline ScriptWindow::TownAuthorityWidgets GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptWindow::TownAuthorityWidgets)tmp; } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index c9c93be4bb..9892a62ed3 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1162,6 +1162,30 @@ static CallBackFunction ToolbarSwitchClick(Window *w) return CBF_NONE; } +static CallBackFunction ToolbarCtrlClick(Window *w) +{ + _ctrl_pressed = !_ctrl_pressed; + w->ToggleWidgetLoweredState(WID_TN_CTRL); + HandleCtrlChanged(); + w->SetWidgetDirty(WID_TN_CTRL); + EraseQueuedTouchCommand(); + return CBF_NONE; +} + +static CallBackFunction ToolbarShiftClick(Window *w) +{ + _shift_pressed = !_shift_pressed; + w->ToggleWidgetLoweredState(WID_TN_SHIFT); + w->SetWidgetDirty(WID_TN_SHIFT); + return CBF_NONE; +} + +static CallBackFunction ToolbarDeleteClick(Window *w) +{ + DeleteNonVitalWindows(); + return CBF_NONE; +} + /* --- Scenario editor specific handlers. */ /** @@ -1459,7 +1483,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer { /* virtual */ const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const { static const uint SMALLEST_ARRANGEMENT = 14; - static const uint BIGGEST_ARRANGEMENT = 21; + static const uint BIGGEST_ARRANGEMENT = 20; static const byte arrange14[] = { 0, 1, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 29, 2, 3, 4, 5, 6, 7, 8, 9, 12, 14, 26, 27, 28, 29, @@ -1488,19 +1512,23 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer { 0, 1, 2, 4, 5, 6, 15, 16, 17, 18, 21, 22, 23, 24, 25, 26, 11, 19, 20, 29, 0, 1, 3, 4, 7, 8, 9, 12, 14, 27, 21, 22, 23, 24, 25, 10, 28, 19, 20, 29, }; - static const byte arrange21[] = { - 0, 1, 2, 3, 4, 5, 6, 15, 16, 17, 18, 21, 22, 23, 24, 25, 26, 11, 19, 20, 29, - 0, 1, 2, 3, 4, 7, 8, 9, 12, 14, 27, 21, 22, 23, 24, 25, 10, 28, 19, 20, 29, - }; static const byte arrange_all[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 }; +#ifdef __ANDROID__ + static const byte arrange_android[] = { + 0, 1, 2, 4, 5, 6, 7, 8, 9, 14, 21, 22, 23, 24, 25, 19, 20, 29, 30, 31, 32, + 0, 1, 3, 4, 5, 6, 7, 12, 15, 16, 17, 18, 26, 27, 28, 19, 20, 29, 30, 31, 32, + }; + + button_count = arrangable_count = lengthof(arrange_android) / 2; + spacer_count = this->spacers; + return arrange_android; +#else + /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */ uint full_buttons = max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT); -#ifdef __ANDROID__ - full_buttons = BIGGEST_ARRANGEMENT; // On Android there are lot of pixels, but the screen is still small -#endif if (full_buttons > BIGGEST_ARRANGEMENT) { button_count = arrangable_count = lengthof(arrange_all); @@ -1509,11 +1537,12 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer { } /* Introduce the split toolbar */ - static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20, arrange21 }; + static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 }; button_count = arrangable_count = full_buttons; spacer_count = this->spacers; return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0); +#endif } }; @@ -1613,6 +1642,9 @@ static ToolbarButtonProc * const _toolbar_button_procs[] = { ToolbarNewspaperClick, ToolbarHelpClick, ToolbarSwitchClick, + ToolbarCtrlClick, + ToolbarShiftClick, + ToolbarDeleteClick, }; enum MainToolbarHotkeys { @@ -1890,14 +1922,19 @@ static NWidgetBase *MakeMainToolbar(int *biggest_index) }; NWidgetMainToolbarContainer *hor = new NWidgetMainToolbarContainer(); - for (uint i = 0; i < WID_TN_END; i++) { + for (uint i = 0; i <= SPR_IMG_SWITCH_TOOLBAR; i++) { switch (i) { case 4: case 8: case 15: case 19: case 21: /*case 26:*/ hor->Add(new NWidgetSpacer(0, 0)); break; } hor->Add(new NWidgetLeaf(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i)); } - *biggest_index = max(*biggest_index, WID_TN_SWITCH_BAR); + hor->Add(new NWidgetSpacer(0, 0)); + hor->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_CTRL, STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP)); + hor->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TN_SHIFT, STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP)); + hor->Add(new NWidgetLeaf(WWT_TEXTBTN, COLOUR_GREY, WID_TN_DELETE, STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP)); + + *biggest_index = max(*biggest_index, WID_TN_DELETE); return hor; } @@ -2224,142 +2261,6 @@ static WindowDesc _toolb_scen_desc( &ScenarioEditorToolbarWindow::hotkeys ); - -/** Tablet toolbar. */ -struct TabletToolbar : Window { - - TabletToolbar(WindowDesc *desc) : Window(desc) - { - this->InitNested(0); - this->flags |= WF_STICKY; - ResetObjectToPlace(); - this->OnInvalidateData(1 << 2); // Disable widgets. - if (_current_text_dir == TD_RTL) { this->left = _screen.width - this->width; } - } - - ~TabletToolbar() { - _shift_pressed = false; - _move_pressed = false; - - if (_ctrl_pressed) { - _ctrl_pressed = false; - HandleCtrlChanged(); - } - } - - virtual void OnClick(Point pt, int widget, int click_count) - { - switch (widget) { - case WID_TT_X: - extern void ResetRestoreAllTransparency(); - ResetRestoreAllTransparency(); - break; - case WID_TT_DELETE: - DeleteNonVitalWindows(); - break; - case WID_TT_SHIFT: - _shift_pressed = !_shift_pressed; - this->ToggleWidgetLoweredState(WID_TT_SHIFT); - this->SetWidgetDirty(WID_TT_SHIFT); - break; - case WID_TT_CTRL: - _ctrl_pressed = !_ctrl_pressed; - this->ToggleWidgetLoweredState(WID_TT_CTRL); - HandleCtrlChanged(); - this->SetWidgetDirty(WID_TT_CTRL); - EraseQueuedTouchCommand(); - break; - case WID_TT_MOVE: - _move_pressed = !_move_pressed; - this->ToggleWidgetLoweredState(WID_TT_MOVE); - this->SetWidgetDirty(WID_TT_MOVE); - break; - case WID_TT_CONFIRM: - DoQueuedTouchCommand(); - break; - default: - NOT_REACHED(); - } - } - - /** - * Some data on this window has become invalid. - * @param data Information about the changed data. - * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details. - * @note bit 2 -> Update tile selection. - * bit 3 -> Set window dirty. - */ - virtual void OnInvalidateData(int data = 0, bool gui_scope = true) - { - /* Selection has changed. */ - if (HasBit(data, 2)) { UpdateTileSelection(); } - - /* This window is dirty. */ - if (HasBit(data, 3)) { - SetWidgetDisabledState(WID_TT_CONFIRM, !IsQueuedTouchCommand()); - this->SetWidgetDirty(WID_TT_CONFIRM); - } - } -}; - -static const NWidgetPart _nested_tablet_simple_widgets[] = { - NWidget(NWID_VERTICAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TT_DELETE), SetDataTip(STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TT_X), SetDataTip(STR_TABLET_X, STR_TABLET_TOGGLE_TRANSPARENCY_TOOLTIP), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TT_SHIFT), SetDataTip(STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TT_CTRL), SetDataTip(STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP), - //NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TT_MOVE), SetDataTip(STR_TABLET_MOVE, STR_TABLET_MOVE_TOOLTIP), - EndContainer(), -}; - -static const NWidgetPart _nested_tablet_confirm_widgets[] = { - NWidget(NWID_VERTICAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TT_X), SetDataTip(STR_TABLET_X, STR_TABLET_TOGGLE_TRANSPARENCY_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TT_DELETE), SetDataTip(STR_TABLET_CLOSE, STR_TABLET_CLOSE_TOOLTIP), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TT_SHIFT), SetDataTip(STR_TABLET_SHIFT, STR_TABLET_SHIFT_TOOLTIP), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TT_CTRL), SetDataTip(STR_TABLET_CTRL, STR_TABLET_CTRL_TOOLTIP), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TT_MOVE), SetDataTip(STR_TABLET_MOVE, STR_TABLET_MOVE_TOOLTIP), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TT_CONFIRM), SetDataTip(STR_TABLET_CONFIRM, STR_TABLET_CONFIRM_TOOLTIP), - EndContainer(), -}; - -static WindowDesc _toolbar_tablet_simple_desc( - WDP_AUTO, NULL, 0, 0, - WC_TABLET_BAR, WC_NONE, - WDF_NO_FOCUS, - _nested_tablet_simple_widgets, lengthof(_nested_tablet_simple_widgets) -); - -static WindowDesc _toolbar_tablet_confirm_desc( - WDP_AUTO, NULL, 0, 0, - WC_TABLET_BAR, WC_NONE, - WDF_NO_FOCUS, - _nested_tablet_confirm_widgets, lengthof(_nested_tablet_confirm_widgets) -); - -void ResetTabletWindow() -{ - if (_game_mode == GM_MENU) return; - - DeleteWindowByClass(WC_TABLET_BAR); - EraseQueuedTouchCommand(); - - switch (_settings_client.gui.touchscreen_mode) { - case TSC_NONE: - break; - case TSC_SIMPLE: - new TabletToolbar(&_toolbar_tablet_simple_desc); - break; - case TSC_CONFIRM: - new TabletToolbar(&_toolbar_tablet_confirm_desc); - InvalidateWindowData(WC_TABLET_BAR, 0, 1 << 3); - break; - default: NOT_REACHED(); - } - - MarkWholeScreenDirty(); -} - /** Allocate the toolbar. */ void AllocateToolbar() { @@ -2371,11 +2272,4 @@ void AllocateToolbar() } else { new MainToolbarWindow(&_toolb_normal_desc); } - - ResetTabletWindow(); -} - -void UpdateTouchscreenBar() -{ - InvalidateWindowData(WC_TABLET_BAR, 0, 1 << 3); } diff --git a/src/widgets/toolbar_widget.h b/src/widgets/toolbar_widget.h index 4399b5d10c..172564b883 100644 --- a/src/widgets/toolbar_widget.h +++ b/src/widgets/toolbar_widget.h @@ -45,6 +45,9 @@ enum ToolbarNormalWidgets { WID_TN_MESSAGES, ///< Messages menu. WID_TN_HELP, ///< Help menu. WID_TN_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. + WID_TN_CTRL, ///< Press CTRL. + WID_TN_SHIFT, ///< Press SHIFT. + WID_TN_DELETE, ///< Press DELETE. WID_TN_END, ///< Helper for knowing the amount of widgets. }; @@ -75,14 +78,4 @@ enum ToolbarEditorWidgets { WID_TE_SWITCH_BAR = WID_TN_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. }; -/** Widgets of the TabletToolbar class. */ -enum ToolbarTabletWidgets { - WID_TT_X, ///< Press X (toggle transparency). - WID_TT_DELETE, ///< Press DELETE. - WID_TT_SHIFT, ///< Press SHIFT. - WID_TT_CTRL, ///< Press CTRL. - WID_TT_MOVE, ///< Click for moving around viewports. - WID_TT_CONFIRM, ///< Confirm action. -}; - #endif /* WIDGETS_TOOLBAR_WIDGET_H */