Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
authorWuzzy <Wuzzy2@mail.ru>
Tue, 10 Jul 2018 16:44:13 +0200
changeset 13461 854caa3c9212
parent 13460 c6ecb87b3231
child 13462 4c47a480009b
Lua API: Add parameter forceDisplay to ShowMission to prevent manual hiding
ChangeLog.txt
hedgewars/uCommandHandlers.pas
hedgewars/uScript.pas
hedgewars/uVariables.pas
hedgewars/uWorld.pas
--- a/ChangeLog.txt	Tue Jul 10 16:25:58 2018 +0200
+++ b/ChangeLog.txt	Tue Jul 10 16:44:13 2018 +0200
@@ -40,6 +40,7 @@
  + New call: EnableSwitchHog(): Enable hog switching
  + New call: GetAmmo(ammoType): Returns ammo configuration (corresponds to SetAmmo)
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
+ + New parameter: ShowMission: 6th param. forceDisplay: Set to true to prevent this particular mission panel to be hidden manually by player
  * Fixed variable: TotalRounds was -1 (instead of 0) in first real round after hog placement phase
 
 ====================== 0.9.24.1 ====================
--- a/hedgewars/uCommandHandlers.pas	Tue Jul 10 16:25:58 2018 +0200
+++ b/hedgewars/uCommandHandlers.pas	Tue Jul 10 16:44:13 2018 +0200
@@ -844,7 +844,8 @@
 begin
   s:= s; // avoid compiler hint
   isShowMission:= false;
-  HideMission();
+  if (not isForceMission) then
+    HideMission();
 end;
 
 procedure initModule;
--- a/hedgewars/uScript.pas	Tue Jul 10 16:25:58 2018 +0200
+++ b/hedgewars/uScript.pas	Tue Jul 10 16:44:13 2018 +0200
@@ -544,9 +544,13 @@
 end;
 
 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
+var n: LongInt;
 begin
-    if CheckLuaParamCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then
-        ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)));
+    if CheckAndFetchParamCount(L, 5, 6, 'ShowMission', 'caption, subcaption, text, icon, time [, forceDisplay]', n) then
+        if n = 5 then
+            ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)))
+        else
+            ShowMission(lua_tostringA(L, 1), lua_tostringA(L, 2), lua_tostringA(L, 3), Trunc(lua_tonumber(L, 4)), Trunc(lua_tonumber(L, 5)), lua_toboolean(L, 6));
     lc_showmission:= 0;
 end;
 
--- a/hedgewars/uVariables.pas	Tue Jul 10 16:25:58 2018 +0200
+++ b/hedgewars/uVariables.pas	Tue Jul 10 16:44:13 2018 +0200
@@ -79,6 +79,7 @@
     isSpeed         : boolean;
     isAFK           : boolean;
     isShowMission   : boolean;
+    isForceMission  : boolean;
     SpeedStart      : LongWord;
 
     fastUntilLag    : boolean;
@@ -2845,6 +2846,7 @@
     isSpeed         := false;
     isAFK           := false;
     isShowMission   := false;
+    isForceMission  := false;
     SpeedStart      := 0;
     fastUntilLag    := false;
     fastScrolling   := false;
--- a/hedgewars/uWorld.pas	Tue Jul 10 16:25:58 2018 +0200
+++ b/hedgewars/uWorld.pas	Tue Jul 10 16:44:13 2018 +0200
@@ -31,6 +31,7 @@
 procedure DrawWorld(Lag: LongInt);
 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
+procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt; forceDisplay : boolean);
 procedure HideMission;
 procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring; autoLabels: boolean);
 procedure ShakeCamera(amount: LongInt);
@@ -1606,6 +1607,8 @@
     if missionTex <> nil then
         DrawTextureCentered(0, Min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
     end;
+if missionTimer = 0 then
+    isForceMission := false;
 
 // fps
 {$IFDEF USE_TOUCH_INTERFACE}
@@ -1941,6 +1944,11 @@
 end;
 
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
+begin
+    ShowMission(caption, subcaption, text, icon, time, false);
+end;
+
+procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt; forceDisplay : boolean);
 var r: TSDL_Rect;
 begin
 if cOnlyStats then exit;
@@ -1948,6 +1956,10 @@
 r.w:= 32;
 r.h:= 32;
 
+// If true, then mission panel cannot be hidden by releasing the mission panel key.
+// Is in effect until timer runs out, is hidden with HideMission or ShowMission is called with forceDisplay=false.
+isForceMission := forceDisplay;
+
 if time = 0 then
     time:= 5000;
 missionTimer:= time;
@@ -1970,6 +1982,7 @@
 procedure HideMission;
 begin
     missionTimer:= 0;
+    isForceMission:= false;
 end;
 
 procedure SetAmmoTexts(ammoType: TAmmoType; name: ansistring; caption: ansistring; description: ansistring; autoLabels: boolean);