globals
integer udg_FSW_Index = -1
integer array udg_FSW_Array_LocationX
integer array udg_FSW_Array_LocationY
integer array udg_FSW_Array_LocationCenterX
integer array udg_FSW_Array_LocationCenterY
integer array udg_FSW_Array_SizeX
integer array udg_FSW_Array_SizeY
unit array udg_FSW_Array_DummyUnit
integer array udg_FSW_Array_TerrainType
real array udg_FSW_Array_CameraDistance
integer udg_FSW_ObjectType_Destructable = 1
integer udg_FSW_ObjectType_Texttag = 2
integer udg_FSW_ObjectType_Unit = 3
trigger array udg_FSW_Trigger_WhileOpen
integer udg_FSW_Black_Terrain = 'Oaby'
trigger udg_FSW_Trigger_TrackableClick = CreateTrigger()
trigger udg_FSW_Trigger_TrackableHover = CreateTrigger()
string udg_FSW_Trackable_Model = "AutoImport\\Models\\Custom Window\\Trackable.mdx"
hashtable udg_FSW_Hashtable = InitHashtable()
endglobals
library fswSystem
function FSW_System_SaveStandardDestructable takes integer whichFSW, destructable d returns nothing
local integer i = 20
loop
exitwhen LoadInteger(udg_FSW_Hashtable, whichFSW, i) == 0
set i = i + 2
endloop
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, udg_FSW_ObjectType_Destructable)
call SaveDestructableHandle(udg_FSW_Hashtable, whichFSW, i+1, d)
endfunction
function FSW_System_SaveStandardTexttag takes integer whichFSW, texttag t returns nothing
local integer i = 20
loop
exitwhen LoadInteger(udg_FSW_Hashtable, whichFSW, i) == 0
set i = i + 2
endloop
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, udg_FSW_ObjectType_Texttag)
call SaveTextTagHandle(udg_FSW_Hashtable, whichFSW, i+1, t)
endfunction
function FSW_System_SaveStandardUnit takes integer whichFSW, unit u returns nothing
local integer i = 20
loop
exitwhen LoadInteger(udg_FSW_Hashtable, whichFSW, i) == 0
set i = i + 2
endloop
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, udg_FSW_ObjectType_Unit)
call SaveUnitHandle(udg_FSW_Hashtable, whichFSW, i+1, u)
endfunction
function FSW_System_ShowStandardObjects takes integer whichFSW, boolean show returns nothing
local integer i = 20
local integer objectType
loop
set objectType = LoadInteger(udg_FSW_Hashtable, whichFSW, i)
exitwhen objectType == 0
if objectType == udg_FSW_ObjectType_Destructable then
call ShowDestructable(LoadDestructableHandle(udg_FSW_Hashtable, whichFSW, i+1), show)
elseif objectType == udg_FSW_ObjectType_Texttag then
call SetTextTagVisibility(LoadTextTagHandle(udg_FSW_Hashtable, whichFSW, i+1), show)
elseif objectType == udg_FSW_ObjectType_Unit then
call ShowUnit(LoadUnitHandle(udg_FSW_Hashtable, whichFSW, i+1), show)
endif
set i = i + 2
endloop
endfunction
function FSW_System_SaveTempDestructable takes integer whichFSW, integer pId, destructable d returns nothing
local integer i = 2000
loop
exitwhen i > 3000
if LoadInteger(udg_FSW_Hashtable, whichFSW, i) == 0 then
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, udg_FSW_ObjectType_Destructable)
call SaveDestructableHandle(udg_FSW_Hashtable, whichFSW, i+1, d)
call SaveInteger(udg_FSW_Hashtable, whichFSW, i+2, pId)
return
endif
set i = i + 3
endloop
endfunction
function FSW_System_SaveTempTexttag takes integer whichFSW, integer pId, texttag t returns nothing
local integer i = 2000
loop
exitwhen i > 3000
if LoadInteger(udg_FSW_Hashtable, whichFSW, i) == 0 then
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, udg_FSW_ObjectType_Texttag)
call SaveTextTagHandle(udg_FSW_Hashtable, whichFSW, i+1, t)
call SaveInteger(udg_FSW_Hashtable, whichFSW, i+2, pId)
return
endif
set i = i + 3
endloop
endfunction
function FSW_Remove_Temp_Objects takes integer whichFSW, integer pId returns nothing
local integer i = 2000
local integer objectType
loop
exitwhen i > 3000
if LoadInteger(udg_FSW_Hashtable, whichFSW, i+2) == pId then
set objectType = LoadInteger(udg_FSW_Hashtable, whichFSW, i)
if objectType == udg_FSW_ObjectType_Destructable then
call RemoveDestructable(LoadDestructableHandle(udg_FSW_Hashtable, whichFSW, i+1))
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, 0)
elseif objectType == udg_FSW_ObjectType_Texttag then
call DestroyTextTag(LoadTextTagHandle(udg_FSW_Hashtable, whichFSW, i+1))
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, 0)
elseif objectType == udg_FSW_ObjectType_Unit then
call RemoveUnit(LoadUnitHandle(udg_FSW_Hashtable, whichFSW, i+1))
call SaveInteger(udg_FSW_Hashtable, whichFSW, i, 0)
endif
endif
set i = i + 3
endloop
endfunction
function FSW_System_Create_FSW takes integer x, integer y, integer sizeX, integer sizeY, real cameraDistance returns integer
set udg_FSW_Index = udg_FSW_Index + 1
set udg_FSW_Array_LocationX[udg_FSW_Index] = x
set udg_FSW_Array_LocationY[udg_FSW_Index] = y
set udg_FSW_Array_LocationCenterX[udg_FSW_Index] = x*64 + sizeX*32
set udg_FSW_Array_LocationCenterY[udg_FSW_Index] = y*64 - sizeY*32
set udg_FSW_Array_SizeX[udg_FSW_Index] = sizeX
set udg_FSW_Array_SizeY[udg_FSW_Index] = sizeY
set udg_FSW_Array_DummyUnit[udg_FSW_Index] = CreateUnit(Player(12), udg_Dummy_Unit_Type, udg_FSW_Array_LocationCenterX[udg_FSW_Index], udg_FSW_Array_LocationCenterY[udg_FSW_Index], 0)
set udg_FSW_Array_TerrainType[udg_FSW_Index] = GetTerrainType(udg_FSW_Array_LocationCenterX[udg_FSW_Index], udg_FSW_Array_LocationCenterY[udg_FSW_Index])
set udg_FSW_Array_CameraDistance[udg_FSW_Index] = cameraDistance
return udg_FSW_Index
endfunction
function FSW_System_Create_Trackable takes integer whichFSW, integer x, integer y returns trackable
local integer fswX = udg_FSW_Array_LocationX[whichFSW]
local integer fswY = udg_FSW_Array_LocationY[whichFSW]
local trackable t
local integer id
local integer i = 0
local player p
local string s
loop
exitwhen i > 12
set p = Player(i)
if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
if GetLocalPlayer() == p then
set s = udg_FSW_Trackable_Model
else
set s = ""
endif
set t = CreateTrackable(s, (fswX+x) * 64, (fswY-y) * 64, 0)
set id = GetHandleId(t)
//Register the events for the trackable.
call TriggerRegisterTrackableHitEvent(udg_FSW_Trigger_TrackableClick, t)
call TriggerRegisterTrackableTrackEvent(udg_FSW_Trigger_TrackableHover, t)
//Save the data to the hashtable.
call SaveInteger(udg_FSW_Hashtable, id, 0, i)
call SaveInteger(udg_FSW_Hashtable, id, 1, fswX + x)
call SaveInteger(udg_FSW_Hashtable, id, 2, fswY + y)
endif
set i = i + 1
endloop
return t
endfunction
function FSW_System_Create_Destructable takes integer whichFSW, integer destId, integer x, integer y returns destructable
local real fswX = udg_FSW_Array_LocationX[whichFSW]
local real fswY = udg_FSW_Array_LocationY[whichFSW]
local destructable d = CreateDestructable(destId, (fswX+x) * 64, (fswY-y) * 64, 0, 0.7, 0)
//local destructable d = CreateDeadDestructableZ(destId, (fswX+x) * 64, (fswY-y) * 64, 250, 0, 0.7, 0)
call FSW_System_SaveStandardDestructable(whichFSW, d)
call ShowDestructable(d, false)
return d
endfunction
function FSW_System_Create_Texttag takes integer whichFSW, string text, real size, real x, real y, integer RGBA_R, integer RGBA_G, integer RGBA_B, integer RGBA_A returns texttag
local real fswX = udg_FSW_Array_LocationX[whichFSW]
local real fswY = udg_FSW_Array_LocationY[whichFSW]
local texttag t = CreateTextTag()
call SetTextTagText(t, text, size * 0.0023)
call SetTextTagPos(t, fswX*64 + x, fswY*64 - y, 0)
call SetTextTagColor(t, RGBA_R, RGBA_G, RGBA_B, RGBA_A)
call SetTextTagPermanent(t, true)
call FSW_System_SaveStandardTexttag(whichFSW, t)
call SetTextTagVisibility(t, false)
return t
endfunction
function FSW_System_Create_Unit takes integer whichFSW, integer unitType, real x, real y, player whichPlayer, real facing returns unit
local real fswX = udg_FSW_Array_LocationX[whichFSW]
local real fswY = udg_FSW_Array_LocationY[whichFSW]
local unit u = CreateUnit(whichPlayer, unitType, fswX*64 + x, fswY*64 - y, facing)
call FSW_System_SaveStandardUnit(whichFSW, u)
call ShowUnit(u, false)
return u
endfunction
function FSW_System_Create_Temp_Destructable takes integer whichFSW, player whichPlayer, integer destId, integer x, integer y returns destructable
local real fswX = udg_FSW_Array_LocationX[whichFSW]
local real fswY = udg_FSW_Array_LocationY[whichFSW]
local destructable d = CreateDestructable(destId, (fswX+x) * 64, (fswY-y) * 64, 0, 0.7, 0)
local timer Timer
//local destructable d = CreateDeadDestructableZ(destId, (fswX+x) * 64, (fswY-y) * 64, 5, 0, 0.7, 0)
call FSW_System_SaveTempDestructable(whichFSW, GetPlayerId(whichPlayer), d)
if GetLocalPlayer() == whichPlayer then
call ShowDestructable(d, true)
else
call ShowDestructable(d, false)
endif
return d
endfunction
function FSW_System_Create_Temp_Texttag takes integer whichFSW, player whichPlayer, string text, real size, real x, real y, integer RGBA_R, integer RGBA_G, integer RGBA_B, integer RGBA_A returns texttag
local real fswX = udg_FSW_Array_LocationX[whichFSW]
local real fswY = udg_FSW_Array_LocationY[whichFSW]
local texttag t = CreateTextTag()
call SetTextTagText(t, text, size * 0.0023)
call SetTextTagPos(t, fswX*64 + x, fswY*64 - y, 0)
call SetTextTagColor(t, RGBA_R, RGBA_G, RGBA_B, RGBA_A)
call SetTextTagPermanent(t, true)
call FSW_System_SaveTempTexttag(whichFSW, GetPlayerId(whichPlayer), t)
if GetLocalPlayer() == whichPlayer then
call SetTextTagVisibility(t, true)
else
call SetTextTagVisibility(t, false)
endif
return t
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Handle Functions
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FSW_System_Close_FSW takes integer whichFSW, player whichPlayer returns nothing
local integer pId = GetPlayerId(whichPlayer)
if (GetLocalPlayer() == whichPlayer) then
call ResetToGameCamera(0)
call PanCameraToTimed(GetUnitX(udg_Heroes[pId]), GetUnitY(udg_Heroes[pId]), 0)
endif
call SetTerrainType(udg_FSW_Array_LocationCenterX[udg_FSW_Index], udg_FSW_Array_LocationCenterY[udg_FSW_Index], udg_FSW_Array_TerrainType[udg_FSW_Index], -1, 8, 1)
call FSW_System_ShowStandardObjects(whichFSW, false)
call FSW_Remove_Temp_Objects(whichFSW, pId)
call SaveBoolean(udg_FSW_Hashtable, whichFSW, pId, false)
set udg_FSW_Selected_X[pId] = -1
set udg_FSW_Selected_Y[pId] = -1
set udg_FSW_Event_Window_Closed = 1
set udg_FSW_Event_Window_Closed = 0
endfunction
function FSW_System_Open_FSW takes integer whichFSW, player whichPlayer returns nothing
local integer pId = GetPlayerId(whichPlayer)
local integer i = 0
if LoadBoolean(udg_FSW_Hashtable, whichFSW, pId) then
return
endif
loop
exitwhen i > udg_FSW_Index
if LoadBoolean(udg_FSW_Hashtable, i, pId) then
call FSW_System_Close_FSW(i, whichPlayer)
exitwhen true
endif
set i = i + 1
endloop
if (GetLocalPlayer() == whichPlayer) then
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, -90, 0)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, udg_FSW_Array_CameraDistance[whichFSW], 0)
call SetCameraTargetController(udg_FSW_Array_DummyUnit[whichFSW], 0, 0, false)
call SetTerrainType(udg_FSW_Array_LocationCenterX[whichFSW], udg_FSW_Array_LocationCenterY[whichFSW], udg_FSW_Black_Terrain, -1, 8, 1)
call FSW_System_ShowStandardObjects(whichFSW, true)
call SaveBoolean(udg_FSW_Hashtable, whichFSW, pId, true)
set udg_FSW_Selected_X[pId] = -1
set udg_FSW_Selected_Y[pId] = -1
set udg_FSW_Param_Player = whichPlayer
set udg_FSW_Param_FSW = whichFSW
call TriggerExecute(udg_FSW_Trigger_WhileOpen[whichFSW])
set udg_FSW_Event_Window_Opened = 1
set udg_FSW_Event_Window_Opened = 0
endif
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Create Trackable Events
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Trackable click event.
function FSW_System_Trackable_Clicked takes nothing returns boolean
local integer id = GetHandleId(GetTriggeringTrackable())
local integer whichFSW
local integer pId = LoadInteger(udg_FSW_Hashtable, id, 0)
local integer i = 0
loop
if i > udg_FSW_Index then
return false
endif
if LoadBoolean(udg_FSW_Hashtable, i, pId) then
set whichFSW = i
exitwhen true
endif
set i = i + 1
endloop
set udg_FSW_Param_LocationX = -udg_FSW_Array_LocationX[whichFSW] + LoadInteger(udg_FSW_Hashtable, id, 1)
set udg_FSW_Param_LocationY = -udg_FSW_Array_LocationY[whichFSW] + LoadInteger(udg_FSW_Hashtable, id, 2)
set udg_FSW_Param_FSW = whichFSW
set udg_FSW_Param_Player = Player(pId)
if LoadBoolean(udg_FSW_Hashtable, whichFSW, pId) then
set udg_FSW_Event_Trackable_Clicked = 1
set udg_FSW_Event_Trackable_Clicked = 0
endif
return false
endfunction
//Trackable hover event.
function FSW_System_Trackable_Hovered takes nothing returns boolean
local integer id = GetHandleId(GetTriggeringTrackable())
local integer whichFSW
local integer pId = LoadInteger(udg_FSW_Hashtable, id, 0)
local integer i = 0
loop
if i > udg_FSW_Index then
return false
endif
if LoadBoolean(udg_FSW_Hashtable, i, pId) then
set whichFSW = i
exitwhen true
endif
set i = i + 1
endloop
set udg_FSW_Param_LocationX = -udg_FSW_Array_LocationX[whichFSW] + LoadInteger(udg_FSW_Hashtable, id, 1)
set udg_FSW_Param_LocationY = -udg_FSW_Array_LocationY[whichFSW] + LoadInteger(udg_FSW_Hashtable, id, 2)
set udg_FSW_Param_FSW = whichFSW
set udg_FSW_Param_Player = Player(pId)
if LoadBoolean(udg_FSW_Hashtable, whichFSW, pId) then
set udg_FSW_Event_Trackable_Hovered = 1
set udg_FSW_Event_Trackable_Hovered = 0
endif
return false
endfunction
function FSW_System_While_Open takes nothing returns boolean
local integer pId = 0
local player p
local integer i = 0
loop
exitwhen pId > 3
set p = Player(pId)
loop
exitwhen i > udg_FSW_Index
if LoadBoolean(udg_FSW_Hashtable, i, pId) then
call FSW_Remove_Temp_Objects(i, pId)
set udg_FSW_Param_Player = p
set udg_FSW_Param_FSW = i
call TriggerEvaluate(udg_FSW_Trigger_WhileOpen[i])
exitwhen true
endif
set i = i + 1
endloop
set pId = pId + 1
endloop
return false
endfunction
endlibrary
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Initialize variables and the system.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function InitTrig_FSW_System takes nothing returns nothing
call TimerStart(CreateTimer(), 0.05, true, function FSW_System_While_Open)
call TriggerAddCondition(udg_FSW_Trigger_TrackableClick, Filter(function FSW_System_Trackable_Clicked))
call TriggerAddCondition(udg_FSW_Trigger_TrackableHover, Filter(function FSW_System_Trackable_Hovered))
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// End of the FSW System trigger.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////