Advertisement
Xacius

10.27.2016 - WorldInput.lua

Oct 22nd, 2016
6,488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 134.37 KB | None | 0 0
  1. -- ===========================================================================
  2. -- World Input
  3. -- Copyright 2015-2016, Firaxis Games
  4. --
  5. -- Handle input that occurs within the 3D world.
  6. --
  7. -- In-file functions are organized in 3 areas:
  8. -- 1) "Operation" functions, occur agnostic of the input device
  9. -- 2) "Input State" functions, handle input base on up/down/update/or
  10. -- another state of the input device.
  11. -- 3) Event listening, mapping, and pre-processing
  12. --
  13. -- ===========================================================================
  14.  
  15. include("PopupDialogSupport.lua");
  16. -- More interface-specific includes before the initialization
  17.  
  18.  
  19.  
  20. -- ===========================================================================
  21. -- Debug
  22. -- ===========================================================================
  23.  
  24. local m_isDebuging :boolean = false; -- Turn on local debug systems
  25.  
  26. -- ===========================================================================
  27. -- CONSTANTS
  28. -- ===========================================================================
  29.  
  30. local INTERFACEMODE_ENTER :string = "InterfaceModeEnter";
  31. local INTERFACEMODE_LEAVE :string = "InterfaceModeLeave";
  32. local NORMALIZED_DRAG_THRESHOLD :number = 0.035; -- How much movement to kick off a drag
  33. local MOUSE_SCALAR :number = 6.0;
  34. local PAN_SPEED :number = 2;
  35. local ZOOM_SPEED :number = 0.1;
  36. local DOUBLETAP_THRESHHOLD :number = 2;
  37.  
  38.  
  39. -- ===========================================================================
  40. -- Table of tables of functions for each interface mode & event the mode handles
  41. -- (Must be defined before support functions in includes.)
  42. -- ===========================================================================
  43. InterfaceModeMessageHandler =
  44. {
  45. [InterfaceModeTypes.DEBUG] = {},
  46. [InterfaceModeTypes.SELECTION] = {},
  47. [InterfaceModeTypes.MOVE_TO] = {},
  48. [InterfaceModeTypes.ROUTE_TO] = {},
  49. [InterfaceModeTypes.ATTACK] = {},
  50. [InterfaceModeTypes.RANGE_ATTACK] = {},
  51. [InterfaceModeTypes.CITY_RANGE_ATTACK] = {},
  52. [InterfaceModeTypes.DISTRICT_RANGE_ATTACK] = {},
  53. [InterfaceModeTypes.AIR_ATTACK] = {},
  54. [InterfaceModeTypes.WMD_STRIKE] = {},
  55. [InterfaceModeTypes.ICBM_STRIKE] = {},
  56. [InterfaceModeTypes.EMBARK] = {},
  57. [InterfaceModeTypes.DISEMBARK] = {},
  58. [InterfaceModeTypes.DEPLOY] = {},
  59. [InterfaceModeTypes.REBASE] = {},
  60. [InterfaceModeTypes.BUILDING_PLACEMENT] = {},
  61. [InterfaceModeTypes.DISTRICT_PLACEMENT] = {},
  62. [InterfaceModeTypes.MAKE_TRADE_ROUTE] = {},
  63. [InterfaceModeTypes.TELEPORT_TO_CITY] = {},
  64. [InterfaceModeTypes.FORM_CORPS] = {},
  65. [InterfaceModeTypes.FORM_ARMY] = {},
  66. [InterfaceModeTypes.AIRLIFT] = {},
  67. [InterfaceModeTypes.COASTAL_RAID] = {},
  68. [InterfaceModeTypes.PLACE_MAP_PIN] = {},
  69. [InterfaceModeTypes.CITY_MANAGEMENT] = {},
  70. [InterfaceModeTypes.WB_SELECT_PLOT] = {},
  71. [InterfaceModeTypes.SPY_CHOOSE_MISSION] = {},
  72. [InterfaceModeTypes.SPY_TRAVEL_TO_CITY] = {},
  73. [InterfaceModeTypes.NATURAL_WONDER] = {},
  74. [InterfaceModeTypes.VIEW_MODAL_LENS] = {}
  75. }
  76.  
  77.  
  78. -- ===========================================================================
  79. -- MEMBERS
  80. -- ===========================================================================
  81.  
  82. local DefaultMessageHandler :table = {};
  83. local m_actionHotkeyToggleGrid :number = Input.GetActionId("ToggleGrid"); -- Hot Key Handling
  84. local m_actionHotkeyOnlinePause :number = Input.GetActionId("OnlinePause"); -- Hot Key Handling
  85. local m_kTouchesDownInWorld :table = {}; -- Tracks "down" touches that occurred in this context.
  86. local m_isTouchEnabled :boolean= false;
  87. local m_isALTDown :boolean= false;
  88. local m_isMouseButtonLDown :boolean= false;
  89. local m_isMouseButtonMDown :boolean= false;
  90. local m_isMouseButtonRDown :boolean= false;
  91. local m_isMouseDownInWorld :boolean= false; -- Did mouse-down start here (true), or in some other UI context?
  92. local m_isMouseDragging :boolean= false;
  93. local m_isTouchDragging :boolean= false;
  94. local m_isTouchZooming :boolean= false;
  95. local m_isTouchPathing :boolean= false;
  96. local m_isDoubleTapping :boolean= false;
  97. local m_touchCount :number = 0; -- # of touches currently occuring
  98. local m_touchStartPlotX :number = -1;
  99. local m_touchStartPlotY :number = -1;
  100. local m_touchTotalNum :number = 0; -- # of multiple touches that occurred
  101. local m_mapZoomStart :number = 0;
  102. local m_dragStartWorldX :number = 0;
  103. local m_dragStartWorldY :number = 0;
  104. local m_dragStartFocusWorldX :number = 0;
  105. local m_dragStartFocusWorldY :number = 0;
  106. local m_dragStartX :number = 0; -- Mouse or virtual mouse (of average touch points) X
  107. local m_dragStartY :number = 0; -- Mouse or virtual mouse (of average touch points) Y
  108. local m_dragX :number = 0;
  109. local m_dragY :number = 0;
  110. local m_edgePanX :number = 0;
  111. local m_edgePanY :number = 0;
  112. local m_constrainToPlotID :number = 0;
  113. local ms_bGridOn :boolean= true;
  114. local m_isMapDragDisabled :boolean = false;
  115. local m_isCancelDisabled :boolean = false; -- Is a cancelable action (e.g., right-click for district placement) been disabled?
  116. local m_debugTrace :table = {}; -- debug
  117. local m_cachedPathUnit :table;
  118. local m_cachedPathPlotId :number;
  119. local m_previousTurnsCount :number = 0;
  120. local m_kConfirmWarDialog :table;
  121. local m_targetPlots :table;
  122. local m_focusedTargetPlot :number = -1;
  123. local m_WBMouseOverPlot :number = -1;
  124. local m_kTutorialPermittedHexes :table = nil; -- Which hexes are permitted for selection by the tutorial (nil if disabled)
  125. local m_kTutorialUnitHexRestrictions :table = nil; -- Any restrictions on where units can move. (Key=UnitType, Value={restricted plotIds})
  126. local m_isPlotFlaggedRestricted :boolean = false; -- In a previous operation to determine a move path, was a plot flagged restrticted/bad? (likely due to the tutorial system)
  127. local m_kTutorialUnitMoveRestrictions :table = nil; -- Restrictions for moving (anywhere) of a selected unit type.
  128.  
  129.  
  130. -- XACIUS MODS
  131. -- variables for additional features:
  132. local showMapYield:boolean = not UserConfiguration.ShowMapYield();
  133.  
  134.  
  135.  
  136.  
  137. -- ===========================================================================
  138. -- FUNCTIONS
  139. -- ===========================================================================
  140.  
  141.  
  142. -- ===========================================================================
  143. -- DEBUG:
  144. -- trace(msg) Add a trace message to be output later (to prevent stalling
  145. -- game while looking at per-frame input).
  146. -- dump() Send to output all the collected traces
  147. -- clear() Empties trace buffer
  148. -- ===========================================================================
  149. function trace( msg:string ) m_debugTrace[table.count(m_debugTrace)+1] = msg; end
  150. function dump() print("DebugTrace: "..table.concat(m_debugTrace)); end
  151. function clear() m_debugTrace = {}; end
  152.  
  153.  
  154.  
  155. -- .,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,
  156. --
  157. -- OPERATIONS
  158. --
  159. -- .,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,
  160.  
  161.  
  162. -- ===========================================================================
  163. -- Empty function (to override default)
  164. -- ===========================================================================
  165. function OnDoNothing()
  166. end
  167.  
  168.  
  169. -- ===========================================================================
  170. -- Pan camera
  171. -- ===========================================================================
  172. function ProcessPan( panX :number, panY :number )
  173.  
  174. if( panY == 0.0 ) then
  175. if( m_isUPpressed ) then panY = panY + PAN_SPEED; end
  176. if( m_isDOWNpressed) then panY = panY - PAN_SPEED; end
  177. end
  178.  
  179. if( panX == 0.0 ) then
  180. if( m_isRIGHTpressed ) then panX = panX + PAN_SPEED; end
  181. if( m_isLEFTpressed ) then panX = panX - PAN_SPEED; end
  182. end
  183.  
  184. UI.PanMap( panX, panY );
  185. end
  186.  
  187.  
  188. -- ===========================================================================
  189. -- Input conditions are set for edge camera panning
  190. -- ===========================================================================
  191. function IsAbleToEdgePan()
  192. return UserConfiguration.IsEdgePanEnabled() or ( (UI.GetInterfaceMode() == InterfaceModeTypes.SELECTION) and m_isMouseButtonRDown );
  193. end
  194.  
  195.  
  196. -- ===========================================================================
  197. -- Have world camera focus on a plot
  198. -- plotId, the plot # to look at
  199. -- ===========================================================================
  200. function SnapToPlot( plotId:number )
  201. if (Map.IsPlot(plotId)) then
  202. local plot = Map.GetPlotByIndex(plotId);
  203. UI.LookAtPlot( plot );
  204. end
  205. end
  206.  
  207. -- ===========================================================================
  208. function IsCancelAllowed()
  209. return (not m_isCancelDisabled);
  210. end
  211.  
  212. -- ===========================================================================
  213. -- Perform a camera zoom based on the native 2-finger gesture
  214. -- ===========================================================================
  215. function RealizeTouchGestureZoom()
  216. if TouchManager:IsInGesture(Gestures.Stretching) then
  217. local fDistance:number = TouchManager:GetGestureDistance(Gestures.Stretching);
  218. local normalizedX :number, normalizedY:number = UIManager:GetNormalizedMousePos();
  219.  
  220. -- If zooming just started, get the starting zoom level.
  221. if not m_isTouchZooming then
  222. m_mapZoomStart = UI.GetMapZoom();
  223. m_isTouchZooming = true;
  224. end
  225.  
  226. local fZoomDelta:number = - (fDistance * 0.5);
  227. local fZoom:number = m_mapZoomStart + fZoomDelta; -- Adjust the zoom level. This speed scalar should be put into the UI configuration.
  228.  
  229. if( fZoomDelta < 0.0 ) then
  230. --UI.SetMapZoom( fZoom, normalizedX, normalizedY );
  231. UI.SetMapZoom( fZoom, 0.0, 0.0 );
  232. else
  233. --UI.SetMapZoom( fZoom, normalizedX, normalizedY );
  234. UI.SetMapZoom( fZoom, 0.0, 0.0 );
  235. end
  236.  
  237. --LuaEvents.WorldInput_TouchPlotTooltipHide(); -- Once this gestures starts, stop and plot tooltip
  238. else
  239. m_isTouchZooming = false;
  240. end
  241. end
  242.  
  243. -- ===========================================================================
  244. function GetCurrentlySelectUnitIndex( unitList:table, ePlayer:number )
  245. local iSelectedUnit :number = -1; -- Which unit index is selected. This is the unit index for the player's units, not all the units in the list
  246. local iCount :number = 0; -- # of units in the list owned by the player
  247. for i, pUnit in ipairs(unitList) do
  248. -- Owned by the local player?
  249. if (pUnit:GetOwner() == ePlayer) then
  250. -- Already selected?
  251. if UI.IsUnitSelected(pUnit) then
  252. iSelectedUnit = iCount;
  253. end
  254. iCount = iCount + 1;
  255. end
  256. end
  257.  
  258. return iSelectedUnit;
  259. end
  260.  
  261. -- ===========================================================================
  262. function SelectNextUnit(unitList:table, iCurrentlySelectedUnit:number, ePlayer:number, bWrap:boolean)
  263. if iCurrentlySelectedUnit == -1 then
  264. -- Nothing selected yet
  265. for i, pUnit in ipairs(unitList) do
  266. -- Owned by the player?
  267. if (pUnit:GetOwner() == ePlayer) then
  268. SelectUnit(pUnit);
  269. end
  270. end
  271. else
  272. local bSelected = false;
  273. local iCount = 0; -- number of units in the list owned by the player
  274. for i, pUnit in ipairs(unitList) do
  275. -- Owned by the player?
  276. if (pUnit:GetOwner() == ePlayer) then
  277. if (iCount > iCurrentlySelectedUnit) then
  278. SelectUnit(pUnit);
  279. bSelected = true;
  280. break;
  281. end
  282. iCount = iCount + 1;
  283. end
  284. end
  285.  
  286. if not bSelected and bWrap then
  287. -- Either the input was wrong or we wrapped, go back and select the first one.
  288. for i, pUnit in ipairs(unitList) do
  289. -- Owned by the player?
  290. if (pUnit:GetOwner() == ePlayer) then
  291. SelectUnit(pUnit);
  292. break;
  293. end
  294. end
  295. end
  296. end
  297. end
  298.  
  299. -- ===========================================================================
  300. -- Selects a unit but firsts deselect any current unit, thereby forcing
  301. -- a cache refresh.
  302. -- ===========================================================================
  303. function SelectUnit( kUnit:table )
  304. UI.DeselectUnit(kUnit);
  305. UI.SelectUnit(kUnit);
  306. end
  307.  
  308. -- ===========================================================================
  309. -- Returns if a specific plot is allowed to be selected.
  310. -- This is generally always true except when the tutorial is running to lock
  311. -- down some (or all) of the plots.
  312. -- ===========================================================================
  313. function IsSelectionAllowedAt( plotId:number )
  314. if m_kTutorialPermittedHexes == nil then return true; end
  315. for i,allowedId:number in ipairs( m_kTutorialPermittedHexes ) do
  316. if allowedId == plotId then
  317. return true;
  318. end
  319. end
  320. return false;
  321. end
  322.  
  323. -- ===========================================================================
  324. -- Selects the unit or city at the plot passed in.
  325. -- ===========================================================================
  326. function SelectInPlot( plotX:number, plotY:number )
  327.  
  328. local kUnitList :table = Units.GetUnitsInPlotLayerID( plotX, plotY, MapLayers.ANY );
  329. local tryCity :boolean= false;
  330. local eLocalPlayer :number = Game.GetLocalPlayer();
  331. local pCity :table = Cities.GetCityInPlot( plotX, plotY );
  332. if pCity ~= nil then
  333. if (pCity:GetOwner() ~= eLocalPlayer) then
  334. pCity = nil;
  335. end
  336. end
  337.  
  338. -- If there are units to try selecting...
  339. if table.count(kUnitList) ~= 0 then
  340. -- Get any currently selected unit so we can cycle to the next.
  341. local iSelected:number = GetCurrentlySelectUnitIndex(kUnitList, eLocalPlayer);
  342.  
  343. -- Cycle to the next, or select the first one if nothing was selected and there is no city
  344. SelectNextUnit(kUnitList, iSelected, eLocalPlayer, pCity == nil);
  345.  
  346. local iNewSelected = GetCurrentlySelectUnitIndex(kUnitList, eLocalPlayer);
  347. if (iNewSelected == -1 or (iNewSelected == iSelected and pCity ~= nil)) then
  348. -- No valid units to select
  349. UI.DeselectAllUnits();
  350. tryCity = true;
  351. else
  352. if (iNewSelected ~= -1 and iNewSelected ~= iSelected) then
  353. local pNewSelectedUnit = UI.GetHeadSelectedUnit();
  354. if (pNewSelectedUnit ~= nil and UI.RebuildSelectionList ~= nil) then -- Checking UI.RebuildSelectionList, so that if an artist fetches the scripts before the next build, they won't be stuck. Remove that check ASAP.
  355. -- The user has manually selected a unit, rebuild the selection list from that unit.
  356. UI.RebuildSelectionList(pNewSelectedUnit);
  357. end
  358. end
  359. end
  360. else
  361. UI.DeselectAllUnits();
  362. tryCity = true;
  363. end
  364.  
  365. if tryCity then
  366. if pCity ~= nil then
  367. UI.SelectCity(pCity);
  368. end
  369. -- No else, as this would be the case when click on a city banner,
  370. -- and so the CityBannerManager will handle the selection.
  371. end
  372.  
  373. return true;
  374. end
  375.  
  376. -- ===========================================================================
  377. -- Has the player moved a down mouse or touch enough that a drag should be
  378. -- considered?
  379. -- RETURNS: true if a drag is occurring.
  380. -- ===========================================================================
  381. function IsDragThreshholdMet()
  382. local normalizedX :number, normalizedY:number = UIManager:GetNormalizedMousePos();
  383. return
  384. math.abs(normalizedX - m_dragStartX) > NORMALIZED_DRAG_THRESHOLD or
  385. math.abs(normalizedY - m_dragStartY) > NORMALIZED_DRAG_THRESHOLD;
  386. end
  387.  
  388. -- ===========================================================================
  389. -- Setup to start dragging the map.
  390. -- ===========================================================================
  391. function ReadyForDragMap()
  392. m_dragStartX, m_dragStartY = UIManager:GetNormalizedMousePos();
  393. m_dragStartFocusWorldX, m_dragStartFocusWorldY = UI.GetMapLookAtWorldTarget();
  394. m_dragStartWorldX, m_dragStartWorldY = UI.GetWorldFromNormalizedScreenPos_NoWrap( m_dragStartX, m_dragStartY );
  395. m_dragX = m_dragStartX;
  396. m_dragY = m_dragStartY;
  397. LuaEvents.WorldInput_DragMapBegin();
  398. end
  399.  
  400. -- ===========================================================================
  401. -- Drag (or spin) the camera based new position
  402. -- ===========================================================================
  403. function UpdateDragMap()
  404.  
  405. -- Obtain either the actual mouse position, or for touch, the virtualized
  406. -- mouse position based on the "average" of all touches:
  407. local x:number, y:number= UIManager:GetNormalizedMousePos();
  408. local dx:number = m_dragX - x;
  409. local dy:number = m_dragY - y;
  410.  
  411. -- Early out if no change:
  412. -- Need m_drag... checks or snap to 0,0 can occur.
  413. if (dx==0 and dy==0) or (m_dragStartWorldX==0 and m_dragStartFocusWorldX==0) then
  414. return;
  415. end
  416. if m_isMapDragDisabled then
  417. return;
  418. end
  419.  
  420. if m_isALTDown then
  421. UI.SpinMap( m_dragStartX - x, m_dragStartY - y );
  422. else
  423. UI.DragMap( x, y, m_dragStartWorldX, m_dragStartWorldY, m_dragStartFocusWorldX, m_dragStartFocusWorldY );
  424. end
  425.  
  426. m_dragX = x;
  427. m_dragY = y;
  428. end
  429.  
  430. -- ===========================================================================
  431. -- Reset drag variables for next go around.
  432. -- ===========================================================================
  433. function EndDragMap()
  434. UI.SpinMap( 0.0, 0.0 );
  435.  
  436. LuaEvents.WorldInput_DragMapEnd();
  437. m_dragX = 0;
  438. m_dragY = 0;
  439. m_dragStartX = 0;
  440. m_dragStartY = 0;
  441. m_dragStartFocusWorldX = 0;
  442. m_dragStartFocusWorldY = 0;
  443. m_dragStartWorldX = 0;
  444. m_dragStartWorldY = 0;
  445. end
  446.  
  447.  
  448. -- ===========================================================================
  449. -- True if a given unit type is allowed to move to a plot.
  450. -- ===========================================================================
  451. function IsUnitTypeAllowedToMoveToPlot( unitType:string, plotId:number )
  452. if m_kTutorialUnitHexRestrictions == nil then return true; end
  453. if m_kTutorialUnitHexRestrictions[unitType] ~= nil then
  454. for _,restrictedPlotId:number in ipairs(m_kTutorialUnitHexRestrictions[unitType]) do
  455. if plotId == restrictedPlotId then
  456. return false; -- Found in restricted list, nope, permission denied to move.
  457. end
  458. end
  459. end
  460. return true;
  461. end
  462.  
  463. -- ===========================================================================
  464. -- Returns true if a unit can move to a particular plot.
  465. -- This is after the pathfinder may have returned that it's okay, but another
  466. -- system (such as the tutorial) has locked it down.
  467. -- ===========================================================================
  468. function IsUnitAllowedToMoveToCursorPlot( pUnit:table )
  469. if m_kTutorialUnitHexRestrictions == nil then return true; end
  470. if m_isPlotFlaggedRestricted then return false; end -- Previous call to check path showed player ending on hex that was restricted.
  471.  
  472. local unitType :string = GameInfo.Units[pUnit:GetUnitType()].UnitType;
  473. local plotId :number = UI.GetCursorPlotID();
  474. return (not m_isPlotFlaggedRestricted) and IsUnitTypeAllowedToMoveToPlot( unitType, plotId );
  475. end
  476.  
  477. -- ===========================================================================
  478. -- RETURNS true if the plot is considered a bad move for a unit.
  479. -- Also returns the plotId (if bad)
  480. -- ===========================================================================
  481. function IsPlotPathRestrictedForUnit( kPlotPath:table, kTurnsList:table, pUnit:table )
  482. local endPlotId:number = kPlotPath[table.count(kPlotPath)];
  483. if m_constrainToPlotID ~= 0 and endPlotId ~= m_constrainToPlotID then
  484. return true, m_constrainToPlotID;
  485. end
  486.  
  487. local unitType:string = GameInfo.Units[pUnit:GetUnitType()].UnitType;
  488.  
  489. -- Is the unit type just not allowed to be moved at all.
  490. if m_kTutorialUnitMoveRestrictions ~= nil and m_kTutorialUnitMoveRestrictions[unitType] ~= nil then
  491. return true, -1;
  492. end
  493.  
  494. -- Is path traveling through a restricted plot?
  495. -- Ignore the first plot, as a unit may be on a restricted plot and the
  496. -- goal is just to get it off of it (and never come back.)
  497. if m_kTutorialUnitHexRestrictions ~= nil then
  498. if m_kTutorialUnitHexRestrictions[unitType] ~= nil then
  499. local lastTurn :number = 1;
  500. local lastRestrictedPlot:number = -1;
  501. for i,plotId in ipairs(kPlotPath) do
  502. -- Past the first plot
  503. if i > 1 then
  504. if kTurnsList[i] == lastTurn then
  505. lastRestrictedPlot = -1; -- Same turn? Reset and previously found restricitions (unit is passing through)
  506. if (not IsUnitTypeAllowedToMoveToPlot( unitType, plotId )) then
  507. lastTurn = kTurnsList[i];
  508. lastRestrictedPlot = plotId;
  509. end
  510. else
  511. if lastRestrictedPlot ~= -1 then
  512. return true, lastRestrictedPlot;
  513. end
  514. if (not IsUnitTypeAllowedToMoveToPlot( unitType, plotId )) then
  515. lastTurn = kTurnsList[i];
  516. lastRestrictedPlot = plotId;
  517. end
  518. end
  519. end
  520. end
  521. if lastRestrictedPlot ~= -1 then
  522. return true, lastRestrictedPlot;
  523. end
  524. end
  525. end
  526.  
  527. m_isPlotFlaggedRestricted = false;
  528. return false;
  529. end
  530.  
  531.  
  532. -- ===========================================================================
  533. -- LUA Event
  534. -- Add plot(s) to the restriction list; units of a certain type may not
  535. -- move to there.
  536. -- ===========================================================================
  537. function OnTutorial_AddUnitHexRestriction( unitType:string, kPlotIds:table )
  538. if m_kTutorialUnitHexRestrictions == nil then
  539. m_kTutorialUnitHexRestrictions = {};
  540. end
  541. if m_kTutorialUnitHexRestrictions[unitType] == nil then
  542. m_kTutorialUnitHexRestrictions[unitType] = {};
  543. end
  544. for _,plotId:number in ipairs(kPlotIds) do
  545. table.insert(m_kTutorialUnitHexRestrictions[unitType], plotId );
  546. end
  547. end
  548.  
  549. -- ===========================================================================
  550. -- LUA Event
  551. -- ===========================================================================
  552. function OnTutorial_RemoveUnitHexRestriction( unitType:string, kPlotIds:table )
  553. if m_kTutorialUnitHexRestrictions == nil then
  554. UI.DataError("Cannot RemoveUnitHexRestriction( "..unitType.." ...) as no restrictions are set.");
  555. return;
  556. end
  557. if m_kTutorialUnitHexRestrictions[unitType] == nil then
  558. UI.DataError("Cannot RemoveUnitHexRestriction( "..unitType.." ...) as a restriction for that unit type is not set.");
  559. return;
  560. end
  561.  
  562. -- Remove all the items in the restriction list based on what was passed in.
  563. for _,plotId in ipairs( kPlotIds ) do
  564. local isRemoved:boolean = false;
  565. for i=#m_kTutorialUnitHexRestrictions[unitType],1,-1 do
  566. if m_kTutorialUnitHexRestrictions[unitType][i] == plotId then
  567. table.remove( m_kTutorialUnitHexRestrictions[unitType], i);
  568. isRemoved = true;
  569. break;
  570. end
  571. end
  572. if (not isRemoved) then
  573. UI.DataError("Cannot remove restriction for the plot "..tostring(plotId)..", it wasn't found in the list for unit "..unitType);
  574. end
  575. end
  576. end
  577.  
  578. -- ===========================================================================
  579. -- LUA Event
  580. -- ===========================================================================
  581. function OnTutorial_ClearAllUnitHexRestrictions()
  582. m_kTutorialUnitHexRestrictions = nil;
  583. end
  584.  
  585.  
  586. -- ===========================================================================
  587. -- LUA Event
  588. -- Prevent a unit type from being selected.
  589. -- ===========================================================================
  590. function OnTutorial_AddUnitMoveRestriction( unitType:string )
  591. if m_kTutorialUnitMoveRestrictions == nil then
  592. m_kTutorialUnitMoveRestrictions = {};
  593. end
  594. if m_kTutorialUnitMoveRestrictions[unitType] then
  595. UI.DataError("Setting tutorial WorldInput unit selection for '"..unitType.."' but it's already set to restricted!");
  596. end
  597.  
  598. m_kTutorialUnitMoveRestrictions[unitType] = true;
  599. end
  600.  
  601.  
  602. -- ===========================================================================
  603. -- LUA Event
  604. -- optionalUnitType The unit to remove from the restriction list or nil
  605. -- to completely clear the list.
  606. -- ===========================================================================
  607. function OnTutorial_RemoveUnitMoveRestrictions( optionalUnitType:string )
  608. -- No arg, clear all...
  609. if optionalUnitType == nil then
  610. m_kTutorialUnitMoveRestrictions = nil;
  611. else
  612. -- Clear a specific type from restriction list.
  613. if m_kTutorialUnitMoveRestrictions[optionalUnitType] == nil then
  614. UI.DataError("Tutorial did not reset WorldInput selection for the unit type '"..optionalUnitType.."' since it's not in the restriction list.");
  615. end
  616. m_kTutorialUnitMoveRestrictions[optionalUnitType] = nil;
  617. end
  618. end
  619.  
  620.  
  621. -- ===========================================================================
  622. -- Perform a movement path operation (if there is a selected unit).
  623. -- ===========================================================================
  624. function MoveUnitToCursorPlot( pUnit:table )
  625.  
  626. -- Clear any paths set for moving the unit and ensure any raised lens
  627. -- due to the selection, is turned off.
  628. ClearMovementPath();
  629. UILens.SetActive("Default");
  630.  
  631. local plotID:number = UI.GetCursorPlotID();
  632. if (not Map.IsPlot(plotID)) then
  633. return;
  634. end
  635.  
  636. if (m_constrainToPlotID == 0 or plotID == m_constrainToPlotID) and not GameInfo.Units[pUnit:GetUnitType()].IgnoreMoves then
  637. local plotX:number, plotY:number = UI.GetCursorPlotCoord();
  638. if m_previousTurnsCount >= 1 then
  639. UI.PlaySound("UI_Move_Confirm");
  640. end
  641. MoveUnitToPlot( pUnit, plotX, plotY );
  642. end
  643. end
  644.  
  645. -- ===========================================================================
  646. function UnitMovementCancel()
  647. ClearMovementPath();
  648. UILens.SetActive("Default");
  649. end
  650.  
  651. -- ===========================================================================
  652. -- Unit Range Attack
  653. -- ===========================================================================
  654. function UnitRangeAttack( plotID:number )
  655. local plot :table = Map.GetPlotByIndex(plotID);
  656. local tParameters :table = {};
  657. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  658. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  659.  
  660. local pSelectedUnit :table = UI.GetHeadSelectedUnit();
  661. if pSelectedUnit == nil then
  662. UI.DataError("A UnitRangeAttack( "..tostring(plotID).." ) was attempted but there is no selected unit.");
  663. return;
  664. end
  665.  
  666. if UnitManager.CanStartOperation( pSelectedUnit, UnitOperationTypes.RANGE_ATTACK, nil, tParameters) then
  667. UnitManager.RequestOperation( pSelectedUnit, UnitOperationTypes.RANGE_ATTACK, tParameters);
  668. else
  669. -- LClicking on an empty hex, deselect unit.
  670. UI.DeselectUnit( pSelectedUnit );
  671. end
  672. -- Always leave ranged attack mode after interaction.
  673. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  674. end
  675.  
  676. -- ===========================================================================
  677. -- Clear the visual representation (and cache) of the movement path
  678. -- ===========================================================================
  679. function ClearMovementPath()
  680. UILens.ClearLayerHexes( LensLayers.MOVEMENT_PATH );
  681. UILens.ClearLayerHexes( LensLayers.NUMBERS );
  682. UILens.ClearLayerHexes( LensLayers.ATTACK_RANGE );
  683. m_cachedPathUnit = nil;
  684. m_cachedPathPlotId = -1;
  685. end
  686.  
  687. -- ===========================================================================
  688. function ClearRangeAttackDragging()
  689. local bWasDragging:boolean = m_isMouseDragging;
  690. OnMouseEnd( pInputStruct );
  691. return bWasDragging;
  692. end
  693.  
  694. -- ===========================================================================
  695. -- Update the 3D displayed path for a unit.
  696. -- ===========================================================================
  697. function RealizeMovementPath()
  698.  
  699. if not UI.IsMovementPathOn() or UI.IsGameCoreBusy() then
  700. return;
  701. end
  702.  
  703. -- Bail if no selected unit.
  704. local kUnit :table = UI.GetHeadSelectedUnit();
  705. if kUnit == nil then
  706. UILens.SetActive("Default");
  707. m_cachedPathUnit = nil;
  708. m_cachedPathPlotId = -1;
  709. return;
  710. end
  711.  
  712. -- Bail if unit is not a type that allows movement.
  713. if GameInfo.Units[kUnit:GetUnitType()].IgnoreMoves then
  714. return;
  715. end
  716.  
  717. -- Bail if end plot is not determined.
  718. local endPlotId :number = UI.GetCursorPlotID();
  719. if (not Map.IsPlot(endPlotId)) then
  720. return;
  721. end
  722.  
  723. -- Only update if a new unit or new plot from the previous update.
  724. if m_cachedPathUnit ~= kUnit or m_cachedPathPlotId ~= endPlotId then
  725. UILens.ClearLayerHexes( LensLayers.MOVEMENT_PATH );
  726. UILens.ClearLayerHexes( LensLayers.NUMBERS );
  727. UILens.ClearLayerHexes( LensLayers.ATTACK_RANGE );
  728. if m_cachedPathPlotId ~= -1 then
  729. UILens.UnFocusHex( LensLayers.ATTACK_RANGE, m_cachedPathPlotId );
  730. end
  731.  
  732. m_cachedPathUnit = kUnit;
  733. m_cachedPathPlotId = endPlotId;
  734.  
  735.  
  736. -- Obtain ordered list of plots.
  737. local turnsList : table;
  738. local obstacles : table;
  739. local variations : table = {}; -- 2 to 3 values
  740. local pathPlots : table = {};
  741. local eLocalPlayer : number = Game.GetLocalPlayer();
  742.  
  743. --check for unit position swap first
  744. local startPlotId :number = Map.GetPlot(kUnit:GetX(),kUnit:GetY()):GetIndex();
  745. if startPlotId ~= endPlotId then
  746. local plot :table = Map.GetPlotByIndex(endPlotId);
  747. local tParameters :table = {};
  748. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  749. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  750. if ( UnitManager.CanStartOperation( kUnit, UnitOperationTypes.SWAP_UNITS, nil, tParameters) ) then
  751. lensNameBase = "MovementGood";
  752. if not UILens.IsLensActive(lensNameBase) then
  753. UILens.SetActive(lensNameBase);
  754. end
  755. table.insert(pathPlots, startPlotId);
  756. table.insert(pathPlots, endPlotId);
  757. table.insert(variations, {lensNameBase.."_Destination",startPlotId} );
  758. table.insert(variations, {lensNameBase.."_Counter", startPlotId} ); -- show counter pip
  759. UI.AddNumberToPath( 1, startPlotId);
  760. table.insert(variations, {lensNameBase.."_Destination",endPlotId} );
  761. table.insert(variations, {lensNameBase.."_Counter", endPlotId} ); -- show counter pip
  762. UI.AddNumberToPath( 1, endPlotId);
  763. UILens.SetLayerHexesPath(LensLayers.MOVEMENT_PATH, eLocalPlayer, pathPlots, variations);
  764. return;
  765. end
  766. end
  767.  
  768. pathPlots, turnsList, obstacles = UnitManager.GetMoveToPath( kUnit, endPlotId );
  769.  
  770. if table.count(pathPlots) > 1 then
  771. -- Start and end art "variations" when drawing path
  772. local startHexId:number = pathPlots[1];
  773. local endHexId :number = pathPlots[table.count(pathPlots)];
  774.  
  775. -- Check if our desired "movement" is actually a ranged attack. Early out if so.
  776. local isImplicitRangedAttack :boolean = false;
  777.  
  778. local pResults = UnitManager.GetOperationTargets(kUnit, UnitOperationTypes.RANGE_ATTACK );
  779. local pAllPlots = pResults[UnitOperationResults.PLOTS];
  780. if pAllPlots ~= nil then
  781. for i, modifier in ipairs( pResults[UnitOperationResults.MODIFIERS] ) do
  782. if modifier == UnitOperationResults.MODIFIER_IS_TARGET then
  783. if pAllPlots[i] == endPlotId then
  784. isImplicitRangedAttack = true;
  785. break;
  786. end
  787. end
  788. end
  789. end
  790.  
  791. if isImplicitRangedAttack then
  792. -- Unit can apparently perform a ranged attack on that hex. Show the arrow!
  793. local kVariations:table = {};
  794. local kEmpty:table = {};
  795. table.insert(kVariations, {"EmptyVariant", startHexId, endHexId} );
  796. UILens.SetLayerHexesArea(LensLayers.ATTACK_RANGE, eLocalPlayer, kEmpty, kVariations);
  797.  
  798. -- Focus must be called AFTER the attack range variants are set.
  799. UILens.FocusHex( LensLayers.ATTACK_RANGE, endHexId );
  800. return; -- We're done here. Do not show a movement path.
  801. end
  802.  
  803. -- Any plots of path in Fog Of War or midfog?
  804. local isPathInFog:boolean = false;
  805. local pPlayerVis :table = PlayersVisibility[eLocalPlayer];
  806. if pPlayerVis ~= nil then
  807. for _,plotIds in pairs(pathPlots) do
  808. isPathInFog = not pPlayerVis:IsVisible(plotIds);
  809. if isPathInFog then
  810. break;
  811. end
  812. end
  813. end
  814.  
  815. -- If any plots are in Fog Of War (FOW) then switch to the FOW movement lens.
  816. local lensNameBase :string = "MovementGood";
  817. local movePostfix :string = "";
  818. local isPathHaveRestriction,restrictedPlotId = IsPlotPathRestrictedForUnit( pathPlots, turnsList, kUnit );
  819.  
  820. if isPathHaveRestriction then
  821. lensNameBase = "MovementBad";
  822. m_isPlotFlaggedRestricted = true;
  823. if restrictedPlotId ~= nil and restrictedPlotId ~= -1 then
  824. table.insert(variations, {"MovementBad_Destination", restrictedPlotId} );
  825. end
  826. elseif isPathInFog then
  827. lensNameBase = "MovementFOW";
  828. movePostfix = "_FOW";
  829. end
  830. -- Turn on lens.
  831. if not UILens.IsLensActive(lensNameBase) then
  832. UILens.SetActive(lensNameBase);
  833. end
  834.  
  835. -- is there an enemy unit at the end?
  836. local bIsEnemyAtEnd:boolean = false;
  837. local endPlot :table = Map.GetPlotByIndex(endPlotId);
  838. if( endPlot ~= nil ) then
  839. local unitList = Units.GetUnitsInPlotLayerID( endPlot:GetX(), endPlot:GetY(), MapLayers.ANY );
  840. for i, pUnit in ipairs(unitList) do
  841. if( eLocalPlayer ~= pUnit:GetOwner() and pPlayerVis ~= nil and pPlayerVis:IsVisible(endPlot:GetX(), endPlot:GetY()) and pPlayerVis:IsUnitVisible(pUnit) ) then
  842. bIsEnemyAtEnd = true;
  843. end
  844. end
  845. end
  846.  
  847. -- Hide the destination indicator only if the attack is guaranteed this turn.
  848. -- Regular movements and attacks planned for later turns still get the indicator.
  849. table.insert(variations, {lensNameBase.."_Origin",startHexId} );
  850. local nTurnCount :number = turnsList[table.count( turnsList )];
  851. if not bIsEnemyAtEnd or nTurnCount > 1 then
  852. table.insert(variations, {lensNameBase.."_Destination",endHexId} );
  853. end
  854.  
  855. -- Since turnsList are matched against plots, this should be the same # as above.
  856. if table.count(turnsList) > 1 then
  857.  
  858. -- Track any "holes" in the path.
  859. local pathHole:table = {};
  860. for i=1,table.count(pathPlots),1 do
  861. pathHole[i] = true;
  862. end
  863.  
  864. local lastTurn:number = 1;
  865. for i,value in pairs(turnsList) do
  866.  
  867. -- If a new turn entry exists, or it's the very last entry of the path... show turn INFO.
  868. if value > lastTurn then
  869. if i > 1 then
  870. table.insert(variations, {lensNameBase.."_Counter", pathPlots[i-1]} ); -- show counter pip
  871. UI.AddNumberToPath( lastTurn, pathPlots[i-1] );
  872. pathHole[i-1]=false;
  873. end
  874. lastTurn = value;
  875. end
  876. if i == table.count(turnsList) and i > 1 then
  877. table.insert(variations, {lensNameBase.."_Counter", pathPlots[i]} ); -- show counter pip
  878. UI.AddNumberToPath( lastTurn, pathPlots[i] );
  879. if lastTurn == 2 then
  880. if m_previousTurnsCount == 1 then
  881. UI.PlaySound("UI_Multi_Turn_Movement_Alert");
  882. end
  883. end
  884. m_previousTurnsCount = lastTurn;
  885. pathHole[i]=false;
  886. end
  887. end
  888.  
  889. -- Any obstacles? (e.g., rivers)
  890. local plotIndex:number = 1;
  891. for i,value in pairs(obstacles) do
  892. while( pathPlots[plotIndex] ~= value ) do plotIndex = plotIndex + 1; end -- Get ID to use for river's next plot
  893. table.insert(variations, {lensNameBase.."_Minus", value, pathPlots[plotIndex+1]} );
  894. end
  895.  
  896. -- Any variations not filled in earlier (holes), are filled in with Pips
  897. for i,isHole in pairs(pathHole) do
  898. if isHole then
  899. table.insert(variations, {lensNameBase.."_Pip", pathPlots[i]} ); -- non-counter pip
  900. end
  901. end
  902. end
  903.  
  904. else
  905. -- No path; is it a bad path or is the player have the cursor on the same hex as the unit?
  906. local startPlotId :number = Map.GetPlot(kUnit:GetX(),kUnit:GetY()):GetIndex();
  907. if startPlotId ~= endPlotId then
  908. if not UILens.IsLensActive("MovementBad") then
  909. UILens.SetActive("MovementBad");
  910. lensNameBase = "MovementBad";
  911. end
  912. table.insert(pathPlots, endPlotId);
  913. table.insert(variations, {"MovementBad_Destination", endPlotId} );
  914. end
  915. end
  916.  
  917. UILens.SetLayerHexesPath(LensLayers.MOVEMENT_PATH, eLocalPlayer, pathPlots, variations);
  918. end
  919. end
  920.  
  921. -- ===========================================================================
  922. -- ===========================================================================
  923. function DefaultKeyDownHandler( uiKey:number )
  924. local keyPanChanged :boolean = false;
  925. if uiKey == Keys.VK_ALT then
  926. if m_isALTDown == false then
  927. m_isALTDown = true;
  928. EndDragMap();
  929. ReadyForDragMap();
  930. end
  931. end
  932. if( uiKey == Keys.VK_UP or uiKey == Keys.W ) then
  933. keyPanChanged = true;
  934. m_isUPpressed = true;
  935. end
  936. if( uiKey == Keys.VK_RIGHT or uiKey == Keys.D ) then
  937. keyPanChanged = true;
  938. m_isRIGHTpressed = true;
  939. end
  940. if( uiKey == Keys.VK_DOWN or uiKey == Keys.S ) then
  941. keyPanChanged = true;
  942. m_isDOWNpressed = true;
  943. end
  944. if( uiKey == Keys.VK_LEFT or uiKey == Keys.A ) then
  945. keyPanChanged = true;
  946. m_isLEFTpressed = true;
  947. end
  948. if( keyPanChanged == true ) then
  949. ProcessPan(m_edgePanX,m_edgePanY);
  950. end
  951.  
  952. -- START: Yield Icon toggling
  953. if (uiKey == Keys.Y and showMapYield == false) then -- if toggle key is pressed and yield icon is off
  954. LuaEvents.MinimapPanel_ShowYieldIcons(); -- then turn it on
  955. showMapYield = true; -- and modify the global variable
  956. elseif (uiKey == Keys.Y and showMapYield == true) then -- if toggle key is pressed and yield icon is on
  957. LuaEvents.MinimapPanel_HideYieldIcons(); --then turn it off
  958. showMapYield = false; -- and modify the global variable
  959. end
  960. -- END: Yield Icon toggling
  961.  
  962. -- START: Resource Icon toggling
  963. if (uiKey == Keys.R) then -- if toggle key is pressed
  964. UserConfiguration.ShowMapResources( not UserConfiguration.ShowMapResources() ); -- toggle the resource icon
  965. end
  966. -- END: Resource Icon toggling
  967.  
  968. -- START: select next unit
  969. if (uiKey == Keys.N) then
  970. UI.SelectNextReadyUnit();
  971. end
  972. -- END: select next unit
  973.  
  974. -- START: toggle strategic map
  975. if (uiKey == Keys.VK_TAB) then
  976. LuaEvents.MinimapPanel_ToggleStrategicMap();
  977. end
  978. -- END: toggle strategic map
  979.  
  980. return false;
  981. end
  982.  
  983. -- ===========================================================================
  984. -- ===========================================================================
  985. function DefaultKeyUpHandler( uiKey:number )
  986.  
  987. local keyPanChanged :boolean = false;
  988. if uiKey == Keys.VK_ALT then
  989. if m_isALTDown == true then
  990. m_isALTDown = false;
  991. EndDragMap();
  992. ReadyForDragMap();
  993. end
  994. end
  995.  
  996. if( uiKey == Keys.VK_UP or uiKey == Keys.W ) then
  997. m_isUPpressed = false;
  998. keyPanChanged = true;
  999. end
  1000. if( uiKey == Keys.VK_RIGHT or uiKey == Keys.D ) then
  1001. m_isRIGHTpressed = false;
  1002. keyPanChanged = true;
  1003. end
  1004. if( uiKey == Keys.VK_DOWN or uiKey == Keys.S ) then
  1005. m_isDOWNpressed = false;
  1006. keyPanChanged = true;
  1007. end
  1008. if( uiKey == Keys.VK_LEFT or uiKey == Keys.A ) then
  1009. m_isLEFTpressed = false;
  1010. keyPanChanged = true;
  1011. end
  1012. if( keyPanChanged == true ) then
  1013. ProcessPan(m_edgePanX,m_edgePanY);
  1014. end
  1015.  
  1016. if( uiKey == Keys.VK_ADD or uiKey == Keys.VK_SUBTRACT ) then
  1017. local oldZoom = UI.GetMapZoom();
  1018. if( uiKey == Keys.VK_ADD ) then
  1019. UI.SetMapZoom( oldZoom - ZOOM_SPEED, 0.0, 0.0 );
  1020. elseif( uiKey == Keys.VK_SUBTRACT ) then
  1021. UI.SetMapZoom( oldZoom + ZOOM_SPEED, 0.0, 0.0 );
  1022. end
  1023. return true;
  1024. end
  1025.  
  1026. return false;
  1027. end
  1028.  
  1029.  
  1030. -- .,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,
  1031. --
  1032. -- INPUT STATE
  1033. --
  1034. -- .,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,
  1035.  
  1036.  
  1037. -- ===========================================================================
  1038. function OnDefaultKeyDown( pInputStruct:table )
  1039. local uiKey :number = pInputStruct:GetKey();
  1040. return DefaultKeyDownHandler( uiKey );
  1041. end
  1042.  
  1043. -- ===========================================================================
  1044. function OnDefaultKeyUp( pInputStruct:table )
  1045. local uiKey :number = pInputStruct:GetKey();
  1046. return DefaultKeyUpHandler( uiKey );
  1047. end
  1048.  
  1049. -- ===========================================================================
  1050. -- Placing a building, wonder, or district; ESC to leave
  1051. -- ===========================================================================
  1052. function OnPlacementKeyUp( pInputStruct:table )
  1053. local uiKey :number = pInputStruct:GetKey();
  1054. if uiKey == Keys.VK_ESCAPE then
  1055. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  1056. return true;
  1057. end
  1058. return DefaultKeyUpHandler( uiKey );
  1059. end
  1060.  
  1061.  
  1062. -- ===========================================================================
  1063. function TogglePause()
  1064. local localPlayerID = Network.GetLocalPlayerID();
  1065. local localPlayerConfig = PlayerConfigurations[localPlayerID];
  1066. local newPause = not localPlayerConfig:GetWantsPause();
  1067. localPlayerConfig:SetWantsPause(newPause);
  1068. Network.BroadcastPlayerInfo();
  1069. end
  1070.  
  1071. -- ===========================================================================
  1072. function OnDefaultChangeToSelectionMode( pInputStruct )
  1073. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  1074. end
  1075.  
  1076. -- ===========================================================================
  1077. function OnMouseDebugEnd( pInputStruct:table )
  1078. -- If a drag was occurring, end it; otherwise attempt selection of whatever
  1079. -- is in the plot the mouse is currently at.
  1080. if m_isMouseDragging then
  1081. print("Stopping drag");
  1082. m_isMouseDragging = false;
  1083.  
  1084. else
  1085. print("Debug placing!!!");
  1086. local plotID:number = UI.GetCursorPlotID();
  1087. if (Map.IsPlot(plotID)) then
  1088. local edge = UI.GetCursorNearestPlotEdge();
  1089. DebugPlacement( plotID, edge );
  1090. end
  1091. end
  1092. EndDragMap(); -- Reset any dragging
  1093. m_isMouseDownInWorld = false;
  1094. return true;
  1095.  
  1096. end
  1097.  
  1098. -- ===========================================================================
  1099. function OnDebugCancelPlacement( pInputStruct )
  1100. local plotID:number = UI.GetCursorPlotID();
  1101. if (Map.IsPlot(plotID)) then
  1102. local edge = UI.GetCursorNearestPlotEdge();
  1103. local plot:table = Map.GetPlotByIndex(plotID);
  1104. local normalizedX, normalizedY = UIManager:GetNormalizedMousePos();
  1105. worldX, worldY, worldZ = UI.GetWorldFromNormalizedScreenPos(normalizedX, normalizedY);
  1106.  
  1107. -- Communicate this to the TunerMapPanel handler
  1108. LuaEvents.TunerMapRButtonDown(plot:GetX(), plot:GetY(), worldX, worldY, worldZ, edge);
  1109. end
  1110. return true;
  1111. end
  1112.  
  1113. -- ===========================================================================
  1114. function OnInterfaceModeChange_Debug( eNewMode:number )
  1115. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  1116. end
  1117.  
  1118.  
  1119. -- ===========================================================================
  1120. function OnInterfaceModeEnter_CityManagement( eNewMode:number )
  1121. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  1122. UILens.SetActive("CityManagement");
  1123. end
  1124.  
  1125. -- ===========================================================================
  1126. function OnInterfaceModeLeave_CityManagement( eNewMode:number )
  1127. UIManager:SetUICursor(CursorTypes.NORMAL);
  1128. UILens.SetActive("Default");
  1129. end
  1130.  
  1131.  
  1132. -- ===========================================================================
  1133. function OnMouseSelectionEnd( pInputStruct:table )
  1134. -- If a drag was occurring, end it; otherwise attempt selection of whatever
  1135. -- is in the plot the mouse is currently at.
  1136. if m_isMouseDragging then
  1137. m_isMouseDragging = false;
  1138. else
  1139. -- If something (such as the tutorial) hasn't disabled mouse deslecting.
  1140. if IsSelectionAllowedAt( UI.GetCursorPlotID() ) then
  1141. local plotX:number, plotY:number = UI.GetCursorPlotCoord();
  1142. SelectInPlot( plotX, plotY );
  1143. end
  1144. end
  1145. EndDragMap(); -- Reset any dragging
  1146. m_isMouseDownInWorld = false;
  1147. return true;
  1148. end
  1149.  
  1150. -- ===========================================================================
  1151. function OnMouseSelectionMove( pInputStruct:table )
  1152.  
  1153. if not m_isMouseDownInWorld then
  1154. return false;
  1155. end
  1156.  
  1157. -- Check for that player who holds the mouse button dwon, drags and releases it over a UI element.
  1158. if m_isMouseDragging then
  1159. UpdateDragMap();
  1160. return true;
  1161. else
  1162. if m_isMouseButtonLDown then
  1163. -- A mouse button is down but isn't currently marked for "dragging",
  1164. -- do some maths to see if this is actually a drag state.
  1165. if not m_isMouseDragging then
  1166. m_isMouseDragging = IsDragThreshholdMet();
  1167. end
  1168. end
  1169.  
  1170. local playerID :number = Game.GetLocalPlayer();
  1171. if playerID == -1 or (not Players[playerID]:IsTurnActive()) then
  1172. return false;
  1173. end
  1174.  
  1175. if m_isMouseButtonRDown then
  1176. RealizeMovementPath();
  1177. end
  1178. end
  1179. return false;
  1180. end
  1181.  
  1182. -- ===========================================================================
  1183. function OnMouseSelectionUnitMoveStart( pInputStruct:table )
  1184. m_isMouseDownInWorld = true;
  1185. return true;
  1186. end
  1187.  
  1188. -- ===========================================================================
  1189. function OnMouseSelectionUnitMoveEnd( pInputStruct:table )
  1190. local pSelectedUnit:table = UI.GetHeadSelectedUnit();
  1191. if pSelectedUnit ~= nil then
  1192. local playerID :number = Game.GetLocalPlayer();
  1193. if playerID ~= -1 and Players[playerID]:IsTurnActive() then
  1194. if IsUnitAllowedToMoveToCursorPlot( pSelectedUnit ) then
  1195. MoveUnitToCursorPlot( pSelectedUnit );
  1196. else
  1197. UnitMovementCancel();
  1198. end
  1199. end
  1200. else
  1201. UnitMovementCancel();
  1202. end
  1203. m_isMouseDownInWorld = false;
  1204. return true;
  1205. end
  1206.  
  1207. -- ===========================================================================
  1208. function OnMouseSelectionSnapToPlot( pInputStruct:table )
  1209. local plotId :number= UI.GetCursorPlotID();
  1210. SnapToPlot( plotId );
  1211. end
  1212.  
  1213. -- ===========================================================================
  1214. function OnMouseMove( pInputStruct:table )
  1215.  
  1216. if not m_isMouseDownInWorld then
  1217. return false;
  1218. end
  1219.  
  1220. -- Check for that player who holds the mouse button dwon, drags and releases it over a UI element.
  1221. if m_isMouseDragging then
  1222. UpdateDragMap();
  1223. return true;
  1224. else
  1225. if m_isMouseButtonLDown then
  1226. -- A mouse button is down but isn't currently marked for "dragging".
  1227. if not m_isMouseDragging then
  1228. m_isMouseDragging = IsDragThreshholdMet();
  1229. end
  1230. end
  1231. end
  1232. return false;
  1233. end
  1234.  
  1235.  
  1236. -- ===========================================================================
  1237. -- Common way for mouse to function with a press start.
  1238. -- ===========================================================================
  1239. function OnMouseStart( pInputStruct:table )
  1240. ReadyForDragMap();
  1241. m_isMouseDownInWorld = true;
  1242. return true;
  1243. end
  1244.  
  1245. -- ===========================================================================
  1246. function OnMouseEnd( pInputStruct:table )
  1247. -- If a drag was occurring, end it; otherwise attempt selection of whatever
  1248. -- is in the plot the mouse is currently at.
  1249. if m_isMouseDragging then
  1250. m_isMouseDragging = false;
  1251. end
  1252. EndDragMap(); -- Reset any dragging
  1253. m_isMouseDownInWorld = false;
  1254. return true;
  1255. end
  1256.  
  1257. -- ===========================================================================
  1258. -- Zoom
  1259. -- ===========================================================================
  1260. function OnMouseWheelZoom( pInputStruct:table )
  1261. local wheelValue = pInputStruct:GetWheel() * (-( (1.0/12000.0) * MOUSE_SCALAR)); -- Wheel values come in as multiples of 120, make it so that one 'click' is %1, modified by a speed scalar.
  1262. local normalizedX :number, normalizedY:number = UIManager:GetNormalizedMousePos();
  1263. local oldZoom = UI.GetMapZoom();
  1264. local newZoom = oldZoom + wheelValue;
  1265.  
  1266. if( wheelValue < 0.0 ) then
  1267. --UI.SetMapZoom( newZoom, normalizedX, normalizedY );
  1268. UI.SetMapZoom( newZoom, 0.0, 0.0 );
  1269. else
  1270. --UI.SetMapZoom( newZoom, normalizedX, normalizedY );
  1271. UI.SetMapZoom( newZoom, 0.0, 0.0 );
  1272. end
  1273.  
  1274. return true;
  1275. end
  1276.  
  1277. -- ===========================================================================
  1278. -- Either Mouse Double-Click or Touch Double-Tap
  1279. -- ===========================================================================
  1280. function OnSelectionDoubleTap( pInputStruct:table )
  1281. -- Determine if mouse or touch...
  1282. if m_isMouseDownInWorld then
  1283. -- Ignore if mouse.
  1284. else
  1285. local pSelectedUnit:table = UI.GetHeadSelectedUnit();
  1286. if pSelectedUnit ~= nil then
  1287. if IsUnitAllowedToMoveToCursorPlot( pSelectedUnit ) then
  1288. MoveUnitToCursorPlot( pSelectedUnit );
  1289. end
  1290. m_isDoubleTapping = true;
  1291. return true;
  1292. end
  1293. end
  1294. return false;
  1295. end
  1296.  
  1297. -- ===========================================================================
  1298. function OnMouseMakeTradeRouteEnd( pInputStruct:table )
  1299. -- If a drag was occurring, end it; otherwise raise event.
  1300. if m_isMouseDragging then
  1301. m_isMouseDragging = false;
  1302. else
  1303. local plotId:number = UI.GetCursorPlotID();
  1304. if (Map.IsPlot(plotId)) then
  1305. LuaEvents.WorldInput_MakeTradeRouteDestination( plotId );
  1306. end
  1307. end
  1308. EndDragMap();
  1309. m_isMouseDownInWorld = true;
  1310. return true;
  1311. end
  1312.  
  1313. -- ===========================================================================
  1314. function OnMouseMakeTradeRouteSnapToPlot( pInputStruct:table )
  1315. local plotId :number= UI.GetCursorPlotID();
  1316. SnapToPlot( plotId );
  1317. end
  1318.  
  1319. -- ===========================================================================
  1320. function OnMouseTeleportToCityEnd( pInputStruct:table )
  1321. -- If a drag was occurring, end it; otherwise raise event.
  1322. if m_isMouseDragging then
  1323. m_isMouseDragging = false;
  1324. else
  1325. TeleportToCity();
  1326. end
  1327. EndDragMap();
  1328. m_isMouseDownInWorld = true;
  1329. return true;
  1330. end
  1331.  
  1332. -- ===========================================================================
  1333. function OnMouseTeleportToCitySnapToPlot( pInputStruct:table )
  1334. local plotId :number= UI.GetCursorPlotID();
  1335. SnapToPlot( plotId );
  1336. end
  1337.  
  1338. -- ===========================================================================
  1339. function OnMouseBuildingPlacementEnd( pInputStruct:table )
  1340. -- If a drag was occurring, end it; otherwise raise event.
  1341. if m_isMouseDragging then
  1342. m_isMouseDragging = false;
  1343. else
  1344. if IsSelectionAllowedAt( UI.GetCursorPlotID() ) then
  1345. ConfirmPlaceWonder(pInputStruct); -- StrategicView_MapPlacement.lua
  1346. end
  1347. end
  1348. EndDragMap();
  1349. m_isMouseDownInWorld = false;
  1350. return true;
  1351. end
  1352.  
  1353. -- ===========================================================================
  1354. function OnMouseBuildingPlacementCancel( pInputStruct:table )
  1355. if IsCancelAllowed() then
  1356. ExitPlacementMode( true );
  1357. end
  1358. end
  1359.  
  1360. -- ===========================================================================
  1361. function OnMouseBuildingPlacementMove( pInputStruct:table)
  1362. OnMouseMove( pInputStruct );
  1363. RealizeCurrentPlaceDistrictOrWonderPlot();
  1364. end
  1365.  
  1366. -- ===========================================================================
  1367. function OnMouseDistrictPlacementEnd( pInputStruct:table )
  1368. -- If a drag was occurring, end it; otherwise raise event.
  1369. if m_isMouseDragging then
  1370. m_isMouseDragging = false;
  1371. else
  1372. if IsSelectionAllowedAt( UI.GetCursorPlotID() ) then
  1373. ConfirmPlaceDistrict(pInputStruct);
  1374. end
  1375. end
  1376. EndDragMap();
  1377. m_isMouseDownInWorld = false;
  1378. return true;
  1379. end
  1380.  
  1381. -- ===========================================================================
  1382. function OnMouseDistrictPlacementCancel( pInputStruct:table )
  1383. if IsCancelAllowed() then
  1384. ExitPlacementMode( true );
  1385. end
  1386. end
  1387.  
  1388. -- ===========================================================================
  1389. function OnMouseDistrictPlacementMove( pInputStruct:table)
  1390. OnMouseMove( pInputStruct );
  1391. RealizeCurrentPlaceDistrictOrWonderPlot();
  1392. end
  1393.  
  1394. -- ===========================================================================
  1395. function OnMouseUnitRangeAttack( pInputStruct:table )
  1396. if ClearRangeAttackDragging() then
  1397. return true;
  1398. end
  1399.  
  1400. local plotID:number = UI.GetCursorPlotID();
  1401. if (Map.IsPlot(plotID)) then
  1402. UnitRangeAttack( plotID );
  1403. end
  1404. return true;
  1405. end
  1406.  
  1407. -- ===========================================================================
  1408. function OnMouseMoveRangeAttack( pInputStruct:table )
  1409. OnMouseMove( pInputStruct );
  1410.  
  1411. local plotID:number = UI.GetCursorPlotID();
  1412.  
  1413. if (Map.IsPlot(plotID)) then
  1414. if m_focusedTargetPlot ~= plotID then
  1415. if m_focusedTargetPlot ~= -1 then
  1416. UILens.UnFocusHex(LensLayers.ATTACK_RANGE, m_focusedTargetPlot);
  1417. m_focusedTargetPlot = -1;
  1418. end
  1419.  
  1420. if (m_targetPlots ~= nil) then
  1421. local bPlotIsTarget:boolean = false;
  1422. for i=1,#m_targetPlots do
  1423. if m_targetPlots[i] == plotID then
  1424. bPlotIsTarget = true;
  1425. break;
  1426. end
  1427. end
  1428.  
  1429. if bPlotIsTarget then
  1430. m_focusedTargetPlot = plotID;
  1431. UILens.FocusHex(LensLayers.ATTACK_RANGE, plotID);
  1432. end
  1433. end
  1434. end
  1435. end
  1436. return true;
  1437. end
  1438.  
  1439. -- ===========================================================================
  1440. function OnMouseMoveToStart( pInputStruct:table )
  1441. ReadyForDragMap();
  1442. m_isMouseDownInWorld = true;
  1443. return true;
  1444. end
  1445.  
  1446. -- ===========================================================================
  1447. function OnMouseMoveToEnd( pInputStruct:table )
  1448. -- Stop a dragging or kick off a move selection.
  1449. if m_isMouseDragging then
  1450. m_isMouseDragging = false;
  1451. else
  1452. local pSelectedUnit:table = UI.GetHeadSelectedUnit();
  1453. if pSelectedUnit ~= nil and IsUnitAllowedToMoveToCursorPlot( pSelectedUnit ) then
  1454. MoveUnitToCursorPlot( pSelectedUnit );
  1455. else
  1456. UnitMovementCancel();
  1457. end
  1458. UI.SetInterfaceMode( InterfaceModeTypes.SELECTION );
  1459. end
  1460. EndDragMap();
  1461. m_isMouseDownInWorld = false;
  1462. return true;
  1463. end
  1464.  
  1465. -- ===========================================================================
  1466. function OnMouseMoveToUpdate( pInputStruct:table )
  1467.  
  1468. if m_isMouseDownInWorld then
  1469. -- Check for that player who holds the mouse button dwon, drags and releases it over a UI element.
  1470. if m_isMouseDragging then
  1471. UpdateDragMap();
  1472. else
  1473. if m_isMouseButtonLDown then
  1474. -- A mouse button is down but isn't currently marked for "dragging",
  1475. -- do some maths to see if this is actually a drag state.
  1476. if not m_isMouseDragging then
  1477. m_isMouseDragging = IsDragThreshholdMet();
  1478. end
  1479. end
  1480. end
  1481. end
  1482. RealizeMovementPath();
  1483. return true;
  1484. end
  1485.  
  1486. -- ===========================================================================
  1487. function OnMouseMoveToCancel( pInputStruct:table )
  1488. UnitMovementCancel();
  1489. UI.SetInterfaceMode( InterfaceModeTypes.SELECTION );
  1490. return true;
  1491. end
  1492.  
  1493.  
  1494. -- ===========================================================================
  1495. -- Start touch, until release or move, do not take action.
  1496. -- ===========================================================================
  1497. function OnTouchSelectionStart( pInputStruct:table )
  1498.  
  1499. if m_touchCount > m_touchTotalNum then
  1500. m_touchTotalNum = m_touchCount;
  1501. end
  1502.  
  1503. -- If the first touch then obtain the plot the touch started in.
  1504. if m_touchTotalNum == 1 then
  1505. local normalizedX, normalizedY = UIManager:GetNormalizedMousePos();
  1506. m_touchStartPlotX, m_touchStartPlotY = UI.GetPlotCoordFromNormalizedScreenPos(normalizedX, normalizedY);
  1507.  
  1508. -- Potentially draw path based on if a unit is selected.
  1509. local pSelectedUnit:table = UI.GetHeadSelectedUnit();
  1510. if pSelectedUnit ~= nil and m_touchStartPlotX == pSelectedUnit:GetX() and m_touchStartPlotY == pSelectedUnit:GetY() then
  1511. m_isTouchPathing = true;
  1512. RealizeMovementPath();
  1513. else
  1514. -- No unit selected to draw a path, the player is either about to
  1515. -- start a drag or is just now selecting a unit.
  1516. ReadyForDragMap();
  1517. end
  1518. end
  1519. return true;
  1520. end
  1521.  
  1522.  
  1523. -- ===========================================================================
  1524. function OnTouchSelectionUpdate( pInputStruct:table )
  1525.  
  1526. -- Determine maximum # of touches that have occurred.
  1527. if m_touchCount > m_touchTotalNum then
  1528. m_touchTotalNum = m_touchCount;
  1529. end
  1530.  
  1531. RealizeTouchGestureZoom();
  1532.  
  1533. -- If more than one touch ever occured; take no more actions.
  1534. if m_touchTotalNum > 1 then
  1535. return true;
  1536. end
  1537.  
  1538. -- Drawing a path or dragging?
  1539. if m_isTouchPathing then
  1540. RealizeMovementPath();
  1541. else
  1542. if m_isTouchDragging then
  1543. UpdateDragMap();
  1544. else
  1545. m_isTouchDragging = IsDragThreshholdMet();
  1546. end
  1547. end
  1548. return true;
  1549. end
  1550.  
  1551. -- ===========================================================================
  1552. function OnTouchSelectionEnd( pInputStruct:table )
  1553.  
  1554. -- If last touch in a sequence or double tapping.
  1555. if m_touchCount > 0 then
  1556. return true;
  1557. end
  1558.  
  1559. if m_isDoubleTapping then
  1560. -- If a double tap just happened, clear out.
  1561. m_isDoubleTapping = false;
  1562. m_isTouchPathing = false;
  1563. m_isTouchDragging = false;
  1564. else
  1565. -- Moving a unit?
  1566. if m_isTouchPathing then
  1567. m_isTouchPathing = false;
  1568. local pSelectedUnit:table = UI.GetHeadSelectedUnit();
  1569. if pSelectedUnit ~= nil then
  1570. if IsUnitAllowedToMoveToCursorPlot( pSelectedUnit ) then
  1571. MoveUnitToCursorPlot( pSelectedUnit );
  1572. else
  1573. UnitMovementCancel();
  1574. end
  1575. else
  1576. UnitMovementCancel();
  1577. end
  1578. else
  1579. -- Selection or Dragging
  1580. if m_isTouchDragging then
  1581. m_isTouchDragging = false;
  1582. else
  1583. local plotX:number, plotY:number = UI.GetCursorPlotCoord();
  1584. if plotX == m_touchStartPlotX and plotY == m_touchStartPlotY then
  1585. SelectInPlot( plotX, plotY );
  1586. end
  1587. end
  1588. end
  1589. end
  1590.  
  1591. EndDragMap();
  1592. m_touchTotalNum = 0;
  1593. m_isTouchZooming = false;
  1594. m_touchStartPlotX = -1;
  1595. m_touchStartPlotY = -1;
  1596. return true;
  1597. end
  1598.  
  1599. -- ===========================================================================
  1600. -- Common start for touch
  1601. -- ===========================================================================
  1602. function OnTouchStart( pInputStruct:table )
  1603. if m_touchCount > m_touchTotalNum then
  1604. m_touchTotalNum = m_touchCount;
  1605. end
  1606.  
  1607. -- If the first touch then obtain the plot the touch started in.
  1608. if m_touchTotalNum == 1 then
  1609. local normalizedX, normalizedY = UIManager:GetNormalizedMousePos();
  1610. m_touchStartPlotX, m_touchStartPlotY = UI.GetPlotCoordFromNormalizedScreenPos(normalizedX, normalizedY);
  1611. ReadyForDragMap();
  1612. end
  1613. return true;
  1614. end
  1615.  
  1616. -- ===========================================================================
  1617. -- Common update for touch
  1618. -- ===========================================================================
  1619. function OnTouchUpdate( pInputStruct:table )
  1620. -- Determine maximum # of touches that have occurred.
  1621. if m_touchCount > m_touchTotalNum then
  1622. m_touchTotalNum = m_touchCount;
  1623. end
  1624.  
  1625. RealizeTouchGestureZoom();
  1626.  
  1627. -- If more than one touch ever occured; take no more actions.
  1628. if m_touchTotalNum > 1 then
  1629. return true;
  1630. end
  1631.  
  1632. if m_isTouchDragging then
  1633. UpdateDragMap();
  1634. else
  1635. m_isTouchDragging = IsDragThreshholdMet();
  1636. end
  1637. return true;
  1638. end
  1639.  
  1640.  
  1641. -- ===========================================================================
  1642. function OnTouchTradeRouteEnd( pInputStruct:table )
  1643.  
  1644. -- If last touch in a sequence or double tapping.
  1645. if m_touchCount > 0 then
  1646. return true;
  1647. end
  1648.  
  1649. -- Selection or Dragging
  1650. if m_isTouchDragging then
  1651. m_isTouchDragging = false;
  1652. else
  1653. local plotId:number = UI.GetCursorPlotID();
  1654. if (Map.IsPlot(plotId)) then
  1655. LuaEvents.WorldInput_MakeTradeRouteDestination( plotId );
  1656. end
  1657. end
  1658.  
  1659. EndDragMap();
  1660. m_touchTotalNum = 0;
  1661. m_isTouchZooming = false;
  1662. m_touchStartPlotX = -1;
  1663. m_touchStartPlotY = -1;
  1664. return true;
  1665. end
  1666.  
  1667. -- ===========================================================================
  1668. function OnTouchTeleportToCityEnd( pInputStruct:table )
  1669.  
  1670. -- If last touch in a sequence or double tapping.
  1671. if m_touchCount > 0 then
  1672. return true;
  1673. end
  1674.  
  1675. -- Selection or Dragging
  1676. if m_isTouchDragging then
  1677. m_isTouchDragging = false;
  1678. else
  1679. TeleportToCity();
  1680. end
  1681.  
  1682. EndDragMap();
  1683. m_touchTotalNum = 0;
  1684. m_isTouchZooming = false;
  1685. m_touchStartPlotX = -1;
  1686. m_touchStartPlotY = -1;
  1687. return true;
  1688. end
  1689.  
  1690. -- ===========================================================================
  1691. function OnTouchDistrictPlacementEnd( pInputStruct:table )
  1692. ConfirmPlaceDistrict(pInputStruct);
  1693. end
  1694.  
  1695. -- ===========================================================================
  1696. function OnTouchBuildingPlacementEnd( pInputStruct:table )
  1697. ConfirmPlaceWonder(pInputStruct);
  1698. end
  1699.  
  1700. -- ===========================================================================
  1701. function OnTouchMoveToStart( pInputStruct:table )
  1702. return true;
  1703. end
  1704.  
  1705. -- ===========================================================================
  1706. function OnTouchMoveToUpdate( pInputStruct:table )
  1707. -- Determine maximum # of touches that have occurred.
  1708. if m_touchCount > m_touchTotalNum then
  1709. m_touchTotalNum = m_touchCount;
  1710. end
  1711.  
  1712. if m_touchTotalNum == 1 then
  1713. RealizeMovementPath();
  1714. else
  1715. UnitMovementCancel();
  1716. end
  1717. return true;
  1718. end
  1719.  
  1720. -- ===========================================================================
  1721. function OnTouchMoveToEnd( pInputStruct:table )
  1722. -- If last touch in a sequence or double tapping.
  1723. if m_touchCount > 0 then
  1724. return true;
  1725. end
  1726.  
  1727. if m_touchTotalNum == 1 then
  1728. local pSelectedUnit:table = UI.GetHeadSelectedUnit();
  1729. if IsUnitAllowedToMoveToCursorPlot( pSelectedUnit ) then
  1730. MoveUnitToCursorPlot( pSelectedUnit );
  1731. else
  1732. UnitMovementCancel();
  1733. end
  1734. else
  1735. UnitMovementCancel();
  1736. end
  1737.  
  1738. m_touchTotalNum = 0;
  1739. m_isTouchZooming = false;
  1740. m_touchStartPlotX = -1;
  1741. m_touchStartPlotY = -1;
  1742. UI.SetInterfaceMode( InterfaceModeTypes.SELECTION );
  1743. return true;
  1744. end
  1745.  
  1746. -- ===========================================================================
  1747. function OnTouchUnitRangeAttack( pInputStruct:table )
  1748. local plotID:number = UI.GetCursorPlotID();
  1749. if (Map.IsPlot(plotID)) then
  1750. UnitRangeAttack( plotID );
  1751. end
  1752. return true;
  1753. end
  1754.  
  1755.  
  1756. -------------------------------------------------------------------------------
  1757. function OnInterfaceModeChange_UnitRangeAttack(eNewMode)
  1758. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  1759. local pSelectedUnit = UI.GetHeadSelectedUnit();
  1760. if (pSelectedUnit ~= nil) then
  1761.  
  1762. if m_focusedTargetPlot ~= -1 then
  1763. UILens.UnFocusHex(LensLayers.ATTACK_RANGE, m_focusedTargetPlot);
  1764. m_focusedTargetPlot = -1;
  1765. end
  1766.  
  1767. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, UnitOperationTypes.RANGE_ATTACK );
  1768. local allPlots = tResults[UnitOperationResults.PLOTS];
  1769. if (allPlots ~= nil) then
  1770. m_targetPlots = {};
  1771. for i,modifier in ipairs(tResults[UnitOperationResults.MODIFIERS]) do
  1772. if(modifier == UnitOperationResults.MODIFIER_IS_TARGET) then
  1773. table.insert(m_targetPlots, allPlots[i]);
  1774. end
  1775. end
  1776.  
  1777. -- Highlight the plots available to attack
  1778. if (table.count(m_targetPlots) ~= 0) then
  1779. -- Variation will hold specific targets in range
  1780. local kVariations:table = {};
  1781. for _,plotId in ipairs(m_targetPlots) do
  1782. -- Variant needed to place the attack arc, but we don't want to double-draw the crosshair on the hex.
  1783. table.insert(kVariations, {"EmptyVariant", allPlots[1], plotId} );
  1784. end
  1785. local eLocalPlayer:number = Game.GetLocalPlayer();
  1786.  
  1787. UILens.SetLayerHexesArea(LensLayers.ATTACK_RANGE, eLocalPlayer, allPlots, kVariations);
  1788. end
  1789. end
  1790. end
  1791. end
  1792.  
  1793. -------------------------------------------------------------------------------
  1794. function OnInterfaceModeLeave_UnitRangeAttack(eNewMode)
  1795. UILens.ClearLayerHexes( LensLayers.ATTACK_RANGE );
  1796. end
  1797.  
  1798. -- ===========================================================================
  1799. -- Code related to the Unit Air Attack interface mode
  1800. -- ===========================================================================
  1801. function UnitAirAttack( pInputStruct )
  1802. local plotID = UI.GetCursorPlotID();
  1803. if (Map.IsPlot(plotID)) then
  1804. local plot = Map.GetPlotByIndex(plotID);
  1805.  
  1806. local tParameters = {};
  1807. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  1808. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  1809.  
  1810. local pSelectedUnit = UI.GetHeadSelectedUnit();
  1811. -- Assuming that the operation is AIR_ATTACK. Store this in the InterfaceMode somehow?
  1812. if (UnitManager.CanStartOperation( pSelectedUnit, UnitOperationTypes.AIR_ATTACK, nil, tParameters)) then
  1813. UnitManager.RequestOperation( pSelectedUnit, UnitOperationTypes.AIR_ATTACK, tParameters);
  1814. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  1815. end
  1816. end
  1817. return true;
  1818. end
  1819. -------------------------------------------------------------------------------
  1820. function OnInterfaceModeChange_Air_Attack(eNewMode)
  1821. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  1822. local pSelectedUnit = UI.GetHeadSelectedUnit();
  1823. if (pSelectedUnit ~= nil) then
  1824.  
  1825. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, UnitOperationTypes.AIR_ATTACK );
  1826. local allPlots = tResults[UnitOperationResults.PLOTS];
  1827. if (allPlots ~= nil) then
  1828. m_targetPlots = {};
  1829. for i,modifier in ipairs(tResults[UnitOperationResults.MODIFIERS]) do
  1830. if(modifier == UnitOperationResults.MODIFIER_IS_TARGET) then
  1831. table.insert(m_targetPlots, allPlots[i]);
  1832. end
  1833. end
  1834.  
  1835. -- Highlight the plots available to attack
  1836. if (table.count(m_targetPlots) ~= 0) then
  1837. local eLocalPlayer:number = Game.GetLocalPlayer();
  1838. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_ATTACK);
  1839. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_ATTACK, eLocalPlayer, m_targetPlots);
  1840. end
  1841. end
  1842. end
  1843. end
  1844.  
  1845. ---------------------------------------------------------------------------------
  1846. function OnInterfaceModeLeave_Air_Attack( eNewMode:number )
  1847. UIManager:SetUICursor(CursorTypes.NORMAL);
  1848. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_ATTACK );
  1849. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_ATTACK );
  1850. end
  1851.  
  1852. -- ===========================================================================
  1853. -- Code related to the WMD Strike interface mode
  1854. -- ===========================================================================
  1855. function OnWMDStrikeEnd( pInputStruct )
  1856. if ClearRangeAttackDragging() then
  1857. return true;
  1858. end
  1859.  
  1860. local pSelectedUnit = UI.GetHeadSelectedUnit();
  1861. if (pSelectedUnit == nil) then
  1862. return false;
  1863. end
  1864.  
  1865. local plotID = UI.GetCursorPlotID();
  1866. if (Map.IsPlot(plotID)) then
  1867. local plot = Map.GetPlotByIndex(plotID);
  1868. local eWMD = UI.GetInterfaceModeParameter(UnitOperationTypes.PARAM_WMD_TYPE);
  1869. local strikeFn = function() WMDStrike(plot, pSelectedUnit, eWMD); end;
  1870. local bWillStartWar = CombatManager.IsAttackChangeWarState( pSelectedUnit:GetComponentID(), plot:GetX(), plot:GetY(), eWMD );
  1871. if (bWillStartWar) then
  1872. local eDefendingPlayer = CombatManager.GetBestDefender( pSelectedUnit:GetComponentID(), plot:GetX(), plot:GetY() );
  1873. if (eDefendingPlayer == nil) then
  1874. eDefendingPlayer = plot:GetOwner();
  1875. end
  1876. -- Create the action specific parameters
  1877. if (eDefendingPlayer ~= nil and eDefendingPlayer ~= -1) then
  1878. LuaEvents.WorldInput_ConfirmWarDialog(pSelectedUnit:GetOwner(), eDefendingPlayer, WarTypes.SURPRISE_WAR, strikeFn);
  1879. end
  1880. else
  1881. local pPopupDialog :table = PopupDialog:new("ConfirmWMDStrike");
  1882. pPopupDialog:AddText(Locale.Lookup("LOC_LAUNCH_WMD_DIALOG_ARE_YOU_SURE"));
  1883. pPopupDialog:AddButton(Locale.Lookup("LOC_LAUNCH_WMD_DIALOG_CANCEL"), nil);
  1884. pPopupDialog:AddButton(Locale.Lookup("LOC_LAUNCH_WMD_DIALOG_LAUNCH"), strikeFn);
  1885. pPopupDialog:Open();
  1886. end
  1887. end
  1888. return true;
  1889. end
  1890. -------------------------------------------------------------------------------
  1891. function WMDStrike( plot, unit, eWMD )
  1892. local tParameters = {};
  1893. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  1894. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  1895. tParameters[UnitOperationTypes.PARAM_WMD_TYPE] = eWMD;
  1896. if (UnitManager.CanStartOperation( unit, UnitOperationTypes.WMD_STRIKE, nil, tParameters)) then
  1897. UnitManager.RequestOperation( unit, UnitOperationTypes.WMD_STRIKE, tParameters);
  1898. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  1899. end
  1900. end
  1901. -------------------------------------------------------------------------------
  1902. function OnInterfaceModeChange_WMD_Strike(eNewMode)
  1903. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  1904. local pSelectedUnit = UI.GetHeadSelectedUnit();
  1905. if (pSelectedUnit ~= nil) then
  1906. if m_focusedTargetPlot ~= -1 then
  1907. UILens.UnFocusHex(LensLayers.ATTACK_RANGE, m_focusedTargetPlot);
  1908. m_focusedTargetPlot = -1;
  1909. end
  1910. local sourcePlot : number = Map.GetPlot(pSelectedUnit:GetX(),pSelectedUnit:GetY()):GetIndex();
  1911. local tParameters = {};
  1912. local eWMD = UI.GetInterfaceModeParameter(UnitOperationTypes.PARAM_WMD_TYPE);
  1913. tParameters[UnitOperationTypes.PARAM_WMD_TYPE] = eWMD;
  1914.  
  1915. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, UnitOperationTypes.WMD_STRIKE, tParameters );
  1916. local allPlots = tResults[UnitOperationResults.PLOTS];
  1917. if (allPlots ~= nil) then
  1918. m_targetPlots = {}; -- Used shared list
  1919. for i,modifier in ipairs(tResults[UnitOperationResults.PLOTS]) do
  1920. table.insert(m_targetPlots, allPlots[i]);
  1921. end
  1922.  
  1923. -- Highlight the plots available to attack
  1924. if (table.count(m_targetPlots) ~= 0) then
  1925. -- Variation will hold specific targets in range
  1926. local kVariations:table = {};
  1927. for _,plotId in ipairs(m_targetPlots) do
  1928. table.insert(kVariations, {"AttackRange_Target", sourcePlot, plotId} );
  1929. end
  1930. local eLocalPlayer:number = Game.GetLocalPlayer();
  1931. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_ATTACK);
  1932. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_ATTACK, eLocalPlayer, m_targetPlots, kVariations);
  1933. end
  1934. end
  1935. end
  1936. end
  1937.  
  1938. -------------------------------------------------------------------------------
  1939. function OnInterfaceModeLeave_WMD_Strike( eNewMode:number )
  1940. UIManager:SetUICursor(CursorTypes.NORMAL);
  1941. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_ATTACK );
  1942. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_ATTACK );
  1943. end
  1944.  
  1945. -- ===========================================================================
  1946. -- Code related to the ICBM Strike interface mode
  1947. -- ===========================================================================
  1948. function OnICBMStrikeEnd( pInputStruct )
  1949. if ClearRangeAttackDragging() then
  1950. return true;
  1951. end
  1952.  
  1953. local pSelectedCity = UI.GetHeadSelectedCity();
  1954. if (pSelectedCity == nil) then
  1955. return false;
  1956. end
  1957.  
  1958. local targetPlotID = UI.GetCursorPlotID();
  1959. if (Map.IsPlot(targetPlotID)) then
  1960. local targetPlot = Map.GetPlotByIndex(targetPlotID);
  1961. local eWMD = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_WMD_TYPE);
  1962. local sourcePlotX = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_X0);
  1963. local sourcePlotY = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_Y0);
  1964. local strikeFn = function() ICBMStrike(pSelectedCity, sourcePlotX, sourcePlotY, targetPlot, eWMD); end;
  1965. --PlayersVisibility[ pSelectedCity:GetOwner() ]:IsVisible(targetPlot:GetX(), targetPlot:GetY())
  1966. local bWillStartWar = CombatManager.IsAttackChangeWarState( pSelectedCity:GetComponentID(), targetPlot:GetX(), targetPlot:GetY(), eWMD );
  1967. if (bWillStartWar) then
  1968. local eDefendingPlayer = CombatManager.GetBestDefender( pSelectedCity:GetComponentID(), targetPlot:GetX(), targetPlot:GetY() );
  1969. if (eDefendingPlayer == nil) then
  1970. eDefendingPlayer = targetPlot:GetOwner();
  1971. end
  1972. -- Create the action specific parameters
  1973. if (eDefendingPlayer ~= nil and eDefendingPlayer ~= -1) then
  1974. LuaEvents.WorldInput_ConfirmWarDialog(pSelectedCity:GetOwner(), eDefendingPlayer, WarTypes.SURPRISE_WAR, strikeFn );
  1975. end
  1976. else
  1977. local pPopupDialog :table = PopupDialog:new("ConfirmICBMStrike");
  1978. pPopupDialog:AddText(Locale.Lookup("LOC_LAUNCH_ICBM_DIALOG_ARE_YOU_SURE"));
  1979. pPopupDialog:AddButton(Locale.Lookup("LOC_LAUNCH_ICBM_DIALOG_CANCEL"), nil);
  1980. pPopupDialog:AddButton(Locale.Lookup("LOC_LAUNCH_ICBM_DIALOG_LAUNCH"), strikeFn);
  1981. pPopupDialog:Open();
  1982. end
  1983. end
  1984. end
  1985. -------------------------------------------------------------------------------
  1986. function ICBMStrike( fromCity, sourcePlotX, sourcePlotY, targetPlot, eWMD )
  1987. local tParameters = {};
  1988. tParameters[CityCommandTypes.PARAM_X0] = sourcePlotX;
  1989. tParameters[CityCommandTypes.PARAM_Y0] = sourcePlotY;
  1990. tParameters[CityCommandTypes.PARAM_X1] = targetPlot:GetX();
  1991. tParameters[CityCommandTypes.PARAM_Y1] = targetPlot:GetY();
  1992. tParameters[CityCommandTypes.PARAM_WMD_TYPE] = eWMD;
  1993. if (CityManager.CanStartCommand( fromCity, CityCommandTypes.WMD_STRIKE, tParameters)) then
  1994. CityManager.RequestCommand( fromCity, CityCommandTypes.WMD_STRIKE, tParameters);
  1995. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  1996. end
  1997. end
  1998. -------------------------------------------------------------------------------
  1999. function OnInterfaceModeChange_ICBM_Strike(eNewMode)
  2000. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2001. local pCity = UI.GetHeadSelectedCity();
  2002.  
  2003. if (pCity ~= nil) then
  2004. if m_focusedTargetPlot ~= -1 then
  2005. UILens.UnFocusHex(LensLayers.ATTACK_RANGE, m_focusedTargetPlot);
  2006. m_focusedTargetPlot = -1;
  2007. end
  2008. local eWMD = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_WMD_TYPE);
  2009. local iSourceLocX = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_X0);
  2010. local iSourceLocY = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_Y0);
  2011.  
  2012. local tParameters = {};
  2013. tParameters[CityCommandTypes.PARAM_WMD_TYPE] = eWMD;
  2014. tParameters[CityCommandTypes.PARAM_X0] = iSourceLocX;
  2015. tParameters[CityCommandTypes.PARAM_Y0] = iSourceLocY;
  2016.  
  2017. local sourcePlot : number = Map.GetPlot(iSourceLocX,iSourceLocY):GetIndex();
  2018.  
  2019. local tResults = CityManager.GetCommandTargets(pCity, CityCommandTypes.WMD_STRIKE, tParameters);
  2020. local allPlots = tResults[CityCommandResults.PLOTS];
  2021. if (allPlots ~= nil) then
  2022. m_targetPlots = {}; -- Use shared list so other functions know our targets
  2023. for i,modifier in ipairs(tResults[CityCommandResults.PLOTS]) do
  2024. table.insert(m_targetPlots, allPlots[i]);
  2025. end
  2026.  
  2027. -- Highlight the plots available to attack
  2028. if (table.count(m_targetPlots) ~= 0) then
  2029. local kVariations:table = {};
  2030. for _,plotId in ipairs(m_targetPlots) do
  2031. table.insert(kVariations, {"AttackRange_Target", sourcePlot , plotId} );
  2032. end
  2033. local eLocalPlayer:number = Game.GetLocalPlayer();
  2034. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_ATTACK);
  2035. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_ATTACK, eLocalPlayer, m_targetPlots, kVariations);
  2036. end
  2037. else
  2038. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2039. end
  2040. end
  2041. end
  2042.  
  2043. ---------------------------------------------------------------------------------
  2044. function OnInterfaceModeLeave_ICBM_Strike( eNewMode:number )
  2045. UIManager:SetUICursor(CursorTypes.NORMAL);
  2046. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_ATTACK );
  2047. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_ATTACK );
  2048. end
  2049.  
  2050. -- ===========================================================================
  2051. -- Code related to the Coastal Raid interface mode
  2052. -- ===========================================================================
  2053. function CoastalRaid( pInputStruct )
  2054. local plotID = UI.GetCursorPlotID();
  2055. if (Map.IsPlot(plotID)) then
  2056. local plot = Map.GetPlotByIndex(plotID);
  2057.  
  2058. local tParameters = {};
  2059. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  2060. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  2061.  
  2062. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2063.  
  2064. if (UnitManager.CanStartOperation( pSelectedUnit, UnitOperationTypes.COASTAL_RAID, nil, tParameters)) then
  2065. UnitManager.RequestOperation( pSelectedUnit, UnitOperationTypes.COASTAL_RAID, tParameters);
  2066. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2067. end
  2068. end
  2069. return true;
  2070. end
  2071. -------------------------------------------------------------------------------
  2072. function OnInterfaceModeChange_CoastalRaid(eNewMode)
  2073. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2074. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2075. if (pSelectedUnit ~= nil) then
  2076. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, UnitOperationTypes.COASTAL_RAID );
  2077. local allPlots = tResults[UnitOperationResults.PLOTS];
  2078. if (allPlots ~= nil) then
  2079. m_targetPlots = {};
  2080. for i,modifier in ipairs(tResults[UnitOperationResults.PLOTS]) do
  2081. table.insert(m_targetPlots, allPlots[i]);
  2082. end
  2083.  
  2084. -- Highlight the plots available to attack
  2085. if (table.count(m_targetPlots) ~= 0) then
  2086. local eLocalPlayer:number = Game.GetLocalPlayer();
  2087. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_ATTACK);
  2088. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_ATTACK, eLocalPlayer, m_targetPlots);
  2089. end
  2090. end
  2091. end
  2092. end
  2093.  
  2094. ---------------------------------------------------------------------------------
  2095. function OnInterfaceModeLeave_CoastalRaid( eNewMode:number )
  2096. UIManager:SetUICursor(CursorTypes.NORMAL);
  2097. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_ATTACK );
  2098. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_ATTACK );
  2099. end
  2100.  
  2101. -- ===========================================================================
  2102. -- Code related to the Unit Air Deploy interface mode
  2103. -- ===========================================================================
  2104. function OnMouseDeployEnd( pInputStruct )
  2105. -- If a drag was occurring, end it; otherwise raise event.
  2106. if m_isMouseDragging then
  2107. m_isMouseDragging = false;
  2108. else
  2109. if IsSelectionAllowedAt( UI.GetCursorPlotID() ) then
  2110. AirUnitDeploy(pInputStruct);
  2111. end
  2112. end
  2113. EndDragMap();
  2114. m_isMouseDownInWorld = false;
  2115. return true;
  2116. end
  2117. -------------------------------------------------------------------------------
  2118. function AirUnitDeploy( pInputStruct )
  2119. local plotID = UI.GetCursorPlotID();
  2120. if (Map.IsPlot(plotID)) then
  2121. local plot = Map.GetPlotByIndex(plotID);
  2122.  
  2123. local tParameters = {};
  2124. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  2125. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  2126.  
  2127. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2128. -- Assuming that the operation is DEPLOY. Store this in the InterfaceMode somehow?
  2129. if (UnitManager.CanStartOperation( pSelectedUnit, UnitOperationTypes.DEPLOY, nil, tParameters)) then
  2130. UnitManager.RequestOperation( pSelectedUnit, UnitOperationTypes.DEPLOY, tParameters);
  2131. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2132. end
  2133. end
  2134. return true;
  2135. end
  2136. -------------------------------------------------------------------------------
  2137. function OnInterfaceModeChange_Deploy(eNewMode)
  2138. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2139. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2140. if (pSelectedUnit ~= nil) then
  2141.  
  2142. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, UnitOperationTypes.DEPLOY );
  2143. local allPlots = tResults[UnitOperationResults.PLOTS];
  2144. if (allPlots ~= nil) then
  2145. m_targetPlots = {};
  2146. for i,modifier in ipairs(tResults[UnitOperationResults.PLOTS]) do
  2147. --if(modifier == UnitOperationResults.MODIFIER_IS_TARGET) then
  2148. table.insert(m_targetPlots, allPlots[i]);
  2149. --end
  2150. end
  2151.  
  2152. -- Highlight the plots available to deploy to
  2153. if (table.count(m_targetPlots) ~= 0) then
  2154. local eLocalPlayer:number = Game.GetLocalPlayer();
  2155. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_MOVEMENT);
  2156. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_MOVEMENT, eLocalPlayer, m_targetPlots);
  2157. end
  2158. end
  2159. end
  2160. end
  2161.  
  2162. ---------------------------------------------------------------------------------
  2163. function OnInterfaceModeLeave_Deploy( eNewMode:number )
  2164. UIManager:SetUICursor(CursorTypes.NORMAL);
  2165. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_MOVEMENT );
  2166. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_MOVEMENT );
  2167. end
  2168.  
  2169. -- ===========================================================================
  2170. -- Code related to the Unit Air Re-Base interface mode
  2171. -- ===========================================================================
  2172. function OnMouseRebaseEnd( pInputStruct )
  2173. -- If a drag was occurring, end it; otherwise raise event.
  2174. if m_isMouseDragging then
  2175. m_isMouseDragging = false;
  2176. else
  2177. if IsSelectionAllowedAt( UI.GetCursorPlotID() ) then
  2178. AirUnitReBase(pInputStruct);
  2179. end
  2180. end
  2181. EndDragMap();
  2182. m_isMouseDownInWorld = false;
  2183. return true;
  2184. end
  2185. -------------------------------------------------------------------------------
  2186. function AirUnitReBase( pInputStruct )
  2187. local plotID = UI.GetCursorPlotID();
  2188. if (Map.IsPlot(plotID)) then
  2189. local plot = Map.GetPlotByIndex(plotID);
  2190.  
  2191. local tParameters = {};
  2192. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  2193. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  2194.  
  2195. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2196. -- Assuming that the operation is DEPLOY. Store this in the InterfaceMode somehow?
  2197. if (UnitManager.CanStartOperation( pSelectedUnit, UnitOperationTypes.REBASE, nil, tParameters)) then
  2198. UnitManager.RequestOperation( pSelectedUnit, UnitOperationTypes.REBASE, tParameters);
  2199. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2200. end
  2201. end
  2202. return true;
  2203. end
  2204. -------------------------------------------------------------------------------
  2205. function OnInterfaceModeChange_ReBase(eNewMode)
  2206. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2207. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2208. if (pSelectedUnit ~= nil) then
  2209.  
  2210. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, UnitOperationTypes.REBASE );
  2211. local allPlots = tResults[UnitOperationResults.PLOTS];
  2212. if (allPlots ~= nil) then
  2213. m_targetPlots = {};
  2214. for i,modifier in ipairs(tResults[UnitOperationResults.PLOTS]) do
  2215. table.insert(m_targetPlots, allPlots[i]);
  2216. end
  2217.  
  2218. -- Highlight the plots available to deploy to
  2219. if (table.count(m_targetPlots) ~= 0) then
  2220. local eLocalPlayer:number = Game.GetLocalPlayer();
  2221. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_MOVEMENT);
  2222. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_MOVEMENT, eLocalPlayer, m_targetPlots);
  2223. end
  2224. end
  2225. end
  2226. end
  2227.  
  2228. ---------------------------------------------------------------------------------
  2229. function OnInterfaceModeLeave_ReBase( eNewMode:number )
  2230. UIManager:SetUICursor(CursorTypes.NORMAL);
  2231. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_MOVEMENT );
  2232. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_MOVEMENT );
  2233. end
  2234.  
  2235. -- ===========================================================================
  2236. -- Code related to the Place Map Pin interface mode
  2237. -- ===========================================================================
  2238. function PlaceMapPin()
  2239. local plotId = UI.GetCursorPlotID();
  2240. if (Map.IsPlot(plotId)) then
  2241. local kPlot = Map.GetPlotByIndex(plotId);
  2242. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION); -- Revert to default interface mode.
  2243. LuaEvents.MapPinPopup_RequestMapPin(kPlot:GetX(), kPlot:GetY());
  2244. end
  2245. return true;
  2246. end
  2247.  
  2248. ------------------------------------------------------------------------------------------------
  2249. -- Code related to the City and District Range Attack interface mode
  2250. ------------------------------------------------------------------------------------------------
  2251. function CityRangeAttack( pInputStruct )
  2252. if ClearRangeAttackDragging() then
  2253. return true;
  2254. end
  2255.  
  2256. local plotID = UI.GetCursorPlotID();
  2257. if (Map.IsPlot(plotID)) then
  2258. local plot = Map.GetPlotByIndex(plotID);
  2259.  
  2260. local tParameters = {};
  2261. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  2262. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  2263.  
  2264. local pSelectedCity = UI.GetHeadSelectedCity();
  2265. -- Assuming that the command is RANGE_ATTACK. Store this in the InterfaceMode somehow?
  2266. if (CityManager.CanStartCommand( pSelectedCity, CityCommandTypes.RANGE_ATTACK, tParameters)) then
  2267. CityManager.RequestCommand( pSelectedCity, CityCommandTypes.RANGE_ATTACK, tParameters);
  2268. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2269. end
  2270. end
  2271. return true;
  2272. end
  2273.  
  2274. -------------------------------------------------------------------------------
  2275. function OnInterfaceModeChange_CityRangeAttack(eNewMode)
  2276. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2277. local pSelectedCity = UI.GetHeadSelectedCity();
  2278. if (pSelectedCity ~= nil) then
  2279.  
  2280. if m_focusedTargetPlot ~= -1 then
  2281. UILens.UnFocusHex(LensLayers.ATTACK_RANGE, m_focusedTargetPlot);
  2282. m_focusedTargetPlot = -1;
  2283. end
  2284.  
  2285. local tParameters = {};
  2286. tParameters[CityCommandTypes.PARAM_RANGED_ATTACK] = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_RANGED_ATTACK);
  2287.  
  2288. local tResults = CityManager.GetCommandTargets(pSelectedCity, CityCommandTypes.RANGE_ATTACK, tParameters );
  2289. local allPlots = tResults[CityCommandResults.PLOTS];
  2290. if (allPlots ~= nil) then
  2291. m_targetPlots = {};
  2292. for i,modifier in ipairs(tResults[CityCommandResults.MODIFIERS]) do
  2293. if(modifier == CityCommandResults.MODIFIER_IS_TARGET) then
  2294. table.insert(m_targetPlots, allPlots[i]);
  2295. end
  2296. end
  2297.  
  2298. -- Highlight the plots available to attack
  2299. if (table.count(m_targetPlots) ~= 0) then
  2300. -- Variation will hold specific targets in range
  2301. local kVariations:table = {};
  2302. for _,plotId in ipairs(m_targetPlots) do
  2303. table.insert(kVariations, {"AttackRange_Target", allPlots[1], plotId} );
  2304. end
  2305. local eLocalPlayer:number = Game.GetLocalPlayer();
  2306.  
  2307. UILens.SetLayerHexesArea(LensLayers.ATTACK_RANGE, eLocalPlayer, allPlots, kVariations);
  2308.  
  2309. end
  2310. end
  2311. end
  2312. end
  2313.  
  2314. -------------------------------------------------------------------------------
  2315. function OnInterfaceModeLeave_CityRangeAttack(eNewMode)
  2316. UILens.ClearLayerHexes( LensLayers.ATTACK_RANGE );
  2317. end
  2318.  
  2319. -------------------------------------------------------------------------------
  2320. function DistrictRangeAttack( pInputStruct )
  2321. if ClearRangeAttackDragging() then
  2322. return true;
  2323. end
  2324.  
  2325. local plotID = UI.GetCursorPlotID();
  2326. if (Map.IsPlot(plotID)) then
  2327. local plot = Map.GetPlotByIndex(plotID);
  2328.  
  2329. local tParameters = {};
  2330. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  2331. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  2332.  
  2333. local pSelectedDistrict = UI.GetHeadSelectedDistrict();
  2334. -- Assuming that the command is RANGE_ATTACK. Store this in the InterfaceMode somehow?
  2335. if (CityManager.CanStartCommand( pSelectedDistrict, CityCommandTypes.RANGE_ATTACK, tParameters)) then
  2336. CityManager.RequestCommand( pSelectedDistrict, CityCommandTypes.RANGE_ATTACK, tParameters);
  2337. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2338. end
  2339. end
  2340. return true;
  2341. end
  2342. -------------------------------------------------------------------------------
  2343. function OnInterfaceModeChange_DistrictRangeAttack(eNewMode)
  2344. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2345. local pSelectedDistrict = UI.GetHeadSelectedDistrict();
  2346. if (pSelectedDistrict ~= nil) then
  2347.  
  2348. if m_focusedTargetPlot ~= -1 then
  2349. UILens.UnFocusHex(LensLayers.ATTACK_RANGE, m_focusedTargetPlot);
  2350. m_focusedTargetPlot = -1;
  2351. end
  2352.  
  2353. local tParameters = {};
  2354. tParameters[CityCommandTypes.PARAM_RANGED_ATTACK] = UI.GetInterfaceModeParameter(CityCommandTypes.PARAM_RANGED_ATTACK);
  2355.  
  2356. local tResults :table = CityManager.GetCommandTargets(pSelectedDistrict, CityCommandTypes.RANGE_ATTACK, tParameters );
  2357. local allPlots :table = tResults[CityCommandResults.PLOTS];
  2358. if (allPlots ~= nil) then
  2359. m_targetPlots = {};
  2360. for i,modifier in ipairs(tResults[CityCommandResults.MODIFIERS]) do
  2361. if(modifier == CityCommandResults.MODIFIER_IS_TARGET) then
  2362. table.insert(m_targetPlots, allPlots[i]);
  2363. end
  2364. end
  2365.  
  2366. -- Highlight the plots available to attack
  2367. if (table.count(m_targetPlots) ~= 0) then
  2368. -- Variation will hold specific targets in range
  2369. local kVariations:table = {};
  2370. for _,plotId in ipairs(m_targetPlots) do
  2371. table.insert(kVariations, {"AttackRange_Target", allPlots[1], plotId} );
  2372. end
  2373. local eLocalPlayer:number = Game.GetLocalPlayer();
  2374.  
  2375. UILens.SetLayerHexesArea(LensLayers.ATTACK_RANGE, eLocalPlayer, allPlots, kVariations);
  2376.  
  2377. end
  2378. end
  2379. end
  2380. end
  2381.  
  2382. -------------------------------------------------------------------------------
  2383. function OnInterfaceModeLeave_DistrictRangeAttack(eNewMode)
  2384. UILens.ClearLayerHexes( LensLayers.ATTACK_RANGE );
  2385. end
  2386.  
  2387. -------------------------------------------------------------------------------
  2388. function OnInterfaceModeLeave_WMDRangeAttack(eNewMode)
  2389. UILens.ClearLayerHexes( LensLayers.ATTACK_RANGE );
  2390. end
  2391.  
  2392. ------------------------------------------------------------------------------------------------
  2393. -- Code related to the Unit's Make Trade Route interface mode
  2394. -- Some input is handled separately, by TradePanel.lua
  2395. ------------------------------------------------------------------------------------------------
  2396. function OnInterfaceModeChange_MakeTradeRoute(eNewMode)
  2397. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2398. end
  2399.  
  2400. ------------------------------------------------------------------------------------------------
  2401. -- Code related to the Unit's 'Teleport to City' mode
  2402. ------------------------------------------------------------------------------------------------
  2403. function TeleportToCity()
  2404. local plotID = UI.GetCursorPlotID();
  2405. if (Map.IsPlot(plotID)) then
  2406. local plot = Map.GetPlotByIndex(plotID);
  2407.  
  2408. local tParameters = {};
  2409. tParameters[UnitOperationTypes.PARAM_X] = plot:GetX();
  2410. tParameters[UnitOperationTypes.PARAM_Y] = plot:GetY();
  2411.  
  2412. local eOperation = UI.GetInterfaceModeParameter(UnitOperationTypes.PARAM_OPERATION_TYPE);
  2413.  
  2414. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2415. if (UnitManager.CanStartOperation( pSelectedUnit, eOperation, nil, tParameters)) then
  2416. UnitManager.RequestOperation( pSelectedUnit, eOperation, tParameters);
  2417. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2418. UI.PlaySound("Unit_Relocate");
  2419. end
  2420. end
  2421. return true;
  2422. end
  2423. -------------------------------------------------------------------------------
  2424. function OnInterfaceModeChange_TeleportToCity(eNewMode)
  2425. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2426. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2427. if (pSelectedUnit ~= nil) then
  2428.  
  2429. local eOperation = UI.GetInterfaceModeParameter(UnitOperationTypes.PARAM_OPERATION_TYPE);
  2430. local tResults = UnitManager.GetOperationTargets(pSelectedUnit, eOperation );
  2431. local allPlots = tResults[UnitOperationResults.PLOTS];
  2432. if (allPlots ~= nil) then
  2433. m_targetPlots = {};
  2434. for i,modifier in ipairs(tResults[UnitOperationResults.PLOTS]) do
  2435. table.insert(m_targetPlots, allPlots[i]);
  2436. end
  2437.  
  2438. -- Highlight the plots available to deploy to
  2439. if (table.count(m_targetPlots) ~= 0) then
  2440. local eLocalPlayer:number = Game.GetLocalPlayer();
  2441. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_MOVEMENT);
  2442. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_MOVEMENT, eLocalPlayer, m_targetPlots);
  2443. end
  2444. end
  2445. end
  2446. end
  2447.  
  2448. ---------------------------------------------------------------------------------
  2449. function OnInterfaceModeLeave_TeleportToCity( eNewMode:number )
  2450. UIManager:SetUICursor(CursorTypes.NORMAL);
  2451. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_MOVEMENT );
  2452. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_MOVEMENT );
  2453. end
  2454.  
  2455. -- =============================================================================================
  2456. function OnInterfaceModeChange_MoveTo( eNewMode:number )
  2457. m_cachedPathUnit = nil;
  2458. m_cachedPathPlotId = -1 ;
  2459. RealizeMovementPath();
  2460. end
  2461.  
  2462. -- =============================================================================================
  2463. function OnInterfaceModeChange_MoveToLeave( eOldMode:number )
  2464. ClearMovementPath();
  2465. UILens.SetActive("Default");
  2466. end
  2467.  
  2468. -- =============================================================================================
  2469. function OnInterfaceModeChange_PlaceMapPin( eNewMode:number )
  2470. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2471. end
  2472.  
  2473. ------------------------------------------------------------------------------------------------
  2474. -- Code related to the World Builder's Select Plot Mode
  2475. ------------------------------------------------------------------------------------------------
  2476.  
  2477. -- =============================================================================================
  2478. function OnInterfaceModeChange_WBSelectPlot()
  2479. m_WBMouseOverPlot = -1;
  2480. end
  2481.  
  2482. -- =============================================================================================
  2483. function OnInterfaceModeChange_SpyChooseMission()
  2484. UIManager:SetUICursor(CursorTypes.NORMAL);
  2485. UILens.SetActive("Default");
  2486. end
  2487.  
  2488. -- =============================================================================================
  2489. function OnInterfaceModeChange_SpyTravelToCity()
  2490. UIManager:SetUICursor(CursorTypes.NORMAL);
  2491. UILens.SetActive("Default");
  2492.  
  2493. end
  2494.  
  2495. function OnInterfaceModeChange_NaturalWonder()
  2496. UIManager:SetUICursor(CursorTypes.NORMAL);
  2497. UI.SetFixedTiltMode( true );
  2498. end
  2499.  
  2500. -- ===========================================================================
  2501. function OnInterfaceModeLeave_NaturalWonder( eNewMode:number )
  2502. UIManager:SetUICursor(CursorTypes.NORMAL);
  2503. UI.SetFixedTiltMode( false );
  2504. OnCycleUnitSelectionRequest();
  2505. end
  2506.  
  2507. -- ===========================================================================
  2508. function OnMouseEnd_WBSelectPlot( pInputStruct:table )
  2509. -- If a drag was occurring, end it; otherwise attempt selection of whatever
  2510. -- is in the plot the mouse is currently at.
  2511. if m_isMouseDragging then
  2512. print("Stopping drag");
  2513. m_isMouseDragging = false;
  2514. else
  2515. print("World Builder Placement");
  2516. if (Map.IsPlot(UI.GetCursorPlotID())) then
  2517. LuaEvents.WorldInput_WBSelectPlot(UI.GetCursorPlotID(), UI.GetCursorNearestPlotEdge(), true);
  2518. end
  2519. end
  2520. EndDragMap(); -- Reset any dragging
  2521. m_isMouseDownInWorld = false;
  2522. return true;
  2523. end
  2524.  
  2525. -- ===========================================================================
  2526. function OnRButtonUp_WBSelectPlot( pInputStruct )
  2527. if (Map.IsPlot(UI.GetCursorPlotID())) then
  2528. LuaEvents.WorldInput_WBSelectPlot(UI.GetCursorPlotID(), UI.GetCursorNearestPlotEdge(), false);
  2529. end
  2530. return true;
  2531. end
  2532.  
  2533. -- ===========================================================================
  2534. function OnMouseMove_WBSelectPlot( pInputStruct )
  2535.  
  2536. -- Check to see if the plot the mouse is over has changed
  2537. if not m_isMouseDragging then
  2538. local mouseOverPlot = UI.GetCursorPlotID();
  2539. if (Map.IsPlot(mouseOverPlot)) then
  2540. if mouseOverPlot ~= m_WBMouseOverPlot then
  2541. m_WBMouseOverPlot = mouseOverPlot;
  2542. LuaEvents.WorldInput_WBMouseOverPlot(mouseOverPlot);
  2543. end
  2544. end
  2545. end
  2546.  
  2547. return OnMouseMove();
  2548. end
  2549.  
  2550. ------------------------------------------------------------------------------------------------
  2551. -- Code related to the Unit's 'Form Corps' mode
  2552. ------------------------------------------------------------------------------------------------
  2553. function FormCorps( pInputStruct )
  2554. local plotID = UI.GetCursorPlotID();
  2555. if (Map.IsPlot(plotID)) then
  2556. local plot = Map.GetPlotByIndex(plotID);
  2557. local unitList = Units.GetUnitsInPlotLayerID( plot:GetX(), plot:GetY(), MapLayers.ANY );
  2558. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2559.  
  2560. local tParameters :table = {};
  2561. for i, pUnit in ipairs(unitList) do
  2562. tParameters[UnitCommandTypes.PARAM_UNIT_PLAYER] = pUnit:GetOwner();
  2563. tParameters[UnitCommandTypes.PARAM_UNIT_ID] = pUnit:GetID();
  2564. if (UnitManager.CanStartCommand( pSelectedUnit, UnitCommandTypes.FORM_CORPS, tParameters)) then
  2565. UnitManager.RequestCommand( pSelectedUnit, UnitCommandTypes.FORM_CORPS, tParameters);
  2566. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2567. end
  2568. end
  2569. end
  2570. return true;
  2571. end
  2572.  
  2573. ------------------------------------------------------------------------------------------------
  2574. function OnInterfaceModeChange_UnitFormCorps(eNewMode)
  2575. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2576. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2577. local player = pSelectedUnit:GetOwner();
  2578. local tResults = UnitManager.GetCommandTargets( pSelectedUnit, UnitCommandTypes.FORM_CORPS );
  2579. if (tResults[UnitCommandResults.UNITS] ~= nil and #tResults[UnitCommandResults.UNITS] ~= 0) then
  2580. local tUnits = tResults[UnitCommandResults.UNITS];
  2581. local unitPlots :table = {};
  2582. m_targetPlots = {};
  2583. for i, unitComponentID in ipairs(tUnits) do
  2584. local unit = Players[player]:GetUnits():FindID(unitComponentID.id);
  2585. table.insert(unitPlots, Map.GetPlotIndex(unit:GetX(), unit:GetY()));
  2586. end
  2587. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_PLACEMENT);
  2588. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_PLACEMENT, player, unitPlots);
  2589. m_targetPlots = unitPlots;
  2590. end
  2591. end
  2592.  
  2593. --------------------------------------------------------------------------------------------------
  2594. function OnInterfaceModeLeave_UnitFormCorps( eNewMode:number )
  2595. UIManager:SetUICursor(CursorTypes.NORMAL);
  2596. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_PLACEMENT );
  2597. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_PLACEMENT );
  2598. end
  2599.  
  2600. ------------------------------------------------------------------------------------------------
  2601. -- Code related to the Unit's 'Form Army' mode
  2602. ------------------------------------------------------------------------------------------------
  2603. function FormArmy( pInputStruct )
  2604. local plotID = UI.GetCursorPlotID();
  2605. if (Map.IsPlot(plotID)) then
  2606. local plot = Map.GetPlotByIndex(plotID);
  2607. local unitList = Units.GetUnitsInPlotLayerID( plot:GetX(), plot:GetY(), MapLayers.ANY );
  2608. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2609.  
  2610. local tParameters :table = {};
  2611. for i, pUnit in ipairs(unitList) do
  2612. tParameters[UnitCommandTypes.PARAM_UNIT_PLAYER] = pUnit:GetOwner();
  2613. tParameters[UnitCommandTypes.PARAM_UNIT_ID] = pUnit:GetID();
  2614. if (UnitManager.CanStartCommand( pSelectedUnit, UnitCommandTypes.FORM_ARMY, tParameters)) then
  2615. UnitManager.RequestCommand( pSelectedUnit, UnitCommandTypes.FORM_ARMY, tParameters);
  2616. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2617. end
  2618. end
  2619. end
  2620.  
  2621. return true;
  2622. end
  2623.  
  2624. ------------------------------------------------------------------------------------------------
  2625. function OnInterfaceModeChange_UnitFormArmy(eNewMode)
  2626. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2627. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2628. local player = pSelectedUnit:GetOwner();
  2629. local tResults = UnitManager.GetCommandTargets( pSelectedUnit, UnitCommandTypes.FORM_ARMY );
  2630. if (tResults[UnitCommandResults.UNITS] ~= nil and #tResults[UnitCommandResults.UNITS] ~= 0) then
  2631. local tUnits = tResults[UnitCommandResults.UNITS];
  2632. local unitPlots :table = {};
  2633. m_targetPlots = {};
  2634. for i, unitComponentID in ipairs(tUnits) do
  2635. local unit = Players[player]:GetUnits():FindID(unitComponentID.id);
  2636. table.insert(unitPlots, Map.GetPlotIndex(unit:GetX(), unit:GetY()));
  2637. end
  2638. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_PLACEMENT);
  2639. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_PLACEMENT, player, unitPlots);
  2640. m_targetPlots = unitPlots;
  2641. end
  2642. end
  2643.  
  2644. --------------------------------------------------------------------------------------------------
  2645. function OnInterfaceModeLeave_UnitFormArmy( eNewMode:number )
  2646. UIManager:SetUICursor(CursorTypes.NORMAL);
  2647. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_PLACEMENT );
  2648. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_PLACEMENT );
  2649. end
  2650.  
  2651. ------------------------------------------------------------------------------------------------
  2652. -- Code related to the Unit's 'Airlift' mode
  2653. ------------------------------------------------------------------------------------------------
  2654. function OnMouseAirliftEnd( pInputStruct )
  2655. -- If a drag was occurring, end it; otherwise raise event.
  2656. if m_isMouseDragging then
  2657. m_isMouseDragging = false;
  2658. else
  2659. if IsSelectionAllowedAt( UI.GetCursorPlotID() ) then
  2660. UnitAirlift(pInputStruct);
  2661. end
  2662. end
  2663. EndDragMap();
  2664. m_isMouseDownInWorld = false;
  2665. return true;
  2666. end
  2667. ------------------------------------------------------------------------------------------------
  2668. function UnitAirlift( pInputStruct )
  2669. local plotID = UI.GetCursorPlotID();
  2670. if (Map.IsPlot(plotID)) then
  2671. local plot = Map.GetPlotByIndex(plotID);
  2672.  
  2673. local tParameters = {};
  2674. tParameters[UnitCommandTypes.PARAM_X] = plot:GetX();
  2675. tParameters[UnitCommandTypes.PARAM_Y] = plot:GetY();
  2676.  
  2677. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2678. -- Assuming that the operation is AIRLIFT. Store this in the InterfaceMode somehow?
  2679. if (UnitManager.CanStartCommand( pSelectedUnit, UnitCommandTypes.AIRLIFT, nil, tParameters)) then
  2680. UnitManager.RequestCommand( pSelectedUnit, UnitCommandTypes.AIRLIFT, tParameters);
  2681. UI.SetInterfaceMode(InterfaceModeTypes.SELECTION);
  2682. end
  2683. end
  2684. return true;
  2685. end
  2686. ------------------------------------------------------------------------------------------------
  2687. function OnInterfaceModeChange_UnitAirlift(eNewMode)
  2688. UIManager:SetUICursor(CursorTypes.RANGE_ATTACK);
  2689. local pSelectedUnit = UI.GetHeadSelectedUnit();
  2690. local tResults = UnitManager.GetCommandTargets(pSelectedUnit, UnitCommandTypes.AIRLIFT );
  2691. local allPlots = tResults[UnitCommandResults.PLOTS];
  2692. if (allPlots ~= nil) then
  2693. m_targetPlots = {};
  2694. for i,modifier in ipairs(tResults[UnitCommandResults.PLOTS]) do
  2695. table.insert(m_targetPlots, allPlots[i]);
  2696. end
  2697.  
  2698. -- Highlight the plots available to airlift to
  2699. if (table.count(m_targetPlots) ~= 0) then
  2700. local eLocalPlayer:number = Game.GetLocalPlayer();
  2701. UILens.ToggleLayerOn(LensLayers.HEX_COLORING_MOVEMENT);
  2702. UILens.SetLayerHexesArea(LensLayers.HEX_COLORING_MOVEMENT, eLocalPlayer, m_targetPlots);
  2703. end
  2704. end
  2705. end
  2706. --------------------------------------------------------------------------------------------------
  2707. function OnInterfaceModeLeave_UnitAirlift( eNewMode:number )
  2708. UIManager:SetUICursor(CursorTypes.NORMAL);
  2709. UILens.ToggleLayerOff( LensLayers.HEX_COLORING_MOVEMENT );
  2710. UILens.ClearLayerHexes( LensLayers.HEX_COLORING_MOVEMENT );
  2711. end
  2712.  
  2713.  
  2714. -- ===========================================================================
  2715. function OnInterfaceModeChange_Selection(eNewMode)
  2716. UIManager:SetUICursor(CursorTypes.NORMAL);
  2717. UILens.SetActive("Default");
  2718. end
  2719.  
  2720.  
  2721.  
  2722. -- .,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,
  2723. --
  2724. -- EVENT MAPPINGS, PRE-PROCESSING & HANDLING
  2725. --
  2726. -- .,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,.,;/^`'^\:,
  2727.  
  2728.  
  2729. -- ===========================================================================
  2730. -- ENGINE Event
  2731. -- Will only be called once the animation from the previous player is
  2732. -- complete or will be skipped if a player has no selection or explicitly
  2733. -- selected another unit/city.
  2734. -- ===========================================================================
  2735. function OnCycleUnitSelectionRequest()
  2736.  
  2737. -- If the right button is (still) down, do not select a new unit otherwise
  2738. -- a long path may be created if there is a long camera pan.
  2739. --if m_isMouseButtonRDown then
  2740. -- return;
  2741. --end
  2742.  
  2743. if(UI.GetInterfaceMode() ~= InterfaceModeTypes.NATURAL_WONDER or m_isMouseButtonRDown) then
  2744. -- Auto-advance selection to the next unit.
  2745. if not UI.SelectNextReadyUnit() then
  2746. UI.DeselectAllUnits();
  2747. end
  2748. end
  2749. end
  2750.  
  2751.  
  2752. -- ===========================================================================
  2753. -- ENGINE Event
  2754. -- eOldMode, mode the engine was formally in
  2755. -- eNewMode, new mode the engine has just changed to
  2756. -- ===========================================================================
  2757. function OnInterfaceModeChanged( eOldMode:number, eNewMode:number )
  2758.  
  2759. -- Optional: function run before a mode is exited.
  2760. local pOldModeHandler :table = InterfaceModeMessageHandler[eOldMode];
  2761. if pOldModeHandler then
  2762. local pModeLeaveFunc :ifunction = pOldModeHandler[INTERFACEMODE_LEAVE];
  2763. if pModeLeaveFunc ~= nil then
  2764. pModeLeaveFunc(eOldMode);
  2765. end
  2766. end
  2767.  
  2768. -- Required: function to setup next interface mode in world input
  2769. local pNewModeHandler :table = InterfaceModeMessageHandler[eNewMode];
  2770. if pNewModeHandler then
  2771. local pModeChangeFunc :ifunction = pNewModeHandler[INTERFACEMODE_ENTER];
  2772. if pModeChangeFunc ~= nil then
  2773. pModeChangeFunc(eNewMode);
  2774. end
  2775. else
  2776. local msg:string = string.format("Change requested an unhandled interface mode of value '0x%x'. (Previous mode '0x%x')",eNewMode,eOldMode);
  2777. print(msg);
  2778. UIManager:SetUICursor(CursorTypes.NORMAL);
  2779. UILens.SetActive("Default");
  2780. end
  2781. end
  2782.  
  2783. -- ===========================================================================
  2784. -- ENGINE Event
  2785. -- ===========================================================================
  2786. function IsEndGameMenuShown()
  2787. local endGameShown = false;
  2788. local endGameContext = ContextPtr:LookUpControl("/InGame/EndGameMenu");
  2789. if(endGameContext) then
  2790. endGameShown = not endGameContext:IsHidden();
  2791. end
  2792. return endGameShown;
  2793. end
  2794.  
  2795. function OnMultiplayerGameLastPlayer()
  2796. -- Only show the last player popup in multiplayer games where the session is a going concern
  2797. if(GameConfiguration.IsNetworkMultiplayer()
  2798. and not Network.IsSessionInCloseState()
  2799. -- suppress popup when the end game screen is up.
  2800. -- This specifically prevents a turn spinning issue that can occur if the host migrates to a dead human player on the defeated screen. TTP 18902
  2801. and not IsEndGameMenuShown()) then
  2802. local lastPlayerStr = Locale.Lookup( "TXT_KEY_MP_LAST_PLAYER" );
  2803. local okStr = Locale.Lookup( "LOC_OK_BUTTON" );
  2804. local pPopupDialog :table = PopupDialog:new("LastPlayer");
  2805. pPopupDialog:AddText(lastPlayerStr);
  2806. pPopupDialog:AddButton(okStr, nil );
  2807. pPopupDialog:Open();
  2808. end
  2809. end
  2810.  
  2811. -- ===========================================================================
  2812. -- ENGINE Event
  2813. -- ===========================================================================
  2814. function OnMultiplayerGameAbandoned(eReason)
  2815. if(GameConfiguration.IsNetworkMultiplayer()) then
  2816. local errorStr = Locale.Lookup( "LOC_GAME_ABANDONED_CONNECTION_LOST" );
  2817. local exitStr = Locale.Lookup( "LOC_GAME_MENU_EXIT_TO_MAIN" );
  2818.  
  2819. -- Select error message based on KickReason.
  2820. -- Not all of these should be possible while in game but we include them anyway.
  2821. if (eReason == KickReason.KICK_HOST) then
  2822. errorStr = Locale.Lookup( "LOC_GAME_ABANDONED_KICKED" );
  2823. elseif (eReason == KickReason.KICK_NO_HOST) then
  2824. errorStr = Locale.Lookup( "LOC_GAME_ABANDONED_HOST_LOSTED" );
  2825. elseif (eReason == KickReason.KICK_NO_ROOM) then
  2826. errorStr = Locale.Lookup( "LOC_GAME_ABANDONED_ROOM_FULL" );
  2827. elseif (eReason == KickReason.KICK_VERSION_MISMATCH) then
  2828. errorStr = Locale.Lookup( "LOC_GAME_ABANDONED_VERSION_MISMATCH" );
  2829. elseif (eReason == KickReason.KICK_MOD_ERROR) then
  2830. errorStr = Locale.Lookup( "LOC_GAME_ABANDONED_MOD_ERROR" );
  2831. end
  2832.  
  2833. local pPopupDialog :table = PopupDialog:new("PlayerKicked");
  2834. pPopupDialog:AddText(errorStr);
  2835. pPopupDialog:AddButton(exitStr,
  2836. function()
  2837. Events.ExitToMainMenu();
  2838. end);
  2839. pPopupDialog:Open();
  2840. end
  2841. end
  2842.  
  2843. -- ===========================================================================
  2844. -- LUA Event
  2845. -- ===========================================================================
  2846. function OnTutorial_ConstrainMovement( plotID:number )
  2847. m_constrainToPlotID = plotID;
  2848. end
  2849.  
  2850. -- ===========================================================================
  2851. -- LUA Event
  2852. -- Effectively turns on/off ability to drag pan the map.
  2853. -- ===========================================================================
  2854. function OnTutorial_DisableMapDrag( isDisabled:boolean )
  2855. m_isMapDragDisabled = isDisabled;
  2856. end
  2857.  
  2858. -- ===========================================================================
  2859. -- LUA Event
  2860. -- Turns off canceling an event via a cancel action
  2861. -- (e.g., right click for district placement)
  2862. -- ===========================================================================
  2863. function OnTutorial_DisableMapCancel( isDisabled:boolean )
  2864. m_isCancelDisabled = isDisabled;
  2865. end
  2866.  
  2867. -- ===========================================================================
  2868. -- LUA Event
  2869. -- Effectively turns on/off ability to deselect unit.
  2870. -- exceptionHexIds (optional) a list of hex Ids that are still permitted to
  2871. -- be selected even in this state.
  2872. -- ===========================================================================
  2873. function OnTutorial_DisableMapSelect( isDisabled:boolean, kExceptionHexIds:table )
  2874. if isDisabled then
  2875. -- Set to either an empty table or the table of exception Ids if one was passed in.
  2876. m_kTutorialPermittedHexes = (kExceptionHexIds ~= nil) and kExceptionHexIds or {};
  2877. else
  2878. m_kTutorialPermittedHexes = nil; -- Disabling
  2879. end
  2880. end
  2881.  
  2882. -- ===========================================================================
  2883. -- TEST
  2884. -- ===========================================================================
  2885. function Test()
  2886. if (UI.GetHeadSelectedUnit() == nil) then
  2887. print("Need head unit!");
  2888. return false;
  2889. end
  2890. local kUnit :table = UI.GetHeadSelectedUnit();
  2891. -- local startPlotId :table = Map.GetPlot(sx, sy);
  2892. -- local endPlotId :number = UI.GetCursorPlotID();
  2893.  
  2894. local plots:table = UnitManager.GetReachableZonesOfControl( kUnit );
  2895. if plots == nil then
  2896. print("NIL plots return");
  2897. else
  2898. for k,v in pairs(plots) do
  2899. print("LENSTest Plot: " .. tostring(k) .. " = " .. tostring(v) );
  2900. end
  2901. end
  2902. return true;
  2903. end
  2904.  
  2905.  
  2906. -- ===========================================================================
  2907. -- Related to edge-panning.
  2908. -- ===========================================================================
  2909. function OnMouseBeginPanLeft()
  2910. if IsAbleToEdgePan() then
  2911. m_edgePanX = -PAN_SPEED;
  2912. ProcessPan(m_edgePanX,m_edgePanY);
  2913. end
  2914. end
  2915. function OnMouseStopPanLeft()
  2916. if not ( m_edgePanX == 0.0 ) then
  2917. m_edgePanX = 0.0;
  2918. ProcessPan(m_edgePanX,m_edgePanY);
  2919. end
  2920. end
  2921. function OnMouseBeginPanRight()
  2922. if IsAbleToEdgePan() then
  2923. m_edgePanX = PAN_SPEED;
  2924. ProcessPan(m_edgePanX,m_edgePanY);
  2925. end
  2926. end
  2927. function OnMouseStopPanRight()
  2928. if not ( m_edgePanX == 0.0 ) then
  2929. m_edgePanX = 0;
  2930. ProcessPan(m_edgePanX,m_edgePanY);
  2931. end
  2932. end
  2933. function OnMouseBeginPanUp()
  2934. if IsAbleToEdgePan() then
  2935. m_edgePanY = PAN_SPEED;
  2936. ProcessPan(m_edgePanX,m_edgePanY);
  2937. end
  2938. end
  2939. function OnMouseStopPanUp()
  2940. if not ( m_edgePanY == 0.0 ) then
  2941. m_edgePanY = 0;
  2942. ProcessPan(m_edgePanX,m_edgePanY);
  2943. end
  2944. end
  2945. function OnMouseBeginPanDown()
  2946. if IsAbleToEdgePan() then
  2947. m_edgePanY = -PAN_SPEED;
  2948. ProcessPan(m_edgePanX,m_edgePanY);
  2949. end
  2950. end
  2951. function OnMouseStopPanDown()
  2952. if not ( m_edgePanY == 0.0 ) then
  2953. m_edgePanY = 0;
  2954. ProcessPan(m_edgePanX,m_edgePanY);
  2955. end
  2956. end
  2957.  
  2958.  
  2959. -- ===========================================================================
  2960. -- UI Event
  2961. -- Input Event Processing
  2962. -- ===========================================================================
  2963. function OnInputHandler( pInputStruct:table )
  2964.  
  2965. local uiMsg :number = pInputStruct:GetMessageType();
  2966. local mode :number = UI.GetInterfaceMode();
  2967.  
  2968. if uiMsg == MouseEvents.PointerLeave then
  2969. ClearAllCachedInputState();
  2970. ProcessPan(0,0);
  2971. return;
  2972. end
  2973.  
  2974.  
  2975. -- DEBUG: T for Test (remove eventually; or at least comment out)
  2976. --if pInputStruct:GetKey() == Keys.T and pInputStruct:IsControlDown() and pInputStruct:IsShiftDown() then
  2977. if pInputStruct:GetKey() == Keys.T and pInputStruct:IsAltDown() and pInputStruct:IsControlDown() then
  2978. return Test(); --??TRON
  2979. end
  2980.  
  2981. -- Set internal represenation of inputs.
  2982. m_isMouseButtonLDown = pInputStruct:IsLButtonDown();
  2983. m_isMouseButtonRDown = pInputStruct:IsRButtonDown();
  2984. m_isMouseButtonMDown = pInputStruct:IsMButtonDown();
  2985.  
  2986. -- Prevent "sticky" button down issues where a mouse release occurs else-where in UI so this context is unaware.
  2987. m_isMouseDownInWorld = m_isMouseButtonLDown or m_isMouseButtonRDown or m_isMouseButtonMDown;
  2988.  
  2989. -- TODO: Below is test showing endPlot is not updating fast enough via event system
  2990. -- (even with ImmediatePublish) and a direct/alternative way into the pathfinder
  2991. -- needs to be added. Remove once new update paradigm is added. --??TRON debug:
  2992. --local endPlotId :number = UI.GetCursorPlotID();
  2993. --print("endPlotId, ",endPlotId,uiMsg);
  2994.  
  2995. -- Only except touch "up" or "move", if a mouse "down" occurred in the world.
  2996. if m_isTouchEnabled then
  2997. m_touchCount = TouchManager:GetTouchPointCount();
  2998.  
  2999. -- Show touch ID in squares
  3000. if m_isDebuging then
  3001. local kTouchIds:table = {};
  3002. if m_touchCount > 0 then
  3003. Controls.a1:SetToBeginning();
  3004. Controls.a1:Play();
  3005. local index:number = next(m_kTouchesDownInWorld,nil);
  3006. table.insert(kTouchIds, index);
  3007. if m_touchCount > 1 then
  3008. Controls.a2:SetToBeginning();
  3009. Controls.a2:Play();
  3010. index = next(m_kTouchesDownInWorld,index);
  3011. table.insert(kTouchIds, index);
  3012. if m_touchCount > 2 then
  3013. Controls.a3:SetToBeginning();
  3014. Controls.a3:Play();
  3015. index = next(m_kTouchesDownInWorld,index);
  3016. table.insert(kTouchIds, index);
  3017. end
  3018. end
  3019. end
  3020. table.sort(kTouchIds);
  3021. if m_touchCount > 0 then Controls.t1:SetText(tostring(kTouchIds[1])); end
  3022. if m_touchCount > 1 then Controls.t2:SetText(tostring(kTouchIds[2])); end
  3023. if m_touchCount > 2 then Controls.t3:SetText(tostring(kTouchIds[3])); end
  3024. end
  3025.  
  3026. if uiMsg == MouseEvents.PointerUpdate then
  3027. if m_kTouchesDownInWorld[ pInputStruct:GetTouchID() ] == nil then
  3028. return false; -- Touch "down" did not occur in this context; ignore related touch sequence input.
  3029. end
  3030. elseif uiMsg == MouseEvents.PointerUp then
  3031. -- Stop plot tool tippin' if more or less than 2 digits
  3032. if m_touchCount < 2 then
  3033. LuaEvents.WorldInput_TouchPlotTooltipHide();
  3034. end
  3035. if m_kTouchesDownInWorld[ pInputStruct:GetTouchID() ] == nil then
  3036. return false; -- Touch "down" did not occur in this context; ignore related touch sequence input.
  3037. end
  3038. m_kTouchesDownInWorld[ pInputStruct:GetTouchID() ] = nil;
  3039. elseif uiMsg == MouseEvents.PointerDown then
  3040. m_kTouchesDownInWorld[ pInputStruct:GetTouchID() ] = true;
  3041. -- If the 2nd touch occurs in the world (first one doesn't) then use it
  3042. -- like a mouse for plot tool tips.
  3043. if m_touchCount == 2 then
  3044. LuaEvents.WorldInput_TouchPlotTooltipShow( pInputStruct:GetTouchID() );
  3045. end
  3046. end
  3047. end
  3048.  
  3049. local isHandled:boolean = false;
  3050.  
  3051. -- Get the handler for the mode
  3052. local modeHandler = InterfaceModeMessageHandler[mode];
  3053.  
  3054. -- Is it valid and is able to handle this message?
  3055. if modeHandler and modeHandler[uiMsg] then
  3056. isHandled = modeHandler[uiMsg]( pInputStruct );
  3057. elseif DefaultMessageHandler[uiMsg] then
  3058. isHandled = DefaultMessageHandler[uiMsg]( pInputStruct );
  3059. end
  3060.  
  3061. -- Do this after the handler has completed as it may be making decisions based on if mouse dragging occurred.
  3062. if not m_isMouseDownInWorld and m_isMouseDragging then
  3063. --print("Forced mouse dragging false!");
  3064. m_isMouseDragging = false; -- No mouse down, no dragging is occuring!
  3065. end
  3066.  
  3067.  
  3068. return isHandled;
  3069. end
  3070.  
  3071.  
  3072. -- ===========================================================================
  3073. -- UI Event
  3074. -- Per-frame (e.g., expensive) event.
  3075. -- ===========================================================================
  3076. function OnRefresh()
  3077. -- If there is a panning delta, and screen can pan, do the pan and request
  3078. -- this is refreshed again.
  3079. --if (m_edgePanX ~= 0 or m_edgePanY ~= 0) and IsAbleToEdgePan() then
  3080. -- RealizePan();
  3081. -- ContextPtr:RequestRefresh()
  3082. --end
  3083. end
  3084.  
  3085.  
  3086. -- ===========================================================================
  3087. --
  3088. -- ===========================================================================
  3089. function ClearAllCachedInputState()
  3090. m_isALTDown = false;
  3091. m_isUPpressed = false;
  3092. m_isDOWNpressed = false;
  3093. m_isLEFTpressed = false;
  3094. m_isRIGHTpressed = false;
  3095.  
  3096. m_isDoubleTapping = false;
  3097. m_isMouseDownInWorld= false;
  3098. m_isMouseButtonLDown= false;
  3099. m_isMouseButtonMDown= false;
  3100. m_isMouseButtonRDown= false;
  3101. m_isMouseDragging = false;
  3102. m_isTouchDragging = false;
  3103. m_isTouchZooming = false;
  3104. m_isTouchPathing = false;
  3105. m_mapZoomStart = 0;
  3106. m_dragStartFocusWorldX = 0;
  3107. m_dragStartFocusWorldY = 0;
  3108. m_dragStartWorldX = 0;
  3109. m_dragStartWorldY = 0;
  3110. m_dragStartX = 0;
  3111. m_dragStartY = 0;
  3112. m_dragX = 0;
  3113. m_dragY = 0;
  3114. m_edgePanX = 0.0;
  3115. m_edgePanY = 0.0;
  3116. m_touchTotalNum = 0;
  3117. m_touchStartPlotX = -1;
  3118. m_touchStartPlotY = -1;
  3119. ms_bGridOn = true;
  3120. end
  3121.  
  3122.  
  3123. -- ===========================================================================
  3124. -- UI Event
  3125. -- Called whenever the application regains focus.
  3126. -- ===========================================================================
  3127. function OnAppRegainedFocusHandler()
  3128. ClearAllCachedInputState();
  3129. ProcessPan(m_edgePanX,m_edgePanY);
  3130. end
  3131.  
  3132.  
  3133. -- ===========================================================================
  3134. -- UI Event
  3135. -- Called whenever the application loses focus.
  3136. -- ===========================================================================
  3137. function OnAppLostFocusHandler()
  3138. ClearAllCachedInputState();
  3139. ProcessPan(0,0);
  3140. end
  3141.  
  3142.  
  3143. -- ===========================================================================
  3144. -- UI Event
  3145. -- ===========================================================================
  3146. function OnShutdown()
  3147. -- Clean up events
  3148. Events.CycleUnitSelectionRequest.Remove( OnCycleUnitSelectionRequest );
  3149. Events.InterfaceModeChanged.Remove( OnInterfaceModeChanged );
  3150.  
  3151. LuaEvents.Tutorial_ConstrainMovement.Remove( OnTutorial_ConstrainMovement );
  3152. LuaEvents.Tutorial_DisableMapDrag.Remove( OnTutorial_DisableMapDrag );
  3153. LuaEvents.Tutorial_DisableMapSelect.Remove( OnTutorial_DisableMapSelect );
  3154. end
  3155.  
  3156. -- ===========================================================================
  3157. -- Hotkey Event
  3158. -- ===========================================================================
  3159. function OnInputActionTriggered( actionId )
  3160. if actionId == m_actionHotkeyToggleGrid then
  3161. -- TODO: query if already on (or will get out of sync with button presses!)
  3162. ms_bGridOn = not ms_bGridOn;
  3163. UI.ToggleGrid( ms_bGridOn );
  3164. end
  3165.  
  3166. if actionId == m_actionHotkeyOnlinePause then
  3167. if GameConfiguration.IsNetworkMultiplayer() then
  3168. TogglePause();
  3169. end
  3170. end
  3171. end
  3172.  
  3173. -- ===========================================================================
  3174. -- INCLUDES
  3175. -- Other handlers & helpers that may utilze functionality defined in here
  3176. -- ===========================================================================
  3177.  
  3178. include ("StrategicView_MapPlacement"); -- handlers for: BUILDING_PLACEMENT, DISTRICT_PLACEMENT
  3179. include ("StrategicView_DebugSupport"); -- the Debug interface mode
  3180.  
  3181.  
  3182. -- ===========================================================================
  3183. -- Assign callbacks
  3184. -- ===========================================================================
  3185. function Initialize()
  3186.  
  3187. m_isTouchEnabled = Options.GetAppOption("UI", "IsTouchScreenEnabled") ~= 0;
  3188.  
  3189. -- Input assignments.
  3190.  
  3191. -- Default handlers:
  3192. DefaultMessageHandler[KeyEvents.KeyDown] = OnDefaultKeyDown;
  3193. DefaultMessageHandler[KeyEvents.KeyUp] = OnDefaultKeyUp;
  3194. DefaultMessageHandler[MouseEvents.LButtonDown] = OnMouseStart;
  3195. DefaultMessageHandler[MouseEvents.LButtonUp] = OnMouseEnd;
  3196. DefaultMessageHandler[MouseEvents.MouseMove] = OnMouseMove;
  3197. DefaultMessageHandler[MouseEvents.RButtonUp] = OnDefaultChangeToSelectionMode;
  3198. DefaultMessageHandler[MouseEvents.PointerUp] = OnDefaultChangeToSelectionMode;
  3199. DefaultMessageHandler[MouseEvents.MouseWheel] = OnMouseWheelZoom;
  3200.  
  3201. -- Interface Mode ENTERING :
  3202. InterfaceModeMessageHandler[InterfaceModeTypes.AIR_ATTACK] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_Air_Attack;
  3203. InterfaceModeMessageHandler[InterfaceModeTypes.DEBUG] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_Debug;
  3204. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_MANAGEMENT] [INTERFACEMODE_ENTER] = OnInterfaceModeEnter_CityManagement;
  3205. InterfaceModeMessageHandler[InterfaceModeTypes.WMD_STRIKE] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_WMD_Strike;
  3206. InterfaceModeMessageHandler[InterfaceModeTypes.ICBM_STRIKE] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_ICBM_Strike;
  3207. InterfaceModeMessageHandler[InterfaceModeTypes.COASTAL_RAID] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_CoastalRaid;
  3208. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [INTERFACEMODE_ENTER] = OnInterfaceModeEnter_BuildingPlacement; -- StrategicView_MapPlacement.lua
  3209. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_RANGE_ATTACK] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_CityRangeAttack;
  3210. InterfaceModeMessageHandler[InterfaceModeTypes.DEPLOY] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_Deploy;
  3211. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [INTERFACEMODE_ENTER] = OnInterfaceModeEnter_DistrictPlacement; -- StrategicView_MapPlacement.lua
  3212. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_RANGE_ATTACK][INTERFACEMODE_ENTER] = OnInterfaceModeChange_DistrictRangeAttack;
  3213. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_ARMY] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_UnitFormArmy;
  3214. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_CORPS] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_UnitFormCorps;
  3215. InterfaceModeMessageHandler[InterfaceModeTypes.AIRLIFT] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_UnitAirlift;
  3216. InterfaceModeMessageHandler[InterfaceModeTypes.MAKE_TRADE_ROUTE] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_MakeTradeRoute;
  3217. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_TeleportToCity;
  3218. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_MoveTo;
  3219. InterfaceModeMessageHandler[InterfaceModeTypes.RANGE_ATTACK] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_UnitRangeAttack;
  3220. InterfaceModeMessageHandler[InterfaceModeTypes.REBASE] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_ReBase;
  3221. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_Selection;
  3222. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_MoveTo;
  3223. InterfaceModeMessageHandler[InterfaceModeTypes.PLACE_MAP_PIN] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_PlaceMapPin;
  3224. InterfaceModeMessageHandler[InterfaceModeTypes.WB_SELECT_PLOT] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_WBSelectPlot;
  3225. InterfaceModeMessageHandler[InterfaceModeTypes.SPY_CHOOSE_MISSION] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_SpyChooseMission;
  3226. InterfaceModeMessageHandler[InterfaceModeTypes.SPY_TRAVEL_TO_CITY] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_SpyTravelToCity;
  3227. InterfaceModeMessageHandler[InterfaceModeTypes.NATURAL_WONDER] [INTERFACEMODE_ENTER] = OnInterfaceModeChange_NaturalWonder;
  3228.  
  3229. -- Interface Mode LEAVING (optional):
  3230. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_BuildingPlacement; -- StrategicView_MapPlacement.lua
  3231. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_MANAGEMENT] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_CityManagement;
  3232. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_DistrictPlacement; -- StrategicView_MapPlacement.lua
  3233. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [INTERFACEMODE_LEAVE] = OnInterfaceModeChange_MoveToLeave;
  3234. InterfaceModeMessageHandler[InterfaceModeTypes.RANGE_ATTACK] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_UnitRangeAttack;
  3235. InterfaceModeMessageHandler[InterfaceModeTypes.NATURAL_WONDER] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_NaturalWonder;
  3236. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_RANGE_ATTACK] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_CityRangeAttack;
  3237. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_RANGE_ATTACK] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_DistrictRangeAttack;
  3238. InterfaceModeMessageHandler[InterfaceModeTypes.WMD_STRIKE] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_WMDRangeAttack;
  3239. InterfaceModeMessageHandler[InterfaceModeTypes.ICBM_STRIKE] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_WMDRangeAttack;
  3240. InterfaceModeMessageHandler[InterfaceModeTypes.AIR_ATTACK] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_Air_Attack;
  3241. InterfaceModeMessageHandler[InterfaceModeTypes.WMD_STRIKE] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_WMD_Strike;
  3242. InterfaceModeMessageHandler[InterfaceModeTypes.ICBM_STRIKE] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_ICBM_Strike;
  3243. InterfaceModeMessageHandler[InterfaceModeTypes.COASTAL_RAID] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_CoastalRaid;
  3244. InterfaceModeMessageHandler[InterfaceModeTypes.DEPLOY] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_Deploy;
  3245. InterfaceModeMessageHandler[InterfaceModeTypes.REBASE] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_ReBase;
  3246. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_TeleportToCity;
  3247. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_CORPS] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_UnitFormCorps;
  3248. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_ARMY] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_UnitFormArmy;
  3249. InterfaceModeMessageHandler[InterfaceModeTypes.AIRLIFT] [INTERFACEMODE_LEAVE] = OnInterfaceModeLeave_UnitAirlift;
  3250.  
  3251. -- Keyboard Events (all happen on up!)
  3252. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [KeyEvents.KeyUp] = OnPlacementKeyUp;
  3253. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [KeyEvents.KeyUp] = OnPlacementKeyUp;
  3254.  
  3255.  
  3256. -- Mouse Events
  3257. InterfaceModeMessageHandler[InterfaceModeTypes.DEBUG] [MouseEvents.LButtonUp] = OnMouseDebugEnd;
  3258. InterfaceModeMessageHandler[InterfaceModeTypes.DEBUG] [MouseEvents.RButtonUp] = OnDebugCancelPlacement;
  3259. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.LButtonUp] = OnMouseSelectionEnd;
  3260. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.RButtonDown] = OnMouseSelectionUnitMoveStart;
  3261. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.RButtonUp] = OnMouseSelectionUnitMoveEnd;
  3262. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.MButtonDown] = OnMouseSelectionSnapToPlot;
  3263. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.MouseMove] = OnMouseSelectionMove;
  3264. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.LButtonDoubleClick] = OnSelectionDoubleTap;
  3265. InterfaceModeMessageHandler[InterfaceModeTypes.VIEW_MODAL_LENS] [MouseEvents.LButtonUp] = OnMouseSelectionEnd;
  3266. InterfaceModeMessageHandler[InterfaceModeTypes.MAKE_TRADE_ROUTE] [MouseEvents.LButtonUp] = OnMouseMakeTradeRouteEnd;
  3267. InterfaceModeMessageHandler[InterfaceModeTypes.MAKE_TRADE_ROUTE] [MouseEvents.MButtonDown] = OnMouseMakeTradeRouteSnapToPlot;
  3268. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [MouseEvents.LButtonUp] = OnMouseTeleportToCityEnd;
  3269. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [MouseEvents.MButtonDown] = OnMouseTeleportToCitySnapToPlot;
  3270. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [MouseEvents.LButtonUp] = OnMouseDistrictPlacementEnd;
  3271. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [MouseEvents.RButtonUp] = OnMouseDistrictPlacementCancel;
  3272. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [MouseEvents.MouseMove] = OnMouseDistrictPlacementMove;
  3273. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.LButtonDown] = OnMouseMoveToStart;
  3274. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.LButtonUp] = OnMouseMoveToEnd;
  3275. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.MouseMove] = OnMouseMoveToUpdate;
  3276. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.RButtonUp] = OnMouseMoveToCancel;
  3277. InterfaceModeMessageHandler[InterfaceModeTypes.RANGE_ATTACK] [MouseEvents.LButtonUp] = OnMouseUnitRangeAttack;
  3278. InterfaceModeMessageHandler[InterfaceModeTypes.RANGE_ATTACK] [MouseEvents.MouseMove] = OnMouseMoveRangeAttack;
  3279. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_RANGE_ATTACK][MouseEvents.MouseMove] = OnMouseMoveRangeAttack;
  3280. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_RANGE_ATTACK][MouseEvents.LButtonUp] = DistrictRangeAttack;
  3281. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [MouseEvents.LButtonUp] = OnMouseBuildingPlacementEnd;
  3282. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [MouseEvents.RButtonUp] = OnMouseBuildingPlacementCancel;
  3283. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [MouseEvents.MouseMove] = OnMouseBuildingPlacementMove;
  3284. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_RANGE_ATTACK] [MouseEvents.LButtonUp] = CityRangeAttack;
  3285. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_RANGE_ATTACK] [MouseEvents.MouseMove] = OnMouseMoveRangeAttack;
  3286. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_CORPS] [MouseEvents.LButtonUp] = FormCorps;
  3287. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_ARMY] [MouseEvents.LButtonUp] = FormArmy;
  3288. InterfaceModeMessageHandler[InterfaceModeTypes.AIRLIFT] [MouseEvents.LButtonUp] = OnMouseAirliftEnd;
  3289. InterfaceModeMessageHandler[InterfaceModeTypes.AIR_ATTACK] [MouseEvents.LButtonUp] = UnitAirAttack;
  3290. InterfaceModeMessageHandler[InterfaceModeTypes.WMD_STRIKE] [MouseEvents.LButtonUp] = OnWMDStrikeEnd;
  3291. InterfaceModeMessageHandler[InterfaceModeTypes.WMD_STRIKE] [MouseEvents.MouseMove] = OnMouseMoveRangeAttack;
  3292. InterfaceModeMessageHandler[InterfaceModeTypes.ICBM_STRIKE] [MouseEvents.LButtonUp] = OnICBMStrikeEnd;
  3293. InterfaceModeMessageHandler[InterfaceModeTypes.ICBM_STRIKE] [MouseEvents.MouseMove] = OnMouseMoveRangeAttack;
  3294. InterfaceModeMessageHandler[InterfaceModeTypes.DEPLOY] [MouseEvents.LButtonUp] = OnMouseDeployEnd;
  3295. InterfaceModeMessageHandler[InterfaceModeTypes.REBASE] [MouseEvents.LButtonUp] = OnMouseRebaseEnd;
  3296. InterfaceModeMessageHandler[InterfaceModeTypes.COASTAL_RAID] [MouseEvents.LButtonUp] = CoastalRaid;
  3297. InterfaceModeMessageHandler[InterfaceModeTypes.PLACE_MAP_PIN] [MouseEvents.LButtonUp] = PlaceMapPin;
  3298. InterfaceModeMessageHandler[InterfaceModeTypes.WB_SELECT_PLOT] [MouseEvents.LButtonUp] = OnMouseEnd_WBSelectPlot;
  3299. InterfaceModeMessageHandler[InterfaceModeTypes.WB_SELECT_PLOT] [MouseEvents.RButtonUp] = OnRButtonUp_WBSelectPlot;
  3300. InterfaceModeMessageHandler[InterfaceModeTypes.WB_SELECT_PLOT] [MouseEvents.MouseMove] = OnMouseMove_WBSelectPlot;
  3301.  
  3302. -- Touch Events (if a touch system)
  3303. if m_isTouchEnabled then
  3304. InterfaceModeMessageHandler[InterfaceModeTypes.DEBUG] [MouseEvents.PointerUp] = DebugPlacement;
  3305. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.PointerDown] = OnTouchSelectionStart;
  3306. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.PointerUpdate] = OnTouchSelectionUpdate;
  3307. InterfaceModeMessageHandler[InterfaceModeTypes.SELECTION] [MouseEvents.PointerUp] = OnTouchSelectionEnd;
  3308. InterfaceModeMessageHandler[InterfaceModeTypes.MAKE_TRADE_ROUTE] [MouseEvents.PointerDown] = OnTouchStart;
  3309. InterfaceModeMessageHandler[InterfaceModeTypes.MAKE_TRADE_ROUTE] [MouseEvents.PointerUpdate] = OnTouchUpdate;
  3310. InterfaceModeMessageHandler[InterfaceModeTypes.MAKE_TRADE_ROUTE] [MouseEvents.PointerUp] = OnTouchTradeRouteEnd;
  3311. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [MouseEvents.PointerDown] = OnTouchStart;
  3312. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [MouseEvents.PointerUpdate] = OnTouchUpdate;
  3313. InterfaceModeMessageHandler[InterfaceModeTypes.TELEPORT_TO_CITY] [MouseEvents.PointerUp] = OnTouchTeleportToCityEnd;
  3314. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [MouseEvents.PointerDown] = OnTouchStart;
  3315. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [MouseEvents.PointerUpdate] = OnTouchUpdate;
  3316. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_PLACEMENT] [MouseEvents.PointerUp] = OnTouchDistrictPlacementEnd;
  3317. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.PointerDown] = OnTouchMoveToStart;
  3318. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.PointerUpdate] = OnTouchMoveToUpdate;
  3319. InterfaceModeMessageHandler[InterfaceModeTypes.MOVE_TO] [MouseEvents.PointerUp] = OnTouchMoveToEnd;
  3320. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [MouseEvents.PointerDown] = OnTouchStart;
  3321. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [MouseEvents.PointerUpdate] = OnTouchUpdate;
  3322. InterfaceModeMessageHandler[InterfaceModeTypes.BUILDING_PLACEMENT] [MouseEvents.PointerUp] = OnTouchBuildingPlacementEnd;
  3323. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_RANGE_ATTACK] [MouseEvents.PointerUp] = CityRangeAttack;
  3324. InterfaceModeMessageHandler[InterfaceModeTypes.DISTRICT_RANGE_ATTACK][MouseEvents.PointerUp] = DistrictRangeAttack;
  3325. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_ARMY] [MouseEvents.PointerUp] = FormArmy;
  3326. InterfaceModeMessageHandler[InterfaceModeTypes.FORM_CORPS] [MouseEvents.PointerUp] = FormCorps;
  3327. InterfaceModeMessageHandler[InterfaceModeTypes.AIRLIFT] [MouseEvents.PointerUp] = Airlift;
  3328. InterfaceModeMessageHandler[InterfaceModeTypes.RANGE_ATTACK] [MouseEvents.PointerUp] = UnitRangeAttack;
  3329. InterfaceModeMessageHandler[InterfaceModeTypes.AIR_ATTACK] [MouseEvents.PointerUp] = UnitAirAttack;
  3330. InterfaceModeMessageHandler[InterfaceModeTypes.WMD_STRIKE] [MouseEvents.PointerUp] = OnWMDStrikeEnd;
  3331. InterfaceModeMessageHandler[InterfaceModeTypes.ICBM_STRIKE] [MouseEvents.PointerUp] = OnICBMStrikeEnd;
  3332. InterfaceModeMessageHandler[InterfaceModeTypes.DEPLOY] [MouseEvents.PointerUp] = AirUnitDeploy;
  3333. InterfaceModeMessageHandler[InterfaceModeTypes.REBASE] [MouseEvents.PointerUp] = AirUnitReBase;
  3334. InterfaceModeMessageHandler[InterfaceModeTypes.COASTAL_RAID] [MouseEvents.PointerUp] = CoastalRaid;
  3335. InterfaceModeMessageHandler[InterfaceModeTypes.PLACE_MAP_PIN] [MouseEvents.PointerUp] = PlaceMapPin;
  3336. InterfaceModeMessageHandler[InterfaceModeTypes.CITY_MANAGEMENT] [MouseEvents.PointerUp] = OnDoNothing;
  3337. end
  3338.  
  3339.  
  3340. -- ===== EVENTS =====
  3341.  
  3342. -- Game Engine Events
  3343. Events.CityMadePurchase.Add( OnCityMadePurchase_StrategicView_MapPlacement );
  3344. Events.CycleUnitSelectionRequest.Add( OnCycleUnitSelectionRequest );
  3345. Events.InputActionTriggered.Add( OnInputActionTriggered );
  3346. Events.InterfaceModeChanged.Add(OnInterfaceModeChanged);
  3347. Events.MultiplayerGameLastPlayer.Add(OnMultiplayerGameLastPlayer);
  3348. Events.MultiplayerGameAbandoned.Add(OnMultiplayerGameAbandoned);
  3349.  
  3350. -- LUA Events
  3351. LuaEvents.Tutorial_ConstrainMovement.Add( OnTutorial_ConstrainMovement );
  3352. LuaEvents.Tutorial_DisableMapDrag.Add( OnTutorial_DisableMapDrag );
  3353. LuaEvents.Tutorial_DisableMapSelect.Add( OnTutorial_DisableMapSelect );
  3354. LuaEvents.Tutorial_DisableMapCancel.Add( OnTutorial_DisableMapCancel );
  3355.  
  3356. LuaEvents.Tutorial_AddUnitHexRestriction.Add( OnTutorial_AddUnitHexRestriction );
  3357. LuaEvents.Tutorial_RemoveUnitHexRestriction.Add( OnTutorial_RemoveUnitHexRestriction );
  3358. LuaEvents.Tutorial_ClearAllHexMoveRestrictions.Add( OnTutorial_ClearAllUnitHexRestrictions );
  3359.  
  3360. LuaEvents.Tutorial_AddUnitMoveRestriction.Add( OnTutorial_AddUnitMoveRestriction );
  3361. LuaEvents.Tutorial_RemoveUnitMoveRestrictions.Add( OnTutorial_RemoveUnitMoveRestrictions );
  3362.  
  3363.  
  3364. -- UI Events
  3365. Controls.LeftScreenEdge:RegisterMouseEnterCallback( OnMouseBeginPanLeft );
  3366. Controls.LeftScreenEdge:RegisterMouseExitCallback( OnMouseStopPanLeft );
  3367. Controls.RightScreenEdge:RegisterMouseEnterCallback( OnMouseBeginPanRight );
  3368. Controls.RightScreenEdge:RegisterMouseExitCallback( OnMouseStopPanRight );
  3369. Controls.TopScreenEdge:RegisterMouseEnterCallback( OnMouseBeginPanUp );
  3370. Controls.TopScreenEdge:RegisterMouseExitCallback( OnMouseStopPanUp );
  3371. Controls.BottomScreenEdge:RegisterMouseEnterCallback( OnMouseBeginPanDown );
  3372. Controls.BottomScreenEdge:RegisterMouseExitCallback( OnMouseStopPanDown );
  3373. ContextPtr:SetInputHandler( OnInputHandler, true );
  3374. ContextPtr:SetRefreshHandler( OnRefresh );
  3375. ContextPtr:SetAppRegainedFocusHandler( OnAppRegainedFocusHandler );
  3376. ContextPtr:SetAppLostFocusHandler( OnAppLostFocusHandler );
  3377. ContextPtr:SetShutdown( OnShutdown );
  3378.  
  3379. Controls.DebugStuff:SetHide(not m_isDebuging);
  3380. -- Popup setup
  3381. m_kConfirmWarDialog = PopupDialog:new( "ConfirmWarPopup" );
  3382. end
  3383. Initialize();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement