Добавлен , опубликован

Обращение к фреймам

Кратко: этот раздел объясняет как можно обратиться к фреймам. Есть различные способы.

1. По имени

Изначально в варкрафте были доступны именные фреймы (1.26 они также доступны). У каждого главного фрейма должно быть имя. Они записаны в fdf, и лежат в архивах игры. Содержимое всех fdf фреймов можно получить здесь или лично достать mpq-архиватором для варика 1.26 или архиватором CASC Viewer из игры и открыть любой fdf-file
есть несколько нативок для работы с ними
---@param name string
---@param createContext integer
---@return framehandle
function BlzGetFrameByName(name, createContext) end	-- (native)

---@param frame framehandle
---@return string
function BlzFrameGetName(frame) end	-- (native)
пример обращения к ConsoleUIBackdrop
BlzGetFrameByName("ConsoleUIBackdrop",0)
Однако, не у всех есть имена. Обычно, у потомков главных фреймов их нет.

2. Константы из рефорджа

В рефордже ввели константы originframetype, дабы упростить обращения к нужным фреймам.
список констант
constant originframetype ORIGIN_FRAME_GAME_UI  = ConvertOriginFrameType(0)
constant originframetype ORIGIN_FRAME_COMMAND_BUTTON = ConvertOriginFrameType(1)
constant originframetype ORIGIN_FRAME_HERO_BAR = ConvertOriginFrameType(2)
constant originframetype ORIGIN_FRAME_HERO_BUTTON = ConvertOriginFrameType(3)
constant originframetype ORIGIN_FRAME_HERO_HP_BAR = ConvertOriginFrameType(4)
constant originframetype ORIGIN_FRAME_HERO_MANA_BAR = ConvertOriginFrameType(5)
constant originframetype ORIGIN_FRAME_HERO_BUTTON_INDICATOR = ConvertOriginFrameType(6)
constant originframetype ORIGIN_FRAME_ITEM_BUTTON = ConvertOriginFrameType(7)
constant originframetype ORIGIN_FRAME_MINIMAP  = ConvertOriginFrameType(8)
constant originframetype ORIGIN_FRAME_MINIMAP_BUTTON = ConvertOriginFrameType(9)
constant originframetype ORIGIN_FRAME_SYSTEM_BUTTON  = ConvertOriginFrameType(10)
constant originframetype ORIGIN_FRAME_TOOLTIP  = ConvertOriginFrameType(11)
constant originframetype ORIGIN_FRAME_UBERTOOLTIP  = ConvertOriginFrameType(12)
constant originframetype ORIGIN_FRAME_CHAT_MSG = ConvertOriginFrameType(13)
constant originframetype ORIGIN_FRAME_UNIT_MSG = ConvertOriginFrameType(14)
constant originframetype ORIGIN_FRAME_TOP_MSG = ConvertOriginFrameType(15)
constant originframetype ORIGIN_FRAME_PORTRAIT = ConvertOriginFrameType(16)
constant originframetype ORIGIN_FRAME_WORLD_FRAME = ConvertOriginFrameType(17)
constant originframetype ORIGIN_FRAME_SIMPLE_UI_PARENT = ConvertOriginFrameType(18)
constant originframetype ORIGIN_FRAME_PORTRAIT_HP_TEXT = ConvertOriginFrameType(19)
constant originframetype ORIGIN_FRAME_PORTRAIT_MANA_TEXT = ConvertOriginFrameType(20)
constant originframetype ORIGIN_FRAME_UNIT_PANEL_BUFF_BAR = ConvertOriginFrameType(21)
constant originframetype ORIGIN_FRAME_UNIT_PANEL_BUFF_BAR_LABEL = ConvertOriginFrameType(22)
обратиться к фреймам с помощью этих констант можно нативкой
---@param frameType originframetype
---@param index integer
---@return framehandle
function BlzGetOriginFrame(frameType, index) end	-- (native)
пример обращения к ORIGIN_FRAME_GAME_UI
BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)

3. ​Родитель-ребенок

Патч 1.32.6 дал возможность доступа к дочерним элементам фреймов. Так вы можете получить доступ к потомкам.
BlzFrameGetChildrenCount(frame) -> integer - возвращает число, таким образом мы можем у родителя узнать кол-во потомков-фреймов, не являющимися String/Texture. А от старших потомков еще узнать других. Это все меняет, так мы можем понимать сколько потомков имеется в наличии, чтобы попусту не тратить время, а также узнать имена.
BlzFrameGetChild(frame, index) -> framehandle - возвращает фрейм-потомка, не являющимся String/Texture. В варкрафте доступ к некоторым фреймам не получить обычным способом, только через потомков можно получить доступ к стандартным файлам.
BlzFrameGetParent(frame) -> framehandle - возвращает фрейм-родителя.
код
---@param frame framehandle
---@param parent framehandle
---@return nothing
function BlzFrameSetParent(frame, parent) end	-- (native)

---@param frame framehandle
---@return framehandle
function BlzFrameGetParent(frame) end	-- (native)

---@param frame framehandle
---@param index integer
---@return framehandle
function BlzFrameGetChild(frame, index) end	-- (native)

---@param frame framehandle
---@return integer
function BlzFrameGetChildrenCount(frame) end	-- (native)
примеры
do
    local real = MarkGameStarted
  function MarkGameStarted()
        real()
    local frame = BlzCreateFrame("ScriptDialogButton", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 0, 0)
    BlzFrameSetText(frame, "text")
    print(BlzFrameGetChildrenCount(frame))
    for int = 0, BlzFrameGetChildrenCount(frame) - 1 do
        print(int, BlzFrameGetName(BlzFrameGetChild(frame, int)))
    end
  end
end
или
TimerStart(CreateTimer(),0,false, function()
        local frame = BlzGetFrameByName("InsideMainPanel", 0)
        
        for i = 0, BlzFrameGetChildrenCount(frame)-1 do
            local child = BlzFrameGetChild(frame,i)
            print(i..BlzFrameGetName(child))
        end              
end)

Изучение фреймов

Кратко: расскажу о каждом фрейме.
ORIGIN_FRAME_GAME_UI
Это наш ключ для создания новых фреймов контейнера. В других руководствах и во многих примерах ORIGIN_FRAME_GAME_UI используется как родительский для пользовательских созданных фреймов. Это сделано потому, что каждому кадру нужен родитель.
Пример Frame-GameUI:
local framehandle gameUI = BlzGetOriginFrame ( ORIGIN_FRAME_GAME_UI, 0 )
originframetype index info
ORIGIN_FRAME_GAME_UI 0 Самый главный родитель всего интерфейса. Без него ничего не будет отображаться. Для чего он нужен? Ну например, при создании фрейма нужно указать родителя. Если указать неправильного родителя, то фрейм у вас не создастся.
Поскольку gameUI является родителем всего интерфейса, мы рассмотрим всех потомков.
кол-во потомков gameUI может изменяться
По умолчанию: у gameUI 14 потомков. Это если не учитывать Multiboard, Leaderboard, TimerDialog, без нажатия диалогового окна квеста (quest dialog clicked). Это зависит, скорее всего от того, включены ли эти данные в игре изначально.
Вот скрин с пустой картой:
Когда создал пустой Multiboard, число дочерних фреймов изменилось:
Когда создал Multiboard и Leaderboard, число дочерних фрэймов изменилось:
Теперь вы должны понимать, что общее число потомков может меняться.
В игре максимальное число потомков: 19.
`
ОЖИДАНИЕ РЕКЛАМЫ...