From 73e3b214118748d669d80353a0dc594bf4d5aadf Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 18 May 2010 02:27:38 +0300
Subject: [PATCH 3/3] Add "Show terrain attributes" check box in editor menu

This caption is localizable.  Use its hot key also as the
command key for when the menu is not open.
---
 engine/editor/editloop.cpp      |   11 +------
 engine/include/editor.h         |    2 +
 engine/tolua/editor.pkg         |    1 +
 engine/tolua/tolua.cpp          |   33 +++++++++++++++++++++-
 languages/bos-fi.po             |   58 +++++++++++++++++++++------------------
 scripts/editor.lua              |    1 +
 scripts/menus/ingame/editor.lua |   18 +++++++++++-
 7 files changed, 85 insertions(+), 39 deletions(-)

diff --git a/engine/editor/editloop.cpp b/engine/editor/editloop.cpp
index de14e6e..35a410c 100644
--- a/engine/editor/editloop.cpp
+++ b/engine/editor/editloop.cpp
@@ -99,7 +99,6 @@ static bool PatchPlacedThisPress = false;   /// Only allow one patch per press
 static bool UpdateMinimap = false;          /// Update units on the minimap
 static bool UpdateMinimapTerrain = false;   /// Terrain has changed, minimap needs updating
 static int VisibleIcons;                    /// Number of icons that are visible at a time
