• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Basic Click-able Button

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
Hi everybody, I couldn't find a tutorial for click-able buttons yet so I have been thinking about ways of making click-able buttons/icons for the UI and I have come to the conclusion that the easiest way is to make a Backdrop and then make a TextButton below it.

Basically I combined 2 tutorials from Tasyen = this + this

Here is my final code:
JASS:
function blademaster_icon_Actions takes nothing returns nothing
    local framehandle blademaster = BlzCreateFrameByType("BACKDROP", "Blademaster", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    call BlzFrameSetSize(blademaster, 0.04, 0.04)
    call BlzFrameSetAbsPoint(blademaster, FRAMEPOINT_CENTER, 0.4, 0.3)
    call BlzFrameSetTexture(blademaster, "ReplaceableTextures\\CommandButtons\\BTNHeroBlademaster",0, true)
endfunction
//===========================================================================
function InitTrig_blademaster_icon takes nothing returns nothing
    set gg_trg_blademaster_icon = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_blademaster_icon, 0.50 )
    call TriggerAddAction( gg_trg_blademaster_icon, function blademaster_icon_Actions )
endfunction
JASS:
function ButtonCallBackBlademaster takes nothing returns nothing
    call BJDebugMsg("xorka test")
endfunction
function CreateBlademasterButton takes nothing returns nothing
    local trigger trig1 = CreateTrigger()
    local framehandle BlademasterButton  = BlzCreateFrame("ScriptDialogButton", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI,0), 0,0)
    call BlzFrameSetSize(BlademasterButton, 0.04,0.04)
    call BlzFrameSetAbsPoint(BlademasterButton, FRAMEPOINT_CENTER, 0.4,0.3)
 
    call BlzTriggerRegisterFrameEvent(trig1, BlademasterButton, FRAMEEVENT_CONTROL_CLICK)
    call TriggerAddAction(trig1, function ButtonCallBackBlademaster)
endfunction
//===========================================================================
function InitTrig_textbutton_test takes nothing returns nothing
    set gg_trg_textbutton_test = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_textbutton_test, 0.40 )
    call TriggerAddAction( gg_trg_textbutton_test, function CreateBlademasterButton )
endfunction

I'm NOT asking if this works because I know it does, I'm just curious if there are other better/more efficient ways to do it.

I actually tried to make it work using only the TextButton and use:
JASS:
    call BlzFrameSetTexture(BlademasterButton, "ReplaceableTextures\\CommandButtons\\BTNHeroBlademaster",0, true)
Unfortunately it looks like TextButton can't have a texture, which is actually a HUGE middle finger from blizzard as it would have made everything a lot easier lol...

Notes:
-Always create the Textbutton before the Backdrop or it will look like this:
fail.jpg

-Doesn't use .toc & .fdf files
 

Attachments

  • clickable button.w3x
    8 KB · Views: 26
Status
Not open for further replies.
Top