• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

UIBasic

Level 19
Joined
Mar 18, 2012
Messages
1,716

UIBasic


Collection of data and functions used all over the UI package.


JASS:
//*  Library collection:
//*  ===================
//*  Simply list library "UIPackage" as requirement for your custom UIs.
//* The compiler will place all required UI libraries above your script.
//* Example: - library MyCustomUI requires UIPackage.
library_once UIPackage uses UIBasic, UIBorder, UIButton, UIWindow, UICamera optional UISound optional UIBoard
endlibrary

library UIBasic/* v1.0
*****************************************************************************
*
*  	Collection of data used all over the UI package.
*
*****************************************************************************
*
*   */ uses /*
*   
*       */ Track                   /* https://www.hiveworkshop.com/forums/jass-resources-412/system-track-205760/
*       */ Table                   /* https://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
*       */ ImageTools              /* https://www.hiveworkshop.com/forums/submissions-414/imagetools-271099/
*       */ WorldBounds             /* http://github.com/nestharus/JASS/tree/master/jass/Systems/WorldBounds
*       */ ErrorMessage            /* http://github.com/nestharus/JASS/tree/master/jass/Systems/ErrorMessage
*       */ optional TileDefinition /* https://www.hiveworkshop.com/forums/jass-resources-412/snippet-tiledefinition-259347/
*       */ optional WordWrap       /* http://wc3jass.com/5016/system-wordwrap/
*
***************************************************************
*/
  
    globals
        //*  Public constants:
		//*  =================
        constant integer UI_CAMERA_DUMMY_ID      = 'dumi'
        constant integer EVENT_PLAYER_UI         = 1
        constant timer   UI_STAMP                = CreateTimer()
        constant real    UI_DEFAULT_BUTTON_Z     = -10.00
        constant real    UI_MOUSE_DOUBLE_CLICK   = .5
        constant rect    UI_RECT                 = Rect(0, 0, 0, 0)
        constant real    UI_PERFECT_SCREEN_RATIO = 1.803
        constant real    UI_TILE_SIZE            = 64.00
        
        //*  Public variables: ( UIBorder related )
        //*  =================
        //*  You can change these values, between
        //* two border creations. Make sure the string paths do exist.
        //* "null" and "" are considered as valid ( empty ) string path. 
        boolean UI_BORDER_INCLUDED_IN_RECT = false
        real    UI_BORDER_WIDTH            = 32.
        integer UI_BORDER_BACKGOUND_RED    = 255
        integer UI_BORDER_BACKGOUND_GREEN  = 255
        integer UI_BORDER_BACKGOUND_BLUE   = 255
        integer UI_BORDER_BACKGOUND_ALPHA  = 200
        integer UI_BORDER_IMAGE_TYPE       = IMAGE_TYPE_OCCLUSION_MASK
        string  UI_BORDER_BACKGROUND       = "war3mapImported\\background.TGA"
        string  UI_BORDER_LEFT             = "war3mapImported\\BorderLeftNE.TGA"
        string  UI_BORDER_RIGHT            = "war3mapImported\\BorderRightNE.TGA"
        string  UI_BORDER_TOP              = "war3mapImported\\BorderUpNE.TGA"
        string  UI_BORDER_BOTTOM           = "war3mapImported\\BorderDownNE.TGA"
        string  UI_BORDER_BOTTOM_LEFT      = "war3mapImported\\BorderDownLeftNE.TGA"
        string  UI_BORDER_BOTTOM_RIGHT     = "war3mapImported\\BorderDownRightNE.TGA"
        string  UI_BORDER_TOP_LEFT         = "war3mapImported\\BorderUpLeftNE.TGA"
        string  UI_BORDER_TOP_RIGHT        = "war3mapImported\\BorderUpRightNE.TGA"
    endglobals

    //*  Public functions:
    //*  =================
    native UnitAlive takes unit id returns boolean

    //*  Useful for creating dummy units.
    function ToogleUnitIndexer takes boolean enable returns boolean 
        local boolean prevSetup = true
        static if LIBRARY_UnitIndexer then
            set prevSetup = UnitIndexer.enabled
            set UnitIndexer.enabled = enable
        elseif LIBRARY_UnitIndexerGUI then
            set prevSetup = udg_UnitIndexerEnabled
            set udg_UnitIndexerEnabled = enable
        elseif LIBRARY_UnitDex then
            set prevSetup = UnitDex.Enabled
            set UnitDex.Enabled = enable
        endif
        return prevSetup
    endfunction

    globals
    	private player client = null
    endglobals

    //*  Returns GetLocalPlayer(). Just faster.
    constant function GetLocalClient takes nothing returns player
        return client 
    endfunction

    //*  Returns the slot status of a player.
    function IsPlayerUser takes player p returns boolean
        return (GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING) and (GetPlayerController(p) == MAP_CONTROL_USER) 
    endfunction

    function IsPlayerComputer takes player p returns boolean
        return not IsPlayerUser(p)
    endfunction

    globals
    	//*  Event variables:
    	//*  ================
    	private trigger array events
    	private integer  	  index = 0 
    endglobals

    //*  So far only one event exists. There will be a few more soon.
    private function CreateEvents takes nothing returns nothing
    	set events[EVENT_PLAYER_UI] = CreateTrigger()
    endfunction

    function UI_RegisterPlayerEvent takes integer id, code func returns nothing
        local boolean pJass = true
        debug call ThrowError((events[id] == null), "UIBasic", "UI_RegisterPlayerEvent", "events[id]", id, "Attempt to register code to an invalid UI event!")
        call TriggerAddCondition(events[id], Condition(func))
    endfunction

    constant function UI_GetTriggerPlayer takes nothing returns player
        return Player(index)
    endfunction

	//*  Non public API. Do not use this function.
    function UI_FireEvent takes integer pi, integer id returns nothing
    	local integer prev = index
    	set index 		   = pi
    	call TriggerEvaluate(events[id])
    	set index 		   = prev
    endfunction

    //*  Makes sure everything is initialized in time.
    //* Expects static method init inside the struct.
    module UIInit
        static if thistype.init.exists then
            private static method onInit takes nothing returns nothing
                call thistype.init()
            endmethod
        else
            "Error: Can't find static method thistype.init" 
        endif
    endmodule

    struct I extends array

        private static method init takes nothing returns nothing
            set client = GetLocalPlayer()
            call CreateEvents()
            call TimerStart(UI_STAMP, 10000000, false, null)
        endmethod
        implement UIInit

    endstruct

endlibrary
Last edited:
Back
Top