• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

CustomWindow (v. 0.0.B)

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
  • Like
Reactions: deepstrasz
Happy new Year!

This is a very first beta of my CustomWindow system which helps you
displaying icons for every player himself, with only needing one rect for displaying at all.

It works with hiding / showing handles.

Please report any bugs / suggestions and note, this is really beta.
A more detailed version with much more features and stuff comes in the next time.

Librarys:


JASS:
library WindowExample initializer initTest requires CWWindow

    globals
        private Destructable    array EscButtons[15]
        private Destructable    array InfoButtons[15]
        private Destructable    array ThanksButtons[15]
        private Destructable    array SwitchHeroButtons[15]
        
        private TrackAble       array EscTracks[15]
        private TrackAble       array InfoTracks[15]
        private TrackAble       array ThanksTracks[15]
        private TrackAble       array SwitchHeroTracks[15]
        
        private Destructable    array selected[15]
        private unit            array heroes[15]
        private integer         array heroIDS[100]
        private integer         array curHero[15]
        private integer         maxHeroID = 1
    endglobals
    
    private function lockCamera takes nothing returns nothing
        call SetCameraPosition(0, 0)
        call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 270, 0)
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 1000, 0)
    endfunction
    
    //! textmacro EW_addAction takes DEST_ID, X, Y, DESTSAFE, TRACKSAFE
    set $TRACKSAFE$ = .createTrack(Player(i), "CustomWindow\\IconBase.mdx", dist2destdist($X$), dist2destdist($Y$), 0, 0.)
    set $DESTSAFE$ = .createDestructable(Player(i), $DEST_ID$, 1.01, dist2destdist($X$), dist2destdist($Y$), 0.01, 270)
    //! endtextmacro
    
    private function changeUnit takes integer i returns nothing
        set curHero[i] = curHero[i] +1
        if curHero[i] > maxHeroID then
            set curHero[i] = 0
        endif
        
        call RemoveUnit(heroes[i])
        
        set heroes[i] = CreateUnit(Player(i), heroIDS[curHero[i]], 0., -64., 0.)
        if GetLocalPlayer() != Player(i) then
            call SetUnitVertexColor(heroes[i], 255, 255, 255, 0)
        endif
    endfunction

    struct ExampleWindow extends Window
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Methods 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        public method init takes nothing returns nothing
            local integer i = 0
            
            set heroIDS[0] = 'Hpal'
            set heroIDS[1] = 'Hamg'
            
            call makeBlack(bj_mapInitialPlayableArea)
            
            call FogModifierStart(CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, false, false))
            call TimerStart(CreateTimer(), 0.1, true, function lockCamera)
            
            loop
                exitwhen i >= 15
                
                call changeUnit(i)
                
                //! runtextmacro EW_addAction("'B000'", "400", "200", "EscButtons[i]", "EscTracks[i]") 
                //! runtextmacro EW_addAction("'B001'", "-400", "200", "InfoButtons[i]", "InfoTracks[i]") 
                //! runtextmacro EW_addAction("'B002'", "-400", "100", "ThanksButtons[i]", "ThanksTracks[i]")
                
                //! runtextmacro EW_addAction("'B004'", "0", "-100", "SwitchHeroButtons[i]", "SwitchHeroTracks[i]")
                set i = i + 1
            endloop
        endmethod
    endstruct
    
    public function exampleEvent takes Window eventWindow, TrackAble eventTrack returns nothing
        //call BJDebugMsg("Window #" + I2S(integer(eventWindow)) + ": Event fires")    
    endfunction
    
    public function exampleHit takes Window eventWindow, TrackAble eventTrack returns nothing
        local trackable     trackHandle = eventTrack.getHandle()
        local integer       i           = GetPlayerId(eventTrack.getOwner())
        
        //call BJDebugMsg("Player " + GetPlayerName(Player(i)) + " has clicked on trackable!")
        call ClearTextMessages()
        
        //: Compare data to see what happened
        if trackHandle == EscTracks[i].getHandle() then
            call EndGame(false)
        endif
        
        if trackHandle == InfoTracks[i].getHandle() then
            call BJDebugMsg("This system was made by Anachron / dhk_undead_lord.")
            call BJDebugMsg("Please give him credits if you use this.")
        endif
        
        if trackHandle == ThanksTracks[i].getHandle() then
            call BJDebugMsg("Thanks for Deaod for his advanced knowledge and systems.")
            call BJDebugMsg("Thanks to Vexorian for vJass <3.")
            call BJDebugMsg("And thanks to hiveworkshop for hosting.")
        endif
        
        if trackHandle == SwitchHeroTracks[i].getHandle() then
            call changeUnit(i)
        endif
    endfunction
    
    public function exampleHover takes Window eventWindow, TrackAble eventTrack returns nothing
        local trackable     trackHandle = eventTrack.getHandle()
        local integer       i           = GetPlayerId(eventTrack.getOwner())
        local effect        tmp         = null
        local real          x           = eventTrack.getX()
        local real          y           = eventTrack.getY()
        
        call ClearTextMessages()
        
        if selected[i] != 0 then
            call RemoveDestructable(selected[i].getHandle())
            call selected[i].destroy()
        endif
        set selected[i] = eventWindow.createDestructable(Player(i), 'B003', 1.01, x, y, 0.01, 270)
        
        if trackHandle == EscTracks[i].getHandle() then
            call BJDebugMsg("Click on this icon to exit the game.")
        endif
        
        if trackHandle == InfoTracks[i].getHandle() then
            call BJDebugMsg("Click meh!")
        endif
        
        if trackHandle == ThanksTracks[i].getHandle() then
            call BJDebugMsg("Click meh too!")
        endif
    endfunction

    private function initTest takes nothing returns nothing
        //: Enable the Window, set the methods 
        //: to run on generalEvent, hit and hover event.
        local ExampleWindow ew = ExampleWindow.create(exampleEvent, exampleHit, exampleHover)
        call ew.init()
    endfunction

