Lua API: Fix not updating CursorX/CursorY properly when moving cursor at screen border
--- a/ChangeLog.txt Thu Mar 15 03:29:31 2018 +0100
+++ b/ChangeLog.txt Thu Mar 15 04:33:11 2018 +0100
@@ -116,6 +116,7 @@
* Fix call: SetWeapon(amNothing) now unselects weapon
* Fix call: SetWind did not update flake flying direction
* Fix global: TotalRounds was stuck at -1 for several turns
+ * Fix CursorX, CursorY often not being updated when moving cursor at screen border
====================== 0.9.23 ======================
HIGHLIGHTS:
--- a/hedgewars/uScript.pas Thu Mar 15 03:29:31 2018 +0100
+++ b/hedgewars/uScript.pas Thu Mar 15 04:33:11 2018 +0100
@@ -100,7 +100,7 @@
ScriptLoaded : boolean;
mapDims : boolean;
PointsBuffer: shortstring;
- prevCursorPoint: TPoint; // why is tpoint still in sdlh...
+ PrevCursorX, PrevCursorY: LongInt;
{$IFDEF USE_LUA_SCRIPT}
procedure ScriptPrepareAmmoStore; forward;
@@ -3139,8 +3139,8 @@
exit;
// push game variables so they may be modified by the script
-ScriptSetInteger('CursorX', CursorPoint.X);
-ScriptSetInteger('CursorY', CursorPoint.Y);
+ScriptSetInteger('CursorX', NoPointX);
+ScriptSetInteger('CursorY', NoPointX);
ScriptSetInteger('GameFlags', GameFlags);
ScriptSetInteger('WorldEdge', ord(WorldEdge));
ScriptSetString('Seed', cSeed);
@@ -3380,6 +3380,7 @@
end;
procedure SetGlobals;
+var x, y: LongInt;
begin
ScriptSetInteger('TurnTimeLeft', TurnTimeLeft);
ScriptSetInteger('ReadyTimeLeft', ReadyTimeLeft);
@@ -3388,21 +3389,23 @@
ScriptSetInteger('WaterLine', cWaterLine);
if isCursorVisible and (not bShowAmmoMenu) then
begin
- if (prevCursorPoint.X <> CursorPoint.X) or
- (prevCursorPoint.Y <> CursorPoint.Y) then
+ x:= CursorPoint.X - WorldDx;
+ y:= cScreenHeight - CursorPoint.Y - WorldDy;
+ if (PrevCursorX <> x) or
+ (PrevCursorY <> y) then
begin
- ScriptSetInteger('CursorX', CursorPoint.X - WorldDx);
- ScriptSetInteger('CursorY', cScreenHeight - CursorPoint.Y- WorldDy);
- prevCursorPoint.X:= CursorPoint.X;
- prevCursorPoint.Y:= CursorPoint.Y;
+ ScriptSetInteger('CursorX', x);
+ ScriptSetInteger('CursorY', y);
+ PrevCursorX:= x;
+ PrevCursorY:= y;
end
end
else
begin
ScriptSetInteger('CursorX', NoPointX);
ScriptSetInteger('CursorY', NoPointX);
- prevCursorPoint.X:= NoPointX;
- prevCursorPoint.Y:= NoPointX
+ PrevCursorX:= NoPointX;
+ PrevCursorY:= NoPointX
end;
if not mapDims then
@@ -4023,8 +4026,8 @@
begin
mapDims:= false;
PointsBuffer:= '';
-prevCursorPoint.X:= NoPointX;
-prevCursorPoint.Y:= 0;
+PrevCursorX:= NoPointX;
+PrevCursorY:= NoPointX;
end;
procedure freeModule;