- Joined
- Mar 13, 2020
- Messages
- 421
Tasyen you are amazing..
Last edited:
AddUnitInfoPanel(frame, update[, condition])
frame is the containerPanel, update a function(unit) that runs every updateTick, condition is a function(unit) that returns true or false it is used to prevent rotating to this panel.
AddUnitInfoPanelEx(update, condition)
wrapper for AddUnitInfoPanel, it creates and returns a new frame
SetUnitInfoPanelFrame(frame)
makes a non SimpleFrame share visibility with the last Added InfoPanel, supports only one Frame per InfoPanel
SetUnitInfoPanelFrameEx()
wrapper SetUnitInfoPanelFrame creates and returns a new empty Frame
UnitInfoPanelAddTooltipListener(frame, code)
detects if this frame is visible if it is call the given function which should return a text which is the now wanted tooltipText.
UnitInfoCreateCustomInfo(parent, label, texture, tooltipCode)
return createContext, infoFrame, iconFrame, labelFrame, textFrame
UnitInfoGetUnit([player])
returns & recacls the current selected Unit
without a player it will use the local player.
function UnitInfoPanelSetPage(newPage, updateWanted)
ignores conditions, newPage can be "+" or "-" or a frame
local AutoRun = true -- (false) call InitUnitInfoPanels()
-- Shows how much gold and Lumber bounty one gets when slaying an unit
do
local realFunction = InitUnitInfoPanels
local lumberText, goldText, parent
local createContext, infoFrame, iconFrame, labelFrame, textFrame
local function Init()
-- create a new Unit Info Panel, this panel can only be shown when the current selected unit's owner gives bounty
parent = AddUnitInfoPanelEx(function(unit)
local min, max
min = BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_NUMBER_OF_DICE) + BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_BASE)
max = BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_NUMBER_OF_DICE) *BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_SIDES_PER_DIE) + BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_BASE)
BlzFrameSetText(goldText, min.." - "..max)
min = BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_NUMBER_OF_DICE) + BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_BASE)
max = BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_NUMBER_OF_DICE) *BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_SIDES_PER_DIE) + BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_BASE)
BlzFrameSetText(lumberText, min.." - "..max)
end,
function(unit) return IsPlayerFlagSetBJ(PLAYER_STATE_GIVES_BOUNTY, GetOwningPlayer(unit)) end)
-- define locals
-- create a new custom Info and load all created frames into the locals
createContext, infoFrame, iconFrame, labelFrame, textFrame = UnitInfoCreateCustomInfo(parent, " Gold:", "UI\\Widgets\\ToolTips\\Human\\ToolTipGoldIcon", function(unit)
-- this function returns the text shown inside the tooltip when this UnitInfo is mouse hovered.
local min, max
min = BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_NUMBER_OF_DICE) + BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_BASE)
max = BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_NUMBER_OF_DICE) *BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_SIDES_PER_DIE) + BlzGetUnitIntegerField(unit, UNIT_IF_GOLD_BOUNTY_AWARDED_BASE)
return "Bounty Gold: "..min.." - "..max
.."\nWhen an unit owned by you kills this unit, you gain this amount of Gold.\nOnly unallied unit give bounty."
end)
local prevIcon = iconFrame
goldText = textFrame
BlzFrameSetPoint(iconFrame, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("SimpleHeroLevelBar", 0), FRAMEPOINT_BOTTOMLEFT, 0, -0.001)
-- 2. Custom Info
createContext, infoFrame, iconFrame, labelFrame, textFrame = UnitInfoCreateCustomInfo(parent, " Lumber:", "UI\\Widgets\\ToolTips\\Human\\ToolTipLumberIcon", function(unit)
local min, max
min = BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_NUMBER_OF_DICE) + BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_BASE)
max = BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_NUMBER_OF_DICE) *BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_SIDES_PER_DIE) + BlzGetUnitIntegerField(unit, UNIT_IF_LUMBER_BOUNTY_AWARDED_BASE)
return "Bounty Lumber: "..min.." - "..max
.."\nWhen an unit owned by you kills this unit, you gain this amount of Lumber.\nOnly unallied unit give bounty."
end)
lumberText = textFrame
BlzFrameSetPoint(iconFrame, FRAMEPOINT_TOPLEFT, prevIcon, FRAMEPOINT_TOPLEFT, 0.095, 0)
prevIcon = nil
end
function InitUnitInfoPanels()
realFunction()
Init()
if FrameLoaderAdd then FrameLoaderAdd(Init) end
end
end
UnitInfoGetUnit(player p) -> unit
returns & recacls the current selected Unit, unneeded in given actionfunctions
AddUnitInfoPanel(framehandle frame, code update, code condition)
frame is the containerPanel, update a function() that runs every updateTick, condition is a function() that returns true or false it is used to prevent rotating to this panel.
it is suggested to use UnitInfoUnit inside this functions
AddUnitInfoPanelEx(code update, code condition) -> framehandle
wrapper for AddUnitInfoPanel, it creates and returns a new frame
SetUnitInfoPanelFrame(framehandle frame)
makes a non SimpleFrame share visibility with the last Added InfoPanel, supports only one Frame per InfoPanel
SetUnitInfoPanelFrameEx() -> framehandle
wrapper SetUnitInfoPanelFrame creates and returns a new empty Frame
UnitInfoPanelAddTooltipListener(framehandle frame, code func)
detects if this frame is visible if it is call the given function which is expected to set string UnitInfoTooltipText to the now wanted tooltipText.
UnitInfoCreateCustomInfo(framehandle parent, string label, string texture, code tooltipCode) -> integer
returns createContext
you can get the frames over globals UnitInfoInfoFrame, UnitInfoIconFrame, UnitInfoLabelFrame, UnitInfoTextFrame
UnitInfoPanelSetPage(integer newPage)
ignores conditions, using 0 will change to next page and -1 previous page
UnitInfoPanelSetPageByFrame(framehandle newPage, boolean updateWanted)
searches the index of newPage and calls UnitInfoPanelSetPage when found
library SkillPanel initializer init_function requires UnitInfoPanels
// Creates an UnitInfopanel showing the last 8 abilities the unit got, ignoring abilities having no tooltip.
// Ignores abilities without a Tooltip: When BlzGetAbilityStringLevelField returns "Tool tip missing!" or "" or " "
globals
private framehandle array Icon
private framehandle array Text
private framehandle array Button
private framehandle array ToolTip
private integer buttonCount = 8
private integer array SkillIndex
private framehandle parent
private trigger buttonTrigger = CreateTrigger()
endglobals
private function buttonAction takes nothing returns nothing
// request currently used unit of the clicking player
local integer i = buttonCount
local framehandle frame = BlzGetTriggerFrame()
call UnitInfoGetUnit(GetTriggerPlayer())
// get the clicked buttonIndex
// find the used Button
call BJDebugMsg("Skill Panel")
loop
exitwhen i == 0
if frame == Button[i] then
call BJDebugMsg(GetPlayerName(GetTriggerPlayer()) + " Clicked: " + I2S(i) + " "+ GetUnitName(UnitInfoUnit))
exitwhen true
endif
set i = i - 1
endloop
set frame = null
endfunction
private function tooltipAction takes nothing returns nothing
// the tooltip function is async do not create or destroy here
local integer i = buttonCount
local ability abi
// find the active tooltip
loop
exitwhen i == 0
if UnitInfoTooltipFrame == ToolTip[i] then
set abi = BlzGetUnitAbilityByIndex(UnitInfoUnit, SkillIndex[i])
if BlzGetAbilityBooleanField(abi, ABILITY_BF_HERO_ABILITY) then
set UnitInfoTooltipText = BlzGetAbilityStringLevelField(abi, ABILITY_SLF_TOOLTIP_LEARN, 0) + "\n" + BlzGetAbilityStringLevelField(abi, ABILITY_SLF_TOOLTIP_LEARN_EXTENDED, 0)
else
set UnitInfoTooltipText = BlzGetAbilityStringLevelField(abi, ABILITY_SLF_TOOLTIP_NORMAL, 0) + "\n" + BlzGetAbilityStringLevelField(abi, ABILITY_SLF_TOOLTIP_NORMAL_EXTENDED, 0)
endif
exitwhen true
endif
set i = i - 1
endloop
set abi = null
endfunction
private function condition takes nothing returns boolean
return IsUnitOwnedByPlayer(UnitInfoUnit, Player(PLAYER_NEUTRAL_AGGRESSIVE))
endfunction
private function abiFilter takes ability abi, string text returns boolean
if BlzGetAbilityBooleanField(abi, ABILITY_BF_ITEM_ABILITY) then
return false
endif
if text == "Tool tip missing!" or text == "" or text == " " then
return false
endif
return true
endfunction
private function update takes nothing returns nothing
local ability abi
local integer buttonIndex = 1
local integer abiIndex = 0
local string text
loop
exitwhen buttonIndex > buttonCount
set abi = BlzGetUnitAbilityByIndex(UnitInfoUnit, abiIndex)
if abi != null then
set text = BlzGetAbilityStringLevelField(abi, ABILITY_SLF_TOOLTIP_NORMAL, 0)
if abiFilter(abi, text) then
set SkillIndex[buttonIndex] = abiIndex
call BlzFrameSetVisible(Button[buttonIndex], true)
call BlzFrameSetTexture(Icon[buttonIndex], BlzGetAbilityStringLevelField(abi, ABILITY_SLF_ICON_NORMAL, 0), 0, false)
call BlzFrameSetText(Text[buttonIndex], text)
set buttonIndex = buttonIndex + 1
endif
set abiIndex = abiIndex + 1
else
call BlzFrameSetVisible(Button[buttonIndex], false)
set buttonIndex = buttonIndex + 1
endif
endloop
endfunction
private function At0s takes nothing returns nothing
local integer i = buttonCount
set parent = BlzCreateSimpleFrame("CustomUnitInfoPanel2x4", BlzGetFrameByName("SimpleInfoPanelUnitDetail", 0), 0)
call AddUnitInfoPanel(parent, function update, function condition)
loop
exitwhen i == 0
set Button[i] = BlzGetFrameByName("CustomUnitInfoButton" + I2S(i), 0)
set ToolTip[i] = BlzCreateFrameByType("SIMPLEFRAME", "", Button[i], "", 0)
set Icon[i] = BlzGetFrameByName("CustomUnitInfoButtonIcon" + I2S(i), 0)
set Text[i] = BlzGetFrameByName("CustomUnitInfoButtonText" + I2S(i), 0)
call BlzTriggerRegisterFrameEvent(buttonTrigger, Button[i], FRAMEEVENT_CONTROL_CLICK)
call BlzFrameSetTooltip(Button[i], ToolTip[i])
call BlzFrameSetVisible(ToolTip[i], false)
call UnitInfoPanelAddTooltipListener(ToolTip[i], function tooltipAction)
set i = i - 1
endloop
endfunction
private function init_function takes nothing returns nothing
call TimerStart(CreateTimer(), 0, false, function At0s)
call TriggerAddAction(buttonTrigger, function buttonAction)
call FrameLoaderAdd(function At0s)
endfunction
endlibrary