endlibrary



JASS:
library CWWindow initializer init requires Table, CWTrackAble, CWDestructable

    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    //: Change anything below to what you need!
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#

    //: The interfaces for the system
    public function interface iTrackHover takes Window eventWindow, TrackAble eventTrack returns nothing
    public function interface iTrackHit takes Window eventWindow, TrackAble eventTrack returns nothing
    public function interface iOnEvent takes Window eventWindow, TrackAble eventTrack returns nothing
    
    //: Default functions for this system
    public function defTrackHover takes Window eventWindow, TrackAble eventTrack returns nothing
    endfunction
    public function defTrackHit takes Window eventWindow, TrackAble eventTrack returns nothing
    endfunction
    public function defOnEvent takes Window eventWindow, TrackAble eventTrack returns nothing
    endfunction
    
    //: The customizeable constants.
    //: I hope the names are self-explaining.
    globals
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Window defaults. 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        Table WindowTable = 0
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Window settings. 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    endglobals
    
    //: Useful functions
    function dist2destdist takes real r returns real
        local real tmp = 0
        
        loop
            if r <= 0 then
                exitwhen tmp <= r
                set tmp = tmp - 32.
            else
                exitwhen tmp >= r
                set tmp = tmp + 32.
            endif
        endloop
        
        return tmp
    endfunction
    
    //: A little terrain generator
    globals
        private constant real       TILE_DIST = 64
        private constant integer    TILE_SIZE = 1
        private constant integer    BLACK_TILE = 'cOc1'
    endglobals

    function makeBlack takes rect r returns nothing
        local real xMin = GetRectMinX(r)
        local real yMin = GetRectMinY(r)
        local real xMax = GetRectMaxX(r)
        local real yMax = GetRectMaxY(r)
        local real x    = xMin
        local real y    = yMin
        local integer xTimes = R2I((xMax - xMin) / TILE_DIST)
        local integer yTimes = R2I((yMax - yMin) / TILE_DIST)
        local integer xCur = 0
        local integer yCur = 0
        
        loop
            exitwhen xCur >= xTimes
            
            set yCur = 0 
            set y = yMin
            loop
                exitwhen yCur >= yTimes
                
                set y = y + TILE_DIST
                call SetTerrainType(x, y, BLACK_TILE, 0, TILE_SIZE, 0)
                
                set yCur = yCur + 1
            endloop
            
            set x = x + TILE_DIST 
            set xCur = xCur + 1
        endloop
    endfunction
    
    
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    //: I don't recommend changing code below this!
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    struct Window
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Members 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        private iTrackHover OnTrackHover    = defTrackHover
        private iTrackHit   OnTrackHit      = defTrackHit
        private iOnEvent    OnEvent         = defOnEvent
        public  Table       TrackTable      = 0
        public  Table       DestructTable   = 0
        private trigger     Trigger         = null
        private integer     Id              = -1
        
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Methods 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        public method Event takes TrackAble eventTrack, eventid eventID returns nothing
            //: Fire the onEvent function
            call .OnEvent.execute(this, eventTrack)
            
            //: Depending on gameevent, we need
            //: to call diffrent methods
            if eventID == EVENT_GAME_TRACKABLE_HIT then
                //: Game event is hit, so run those
                call eventTrack.hit()
                call .OnTrackHit.execute(this, eventTrack)
            elseif eventID == EVENT_GAME_TRACKABLE_TRACK then
                //: Game event is hover, so run those
                call eventTrack.hover()
                call .OnTrackHover.execute(this, eventTrack)
            endif
        endmethod
        
        private static method onTrackEvent takes nothing returns nothing
            local trigger   eventTrig   = GetTriggeringTrigger()
            local integer   windowID    = WindowTable[GetHandleId(eventTrig)]
            local thistype  window      = thistype(windowID)
            local trackable eventTrack  = GetTriggeringTrackable()
            local integer   trackID     = window.TrackTable[GetHandleId(eventTrack)]
            local TrackAble track       = TrackAble(trackID)
            local eventid   eventID     = GetTriggerEventId()
            
            //: Fire the actual event 
            //: for the specific window
            call window.Event(track, eventID)
            
            set eventTrig = null
            set eventTrack = null
            set eventID = null
        endmethod
        
        public static method create takes iOnEvent e, iTrackHit hit, iTrackHover hover returns thistype
            local thistype this = thistype.allocate()
            
            //: Set a few members
            set .OnTrackHit     = hit
            set .OnTrackHover   = hover
            set .OnEvent        = e
            
            //: Init tables
            set .DestructTable = Table.create()
            set .TrackTable = Table.create()
            
            //: Create a new system trigger
            set .Trigger = CreateTrigger()
            set .Id = GetHandleId(.Trigger)
            call TriggerAddAction(.Trigger, function thistype.onTrackEvent)
            
            //: Save the window instance
            set WindowTable[.Id] = integer(this)
    
            return this
        endmethod
        
        public method createTrack takes player p, string s, real x, real y, real z, real f returns TrackAble
            local TrackAble t = TrackAble.create(p, s, x, y, z, f)
            
            //: Register the events of the trackable
            call t.registerHit(.Trigger)
            call t.registerHover(.Trigger)
            
            //: Save the trackable
            set .TrackTable[GetHandleId(t.getHandle())] = integer(t)
            
            return t
        endmethod
        
        public method createDestructable takes player p, integer id, real size, real posX, real posY, real posZ, real posF returns Destructable
            local Destructable d = Destructable.create(p, id, size, posX, posY, posZ, posF)
            
            //: Save the image
            set .DestructTable[GetHandleId(d.getHandle())] = integer(d)
            
            return d
        endmethod
    endstruct
    
    private function init takes nothing returns nothing
        set WindowTable             = Table.create()
    endfunction

