Interface Mode to select plot

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
I should be pretty good at looking at Lua code and understanding it by now. But I'm struggling with interface modes in WorldView.lua and InGame.lua.

What I want to do is create an interface mode to select a plot. It's for a spell, so there is a casting unit and a max range. Unit casts spell and then (if active player) interface mode should happen to allow plot selection. When player selects plot, stuff happens. I can code the spell and the stuff that happens, but I need some help or example code to follow for the interface part. Can anyone help?
 
Indeed, has an answer surfaced? I find myself in a similar position, wanting to execute something akin to ranged attacking (The: 'select plot, but only continue if conditions(I.e. terrain and range) are met' section) but have had no luck on this front.

Edit: Is this what you are looking for?
Spoiler :

-- Function to provide the UI effects of selecting the Beacon improvement
function ShowBeaconSelect()
local pHeadSelectedUnit = UI.GetHeadSelectedUnit();
-- First check that the selection was valid
if not pHeadSelectedUnit then
return;
end
local thisPlot = pHeadSelectedUnit:GetPlot();
-- Here is the optimal spot for checkign that your current hex still provides you legailty for your intended action
-- An example would be the paratrooper, here you would check if you can paradrop FROM the hex you occupy.
local iRange = 1;
local thisY = pHeadSelectedUnit:GetY();
local thisX = pHeadSelectedUnit:GetX();

for iDX = -iRange, iRange, 1 do -- Set the x and y ranges
for iDY = -iRange, iRange, 1 do
local pTargetPlot = Map.GetPlotXY(thisX, thisY, iDX, iDY);
if pTargetPlot ~= nil then
local plotX = pTargetPlot:GetX();
local plotY = pTargetPlot:GetY();
local plotDistance = Map.PlotDistance(thisX, thisY, plotX, plotY);
if plotDistance <= iRanger then
-- Final check to see if the mouses hex is a viable target
--if check for mountain plot
local hexID = ToHexFromGrid( Vector2( plotX, plotY) );
-- call UI Event
Events.SerialEventHexHighlight( hexID, true, tuen1Color, pathBorderStyle );
--end
end
end
end
end
end
function HideBeaconSelect()
ClearUnitHexHightlights();
end


This is a bastardized form of the UI function for plot selection, in theory it should do what you are asking for when called by your button press. However I have not put this to the test, nor finished it actually.. It got set to the backburner as I tackled other things.

I yoinked this from the paradrop UI function.
 
Back
Top Bottom