- Joined
- Apr 24, 2012
- Messages
- 5,113
JASS:
//************************************************************************************
//*
//*
//* UNIT APPEARANCE
//*
//* by: ALMIA
//*
//*
//************************************************************************************
//*
//* Used to track unit appearance
//* This includes :
//* - Scale
//* - Alpha Vertex
//* - Red Vertex
//* - Blue Vertex
//* - Green Vertex
//*
//************************************************************************************
//*
//*
//* Before using this system, do the following:
//*
//* - Read this tutorial to implement this system:
//* http://www.hiveworkshop.com/forums/tutorial-submission-283/use-functions-other-triggers-232537-new/
//* - Create the variables written in the lowest part of the documentation
//* - All units must have 1.00 model scale
//* - All units must have 255 Red/Blue/Green Vertex Color
//*
//*
//************************************************************************************
//*
//* Requires:
//*
//* Unit Indexer
//* - http://www.hiveworkshop.com/forums/spells-569/gui-unit-indexer-1-2-0-2-a-197329
//*
//*
//************************************************************************************
//*
//* Code API
//*
//* function SetUnitVertexColorEx takes unit u, real r, real g, real b, real a returns nothing
//* - Set the units vertex color which also caches the ARGB values.
//* - ARGB must be 0 - 100 not 0 - 255(represents percentage)
//*
//* function SetUnitScaleEx takes unit u, real scale returns nothing
//* - Set the units model scale which also caches the scale value
//*
//* function SetUnitLoopingColor takes unit u, real r, real g, real b, real a, real r2, real g2, real b2, real a2, real time returns nothing
//* - Set the units vertex color from a given ARGB to a new given ARGB in between timeout
//* - ARGB must be 0 - 100 not 0 - 255(represents percentage)
//*
//* function SetUnitLoopingScale takes unit u, real scale, real scale2, real time returns nothing
//* - Set the units model scale from a given scale to a new scale in between timeout
//*
//* function SetUnitLoopingColorEx takes unit u,real r, real g, real b, real a, real time returns nothing
//* - Set the units vertex from its current ARGB to a new ARGB in between timeout
//* - ARGB must be 0 - 100 not 0 - 255(represents percentage)
//*
//* function SetUnitLoopingScaleEx takes unit u, real scale, real time returns nothing
//* - Set the units model scale from its current scale to a new scale
//*
//* function GetUnitColorRed takes unit u returns real
//* function GetUnitColorGreen takes unit u returns real
//* function GetUnitColorBlue takes unit u returns real
//* function GetUnitColorAlpha takes unit u returns real
//* function GetUnitScale takes unit u returns real
//* - Wrappers for retrieving ARGB values and scales.
//*
//************************************************************************************
//*
//* Variables
//*
//* UA_Red real array
//* UA_Green real array
//* UA_Blue real array
//* UA_Alpha real array
//* UA_Scale real array
//* UA_RSpeed real array
//* UA_GSpeed real array
//* UA_BSpeed real array
//* UA_ASpeed real array
//* UA_SSpeed real array
//* UA_ScaleTime real array
//* UA_VertexTime real array
//* UA_N integer array
//* UA_P integer array
//* UA_Timer timer
//* UA_Count integer
//* UA_Unit unit array
//*
//************************************************************************************
constant function UA_Timeout takes nothing returns real
return 0.031250000
endfunction
function UA_Normalize takes real r returns real
if r < 0 then
return 0
elseif r > 100 then
return 100
endif
endfunction
//************************************************************************************
function SetUnitVertexColorEx takes unit u, real r, real g, real b, real a returns nothing
local integer i = GetUnitUserData(u)
set r = UA_Normalize(r)
set g = UA_Normalize(g)
set b = UA_Normalize(b)
set a = UA_Normalize(a)
set udg_UA_Red[i] = r
set udg_UA_Green[i] = g
set udg_UA_Blue[i] = b
set udg_UA_Alpha[i] = a
call SetUnitVertexColor(u, R2I(r * 255 * 0.01), R2I(g * 255 * 0.01), R2I(b * 255 * 0.01), R2I(a * 255 * 0.01))
endfunction
function SetUnitScaleEx takes unit u, real scale returns nothing
local integer i = GetUnitUserData(u)
set scale = UA_Normalize(scale)
set udg_UA_Scale[i] = scale
call SetUnitScale(u, scale * 0.01, 0, 0)
endfunction
//************************************************************************************
function UA_Destroy takes integer i returns nothing
set udg_UA_N[udg_UA_P[i]] = udg_UA_N[i]
set udg_UA_P[udg_UA_N[i]] = udg_UA_P[i]
set udg_UA_Count = udg_UA_Count - 1
if 0 == udg_UA_Count then
call PauseTimer(udg_UA_Timer)
endif
endfunction
function UA_Loop takes nothing returns nothing
local integer i = udg_UA_N[0]
loop
exitwhen 0 == i
if 0 < udg_UA_ScaleTime[i] then
set udg_UA_ScaleTime[i] = udg_UA_ScaleTime[i] - UA_Timeout()
call SetUnitScaleEx(udg_UA_Unit[i], udg_UA_Scale[i] + udg_UA_SSpeed[i])
else
call UA_Destroy(i)
set udg_UA_SSpeed[i] = 0
set udg_UA_ScaleTime[i] = 0
endif
if 0 < udg_UA_VertexTime[i] then
set udg_UA_VertexTime[i] = udg_UA_VertexTime[i] - UA_Timeout()
call SetUnitVertexColorEx(udg_UA_Unit[i], udg_UA_Red[i] + udg_UA_RSpeed[i], udg_UA_Green[i] + udg_UA_GSpeed[i], udg_UA_Blue[i] + udg_UA_BSpeed[i], udg_UA_Alpha[i] + udg_UA_ASpeed[i])
else
call UA_Destroy(i)
set udg_UA_VertexTime[i] = 0
set udg_UA_RSpeed[i] = 0
set udg_UA_GSpeed[i] = 0
set udg_UA_BSpeed[i] = 0
set udg_UA_ASpeed[i] = 0
endif
set i = udg_UA_N[i]
endloop
endfunction
//************************************************************************************
function UA_Insert takes integer this returns nothing
local integer i = udg_UA_N[0]
local boolean found = false
loop
exitwhen 0 == i
if i == this then
set found = true
endif
set i = udg_UA_N[i]
endloop
if not found then
set udg_UA_N[this] = 0
set udg_UA_P[this] = 0
set udg_UA_N[udg_UA_P[0]] = this
set udg_UA_P[0] = this
set udg_UA_Count = udg_UA_Count + 1
if 1 == udg_UA_Count then
call TimerStart(udg_UA_Timer, UA_Timeout(), true, function UA_Loop)
endif
endif
endfunction
//************************************************************************************
function SetUnitLoopingColor takes unit u, real r, real g, real b, real a, real r2, real g2, real b2, real a2, real time returns nothing
local integer this = GetUnitUserData(u)
call SetUnitVertexColorEx(u, r, g, b, a)
call UA_Insert(this)
set r2 = r2 - r
set g2 = g2 - g
set b2 = b2 - b
set a2 = a2 - a
set udg_UA_Unit[this] = u
set udg_UA_VertexTime[this] = time
set udg_UA_RSpeed[this] = (r2 * time) * UA_Timeout()
set udg_UA_GSpeed[this] = (g2 * time) * UA_Timeout()
set udg_UA_BSpeed[this] = (b2 * time) * UA_Timeout()
set udg_UA_ASpeed[this] = (a2 * time) * UA_Timeout()
endfunction
function SetUnitLoopingScale takes unit u, real scale, real scale2, real time returns nothing
local integer this = GetUnitUserData(u)
call SetUnitScaleEx(u, scale)
call UA_Insert(this)
set scale2 = scale2 - scale
set udg_UA_Unit[this] = u
set udg_UA_ScaleTime[this] = time
set udg_UA_SSpeed[this] = (scale2 * time) * UA_Timeout()
endfunction
//************************************************************************************
function SetUnitLoopingColorEx takes unit u,real r, real g, real b, real a, real time returns nothing
local integer this = GetUnitUserData(u)
call UA_Insert(this)
set r = r - udg_UA_Red[this]
set g = g - udg_UA_Green[this]
set b = b - udg_UA_Blue[this]
set a = a - udg_UA_Alpha[this]
set udg_UA_Unit[this] = u
set udg_UA_VertexTime[this] = time
set udg_UA_RSpeed[this] = (r * time) * UA_Timeout()
set udg_UA_GSpeed[this] = (g * time) * UA_Timeout()
set udg_UA_BSpeed[this] = (b * time) * UA_Timeout()
set udg_UA_ASpeed[this] = (a * time) * UA_Timeout()
endfunction
function SetUnitLoopingScaleEx takes unit u, real scale, real time returns nothing
local integer this = GetUnitUserData(u)
call UA_Insert(this)
set scale = scale - udg_UA_Scale[this]
set udg_UA_Unit[this] = u
set udg_UA_ScaleTime[this] = time
set udg_UA_SSpeed[this] = (scale * time) * UA_Timeout()
endfunction
//************************************************************************************
//*
//* Get API
//*
//************************************************************************************
function GetUnitColorRed takes unit u returns real
return udg_UA_Red[GetUnitUserData(u)]
endfunction
function GetUnitColorGreen takes unit u returns real
return udg_UA_Green[GetUnitUserData(u)]
endfunction
function GetUnitColorBlue takes unit u returns real
return udg_UA_Blue[GetUnitUserData(u)]
endfunction
function GetUnitColorAlpha takes unit u returns real
return udg_UA_Alpha[GetUnitUserData(u)]
endfunction
function GetUnitScale takes unit u returns real
return udg_UA_Scale[GetUnitUserData(u)]
endfunction
//************************************************************************************
function UA_OnIndex takes nothing returns boolean
set udg_UA_Unit[udg_UDex] = udg_UDexUnits[udg_UDex]
set udg_UA_Red[udg_UDex] = 100
set udg_UA_Green[udg_UDex] = 100
set udg_UA_Blue[udg_UDex] = 100
set udg_UA_Alpha[udg_UDex] = 100
set udg_UA_Scale[udg_UDex] = 100
return false
endfunction
//************************************************************************************
function InitTrig_Unit_Appearance takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, 1.0)
call TriggerAddCondition(t, Filter(function UA_OnIndex))
set t = null
endfunction
Attachments
Last edited: