////////////////////////////////////////////////////////
//Guhun's MUI Engine version 2.0.0
////////////////////////////////////////////////////////
//This code generates an instance number for a RecycleKey
function GMUI_GetIndex takes integer RecycleKey returns integer
local integer instance
set instance = LoadInteger(udg_GMUI_Hashtable, RecycleKey, 0)
if not HaveSavedInteger(udg_GMUI_Hashtable, RecycleKey, instance) then
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, instance + 1)
else
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, LoadInteger(udg_GMUI_Hashtable, RecycleKey, instance))
call RemoveSavedInteger(udg_GMUI_Hashtable, RecycleKey, instance)
endif
return instance
endfunction
//This code generates recycles a used instance number for a RecycleKey
function GMUI_RecycleIndex takes integer RecycleKey, integer instance returns nothing
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, instance, LoadInteger(udg_GMUI_Hashtable, RecycleKey, 0))
call SaveInteger(udg_GMUI_Hashtable, RecycleKey, 0, instance)
endfunction
//This code generates a new, unused, RecycleKey
function GMUI_CreateRecycleKey takes nothing returns integer
local integer newKey = GMUI_GetIndex(0)
call SaveInteger(udg_GMUI_Hashtable, newKey, 0, 1)
return newKey
endfunction
//This code recycles a used RecycleKey
function GMUI_DestroyRecycleKey takes integer whichKey returns nothing
if whichKey == 0 then
return
endif
call GMUI_RecycleIndex(0, whichKey)
call FlushChildHashtable(udg_GMUI_Hashtable, whichKey)
endfunction
//This function initializes GMUI if it has not yet been initialized
function GMUI_Initialize takes nothing returns nothing
if udg_GMUI_Hashtable == null then
//Initialize Hashtable
set udg_GMUI_Hashtable = InitHashtable()
//Initialize the recycling algorithm for Recycle Keys
call SaveInteger(udg_GMUI_Hashtable, 0, 0, 1)
//Initialize the generic Recycle Key
call GMUI_CreateRecycleKey() //Will always be 1
endif
endfunction
////////////////////////////////////////////////////////
//End of MUI Engine
////////////////////////////////////////////////////////
Name | Type | is_array | initial_value |
GMUI_Hashtable | hashtable | No | |
GMUI_Index | integer | No | |
GMUI_RecycleKey | integer | No | |
GTS_CustomValue | integer | No | |
GTS_DestroyTimer | boolean | No | |
GTS_ExecutionCounter | integer | No | |
GTS_Hashtable | hashtable | No | |
GTS_TimeOut | real | No | |
GTS_Timer | timer | No | |
GTS_Trigger | trigger | No | |
Test_EscTimer | timer | No | |
Test_PeriodicTimer | timer | No |
////////////////////////////////////////////////////////
//Guhun's Timer System version 1.0
////////////////////////////////////////////////////////
//Hashtable adresses:
//-3: Trigger
//-2: Execution Counter
//-1: User Data
////////////////////////////////////////////////////////
function GTS_DestroyTimer takes timer t returns nothing
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(udg_GTS_Hashtable, GetHandleId(t))
endfunction
//This function executes when a timer expires, running the correct trigger while checking conditions and if it is enabled
function GTS_ExecuteTimer takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tId = GetHandleId(t)
local integer counter = LoadInteger(udg_GTS_Hashtable, tId, -2) + 1 //Increase counter
local trigger trig = LoadTriggerHandle(udg_GTS_Hashtable, tId, -3)
set udg_GTS_CustomValue = LoadInteger(udg_GTS_Hashtable, tId, -1)
set udg_GTS_ExecutionCounter = counter
if IsTriggerEnabled(trig) and TriggerEvaluate(trig) then
call TriggerExecute(trig)
endif
if udg_GTS_DestroyTimer then
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(udg_GTS_Hashtable, tId)
set udg_GTS_DestroyTimer = false //User must manually specify if timer should be destroyed
else
call SaveInteger(udg_GTS_Hashtable, tId, -2, counter)
endif
set t = null
set trig = null
endfunction
function GTS_RestartTimer takes timer t, real timeout returns nothing
call TimerStart(t, timeout, true, function GTS_ExecuteTimer)
endfunction
//Creates a new timer, starts it and stores relevant data in hashtable
function GTS_StartTimer takes timer t, real timeout, trigger whichTrigger, boolean useHandleId, integer userData returns nothing
local integer tId = GetHandleId(t)
call TimerStart(t, timeout, true, function GTS_ExecuteTimer)
if useHandleId then
call SaveInteger(udg_GTS_Hashtable, tId, -1, tId)
set udg_GTS_CustomValue = tId
else
call SaveInteger(udg_GTS_Hashtable, tId, -1, userData)
endif
call SaveTriggerHandle(udg_GTS_Hashtable, tId, -3, whichTrigger)
endfunction
//Creates a new timer and sets GTS_Timer to it, then starts the timer
function GTS_CreateTimer takes real timeout, trigger whichTrigger, boolean useHandleId, integer userData returns nothing
set udg_GTS_Timer = CreateTimer()
call GTS_StartTimer(udg_GTS_Timer, timeout, whichTrigger, useHandleId, userData)
endfunction
////////////////////////////////////////////////////////
//End of Guhun's Timer System
////////////////////////////////////////////////////////
function Trig_GTS_Main_Actions takes nothing returns nothing
if udg_GTS_TimeOut >= 0 then
call GTS_CreateTimer(udg_GTS_TimeOut, udg_GTS_Trigger, false, udg_GTS_CustomValue)
else
call GTS_DestroyTimer(udg_GTS_Timer)
set udg_GTS_Timer = null
endif
endfunction
function Trig_GTS_Main_Conditions takes nothing returns boolean
if udg_GTS_TimeOut >= 0 then
call GTS_CreateTimer(udg_GTS_TimeOut, udg_GTS_Trigger, true, 0)
else
call GTS_RestartTimer(udg_GTS_Timer, -udg_GTS_TimeOut)
endif
return false
endfunction
//===========================================================================
function InitTrig_GTS_Main takes nothing returns nothing
set gg_trg_GTS_Main = CreateTrigger()
set udg_GTS_Hashtable = InitHashtable()
call TriggerAddAction( gg_trg_GTS_Main, function Trig_GTS_Main_Actions )
call TriggerAddCondition(gg_trg_GTS_Main, Condition(function Trig_GTS_Main_Conditions))
endfunction
function Trig_GMUI_Main_Actions takes nothing returns nothing
if udg_GMUI_RecycleKey == 0 then
set udg_GMUI_RecycleKey = GMUI_CreateRecycleKey()
else
call GMUI_DestroyRecycleKey(udg_GMUI_RecycleKey)
endif
endfunction
function Trig_GMUI_Main_Conditions takes nothing returns boolean
if udg_GMUI_Index == 0 then
set udg_GMUI_Index = GMUI_GetIndex(udg_GMUI_RecycleKey)
else
call GMUI_RecycleIndex(udg_GMUI_RecycleKey, udg_GMUI_Index)
endif
return false
endfunction
//===========================================================================
function InitTrig_GMUI_Main takes nothing returns nothing
call GMUI_Initialize()
//Create Trigger for GUI users
set gg_trg_GMUI_Main = CreateTrigger( )
call TriggerAddAction( gg_trg_GMUI_Main, function Trig_GMUI_Main_Actions )
call TriggerAddCondition(gg_trg_GMUI_Main, Condition(function Trig_GMUI_Main_Conditions))
endfunction