endlibrary



JASS:
library CWDestructable

    //: The textmacros for the system
    //! textmacro IMAGE_getVar takes method, variable, type
    public method $method$ takes nothing returns $type$
        return .$variable$
    endmethod
    //! endtextmacro
    //! textmacro IMAGE_setVar takes method, variable, type
    public method $method$ takes $type$ val returns nothing
        set .$variable$ = val
    endmethod
    //! endtextmacro

    struct Destructable
        private destructable Handle = null
        private integer id = 0
        private real Size = 0.
        private player Owner = null
        
        public static method create takes player p, integer id, real size, real posX, real posY, real posZ, real posF returns thistype
            local thistype this = thistype.allocate()
            
            set .Handle = CreateDestructableZ(id, posX, posY, posZ, posF, size, 0)
            set .Owner = p
            set .id = id
            
            if GetLocalPlayer() != .Owner then
                call ShowDestructable(.Handle, false)
            endif
            
            return this
        endmethod
        
        public method show takes boolean b returns nothing
            if GetLocalPlayer() == .Owner then
                call ShowDestructable(.Handle, b)
            endif
        endmethod
        
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Textmacros 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //! runtextmacro IMAGE_getVar("getHandle", "Handle", "destructable")
        //==-------------------------------------------
    endstruct

endlibrary



