library DGUI requires Math, Camera
globals
private constant integer TypeUnit = 'DGUI'
private integer TypeSkinChanger = 'A00N'
private BUTTON TriggerButton
private location GL4DGUI = Location(0,0)
endglobals
function GetTriggerButton takes nothing returns BUTTON
return TriggerButton
endfunction
private function GetZ4DGUI takes real X, real Y returns real
call MoveLocation(GL4DGUI, X, Y)
return GetLocationZ(GL4DGUI)
endfunction
private function FineIndexAnimModel takes real w, real h, real z returns integer
local real W = w*WidthScreen*z
local real H = h*HeightScreen*z
local real anim
if (H<W) then
set anim = 10*(W/H-1)
return R2I_n(anim)
else
set anim = 10*(H/W-1)
if anim >= 0.5 then
return 100+R2I_n(anim)
endif
endif
return 0
endfunction
private function FineSizeModel takes real w, real h, real z returns real
local real W = w*WidthScreen*z
local real H = h*HeightScreen*z
if (H<W) then
return 0.5*H
else
return 0.5*W
endif
endfunction
struct BUTTON
static BUTTON array AllShow
static integer CountShow = 0
private integer index
private CAMERA Camera
private real centerx
private real centery
private real minx
private real maxx
private real miny
private real maxy
private real width
private real height
private real z
unit picture
private integer indexanim
private effect model
private trigger trigLclick
private trigger trigRclick
boolean show
integer CostumValue
player caster
string order
static method New takes real minx, real maxy, real W, real H, real z, integer texture , string o , player c returns BUTTON
local BUTTON this = BUTTON.create()
local destructable tree
set .CostumValue = 0
set .Camera = 0
set .width = W
set .height = H
set .minx = minx
set .maxx = minx+W
set .maxy = maxy
set .miny = maxy-H
set .z = 100.2+z
set .centerx = minx+W/2.0
set .centery = maxy-H/2.0
set .show = false
set .caster = c
set .order = o
set .trigLclick = CreateTrigger()
set .trigRclick = CreateTrigger()
set .picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
call UnitAddAbility(.picture, TypeSkinChanger)
if (texture != 0) then
set tree = CreateDestructable(texture,0,0,0,0,1)
call IssueTargetOrder(.picture, "grabtree", tree)
call RemoveDestructable(tree)
set tree = null
endif
set .indexanim = FineIndexAnimModel(W, H, .z)
call SetUnitAnimationByIndex(.picture, .indexanim)
call SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
call UnitAddAbility(.picture, 'Aave')
call UnitRemoveAbility(.picture, 'Aave')
call ShowUnit(.picture, false)
call SetUnitUserData(.picture, this)
return this
endmethod
method AddActionL takes code func returns triggeraction
return TriggerAddAction(.trigLclick, func)
endmethod
method RemoveActionL takes triggeraction action returns nothing
call TriggerRemoveAction(.trigLclick, action)
endmethod
method AddActionR takes code func returns triggeraction
return TriggerAddAction(.trigRclick, func)
endmethod
method RemoveActionR takes triggeraction action returns nothing
call TriggerRemoveAction(.trigRclick, action)
endmethod
method Delete takes nothing returns nothing
call DestroyTrigger(.trigLclick)
call DestroyTrigger(.trigRclick)
call RemoveUnit(.picture)
if .show then
set .AllShow[.index] = .AllShow[.CountShow]
set .AllShow[.index].index = .index
set .CountShow = .CountShow - 1
endif
endmethod
method Update takes nothing returns nothing
local VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
call SetUnitX(.picture, Pos.x)
call SetUnitY(.picture, Pos.y)
call MoveLocation(GL4DGUI, Pos.x, Pos.y)
call SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
call Pos.destroy()
endmethod
method Show takes boolean show, CAMERA Cam returns nothing
if Cam != -1 then
set .Camera = Cam
endif
call ShowUnit(.picture, show)
if show != .show then
if show then
set .AllShow[.CountShow] = this
set .index = .CountShow
set .CountShow = .CountShow + 1
call .Update()
call SetUnitAnimationByIndex(.picture, .indexanim)
else
set .CountShow = .CountShow - 1
set .AllShow[.index] = .AllShow[.CountShow]
set .AllShow[.index].index = .index
endif
endif
set .show = show
endmethod
method IsClick takes unit u returns boolean
return .picture == u
endmethod
method IsClickEx takes real x, real y returns boolean
return .minx < x and x < .maxx and .miny < y and y < .maxy
endmethod
method ClickL takes nothing returns nothing
set TriggerButton = this
call TriggerExecute(.trigLclick)
endmethod
method ClickR takes nothing returns nothing
set TriggerButton = this
call TriggerExecute(.trigRclick)
endmethod
method SetPosition takes real minx, real maxy returns nothing
set .minx = minx
set .maxx = minx+.width
set .maxy = maxy
set .miny = maxy-.height
set .centerx = minx+.width/2.0
set .centery = maxy-.height/2.0
if .show then
call .Update()
endif
endmethod
method SetTexture takes integer texture returns nothing
local destructable tree = CreateDestructable(texture,0,0,0,0,1)
call ShowUnit(.picture, true)
call SetUnitX(.picture, 0)
call SetUnitY(.picture, 0)
call IssueTargetOrder(.picture,"grabtree",tree)
call ShowUnit(.picture, .show)
call RemoveDestructable(tree)
if .show then
call .Update()
endif
set tree = null
endmethod
static method AllUpdate takes nothing returns nothing
local integer i = .CountShow
loop
exitwhen i < 0
call .AllShow[i].Update()
set i = i - 1
endloop
endmethod
static method Click takes unit u, boolean IsLeft returns boolean
local BUTTON b
if GetUnitTypeId(u) == TypeUnit then
set b = GetUnitUserData(u)
if b != 0 and b.show then
if IsLeft then
call b.ClickL()
else
call b.ClickR()
endif
return true
endif
endif
return false
endmethod
static method ClickEx takes real x, real y, boolean IsLeft returns boolean
local integer i = .CountShow
loop
exitwhen i < 0
if .AllShow[i].IsClickEx(x, y) then
if IsLeft then
call .AllShow[i].ClickL()
else
call .AllShow[i].ClickR()
endif
return true
endif
set i = i - 1
endloop
return false
endmethod
static method ClickPeriodicSelect takes player p, boolean IsLeft returns boolean
local integer i = .CountShow
loop
exitwhen i < 0
if IsUnitSelected(.AllShow[i].picture, p) then
if IsLeft then
call .AllShow[i].ClickL()
else
call .AllShow[i].ClickR()
endif
return true
endif
set i = i - 1
endloop
return false
endmethod
endstruct
function DGUIClickEx takes real x, real y, boolean IsLeft returns boolean
local integer i = BUTTON.CountShow
loop
exitwhen i < 0
if BUTTON.AllShow[i].IsClickEx(x, y) then
if IsLeft then
call BUTTON.AllShow[i].ClickL()
else
call BUTTON.AllShow[i].ClickR()
endif
return true
endif
set i = i - 1
endloop
return false
endfunction
struct PICTURE
private static PICTURE array AllShow
private static integer CountShow = 0
private integer index
private CAMERA Camera
private real centerx
private real centery
private real width
private real height
private real z
unit picture
private integer indexanim
boolean show
integer CostumValue
static method New takes real minx, real maxy, real W, real H, real z, integer texture returns PICTURE
local PICTURE this = PICTURE.create()
local destructable tree
set .CostumValue = 0
set .Camera = 0
set .width = W
set .height = H
set .centerx = minx+W/2.0
set .centery = maxy-H/2.0
set .z = 100.2+z
set .show = false
set .picture = CreateUnit(Player(15), TypeUnit, 0, 0, 0)
call UnitAddAbility(.picture, TypeSkinChanger)
if (texture != 0) then
set tree = CreateDestructable(texture,0,0,0,0,1)
call IssueTargetOrder(.picture, "grabtree", tree)
call RemoveDestructable(tree)
set tree = null
endif
set .indexanim = FineIndexAnimModel(W, H, .z)
call SetUnitAnimationByIndex(.picture, .indexanim)
call SetUnitScale(.picture, FineSizeModel(W, H, .z), 0, 0)
call UnitAddAbility(.picture, 'Aave')
call UnitRemoveAbility(.picture, 'Aave')
call UnitAddAbility(.picture, 'Aloc')
call UnitRemoveAbility(.picture, 'Aloc')
call ShowUnit(.picture, false)
return this
endmethod
static method NewCostumModel takes real minx, real maxy, real z, real size, integer typeunit, real WidthModel, real HeightModel, integer texture returns PICTURE
local PICTURE this = PICTURE.create()
local destructable tree
set .CostumValue = 0
set .Camera = 0
set .z = 100.2+z
set .width = (WidthModel*size)/(WidthScreen*.z)
set .height = (HeightModel*size)/(HeightScreen*.z)
set .centerx = minx+.width/2.0
set .centery = maxy-.height/2.0
set .show = false
set .picture = CreateUnit(Player(15), typeunit, 0, 0, 0)
call UnitAddAbility(.picture, TypeSkinChanger)
if (texture != 0) then
set tree = CreateDestructable(texture,0,0,0,0,1)
call IssueTargetOrder(.picture, "grabtree", tree)
call RemoveDestructable(tree)
set tree = null
endif
call SetUnitScale(.picture, size, 0, 0)
call UnitAddAbility(.picture, 'Aave')
call UnitRemoveAbility(.picture, 'Aave')
call UnitAddAbility(.picture, 'Aloc')
call UnitRemoveAbility(.picture, 'Aloc')
call ShowUnit(.picture, false)
return this
endmethod
method Delete takes nothing returns nothing
call RemoveUnit(.picture)
if .show then
set .AllShow[.index] = .AllShow[.CountShow]
set .AllShow[.index].index = .index
set .CountShow = .CountShow - 1
endif
endmethod
method Update takes nothing returns nothing
local VECTOR3 Pos = .Camera.Win2World(.centerx, .centery, .z)
call SetUnitX(.picture, Pos.x)
call SetUnitY(.picture, Pos.y)
call MoveLocation(GL4DGUI, Pos.x, Pos.y)
call SetUnitFlyHeight(.picture, Pos.z-GetLocationZ(GL4DGUI), 0)
call Pos.destroy()
endmethod
method Show takes boolean show, CAMERA Cam returns nothing
if Cam != -1 then
set .Camera = Cam
endif
call ShowUnit(.picture, show)
if show != .show then
if show then
set .AllShow[.CountShow] = this
set .index = .CountShow
set .CountShow = .CountShow + 1
call .Update()
call SetUnitAnimationByIndex(.picture, .indexanim)
call UnitAddAbility(.picture, 'Aloc')
call UnitRemoveAbility(.picture, 'Aloc')
else
set .CountShow = .CountShow - 1
set .AllShow[.index] = .AllShow[.CountShow]
set .AllShow[.index].index = .index
endif
endif
set .show = show
endmethod
method SetPosition takes real minx, real maxy returns nothing
set .centerx = minx+.width/2.0
set .centery = maxy-.height/2.0
if .show then
call .Update()
endif
endmethod
method SetTexture takes integer texture returns nothing
local destructable tree = CreateDestructable(texture,0,0,0,0,1)
call ShowUnit(.picture, true)
call SetUnitX(.picture, 0)
call SetUnitY(.picture, 0)
call IssueTargetOrder(.picture,"grabtree",tree)
call ShowUnit(.picture, .show)
call RemoveDestructable(tree)
if .show then
call .Update()
endif
set tree = null
endmethod
static method AllUpdate takes nothing returns nothing
local integer i = .CountShow
loop
exitwhen i < 0
call .AllShow[i].Update()
set i = i - 1
endloop
endmethod
endstruct
struct TEXT
private static TEXT array AllShow
private static integer CountShow = 0
private integer index
private CAMERA Camera
private real minx
private real maxy
private real z
texttag text
boolean show
integer CostumValue
static method New takes real minx, real maxy, real z returns TEXT
local TEXT this = TEXT.create()
set .CostumValue = 0
set .Camera = 0
set .minx = minx
set .maxy = maxy
set .z = 100+z
set .show = false
set .text = CreateTextTag()
call SetTextTagVisibility(.text, false)
return this
endmethod
method Delete takes nothing returns nothing
call DestroyTextTag(.text)
if .show then
set .AllShow[.index] = .AllShow[.CountShow]
set .AllShow[.index].index = .index
set .CountShow = .CountShow - 1
endif
endmethod
method Update takes nothing returns nothing
local VECTOR3 Pos = .Camera.Win2World(.minx, .maxy, .z)
call SetTextTagPos(.text, Pos.x, Pos.y, Pos.z-GetZ4DGUI(Pos.x,Pos.y))
call Pos.destroy()
endmethod
method SetPosition takes real minx, real maxy returns nothing
set .minx = minx
set .maxy = maxy
if .show then
call .Update()
endif
endmethod
method Show takes boolean show, CAMERA Cam returns nothing
if Cam != -1 then
set .Camera = Cam
endif
call SetTextTagVisibility(.text, show)
if show != .show then
if show then
set .AllShow[.CountShow] = this
set .index = .CountShow
set .CountShow = .CountShow + 1
call .Update()
else
set .CountShow = .CountShow - 1
set .AllShow[.index] = .AllShow[.CountShow]
set .AllShow[.index].index = .index
endif
endif
set .show = show
endmethod
static method AllUpdate takes nothing returns nothing
local integer i = .CountShow
loop
exitwhen i < 0
call .AllShow[i].Update()
set i = i - 1
endloop
endmethod
endstruct
function DGUIUpdate takes boolean but, boolean pic, boolean tex returns nothing
if but then
call BUTTON.AllUpdate()
endif
if pic then
call PICTURE.AllUpdate()
endif
if tex then
call TEXT.AllUpdate()
endif
endfunction
endlibrary