Skip to content

Commit

Permalink
refactor: finished moving mapAccelerators to Nim
Browse files Browse the repository at this point in the history
FossilOrigin-Name: ece770e5d1d6ca0a42abcb8e610690cba2be223fa18ab440f825f850512effc3
  • Loading branch information
thindil committed Jan 6, 2024
1 parent 0a4e556 commit 82e4170
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 57 deletions.
2 changes: 1 addition & 1 deletion nim/src/ui/mapsui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Steam Sky. If not, see <http://www.gnu.org/licenses/>.

import std/[parsecfg, streams, strutils, tables]
import std/[parsecfg, streams, tables]
import ../[config, game, maps, messages, shipscargo, shipsmovement, statistics,
stories, tk, types]
import coreui, dialogs, utilsui2
Expand Down
58 changes: 32 additions & 26 deletions src/ui/gameoptions.adb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (c) 2020-2023 Bartek thindil Jasicki
-- Copyright (c) 2020-2024 Bartek thindil Jasicki
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -74,47 +74,58 @@ package body GameOptions is
-- SOURCE
Accels: array(1 .. 53) of Accel_Data :=
(1 =>
(Shortcut => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 1)),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 1)),
Entry_Name => To_Unbounded_String(Source => ".menu.shipinfo"),
Config_Name => To_Unbounded_String(Source => "ShipInfo")),
2 =>
(Shortcut => Menu_Accelerators(2),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 2)),
Entry_Name => To_Unbounded_String(Source => ".menu.orders"),
Config_Name => To_Unbounded_String(Source => "Orders")),
3 =>
(Shortcut => Menu_Accelerators(3),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 3)),
Entry_Name => To_Unbounded_String(Source => ".menu.crafts"),
Config_Name => To_Unbounded_String(Source => "Crafting")),
4 =>
(Shortcut => Menu_Accelerators(4),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 4)),
Entry_Name => To_Unbounded_String(Source => ".menu.messages"),
Config_Name => To_Unbounded_String(Source => "LastMessages")),
5 =>
(Shortcut => Menu_Accelerators(5),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 5)),
Entry_Name => To_Unbounded_String(Source => ".menu.knowledge"),
Config_Name => To_Unbounded_String(Source => "Knowledge")),
6 =>
(Shortcut => Menu_Accelerators(6),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 6)),
Entry_Name => To_Unbounded_String(Source => ".menu.waitorders"),
Config_Name => To_Unbounded_String(Source => "WaitOrders")),
7 =>
(Shortcut => Menu_Accelerators(7),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 7)),
Entry_Name => To_Unbounded_String(Source => ".menu.gamestats"),
Config_Name => To_Unbounded_String(Source => "GameStats")),
8 =>
(Shortcut => Menu_Accelerators(8),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 8)),
Entry_Name => To_Unbounded_String(Source => ".menu.help"),
Config_Name => To_Unbounded_String(Source => "Help")),
9 =>
(Shortcut => Menu_Accelerators(9),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 9)),
Entry_Name => To_Unbounded_String(Source => ".menu.gameoptions"),
Config_Name => To_Unbounded_String(Source => "GameOptions")),
10 =>
(Shortcut => Menu_Accelerators(10),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 10)),
Entry_Name => To_Unbounded_String(Source => ".menu.quit"),
Config_Name => To_Unbounded_String(Source => "Quit")),
11 =>
(Shortcut => Menu_Accelerators(11),
(Shortcut =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 11)),
Entry_Name => To_Unbounded_String(Source => ".menu.resign"),
Config_Name => To_Unbounded_String(Source => "Resign")),
12 =>
Expand Down Expand Up @@ -712,19 +723,18 @@ package body GameOptions is
Options_Frame.Name :=
New_String(Str => Widget_Image(Win => Options_Canvas) & ".options");
Load_Menu_Accelerators_Loop :
for I in Menu_Accelerators'Range loop
Accels(I).Shortcut := Menu_Accelerators(I);
for I in 1 .. 11 loop
Accels(I).Shortcut :=
To_Unbounded_String(Source => Get_Menu_Accelerator(I));
end loop Load_Menu_Accelerators_Loop;
Load_Map_Accelerators_Loop :
for I in Map_Accelerators'Range loop
Accels(I + Menu_Accelerators'Last).Shortcut := Map_Accelerators(I);
Accels(I + 11).Shortcut := Map_Accelerators(I);
end loop Load_Map_Accelerators_Loop;
Accels(Menu_Accelerators'Last + Map_Accelerators'Last + 1).Shortcut :=
Full_Screen_Accel;
Accels(11 + Map_Accelerators'Last + 1).Shortcut := Full_Screen_Accel;
Load_General_Accelerators_Loop :
for I in 1 .. 4 loop
Accels(I + Menu_Accelerators'Last + Map_Accelerators'Last + 1)
.Shortcut :=
Accels(I + 11 + Map_Accelerators'Last + 1).Shortcut :=
To_Unbounded_String(Source => Get_General_Accelerator(Index => I));
end loop Load_General_Accelerators_Loop;
Load_Accelerators_Loop :
Expand Down Expand Up @@ -1097,8 +1107,7 @@ package body GameOptions is
(Str => Root_Name & To_String(Source => Accels(I).Entry_Name));
--## rule off SIMPLIFIABLE_STATEMENTS
if I < 12 then
Menu_Accelerators(I) :=
To_Unbounded_String(Source => Get(Widgt => Key_Entry));
Set_Menu_Accelerator(Index => I, Value => Get(Widgt => Key_Entry));
Bind_To_Main_Window
(Interp => Get_Context,
Sequence =>
Expand All @@ -1119,8 +1128,7 @@ package body GameOptions is
New_Item => "KeyPress-")) &
">",
Script =>
"{InvokeMenu " & To_String(Source => Menu_Accelerators(I)) &
"}");
"{InvokeMenu " & Get_Menu_Accelerator(Index => I) & "}");
elsif I < 49 then
Map_Accelerators(I - 11) :=
To_Unbounded_String(Source => Get(Widgt => Key_Entry));
Expand Down Expand Up @@ -1154,9 +1162,7 @@ package body GameOptions is
(Str =>
Root_Name &
To_String
(Source =>
Accels(Menu_Accelerators'Last + Map_Accelerators'Last + 1)
.Entry_Name));
(Source => Accels(11 + Map_Accelerators'Last + 1).Entry_Name));
Full_Screen_Accel :=
To_Unbounded_String(Source => Get(Widgt => Key_Entry));
Save_Keys_To_File_Block :
Expand Down
26 changes: 17 additions & 9 deletions src/ui/help-ui.adb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (c) 2020-2023 Bartek thindil Jasicki
-- Copyright (c) 2020-2024 Bartek thindil Jasicki
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -189,14 +189,22 @@ package body Help.UI is
5 => Map_Accelerators(9), 6 => Map_Accelerators(10),
7 => Map_Accelerators(11), 8 => Map_Accelerators(12),
9 => Map_Accelerators(13), 10 => Map_Accelerators(14),
11 => Menu_Accelerators(1), 12 => Menu_Accelerators(2),
13 => Menu_Accelerators(3), 14 => Menu_Accelerators(4),
15 => Menu_Accelerators(5), 16 => Menu_Accelerators(6),
17 => Map_Accelerators(2), 18 => Menu_Accelerators(7),
19 => Menu_Accelerators(9), 20 => Menu_Accelerators(10),
21 => Menu_Accelerators(11), 22 => Map_Accelerators(1),
23 => Menu_Accelerators(8), 24 => Map_Accelerators(3),
25 => Map_Accelerators(4));
11 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 1)),
12 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 2)),
13 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 3)),
14 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 4)),
15 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 5)),
16 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 6)),
17 => Map_Accelerators(2),
18 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 7)),
19 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 9)),
20 =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 10)),
21 =>
To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 11)),
22 => Map_Accelerators(1),
23 => To_Unbounded_String(Source => Get_Menu_Accelerator(Index => 8)),
24 => Map_Accelerators(3), 25 => Map_Accelerators(4));
--## rule off TYPE_INITIAL_VALUES
type Font_Tag is record
Tag: String(1 .. 1);
Expand Down
49 changes: 28 additions & 21 deletions src/ui/maps-ui-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,8 @@ package body Maps.UI.Commands is
Player_Ship.Destination_Y = 0 then
Result := 1;
Update_Game(Minutes => Get_Integer_Setting(Name => "waitMinutes"));
Wait_In_Place(Minutes => Get_Integer_Setting(Name => "waitMinutes"));
Wait_In_Place
(Minutes => Get_Integer_Setting(Name => "waitMinutes"));
else
Update_Coordinates;
Result := Move_Ship(X => New_X, Y => New_Y, Message => Message);
Expand Down Expand Up @@ -1341,13 +1342,13 @@ package body Maps.UI.Commands is
--## rule on IMPROPER_INITIALIZATION
Game_Menu: Ttk_Frame := Get_Widget(pathName => ".gameframe.gamemenu");
procedure Add_Button
(Name, Label, Command: String; Shortcut: Unbounded_String;
(Name, Label, Command: String; Shortcut: String;
Last: Boolean := False) is
Button: constant Ttk_Button :=
Create
(pathName => Game_Menu & Name,
options =>
"-text {" & Label & " [" & To_String(Source => Shortcut) &
"-text {" & Label & " [" & Shortcut &
"]} -command {CloseDialog " & Game_Menu & ";" & Command & "}");
begin
if Last then
Expand All @@ -1367,7 +1368,7 @@ package body Maps.UI.Commands is
Shortcuts.Append
(New_Item =>
(Button_Name => To_Unbounded_String(Source => Game_Menu & Name),
Shortcut => Shortcut));
Shortcut => To_Unbounded_String(Source => Shortcut)));
Row := Row + 1;
end Add_Button;
begin
Expand All @@ -1379,49 +1380,56 @@ package body Maps.UI.Commands is
Create_Dialog(Name => ".gameframe.gamemenu", Title => "Game menu");
Add_Button
(Name => ".shipinfo", Label => "Ship information",
Command => "ShowShipInfo", Shortcut => Menu_Accelerators(1));
Command => "ShowShipInfo",
Shortcut => Get_Menu_Accelerator(Index => 1));
if State not in "combat" | "dead" then
Add_Button
(Name => ".shiporders", Label => "Ship orders",
Command => "ShowOrders", Shortcut => Menu_Accelerators(2));
Command => "ShowOrders",
Shortcut => Get_Menu_Accelerator(Index => 2));
end if;
if State /= "dead" then
Add_Button
(Name => ".crafting", Label => "Crafting",
Command => "ShowCrafting", Shortcut => Menu_Accelerators(3));
Command => "ShowCrafting",
Shortcut => Get_Menu_Accelerator(Index => 3));
end if;
Add_Button
(Name => ".messages", Label => "Last messages",
Command => "ShowLastMessages", Shortcut => Menu_Accelerators(4));
Command => "ShowLastMessages",
Shortcut => Get_Menu_Accelerator(Index => 4));
Add_Button
(Name => ".knowledge", Label => "Knowledge lists",
Command => "ShowKnowledge", Shortcut => Menu_Accelerators(5));
Command => "ShowKnowledge",
Shortcut => Get_Menu_Accelerator(Index => 5));
if State not in "combat" | "dead" then
Add_Button
(Name => ".wait", Label => "Wait orders", Command => "ShowWait",
Shortcut => Menu_Accelerators(6));
Shortcut => Get_Menu_Accelerator(Index => 6));
end if;
Add_Button
(Name => ".stats", Label => "Game statistics", Command => "ShowStats",
Shortcut => Menu_Accelerators(7));
Shortcut => Get_Menu_Accelerator(Index => 7));
if State /= "dead" then
Add_Button
(Name => ".help", Label => "Help", Command => "ShowHelp " & State,
Shortcut => Menu_Accelerators(8));
Shortcut => Get_Menu_Accelerator(Index => 8));
Add_Button
(Name => ".options", Label => "Game options",
Command => "ShowOptions", Shortcut => Menu_Accelerators(9));
Command => "ShowOptions",
Shortcut => Get_Menu_Accelerator(Index => 9));
Add_Button
(Name => ".quit", Label => "Quit from game", Command => "QuitGame",
Shortcut => Menu_Accelerators(10));
Shortcut => Get_Menu_Accelerator(Index => 10));
Add_Button
(Name => ".resign", Label => "Resign from game",
Command => "ResignGame", Shortcut => Menu_Accelerators(11));
Command => "ResignGame",
Shortcut => Get_Menu_Accelerator(Index => 11));
end if;
Add_Button
(Name => ".close", Label => "Close",
Command => "CloseDialog " & Game_Menu,
Shortcut => To_Unbounded_String(Source => "Escape"), Last => True);
Command => "CloseDialog " & Game_Menu, Shortcut => "Escape",
Last => True);
Add_Bindings_Block :
declare
--## rule off IMPROPER_INITIALIZATION
Expand Down Expand Up @@ -1480,8 +1488,7 @@ package body Maps.UI.Commands is
pragma Unreferenced(Client_Data, Argc);
Focused_Widget: constant Ttk_Frame :=
Get_Widget(pathName => Focus(Interp => Interp), Interp => Interp);
Menu_Commands: constant array
(Menu_Accelerators'Range) of Unbounded_String :=
Menu_Commands: constant array(1 .. 11) of Unbounded_String :=
(1 => To_Unbounded_String(Source => "ShowShipInfo"),
2 => To_Unbounded_String(Source => "ShowOrders"),
3 => To_Unbounded_String(Source => "ShowCrafting"),
Expand All @@ -1499,8 +1506,8 @@ package body Maps.UI.Commands is
return TCL_OK;
end if;
Invoke_Button_Loop :
for I in Menu_Accelerators'Range loop
if To_String(Source => Menu_Accelerators(I)) =
for I in 1 .. 11 loop
if Get_Menu_Accelerator(Index => I) =
CArgv.Arg(Argv => Argv, N => 1) then
Tcl_Eval
(interp => Interp,
Expand Down

0 comments on commit 82e4170

Please sign in to comment.