JASS:
library TrackAble

    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    //: Change anything below to what you need!
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#

    //: The interfaces for the system
    public function interface iHover takes TrackAble t returns nothing
    public function interface iHit takes TrackAble t returns nothing
    
    //: Default methods
    public function defHover takes TrackAble t returns nothing
    endfunction
    
    public function defHit takes TrackAble t returns nothing
    endfunction
    
    //: The customizeable constants.
    //: I hope the names are self-explaining.
    globals
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: TrackAble defaults. 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        private constant trackable  DEFAULT_HANDLE      = null
        private constant string     DEFAULT_MODEL       = ""
        private constant player     DEFAULT_OWNER       = Player(PLAYER_NEUTRAL_PASSIVE)
        private constant real       DEFAULT_POSF        = 0.
        private constant real       DEFAULT_POSX        = 0.
        private constant real       DEFAULT_POSY        = 0.
        private constant real       DEFAULT_POSZ        = 0.
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: TrackAble settings. 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        private constant integer    SYSTEM_DESTID       = 'YTpb'
    endglobals

    //: The textmacros for the system
    //! textmacro getVar takes method, variable, type
    public method $method$ takes nothing returns $type$
        return .$variable$
    endmethod
    //! endtextmacro
    //! textmacro setVar takes method, variable, type
    public method $method$ takes $type$ val returns nothing
        set .$variable$ = val
    endmethod
    //! endtextmacro
    
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    //: I don't recommend changing code below this!
    //=!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#
    
    struct TrackAble
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Members 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        private trackable   Handle      = DEFAULT_HANDLE
        private string      Model       = DEFAULT_MODEL
        private iHit        OnHit       = defHit
        private iHover      OnHover     = defHover
        private player      Owner       = DEFAULT_OWNER
        private real        PosF        = DEFAULT_POSF
        private real        PosX        = DEFAULT_POSX
        private real        PosY        = DEFAULT_POSY
        private real        PosZ        = DEFAULT_POSZ
        
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Methods 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        public static method create takes player p, string s, real x, real y, real z, real f returns thistype
            local thistype this = thistype.allocate()
            //local destructable d = CreateDestructableZ(SYSTEM_DESTID, x, y, z, f, 1., 0)
            local string path = ""
            
            if GetLocalPlayer() == p then
                set path = s
            else
                set path = ""
            endif

            set .Handle     = CreateTrackable(path, x, y, f)
            set .Model      = s
            set .PosF       = f
            set .PosX       = x
            set .PosY       = y
            set .PosZ       = z
            set .Owner      = p
            
            //call RemoveDestructable(d)
            //set d = null
            
            return this
        endmethod
        
        public method registerHit takes trigger t returns nothing
            call TriggerRegisterTrackableHitEvent(t, .Handle)
        endmethod
        
        public method registerHover takes trigger t returns nothing
            call TriggerRegisterTrackableTrackEvent(t, .Handle)
        endmethod
        
        public method hit takes nothing returns nothing
            call .OnHit.execute(this)
        endmethod
        
        public method hover takes nothing returns nothing
            call .OnHover.execute(this)
        endmethod
        
        public method getOwner takes nothing returns player
            return .Owner
        endmethod
        
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //: Textmacros 
        //==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        //! runtextmacro getVar("getF", "PosF", "real")
        //! runtextmacro getVar("getX", "PosX", "real")
        //! runtextmacro getVar("getY", "PosY", "real")
        //! runtextmacro getVar("getZ", "PosZ", "real")
        //! runtextmacro getVar("getHandle", "Handle", "trackable")
        //==-------------------------------------------
        //! runtextmacro setVar("setOnHover",   "OnHover",  "iHover")
        //! runtextmacro setVar("setOnHit",     "OnHit",    "iHit")
        //==-------------------------------------------
    endstruct
endlibrary


Keywords:
Window, System, Display, Player, Custom, UI, Action, Advanced
Contents

Noch eine WARCRAFT-III-Karte (Map)

Reviews
10:50, 30th Dec 2009 TriggerHappy: Please submit it once you have it finished. If you want comments on a WIP, post in T/S or project development.

Moderator

M

Moderator

10:50, 30th Dec 2009
TriggerHappy:

Please submit it once you have it finished.
If you want comments on a WIP, post in T/S or project development.
 
Level 25
Joined
Jun 5, 2008
Messages
2,572
Where is the interface created?

Also adding somewhat more documentation and examples could be usefull.
It also lacks somewhat more examples of it's usage, i mean it looks fine but i doubt that most of people will understand the usage of this system.
(Also you could have added a rotate button for heroes, just to make it look better)

As far as i can tell you used trackables/destructables and some libraries, which to be honest could have been done with hashtables only :p

Anyway nice example of trackables/destructable usage.
 
Top