О системе
Относительно краткий пример создания PopupMenu фрейма используя UjAPI и Frame API.
Главным бонусом UjAPI в данной наработке является полноценный API специально добавленный для обработки PopupMenu фреймов, который позволяет просто на просто отказаться от fdf, а так же позволяет не только добавлять элементы, а так же удалять их. Зачем же нужны PopupMenu? Если Вы планируете создать допустим выборку разных текстовых опций для выбора нужной, то PopupMenu для вас.
Что же можно добавлять в PopupMenu? Практически что угодно, однако есть маленький нюанс. Создавать фрейм, который мы захотим затем "закрепить" в PopupMenu обязательно требует указание родителя - сам PopupMenu при его создании, SetFrameParent к сожалению в данной ситуации нам не поможет и фрейм не будет "заточен" в PopupMenu.
Событий у PopupMenu конечно же маловато внутри движка, а точнее: SELECTION_CHANGED (SELECTED/CLICKED).
Данная система конечно же работает в онлайне и не вызывает десинха, иначе это не имело бы смысла.
Код
раскрыть
library API
function B2S takes boolean flag returns string
if flag then
return "true"
endif
return "false"
endfunction
function B2I takes boolean flag returns integer
if flag then
return 1
endif
return 0
endfunction
// These leak trigger handle on each call, only use this to test things where you want to call TriggerSleepAction
// since destroying returned trigger will skip sleep action.
// <------
function RunTriggeredCodeEx takes trigger t, code func returns trigger
if t == null then
return null
endif
call ResetTrigger( t ) // simply resets Eval and Exec count
call TriggerClear( t ) // probably a bad idea. :)
call TriggerAddAction( t, func )
call TriggerExecute( t )
return t
endfunction
function RunTriggeredCode takes code func returns trigger
return RunTriggeredCodeEx( CreateTrigger( ), func )
endfunction
// ------>
endlibrary
globals
framehandle frm_PopupMenu = null
boolean frameDebugMode = false
endglobals
function OnFrameEvent takes string eventName, boolean extraData returns nothing
local player p = GetTriggerPlayer( )
if frameDebugMode then
if eventName != "" then
call ConsolePrint( eventName + "\n" )
endif
if extraData then
call ConsolePrint( "TriggerPlayerId = " + I2S( GetPlayerId( p ) ) + "\n" )
call ConsolePrint( "TriggerPlayer = " + IntToHex( GetHandleId( GetTriggerPlayer( ) ) ) + "\n" )
call ConsolePrint( "TriggerPlayerName = " + GetPlayerName( GetTriggerPlayer( ) ) + "\n" )
call ConsolePrint( "TriggeringTrigger = " + IntToHex( GetHandleId( GetTriggeringTrigger( ) ) ) + "\n" )
call ConsolePrint( "TriggerFrame = " + IntToHex( GetHandleId( GetTriggerFrame( ) ) ) + "\n" )
call ConsolePrint( "TriggerFrameEvent = " + I2S( GetHandleId( GetTriggerFrameEvent( ) ) ) + "\n" )
endif
endif
set p = null
endfunction
function OnPopupMenuChangeItem takes nothing returns nothing
call OnFrameEvent( "OnPopupMenuChangeItem", true )
if frameDebugMode then
call ConsolePrint( "GetTriggerFrameInteger = " + I2S( GetTriggerFrameInteger( ) ) + "\n" )
call ConsolePrint( "GetTriggerFrameTargetFrame = " + IntToHex( GetHandleId( GetTriggerFrameTargetFrame( ) ) ) + "\n" )
endif
endfunction
function TestCreatePopUpMenu takes nothing returns framehandle
local framehandle gameUI = GetOriginFrame( ORIGIN_FRAME_GAME_UI, 0 )
local framehandle frm = null
local framehandle textFrame = null
local framehandle menu = null
local trigger t = null
local integer i = 0
local integer itemCount = GetRandomInt( 5, 10 )
set frm_PopupMenu = CreateFrameByType( "POPUPMENU", "", gameUI, "", 0 )
//call ConsolePrint( "frm_PopupMenu = " + IntToHex( GetHandleId( frm_PopupMenu ) ) + " | " + IntToHex( HandleToAddress( frm_PopupMenu ) ) + "\n" )
call ClearFrameAllPoints( frm_PopupMenu )
call SetFrameSize( frm_PopupMenu, .1, .03 )
call SetFrameAbsolutePoint( frm_PopupMenu, FRAMEPOINT_CENTER, .4, .3 )
call SetFrameControlFlag( frm_PopupMenu, CONTROL_STYLE_AUTOTRACK, true )
call SetFrameControlFlag( frm_PopupMenu, CONTROL_STYLE_HIGHLIGHT_FOCUS, true )
call SetFrameBackdropTexture( frm_PopupMenu, 1, "UI\\widgets\\BattleNet\\bnet-tooltip-background.blp", true, true, "UI\\widgets\\BattleNet\\bnet-tooltip-border.blp", BORDER_FLAG_ALL, false )
call SetFrameBorderSize( frm_PopupMenu, 1, .0125 )
call SetFrameBackgroundSize( frm_PopupMenu, 1, .256 )
call SetFrameBackgroundInsets( frm_PopupMenu, 1, .005, .005, .005, .005 )
call SetFrameBackdropTexture( frm_PopupMenu, 3, "UI\\widgets\\BattleNet\\bnet-tooltip-background-disabled.blp", true, true, "UI\\widgets\\BattleNet\\bnet-tooltip-border.blp", BORDER_FLAG_ALL, false )
call SetFrameBorderSize( frm_PopupMenu, 3, .0125 )
call SetFrameBackgroundSize( frm_PopupMenu, 3, .256 )
call SetFrameBackgroundInsets( frm_PopupMenu, 3, .005, .005, .005, .005 )
set frm = GetFrameChildEx( frm_PopupMenu, 1, 0 ) // textButton
call SetFrameFont( frm, "Fonts\\FRIZQT__.TTF", .011, 0 )
set textFrame = GetFrameChildEx( frm, 1, 0 ) // textFrame of textButton
call SetFrameTextAlignmentValue( frm, 0, .01 )
//call ClearFrameAllPoints( textFrame )
//call SetFrameRelativePoint( textFrame, FRAMEPOINT_TOPLEFT, frm, FRAMEPOINT_TOPLEFT, .01, .0 )
//call SetFrameRelativePoint( textFrame, FRAMEPOINT_BOTTOMRIGHT, frm, FRAMEPOINT_BOTTOMRIGHT, .0, .0 )
set menu = GetFrameChildEx( frm_PopupMenu, 1, 2 ) // menu
call SetFrameFont( menu, "Fonts\\FRIZQT__.TTF", .011, 0 )
call SetFrameControlFlag( menu, CONTROL_STYLE_HIGHLIGHT_FOCUS, true )
call SetFrameBackdropTexture( menu, 1, "UI\\widgets\\BattleNet\\bnet-tooltip-background.blp", true, true, "UI\\widgets\\BattleNet\\bnet-tooltip-border.blp", BORDER_FLAG_ALL, false )
call SetFrameBorderSize( menu, 1, .0125 )
call SetFrameBackgroundSize( menu, 1, .256 )
call SetFrameBackgroundInsets( menu, 1, .005, .005, .005, .005 )
call SetFrameItemsBorder( menu, .009 )
call SetFrameItemsHeight( menu, .014 )
set frm = GetFrameChildEx( frm_PopupMenu, 1, 1 ) // arrow button
call SetFrameControlFlag( frm, CONTROL_STYLE_HIGHLIGHT_FOCUS, true )
call SetFrameSize( frm, .01, .01 )
call SetFrameRelativePoint( frm, FRAMEPOINT_RIGHT, frm_PopupMenu, FRAMEPOINT_RIGHT, -.01, .0 )
call SetFrameTexture( frm, "UI\\Widgets\\Glues\\GlueScreen-Pulldown-Arrow.blp", 0, false )
loop
exitwhen i == itemCount
set frm = AddFrameListItem( frm_PopupMenu, "KEKW " + I2S( i + 1 ), null )
call SetFrameTextAlignment( frm, TEXT_JUSTIFY_TOP, TEXT_JUSTIFY_LEFT )
call SetFrameTextColourEx( frm, 1, ConvertColour( 0xFF, GetRandomInt( 50, 255 ), GetRandomInt( 50, 255 ), GetRandomInt( 50, 255 ) ) )
set i = i + 1
endloop
set t = CreateTrigger( )
call TriggerRegisterFrameEvent( t, frm_PopupMenu, FRAMEEVENT_POPUPMENU_ITEM_CHANGED )
call TriggerAddAction( t, function OnPopupMenuChangeItem )
set gameUI = null
set frm = null
set textFrame = null
set menu = null
set t = null
return frm_PopupMenu
endfunction
function OnTestPopUpMenu takes nothing returns nothing
local framehandle frm = TestCreatePopUpMenu( )
if true then // not really necessary, remove this whole block if you do not care about highlight.
call SetFrameControlFlag( frm_PopupMenu, CONTROL_STYLE_HIGHLIGHT_ON_MOUSE_OVER, true )
call TriggerSleepAction( .01 )
call SetFrameHighlightTexture( frm, 1, "UI\\Glues\\ScoreScreen\\scorescreen-tab-hilight.blp", BLEND_MODE_ADDITIVE )
endif
set frm = null
endfunction
function OnInitSystemDelayed takes nothing returns nothing
call DestroyTimer( GetExpiredTimer( ) )
call BJDebugMsg( "UjAPI Version: " + GetUjAPIVersion( ) )
call RunTriggeredCode( function OnTestPopUpMenu )
endfunction
//===========================================================================
function InitTrig_TestPopupMenu takes nothing returns nothing
// set gg_trg_TestPopupMenu = CreateTrigger( )
call FogEnable( false )
call FogMaskEnable( false )
call PanCameraToTimed( 0., 0., 0. )
call EnableOperationLimit( false )
call TimerStart( CreateTimer( ), .5, false, function OnInitSystemDelayed )
endfunction