-static bool EditorTerrainFlagsVisible = false; /// Whether to show CMapField::Flags
 
 enum _mode_buttons_ {
 	SelectButton = 201,  /// Select mode button
@@ -1075,7 +1074,7 @@ static void EditorDrawTerrainFlags(const CViewport *vp)
 */
 static void EditorDrawTerrainFlagsIfEnabled()
 {
-	if (EditorTerrainFlagsVisible)
+	if (Editor.ShowTerrainFlags)
 	{
 		for (const CViewport *vp = UI.Viewports; vp < UI.Viewports + UI.NumViewports; ++vp)
 		{
@@ -1532,13 +1531,6 @@ static void EditorCallbackKeyDown(unsigned key, unsigned keychar)
 			ToggleFullScreen();
 			break;
 
-		case 't': // 't': Show or hide terrain flags
-			if (!(KeyModifiers & (ModifierControl | ModifierAlt | ModifierSuper)))
-			{
-				EditorTerrainFlagsVisible = !EditorTerrainFlagsVisible;
-			}
-			break;
-
 		case 'v': // 'v' Viewport
 			if (KeyModifiers & ModifierControl)
 			{
@@ -2337,6 +2329,7 @@ static void EditorMainLoop()
 		InterfaceState = IfaceStateNormal;
 		Editor.State = EditorSelecting;
 		Editor.ShowPatchOutlines = false;
+		Editor.ShowTerrainFlags = false;
 		UI.SelectedViewport = UI.Viewports;
 
 		while (Editor.Running)
diff --git a/engine/include/editor.h b/engine/include/editor.h
index 8e1d435..1de8cc9 100644
--- a/engine/include/editor.h
+++ b/engine/include/editor.h
@@ -104,6 +104,8 @@ public:
 	bool ShowPatchOutlines;      /// Show outlines around patches
 	Uint32 PatchOutlineColor;    /// Patch outline color
 
+	bool ShowTerrainFlags;       /// Show CMapField::Flags
+
 	EditorRunningType Running;   /// Editor is running
 
 	EditorStateType State;       /// Current editor state
diff --git a/engine/tolua/editor.pkg b/engine/tolua/editor.pkg
index 4bdd259..3e50392 100644
--- a/engine/tolua/editor.pkg
+++ b/engine/tolua/editor.pkg
@@ -11,6 +11,7 @@ class CEditor
 {
 	vector<string> UnitTypes;
 	const CUnitType *StartUnit;
+	bool ShowTerrainFlags;
 	EditorRunningType Running;
 };
 
diff --git a/engine/tolua/tolua.cpp b/engine/tolua/tolua.cpp
index 82a6eb3..13b7ac5 100644
--- a/engine/tolua/tolua.cpp
+++ b/engine/tolua/tolua.cpp
@@ -1,6 +1,6 @@
 /*
 ** Lua binding: stratagus
-** Generated automatically by tolua++-1.0.92 on Tue May 18 02:22:15 2010.
+** Generated automatically by tolua++-1.0.92 on Tue May 18 02:23:40 2010.
 */
 
 #ifndef __cplusplus
@@ -16292,6 +16292,36 @@ static int tolua_get_CEditor_StartUnit_ptr(lua_State* tolua_S)
 }
 #endif //#ifndef TOLUA_DISABLE
 
+/* get function: ShowTerrainFlags of class  CEditor */
+#ifndef TOLUA_DISABLE_tolua_get_CEditor_ShowTerrainFlags
+static int tolua_get_CEditor_ShowTerrainFlags(lua_State* tolua_S)
+{
+  CEditor* self = (CEditor*)  tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+  if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'ShowTerrainFlags'",NULL);
+#endif
+  tolua_pushboolean(tolua_S,(bool)self->ShowTerrainFlags);
+ return 1;
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* set function: ShowTerrainFlags of class  CEditor */
+#ifndef TOLUA_DISABLE_tolua_set_CEditor_ShowTerrainFlags
+static int tolua_set_CEditor_ShowTerrainFlags(lua_State* tolua_S)
+{
+  CEditor* self = (CEditor*)  tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+  tolua_Error tolua_err;
+  if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'ShowTerrainFlags'",NULL);
+  if (!tolua_isboolean(tolua_S,2,0,&tolua_err))
+   tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err);
+#endif
+  self->ShowTerrainFlags = ((bool)  tolua_toboolean(tolua_S,2,0))
+;
+ return 0;
+}
+#endif //#ifndef TOLUA_DISABLE
+
 /* get function: Running of class  CEditor */
 #ifndef TOLUA_DISABLE_tolua_get_CEditor_Running
 static int tolua_get_CEditor_Running(lua_State* tolua_S)
@@ -20584,6 +20614,7 @@ TOLUA_API int tolua_stratagus_open (lua_State* tolua_S)
   tolua_beginmodule(tolua_S,"CEditor");
    tolua_variable(tolua_S,"UnitTypes",tolua_get_CEditor_UnitTypes,tolua_set_CEditor_UnitTypes);
    tolua_variable(tolua_S,"StartUnit",tolua_get_CEditor_StartUnit_ptr,NULL);
+   tolua_variable(tolua_S,"ShowTerrainFlags",tolua_get_CEditor_ShowTerrainFlags,tolua_set_CEditor_ShowTerrainFlags);
    tolua_variable(tolua_S,"Running",tolua_get_CEditor_Running,tolua_set_CEditor_Running);
   tolua_endmodule(tolua_S);
   tolua_function(tolua_S,"SetEditorSelectIcon",tolua_stratagus_SetEditorSelectIcon00);
diff --git a/languages/bos-fi.po b/languages/bos-fi.po
index 90f7418..b89d512 100644
--- a/languages/bos-fi.po
+++ b/languages/bos-fi.po
@@ -8,8 +8,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: boswars 2.6\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-05-15 21:05+0300\n"
-"PO-Revision-Date: 2010-05-15 21:08+0300\n"
+"POT-Creation-Date: 2010-05-18 02:23+0300\n"
+"PO-Revision-Date: 2010-05-18 01:41+0300\n"
 "Last-Translator: Kalle Olavi Niemitalo <kon@iki.fi>\n"
 "Language-Team: Kimmo Kalevi Merikivi <fi@li.org>\n"
 "MIME-Version: 1.0\n"
@@ -18,11 +18,11 @@ msgstr ""
 "Language: fi\n"
 "X-Generator: KBabel 1.11.2\n"
 
-#: scripts/boswars.lua:127 scripts/menus/ingame/editor.lua:195
+#: scripts/boswars.lua:127 scripts/menus/ingame/editor.lua:209
 msgid "Energy"
 msgstr "Energia"
 
-#: scripts/boswars.lua:127 scripts/menus/ingame/editor.lua:207
+#: scripts/boswars.lua:127 scripts/menus/ingame/editor.lua:221
 msgid "Magma"
 msgstr "Magma"
 
@@ -90,7 +90,7 @@ msgid "File:"
 msgstr "Tiedosto:"
 
 #: scripts/guichan.lua:535 scripts/guichan.lua:742 scripts/guichan.lua:782
-#: scripts/menus/ingame/editor.lua:109 scripts/menus/network.lua:423
+#: scripts/menus/ingame/editor.lua:123 scripts/menus/network.lua:423
 #: scripts/menus/patch.lua:77
 msgid "Size:"
 msgstr "Koko:"
@@ -232,8 +232,8 @@ msgid "Create New Map"
 msgstr "Luo uusi kartta"
 
 #: scripts/guichan.lua:758 scripts/guichan.lua:813
-#: scripts/menus/campaigns.lua:62 scripts/menus/ingame/editor.lua:87
-#: scripts/menus/ingame/editor.lua:125 scripts/menus/ingame/editor.lua:230
+#: scripts/menus/campaigns.lua:62 scripts/menus/ingame/editor.lua:101
+#: scripts/menus/ingame/editor.lua:139 scripts/menus/ingame/editor.lua:244
 #: scripts/menus/ingame/game.lua:112 scripts/menus/ingame/game.lua:304
 #: scripts/menus/ingame/game.lua:352 scripts/menus/ingame/game.lua:365
 #: scripts/menus/network.lua:176 scripts/menus/network.lua:242
@@ -345,50 +345,54 @@ msgstr "paikkauksista, bugi-ilmoituksista, ideoista."
 msgid "Bos Wars Credits"
 msgstr "Bos Wars -tekijät"
 
+#: scripts/menus/ingame/editor.lua:33 scripts/menus/ingame/editor.lua:66
+msgid "Show ~!terrain attributes"
+msgstr "Näytä ~!maaston piirteet"
+
 # Tämä valikko aukeaa vasta editorin sisällä. Ei siis "editorivalikko"
 # joka kuulostaa että siitä voisi valita haluamansa editorin.
-#: scripts/menus/ingame/editor.lua:49
+#: scripts/menus/ingame/editor.lua:59
 msgid "Editor Menu"
 msgstr "Editorin valikko"
 
-#: scripts/menus/ingame/editor.lua:50 scripts/menus/ingame/game.lua:58
+#: scripts/menus/ingame/editor.lua:60 scripts/menus/ingame/game.lua:58
 msgid "Save (~<F11~>)"
 msgstr "Tallenna (~<F11~>)"
 
-#: scripts/menus/ingame/editor.lua:52
+#: scripts/menus/ingame/editor.lua:62
 msgid "Map Properties (~<F5~>)"
 msgstr "Kartan ominaisuudet (~<F5~>)"
 
-#: scripts/menus/ingame/editor.lua:54
+#: scripts/menus/ingame/editor.lua:64
 msgid "Player Properties (~<F6~>)"
 msgstr "Pelaajien ominaisuudet (~<F6~>)"
 
 # poistuu editorista päävalikkoon
-#: scripts/menus/ingame/editor.lua:57
+#: scripts/menus/ingame/editor.lua:71
 msgid "~!Exit to menu"
 msgstr "~!Poistu valikkoon"
 
-#: scripts/menus/ingame/editor.lua:59
+#: scripts/menus/ingame/editor.lua:73
 msgid "Return to the Editor (~<Esc~>)"
 msgstr "Palaa editoriin (~<Esc~>)"
 
-#: scripts/menus/ingame/editor.lua:68
+#: scripts/menus/ingame/editor.lua:82
 msgid "Save Map"
 msgstr "Tallenna kartta"
 
-#: scripts/menus/ingame/editor.lua:78 scripts/menus/ingame/game.lua:91
+#: scripts/menus/ingame/editor.lua:92 scripts/menus/ingame/game.lua:91
 msgid "~!Save"
 msgstr "~!Tallenna"
 
-#: scripts/menus/ingame/editor.lua:99
+#: scripts/menus/ingame/editor.lua:113
 msgid "Map Properties"
 msgstr "Kartan ominaisuudet"
 
-#: scripts/menus/ingame/editor.lua:101
+#: scripts/menus/ingame/editor.lua:115
 msgid "Map Description:"
 msgstr "Kartan kuvaus:"
 
-#: scripts/menus/ingame/editor.lua:118 scripts/menus/ingame/editor.lua:219
+#: scripts/menus/ingame/editor.lua:132 scripts/menus/ingame/editor.lua:233
 #: scripts/menus/ingame/game.lua:180 scripts/menus/ingame/game.lua:254
 #: scripts/menus/ingame/game.lua:533 scripts/menus/ingame/game.lua:559
 #: scripts/menus/network.lua:67 scripts/menus/options.lua:64
@@ -397,40 +401,40 @@ msgstr "Kartan kuvaus:"
 msgid "~!OK"
 msgstr "~!Valmis"
 
-#: scripts/menus/ingame/editor.lua:140
+#: scripts/menus/ingame/editor.lua:154
 msgid "Player Properties"
 msgstr "Pelaajien ominaisuudet"
 
-#: scripts/menus/ingame/editor.lua:149
+#: scripts/menus/ingame/editor.lua:163
 msgid "Type"
 msgstr "Tyyppi"
 
-#: scripts/menus/ingame/editor.lua:154
+#: scripts/menus/ingame/editor.lua:168
 #, fuzzy
 msgid "Person"
 msgstr "Pelaaja"
 
-#: scripts/menus/ingame/editor.lua:154
+#: scripts/menus/ingame/editor.lua:168
 msgid "Computer"
 msgstr "Tietokone"
 
-#: scripts/menus/ingame/editor.lua:154
+#: scripts/menus/ingame/editor.lua:168
 msgid "Rescue (Passive)"
 msgstr "Pelastettava (passiivinen)"
 
-#: scripts/menus/ingame/editor.lua:155
+#: scripts/menus/ingame/editor.lua:169
 msgid "Rescue (Active)"
 msgstr "Pelastettava (aktiivinen)"
 
-#: scripts/menus/ingame/editor.lua:155
+#: scripts/menus/ingame/editor.lua:169
 msgid "Neutral"
 msgstr "Puolueeton"
 
-#: scripts/menus/ingame/editor.lua:155
+#: scripts/menus/ingame/editor.lua:169
 msgid "Nobody"
 msgstr "Ei kukaan"
 
-#: scripts/menus/ingame/editor.lua:168
+#: scripts/menus/ingame/editor.lua:182
 msgid "AI"
 msgstr "Tekoäly"
 
diff --git a/scripts/editor.lua b/scripts/editor.lua
index 4ff4fe7..d622921 100644
--- a/scripts/editor.lua
+++ b/scripts/editor.lua
@@ -29,6 +29,7 @@
 
 Load("scripts/uilayout.lua")
 
+InitEditorIngameCommandKeys()
 HandleCommandKey = HandleEditorIngameCommandKey
 
 DefineIcon({
diff --git a/scripts/menus/ingame/editor.lua b/scripts/menus/ingame/editor.lua
index 899f752..149243b 100644
--- a/scripts/menus/ingame/editor.lua
+++ b/scripts/menus/ingame/editor.lua
@@ -27,6 +27,12 @@
 --
 --      $Id: game.lua 453 2006-06-26 18:36:19Z feb $
 
+local terrainHotKey
+
+function InitEditorIngameCommandKeys()
+  terrainHotKey = UI:HotKeyOfCaption(_("Show ~!terrain attributes"))
+end
+
 function HandleEditorIngameCommandKey(key, ctrl, alt, shift)
   if ((key == "m" and alt) or key == "f10") then
     RunEditorIngameMenu()
@@ -36,6 +42,8 @@ function HandleEditorIngameCommandKey(key, ctrl, alt, shift)
     RunEditorMapPropertiesMenu()
   elseif (key == "f6") then
     RunEditorPlayerPropertiesMenu()
+  elseif (key == terrainHotKey and not (ctrl or alt)) then
+    Editor.ShowTerrainFlags = not Editor.ShowTerrainFlags
   else
     return false
   end
@@ -45,7 +53,9 @@ end
 
 function RunEditorIngameMenu(s)
   local menu = BosGameMenu()
+  local showTerrain
 
+  menu:setSize(256, 324)
   menu:addLabel(_("Editor Menu"), 128, 11)
   menu:addButton(_("Save (~<F11~>)"), 16, 40,
     function() RunEditorSaveMenu() end)
@@ -53,10 +63,14 @@ function RunEditorIngameMenu(s)
     function() RunEditorMapPropertiesMenu() end)
   menu:addButton(_("Player Properties (~<F6~>)"), 16, 40 + (36 * 2),
     function() RunEditorPlayerPropertiesMenu() end)
+  showTerrain = menu:addCheckBox(_("Show ~!terrain attributes"), 16, 40 + (36 * 3),
+    function() Editor.ShowTerrainFlags = showTerrain:isMarked() end)
+  showTerrain:setFont(Fonts["large"])
+  showTerrain:setMarked(Editor.ShowTerrainFlags)
 
-  menu:addButton(_("~!Exit to menu"), 16, 40 + (36 * 4),
+  menu:addButton(_("~!Exit to menu"), 16, 40 + (36 * 5),
     function() Editor.Running = EditorNotRunning; menu:stop() end)
-  menu:addButton(_("Return to the Editor (~<Esc~>)"), 16, 248,
+  menu:addButton(_("Return to the Editor (~<Esc~>)"), 16, 284,
     function() menu:stop() end)
 
   menu:run(false)
-- 
1.7.1

