Name | Type | is_array | initial_value |
TasItemBagEquipNow | boolean | No | |
TasItemBagItem | itemcode | No | |
TasItemBagNeedSkill | trigger | No | |
TasItemBagSkill | abilcode | No |
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
One map, one hashtable. Welcome to NewTable 4.1.0.1
This newest iteration of Table introduces the new HashTable struct.
You can now instantiate HashTables which enables the use of large
parent and large child keys, just like a standard hashtable. Previously,
the user would have to instantiate a Table to do this on their own which -
while doable - is something the user should not have to do if I can add it
to this resource myself (especially if they are inexperienced).
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array
//Enables myHash[parentKey][childKey] syntax.
//Basically, it creates a Table in the place of the parent key if
//it didn't already get created earlier.
method operator [] takes integer index returns Table
local Table t = Table(this)[index]
if t == 0 then
set t = Table.create()
set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
endif
return t
endmethod
//You need to call this on each parent key that you used if you
//intend to destroy the HashTable or simply no longer need that key.
method remove takes integer index returns nothing
local Table t = Table(this)[index]
if t != 0 then
call t.destroy()
call Table(this).remove(index)
endif
endmethod
//Added in version 4.1
method has takes integer index returns boolean
return Table(this).has(index)
endmethod
//HashTables are just fancy Table indices.
method destroy takes nothing returns nothing
call Table(this).destroy()
endmethod
//Like I said above...
static method create takes nothing returns thistype
return Table.create()
endmethod
endstruct
endlibrary
library TasItemBag initializer init_function requires Table
/* TasItemBag 1.3
by Tasyen
Allows units to carry additional items in a bag. Items in the bag do not give any boni.
The Items in the bag are displayed in a scrollable UI which is opened/closed by a button.
Items from the bag can be equiped or droped.
Equiping an item moves the item from the bag into the warcraft 3 inventory.
When the unit fullfils the Requirments to use it.
TasItemBag puts all items gained into the bag, instead of the inventory.
The items still trigger a pickup&drop Event.
Affected by HeroScoreFrame-Options, if found in the same map
Requires:
Table by Bribe https://www.hiveworkshop.com/threads/snippet-new-table.188084/
war3mapImported\TasItemBag.fdf
war3mapImported\TasItemBag.toc
*/
globals
private real PosX = 0.4
private real PosY = 0.57
private framepointtype Pos = FRAMEPOINT_TOP
private integer Cols = 6
private integer Rows = 4
private real ShowButtonPosX = 0.48
private real ShowButtonPosY = 0.145
private framepointtype ShowButtonPos = FRAMEPOINT_TOPLEFT
private string ShowButtonTexture = "ReplaceableTextures/CommandButtons/BTNDustOfAppearance"
private string ShowButtonTextureDisabled = "ReplaceableTextures/CommandButtonsDisabled/DISBTNDustOfAppearance"
// show the showButton only when the inventory is shown?
public boolean ShowButtonNeedsInventory = true
// showButton closes the UI when clicked while the UI is shown?
public boolean ShowButtonCloses = true
private real TooltipWidth = 0.27
public real TooltipScale = 1.0
public boolean TooltipFixedPosition = true
private real TooltipFixedPositionX = 0.79
private real TooltipFixedPositionY = 0.16
private framepointtype TooltipFixedPositionPoint = FRAMEPOINT_BOTTOMRIGHT
public boolean MoveUsedItemsIntoBag = false
// Can drop Items from the TasItemBag regardless of item/Inventory Flags
public boolean IgnoreUndropAble = true
// Units with the Locust skill do not move gained items into the bag
public boolean IgnoreDummy = true
private integer DummySkill = 'Aloc'
// DestroyUndropAbleItems = true, When by death an undropable item would have to be droped from the TasItemBag, it is destroyed.
private boolean DestroyUndropAbleItems = true
// ItemBagSize is the maximum amount of items, an unit can carry in the bag, additional items are droped on pickup
private integer ItemBagSize = 9999
// can Equip only EquipClassLimit of one Item Class at one time
public integer EquipClassLimit = 999
// InventorySkills are the Inventory Abilities in the used map
// They are used for drop on death
public integer array InventorySkills
// An unit that can not use Items (cause of it's inventory skills) does not need to fullfill the requirments
private boolean IgnoreNeedWhenCanNotUse = true
// Display the requirements in the Item Tooltip
public boolean AddNeedText = true
// ItemLevelRestriction = true; only a hero which level is equal or higher to the item's level can equip it
private boolean ItemLevelRestriction = true
//itemCode Require the unit to have ability X to equip
//itemCode = AbilityCode
public Table ItemAbilityNeed
public Table ItemIsInBag
public HashTable BagItem
private abilityintegerlevelfield AbilityFieldDrop
private abilityintegerlevelfield AbilityFieldUse
private abilityintegerlevelfield AbilityFieldCanDrop
public timer TimerUpdate
public trigger Trigger
public trigger TriggerESC
public trigger TriggerItemGain
public trigger TriggerItemUse
public trigger TriggerUnitDeath
public trigger TriggerUIOpen
public trigger TriggerUIClose
public trigger TriggerUIBagButton
public trigger TriggerUISlider
public trigger TriggerUIWheel
public trigger TriggerUIEquip
public trigger TriggerUIDrop
public trigger TriggerUISwap
// TransferItem remembers the current Target
public item array TransferItem
public integer array TransferIndex
public integer array SwapIndex
public integer array Offset
public unit array Selected
// The UI moves all picked up items into the bag, RpgCustomUI.EquipNow = true prevents that
public boolean EquipNow = false
private unit array ItemGainTimerUnit
private timer ItemGainTimer
private item array ItemGainTimerItem
private integer ItemGainTimerCount = 0
endglobals
private function UserInit takes nothing returns nothing
set InventorySkills[0] = 'AInv'
set InventorySkills[1] = 'Apak'
set InventorySkills[2] = 'Aiun'
set InventorySkills[3] = 'Aien'
set InventorySkills[4] = 'Aihn'
set InventorySkills[5] = 'Aion'
endfunction
function TasItemBagAddItem takes unit u, item i returns nothing
local integer unitHandle = GetHandleId(u)
call SetItemPosition(i, GetUnitX(u), GetUnitY(u))
if not ItemIsInBag.boolean[GetHandleId(i)] and BagItem[unitHandle].integer[0] < ItemBagSize then
set BagItem[unitHandle].integer[0] = BagItem[unitHandle].integer[0] + 1
set ItemIsInBag.boolean[GetHandleId(i)] = true
call SetItemVisible(i, false)
set BagItem[unitHandle].item[BagItem[unitHandle].integer[0]] = i
elseif ItemIsInBag.boolean[GetHandleId(i)] then
call SetItemVisible(i, false)
endif
endfunction
function TasItemBagGetItem takes unit u, integer index returns item
local integer unitHandle = GetHandleId(u)
if BagItem[unitHandle].integer[0] <= 0 then
return null
endif
return BagItem[unitHandle].item[index]
endfunction
function TasItemBagSwap takes unit u, integer indexA, integer indexB returns boolean
local integer unitHandle = GetHandleId(u)
local item i
local item i2
if BagItem[unitHandle].integer[0] <= 0 then
return false
endif
if indexA <= 0 or indexB <= 0 then
return false
endif
set i = BagItem[unitHandle].item[indexA]
set i2 = BagItem[unitHandle].item[indexB]
if GetHandleId(i) > 0 and GetHandleId(i2) > 0 then
set BagItem[unitHandle].item[indexB] = i
set BagItem[unitHandle].item[indexA] = i2
set i = null
set i2 = null
return true
endif
set i = null
set i2 = null
return false
endfunction
function TasItemBagRemoveIndex takes unit u , integer index, boolean drop returns boolean
local item i
local integer unitHandle = GetHandleId(u)
if BagItem[unitHandle].integer[0] <= 0 then
return false
endif
set i = BagItem[unitHandle].item[index]
set BagItem[unitHandle].item[index] = BagItem[unitHandle].item[BagItem[unitHandle].integer[0]]
set BagItem[unitHandle].item[BagItem[unitHandle].integer[0]] = null
set BagItem[unitHandle].integer[0] = BagItem[unitHandle].integer[0] - 1
set ItemIsInBag.boolean[GetHandleId(i)] = false
if drop and GetHandleId(i) > 0 then
call SetItemPosition(i, GetUnitX(u), GetUnitY(u))
call SetItemVisible(i, true)
set i = null
return true
endif
set i = null
return false
endfunction
function TasItemBagRemoveItem takes unit u , item i, boolean drop returns boolean
local integer unitHandle = GetHandleId(u)
local integer loopA = BagItem[unitHandle].integer[0]
if loopA <= 0 then
return false
endif
// loop all items in the bag and remove it if found
loop
exitwhen loopA <= 0
if BagItem[unitHandle].item[loopA] == i then
call TasItemBagRemoveIndex(u, loopA, drop)
return true
endif
set loopA = loopA - 1
endloop
return false
endfunction
private function FrameLoseFocus takes nothing returns nothing
if GetLocalPlayer() == GetTriggerPlayer() then
call BlzFrameSetEnable(BlzGetTriggerFrame(), false)
call BlzFrameSetEnable(BlzGetTriggerFrame(), true)
endif
endfunction
public function TasItemBagUnitCanUseItems takes unit u returns boolean
// check all Inventory skills for the USE flag
local integer i = 0
loop
exitwhen InventorySkills[i] == 0
if GetUnitAbilityLevel(u, InventorySkills[i]) > 0 and BlzGetAbilityIntegerLevelField(BlzGetUnitAbility(u, InventorySkills[i]), AbilityFieldUse, 0) > 0 then
return true
endif
set i = i + 1
endloop
return false
endfunction
public function TasItemBagUnitIsDropItems takes unit u returns boolean
// check all Inventory skills for the DROP flag
local integer i = 0
loop
exitwhen InventorySkills[i] == 0
if GetUnitAbilityLevel(u, InventorySkills[i]) > 0 and BlzGetAbilityIntegerLevelField(BlzGetUnitAbility(u, InventorySkills[i]), AbilityFieldDrop, 0) > 0 then
return true
endif
set i = i + 1
endloop
return false
endfunction
private function DropsOnDeath takes unit u returns boolean
local integer i = 0
if not IsUnitType(u, UNIT_TYPE_HERO) then
return true
endif
if TasItemBagUnitIsDropItems(u) then
return true
endif
return false
endfunction
private function CountItemsOfClass takes unit u, itemtype itemClass returns integer
local integer count = 0
local integer i = 0
loop
exitwhen i >= bj_MAX_INVENTORY
if GetItemType(UnitItemInSlot(u, i)) == itemClass then
set count = count + 1
endif
set i = i + 1
endloop
return count
endfunction
private function UnitCanDropItems takes unit u returns boolean
// check all Inventory skills for the DROP flag
local integer i = 0
loop
exitwhen InventorySkills[i] == 0
if GetUnitAbilityLevel(u, InventorySkills[i]) > 0 and BlzGetAbilityIntegerLevelField(BlzGetUnitAbility(u, InventorySkills[i]), AbilityFieldCanDrop, 0) == 0 then
return false
endif
set i = i + 1
endloop
return true
endfunction
private function CanDropItem takes item it returns boolean
return BlzGetItemBooleanField(it, ITEM_BF_CAN_BE_DROPPED)
endfunction
private function UnitCanEquipItem takes unit u , item i returns boolean
// don't use returns, to display all errors
local boolean returnValue = true
local integer itemCode = GetItemTypeId(i)
// units that can not use items, ignore requirements hence return true when not
local boolean canUse = false
local integer loopA = 0
if IgnoreNeedWhenCanNotUse and not TasItemBagUnitCanUseItems(u) then
return true
endif
// use Item Level as requirement. A lower Level can not equip it
if ItemLevelRestriction and TasItemBagUnitCanUseItems(u) and GetUnitLevel(u) < GetItemLevel(i) then
call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 20, GetItemName(i)+" needs "+GetLocalizedString("LEVEL")+" "+ I2S(GetItemLevel(i)))
set returnValue = false
endif
// itemCode can require an ability
if ItemAbilityNeed[itemCode] != 0 and GetUnitAbilityLevel(u, ItemAbilityNeed[itemCode]) == 0 then
call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 20, GetItemName(i)+" needs Ability "+ GetObjectName(ItemAbilityNeed[itemCode]))
set returnValue = false
endif
if EquipClassLimit <= CountItemsOfClass(u, GetItemType(i)) then
call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 20, "To many Items of this Item-Class")
return false
endif
return returnValue
endfunction
private function ItemBag2Equip takes unit u , item i returns nothing
// Inventory Full?
if UnitInventoryCount(u) >= UnitInventorySize(u) then
return
endif
// unit can equip this, restrictions
if not UnitCanEquipItem(u, i) then
return
endif
set EquipNow = true
if UnitAddItem(u, i) then
call TasItemBagRemoveItem(u, i, false)
endif
set EquipNow = false
endfunction
private function ItemEquip2Bag takes unit u , item i returns nothing
call TasItemBagAddItem(u, i)
endfunction
private function BagPopupActionDrop takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer pId = GetPlayerId(GetTriggerPlayer())
if GetPlayerAlliance(GetOwningPlayer(Selected[pId]), p, ALLIANCE_SHARED_CONTROL) then
if GetLocalPlayer() == p then
call BlzFrameSetVisible(BlzFrameGetParent(BlzGetTriggerFrame()), false)
endif
endif
call TasItemBagRemoveIndex(Selected[pId], TransferIndex[pId], true)
call FrameLoseFocus()
endfunction
private function BagPopupActionEquip takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer pId = GetPlayerId(GetTriggerPlayer())
if GetPlayerAlliance(GetOwningPlayer(Selected[pId]), p, ALLIANCE_SHARED_CONTROL) then
call ItemBag2Equip(Selected[pId], TransferItem[pId])
if GetLocalPlayer() == p then
call BlzFrameSetVisible(BlzFrameGetParent(BlzGetTriggerFrame()), false)
endif
endif
call FrameLoseFocus()
endfunction
private function BagPopupActionSwap takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer pId = GetPlayerId(GetTriggerPlayer())
if GetPlayerAlliance(GetOwningPlayer(Selected[pId]), p, ALLIANCE_SHARED_CONTROL) then
if GetLocalPlayer() == p then
call BlzFrameSetVisible(BlzFrameGetParent(BlzGetTriggerFrame()), false)
endif
set SwapIndex[pId] = TransferIndex[pId]
endif
call FrameLoseFocus()
endfunction
private function BagButtonAction takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer pId = GetPlayerId(GetTriggerPlayer())
local integer bagIndex = S2I(BlzFrameGetText(BlzGetTriggerFrame())) + Offset[pId]
if GetPlayerAlliance(GetOwningPlayer(Selected[pId]), p, ALLIANCE_SHARED_CONTROL) then
set TransferItem[pId] = BagItem[GetHandleId(Selected[pId])].item[bagIndex]
set TransferIndex[pId] = bagIndex
if SwapIndex[pId] > 0 then
call TasItemBagSwap(Selected[pId], bagIndex, SwapIndex[pId])
set SwapIndex[pId] = 0
elseif GetLocalPlayer() == p then
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), true)
call BlzFrameSetEnable(BlzGetFrameByName("TasItemBagPopUpButtonDrop", 0), IgnoreUndropAble or (UnitCanDropItems(Selected[pId]) and CanDropItem(TransferItem[pId])))
call BlzFrameSetPoint(BlzGetFrameByName("TasItemBagPopUpPanel", 0), FRAMEPOINT_TOPLEFT, BlzGetTriggerFrame(), FRAMEPOINT_TOPRIGHT, 0.005, 0)
endif
endif
call FrameLoseFocus()
endfunction
private function WheelAction takes nothing returns nothing
local boolean upwards = BlzGetTriggerFrameValue() > 0
if GetLocalPlayer() == GetTriggerPlayer() then
if upwards then
call BlzFrameSetValue(BlzGetFrameByName("TasItemBagSlider", 0), BlzFrameGetValue(BlzGetFrameByName("TasItemBagSlider", 0)) + 1)
else
call BlzFrameSetValue(BlzGetFrameByName("TasItemBagSlider", 0), BlzFrameGetValue(BlzGetFrameByName("TasItemBagSlider", 0)) - 1)
endif
endif
endfunction
private function CloseButtonAction takes nothing returns nothing
local integer pId = GetPlayerId(GetTriggerPlayer())
set SwapIndex[pId] = 0
set TransferIndex[pId] = 0
set TransferItem[pId] = null
if GetLocalPlayer() == GetTriggerPlayer() then
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
endif
call FrameLoseFocus()
endfunction
private function ShowButtonAction takes nothing returns nothing
local integer pId = GetPlayerId(GetTriggerPlayer())
set SwapIndex[pId] = 0
set TransferIndex[pId] = 0
set TransferItem[pId] = null
if GetLocalPlayer() == GetTriggerPlayer() then
if ShowButtonCloses and BlzFrameIsVisible(BlzGetFrameByName("TasItemBagPanel", 0)) then
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
else
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), true)
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
endif
endif
call FrameLoseFocus()
endfunction
private function SliderAction takes nothing returns nothing
set Offset[GetPlayerId(GetTriggerPlayer())] = R2I(BlzGetTriggerFrameValue()*Cols)
endfunction
private function SelectAction takes nothing returns nothing
local integer pId = GetPlayerId(GetTriggerPlayer())
set Selected[pId] = GetTriggerUnit()
set Offset[pId] = 0
endfunction
private function ESCAction takes nothing returns nothing
if GetLocalPlayer() == GetTriggerPlayer() then
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
endif
endfunction
private function ItemGainTimerAction takes nothing returns nothing
loop
exitwhen ItemGainTimerCount <= 0
if UnitHasItem(ItemGainTimerUnit[ItemGainTimerCount], ItemGainTimerItem[ItemGainTimerCount]) then
call ItemEquip2Bag(ItemGainTimerUnit[ItemGainTimerCount], ItemGainTimerItem[ItemGainTimerCount])
endif
set ItemGainTimerCount = ItemGainTimerCount - 1
endloop
endfunction
private function ItemGainAction takes nothing returns nothing
// dummies do not use the bag feature
if IgnoreDummy and GetUnitAbilityLevel(GetTriggerUnit(), DummySkill) > 0 then
return
endif
// Do not move Powerups that can be used into the bag
if IsItemPowerup(GetManipulatedItem()) and TasItemBagUnitCanUseItems(GetTriggerUnit()) then
return
endif
// GUI flag to ignore pick up 2 bag
static if LIBRARY_TasUnitBagGUI then
if udg_TasItemBagEquipNow then
return
endif
endif
//System flag to ignore pickup 2 bag
if not EquipNow then
// dont move it instantly, delay it with a 0s timer, this stops item pickup orders onto the same item in a row and allows the user to do some stuff to pickedup items
// does not prevent move ground pick up in rotation
set ItemGainTimerCount = ItemGainTimerCount + 1
set ItemGainTimerUnit[ItemGainTimerCount] = GetTriggerUnit()
set ItemGainTimerItem[ItemGainTimerCount] = GetManipulatedItem()
call TimerStart(ItemGainTimer, 0, false, function ItemGainTimerAction)
endif
endfunction
private function ItemUseAction takes nothing returns nothing
if IgnoreDummy and GetUnitAbilityLevel(GetTriggerUnit(), DummySkill) > 0 then
return
endif
if MoveUsedItemsIntoBag then
call ItemEquip2Bag(GetTriggerUnit(), GetManipulatedItem())
endif
endfunction
private function UnitDeathAction takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer unitHandle = GetHandleId(u)
local item i
local integer loopA
local boolean dropOnDeath
local boolean canDropItems
set loopA = BagItem[unitHandle].integer[0]
if loopA > 0 then
set dropOnDeath = DropsOnDeath(u)
set canDropItems = UnitCanDropItems(u)
loop
exitwhen loopA <= 0
set loopA = loopA - 1
set i = BagItem[unitHandle].item[loopA]
if dropOnDeath then
call TasItemBagRemoveIndex(u, loopA, true)
if DestroyUndropAbleItems and (not CanDropItem(i) or not canDropItems) then
call RemoveItem(i)
endif
endif
endloop
if not IsUnitType(u, UNIT_TYPE_HERO) then
call BagItem.remove(unitHandle)
endif
endif
set u = null
set i = null
endfunction
private function UpdateUI takes nothing returns nothing
local integer pId = GetPlayerId(GetLocalPlayer())
local integer unitHandle = GetHandleId(Selected[pId])
local integer itemCount = BagItem[unitHandle].integer[0]
local integer offset = Offset[pId]
local integer max
local integer itemCode
local item it
local string text = ""
local integer dataIndex
local integer i
// When the options from HeroScoreFrame are in this map use the tooltip&total scale slider
if GetHandleId(BlzGetFrameByName("HeroScoreFrameOptionsSlider1", 0)) > 0 then
set TooltipScale = BlzFrameGetValue(BlzGetFrameByName("HeroScoreFrameOptionsSlider1", 0))
endif
if GetHandleId(BlzGetFrameByName("HeroScoreFrameOptionsSlider3", 0)) > 0 then
call BlzFrameSetScale(BlzGetFrameByName("TasItemBagPanel", 0), BlzFrameGetValue(BlzGetFrameByName("HeroScoreFrameOptionsSlider3", 0)))
endif
call BlzFrameSetScale(BlzGetFrameByName("TasItemBagTooltipPanel", 0), TooltipScale)
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlot", 0), not ShowButtonNeedsInventory or BlzFrameIsVisible(BlzGetOriginFrame(ORIGIN_FRAME_ITEM_BUTTON, 0)))
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonOverLayText", 0), I2S(itemCount))
if BlzFrameIsVisible(BlzGetFrameByName("TasItemBagPanel", 0)) then
if itemCount > 0 then
// scroll by rows
set max = IMaxBJ(0, (itemCount+Cols - Cols*Rows)/Cols)
call BlzFrameSetMinMaxValue(BlzGetFrameByName("TasItemBagSlider", 0), 0, max)
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSliderTooltip", 0), I2S(R2I(offset/Cols))+"/"+I2S(max))
else
call BlzFrameSetMinMaxValue(BlzGetFrameByName("TasItemBagSlider", 0), 0, 0)
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSliderTooltip", 0), "")
endif
set i = 1
loop
exitwhen i > Cols*Rows
set dataIndex = i + offset
call BlzFrameSetEnable(BlzGetFrameByName("TasItemBagSlotButton", i), dataIndex <= itemCount)
if dataIndex <= itemCount then
set it = BagItem[unitHandle].item[dataIndex]
set itemCode = GetItemTypeId(it)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdrop", i), BlzGetAbilityIcon(itemCode) , 0, true)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdropPushed", i), BlzGetAbilityIcon(itemCode) , 0, true)
if AddNeedText then
set text = "|nNEED "+ GetLocalizedString("REQUIREDLEVELTOOLTIP")+" "+I2S(GetItemLevel(it))
if ItemAbilityNeed[itemCode] > 0 then
set text = text + "|nNEED "+ GetObjectName(ItemAbilityNeed[itemCode])
endif
endif
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonTooltip", i), GetObjectName(itemCode)+ "|n"+BlzGetAbilityExtendedTooltip(itemCode, 0) +"|n|n"+text)
if GetItemCharges(it) > 0 then
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonOverLayText", i), I2S(GetItemCharges(it)))
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlotButtonOverLay", i), true)
else
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlotButtonOverLay", i), false)
endif
else
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlotButtonOverLay", i), false)
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonTooltip", i), "")
endif
set i = i + 1
endloop
endif
set it = null
endfunction
private function CreateTextTooltip takes framehandle frame, string wantedframeName, integer wantedCreateContext, string text returns framehandle
// this FRAME is important when the Box is outside of 4:3 it can be limited to 4:3.
local framehandle toolTipParent = BlzCreateFrameByType("FRAME", "", BlzGetFrameByName("TasItemBagTooltipPanel", 0), "", 0)
local framehandle toolTipBox = BlzCreateFrame("TasToolTipBox", toolTipParent, 0, 0)
local framehandle toolTip = BlzCreateFrameByType("TEXT", wantedframeName, toolTipBox, "TasTooltipText", wantedCreateContext)
if TooltipFixedPosition then
call BlzFrameSetAbsPoint(toolTip, TooltipFixedPositionPoint, TooltipFixedPositionX, TooltipFixedPositionY)
else
call BlzFrameSetPoint(toolTip, FRAMEPOINT_TOP, frame, FRAMEPOINT_BOTTOM, 0, -0.008)
endif
call BlzFrameSetPoint(toolTipBox, FRAMEPOINT_TOPLEFT, toolTip, FRAMEPOINT_TOPLEFT, -0.008, 0.008)
call BlzFrameSetPoint(toolTipBox, FRAMEPOINT_BOTTOMRIGHT, toolTip, FRAMEPOINT_BOTTOMRIGHT, 0.008, -0.008)
call BlzFrameSetText(toolTip, text)
call BlzFrameSetTooltip(frame, toolTipParent)
call BlzFrameSetSize(toolTip, TooltipWidth, 0)
return toolTip
endfunction
private function InitFrames takes nothing returns nothing
local boolean loaded = BlzLoadTOCFile("war3mapImported/TasItemBag.toc")
local framehandle panel
local framehandle frame
local framehandle frame2
local framehandle frame3
local integer count = 0
local integer buttonIndex = 0
local boolean backup
set panel = BlzCreateFrameByType("BUTTON", "TasItemBagPanel", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(panel, Pos, PosX, PosY)
call BlzFrameSetAllPoints(BlzCreateFrame("TasItemBagBox", panel, 0, 0), panel)
call BlzTriggerRegisterFrameEvent(TriggerUIWheel, panel, FRAMEEVENT_MOUSE_WHEEL)
call BlzCreateFrameByType("BUTTON", "TasItemBagTooltipPanel", panel, "", 0)
// Custom Bag
set count = 0
set buttonIndex = 1
loop
exitwhen buttonIndex > Rows*Cols
set frame = BlzCreateFrame("TasItemBagSlot", panel, 0, buttonIndex)
call BlzGetFrameByName("TasItemBagSlotButton", buttonIndex)
call BlzGetFrameByName("TasItemBagSlotButtonBackdrop", buttonIndex)
call BlzGetFrameByName("TasItemBagSlotButtonBackdropDisabled", buttonIndex)
call BlzGetFrameByName("TasItemBagSlotButtonBackdropPushed", buttonIndex)
call BlzGetFrameByName("TasItemBagSlotButtonOverLay", buttonIndex)
call BlzGetFrameByName("TasItemBagSlotButtonOverLayText", buttonIndex)
call CreateTextTooltip(BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), "TasItemBagSlotButtonTooltip", buttonIndex, "")
call BlzTriggerRegisterFrameEvent(TriggerUIBagButton, BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), FRAMEEVENT_CONTROL_CLICK)
call BlzTriggerRegisterFrameEvent(TriggerUIWheel, BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), FRAMEEVENT_MOUSE_WHEEL)
call BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), I2S(buttonIndex))
set count = count + 1
if count > Cols then
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("TasItemBagSlot", buttonIndex - Cols), FRAMEPOINT_BOTTOMLEFT, 0, -0.002)
set count = 1
elseif buttonIndex > 1 then
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("TasItemBagSlot", buttonIndex - 1), FRAMEPOINT_TOPRIGHT, 0.002, 0)
endif
set buttonIndex = buttonIndex + 1
endloop
if GetHandleId(frame) == 0 then
call BJDebugMsg("Error - Creating TasItemBagSlot")
endif
call BlzFrameSetSize(panel, BlzFrameGetWidth(frame)*Cols + (Cols - 1)*0.002 + 0.02, BlzFrameGetHeight(frame)*Rows + (Rows - 1)*0.002 + 0.012)
call BlzFrameSetPoint(BlzGetFrameByName("TasItemBagSlot", 1), FRAMEPOINT_TOPLEFT, panel, FRAMEPOINT_TOPLEFT, 0.006, -0.006)
set frame = BlzCreateFrameByType("SLIDER", "TasItemBagSlider", panel, "QuestMainListScrollBar", 0)
call BlzFrameClearAllPoints(frame)
call BlzFrameSetPoint(frame, FRAMEPOINT_BOTTOMRIGHT, panel, FRAMEPOINT_BOTTOMRIGHT, -0.004, 0.008)
call BlzFrameSetSize(frame, BlzFrameGetWidth(frame), BlzFrameGetHeight(panel) - 0.02)
//BlzFrameSetStepSize(frame, Cols)
set backup = TooltipFixedPosition
set TooltipFixedPosition = false
call CreateTextTooltip(frame, "TasItemBagSliderTooltip", 0, "")
call BlzFrameSetSize(BlzGetFrameByName("TasItemBagSliderTooltip", 0), 0, 0)
set TooltipFixedPosition = backup
call BlzTriggerRegisterFrameEvent(TriggerUIWheel, frame, FRAMEEVENT_MOUSE_WHEEL)
call BlzTriggerRegisterFrameEvent(TriggerUISlider, frame, FRAMEEVENT_SLIDER_VALUE_CHANGED)
// show Buttons
set frame = BlzCreateFrame("TasItemBagSlot", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 0, 0)
call BlzFrameSetAbsPoint(frame, ShowButtonPos, ShowButtonPosX, ShowButtonPosY)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdrop", 0), ShowButtonTexture, 0, false)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdropDisabled", 0), ShowButtonTextureDisabled, 0, false)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdropPushed", 0), ShowButtonTexture, 0, false)
call BlzGetFrameByName("TasItemBagSlotButtonOverLay", 0)
call BlzGetFrameByName("TasItemBagSlotButtonOverLayText", 0)
call BlzTriggerRegisterFrameEvent(TriggerUIOpen, BlzGetFrameByName("TasItemBagSlotButton", 0), FRAMEEVENT_CONTROL_CLICK)
call BlzFrameSetEnable(BlzGetFrameByName("TasItemBagSlotButton", 0), true)
set frame = BlzCreateFrameByType("GLUETEXTBUTTON", "TasItemBagCloseButton", panel, "ScriptDialogButton", 0)
call BlzFrameSetSize(frame, 0.03, 0.03)
call BlzFrameSetText(frame, "X")
call BlzFrameSetPoint(frame, FRAMEPOINT_CENTER, BlzFrameGetParent(frame), FRAMEPOINT_TOPRIGHT, -0.002, -0.002)
call BlzTriggerRegisterFrameEvent(TriggerUIClose, frame, FRAMEEVENT_CONTROL_CLICK)
// BlzFrameClick(BlzGetFrameByName("TasItemBagCloseButton", 0))
call BlzFrameSetLevel(BlzGetFrameByName("TasItemBagTooltipPanel", 0), 8)
// Bag Popup
set frame = BlzCreateFrameByType("BUTTON", "TasItemBagPopUpPanel", panel, "", 0)
call BlzFrameSetLevel(frame, 9)
call BlzFrameSetSize(frame, 0.1, 0.0001)
set frame2 = BlzCreateFrameByType("GLUETEXTBUTTON", "TasItemBagPopUpButtonEquip", frame, "ScriptDialogButton", 0)
call BlzFrameSetSize(frame2, 0.1, 0.03)
call BlzFrameSetPoint(frame2, FRAMEPOINT_TOPLEFT, frame, FRAMEPOINT_TOPLEFT, 0, 0)
call BlzFrameSetText(frame2, "EQUIP")
call BlzTriggerRegisterFrameEvent(TriggerUIEquip, frame2, FRAMEEVENT_CONTROL_CLICK)
set frame3 = BlzCreateFrameByType("GLUETEXTBUTTON", "TasItemBagPopUpButtonDrop", frame, "ScriptDialogButton", 0)
call BlzFrameSetSize(frame3, 0.1, 0.03)
call BlzFrameSetPoint(frame3, FRAMEPOINT_TOPLEFT, frame2, FRAMEPOINT_BOTTOMLEFT, 0, 0)
call BlzFrameSetText(frame3, "DROP")
call BlzTriggerRegisterFrameEvent(TriggerUIDrop, frame3, FRAMEEVENT_CONTROL_CLICK)
set frame2 = BlzCreateFrameByType("GLUETEXTBUTTON", "TasItemBagPopUpButtonSwap", frame, "ScriptDialogButton", 0)
call BlzFrameSetSize(frame2, 0.1, 0.03)
call BlzFrameSetPoint(frame2, FRAMEPOINT_TOPLEFT, frame3, FRAMEPOINT_BOTTOMLEFT, 0, 0)
call BlzFrameSetText(frame2, "SWAP")
call BlzTriggerRegisterFrameEvent(TriggerUISwap, frame2, FRAMEEVENT_CONTROL_CLICK)
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
call BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
endfunction
private function At0s takes nothing returns nothing
local integer i
set AbilityFieldDrop = ConvertAbilityIntegerLevelField('inv2')
set AbilityFieldUse = ConvertAbilityIntegerLevelField('inv3')
set AbilityFieldCanDrop = ConvertAbilityIntegerLevelField('inv5')
set ItemAbilityNeed = Table.create()
set ItemIsInBag = Table.create()
set BagItem = HashTable.create()
set TimerUpdate = CreateTimer()
call TimerStart(TimerUpdate, 0.1, true, function UpdateUI)
set Trigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Trigger, EVENT_PLAYER_UNIT_SELECTED)
call TriggerAddAction(Trigger, function SelectAction)
set TriggerESC = CreateTrigger()
set i = 0
loop
call BlzTriggerRegisterPlayerKeyEvent(TriggerESC, Player(i), OSKEY_ESCAPE, 0, true)
set i = i + 1
exitwhen i >= bj_MAX_PLAYERS
endloop
call TriggerAddAction(TriggerESC, function ESCAction)
set TriggerItemGain = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(TriggerItemGain, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddAction(TriggerItemGain, function ItemGainAction)
set TriggerItemUse = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(TriggerItemUse, EVENT_PLAYER_UNIT_USE_ITEM)
call TriggerAddAction(TriggerItemUse, function ItemUseAction)
set TriggerUnitDeath = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(TriggerUnitDeath, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(TriggerUnitDeath, function UnitDeathAction)
set TriggerUIOpen = CreateTrigger()
call TriggerAddAction(TriggerUIOpen, function ShowButtonAction)
set TriggerUIClose = CreateTrigger()
call TriggerAddAction(TriggerUIClose, function CloseButtonAction)
set TriggerUIBagButton = CreateTrigger()
call TriggerAddAction(TriggerUIBagButton, function BagButtonAction)
set TriggerUISlider = CreateTrigger()
call TriggerAddAction(TriggerUISlider, function SliderAction)
set TriggerUIWheel = CreateTrigger()
call TriggerAddAction(TriggerUIWheel, function WheelAction)
set TriggerUIEquip = CreateTrigger()
call TriggerAddAction(TriggerUIEquip, function BagPopupActionEquip)
set TriggerUIDrop = CreateTrigger()
call TriggerAddAction(TriggerUIDrop, function BagPopupActionDrop)
set TriggerUISwap = CreateTrigger()
call TriggerAddAction(TriggerUISwap, function BagPopupActionSwap)
call UserInit()
call InitFrames()
static if LIBRARY_FrameLoader then
call FrameLoaderAdd(function InitFrames)
endif
endfunction
private function init_function takes nothing returns nothing
set ItemGainTimer = CreateTimer()
call TimerStart(ItemGainTimer, 0, false, function At0s)
endfunction
endlibrary
--[[ TasFrameAction by Tasyen
TasFrameAction is an Lua system to not have to care about Trigger and FrameEvents for FrameAction. All FrameEvents are binded to one trigger that trigger than calls the action for
handles frame Events in one trigger, care only about the actionFunction itself.
calls give Actions inside xpcall.
Supports only one Action per Event+Frame
Example
TasSliderAction(sliderFrame, function(frame, player, value)
print(BlzFrameGetName(frame), GetPlayerId(player), value)
end)
TasButtonAction(frame, function(frame, player))
wrapper for TasFrameAction meant for BUTTON just ControlClick
Removes focus & StopCamera
takes FRAMEEVENT_CONTROL_CLICK from TasFrameAction for this frame
TasSliderAction(frame, function(frame, player, value))
action happens when a Value is set
TasSliderAction.AvoidPoll (true) skip actions with the same value in a row by 1 player
takes FRAMEEVENT_MOUSE_WHEEL and FRAMEEVENT_SLIDER_VALUE_CHANGED from TasFrameAction for this frame
TasEditBoxAction(frame[, actionEnter, actionEdit])
skip an action to not have one for that event
function(frame, player, text)
TasDialogAction(frame, function(frame, player, accept))
TasCheckBoxAction(frame, function(frame, player, checked))
TasFrameMouseMoveAction(frame, actionEnter(frame, player), actionLeave(frame, player), actionWheel(frame, player, upwards))
TasFrameMouseUpAction(frame, action(frame, player, rightClick)
Happens when the mouse click is released over frame
rightClick does not work probably during Paused Games
TasMenuAction(frame, function(frame, player, value))
for POPUPMENU
functions above use an entry in TasFrameAction
TasFrameAction(frame, action, frameEvent)
action = function(frame, player, value, text)
]]
TasFrameAction = setmetatable({
EVENTNAME= {
"CONTROL_CLICK", "MOUSE_ENTER", "MOUSE_LEAVE", "MOUSE_UP"
, "MOUSE_DOWN", "MOUSE_WHEEL", "CHECKBOX_CHECKED", "CHECKBOX_UNCHECKED"
, "EDITBOX_TEXT_CHANGED", "POPUPMENU_ITEM_CHANGED", "MOUSE_DOUBLECLICK", "SPRITE_ANIM_UPDATE"
, "SLIDER_VALUE_CHANGED", "DIALOG_CANCEL", "DIALOG_ACCEPT", "EDITBOX_ENTER"
}
,ERROR = function(x)
print("TasFrameAction - ERROR")
print("FrameName", BlzFrameGetName(BlzGetTriggerFrame()), TasFrameAction.EVENTNAME[GetHandleId(BlzGetTriggerFrameEvent())]
, "PlayerId:", GetPlayerId(GetTriggerPlayer())
-- , BlzGetTriggerFrameValue(), BlzGetTriggerFrameText()
)
print(x)
return x
end
}
,{
__call = function(table, frame, action, frameEvent)
-- first call?
if not TasFrameAction.Trigger then
-- FrameEventData
for i = 1, 16 do
TasFrameAction[ConvertFrameEventType(i)] = {}
end
-- yes, Create the Trigger and the click handler.
TasFrameAction.Trigger = CreateTrigger()
TriggerAddAction(TasFrameAction.Trigger, function()
local frame = BlzGetTriggerFrame()
local event = BlzGetTriggerFrameEvent()
-- call the action set for that frame&Event
if TasFrameAction[event][frame] then
xpcall(TasFrameAction[event][frame], TasFrameAction.ERROR, frame, GetTriggerPlayer(), BlzGetTriggerFrameValue(), BlzGetTriggerFrameText())
--TasFrameAction[event][frame](frame, GetTriggerPlayer(), BlzGetTriggerFrameValue(), BlzGetTriggerFrameText())
end
frame = nil
event = nil
end)
end
-- create the click event only when it does not exist yet.
if not TasFrameAction[frameEvent][frame] then
BlzTriggerRegisterFrameEvent(TasFrameAction.Trigger, frame, frameEvent)
end
-- Using [frameEvent][frame] brings a fixed amout of Tables.
TasFrameAction[frameEvent][frame] = action
end
})
TasSliderAction = setmetatable({
AvoidPoll = true
,WHEEL = function(frame, player, value, text)
if GetLocalPlayer() == player then
if value > 0 then
BlzFrameSetValue(frame, BlzFrameGetValue(frame) + 1)
else
BlzFrameSetValue(frame, BlzFrameGetValue(frame) - 1)
end
end
end
,VALUE = function(frame, player, value, text)
-- avoid Polling
if not TasSliderAction.AvoidPoll or TasSliderAction.AvoidPollData[player][frame] ~= value then
TasSliderAction.AvoidPollData[player][frame] = value
TasSliderAction[frame](frame, player, value)
end
end
}
,{__call = function(table, frame, action)
-- first call?
if not TasSliderAction.AvoidPollData then
TasSliderAction.AvoidPollData = {}
for i=0, bj_MAX_PLAYER_SLOTS - 1 do TasSliderAction.AvoidPollData[Player(i)] = __jarray(0.0) end
end
TasFrameAction(frame, TasSliderAction.WHEEL, FRAMEEVENT_MOUSE_WHEEL)
TasFrameAction(frame, TasSliderAction.VALUE, FRAMEEVENT_SLIDER_VALUE_CHANGED)
TasSliderAction[frame] = action
end
})
TasSliderAction.Set = TasSliderAction
TasButtonAction = setmetatable({
ACTION = function(frame, player, value, text)
-- remove Focus for the local clicking player
if player == GetLocalPlayer() then
BlzFrameSetEnable(frame, false)
BlzFrameSetEnable(frame, true)
StopCamera()
end
-- call the action set for that frame
TasButtonAction[frame](frame, player)
end
},{
__call = function(table, frame, action)
TasFrameAction(frame, TasButtonAction.ACTION, FRAMEEVENT_CONTROL_CLICK)
TasButtonAction[frame] = action
end
})
TasButtonAction.Set = TasButtonAction
TasEditBoxAction = setmetatable({
A = {}
,B = {}
,ENTER = function(frame, player, value, text)
TasEditBoxAction.A[frame](frame, player, text)
end
,EDIT = function(frame, player, value, text)
TasEditBoxAction.B[frame](frame, player, text)
end
},{
__call = function(table, frame, actionEnter, actionEdit)
if actionEnter then
TasFrameAction(frame, TasEditBoxAction.ENTER, FRAMEEVENT_EDITBOX_ENTER)
TasEditBoxAction.A[frame] = actionEnter
end
if actionEdit then
TasFrameAction(frame, TasEditBoxAction.EDIT, FRAMEEVENT_EDITBOX_TEXT_CHANGED)
TasEditBoxAction.B[frame] = actionEdit
end
end
})
TasEditBoxAction.Set = TasEditBoxAction
TasDialogAction = setmetatable({
ACTION = function(frame, player)
TasDialogAction[frame](frame, player, BlzGetTriggerFrameEvent() == FRAMEEVENT_DIALOG_ACCEPT)
end
},{
__call = function(table, frame, action)
TasFrameAction(frame, TasDialogAction.ACTION, FRAMEEVENT_DIALOG_ACCEPT)
TasFrameAction(frame, TasDialogAction.ACTION, FRAMEEVENT_DIALOG_CANCEL)
TasDialogAction[frame] = action
end
})
TasDialogAction.Set = TasDialogAction
TasCheckBoxAction = setmetatable({
ACTION = function(frame, player)
TasCheckBoxAction[frame](frame, player, BlzGetTriggerFrameEvent() == FRAMEEVENT_CHECKBOX_CHECKED)
end
},{
__call = function(table, frame, action)
TasFrameAction(frame, TasCheckBoxAction.ACTION, FRAMEEVENT_CHECKBOX_CHECKED)
TasFrameAction(frame, TasCheckBoxAction.ACTION, FRAMEEVENT_CHECKBOX_UNCHECKED)
TasCheckBoxAction[frame] = action
end
})
TasCheckBoxAction.Set = TasCheckBoxAction
TasFrameMouseMoveAction = setmetatable({
A = {}
,B = {}
,C = {}
,ENTER = function(frame, player)
TasFrameMouseMoveAction.A[frame](frame, player)
end
,LEAVE = function(frame, player)
TasFrameMouseMoveAction.B[frame](frame, player)
end
,WHEEL = function(frame, player, value)
TasFrameMouseMoveAction.C[frame](frame, player, value > 0)
end
},{
__call = function(table, frame, actionEnter, actionLeave, actionWheel)
if actionEnter then
TasFrameAction(frame, TasFrameMouseMoveAction.ENTER, FRAMEEVENT_MOUSE_ENTER)
TasFrameMouseMoveAction.A[frame] = actionEnter
end
if actionLeave then
TasFrameAction(frame, TasFrameMouseMoveAction.LEAVE, FRAMEEVENT_MOUSE_LEAVE)
TasFrameMouseMoveAction.B[frame] = actionLeave
end
if actionWheel then
TasFrameAction(frame, TasFrameMouseMoveAction.WHEEL, FRAMEEVENT_MOUSE_WHEEL)
TasFrameMouseMoveAction.C[frame] = actionWheel
end
end
})
TasFrameMouseMoveAction.Set = TasFrameMouseMoveAction
TasFrameMouseUpAction = setmetatable({
TriggerCount = 0
,ACTION = function(frame, player)
-- during Pause EVENT_PLAYER_MOUSE_UP does not work, -> when The counter didn't increase since last Time do not allow this count as right click
local clickWorked = GetTriggerExecCount(TasFrameMouseUpAction.MouseTrigger) > TasFrameMouseUpAction.TriggerCount
TasFrameMouseUpAction[frame](frame, player, TasFrameMouseUpAction.RightClick[player] and clickWorked)
TasFrameMouseUpAction.TriggerCount = GetTriggerExecCount(TasFrameMouseUpAction.MouseTrigger)
end
},{
__call = function(table, frame, action)
if not TasFrameMouseUpAction.MouseTrigger then
TasFrameMouseUpAction.RightClick = __jarray(false)
TasFrameMouseUpAction.MouseTrigger = CreateTrigger()
for i = 0, bj_MAX_PLAYERS - 1 do
TriggerRegisterPlayerEvent(TasFrameMouseUpAction.MouseTrigger, Player(i), EVENT_PLAYER_MOUSE_UP)
end
TriggerAddAction(TasFrameMouseUpAction.MouseTrigger, function()
TasFrameMouseUpAction.RightClick[GetTriggerPlayer()] = GetHandleId(BlzGetTriggerPlayerMouseButton()) == GetHandleId(MOUSE_BUTTON_TYPE_RIGHT)
end)
end
TasFrameAction(frame, TasFrameMouseUpAction.ACTION, FRAMEEVENT_MOUSE_UP)
TasFrameMouseUpAction[frame] = action
end
})
TasFrameMouseUpAction.Set = TasFrameMouseUpAction
TasMenuAction = setmetatable({
ACTION = function(frame, player, value)
TasMenuAction[frame](frame, player, value)
end
},{
__call = function(table, frame, action)
TasFrameAction(frame, TasMenuAction.ACTION, FRAMEEVENT_POPUPMENU_ITEM_CHANGED)
TasMenuAction[frame] = action
end
})
TasMenuAction.Set = TasMenuAction
do
--[[
TasItemBag 1.3
by Tasyen
Allows units to carry additional items in a bag. Items in the bag do not give any boni.
The Items in the bag are displayed in a scrollable UI which is opened/closed by a button.
Items from the bag can be equiped or droped.
Equiping an item moves the item from the bag into the warcraft 3 inventory.
When the unit fullfils the Requirments to use it.
TasItemBag puts all items gained into the bag, instead of the inventory.
The items still trigger a pickup&drop Event.
Affected by HeroScoreFrame-Options, if found in the same map
Requires:
TasFrameAction
war3mapImported\TasItemBag.fdf
war3mapImported\TasItemBag.toc
]]
TasItemBag = {
PosX = 0.4
,PosY = 0.57
,Pos = FRAMEPOINT_TOP
,Cols = 6
,Rows = 4
,ShowButtonPosX = 0.48
,ShowButtonPosY = 0.145
,ShowButtonPos = FRAMEPOINT_TOPLEFT
,ShowButtonTexture = "ReplaceableTextures/CommandButtons/BTNDustOfAppearance"
,ShowButtonTextureDisabled = "ReplaceableTextures/CommandButtonsDisabled/DISBTNDustOfAppearance"
-- show the showButton only when the inventory is shown?
,ShowButtonNeedsInventory = true
-- showButton closes the UI when clicked while the UI is shown?
,ShowButtonCloses = true
,TooltipWidth = 0.27
,TooltipScale = 1.0
,TooltipFixedPosition = true
,TooltipFixedPositionX = 0.79
,TooltipFixedPositionY = 0.16
,TooltipFixedPositionPoint = FRAMEPOINT_BOTTOMRIGHT
-- TODO --
-- Makes many warcraft 3 Inventory API interact with TasItemBag.
-- for slot/index based calls TasItemBag adds itself after it 0 to 5 are default 6 and higher are inside the bag
-- overwrites UnitRemoveItemFromSlot, UnitItemInSlot, UnitHasItem, UnitRemoveItem.
-- beaware that using this feature is quite costly right now, don't overdo it with ItemBagSize
,UpgradeInventoryAPI = false
-- backup for the default Inventory Size
,DefaultInventorySize = bj_MAX_INVENTORY
-- TODO --
,MoveUsedItemsIntoBag = false
-- Can drop Items from the TasItemBag regardless of item/Inventory Flags
,IgnoreUndropAble = true
-- Units with the Locust skill do not move gained items into the bag
,IgnoreDummy = true
,DummySkill = FourCC('Aloc')
-- When by death an undropable item (either by Item or Inventory) would have to be droped from the TasItemBag, it is destroyed.
,DestroyUndropAbleItems = false
-- ItemBagSize is the maximum amount of items, an unit can carry in the bag, additional items are droped on pickup
,ItemBagSize = 9999
-- can Equip only EquipClassLimit of one Item Class at one time
,EquipClassLimit = 999
-- InventorySkills are the Inventory Abilities in the used map
-- They are used for drop on death
,InventorySkills = {
'AInv','Apak','Aiun','Aien','Aihn','Aion'
}
-- Display the requirements in the Item Tooltip
,AddNeedText = true
-- An unit that can not use Items (cause of it's inventory skills) does not need to fullfill the requirments
,IgnoreNeedWhenCanNotUse = true
-- ItemLevelRestriction = true; only a hero which level is equal or higher to the item's level can equip it
,ItemLevelRestriction = true
--itemCode Require the unit to have ability X to equip
--itemCode = AbilityCode
,ItemAbilityNeed = {
-- [FourCC('bgst')] = FourCC('AHbz')
-- ratf = 'AHbz'
-- Format 2 is converted into format 1 when the init runs.
}
-- The UI moves all picked up items into the bag, RpgCustomUI.EquipNow = true prevents that
,EquipNow = false
-- TransferItem remembers the current Target
,TransferItem = {}
,Selected = {}
,Offset = __jarray(0)
,TransferIndex = __jarray(0)
,SwapIndex = __jarray(0)
}
local this = TasItemBag
function TasItemBagAddItem(unit, item)
if not this[unit] then this[unit] = {} end
SetItemPosition(item, GetUnitX(unit), GetUnitY(unit))
if not this[item] and (not this.ItemBagSize or #this[unit] < this.ItemBagSize) then
SetItemVisible(item, false)
this[item] = true
table.insert(this[unit], item)
elseif this[item] then
SetItemVisible(item, false)
end
end
function TasItemBagGetItem(unit, index)
if not this[unit] then return nil end
return this[unit][index]
end
function TasItemBagRemoveIndex(unit, index, drop)
if not this[unit] then return false end
local item = table.remove(this[unit], index)
this[item] = nil
if drop and GetHandleId(item) > 0 then
SetItemVisible(item, true)
SetItemPosition(item, GetUnitX(unit), GetUnitY(unit))
return true
end
return false
end
function TasItemBagSwap(unit, indexA, indexB)
if not this[unit] then return false end
if indexA <= 0 or indexB <= 0 then return false end
local item = this[unit][indexA]
local item2 = this[unit][indexB]
if GetHandleId(item) > 0 then
this[unit][indexB] = item
this[unit][indexA] = item2
return true
end
return false
end
function TasItemBagRemoveItem(unit, item, drop)
if not this[unit] then return false end
-- loop all items in the bag and remove it if found
for i, o in ipairs(this[unit]) do
if GetHandleId(o) == GetHandleId(item) then
TasItemBagRemoveIndex(unit, i, drop)
return true
end
end
return false
end
function TasItemBagUnitCanUseItems(unit)
-- check all Inventory skills for the USE flag
for i, abiCode in ipairs(this.InventorySkills) do
if GetUnitAbilityLevel(unit, abiCode) > 0 and BlzGetAbilityIntegerLevelField(BlzGetUnitAbility(unit, abiCode), this.AbilityFieldUse, 0) > 0 then
return true
end
end
return false
end
function TasItemBagUnitIsDropItems(unit)
-- check all Inventory skills for the DROP flag
for i, abiCode in ipairs(this.InventorySkills) do
if GetUnitAbilityLevel(unit, abiCode) > 0 and BlzGetAbilityIntegerLevelField(BlzGetUnitAbility(unit, abiCode), this.AbilityFieldDrop, 0) > 0 then
return true
end
end
return false
end
local function CountItemsOfClass(unit, itemClass)
local item
local count = 0
for i= 0, bj_MAX_INVENTORY - 1 do
item = UnitItemInSlot(unit, i)
if GetHandleId(item) > 0 and GetItemType(item) == itemClass then
count = count + 1
end
end
return count
end
function UnitCanDropItems(unit)
-- check all Inventory skills for the DROP flag
for i, abiCode in ipairs(this.InventorySkills) do
if GetUnitAbilityLevel(unit, abiCode) > 0 and BlzGetAbilityIntegerLevelField(BlzGetUnitAbility(unit, abiCode), this.AbilityFieldCanDrop, 0) == 0 then
return false
end
end
return true
end
function CanDropItem(item)
return BlzGetItemBooleanField(item, ITEM_BF_CAN_BE_DROPPED)
end
local function UnitCanEquipItem(unit, item)
if this.IgnoreNeedWhenCanNotUse and not TasItemBagUnitCanUseItems(unit) then
return true
end
-- don't use returns, to display all errors
local returnValue = true
-- use Item Level as requirement. A lower Level can not equip it
if this.ItemLevelRestriction and TasItemBagUnitCanUseItems(unit) and GetUnitLevel(unit) < GetItemLevel(item) then
DisplayTimedTextToPlayer(GetOwningPlayer(unit), 0, 0, 20, GetItemName(item).." needs "..GetLocalizedString("LEVEL").." ".. GetItemLevel(item))
returnValue = false
end
-- itemCode can require an ability
local itemCode = GetItemTypeId(item)
if this.ItemAbilityNeed[itemCode] and GetUnitAbilityLevel(unit, this.ItemAbilityNeed[itemCode]) == 0 then
DisplayTimedTextToPlayer(GetOwningPlayer(unit), 0, 0, 20, GetItemName(item).." needs Ability ".. GetObjectName(this.ItemAbilityNeed[itemCode]))
returnValue = false
end
-- allready have to many of this Class Equiped?
if CountItemsOfClass(unit, GetItemType(item)) >= this.EquipClassLimit then
DisplayTimedTextToPlayer(GetOwningPlayer(unit), 0, 0, 20, "To many Items of this Item-Class")
return false
end
return returnValue
end
local function ItemBag2Equip(unit, item)
-- Inventory Full?
if UnitInventoryCount(unit) >= UnitInventorySize(unit) then
return
end
-- unit can equip this, restrictions
if not UnitCanEquipItem(unit, item) then
return
end
this.EquipNow = true
if UnitAddItem(unit, item) then
TasItemBagRemoveItem(unit, item, false)
end
this.EquipNow = false
end
local function ItemEquip2Bag(unit, item)
TasItemBagAddItem(unit, item)
end
local function BagPopupActionDrop(frame, player)
if GetPlayerAlliance(GetOwningPlayer(this.Selected[player]), player, ALLIANCE_SHARED_CONTROL) then
if GetLocalPlayer() == player then BlzFrameSetVisible(BlzFrameGetParent(frame), false) end
TasItemBagRemoveIndex(this.Selected[player], this.TransferIndex[player], true)
end
end
local function BagPopupActionSwap(frame, player)
if GetPlayerAlliance(GetOwningPlayer(this.Selected[player]), player, ALLIANCE_SHARED_CONTROL) then
if GetLocalPlayer() == player then BlzFrameSetVisible(BlzFrameGetParent(frame), false) end
this.SwapIndex[player] = this.TransferIndex[player]
end
end
local function BagPopupActionEquip(frame, player)
if GetPlayerAlliance(GetOwningPlayer(this.Selected[player]), player, ALLIANCE_SHARED_CONTROL) then
ItemBag2Equip(this.Selected[player], this.TransferItem[player])
if GetLocalPlayer() == player then BlzFrameSetVisible(BlzFrameGetParent(frame), false) end
end
end
local function BagButtonAction(frame, player)
if GetPlayerAlliance(GetOwningPlayer(this.Selected[player]), player, ALLIANCE_SHARED_CONTROL) then
local bagIndex = tonumber(BlzFrameGetText(BlzGetTriggerFrame())) + this.Offset[player]
this.TransferItem[player] = this[this.Selected[player]][bagIndex]
this.TransferIndex[player] = bagIndex
if this.SwapIndex[player] > 0 then
TasItemBagSwap(this.Selected[player], bagIndex, this.SwapIndex[player])
this.SwapIndex[player] = 0
elseif GetLocalPlayer() == player then
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), true)
BlzFrameSetEnable(BlzGetFrameByName("TasItemBagPopUpButtonDrop", 0), this.IgnoreUndropAble or (CanDropItem(this.TransferItem[player]) and UnitCanDropItems(this.Selected[player])))
BlzFrameSetPoint(BlzGetFrameByName("TasItemBagPopUpPanel", 0), FRAMEPOINT_TOPLEFT, frame, FRAMEPOINT_TOPRIGHT, 0.005, 0)
end
end
end
local function NonSliderWheelAction(frame, player, upwards)
-- print("NonSliderWheelAction", upwards)
if GetLocalPlayer() == player then
if upwards then
BlzFrameSetValue(BlzGetFrameByName("TasItemBagSlider", 0), BlzFrameGetValue(BlzGetFrameByName("TasItemBagSlider", 0)) + 1)
else
BlzFrameSetValue(BlzGetFrameByName("TasItemBagSlider", 0), BlzFrameGetValue(BlzGetFrameByName("TasItemBagSlider", 0)) - 1)
end
end
end
local function CloseButtonAction(frame, player)
this.SwapIndex[player] = 0
this.TransferIndex[player] = 0
this.TransferItem[player] = nil
if GetLocalPlayer() == player then
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
end
end
local function ShowButtonAction(frame, player)
this.SwapIndex[player] = 0
this.TransferIndex[player] = 0
this.TransferItem[player] = nil
if GetLocalPlayer() == player then
if this.ShowButtonCloses and BlzFrameIsVisible(BlzGetFrameByName("TasItemBagPanel", 0)) then
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
else
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), true)
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
end
end
end
local function SliderAction(frame, player, value)
this.Offset[player] = value*this.Cols
end
local function UpdateUI()
-- When the options from HeroScoreFrame are in this map use the tooltip&total scale slider
if GetHandleId(BlzGetFrameByName("HeroScoreFrameOptionsSlider1", 0)) > 0 then
this.TooltipScale = BlzFrameGetValue(BlzGetFrameByName("HeroScoreFrameOptionsSlider1", 0))
end
if GetHandleId(BlzGetFrameByName("HeroScoreFrameOptionsSlider3", 0)) > 0 then
BlzFrameSetScale(BlzGetFrameByName("TasItemBagPanel", 0), BlzFrameGetValue(BlzGetFrameByName("HeroScoreFrameOptionsSlider3", 0)))
end
BlzFrameSetScale(BlzGetFrameByName("TasItemBagTooltipPanel", 0), this.TooltipScale)
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlot", 0), not this.ShowButtonNeedsInventory or BlzFrameIsVisible(BlzGetOriginFrame(ORIGIN_FRAME_ITEM_BUTTON, 0)))
if this[this.Selected[GetLocalPlayer()]] then
BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonOverLayText", 0), #this[this.Selected[GetLocalPlayer()]])
else
BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonOverLayText", 0), 0)
end
if BlzFrameIsVisible(BlzGetFrameByName("TasItemBagPanel", 0)) then
local itemCount, itemBag
local offset = this.Offset[GetLocalPlayer()]
if this[this.Selected[GetLocalPlayer()]] then
itemCount = #this[this.Selected[GetLocalPlayer()]]
itemBag = this[this.Selected[GetLocalPlayer()]]
-- scroll by rows
local max = R2I(math.max(0, (itemCount+this.Cols - this.Cols*this.Rows)/this.Cols) )
-- print(max)
BlzFrameSetMinMaxValue(BlzGetFrameByName("TasItemBagSlider", 0), 0, max)
BlzFrameSetText(BlzGetFrameByName("TasItemBagSliderTooltip", 0), R2I(offset/this.Cols).."/"..max)
else
itemCount = 0
BlzFrameSetMinMaxValue(BlzGetFrameByName("TasItemBagSlider", 0), 0, 0)
BlzFrameSetText(BlzGetFrameByName("TasItemBagSliderTooltip", 0), "")
end
local itemCode
local text = ""
local dataIndex
for i = 1, this.Cols*this.Rows do
dataIndex = i + offset
BlzFrameSetEnable(BlzGetFrameByName("TasItemBagSlotButton", i), dataIndex <= itemCount)
if dataIndex <= itemCount then
itemCode = GetItemTypeId(itemBag[dataIndex])
BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdrop", i), BlzGetAbilityIcon(itemCode) , 0, true)
BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdropPushed", i), BlzGetAbilityIcon(itemCode) , 0, true)
if this.AddNeedText then
text = "|nNEED ".. GetLocalizedString("REQUIREDLEVELTOOLTIP").." "..GetItemLevel(itemBag[dataIndex])
if this.ItemAbilityNeed[itemCode] then
text = text .. "|nNEED ".. GetObjectName(this.ItemAbilityNeed[itemCode])
end
end
BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonTooltip", i), GetObjectName(itemCode).. "|n"..BlzGetAbilityExtendedTooltip(itemCode, 0) .."|n|n"..text)
if GetItemCharges(itemBag[dataIndex]) > 0 then
BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonOverLayText", i), GetItemCharges(itemBag[dataIndex]))
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlotButtonOverLay", i), true)
else
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlotButtonOverLay", i), false)
end
else
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagSlotButtonOverLay", i), false)
BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButtonTooltip", i), "")
end
end
end
end
local function CreateTextTooltip(frame, wantedframeName, wantedCreateContext, text)
-- this FRAME is important when the Box is outside of 4:3 it can be limited to 4:3.
local toolTipParent = BlzCreateFrameByType("FRAME", "", BlzGetFrameByName("TasItemBagTooltipPanel", 0), "", 0)
local toolTipBox = BlzCreateFrame("TasToolTipBox", toolTipParent, 0, 0)
local toolTip = BlzCreateFrameByType("TEXT", wantedframeName, toolTipBox, "TasTooltipText", wantedCreateContext)
if this.TooltipFixedPosition then
BlzFrameSetAbsPoint(toolTip, this.TooltipFixedPositionPoint, this.TooltipFixedPositionX, this.TooltipFixedPositionY)
else
BlzFrameSetPoint(toolTip, FRAMEPOINT_TOP, frame, FRAMEPOINT_BOTTOM, 0, -0.008)
end
BlzFrameSetPoint(toolTipBox, FRAMEPOINT_TOPLEFT, toolTip, FRAMEPOINT_TOPLEFT, -0.008, 0.008)
BlzFrameSetPoint(toolTipBox, FRAMEPOINT_BOTTOMRIGHT, toolTip, FRAMEPOINT_BOTTOMRIGHT, 0.008, -0.008)
BlzFrameSetText(toolTip, text)
BlzFrameSetTooltip(frame, toolTipParent)
BlzFrameSetSize(toolTip, this.TooltipWidth, 0)
return toolTip
end
local function CreatePopUpButton(parent, name, text, action)
local frame = BlzCreateFrameByType("GLUETEXTBUTTON", name, parent, "ScriptDialogButton", 0)
BlzFrameSetSize(frame, 0.1, 0.03)
BlzFrameSetText(frame, GetLocalizedString(text))
TasButtonAction(frame, action)
return frame
end
local function InitFrames()
BlzLoadTOCFile("war3mapImported/TasItemBag.toc")
local panel, frame, frame2, frame3
panel = BlzCreateFrameByType("BUTTON", "TasItemBagPanel", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
BlzFrameSetAbsPoint(panel, this.Pos, this.PosX, this.PosY)
BlzFrameSetAllPoints(BlzCreateFrame("TasItemBagBox", panel, 0, 0), panel)
TasFrameMouseMoveAction(panel, nil, nil, NonSliderWheelAction)
BlzCreateFrameByType("BUTTON", "TasItemBagTooltipPanel", panel, "", 0)
-- Custom Bag
local count = 0
for buttonIndex = 1, this.Rows*this.Cols do
frame = BlzCreateFrame("TasItemBagSlot", panel, 0, buttonIndex)
BlzGetFrameByName("TasItemBagSlotButton", buttonIndex)
BlzGetFrameByName("TasItemBagSlotButtonBackdrop", buttonIndex)
BlzGetFrameByName("TasItemBagSlotButtonBackdropDisabled", buttonIndex)
BlzGetFrameByName("TasItemBagSlotButtonBackdropPushed", buttonIndex)
BlzGetFrameByName("TasItemBagSlotButtonOverLay", buttonIndex)
BlzGetFrameByName("TasItemBagSlotButtonOverLayText", buttonIndex)
CreateTextTooltip(BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), "TasItemBagSlotButtonTooltip", buttonIndex, "")
TasButtonAction(BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), BagButtonAction)
TasFrameMouseMoveAction(BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), nil, nil, NonSliderWheelAction)
BlzFrameSetText(BlzGetFrameByName("TasItemBagSlotButton", buttonIndex), buttonIndex)
count = count + 1
if count > this.Cols then
BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("TasItemBagSlot", buttonIndex - this.Cols), FRAMEPOINT_BOTTOMLEFT, 0, -0.002)
count = 1
elseif buttonIndex > 1 then
BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("TasItemBagSlot", buttonIndex - 1), FRAMEPOINT_TOPRIGHT, 0.002, 0)
end
end
if GetHandleId(frame) == 0 then print("Error - Creating TasItemBagSlot") end
BlzFrameSetSize(panel, BlzFrameGetWidth(frame)*this.Cols + (this.Cols - 1)*0.002 + 0.02, BlzFrameGetHeight(frame)*this.Rows + (this.Rows - 1)*0.002 + 0.012)
BlzFrameSetPoint(BlzGetFrameByName("TasItemBagSlot", 1), FRAMEPOINT_TOPLEFT, panel, FRAMEPOINT_TOPLEFT, 0.006, -0.006)
frame = BlzCreateFrameByType("SLIDER", "TasItemBagSlider", panel, "QuestMainListScrollBar", 0)
BlzFrameClearAllPoints(frame)
BlzFrameSetPoint(frame, FRAMEPOINT_BOTTOMRIGHT, panel, FRAMEPOINT_BOTTOMRIGHT, -0.004, 0.008)
BlzFrameSetSize(frame, BlzFrameGetWidth(frame), BlzFrameGetHeight(panel) - 0.02)
--BlzFrameSetStepSize(frame, this.Cols)
local backup = this.TooltipFixedPosition
this.TooltipFixedPosition = false
CreateTextTooltip(frame, "TasItemBagSliderTooltip", 0, "")
BlzFrameSetSize(BlzGetFrameByName("TasItemBagSliderTooltip", 0), 0, 0)
this.TooltipFixedPosition = backup
TasSliderAction(frame, SliderAction)
-- show Buttons
frame = BlzCreateFrame("TasItemBagSlot", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 0, 0)
BlzFrameSetAbsPoint(frame, this.ShowButtonPos, this.ShowButtonPosX, this.ShowButtonPosY)
BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdrop", 0), this.ShowButtonTexture, 0, false)
BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdropDisabled", 0), this.ShowButtonTextureDisabled, 0, false)
BlzFrameSetTexture(BlzGetFrameByName("TasItemBagSlotButtonBackdropPushed", 0), this.ShowButtonTexture, 0, false)
BlzGetFrameByName("TasItemBagSlotButtonOverLay", 0)
BlzGetFrameByName("TasItemBagSlotButtonOverLayText", 0)
TasButtonAction(BlzGetFrameByName("TasItemBagSlotButton", 0), ShowButtonAction)
BlzFrameSetEnable(BlzGetFrameByName("TasItemBagSlotButton", 0), true)
frame = BlzCreateFrameByType("GLUETEXTBUTTON", "TasItemBagCloseButton", panel, "ScriptDialogButton", 0)
BlzFrameSetSize(frame, 0.03, 0.03)
BlzFrameSetText(frame, "X")
BlzFrameSetPoint(frame, FRAMEPOINT_CENTER, BlzFrameGetParent(frame), FRAMEPOINT_TOPRIGHT, -0.002, -0.002)
TasButtonAction(frame, CloseButtonAction)
BlzFrameSetLevel(BlzGetFrameByName("TasItemBagTooltipPanel", 0), 8)
-- Bag Popup
frame = BlzCreateFrameByType("BUTTON", "TasItemBagPopUpPanel", panel, "", 0)
BlzFrameSetLevel(frame, 9)
BlzFrameSetSize(frame, 0.1, 0.0001)
frame2 = CreatePopUpButton(frame, "TasItemBagPopUpButtonEquip" ,"EQUIP", BagPopupActionEquip)
BlzFrameSetPoint(frame2, FRAMEPOINT_TOPLEFT, frame, FRAMEPOINT_TOPLEFT, 0, 0)
frame3 = CreatePopUpButton(frame, "TasItemBagPopUpButtonDrop" ,"DROP", BagPopupActionDrop)
BlzFrameSetPoint(frame3, FRAMEPOINT_TOPLEFT, frame2, FRAMEPOINT_BOTTOMLEFT, 0, 0)
frame2 = CreatePopUpButton(frame, "TasItemBagPopUpButtonSwap" ,"SWAP", BagPopupActionSwap)
BlzFrameSetPoint(frame2, FRAMEPOINT_TOPLEFT, frame3, FRAMEPOINT_BOTTOMLEFT, 0, 0)
--frame3 = CreatePopUpButton(frame, "TasItemBagPopUpButton2Last" ,"2LAST", BagPopupAction2Last)
--BlzFrameSetPoint(frame3, FRAMEPOINT_TOPLEFT, frame2, FRAMEPOINT_BOTTOMLEFT, 0, 0)
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPopUpPanel", 0), false)
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
end
local function DropsOnDeath(unit)
if not IsUnitType(unit, UNIT_TYPE_HERO) then
return true
end
if TasItemBagUnitIsDropItems(unit) then
return true
end
return false
end
local function ItemGainTimerAction()
for i = 1, this.ItemGainTimerCount do
if UnitHasItem(this.ItemGainTimerUnit[i], this.ItemGainTimerItem[i]) then
ItemEquip2Bag(this.ItemGainTimerUnit[i], this.ItemGainTimerItem[i])
end
this.ItemGainTimerUnit[i] = nil
this.ItemGainTimerItem[i] = nil
end
this.ItemGainTimerCount = 0
end
local real = MarkGameStarted
function MarkGameStarted()
real()
this.ItemGainTimerUnit = {}
this.ItemGainTimerItem = {}
this.ItemGainTimerCount = 0
this.AbilityFieldDrop = ConvertAbilityIntegerLevelField(FourCC('inv2'))
this.AbilityFieldUse = ConvertAbilityIntegerLevelField(FourCC('inv3'))
this.AbilityFieldUnDrop = ConvertAbilityIntegerLevelField(FourCC('inv5'))
for key, value in pairs(this.InventorySkills) do
if type(key) == "string" then key = FourCC(key) end
if type(value) == "string" then value = FourCC(value) end
this.InventorySkills[key] = value
end
for key, value in pairs(this.ItemAbilityNeed) do
if type(key) == "string" then key = FourCC(key) end
if type(value) == "string" then value = FourCC(value) end
this.ItemAbilityNeed[key] = value
end
this.TimerUpdate = CreateTimer()
TimerStart(this.TimerUpdate, 0.1, true, UpdateUI)
this.Trigger = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(this.Trigger, EVENT_PLAYER_UNIT_SELECTED)
TriggerAddAction(this.Trigger, function()
this.Selected[GetTriggerPlayer()] = GetTriggerUnit()
this.Offset[GetTriggerPlayer()] = 0
end)
this.TriggerESC = CreateTrigger()
for i = 0, bj_MAX_PLAYERS - 1 do
BlzTriggerRegisterPlayerKeyEvent(this.TriggerESC, Player(i), OSKEY_ESCAPE, 0, true)
end
TriggerAddAction(this.TriggerESC, function()
if GetLocalPlayer() == GetTriggerPlayer() then
BlzFrameSetVisible(BlzGetFrameByName("TasItemBagPanel", 0), false)
end
end)
this.ItemGainTimer = CreateTimer()
this.TriggerItemGain = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(this.TriggerItemGain, EVENT_PLAYER_UNIT_PICKUP_ITEM)
TriggerAddAction(this.TriggerItemGain, function()
-- dummies do not use the bag feature
if this.IgnoreDummy and GetUnitAbilityLevel(GetTriggerUnit(), this.DummySkill) > 0 then
return
end
-- Do not move Powerups that can be used into the bag
if IsItemPowerup(GetManipulatedItem()) and TasItemBagUnitCanUseItems(GetTriggerUnit()) then
return
end
-- Flags to prevent the Pickup 2 bag feature
if not this.EquipNow and not udg_TasItemBagEquipNow then
-- dont move it instantly, delay it with a 0s timer, this stops item pickup orders onto the same item in a row and allows the user to do some stuff to pickedup items
-- does not prevent move ground pick up in rotation
this.ItemGainTimerCount = this.ItemGainTimerCount + 1
this.ItemGainTimerUnit[this.ItemGainTimerCount] = GetTriggerUnit()
this.ItemGainTimerItem[this.ItemGainTimerCount] = GetManipulatedItem()
TimerStart(this.ItemGainTimer, 0, false, ItemGainTimerAction)
--ItemEquip2Bag(GetTriggerUnit(), GetManipulatedItem())
end
end)
this.TriggerItemUse = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(this.TriggerItemUse, EVENT_PLAYER_UNIT_USE_ITEM)
TriggerAddAction(this.TriggerItemUse, function()
if this.IgnoreDummy and GetUnitAbilityLevel(GetTriggerUnit(), this.DummySkill) > 0 then
return
end
if this.MoveUsedItemsIntoBag then
ItemEquip2Bag(GetTriggerUnit(), GetManipulatedItem())
end
end)
this.TriggerUnitDeath = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(this.TriggerUnitDeath, EVENT_PLAYER_UNIT_DEATH)
TriggerAddAction(this.TriggerUnitDeath, function()
local unit = GetTriggerUnit()
local item
if this[unit] then
-- drop by Inventory Skill/Non Hero
local dropByDeath = DropsOnDeath(unit)
local canDropInventory = UnitCanDropItems(unit)
-- drop by Item Data
for i = #this[unit], 1, - 1 do
item = this[unit][i]
if dropByDeath then
TasItemBagRemoveIndex(unit, i, true)
if this.DestroyUndropAbleItems and (not CanDropItem(item) or not canDropInventory) then
RemoveItem(item)
end
end
end
if not IsUnitType(unit, UNIT_TYPE_HERO) then
this[unit] = nil
end
end
unit = nil
item = nil
end)
InitFrames()
if FrameLoaderAdd then FrameLoaderAdd(InitFrames) end
-- UpgradeInventoryAPI
if this.UpgradeInventoryAPI then
this.UpgradeInventoryAPI = {}
local function replacerFunc(oldFuncName, newFunc)
this.UpgradeInventoryAPI[oldFuncName] = _G[oldFuncName]
_G[oldFuncName] = newFunc
end
replacerFunc("UnitRemoveItem", function(unit, item)
this.UpgradeInventoryAPI.UnitRemoveItem(unit, item)
TasItemBagRemoveItem(unit, item, true)
end)
replacerFunc("UnitHasItem", function(unit, item)
if this.UpgradeInventoryAPI.UnitHasItem(unit, item) then
return true
end
if not this[unit] then return false end
for i, o in ipairs(this[unit]) do
if GetHandleId(o) == GetHandleId(item) then
return true
end
end
return false
end)
replacerFunc("UnitItemInSlot", function(unit, itemSlot)
if itemSlot < this.DefaultInventorySize then
return this.UpgradeInventoryAPI.UnitItemInSlot(unit, itemSlot)
else
return TasItemBagGetItem(unit, itemSlot - this.DefaultInventorySize)
end
end)
replacerFunc("UnitRemoveItemFromSlot", function(unit, itemSlot)
if itemSlot < this.DefaultInventorySize then
return this.UpgradeInventoryAPI.UnitRemoveItemFromSlot(unit, itemSlot)
else
local item = TasItemBagGetItem(unit, itemSlot - this.DefaultInventorySize)
TasItemBagRemoveIndex(unit, itemSlot - this.DefaultInventorySize, true)
return item
end
end)
bj_MAX_INVENTORY = bj_MAX_INVENTORY + this.ItemBagSize
end
end
end
do
local real = InitBlizzard
function InitBlizzard()
real()
udg_TasItemBagNeedSkill = CreateTrigger()
TriggerAddAction(udg_TasItemBagNeedSkill, function()
TasItemBag.ItemAbilityNeed[udg_TasItemBagItem] = udg_TasItemBagSkill
end)
end
end
library TasUnitBagGUI initializer init_function
private function Action takes nothing returns nothing
set TasItemBag_ItemAbilityNeed[udg_TasItemBagItem] = udg_TasItemBagSkill
endfunction
private function init_function takes nothing returns nothing
set udg_TasItemBagNeedSkill = CreateTrigger()
call TriggerAddAction(udg_TasItemBagNeedSkill, function Action)
endfunction
endlibrary