globals
integer UpdateCounter = 0
framehandle UpdateCounterText
endglobals
Name | Type | is_array | initial_value |
MyItemShopCat | integer | No | |
MyItemShopCat2 | integer | No | |
TasItemShop_Buff | buffcode | No | |
TasItemShop_Category | integer | No | |
TasItemShop_Gold | real | No | 1.00 |
TasItemShop_GoldAdd | real | No | |
TasItemShop_Icon | imagefile | No | |
TasItemShop_Item | itemcode | No | |
TasItemShop_Lumber | real | No | 1.00 |
TasItemShop_LumberAdd | real | No | |
TasItemShop_Mats | itemcode | Yes | |
TasItemShop_Player | player | No | |
TasItemShop_Skill | abilcode | No | |
TasItemShop_Text | string | No | |
TasItemShop_Unit | unitcode | No | |
TasItemShop_WhiteList | boolean | No | |
TasItemShopAdd | trigger | No | |
TasItemShopCategory | trigger | No | |
TasItemShopCosts | trigger | No | |
TasItemShopCreateShop | trigger | No | |
TasItemShopFusion | trigger | No | |
TasItemShopHaggle | trigger | No | |
TasItemShopShortCuts | trigger | No |
library FrameLoader initializer init_function
// in 1.31 and upto 1.32.9 PTR (when I wrote this). Frames are not correctly saved and loaded, breaking the game.
// This library runs all functions added to it with a 0s delay after the game was loaded.
// function FrameLoaderAdd takes code func returns nothing
// func runs when the game is loaded.
globals
private trigger eventTrigger = CreateTrigger()
private trigger actionTrigger = CreateTrigger()
private timer t = CreateTimer()
endglobals
function FrameLoaderAdd takes code func returns nothing
call TriggerAddAction(actionTrigger, func)
endfunction
private function timerAction takes nothing returns nothing
call TriggerExecute(actionTrigger)
endfunction
private function eventAction takes nothing returns nothing
call TimerStart(t, 0, false, function timerAction)
endfunction
private function init_function takes nothing returns nothing
call TriggerRegisterGameEvent(eventTrigger, EVENT_GAME_LOADED)
call TriggerAddAction(eventTrigger, function eventAction)
endfunction
endlibrary
library ItemHolder requires Table
globals
private Table data
endglobals
public function get takes item i returns unit
return data.unit[GetHandleId(i)]
endfunction
private function gain takes nothing returns nothing
set data.unit[GetHandleId(GetManipulatedItem())] = GetTriggerUnit()
endfunction
private function lose takes nothing returns nothing
set data.unit[GetHandleId(GetManipulatedItem())] = null
endfunction
private module Init
private static method onInit takes nothing returns nothing
// Initialization process here..
local trigger t
set data = Table.create()
set t = CreateTrigger()
call TriggerAddAction(t, function gain)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
set t = CreateTrigger()
call TriggerAddAction(t, function lose)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DROP_ITEM)
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
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")
//! runtextmacro NEW_ARRAY("Frame", "framehandle")
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
implement framehandlem
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 Power2
globals
private integer array data
endglobals
function GetPower2Value takes integer i returns integer
return data[i]
endfunction
private module Init
private static method onInit takes nothing returns nothing
local integer index = 1
local integer value = 1
loop
set data[index] = value
set index = index + 1
set value = value*2
exitwhen index == 32
// body
endloop
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
library SimpleTooltip
function CreateSimpleTooltip takes framehandle frame, 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", "", frame, "", 0)
local framehandle toolTipBox = BlzCreateFrame("EscMenuControlBackdropTemplate", toolTipParent, 0, 0)
local framehandle toolTip = BlzCreateFrame("TasButtonTextTemplate", toolTipBox, 0, 0)
call BlzFrameSetPoint(toolTip, FRAMEPOINT_BOTTOM, frame, FRAMEPOINT_TOP, 0, 0.008)
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)
return toolTip
endfunction
endlibrary
library IsRightClick requires optional FrameLoader
// function IsRightClick takes player p returns boolean
// tells you if the last click was current a rightclick, meant to be used inside a FrameEventMouseUp
globals
private boolean array isRight
private trigger frameTrigger
endglobals
function IsRightClick takes player p returns boolean
return isRight[GetPlayerId(p)]
endfunction
private function Action takes nothing returns nothing
set isRight[GetPlayerId(GetTriggerPlayer())] = BlzGetTriggerPlayerMouseButton() == MOUSE_BUTTON_TYPE_RIGHT
endfunction
private function FrameAction takes nothing returns nothing
// when the game is paused reset the lastClick Flag. This has to be done because EVENT_PLAYER_MOUSE_UP does not trigger during Pause
local integer i = 0
loop
set isRight[i] = false
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
endfunction
private function FrameInit takes nothing returns nothing
call BlzTriggerRegisterFrameEvent(frameTrigger, BlzGetFrameByName("PauseButton", 0), FRAMEEVENT_CONTROL_CLICK)
endfunction
private module Init
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
set frameTrigger = CreateTrigger()
call TriggerAddAction(frameTrigger, function FrameAction)
call TriggerAddAction(t, function Action)
loop
call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_MOUSE_UP)
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
static if LIBRARY_FrameLoader then
call FrameLoaderAdd(function FrameInit)
endif
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
library RaceSounds initializer init_function
globals
sound array SoundNoGold
sound array SoundNoLumber
endglobals
private function init_function takes nothing returns nothing
local integer index
set index = GetHandleId(RACE_HUMAN)
set SoundNoGold[index] = CreateSound("Sound\\Interface\\Warning\\Human\\KnightNoGold1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoGold[index], "NoGoldHuman")
call SetSoundDuration(SoundNoGold[index], 1618)
set SoundNoLumber[index] = CreateSound("Sound\\Interface\\Warning\\Human\\KnightNoLumber1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoLumber[index], "NoLumberHuman")
call SetSoundDuration(SoundNoLumber[index], 1903)
set index = GetHandleId(ConvertRace(11))
set SoundNoGold[index] = CreateSound("Sound\\Interface\\Warning\\Naga\\NagaNoGold1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoGold[index], "NoGoldNaga")
call SetSoundDuration(SoundNoGold[index], 2690)
set SoundNoLumber[index] = CreateSound("Sound\\Interface\\Warning\\Naga\\NagaNoLumber1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoLumber[index], "NoLumberNaga")
call SetSoundDuration(SoundNoLumber[index], 2011)
set index = GetHandleId(RACE_ORC)
set SoundNoGold[index] = CreateSound("Sound\\Interface\\Warning\\Orc\\GruntNoGold1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoGold[index], "NoGoldOrc")
call SetSoundDuration(SoundNoGold[index], 1450)
set SoundNoLumber[index] = CreateSound("Sound\\Interface\\Warning\\Orc\\GruntNoLumber1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoLumber[index], "NoLumberOrc")
call SetSoundDuration(SoundNoLumber[index], 1219)
set index = GetHandleId(RACE_NIGHTELF)
set SoundNoGold[index] = CreateSound("Sound\\Interface\\Warning\\NightElf\\SentinelNoGold1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoGold[index], "NoGoldNightElf")
call SetSoundDuration(SoundNoGold[index], 1229)
set SoundNoLumber[index] = CreateSound("Sound\\Interface\\Warning\\NightElf\\SentinelNoLumber1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoLumber[index], "NoLumberNightElf")
call SetSoundDuration(SoundNoLumber[index], 1454)
set index = GetHandleId(RACE_UNDEAD)
set SoundNoGold[index] = CreateSound("Sound\\Interface\\Warning\\Undead\\NecromancerNoGold1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoGold[index], "NoGoldUndead")
call SetSoundDuration(SoundNoGold[index], 2005)
set SoundNoLumber[index] = CreateSound("Sound\\Interface\\Warning\\Undead\\NecromancerNoLumber1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(SoundNoLumber[index], "NoLumberUndead")
call SetSoundDuration(SoundNoLumber[index], 2005)
endfunction
endlibrary
library TasItemFusion requires TasItemCost, Table
// function TasItemFusionAdd takes integer result, integer mat returns nothing
// function TasItemFusionAdd2 takes integer result, integer a, integer b returns nothing
// function TasItemFusionAdd3 takes integer result, integer a, integer b, integer c returns nothing
// function TasItemFusionAdd4 takes integer result, integer a, integer b, integer c, integer d returns nothing
// function TasItemFusionAdd5 takes integer result, integer a, integer b, integer c, integer d, integer e returns nothing
// function TasItemFusionAdd6 takes integer result, integer a, integer b, integer c, integer d, integer e, integer f returns nothing
// function TasItemFusionGetUseableItems takes player p , group units, boolean checkOwner returns nothing
// function TasItemFusionGetUseableMaterial takes player p, integer result, boolean reset returns nothing
// function TasItemFusionCalc player p, integer result returns nothing
// function TasItemFusionGetMissingMaterial takes player p, integer result, boolean reset returns nothing
globals
public integer Count = 0
public hashtable Hash = InitHashtable()
public integer array ItemCodes
public integer ItemCodesCount = 0
public integer FusionCount = 0
public integer array FusionResult
public HashTable UsedIn // allows to find Fusions from a Mat
public HashTable BuiltWay // find Fusions from the result
public Table array PlayerItems //contains all useable
public Table array PlayerMaterial //contains material used
public Table array PlayerMissing //contains material used
public Table array PlayerMissingUsed //contains material used
private boolean CheckOwner
private player Owner
private integer OwnerIndex
// Costs
integer TasItemFusionGold
integer TasItemFusionLumber
endglobals
function TasItemFusionAdd takes integer result, integer mat returns nothing
local integer materialCount
local integer builtWayCount
local integer count
set FusionCount = FusionCount + 1
set FusionResult[FusionCount] = result
set count = BuiltWay[result][0] + 1
set BuiltWay[result][0] = count
set BuiltWay[result][count] = mat
if not UsedIn[mat].boolean.has(result) then
set UsedIn[mat].boolean[result] = true
set count = UsedIn[mat][0] + 1
set UsedIn[mat][0] = count
set UsedIn[mat][count] = result
call TasItemCaclCost(mat)
endif
call TasItemCaclCost(result)
endfunction
function TasItemFusionAdd2 takes integer result, integer a, integer b returns nothing
call TasItemFusionAdd(result, a)
call TasItemFusionAdd(result, b)
endfunction
function TasItemFusionAdd3 takes integer result, integer a, integer b, integer c returns nothing
call TasItemFusionAdd(result, a)
call TasItemFusionAdd(result, b)
call TasItemFusionAdd(result, c)
endfunction
function TasItemFusionAdd4 takes integer result, integer a, integer b, integer c, integer d returns nothing
call TasItemFusionAdd(result, a)
call TasItemFusionAdd(result, b)
call TasItemFusionAdd(result, c)
call TasItemFusionAdd(result, d)
endfunction
function TasItemFusionAdd5 takes integer result, integer a, integer b, integer c, integer d, integer e returns nothing
call TasItemFusionAdd(result, a)
call TasItemFusionAdd(result, b)
call TasItemFusionAdd(result, c)
call TasItemFusionAdd(result, d)
call TasItemFusionAdd(result, e)
endfunction
function TasItemFusionAdd6 takes integer result, integer a, integer b, integer c, integer d, integer e, integer f returns nothing
call TasItemFusionAdd(result, a)
call TasItemFusionAdd(result, b)
call TasItemFusionAdd(result, c)
call TasItemFusionAdd(result, d)
call TasItemFusionAdd(result, e)
call TasItemFusionAdd(result, f)
endfunction
function TasItemFusionGetUseableItemsEnum takes nothing returns nothing
local integer index = 0
local item i
local unit u = GetEnumUnit()
local integer count
local integer itemCode
loop
set i = UnitItemInSlot(u, index)
if i != null and (not CheckOwner or (GetItemPlayer(i) == Owner or GetItemPlayer(i) == Player(PLAYER_NEUTRAL_PASSIVE))) then
set count = PlayerItems[OwnerIndex][0] + 1
set PlayerItems[OwnerIndex][0] = count
set PlayerItems[OwnerIndex].item[count] = i
set itemCode = GetItemTypeId(i)
set PlayerItems[OwnerIndex][itemCode] = PlayerItems[OwnerIndex][itemCode] + 1
endif
set index = index + 1
exitwhen index >= bj_MAX_INVENTORY
endloop
set u = null
set i = null
endfunction
function TasItemFusionGetUseableItems takes player p , group units, boolean checkOwner returns nothing
// give the units which inventory is useable
local integer playerIndex = GetPlayerId(p)
call PlayerItems[playerIndex].flush()
set OwnerIndex = playerIndex
set Owner = p
set CheckOwner = checkOwner
call ForGroup(units, function TasItemFusionGetUseableItemsEnum)
endfunction
// returns a list of material that can be used for result.
function TasItemFusionGetUseableMaterial takes player p, integer result, boolean reset, boolean quick returns nothing
local integer playerIndex = GetPlayerId(p)
local item i
local boolean canBeFound
local integer loopA
local integer loopB
local integer itemCode
local integer count
if reset then
call PlayerMaterial[playerIndex].flush()
//set UpdateCounter = UpdateCounter + 1
//call BlzFrameSetText(UpdateCounterText, I2S(UpdateCounter))
endif
set loopA = BuiltWay[result][0]
loop
exitwhen loopA < 1
set itemCode = BuiltWay[result][loopA]
// have more total then yet found
set canBeFound = (PlayerItems[playerIndex].integer[itemCode] > PlayerMaterial[playerIndex].integer[itemCode])
if canBeFound then
if quick then
set count = PlayerMaterial[playerIndex][0] + 1
set PlayerMaterial[playerIndex][0] = count
set PlayerMaterial[playerIndex][count] = itemCode
set PlayerMaterial[playerIndex][itemCode] = PlayerMaterial[playerIndex][itemCode] + 1
else
set loopB = PlayerItems[playerIndex][0]
loop
exitwhen loopB < 1
set i = PlayerItems[playerIndex].item[loopB]
if GetItemTypeId(i) == itemCode and not PlayerMaterial[playerIndex].boolean[GetHandleId(i)] then
set PlayerMaterial[playerIndex].boolean[GetHandleId(i)] = true
set PlayerMaterial[playerIndex][itemCode] = PlayerMaterial[playerIndex][itemCode] + 1
set count = PlayerMaterial[playerIndex][0] + 1
set PlayerMaterial[playerIndex][0] = count
set PlayerMaterial[playerIndex].item[count] = i
exitwhen true
endif
set loopB = loopB - 1
endloop
endif
elseif BuiltWay[itemCode][0] > 0 then
call TasItemFusionGetUseableMaterial(p, itemCode, false, quick)
endif
set loopA = loopA - 1
endloop
set i = null
endfunction
// returns the total gold cost and the used material from useAble
function TasItemFusionCalc takes player p, integer result, boolean quick returns nothing
// find all useable fusion material
local integer playerIndex = GetPlayerId(p)
local integer gold = TasItemGetCostGold(result)
local integer lumber = TasItemGetCostLumber(result)
local integer gold2
local integer lumber2
local integer count
call TasItemFusionGetUseableMaterial(p, result, true, quick)
// reduce total gold cost by the useables
set count = PlayerMaterial[playerIndex][0]
loop
exitwhen count < 1
if quick then
set gold2 = TasItemGetCostGold(PlayerMaterial[playerIndex][count])
set lumber2 = TasItemGetCostLumber(PlayerMaterial[playerIndex][count])
else
set gold2 = TasItemGetCostGold(GetItemTypeId(PlayerMaterial[playerIndex].item[count]))
set lumber2 = TasItemGetCostLumber(GetItemTypeId(PlayerMaterial[playerIndex].item[count]))
endif
set gold = gold - gold2
set lumber = lumber - lumber2
set count = count - 1
endloop
// "return values"
set TasItemFusionGold = gold
set TasItemFusionLumber = lumber
endfunction
// returns a table of the material missing
// call it that way TasItemFusionGetMissingMaterial(useAble, result)
function TasItemFusionGetMissingMaterial takes player p, integer result, boolean reset returns nothing
local item i
local integer playerIndex = GetPlayerId(p)
local boolean found
local integer loopA
local integer loopB
local integer itemCode
local integer count
if reset then
call PlayerMissing[playerIndex].flush()
call PlayerMissingUsed[playerIndex].flush()
endif
set loopA = BuiltWay[result][0]
loop
exitwhen loopA < 1
set found = false
set itemCode = BuiltWay[result][loopA]
set loopB = PlayerItems[playerIndex][0]
loop
exitwhen loopB < 1
set i = PlayerItems[playerIndex].item[loopB]
if GetItemTypeId(i) == itemCode and not PlayerMissingUsed[playerIndex].boolean[GetHandleId(i)] then
set PlayerMissingUsed[playerIndex].boolean[GetHandleId(i)] = true
set count = PlayerMissingUsed[playerIndex][0] + 1
set PlayerMissingUsed[playerIndex][0] = count
set PlayerMissingUsed[playerIndex].item[count] = i
set found = true
exitwhen true
endif
set loopB = loopB - 1
endloop
if not found and not PlayerMissing[playerIndex].boolean[itemCode] then
set count = PlayerMissing[playerIndex][0] + 1
set PlayerMissing[playerIndex][0] = count
set PlayerMissing[playerIndex][count] = itemCode
set PlayerMissing[playerIndex].boolean[itemCode] = true
if BuiltWay[itemCode][0] > 0 then
call TasItemFusionGetMissingMaterial(p, itemCode, false)
endif
endif
set loopA = loopA - 1
endloop
endfunction
private module Init
private static method onInit takes nothing returns nothing
local integer loopA = 0
set UsedIn = HashTable.create() // allows to find Fusions from a Mat
set BuiltWay = HashTable.create() // find Fusions from the result
loop
set PlayerItems[loopA] = Table.create()
set PlayerMaterial[loopA] = Table.create() //contains material used
set PlayerMissing[loopA] = Table.create()
set PlayerMissingUsed[loopA] = Table.create()
set loopA = loopA + 1
exitwhen loopA == bj_MAX_PLAYER_SLOTS
// body
endloop
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
library TasItemCost
//function TasItemCaclCost takes integer itemCode returns nothing
//function TasItemGetCostGold takes integer itemCode returns integer
//function TasItemGetCostLumber takes integer itemCode returns integer
globals
private unit shop
// defines position of a hidden shop to get item costs
// the size is used to clear up bought items
private real shopRectSize = 1000
private real shopRectX = 180
private real shopRectY = -340
private rect shopRect
private player shopOwner = Player(bj_PLAYER_NEUTRAL_EXTRA)
private integer array Test
private integer TestCount = 0
private integer HASH_GOLD = StringHash("GOLD")
private integer HASH_LUMBER = StringHash("LUMBER")
private integer HASH_CHARGE = StringHash("CHARGE")
hashtable TasItemHash = InitHashtable()
endglobals
private function ClearItem takes nothing returns nothing
//call BJDebugMsg("Enum " + GetItemName(GetEnumItem()))
call RemoveItem(GetEnumItem())
endfunction
private function ClearItemStart takes nothing returns nothing
//call BJDebugMsg("ClearItemStart")
call EnumItemsInRect(shopRect, null, function ClearItem)
endfunction
private function TasItemCalcDestroy takes nothing returns nothing
call ClearItemStart()
call ShowUnit(shop, true)
call RemoveUnit(shop)
call RemoveRect(shopRect)
endfunction
private function Start takes nothing returns nothing
local integer itemCode = Test[1]
local integer gold
local integer lumber
local item i
call AddItemToStock(shop, itemCode, 1, 1)
call SetPlayerState(shopOwner, PLAYER_STATE_RESOURCE_GOLD, 99999999)
call SetPlayerState(shopOwner, PLAYER_STATE_RESOURCE_LUMBER, 99999999)
set gold = GetPlayerState(shopOwner, PLAYER_STATE_RESOURCE_GOLD)
set lumber = GetPlayerState(shopOwner, PLAYER_STATE_RESOURCE_LUMBER)
call IssueNeutralImmediateOrderById(shopOwner, shop, itemCode)
call SaveInteger(TasItemHash, itemCode, HASH_GOLD, gold - GetPlayerState(shopOwner, PLAYER_STATE_RESOURCE_GOLD))
call SaveInteger(TasItemHash, itemCode, HASH_LUMBER, lumber - GetPlayerState(shopOwner, PLAYER_STATE_RESOURCE_LUMBER))
set i = CreateItem(itemCode,0,0)
call SaveInteger(TasItemHash, itemCode, HASH_CHARGE, GetItemCharges(i))
call RemoveItem(i)
set i = null
call RemoveItemFromStock(shop, itemCode)
// testing order does not matter much, simple reindex
set Test[1] = Test[TestCount]
set TestCount = TestCount - 1
call ClearItemStart()
if TestCount > 0 then
call Start()
else
//call TimerStart(t, 1, false, function ClearItemStart)
endif
endfunction
function TasItemCaclCost takes integer itemCode returns nothing
local item i
// if there is already data for that itemcode, skip it
if not HaveSavedInteger(TasItemHash, itemCode, HASH_GOLD) then
// is this a valid itemCode? Create it, if that fails skip testing it
set i = CreateItem(itemCode, 0, 0)
if GetHandleId(i) > 0 then
call RemoveItem(i)
set TestCount = TestCount + 1
set Test[TestCount] = itemCode
endif
if TestCount > 0 then
call Start()
endif
set i = null
endif
endfunction
function TasItemGetCostGold takes integer itemCode returns integer
call TasItemCaclCost(itemCode)
return LoadInteger(TasItemHash, itemCode, HASH_GOLD)
endfunction
function TasItemGetCostLumber takes integer itemCode returns integer
call TasItemCaclCost(itemCode)
return LoadInteger(TasItemHash, itemCode, HASH_LUMBER)
endfunction
function TasItemGetCharges takes integer itemCode returns integer
call TasItemCaclCost(itemCode)
return LoadInteger(TasItemHash, itemCode, HASH_CHARGE)
endfunction
private module Init
private static method onInit takes nothing returns nothing
set shopRect = Rect(0, 0, shopRectSize, shopRectSize)
set shop = CreateUnit(shopOwner, 'nmrk', shopRectX, shopRectY, 0)
call SetUnitX(shop, shopRectX)
call SetUnitY(shop, shopRectY)
call MoveRectTo(shopRect, shopRectX, shopRectY)
call UnitAddAbility(shop, 'AInv')
call IssueNeutralTargetOrder(shopOwner, shop, "smart", shop)
call ShowUnit(shop, false)
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
library ToggleIconButton requires Power2, SimpleTooltip
// function CreateToggleIconButton takes framehandle parent, integer valueOn, string text, string textureOn, integer mode, string textureOff, string textOff returns integer
// function CreateToggleIconButtonSimple takes framehandle parent, integer valueOn, string text, string textureOn returns integer
// function ToggleIconButtonSetValue takes integer object, player p, boolean enable returns nothing
// function ToggleIconButtonAddAction takes integer object, code action returns nothing
// function ToggleIconButtonGetValue takes integer object, player p returns integer
globals
public real DefaultSizeX = 0.024
public real DefaultSizeY = 0.024
public integer MODE_DEFAULT = 0 // the visual is local only.
public integer MODE_SHARED = 1 // is the same for all players.
public integer MODE_LOCAL = -1 // Visual and Action are for the clicking player only
public integer Counter = 0
public integer array ValueOn
public integer array Value
public framehandle array Button
public framehandle array Icon
public framehandle array IconPushed
public framehandle array ToolTip
public integer array Mode
public string array Texture
public string array TextureOff
public string array Text
public string array TextOff
public trigger array Action
integer ToggleIconButton_Index
player ToggleIconButton_Player
boolean ToggleIconButton_Enabled
private trigger Trigger = CreateTrigger()
public sound Sound
endglobals
private function GetDisabledIcon takes string icon returns string
//ReplaceableTextures\CommandButtons\BTNHeroPaladin.tga -> ReplaceableTextures\CommandButtonsDisabled\DISBTNHeroPaladin.tga
if SubString(icon, 34, 35) != "\\" then
return icon
endif //this string has not enough chars return it
//string.len(icon) < 34 then return icon end //this string has not enough chars return it
return SubString(icon, 0, 34) + "Disabled\\DIS" + SubString(icon, 35, StringLength(icon))
endfunction
function ToggleIconButtonGetKey takes integer object, player p returns integer
if Mode[object] == MODE_SHARED then
return 0
else
return GetPower2Value(GetPlayerId(p) + 1)
endif
endfunction
function ToggleIconButtonSetValue takes integer object, player p, boolean enable returns nothing
local integer key = ToggleIconButtonGetKey(object, p)
if enable and BlzBitAnd(Value[object], key) == 0 then
set Value[object] = Value[object] + key
elseif not enable and BlzBitAnd(Value[object], key) > 0 then
set Value[object] = Value[object] - key
endif
// update visual
if Mode[object] == MODE_SHARED or GetLocalPlayer() == p then
if not enable then
call BlzFrameSetTexture(Icon[object], TextureOff[object], 0, false)
call BlzFrameSetTexture(IconPushed[object], TextureOff[object], 0, false)
call BlzFrameSetText(ToolTip[object], TextOff[object])
else
call BlzFrameSetTexture(Icon[object], Texture[object], 0, false)
call BlzFrameSetTexture(IconPushed[object], Texture[object], 0, false)
call BlzFrameSetText(ToolTip[object], Text[object])
endif
endif
endfunction
function ToggleIconButtonGetValue takes integer object, player p returns integer
if BlzBitAnd(Value[object], ToggleIconButtonGetKey(object, p)) > 0 then
return ValueOn[object]
else
return 0
endif
endfunction
function ToggleIconButtonDefaultSize takes real x, real y returns nothing
set DefaultSizeX = x
set DefaultSizeY = y
endfunction
function CreateToggleIconButton takes framehandle parent, integer valueOn, string text, string textureOn, integer mode, string textureOff, string textOff returns integer
set Counter = Counter + 1
set Button[Counter] = BlzCreateFrame("TasItemShopCatButton", parent, 0, 0)
set Icon[Counter] = BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0)
set IconPushed[Counter] = BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0)
call BlzFrameSetText(Button[Counter], I2S(Counter))
call BlzFrameSetSize(Button[Counter], DefaultSizeX, DefaultSizeY)
call BlzFrameSetTexture(Icon[Counter], textureOff, 0, false)
call BlzFrameSetTexture(IconPushed[Counter], textureOff, 0, false)
call BlzTriggerRegisterFrameEvent(Trigger, Button[Counter], FRAMEEVENT_CONTROL_CLICK)
set ToolTip[Counter] = CreateSimpleTooltip(Button[Counter], textOff)
set Mode[Counter] = mode
set Value[Counter] = 0
set ValueOn[Counter] = valueOn
set Texture[Counter] = textureOn
set TextureOff[Counter] = textureOff
set Text[Counter] = text
set TextOff[Counter] = textOff
set Action[Counter] = CreateTrigger()
return Counter
endfunction
function ToggleIconButtonAddAction takes integer object, code action returns nothing
call TriggerAddCondition(Action[object], Filter(action))
endfunction
function CreateToggleIconButtonSimple takes framehandle parent, integer valueOn, string text, string textureOn returns integer
return CreateToggleIconButton(parent, valueOn, text, textureOn, MODE_DEFAULT, GetDisabledIcon(textureOn), text)
endfunction
private function TriggerAction takes nothing returns nothing
local framehandle frame = BlzGetTriggerFrame()
local integer object = S2I(BlzFrameGetText(frame))
local player p = GetTriggerPlayer()
local integer key = ToggleIconButtonGetKey(object, p)
//StartSoundForPlayerBJ(player, ToggleIconButton.Sound)
call ToggleIconButtonSetValue(object, p, BlzBitAnd(Value[object], key) == 0)
if (Mode[object] != MODE_LOCAL or GetLocalPlayer() == p) then
set ToggleIconButton_Index = object
set ToggleIconButton_Player = p
set ToggleIconButton_Enabled = ToggleIconButtonGetValue(object, p) == ValueOn[object]
call TriggerEvaluate(Action[object])
endif
// remove focus
call BlzFrameSetEnable(frame, false)
call BlzFrameSetEnable(frame, true)
endfunction
private module Init
private static method onInit takes nothing returns nothing
set Sound = CreateSound("Sound\\Interface\\MouseClick1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(Sound, "InterfaceClick")
call SetSoundDuration(Sound, 239)
call BlzLoadTOCFile("war3mapImported\\Templates.toc")
call TriggerAddAction(Trigger, function TriggerAction)
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
library ToggleIconButtonGroup requires ToggleIconButton
// function ToggleIconButtonGroupGetValue takes integer groupObject, player p returns integer
// function ToggleIconButtonGroupClear takes integer groupObject, player p returns nothing
// function ToggleIconButtonGroupAddButton takes integer groupObject, integer buttonObject returns nothing
// function ToggleIconButtonGroupClearButton takes integer groupObject, framehandle parent, string iconPath returns framehandle
// function ToggleIconButtonGroupClearButtonSimple takes integer groupObject returns framehandle
// function CreateToggleIconButtonGroup takes code action returns integer
globals
// limitation all ToggleIconButton of a group have to take indexes next to each other
public integer array IndexStart // first ToggleIconButton Index in a group
public integer array IndexEnd // Last ToggleIconButton Inde in a group
public integer array groupIndex // this is for the buttons not for the group
public framehandle array ClearButton
public framehandle array ClearButtonIcon
public framehandle array ClearButtonIconPushed
public integer Count = 0
// args for the Actions
integer ToggleIconButtonGroup_Index
integer ToggleIconButtonGroup_Value
public trigger array Action
private trigger Trigger = CreateTrigger()
private trigger RightClickTrigger = CreateTrigger()
private trigger ClearTrigger = CreateTrigger()
endglobals
function ToggleIconButtonGroupGetValue takes integer groupObject, player p returns integer
local integer returnValue = 0
local integer loopA = IndexStart[groupObject]
loop
exitwhen loopA > IndexEnd[groupObject]
set returnValue = returnValue + ToggleIconButtonGetValue(loopA, p)
set loopA = loopA + 1
endloop
return returnValue
endfunction
function ToggleIconButtonGroupClear takes integer groupObject, player p returns nothing
local integer loopA = IndexStart[groupObject]
loop
exitwhen loopA > IndexEnd[groupObject]
call ToggleIconButtonSetValue(loopA, p, false)
set loopA = loopA + 1
endloop
endfunction
private function GroupTriggerAction takes nothing returns nothing
local integer groupObject = groupIndex[ToggleIconButton_Index]
set ToggleIconButtonGroup_Index = groupObject
set ToggleIconButtonGroup_Value = ToggleIconButtonGroupGetValue(groupObject, ToggleIconButton_Player)
call TriggerEvaluate(Action[groupObject])
endfunction
function ToggleIconButtonGroupAddButton takes integer groupObject, integer buttonObject returns nothing
if IndexStart[groupObject] == 0 then
set IndexStart[groupObject] = buttonObject
endif
set IndexEnd[groupObject] = buttonObject
call ToggleIconButtonAddAction(buttonObject, function GroupTriggerAction)
set groupIndex[buttonObject] = groupObject
call BlzTriggerRegisterFrameEvent(RightClickTrigger, ToggleIconButton_Button[buttonObject], FRAMEEVENT_MOUSE_UP)
endfunction
function ToggleIconButtonGroupClearButton takes integer groupObject, framehandle parent, string iconPath returns framehandle
local framehandle but = BlzCreateFrame("TasItemShopCatButton", parent, 0, 0)
local framehandle icon = BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0)
local framehandle iconPushed = BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0)
// only one clearButton
if ClearButton[groupObject] == null then
set but = BlzCreateFrame("TasItemShopCatButton", parent, 0, 0)
set icon = BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0)
set iconPushed = BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0)
call BlzFrameSetSize(but, ToggleIconButton_DefaultSizeX, ToggleIconButton_DefaultSizeY)
call BlzFrameSetTexture(icon, iconPath, 0, false)
call BlzFrameSetTexture(iconPushed, iconPath, 0, false)
call CreateSimpleTooltip(but, "Clear")
call BlzFrameSetText(but, I2S(groupObject))
set ClearButton[groupObject] = but
set ClearButtonIcon[groupObject] = icon
set ClearButtonIconPushed[groupObject] = iconPushed
call BlzTriggerRegisterFrameEvent(ClearTrigger, but, FRAMEEVENT_CONTROL_CLICK)
return but
else
return ClearButton[groupObject]
endif
endfunction
function ToggleIconButtonGroupClearButtonSimple takes integer groupObject returns framehandle
return ToggleIconButtonGroupClearButton(groupObject, BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "ReplaceableTextures\\CommandButtons\\BTNCancel")
endfunction
function CreateToggleIconButtonGroup takes code action returns integer
set Count = Count + 1
set Action[Count] = CreateTrigger()
call TriggerAddCondition(Action[Count], Filter(action))
return Count
endfunction
private function RightClickTriggerAction takes nothing returns nothing
local player p = GetTriggerPlayer()
local framehandle frame = BlzGetTriggerFrame()
local integer buttonObject
local integer groupObject
if IsRightClick(p) then
set buttonObject = S2I(BlzFrameGetText(frame))
set groupObject = groupIndex[buttonObject]
call StartSoundForPlayerBJ(p, ToggleIconButton_Sound)
call ToggleIconButtonGroupClear(groupObject, p)
call ToggleIconButtonSetValue(buttonObject, p, true)
set ToggleIconButton_Index = buttonObject
set ToggleIconButtonGroup_Index = groupObject
set ToggleIconButton_Player = p
set ToggleIconButtonGroup_Value = ToggleIconButtonGroupGetValue(groupObject, p)
call TriggerEvaluate(Action[groupObject])
endif
endfunction
private function ClearTriggerAction takes nothing returns nothing
local framehandle but = BlzGetTriggerFrame()
local integer groupObject = S2I(BlzFrameGetText(but))
local player p = GetTriggerPlayer()
call ToggleIconButtonGroupClear(groupObject, p)
// remove focus
call BlzFrameSetEnable(but, false)
call BlzFrameSetEnable(but, true)
set ToggleIconButton_Index = 0
set ToggleIconButtonGroup_Index = groupObject
set ToggleIconButton_Player = p
set ToggleIconButtonGroup_Value = ToggleIconButtonGroupGetValue(groupObject, p)
call TriggerEvaluate(Action[groupObject])
endfunction
private module Init
private static method onInit takes nothing returns nothing
set Trigger = CreateTrigger()
call TriggerAddAction(Trigger, function GroupTriggerAction)
call TriggerAddAction(ClearTrigger, function ClearTriggerAction)
call TriggerAddAction(RightClickTrigger, function RightClickTriggerAction)
endmethod
endmodule
// Dummy struct that's only used for initialization purposes
private struct S extends array
implement Init
endstruct
endlibrary
library String initializer Init
//String functions v1.04
//made by MaskedPoptart
//--------------------IMPORTANT FUNCTIONS------------------------
function FindIndexFrom takes string mainString, string stringToFind, integer startingIndex returns integer
local integer msLength = StringLength(mainString)
local integer sfLength = StringLength(stringToFind)
local integer i = startingIndex
if(sfLength > msLength or i < 0)then
return -1
endif
loop
exitwhen i > msLength - sfLength
if(SubString(mainString, i, i+sfLength) == stringToFind)then
return i
endif
set i = i + 1
endloop
return -1
endfunction
function FindIndex takes string mainString, string stringToFind returns integer
return FindIndexFrom(mainString, stringToFind, 0)
endfunction
function FindLastIndexFrom takes string mainString, string stringToFind, integer startingIndex returns integer
local integer msLength = StringLength(mainString)
local integer sfLength = StringLength(stringToFind)
local integer i = msLength-sfLength
if(startingIndex < i)then
set i = startingIndex
endif
if(sfLength > msLength)then
return -1
endif
loop
exitwhen i < 0
if(SubString(mainString, i, i+sfLength) == stringToFind)then
return i
endif
set i = i - 1
endloop
return -1
endfunction
function FindLastIndex takes string mainString, string stringToFind returns integer
return FindLastIndexFrom(mainString, stringToFind, 2147483647)
endfunction
//-----------------------COLOR FUNCTIONS ------------------------
globals
private playercolor array PLAYER_COLORS
private string array PLAYER_COLOR_STRINGS
private constant string HEX_CHARS = "0123456789abcdef"
private string COLOR_ENDING = "|r"
endglobals
private function Init takes nothing returns nothing
local integer i = 0
loop
exitwhen i >= 12
set PLAYER_COLORS[i] = ConvertPlayerColor(i)
set i = i + 1
endloop
set PLAYER_COLOR_STRINGS[0] = "|cffff0303"
set PLAYER_COLOR_STRINGS[1] = "|cff0042ff"
set PLAYER_COLOR_STRINGS[2] = "|cff1ce6b9"
set PLAYER_COLOR_STRINGS[3] = "|cff540081"
set PLAYER_COLOR_STRINGS[4] = "|cfffffc01"
set PLAYER_COLOR_STRINGS[5] = "|cfffe8a0e"
set PLAYER_COLOR_STRINGS[6] = "|cff20c000"
set PLAYER_COLOR_STRINGS[7] = "|cffe55bb0"
set PLAYER_COLOR_STRINGS[8] = "|cff959697"
set PLAYER_COLOR_STRINGS[9] = "|cff7ebff1"
set PLAYER_COLOR_STRINGS[10] = "|cff106246"
set PLAYER_COLOR_STRINGS[11] = "|cff4e2a04"
set PLAYER_COLOR_STRINGS[12] = "|cff272727"
set PLAYER_COLOR_STRINGS[13] = "|cff272727"
set PLAYER_COLOR_STRINGS[14] = "|cff272727"
endfunction
function PlayerColor2ColorString takes playercolor pc returns string
local integer i = 0
loop
exitwhen i >= 12
if(PLAYER_COLORS[i] == pc)then
return PLAYER_COLOR_STRINGS[i]
endif
set i = i + 1
endloop
return PLAYER_COLOR_STRINGS[12]
endfunction
function GetPlayerColorString takes player p returns string
return PlayerColor2ColorString(GetPlayerColor(p))
endfunction
function GetPlayerNameColored takes player p returns string
return GetPlayerColorString(p)+GetPlayerName(p)+COLOR_ENDING
endfunction
//please use responsibly
function RemoveColorCode takes string mainString returns string
local integer msLength = StringLength(mainString)
if(msLength<12)then
return mainString
endif
return SubString(mainString, 10, msLength-2)
endfunction
function IBase2S takes integer base10Num, integer newBase returns string
local integer placeNum //number at current place
local string newBaseString = ""
loop
exitwhen base10Num == 0
set placeNum = ModuloInteger(base10Num, newBase)
set newBaseString = SubString(HEX_CHARS, placeNum, placeNum+1) + newBaseString
set base10Num = base10Num / newBase
endloop
if(newBaseString == "")then
return "0"
endif
return newBaseString
endfunction
function SBase2I takes string oldBaseString, integer oldBase returns integer
local integer base10Num = 0
local integer placeNum //number at current place
local integer placeIndex = 0 //index of current place. 0 = one's place, etc.
local integer i = StringLength(oldBaseString)-1
loop
exitwhen i < 0
set placeNum = FindLastIndexFrom(HEX_CHARS, SubString(oldBaseString, i, i+1), oldBase-1)
set base10Num = base10Num + placeNum*R2I(Pow(oldBase, placeIndex))
set placeIndex = placeIndex + 1
set i = i - 1
endloop
return base10Num
endfunction
function ConvertRGBToColorString takes integer red, integer green, integer blue returns string
local string RR
local string GG
local string BB
if(red>255)then
set red = 255
endif
if(green>255)then
set green = 255
endif
if(blue>255)then
set blue = 255
endif
set RR = IBase2S(red, 16)
set GG = IBase2S(green, 16)
set BB = IBase2S(blue, 16)
if(StringLength(RR)<2)then
set RR = "0"+RR
endif
if(StringLength(GG)<2)then
set GG = "0"+GG
endif
if(StringLength(BB)<2)then
set BB = "0"+BB
endif
return "|cff"+RR+GG+BB
endfunction
function GetColoredString takes string str, integer r, integer g, integer b returns string
return ConvertRGBToColorString(r,g,b)+str+COLOR_ENDING
endfunction
//----------------------CHAT EVENT FUNCTIONS------------------------------
function RemoveString takes string mainString, string toRemove returns string
local integer i = 0
local string currentString
local integer msLength = StringLength(mainString)
local integer trLength = StringLength(toRemove)
if(trLength > msLength)then
return mainString
endif
loop
exitwhen i+trLength > msLength
set currentString = SubString(mainString, i, i+trLength)
if(currentString == toRemove)then
if(i+trLength <= msLength)then
set mainString = SubString(mainString, 0, i)+SubString(mainString, i+trLength, msLength)
else
set mainString = SubString(mainString, 0, i)
endif
set i = i - trLength
endif
set i = i + 1
endloop
return mainString
endfunction
function NumOccurances takes string mainString, string stringToFind returns integer
local integer count = 0
local integer i = 0
local integer msLength = StringLength(mainString)
local integer sfLength = StringLength(stringToFind)
loop
exitwhen (i+sfLength) > msLength
if(SubString(mainString, i, i+sfLength) == stringToFind)then
set count = count + 1
endif
set i = i + 1
endloop
return count
endfunction
function S2B takes string word returns boolean
if(word == "true")then
return true
endif
return false
endfunction
function S2Player takes string word returns player
return Player(S2I(SubString(word, 1, StringLength(word))))
endfunction
globals
private integer MIN_RAW_CODE = ' ' //32
private string RAW_CHARS = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
endglobals
function S2RawCode takes string str returns integer
local integer rawCode = 0
local integer placeNum //number at current place
local integer placeIndex = 0 //index of current place. 0 = one's place, etc.
local integer i = StringLength(str)-1
loop
exitwhen i < 0
set placeNum = MIN_RAW_CODE + FindIndex(RAW_CHARS, SubString(str, i, i+1))
//the char at index 0 of RAW_CHARS has ASCII value 32, so we need to offset each FindIndex by 32.
set rawCode = rawCode + placeNum*R2I(Pow(256., placeIndex))
set placeIndex = placeIndex + 1
set i = i - 1
endloop
return rawCode
endfunction
//-----------------------DEBUG FUNCTIONS-------------------------
function B2S takes boolean bool returns string
if(bool)then
return "true"
endif
return "false"
endfunction
function Player2S takes player p returns string
return "Player("+I2S(GetPlayerId(p))+")"
endfunction
function Unit2S takes unit u returns string
return GetUnitName(u)+ "_"+I2S(GetHandleId(u)-0x100000)
endfunction
function RawCode2S takes integer rawCode returns string
local integer placeNum //number at current place
local string str = ""
if(rawCode < MIN_RAW_CODE)then
return str
endif
loop
exitwhen rawCode == 0
set placeNum = ModuloInteger(rawCode, 256) - MIN_RAW_CODE
set str = SubString(RAW_CHARS, placeNum, placeNum+1) + str
set rawCode = rawCode / 256
endloop
return str
endfunction
endlibrary
native GetUnitGoldCost takes integer rawCode returns integer
native GetUnitWoodCost takes integer rawCode returns integer
library TasButtonList initializer Init uses String, IsRightClick, optional FrameLoader, optional SimpleTooltip
// TasButtonList10c (CC) by Tasyen
//function CreateTasButtonList10 takes string buttonName, integer cols, integer rows, framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction, code asyncAction, code asyncRigthAction, real colGap, real rowGap returns integer
//function CreateTasButtonListEx takes string buttonName, integer cols, integer rows, framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction returns integer
//create a new List
//parent is the container of this Frame it will attach itself to its TOP.
//the given functions are called over Triggers
//buttonAction is the function that executes when an option is clicked.
//when your data are unit-RawCodes then you can skip updateAction & searchAction.
//updateAction runs for each Button and is used to set the diplayed content.
//searchAction is a function that returns true if the current data matches the searchText.
//filterAction is meant to be used when one wants an addtional non text based filtering, with returning true allowing data or false rejecting it.
//searchAction , udateAction & filterAction are async this functions should not do anything that alters the game state/flow.
//function CreateTasButtonList takes integer buttonCount, framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
// wrapper for CreateTasButtonListEx, 1 col, buttonCount rows.
//function CreateTasButtonListV2 takes integer rowCount, framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
// 2 Buttons each Row, takes more Height then the other Versions
//function CreateTasButtonListV3 takes integer rowCount, framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
// 3 Buttons each Row, only Icon, and Costs
//function TasButtonListClearDataEx takes integer listIndex, integer playerIndex returns nothing
//function TasButtonListClearData takes integer listIndex returns nothing
// remove all data
//function TasButtonListRemoveDataEx takes integer listIndex, integer data, integer playerIndex returns nothing
//function TasButtonListRemoveData takes integer listIndex, integer data returns nothing
// search for data and remove it
//function TasButtonListAddDataEx takes integer listIndex, integer data, integer playerIndex returns nothing
//function TasButtonListAddData takes integer listIndex, integer data returns nothing
// add data for one Button
//function TasButtonListCopyDataEx takes integer writeObject, integer readObject, integer playerIndex returns nothing
//function TasButtonListCopyData takes integer writeObject, integer readObject returns nothing
// writeObject uses the same data as readObject and calls UpdateButtonList.
//function UpdateTasButtonList takes integer listIndex returns nothing
// update the displayed Content should be done after Data was added or removed was used.
//function TasButtonListSearch takes integer listIndex, string text returns nothing
// The buttonList will search it's data for the given text, if nil is given as text it will search for what the user currently has in its box.
// This will also update the buttonList
globals
//args for custom user actions
integer TasButtonListData = 0
string TasButtonListText = ""
boolean TasButtonListIsSearching = false
integer TasButtonListIndex = 0
framehandle TasButtonListFrame = null
// System
public hashtable Hash = InitHashtable()
private integer Counter = 0 //amount of Lists created, each index is one List
private trigger SyncTrigger = CreateTrigger()
private trigger ButtonTrigger = CreateTrigger()
private trigger SearchTrigger = CreateTrigger()
private trigger ButtonScrollTrigger = CreateTrigger()
private trigger SliderTrigger = CreateTrigger()
private trigger SyncRightTrigger = CreateTrigger()
private trigger ButtonRightTrigger = CreateTrigger()
private sound RightClickSound
// ButtonLists
framehandle array TasButtonListSlider
framehandle array TasButtonListSliderText
framehandle array TasButtonListParent
framehandle array TasButtonListInputFrame
framehandle array TasButtonListSyncFrame
framehandle array TasButtonListSyncFrameRight
integer array TasButtonListButtonCount
integer array TasButtonListCreateContext
string array TasButtonListButtonName
integer array TasButtonListStepSize
trigger array TasButtonListButtonAction
trigger array TasButtonListRightAction
trigger array TasButtonListUpdateAction
trigger array TasButtonListSearchAction
trigger array TasButtonListFilterAction
trigger array TasButtonListAsyncAction
trigger array TasButtonListAsyncRightAction
integer array TasButtonListViewPoint
location array TasButtonListDataList
location array TasButtonListDataListFiltered
real TasButtonListGapCol = 0.0
real TasButtonListGapRow = 0.0
public integer CreateContextCounter = 0
endglobals
// update the shown content
function UpdateTasButtonList takes integer listIndex returns nothing
local integer dataHash = GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), GetPlayerId(GetLocalPlayer())))
local integer filteredDataHash = GetHandleId(TasButtonListDataListFiltered[listIndex])
local integer dataFilteredCount = LoadInteger(Hash, filteredDataHash, 0)
local integer i = 1
set TasButtonListIndex = listIndex
call BlzFrameSetVisible(TasButtonListSlider[listIndex], dataFilteredCount > TasButtonListButtonCount[listIndex])
loop
exitwhen i > TasButtonListButtonCount[listIndex]
set TasButtonListFrame = BlzGetFrameByName(TasButtonListButtonName[listIndex], TasButtonListCreateContext[listIndex] + i)
if dataFilteredCount >= i then
set TasButtonListData = LoadInteger(Hash, dataHash, LoadInteger(Hash, filteredDataHash, i + TasButtonListViewPoint[listIndex]))
call TriggerEvaluate(TasButtonListUpdateAction[listIndex])
call BlzFrameSetVisible(TasButtonListFrame, true)
else
call BlzFrameSetVisible(TasButtonListFrame, false)
endif
set i = i + 1
endloop
endfunction
function TasButtonListSearch takes integer listIndex, string text returns nothing
local integer filteredDataHash = GetHandleId(TasButtonListDataListFiltered[listIndex])
local integer dataHash = GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), GetPlayerId(GetLocalPlayer())))
local integer filteredDataCount
local integer i
local integer iEnd
if text == null or text == "" then
set text = BlzFrameGetText(TasButtonListInputFrame[listIndex])
endif
if GetLocalPlayer() == GetTriggerPlayer() then
set TasButtonListText = text
set TasButtonListIndex = listIndex
call FlushChildHashtable(Hash, filteredDataHash)
set filteredDataCount = 0
if text != "" then
set TasButtonListIsSearching = true
set iEnd = LoadInteger(Hash, dataHash, 0)
set i = 1
loop
exitwhen i > iEnd
set TasButtonListData = LoadInteger(Hash, dataHash, i)
if TriggerEvaluate(TasButtonListSearchAction[listIndex]) and TriggerEvaluate(TasButtonListFilterAction[listIndex]) then
set filteredDataCount = filteredDataCount + 1
call SaveInteger(Hash, filteredDataHash, filteredDataCount, i)
endif
set i = i + 1
endloop
call SaveInteger(Hash, filteredDataHash, 0, filteredDataCount)
else
set TasButtonListIsSearching = false
set iEnd = LoadInteger(Hash, dataHash, 0)
set i = 1
loop
exitwhen i > iEnd
set TasButtonListData = LoadInteger(Hash, dataHash, i)
if TriggerEvaluate(TasButtonListFilterAction[listIndex]) then
set filteredDataCount = filteredDataCount + 1
call SaveInteger(Hash, filteredDataHash, filteredDataCount, i)
endif
set i = i + 1
endloop
call SaveInteger(Hash, filteredDataHash, 0, filteredDataCount)
endif
//update Slider, with that also update
call BlzFrameSetMinMaxValue(TasButtonListSlider[listIndex], TasButtonListButtonCount[listIndex], filteredDataCount)
call BlzFrameSetValue(TasButtonListSlider[listIndex], 999999)
endif
endfunction
function TasButtonListTriggerActionSync takes nothing returns nothing
local integer listIndex = LoadInteger(Hash, GetHandleId(BlzGetTriggerFrame()), 0)
local integer dataIndex = R2I(BlzGetTriggerFrameValue() + 0.5)
set TasButtonListData = LoadInteger(Hash, GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), GetPlayerId(GetTriggerPlayer()))), dataIndex)
set TasButtonListIndex = listIndex
call TriggerExecute(TasButtonListButtonAction[listIndex])
call UpdateTasButtonList(listIndex)
endfunction
function TasButtonListTriggerActionButton takes nothing returns nothing
local framehandle frame = BlzGetTriggerFrame()
local integer buttonIndex = LoadInteger(Hash, GetHandleId(frame), 1)
local integer listIndex = LoadInteger(Hash, GetHandleId(frame), 0)
local integer dataIndex = LoadInteger(Hash, GetHandleId(TasButtonListDataListFiltered[listIndex]), buttonIndex + TasButtonListViewPoint[listIndex])
local integer data = LoadInteger(Hash, GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), GetPlayerId(GetTriggerPlayer()))), dataIndex)
call BlzFrameSetEnable(frame, false)
call BlzFrameSetEnable(frame, true)
set TasButtonListData = data
set TasButtonListIndex = listIndex
set TasButtonListFrame = frame
if GetLocalPlayer() == GetTriggerPlayer() then
call TriggerEvaluate(TasButtonListAsyncAction[listIndex])
call BlzFrameSetValue(TasButtonListSyncFrame[listIndex], dataIndex)
endif
set frame = null
endfunction
function TasButtonListTriggerActionSearch takes nothing returns nothing
call TasButtonListSearch(LoadInteger(Hash, GetHandleId(BlzGetTriggerFrame()), 0), null)
endfunction
// scrolling while pointing on Buttons
function TasButtonListTriggerActionButtonScroll takes nothing returns nothing
local integer listIndex = LoadInteger(Hash, GetHandleId(BlzGetTriggerFrame()), 0)
local framehandle frame = TasButtonListSlider[listIndex]
if GetLocalPlayer() == GetTriggerPlayer() then
if BlzGetTriggerFrameValue() > 0 then
call BlzFrameSetValue(frame, BlzFrameGetValue(frame) + TasButtonListStepSize[listIndex])
else
call BlzFrameSetValue(frame, BlzFrameGetValue(frame) - TasButtonListStepSize[listIndex])
endif
endif
set frame = null
endfunction
// scrolling while pointing on slider aswell as calling
function TasButtonListTriggerActionSlider takes nothing returns nothing
local integer listIndex = LoadInteger(Hash, GetHandleId(BlzGetTriggerFrame()), 0)
local integer filteredDataHash = GetHandleId(TasButtonListDataListFiltered[listIndex])
local integer dataFilteredCount = LoadInteger(Hash, filteredDataHash, 0)
local framehandle frame = BlzGetTriggerFrame()
if GetLocalPlayer() == GetTriggerPlayer() then
if BlzGetTriggerFrameEvent() == FRAMEEVENT_MOUSE_WHEEL then
if BlzGetTriggerFrameValue() > 0 then
call BlzFrameSetValue(frame, BlzFrameGetValue(frame) + TasButtonListStepSize[listIndex])
else
call BlzFrameSetValue(frame, BlzFrameGetValue(frame) - TasButtonListStepSize[listIndex])
endif
else
// when there is enough data use viewPoint. the Viewpoint is reduced from the data to make top being top.
if dataFilteredCount > TasButtonListButtonCount[listIndex] then
set TasButtonListViewPoint[listIndex] = dataFilteredCount - R2I(BlzGetTriggerFrameValue())
else
set TasButtonListViewPoint[listIndex] = 0
endif
if TasButtonListSliderText[listIndex] != null then
call BlzFrameSetText(TasButtonListSliderText[listIndex], I2S(R2I(0.5 + dataFilteredCount - BlzFrameGetValue(frame))) + "/" + I2S(R2I(0.5 + dataFilteredCount - TasButtonListButtonCount[listIndex])))
endif
call UpdateTasButtonList(listIndex)
endif
endif
set frame = null
endfunction
// runs once for each button shown
function UpdateTasButtonListDefaultObject takes nothing returns nothing
//TasButtonListFrame
//TasButtonListData
//TasButtonListIndex
local integer frameHandle = GetHandleId(TasButtonListFrame)
local integer data = TasButtonListData
local integer buttonIndex = LoadInteger(Hash, frameHandle, 1)
local integer listIndex = LoadInteger(Hash, frameHandle, 0)
local integer lumber
local integer gold
local integer context = TasButtonListCreateContext[listIndex] + buttonIndex
call BlzFrameSetTexture(BlzGetFrameByName("TasButtonIcon", context), BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetText(BlzGetFrameByName("TasButtonText", context), GetObjectName(data))
call BlzFrameSetTexture(BlzGetFrameByName("TasButtonListTooltipIcon", context), BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetText(BlzGetFrameByName("TasButtonListTooltipName", context), GetObjectName(data))
call BlzFrameSetText(BlzGetFrameByName("TasButtonListTooltipText", context), BlzGetAbilityExtendedTooltip(data, 0))
if not IsUnitIdType(data, UNIT_TYPE_HERO) then
// GetUnitWoodCost GetUnitGoldCost CRASH with heroes
set lumber = GetUnitWoodCost(data)
set gold = GetUnitGoldCost(data)
if GetPlayerState(GetLocalPlayer(), PLAYER_STATE_RESOURCE_GOLD) >= gold then
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", context), I2S(GetUnitGoldCost(data)))
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", context), "|cffff2010" + I2S(GetUnitGoldCost(data)))
endif
if GetPlayerState(GetLocalPlayer(), PLAYER_STATE_RESOURCE_LUMBER) >= lumber then
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", context), I2S(GetUnitWoodCost(data)))
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", context), "|cffff2010" + I2S(GetUnitWoodCost(data)))
endif
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", context), "0")
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", context), "0")
endif
endfunction
function SearchTasButtonListDefaultObject takes nothing returns boolean
//TasButtonListText
//TasButtonListData
//TasButtonListIndex
return FindIndex(GetObjectName(TasButtonListData), TasButtonListText) >= 0
endfunction
function InitTasButtonListObject8c takes framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction, code asyncAction, code asyncRigthAction returns integer
local framehandle frame
local integer playerIndex = 0
set Counter = Counter + 1
// the locations are created to have an unique slot in the hash which are used as something like a Lua table.
set TasButtonListDataList[Counter] = Location(0, 0) //
// each player also got an own list
loop
call SaveLocationHandle(Hash, GetHandleId(TasButtonListDataList[Counter]), playerIndex, Location(0,0))
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
endloop
set TasButtonListDataListFiltered[Counter] = Location(0, 0) //
set TasButtonListParent[Counter] = parent
set TasButtonListViewPoint[Counter] = 0
set TasButtonListButtonAction[Counter] = CreateTrigger() //call this inside the SyncAction after a button is clicked
set TasButtonListUpdateAction[Counter] = CreateTrigger() //function defining how to display stuff (async)
set TasButtonListFilterAction[Counter] = CreateTrigger() //function to return the searched Text (async)
set TasButtonListSearchAction[Counter] = CreateTrigger()
set TasButtonListRightAction[Counter] = CreateTrigger()
set TasButtonListAsyncAction[Counter] = CreateTrigger()
set TasButtonListAsyncRightAction[Counter] = CreateTrigger()
call TriggerAddAction(TasButtonListButtonAction[Counter], buttonAction)
if rightClickAction != null then
call TriggerAddAction(TasButtonListRightAction[Counter], rightClickAction)
endif
// update is a condition with it can be run with TriggerEvaluate in localPlayer code. TriggerExecute would desync
if updateAction == null then
call TriggerAddCondition(TasButtonListUpdateAction[Counter], Filter(function UpdateTasButtonListDefaultObject))
else
call TriggerAddCondition(TasButtonListUpdateAction[Counter], Filter(updateAction))
endif
if searchAction == null then
call TriggerAddCondition(TasButtonListSearchAction[Counter], Filter(function SearchTasButtonListDefaultObject))
else
call TriggerAddCondition(TasButtonListSearchAction[Counter], Filter(searchAction))
endif
if filterAction != null then
call TriggerAddCondition(TasButtonListFilterAction[Counter], Filter(filterAction))
endif
if asyncAction != null then
call TriggerAddCondition(TasButtonListAsyncAction[Counter], Filter(asyncAction))
endif
if asyncRigthAction != null then
call TriggerAddCondition(TasButtonListAsyncRightAction[Counter], Filter(asyncRigthAction))
endif
set frame = BlzCreateFrameByType("SLIDER", "", parent, "", 0)
set TasButtonListSyncFrame[Counter] = frame
call BlzFrameSetMinMaxValue(frame, 0, 9999999)
call BlzFrameSetStepSize(frame, 1.0)
call BlzTriggerRegisterFrameEvent(SyncTrigger, frame, FRAMEEVENT_SLIDER_VALUE_CHANGED)
call BlzFrameSetVisible(frame, false)
call SaveInteger(Hash, GetHandleId(frame), 0, Counter)
set frame = BlzCreateFrameByType("SLIDER", "", parent, "", 0)
set TasButtonListSyncFrameRight[Counter] = frame
call BlzFrameSetMinMaxValue(frame, 0, 9999999)
call BlzFrameSetStepSize(frame, 1.0)
call BlzTriggerRegisterFrameEvent(SyncRightTrigger, frame, FRAMEEVENT_SLIDER_VALUE_CHANGED)
call BlzFrameSetVisible(frame, false)
call SaveInteger(Hash, GetHandleId(frame), 0, Counter)
set frame = BlzCreateFrame("TasEditBox", parent, 0, 0)
set TasButtonListInputFrame[Counter] = frame
call BlzTriggerRegisterFrameEvent(SearchTrigger, frame, FRAMEEVENT_EDITBOX_TEXT_CHANGED)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPRIGHT, parent, FRAMEPOINT_TOPRIGHT, 0, 0)
call SaveInteger(Hash, GetHandleId(frame), 0, Counter)
set frame = null
return Counter
endfunction
// this should have beend called InitTasButtonListObject8
function InitTasButtonListObjectEx takes framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction returns integer
return InitTasButtonListObject8c(parent, buttonAction, rightClickAction, updateAction, searchAction, filterAction, null, null)
endfunction
function InitTasButtonListObject takes framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
return InitTasButtonListObjectEx(parent, buttonAction, null, updateAction, searchAction, filterAction)
endfunction
function InitTasButtonListSlider10a takes integer listIndex, integer stepSize, integer rowCount, real colGap, real rowGap returns nothing
local framehandle frame = BlzCreateFrameByType("SLIDER", "FrameListSlider", TasButtonListParent[listIndex], "QuestMainListScrollBar", 0)
local framehandle buttonFrame = BlzGetFrameByName(TasButtonListButtonName[listIndex], TasButtonListCreateContext[listIndex] + stepSize)
set TasButtonListSlider[listIndex] = frame
call SaveInteger(Hash, GetHandleId(frame), 0, listIndex) // the slider nows the TasButtonListobject
set TasButtonListStepSize[listIndex] = stepSize
call BlzFrameSetStepSize(frame, stepSize)
call BlzFrameClearAllPoints(frame)
call BlzFrameSetVisible(frame, true)
call BlzFrameSetMinMaxValue(frame, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, buttonFrame, FRAMEPOINT_TOPRIGHT, 0, 0)
call BlzFrameSetSize(frame, 0.012, BlzFrameGetHeight(buttonFrame) * rowCount + rowGap * (rowCount - 1))
call BlzTriggerRegisterFrameEvent(SliderTrigger, frame , FRAMEEVENT_SLIDER_VALUE_CHANGED)
call BlzTriggerRegisterFrameEvent(SliderTrigger, frame , FRAMEEVENT_MOUSE_WHEEL)
static if LIBRARY_SimpleTooltip then
set TasButtonListSliderText[listIndex] = CreateSimpleTooltip(TasButtonListSlider[listIndex], "1000/1000")
call BlzFrameClearAllPoints(TasButtonListSliderText[listIndex])
call BlzFrameSetPoint(TasButtonListSliderText[listIndex], FRAMEPOINT_BOTTOMRIGHT, TasButtonListSlider[listIndex], FRAMEPOINT_TOPLEFT, 0, 0)
endif
endfunction
function InitTasButtonListSlider takes integer listIndex, integer stepSize, integer rowCount returns nothing
call InitTasButtonListSlider10a(listIndex, stepSize, rowCount, 0, 0)
endfunction
//Demo Creators
function CreateTasButtonTooltip takes framehandle frameButton, framehandle parent, integer createContext returns nothing
local framehandle frameParent = BlzCreateFrame("TasButtonListTooltipBoxFrame", frameButton, 0, createContext)
local framehandle frame = BlzGetFrameByName("TasButtonListTooltipBox", createContext)
local framehandle frameText = BlzGetFrameByName("TasButtonListTooltipText", createContext)
call BlzGetFrameByName("TasButtonListTooltipIcon", createContext)
call BlzGetFrameByName("TasButtonListTooltipName", createContext)
call BlzGetFrameByName("TasButtonListTooltipSeperator", createContext)
call BlzFrameSetTooltip(frameButton, frameParent)
call BlzFrameSetPoint(frameText, FRAMEPOINT_TOPRIGHT, parent, FRAMEPOINT_TOPLEFT, -0.001, -0.052)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, BlzGetFrameByName("TasButtonListTooltipIcon", createContext), FRAMEPOINT_TOPLEFT, -0.005, 0.005)
call BlzFrameSetPoint(frame, FRAMEPOINT_BOTTOMRIGHT, frameText, FRAMEPOINT_BOTTOMRIGHT, 0.005, -0.005)
endfunction
function CreateTasButtonList10 takes string buttonName, integer cols, integer rows, framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction, code asyncAction, code asyncRigthAction, real colGap, real rowGap returns integer
local integer buttonCount = rows*cols
local integer listIndex = InitTasButtonListObject8c(parent, buttonAction, rightClickAction, updateAction, searchAction, filterAction, asyncAction, asyncRigthAction)
local integer i = 1
local framehandle frame
local integer frameHandle
local integer rowRemain = cols
set TasButtonListButtonName[listIndex] = buttonName
set TasButtonListCreateContext[listIndex] = CreateContextCounter
set TasButtonListButtonCount[listIndex] = buttonCount
loop
exitwhen i > buttonCount
set CreateContextCounter = CreateContextCounter + 1
set frame = BlzCreateFrame(buttonName, parent, 0, CreateContextCounter)
set frameHandle = GetHandleId(frame)
if frameHandle == 0 then
call BJDebugMsg("TasButtonList - Error - can't create Button:" + buttonName)
//return 0
endif
call SaveInteger(Hash, frameHandle, 1, i)
call SaveInteger(Hash, frameHandle, 0, listIndex)
call BlzFrameSetText(frame, I2S(i))
// for some reason in a lan test with same Pc the BlzFrameGetText was not set for the second User.
// restarting warcraft 3 fixed it.
//call BJDebugMsg("TasButtonList " + I2S(i) + " "+ BlzFrameGetText(frame))
//call SaveInteger(Hash, frameHandle, 2, CreateContextCounter)
call BlzTriggerRegisterFrameEvent(ButtonTrigger, frame, FRAMEEVENT_CONTROL_CLICK)
call BlzTriggerRegisterFrameEvent(ButtonRightTrigger, frame, FRAMEEVENT_MOUSE_UP)
call BlzTriggerRegisterFrameEvent(ButtonScrollTrigger, frame, FRAMEEVENT_MOUSE_WHEEL)
//give these handleIds to no desync when calling them in a async manner
call BlzGetFrameByName("TasButtonIcon", CreateContextCounter)
call BlzGetFrameByName("TasButtonText", CreateContextCounter)
call BlzGetFrameByName("TasButtonIconGold", CreateContextCounter)
call BlzGetFrameByName("TasButtonTextGold", CreateContextCounter)
call BlzGetFrameByName("TasButtonIconLumber", CreateContextCounter)
call BlzGetFrameByName("TasButtonTextLumber", CreateContextCounter)
call CreateTasButtonTooltip(frame, parent, CreateContextCounter)
if i > 1 then
if rowRemain == 0 then
call BlzFrameSetPoint(frame, FRAMEPOINT_TOP, BlzGetFrameByName(buttonName, CreateContextCounter - cols), FRAMEPOINT_BOTTOM, 0, -rowGap)
set rowRemain = cols
else
//call BlzFrameSetPoint(frame, FRAMEPOINT_RIGHT, BlzGetFrameByName(buttonName, CreateContextCounter - 1), FRAMEPOINT_LEFT, -colGap, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_LEFT, BlzGetFrameByName(buttonName, CreateContextCounter - 1), FRAMEPOINT_RIGHT, colGap, 0)
endif
else
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPRIGHT, TasButtonListInputFrame[listIndex], FRAMEPOINT_BOTTOMRIGHT, -BlzFrameGetWidth(frame)*cols - colGap*(cols-1), 0)
//call BlzFrameSetPoint(frame, FRAMEPOINT_TOPRIGHT, TasButtonListInputFrame[listIndex], FRAMEPOINT_BOTTOMRIGHT, 0, 0)
endif
set rowRemain = rowRemain - 1
set i = i + 1
endloop
call InitTasButtonListSlider10a(listIndex, cols, rows, colGap, rowGap)
set frame = null
return listIndex
endfunction
function CreateTasButtonList8c takes string buttonName, integer cols, integer rows, framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction, code asyncAction, code asyncRigthAction returns integer
return CreateTasButtonList10(buttonName, cols, rows, parent, buttonAction, rightClickAction, updateAction, searchAction, filterAction, asyncAction, asyncRigthAction, TasButtonListGapCol, TasButtonListGapRow)
endfunction
function CreateTasButtonListEx takes string buttonName, integer cols, integer rows, framehandle parent, code buttonAction, code rightClickAction, code updateAction, code searchAction, code filterAction returns integer
return CreateTasButtonList8c(buttonName, cols, rows, parent, buttonAction, rightClickAction, updateAction, searchAction, filterAction, null, null)
endfunction
function CreateTasButtonList takes integer buttonCount, framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
return CreateTasButtonListEx("TasButton", 1, buttonCount, parent, buttonAction, null, updateAction, searchAction, filterAction)
endfunction
function CreateTasButtonListV2 takes integer rowCount, framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
return CreateTasButtonListEx("TasButtonSmall", 2, rowCount, parent, buttonAction, null, updateAction, searchAction, filterAction)
endfunction
function CreateTasButtonListV3 takes integer rowCount, framehandle parent, code buttonAction, code updateAction, code searchAction, code filterAction returns integer
return CreateTasButtonListEx("TasButtonGrid", 3, rowCount, parent, buttonAction, null, updateAction, searchAction, filterAction)
endfunction
function TasButtonListAddDataEx takes integer listIndex, integer data, integer playerIndex returns nothing
local integer listHandle = GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), playerIndex))
local integer index = LoadInteger(Hash, listHandle, 0) + 1
local integer dataFilteredCount
call SaveInteger(Hash, listHandle, 0, index)
call SaveInteger(Hash, listHandle, index, data)
if GetLocalPlayer() == Player(playerIndex) then
// add to current filtered for local player only
set listHandle = GetHandleId(TasButtonListDataListFiltered[listIndex])
set dataFilteredCount = LoadInteger(Hash, listHandle, 0) + 1
call SaveInteger(Hash, listHandle, 0, dataFilteredCount)
call SaveInteger(Hash, listHandle, dataFilteredCount, index)
call BlzFrameSetMinMaxValue(TasButtonListSlider[listIndex], TasButtonListButtonCount[listIndex], dataFilteredCount)
endif
endfunction
function TasButtonListAddData takes integer listIndex, integer data returns nothing
local integer playerIndex = 0
loop
call TasButtonListAddDataEx(listIndex, data, playerIndex)
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
endloop
endfunction
function TasButtonListCopyDataEx takes integer writeObject, integer readObject, integer playerIndex returns nothing
local integer i = LoadInteger(Hash, GetHandleId(TasButtonListDataListFiltered[readObject]), 0)
local integer listHandleRead = GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[readObject]), playerIndex))
local integer listHandleWrite = GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[writeObject]), playerIndex))
call FlushChildHashtable(Hash, listHandleWrite)
call RemoveLocation(TasButtonListDataList[writeObject])
loop
exitwhen i < 0
call SaveInteger(Hash, listHandleWrite, i, LoadInteger(Hash, listHandleRead, i))
set i = i -1
endloop
if GetLocalPlayer() == Player(playerIndex) then
call BlzFrameSetMinMaxValue(TasButtonListSlider[writeObject], TasButtonListButtonCount[writeObject], LoadInteger(Hash, listHandleRead, 0))
call UpdateTasButtonList(writeObject)
endif
endfunction
function TasButtonListCopyData takes integer writeObject, integer readObject returns nothing
local integer playerIndex = 0
loop
call TasButtonListCopyDataEx(writeObject, readObject, playerIndex)
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
endloop
endfunction
function TasButtonListRemoveDataEx takes integer listIndex, integer data, integer playerIndex returns nothing
local integer listHandle = GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), playerIndex))
local integer i = LoadInteger(Hash, listHandle, 0)
local integer max = LoadInteger(Hash, listHandle, 0)
local integer temp
loop
exitwhen i <= 0
if LoadInteger(Hash, listHandle, 0) == data then
call SaveInteger(Hash, listHandle, i, LoadInteger(Hash, listHandle, max))
call SaveInteger(Hash, listHandle, 0, max - 1)
call RemoveSavedInteger(Hash, listHandle, max)
exitwhen true
endif
set i = i - 1
endloop
if GetLocalPlayer() == Player(playerIndex) then
call BlzFrameSetMinMaxValue(TasButtonListSlider[listIndex], TasButtonListButtonCount[listIndex], LoadInteger(Hash, listHandle, 0))
endif
endfunction
function TasButtonListRemoveData takes integer listIndex, integer data returns nothing
local integer playerIndex = 0
loop
call TasButtonListRemoveDataEx(listIndex, data, playerIndex)
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
endloop
endfunction
function TasButtonListClearDataEx takes integer listIndex, integer playerIndex returns nothing
call FlushChildHashtable(Hash, GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), playerIndex)))
if GetLocalPlayer() == Player(playerIndex) then
call FlushChildHashtable(Hash, GetHandleId(TasButtonListDataListFiltered[listIndex]))
call BlzFrameSetMinMaxValue(TasButtonListSlider[listIndex], 0, 0)
endif
endfunction
function TasButtonListClearData takes integer listIndex returns nothing
local integer playerIndex = 0
loop
call TasButtonListClearDataEx(listIndex, playerIndex)
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
endloop
endfunction
private function SyncRightTriggerAction takes nothing returns nothing
local integer listIndex = LoadInteger(Hash, GetHandleId(BlzGetTriggerFrame()), 0)
local integer dataIndex = R2I(BlzGetTriggerFrameValue() + 0.5)
set TasButtonListData = LoadInteger(Hash, GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), GetPlayerId(GetTriggerPlayer()))), dataIndex)
set TasButtonListIndex = listIndex
call TriggerExecute(TasButtonListRightAction[listIndex])
call UpdateTasButtonList(listIndex)
endfunction
private function ButtonRightClickTriggerAction takes nothing returns nothing
local framehandle frame = BlzGetTriggerFrame()
local integer buttonIndex = LoadInteger(Hash, GetHandleId(frame), 1)
local integer listIndex = LoadInteger(Hash, GetHandleId(frame), 0)
local integer dataIndex = LoadInteger(Hash, GetHandleId(TasButtonListDataListFiltered[listIndex]), buttonIndex + TasButtonListViewPoint[listIndex])
local integer data = LoadInteger(Hash, GetHandleId(LoadLocationHandle(Hash, GetHandleId(TasButtonListDataList[listIndex]), GetPlayerId(GetTriggerPlayer()))), dataIndex)
set TasButtonListData = data
set TasButtonListIndex = listIndex
set TasButtonListFrame = frame
if IsRightClick(GetTriggerPlayer()) and GetLocalPlayer() == GetTriggerPlayer() then
call TriggerEvaluate(TasButtonListAsyncRightAction[listIndex])
call StartSound(RightClickSound)
call BlzFrameSetValue(TasButtonListSyncFrameRight[listIndex], dataIndex)
endif
endfunction
private function LoadToc takes nothing returns nothing
// this function should be Repeated when the game is loaded
call BlzLoadTOCFile("war3mapimported\\TasButtonList.toc")
set CreateContextCounter = 0
endfunction
private function Init takes nothing returns nothing
local integer loopA = 0
call LoadToc()
static if LIBRARY_FrameLoader then
call FrameLoaderAdd(function LoadToc)
endif
call TriggerAddAction(SyncTrigger, function TasButtonListTriggerActionSync)
call TriggerAddAction(ButtonTrigger, function TasButtonListTriggerActionButton)
call TriggerAddAction(SearchTrigger, function TasButtonListTriggerActionSearch)
call TriggerAddAction(ButtonScrollTrigger, function TasButtonListTriggerActionButtonScroll)
call TriggerAddAction(SliderTrigger, function TasButtonListTriggerActionSlider)
call TriggerAddAction(SyncRightTrigger, function SyncRightTriggerAction)
call TriggerAddAction(ButtonRightTrigger, function ButtonRightClickTriggerAction)
set RightClickSound = CreateSound("Sound\\Interface\\MouseClick1.wav", false, false, false, 10, 10, "")
call SetSoundParamsFromLabel(RightClickSound, "InterfaceClick")
call SetSoundDuration(RightClickSound, 239)
endfunction
endlibrary
library TasItemShopGUILoader initializer init_function requires TasItemShop
private function fusion takes nothing returns nothing
local integer i = 1
loop
exitwhen udg_TasItemShop_Mats[i] == 0
call TasItemFusionAdd(udg_TasItemShop_Item, udg_TasItemShop_Mats[i])
set udg_TasItemShop_Mats[i] = 0
set i = i + 1
endloop
endfunction
private function add takes nothing returns nothing
call TasItemShopAdd(udg_TasItemShop_Item, udg_TasItemShop_Category)
endfunction
private function category takes nothing returns nothing
set udg_TasItemShop_Category = TasItemShopAddCategory(udg_TasItemShop_Icon, udg_TasItemShop_Text)
endfunction
private function createShop takes nothing returns nothing
local integer i = 1
call TasItemShopCreateShop(udg_TasItemShop_Unit, udg_TasItemShop_WhiteList, udg_TasItemShop_Gold, udg_TasItemShop_Lumber, null)
loop
exitwhen udg_TasItemShop_Mats[i] == 0
call TasItemShopAddShop(udg_TasItemShop_Unit, udg_TasItemShop_Mats[i])
set udg_TasItemShop_Mats[i] = 0
set i = i + 1
endloop
endfunction
private function haggle takes nothing returns nothing
local integer skill = udg_TasItemShop_Skill
if skill == 0 then
set skill = udg_TasItemShop_Buff
endif
call TasItemShopAddHaggleSkill(skill, udg_TasItemShop_Gold, udg_TasItemShop_Lumber, udg_TasItemShop_GoldAdd, udg_TasItemShop_LumberAdd)
set udg_TasItemShop_Buff = 0
set udg_TasItemShop_Skill = 0
endfunction
private function costs takes nothing returns nothing
call TasItemShopGoldFactor(udg_TasItemShop_Unit, udg_TasItemShop_Gold, udg_TasItemShop_Item)
call TasItemShopLumberFactor(udg_TasItemShop_Unit, udg_TasItemShop_Lumber, udg_TasItemShop_Item)
endfunction
private function shortCuts takes nothing returns nothing
local integer i = 1
call TasItemShop_ClearQuickLink(udg_TasItemShop_Player)
loop
exitwhen udg_TasItemShop_Mats[i] == 0
call TasItemShop_SetQuickLink(udg_TasItemShop_Player, udg_TasItemShop_Mats[i])
set udg_TasItemShop_Mats[i] = 0
set i = i + 1
endloop
endfunction
private function init_function takes nothing returns nothing
set udg_TasItemShopFusion = CreateTrigger()
set udg_TasItemShopAdd = CreateTrigger()
set udg_TasItemShopCategory = CreateTrigger()
set udg_TasItemShopCreateShop = CreateTrigger()
set udg_TasItemShopHaggle = CreateTrigger()
set udg_TasItemShopCosts = CreateTrigger()
set udg_TasItemShopShortCuts = CreateTrigger()
call TriggerAddAction(udg_TasItemShopFusion, function fusion)
call TriggerAddAction(udg_TasItemShopAdd, function add)
call TriggerAddAction(udg_TasItemShopCategory, function category)
call TriggerAddAction(udg_TasItemShopCreateShop, function createShop)
call TriggerAddAction(udg_TasItemShopHaggle, function haggle)
call TriggerAddAction(udg_TasItemShopCosts, function costs)
call TriggerAddAction(udg_TasItemShopShortCuts, function shortCuts)
endfunction
endlibrary
library TasItemShop initializer init_function requires TasItemFusion, Power2, Table, ItemHolder, ToggleIconButtonGroup, optional FrameLoader
// TasItemShopV4m by Tasyen
// TasItemSetCategory(itemCode, category)
// TasItemShopAdd(itemCode, category)
// adds itemCode to the common Buyable Item pool and sets the category
// TasItemShopAdd5(itemCodeA, itemCodeB, itemCodeC, itemCodeD, itemCodeE)
// adds 5 itemCodes to the common Buyable Item pool and sets the category to none
// wrapper for TasItemShopAdd
// TasItemShopAddCategory(icon, text)
// define a new Category, should be done before the UI is created.
// Returns the value of the new category
// TasItemShopCreateShop(unitCode, whiteList, goldFactor, lumberFactor, goldFunction, lumberFunction)
// TasItemShopAddShop(unitCode, itemCode)
// adds itemcode for that specific shop
// TasItemShopAddShop5(unitCode, itemCodeA, itemCodeB, itemCodeC, itemCodeD, itemCodeE)
// add 5 itemCodes to that shop
// // wrapper for TasItemShopAddShop
// TasItemShopGoldFactor(unitCode, factor, itemCode)
// sets the goldFactor for that shop to the given data
// use 0 to change the default
// TasItemShopLumberFactor(unitCode, factor, itemCode)
// lumberFactor ^^
// TasItemShopAddHaggleSkill(skill, goldBase, lumberBase, goldAdd, lumberAdd)
// adds a new Skill which will affect the costs in TasItemShop.
// TasItemShop_SetQuickLink(player, integer itemCode)
// add/remove itemCode from quickLink for player
// TasItemShop_ClearQuickLink(player)
// TasItemShopUIShow(player, shop, shopperGroup, mainShoper)
// TasItemShopUIShow(player) hides the shop for player
// shopperGroup are all units providing items, if you use null the current shoppergroup remains intact. When giving something else the group contains only mainShoper.
// mainShoper is the unit consider for haggel and gains the items. If you gave a group then you can skip mainShoper then a random is taken.
// with player and shop the shoppers are kept but the shop updates.
// Beaware that this System does only update on user input it will not check distance/live or anything.
// from TasItemFusion Add2 to Add6 are wrappers that call TasItemFusionAdd multiple times.
// TasItemFusionAdd onto the same result adds more mats.
// function TasItemFusionAdd takes integer result, integer mat returns nothing
// function TasItemFusionAdd2 takes integer result, integer a, integer b returns nothing
// function TasItemFusionAdd3 takes integer result, integer a, integer b, integer c returns nothing
// function TasItemFusionAdd4 takes integer result, integer a, integer b, integer c, integer d returns nothing
// function TasItemFusionAdd5 takes integer result, integer a, integer b, integer c, integer d, integer e returns nothing
// function TasItemFusionAdd6 takes integer result, integer a, integer b, integer c, integer d, integer e, integer f returns nothing
globals
// Config Start
public real xPos = 0.0
public real yPos = -0.02
public framepointtype posPoint = FRAMEPOINT_TOPRIGHT
public boolean posScreenRelative = true //(true) repos to the screenSize, when the resolution mode changes the box will move further in/out when using a right or Left point.
// It is advised to posScreenRelative = false when posPoint does not include Left or Right
// with posScreenRelative = false xPos and yPos are abs coords, to which posPoint of the Shop UI is placed to.
// position of Item toolTips, this does not affect the tooltips for Categories or Users.
// toolTipPosPointParent = null, if you want a specific position on screen.
// with toolTipPosPoint & toolTipPosPointParent are toolTipPosX & toolTipPosY relative offsets.
// The position is a bit wierd, the position is not the box but the Extended Tooltip Text, the Header has a height of ~0.052.
public real toolTipPosX = 0.0
public real toolTipPosY = -0.052
public framepointtype toolTipPosPoint = FRAMEPOINT_TOPRIGHT
public framepointtype toolTipPosPointParent = FRAMEPOINT_BOTTOMRIGHT
//public framepointtype toolTipPosPointParent = null
public real toolTipSizeX = 0.2 // only content
public real toolTipSizeXBig = 0.3 // only content
public real toolTipLimitBig = 300 // When a TooltipText Contains this amount or more of Chars it will use toolTipSizeXBig
// this can be used to change the visual ("EscMenuControlBackdropTemplate") ("TasItemShopRaceBackdrop")
public string boxFrameName = "TasItemShopRaceBackdrop"
public string boxButtonListFrameName = "EscMenuControlBackdropTemplate"
public string boxRefFrameName = "EscMenuControlBackdropTemplate"
public string boxCatFrameName = "EscMenuControlBackdropTemplate"
public string boxUndoFrameName = "TasItemShopRaceBackdrop"
public string boxDefuseFrameName = "TasItemShopRaceBackdrop"
public string buttonListHighLightFrameName = "TasItemShopSelectedHighlight"
public real boxFrameBorderGap = 0.0065
public real boxButtonListBorderGap = 0.0065 // does nothing right now
public real boxRefBorderGap = 0.0065
public real boxCatBorderGap = 0.0055
public real boxUndoBorderGap = 0.0045
public real boxDefuseBorderGap = 0.0045
public real boxSellBorderGap = 0.0045
public real buttonListButtonGapCol = 0.001
public real buttonListButtonGapRow = 0.005
// material control
public boolean flexibleShop = false // (true) can sell items not added to the shop. This includes items reached over RefButtons and material for autocompletion. I don't know that item, but your description is enough. I craft it, no problem.
public boolean sharedItems = false // (false) can only fuse material owned by neutral passive (default) or oneself. The code handling that is in TasItemFusion.
public boolean canProviderGetItem = true // (true) when the mainShopper's inventory is full, try to give the other matieral provider the item
public boolean canUndo = true // (true) There is an Undo Button which allows to Revert BuyActions done in this shopping. A shopping ends when the UI is closed, changing current shop counts as closed.
public boolean canDefuse = true // (true) There is a Defuse Button which allows to defuse FusionItems hold.
public string DefuseButtonIcon = "ReplaceableTextures\\CommandButtons\\BTNdemolish"
public string DefuseButtonIconDisabled = "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNdemolish"
public boolean canSellItems = true // (true)
public real SellFactor = 0.75
public boolean SellUsesCostModifier = true
public string SellButtonIcon = "ReplaceableTextures\\CommandButtons\\BTNReturnGoods"
public string SellButtonIconDisabled = "ReplaceableTextures\\CommandButtonsDisabled\\DISBTNReturnGoods"
public string MainUserTexture = "ui\\widgets\\console\\human\\commandbutton\\human-multipleselection-border"
public string MainItemTexture = "ui\\widgets\\console\\human\\commandbutton\\human-multipleselection-border"
public real shopRange = 900 // the max distance between shop and Shoper, this can be overwritten by shopObject.Range.
public real updateTime = 0.4 // how many seconds pass before a new update is applied. update: search new shopers, validat current shopers and update UI.
// Titel-text in the reference Boxes
public string textUpgrades = "COLON_UPGRADE" //tries to localize on creation
public string textMats = "SCORESCREEN_TAB3"
public string textInventory = "INVENTORY"
public string textUser = "USER"
public string textCanNotBuyPrefix = "Can not buy: "
public string textCanNotBuySufix = "OUTOFSTOCKTOOLTIP"
public string textNoValidShopper = "No valid Shoper"
public string textUndo = "Undo: "
public string textUnBuyable = "xxxxxxx"
public string textDefuse = "Defuse:"
public string textSell = "Sell:"
public string textQuickLink = "ShortCuts:"
public string categoryModeTextAnd = "ui\\widgets\\battlenet\\bnet-mainmenu-friends-disabled"
public string categoryModeTextOr = "Or"
public string categoryModeIconOr = "ui\\widgets\\battlenet\\bnet-mainmenu-friends-up"
public string categoryModeIconAnd = "And"
public oskeytype quickLinkKey = OSKEY_LSHIFT // null will prevent the user from changing shortcuts.
// how many refButtons, refButtons have pages, if needed.
// A feature is disabled with a counter smaller than 1.
public integer refButtonCountMats = 4 // materialRefs.
public integer refButtonCountUp = 4 // possible upgrades of the current Selected
public integer refButtonCountInv = 6 // inventory items, this system allows an unitgroup to provide items, if you don't use that feature only upto 6 makes sense.
public integer refButtonCountUser = 6 // References to the shopping Units/material provider.
public integer refButtonCountQuickLink = 4 // User SelectAble Shortcuts
public real refButtonSize = 0.02
public real refButtonGap = 0.003
public real refButtonPageSize = 0.012
public boolean refButtonPageRotate = true //(true) swap to first page when going above last page, and swap to last page when going down first Page
public string refButtonPageUp = "ReplaceableTextures\\CommandButtons\\BTNReplay-SpeedUp"
public string refButtonPageDown = "ReplaceableTextures\\CommandButtons\\BTNReplay-SpeedDown"
public real refButtonBoxSizeY = 0.047
// (true) right clicking an refInventoryButton in the UI will sell the item
// (false) right clicking it will buy it again.
public boolean inventoryRightClickSell = true
public boolean inventoryShowMainOnly = true // (false) show all items currently useable
public boolean userButtonOrder = true // (true) Create an UnitTargetOrder Event enables right clicking Units in the world to swap main shoppers.
public real doubleClickTimeOut = 2.0 // amount of seconds a doppleclick inside the Buttonlist counts as Buying
// model displayed when buy request was started.
//public string spriteModel = "UI\\Feedback\\GoldCredit\\GoldCredit.mdl" // in 1.31 the coins are black only.
//public string spriteModel = "Abilities\\Weapons\\RockBoltMissile\\RockBoltMissile.mdl"
//public string spriteModel = "Abilities\\Weapons\\BansheeMissile\\BansheeMissile.mdl"
//public string spriteModel = "Abilities\\Spells\\Other\\GeneralAuraTarget\\GeneralAuraTarget.mdl"
public string spriteModel = "war3mapImported\\BansheeMissile.mdx" //by abfal, (no sound).
public real spriteScale = 0.0006 // The scale has to fit the used model. if you use non-UI models use a low scale, 0.001 or below.
public integer spriteAnimationIndex = 1 // 1 = death animation
public integer buttonListRows = 5
// buttonListCols has a strong impact on the xSize of this UI. make sure that refButtons of one type fit into this.
public integer buttonListCols = 3
// this will not change the size of the Buttons, nor the space the text can take
// true = Show
// false = hide
public boolean buttonListShowGold = true
public boolean buttonListShowLumber = true
public boolean buyButtonShowGold = true
public boolean buyButtonShowLumber = true
// which button is used inside the ButtonList? Enable one block and disable the other one
public string buttonListButtonName = "TasButtonSmall"
public real buttonListButtonSizeX = 0.1
public real buttonListButtonSizeY = 0.0325
// "TasButtonGrid" are smaller, they don't show the names in the list
//public string buttonListButtonName = "TasButtonGrid"
//public real buttonListButtonSizeX = 0.064
//public real buttonListButtonSizeY = 0.0265
public real categoryButtonSize = 0.019
// -------
// Config End
// System variables Start
// -------
public integer array Selected
public integer array SelectedCategory
public item array SelectedItem
public timer Timer
public boolean IsReforged
public group TempGroup = CreateGroup()
public unit TempUnit
public real TempRange
public player TempPlayer
public integer CREATE_CONTEXT_CURRENT = -1
public integer CREATE_CONTEXT_SELL = -2
public integer ButtonListIndex // this is the index of the used TasButtonList.
public integer CategoryModButtonIndex // this is the ToggleIconButton that toggles between items have to fit all categories or one.
public integer RefButtonBoxRows = 0
public framehandle array RefButtonBoxFrameLast
public framehandle array RefButtonBoxFrameFirst
public real array RefButtonBoxSize
public Table Shops
public integer ShopCount = 0
public real array ShopRange
public boolean array ShopWhiteList
public trigger array ShopCostAction
public HashTable ShopsItems
public HashTable ShopsGold
public HashTable ShopsLumber
public Table array UndoItems
public Table array UndoResults
public integer array UndoResultCode
public integer array UndoGold
public integer array UndoLumber
public integer UndoPlayerSize = 800
public integer array UndoPlayerCount
public string array UndoActionName
public item array UndoStackGainer
public integer array UndoStackGained
public Table TasItemCategory
public string array CategoryIcon
public string array CategoryText
public integer CategoryCount = 0
public integer array CategoryValues
public integer MissingCount = 0
public integer array MissingItemCode
public integer array HaggleSkill
public real array HaggleGold
public real array HaggleLumber
public real array HaggleLumberAdd
public real array HaggleGoldAdd
public integer HaggleCount = 0
public integer array CategoryPlayerValues
public framehandle FrameSprite
public framehandle FrameSpriteParent
public framehandle FrameParentSuper
public framehandle FrameParentSuperUI
public framehandle FrameSuperBox
public framehandle FrameTitelText
public framehandle FrameFullscreen
public framehandle FrameTasButtonList
public framehandle FrameCategoryBox
public framehandle FrameUndoBox
public framehandle FrameUndoButton
public framehandle FrameUndoButtonIcon
public framehandle FrameUndoButtonIconPushed
public framehandle FrameUndoText
public framehandle FrameDefuseBox
public framehandle FrameDefuseButton
public framehandle FrameDefuseText
public framehandle FrameSellBox
public framehandle FrameSellButton
public framehandle FrameSellText
public framehandle FrameUserBox
public framehandle FrameUserText
public framehandle FrameUserPage
public framehandle FrameUserPageUp
public framehandle FrameUserPageText
public framehandle FrameUserPageDown
public framehandle FrameInventoryBox
public framehandle FrameInventoryText
public framehandle FrameInventoryPage
public framehandle FrameInventoryPageUp
public framehandle FrameInventoryPageText
public framehandle FrameInventoryPageDown
public framehandle FrameMaterialBox
public framehandle FrameMaterialText
public framehandle FrameMaterialPage
public framehandle FrameMaterialPageUp
public framehandle FrameMaterialPageText
public framehandle FrameMaterialPageDown
public framehandle FrameUpgradeBox
public framehandle FrameUpgradeText
public framehandle FrameUpgradePage
public framehandle FrameUpgradePageUp
public framehandle FrameUpgradePageText
public framehandle FrameUpgradePageDown
public Table array QuickLink
public boolean array QuickLinkKeyActive
public framehandle FrameQuickLinkBox
public framehandle FrameQuickLinkBoxHighLight
public framehandle FrameQuickLinkText
public framehandle FrameQuickLinkPage
public framehandle FrameQuickLinkPageUp
public framehandle FrameQuickLinkPageText
public framehandle FrameQuickLinkPageDown
public trigger ButtonTriggerInventory
public trigger ButtonTriggerInventoryPage
public trigger ButtonTriggerMaterial
public trigger ButtonTriggerMaterialPage
public trigger ButtonTriggerUser
public trigger ButtonTriggerUserPage
public trigger ButtonTriggerUpgrade
public trigger ButtonTriggerUpgradePage
public trigger ButtonTriggerSell
public trigger ButtonTriggerDefuse
public trigger ButtonTriggerBuy
public trigger ButtonTriggerUndo
public trigger ButtonTriggerClear
public trigger ButtonTriggerSelect
public trigger ButtonTriggerOrder
public trigger ButtonTriggerESC
public trigger ButtonTriggerClearFocus
public trigger ButtonTriggerParentScroll
public trigger ButtonTriggerCategoryMode
public trigger ButtonTriggerQuickLink
public trigger ButtonTriggerQuickLinkPage
public trigger ButtonTriggerQuickLinkKeyPress
public trigger ButtonTriggerQuickLinkKeyRelease
public integer RefButtonCount = 0
public framehandle array RefButton
public framehandle array RefButtonIcon
public framehandle array RefButtonIconPushed
public framehandle array RefButtonOverlay
public framehandle array RefButtonOverlay2
public framehandle array RefButtonToolTip
public framehandle array RefButtonToolTipIcon
public framehandle array RefButtonToolTipText
public framehandle array RefButtonToolTipName
//public unit array RefButtonUnit
//public item array RefButtonItem
//public integer array RefButtonItemCode
public integer RefButtonInventoryStart
public integer RefButtonInventoryEnd
public integer RefButtonUpgradeStart
public integer RefButtonUpgradeEnd
public integer RefButtonMaterialStart
public integer RefButtonMaterialEnd
public integer RefButtonUserStart
public integer RefButtonUserEnd
public integer RefButtonQuickLinkStart
public integer RefButtonQuickLinkEnd
public Table TempTable
public HashTable TempHashTable
public integer BUY_ABLE_ITEMS_Count = 0
// use TasItemShopAdd(itemCode, category) inside local function UserInit() to fill it
// This List is used by shops without custom data or by BlackList Shops
public integer array BUY_ABLE_ITEMS
public HashTable BuyAbleMarked
public Table MarkedItemCodes
public group array Shoper
public real DoubleClickStamp
public unit array ShoperMain
public unit array CurrentShop
public integer LocalShopObject
public integer array CurrentOffSetInventory
public integer array CurrentOffSetMaterial
public integer array CurrentOffSetUpgrade
public integer array CurrentOffSetUser
public integer array CurrentOffSetQuickLink
public real xSize // Size of the total Box
public real ySize // this is autocalced
public integer TempGold
public integer TempLumber
public real TempGoldR
public real TempLumberR
endglobals
public function GetParent takes nothing returns framehandle
local framehandle parent
if IsReforged then
set parent = BlzGetFrameByName("ConsoleUIBackdrop", 0)
else
call CreateLeaderboardBJ(bj_FORCE_ALL_PLAYERS, "title")
set parent = BlzGetFrameByName("Leaderboard", 0)
call BlzFrameSetSize(parent, 0, 0)
call BlzFrameSetVisible(BlzGetFrameByName("LeaderboardBackdrop", 0), false)
call BlzFrameSetVisible(BlzGetFrameByName("LeaderboardTitle", 0), false)
endif
return parent
endfunction
public function CostModifier takes real gold, real lumber, integer itemCode, unit buyer, unit shop, integer shopObject returns nothing
local integer loopA
local integer level
local integer skill
// this function is called for each Button that shows costs in the shop UI and right before buying the item.
// Beaware that this function is also called in a async manner -> no sideeffects or state changes.
// buyer got the Haggling skill?
set loopA = HaggleCount
loop
exitwhen loopA < 1
set skill = HaggleSkill[loopA]
set level = GetUnitAbilityLevel(buyer, skill)
if level > 0 then
set gold = gold * (HaggleGold[loopA] + HaggleGoldAdd[loopA]*level)
set lumber = lumber * (HaggleLumber[loopA] + HaggleLumberAdd[loopA]*level)
endif
set loopA = loopA - 1
endloop
if shopObject > 0 then
if ShopsGold[shopObject].real.has(itemCode) then
set gold = gold * ShopsGold[shopObject].real[itemCode]
set lumber = lumber * ShopsLumber[shopObject].real[itemCode]
else
set gold = gold * ShopsGold[shopObject].real[0]
set lumber = lumber * ShopsLumber[shopObject].real[0]
endif
set TempGoldR = gold
set TempLumberR = lumber
call TriggerEvaluate(ShopCostAction[Shops[shopObject]])
endif
set TempGold = R2I(gold + 0.5)
set TempLumber = R2I(lumber + 0.5)
endfunction
public function GetItemSellCosts takes unit u, unit shop, item i returns nothing
local integer itemCode = GetItemTypeId(i)
local integer gold
local integer lumber
local integer charges
set gold = R2I(TasItemGetCostGold(itemCode) * SellFactor)
set lumber = R2I(TasItemGetCostLumber(itemCode) * SellFactor)
if SellUsesCostModifier then
call CostModifier(gold, lumber, itemCode, u, shop, GetUnitTypeId(shop))
set gold = TempGold
set lumber = TempLumber
endif
set charges = TasItemGetCharges(itemCode)
if charges > 0 then
set gold = GetItemCharges(i)*gold/charges
set lumber = GetItemCharges(i)*lumber/charges
endif
set TempGold = gold
set TempLumber = lumber
endfunction
public function IsValidShopper takes player p, unit shop , unit u, real range returns boolean
if not IsUnitOwnedByPlayer(u, p) then
//print("IsUnitOwnedByPlayer")
return false
endif
if UnitInventorySize(u) < 1 then
//print("UnitInventorySize")
return false
endif
if IsUnitType(u, UNIT_TYPE_DEAD) then
//print("UNIT_TYPE_DEAD")
return false
endif
if IsUnitPaused(u) then
//print("IsUnitPaused")
return false
endif
if IsUnitHidden(u) then
//print("IsUnitHidden")
return false
endif
if IsUnitIllusion(u) then
//print("IsUnitIllusion")
return false
endif
if not IsUnitInRange(shop, u, range) then
//print("not IsUnitInRange")
return false
endif
return true
endfunction
public function ShowSprite takes framehandle frame, player p returns nothing
if GetLocalPlayer() != p then
return
endif
call BlzFrameSetVisible(FrameSpriteParent, true)
call BlzFrameSetModel(FrameSprite, spriteModel, 0)
call BlzFrameSetSpriteAnimate(FrameSprite, spriteAnimationIndex, 0)
call BlzFrameSetPoint(FrameSprite, FRAMEPOINT_CENTER, frame, FRAMEPOINT_CENTER, 0, 0)
endfunction
function TasItemSetCategory takes integer itemCode, integer category returns nothing
set TasItemCategory[itemCode] = category
endfunction
function TasItemShopAdd takes integer itemCode, integer category returns nothing
if itemCode <= 0 then
return
endif
call TasItemSetCategory(itemCode, category)
set BUY_ABLE_ITEMS_Count = BUY_ABLE_ITEMS_Count + 1
set BUY_ABLE_ITEMS[BUY_ABLE_ITEMS_Count] = itemCode
call TasItemCaclCost(itemCode)
endfunction
function TasItemShopAdd5 takes integer a, integer b, integer c, integer d, integer e returns nothing
call TasItemShopAdd(a, 0)
call TasItemShopAdd(b, 0)
call TasItemShopAdd(c, 0)
call TasItemShopAdd(d, 0)
call TasItemShopAdd(e, 0)
endfunction
function TasItemShopAddHaggleSkill takes integer skill, real goldBase, real lumberBase, real goldAdd, real lumberAdd returns nothing
set HaggleCount = HaggleCount + 1
set HaggleSkill[HaggleCount] = skill
set HaggleGold[HaggleCount] = goldBase
set HaggleGoldAdd[HaggleCount] = goldAdd
set HaggleLumber[HaggleCount] = lumberBase
set HaggleLumberAdd[HaggleCount] = lumberAdd
endfunction
function TasItemShopAddCategory takes string icon, string text returns integer
if CategoryCount >= 31 then
call BJDebugMsg("TasItemShop - To many Categories!! new category " + text +", " + icon)
else
set CategoryCount = CategoryCount + 1
set CategoryIcon[CategoryCount] = icon
set CategoryText[CategoryCount] = text
set CategoryValues[CategoryCount] = GetPower2Value(CategoryCount)
endif
return CategoryValues[CategoryCount]
endfunction
function TasItemShopCreateShop takes integer unitCode, boolean whiteList, real goldFactor, real lumberFactor, code costFunction returns integer
if not Shops.has(unitCode) then
set ShopCount = ShopCount + 1
set Shops[unitCode] = ShopCount
set ShopWhiteList[ShopCount] = whiteList
set ShopCostAction[ShopCount] = CreateTrigger()
if costFunction != null then
call TriggerAddCondition(ShopCostAction[ShopCount], Filter(costFunction))
endif
set ShopsGold[unitCode].real[0] = goldFactor
set ShopsLumber[unitCode].real[0] = lumberFactor
endif
return Shops[unitCode]
endfunction
function TasItemShopSetMode takes integer unitCode, boolean whiteList returns nothing
set ShopWhiteList[Shops[unitCode]] = whiteList
endfunction
function TasItemShopAddShop takes integer unitCode, integer itemCode returns nothing
if itemCode <= 0 then
return
endif
call TasItemShopCreateShop(unitCode, false, 1.0, 1.0, null)
call TasItemCaclCost(itemCode)
set ShopsItems[unitCode].boolean[itemCode] = true
set ShopsItems[unitCode][0] = ShopsItems[unitCode][0] + 1
set ShopsItems[unitCode][ShopsItems[unitCode][0]] = itemCode
endfunction
function TasItemShopAddShop5 takes integer unitCode, integer a, integer b, integer c, integer d, integer e returns nothing
call TasItemShopAddShop(unitCode, a)
call TasItemShopAddShop(unitCode, b)
call TasItemShopAddShop(unitCode, c)
call TasItemShopAddShop(unitCode, d)
call TasItemShopAddShop(unitCode, e)
endfunction
function TasItemShopGoldFactor takes integer unitCode, real factor, integer itemCode returns nothing
call TasItemShopCreateShop(unitCode, false, 1.0, 1.0, null)
set ShopsGold[unitCode].real[itemCode] = factor
endfunction
function TasItemShopLumberFactor takes integer unitCode, real factor, integer itemCode returns nothing
call TasItemShopCreateShop(unitCode, false, 1.0, 1.0, null)
set ShopsLumber[unitCode].real[itemCode] = factor
endfunction
public function ClearQuickLink takes player p returns nothing
call QuickLink[GetPlayerId(p)].flush()
endfunction
public function SetQuickLink takes player p, integer itemCode returns nothing
local integer playerIndex = GetPlayerId(p)
local integer loopA
// request to calc the itemCode costs, this is done in case it was not added to the shop
call TasItemCaclCost(itemCode)
//print("TasItemShopUI.SetQuickLink")
// have that data already?
if QuickLink[playerIndex].boolean[itemCode] then
set loopA = QuickLink[playerIndex][0]
loop
exitwhen loopA <= 0
if QuickLink[playerIndex][loopA] == itemCode then
set QuickLink[playerIndex][loopA] = QuickLink[playerIndex][QuickLink[playerIndex][0]]
set QuickLink[playerIndex][0] = QuickLink[playerIndex][0] - 1
set QuickLink[playerIndex].boolean[itemCode] = false
// reset offset when falling out of Page 2
if QuickLink[playerIndex][0] <= refButtonCountQuickLink then
set CurrentOffSetQuickLink[playerIndex] = 0
endif
exitwhen true
endif
set loopA = loopA - 1
// body
endloop
else
// no, add it
set QuickLink[playerIndex][0] = QuickLink[playerIndex][0] + 1
set QuickLink[playerIndex][QuickLink[playerIndex][0]] = itemCode
set QuickLink[playerIndex].boolean[itemCode] = true
endif
endfunction
public function CanBuyItem takes integer itemCode, integer shopObject, player p returns boolean
local boolean whilteList
if shopObject > 0 then
set whilteList = ShopWhiteList[Shops[shopObject]]
// do not allow this itemCode or do exclude this itemCode => disallow
if (not ShopsItems[shopObject].boolean[itemCode] and whilteList) or (ShopsItems[shopObject].boolean[itemCode] and not whilteList) then
return false
endif
// allow this for this shop?
if ShopsItems[shopObject].boolean[itemCode] and whilteList then
return true
endif
endif
return BuyAbleMarked[GetPlayerId(p)].boolean[itemCode]
endfunction
public function AllMatsProvided takes player p, integer itemCode, integer shopObject returns boolean
local integer loopA = 0
local integer playerIndex = GetPlayerId(p)
local integer v
set MissingCount = 0
call TasItemFusionGetMissingMaterial(p, itemCode, true)
set loopA = TasItemFusion_PlayerMissing[playerIndex][0]
loop
exitwhen loopA <= 0
set v = TasItemFusion_PlayerMissing[playerIndex][loopA]
if not CanBuyItem(v, shopObject, p) then
set MissingCount = MissingCount + 1
set MissingItemCode[MissingCount] = v
endif
set loopA = loopA - 1
endloop
return MissingCount == 0
endfunction
public function updateItemFrame takes integer createContext, integer data, boolean showGold, boolean showLumber returns nothing
local integer lumber
local integer gold
local integer playerIndex = GetPlayerId(GetLocalPlayer())
if createContext != CREATE_CONTEXT_CURRENT then
call BlzFrameSetVisible(BlzGetFrameByName(buttonListHighLightFrameName, createContext), MarkedItemCodes.boolean[data])
endif
//set UpdateCounter = UpdateCounter + 1
//call BlzFrameSetText(UpdateCounterText, I2S(UpdateCounter))
call BlzFrameSetTexture(BlzGetFrameByName("TasButtonIcon", createContext), BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetText(BlzGetFrameByName("TasButtonText", createContext), GetObjectName(data))
call BlzFrameSetTexture(BlzGetFrameByName("TasButtonListTooltipIcon", createContext), BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetText(BlzGetFrameByName("TasButtonListTooltipName", createContext), GetObjectName(data))
call BlzFrameSetText(BlzGetFrameByName("TasButtonListTooltipText", createContext), BlzGetAbilityExtendedTooltip(data, 0))
if StringLength(BlzGetAbilityExtendedTooltip(data, 0)) >= toolTipLimitBig then
call BlzFrameSetSize(BlzGetFrameByName("TasButtonListTooltipText", createContext), toolTipSizeXBig, 0)
else
call BlzFrameSetSize(BlzGetFrameByName("TasButtonListTooltipText", createContext), toolTipSizeX, 0)
endif
if showGold or showLumber then
// has material -> Fusion
if TasItemFusion_BuiltWay[data][0] > 0 then
call TasItemFusionCalc(GetLocalPlayer(), data, true)
set gold = TasItemFusionGold
set lumber = TasItemFusionLumber
else
set gold = TasItemGetCostGold(data)
set lumber = TasItemGetCostLumber(data)
endif
call CostModifier(gold, lumber, data, ShoperMain[playerIndex], CurrentShop[playerIndex], LocalShopObject)
set gold = TempGold
set lumber = TempLumber
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonTextGold", createContext), showGold)
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonIconGold", createContext), showGold)
if showGold then
if GetPlayerState(GetLocalPlayer(), PLAYER_STATE_RESOURCE_GOLD) >= gold then
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", createContext), I2S(gold))
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", createContext), "|cffff2010" + I2S(gold))
endif
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", createContext), "0")
endif
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonTextLumber", createContext), showLumber)
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonIconLumber", createContext), showLumber)
if showLumber then
if GetPlayerState(GetLocalPlayer(), PLAYER_STATE_RESOURCE_LUMBER) >= lumber then
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", createContext), I2S(lumber))
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", createContext), "|cffff2010" + I2S(lumber))
endif
else
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", createContext), "0")
endif
else
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonTextGold", createContext), false)
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonIconGold", createContext), false)
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonTextLumber", createContext), false)
call BlzFrameSetVisible(BlzGetFrameByName("TasButtonIconLumber", createContext), false)
endif
endfunction
public function updateItemFrameAction takes nothing returns nothing
//TasButtonListFrame
//TasButtonListData
//TasButtonListIndex
local integer buttonIndex = S2I(BlzFrameGetText(TasButtonListFrame))
local integer context = TasButtonListCreateContext[TasButtonListIndex] + buttonIndex
//call BJDebugMsg("updateItemFrameAction" + " context: " + I2S(context) + " buttonIndex: " + I2S(buttonIndex))
call updateItemFrame(context, TasButtonListData, buttonListShowGold, buttonListShowLumber)
endfunction
public function updateUndoButton takes integer data, string actionName returns nothing
call BlzFrameSetTexture(FrameUndoButtonIcon, BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetTexture(FrameUndoButtonIconPushed, BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetText(FrameUndoText, GetLocalizedString(textUndo) + actionName + "\n" + GetObjectName(data))
endfunction
public function CreateUndo takes player p, integer itemCode, integer gold, integer lumber, string actionName returns integer
local integer playerIndex = GetPlayerId(p)
local integer index
set UndoPlayerCount[playerIndex] = UndoPlayerCount[playerIndex] + 1
set index = UndoPlayerCount[playerIndex] + playerIndex*UndoPlayerSize
if UndoItems[index] == null then
set UndoItems[index] = Table.create()
endif
if UndoResults[index] == null then
set UndoResults[index] = Table.create()
endif
set UndoActionName[index] = actionName
set UndoResultCode[index] = itemCode
set UndoGold[index] = gold
set UndoLumber[index] = lumber
if GetLocalPlayer() == p then
call BlzFrameSetVisible(FrameUndoBox, true)
call updateUndoButton(itemCode, actionName)
endif
return index
endfunction
public function updateRefButton takes integer buttonIndex, integer data, unit u returns nothing
// call BJDebugMsg(I2S(buttonIndex)+" "+ GetObjectName(data) + " " + GetUnitName(u))
if data > 0 then
call BlzFrameSetVisible(RefButton[buttonIndex], true)
call BlzFrameSetTexture(RefButtonIcon[buttonIndex], BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetTexture(RefButtonIconPushed[buttonIndex], BlzGetAbilityIcon(data), 0, false)
call BlzFrameSetTexture(RefButtonToolTipIcon[buttonIndex], BlzGetAbilityIcon(data), 0, false)
if RefButtonToolTipName[buttonIndex] != RefButtonToolTipText[buttonIndex] then
call BlzFrameSetText(RefButtonToolTipName[buttonIndex], GetObjectName(data))
call BlzFrameSetText(RefButtonToolTipText[buttonIndex], BlzGetAbilityExtendedTooltip(data, 0))
if StringLength(BlzGetAbilityExtendedTooltip(data, 0)) >= toolTipLimitBig then
call BlzFrameSetSize(RefButtonToolTipText[buttonIndex], toolTipSizeXBig, 0)
else
call BlzFrameSetSize(RefButtonToolTipText[buttonIndex], toolTipSizeX, 0)
endif
else
call BlzFrameSetText(RefButtonToolTipText[buttonIndex], GetObjectName(data))
endif
if u != null and IsUnitType(u, UNIT_TYPE_HERO) then
call BlzFrameSetText(RefButtonToolTipText[buttonIndex], BlzFrameGetText(RefButtonToolTipText[buttonIndex]) +"\n"+ GetHeroProperName(u))
endif
else
call BlzFrameSetVisible(RefButton[buttonIndex], false)
endif
endfunction
public function updateRefButtonsInventory takes player p returns integer
local integer playerIndex = GetPlayerId(p)
local integer count = TasItemFusion_PlayerItems[playerIndex][0]
local boolean valid
local integer offSet = CurrentOffSetInventory[playerIndex]
local integer validCounter = 0
local integer loopA = 1
local integer buttonIndex
local item i
call BlzFrameSetVisible(FrameInventoryBox, true)
call BlzFrameSetText(FrameInventoryPageText, I2S(offSet/refButtonCountInv + 1))
call BlzFrameSetVisible(FrameInventoryPage, not inventoryShowMainOnly and count > refButtonCountInv)
loop
set buttonIndex = loopA + RefButtonInventoryStart
if not inventoryShowMainOnly then
set valid = (loopA + offSet <= count)
call BlzFrameSetVisible(RefButton[buttonIndex], valid)
if valid then
set validCounter = validCounter + 1
call updateRefButton(buttonIndex, GetItemTypeId(TasItemFusion_PlayerItems[playerIndex].item[loopA + offSet]), null)
call BlzFrameSetVisible(RefButtonOverlay[buttonIndex], TasItemFusion_PlayerItems[playerIndex].item[loopA + offSet] == SelectedItem[playerIndex])
endif
else
set i = UnitItemInSlot(ShoperMain[playerIndex], loopA - 1)
call updateRefButton(buttonIndex, GetItemTypeId(i), null)
call BlzFrameSetVisible(RefButtonOverlay[buttonIndex], i == SelectedItem[playerIndex])
if i != null then
set validCounter = validCounter + 1
endif
endif
set loopA = loopA + 1
exitwhen loopA > refButtonCountInv
// body
endloop
set i = null
return validCounter
endfunction
public function updateRefButtonsMaterial takes player p, integer result returns integer
local integer playerIndex = GetPlayerId(p)
local integer count = TasItemFusion_BuiltWay[result][0]
local boolean valid
local integer offSet = CurrentOffSetMaterial[playerIndex]
local integer validCounter = 0
local integer loopA = 1
local integer buttonIndex
call BlzFrameSetVisible(FrameMaterialBox, true)
call BlzFrameSetText(FrameMaterialPageText, I2S(offSet/refButtonCountMats + 1))
call BlzFrameSetVisible(FrameMaterialPage, count > refButtonCountMats)
loop
set buttonIndex = loopA + RefButtonMaterialStart
set valid = (loopA + offSet <= count)
call BlzFrameSetVisible(RefButton[buttonIndex], valid)
if valid then
set validCounter = validCounter + 1
call updateRefButton(buttonIndex, TasItemFusion_BuiltWay[result][loopA + offSet], null)
endif
set loopA = loopA + 1
exitwhen loopA > refButtonCountMats
// body
endloop
return validCounter
endfunction
public function updateRefButtonsUpgrades takes player p, integer result returns integer
local integer playerIndex = GetPlayerId(p)
local integer count = TasItemFusion_UsedIn[result][0]
local boolean valid
local integer offSet = CurrentOffSetUpgrade[playerIndex]
local integer validCounter = 0
local integer loopA = 1
local integer buttonIndex
call BlzFrameSetVisible(FrameUpgradeBox, true)
call BlzFrameSetText(FrameUpgradePageText, I2S(offSet/refButtonCountUp + 1))
call BlzFrameSetVisible(FrameUpgradePage, count > refButtonCountUp)
loop
set buttonIndex = loopA + RefButtonUpgradeStart
set valid = (loopA + offSet <= count)
call BlzFrameSetVisible(RefButton[buttonIndex], valid)
if valid then
set validCounter = validCounter + 1
call updateRefButton(buttonIndex, TasItemFusion_UsedIn[result][loopA + offSet], null)
call BlzFrameSetVisible(RefButtonOverlay2[buttonIndex], BlzFrameIsVisible(RefButton[buttonIndex]) and not CanBuyItem(TasItemFusion_UsedIn[result][loopA + offSet], LocalShopObject, p))
endif
set loopA = loopA + 1
exitwhen loopA > refButtonCountUp
// body
endloop
return validCounter
endfunction
public function updateRefButtonsQuickLink takes player p returns integer
local integer playerIndex = GetPlayerId(p)
local integer count = QuickLink[playerIndex][0]
local boolean valid
local integer offSet = CurrentOffSetQuickLink[playerIndex]
local integer validCounter = 0
local integer loopA = 1
local integer buttonIndex
call BlzFrameSetVisible(FrameQuickLinkBox, true)
call BlzFrameSetText(FrameQuickLinkPageText, I2S(offSet/refButtonCountQuickLink + 1))
call BlzFrameSetVisible(FrameQuickLinkPage, count > refButtonCountQuickLink)
loop
set buttonIndex = loopA + RefButtonQuickLinkStart
set valid = (loopA + offSet <= count)
call BlzFrameSetVisible(RefButton[buttonIndex], valid)
if valid then
set validCounter = validCounter + 1
call updateRefButton(buttonIndex, QuickLink[playerIndex][loopA + offSet], null)
call BlzFrameSetVisible(RefButtonOverlay2[buttonIndex], BlzFrameIsVisible(RefButton[buttonIndex]) and not CanBuyItem(QuickLink[playerIndex][loopA + offSet], LocalShopObject, p))
endif
set loopA = loopA + 1
exitwhen loopA > refButtonCountQuickLink
endloop
return validCounter
endfunction
public function updateRefButtonsUser takes player p returns integer
local integer playerIndex = GetPlayerId(p)
local integer count = BlzGroupGetSize(Shoper[playerIndex])
local boolean valid
local integer offSet = CurrentOffSetUser[playerIndex]
local unit u
local integer validCounter = 0
local integer loopA = 1
local integer buttonIndex
call BlzFrameSetVisible(FrameUserBox, true)
call BlzFrameSetText(FrameUserPageText, I2S(offSet/refButtonCountUser + 1))
call BlzFrameSetVisible(FrameUserPage, count > refButtonCountUser)
loop
set buttonIndex = loopA + RefButtonUserStart
set valid = (loopA + offSet <= count)
call BlzFrameSetVisible(RefButton[buttonIndex], valid)
if valid then
set validCounter = validCounter + 1
set u = BlzGroupUnitAt(Shoper[playerIndex], loopA + offSet - 1)
call updateRefButton(buttonIndex, GetUnitTypeId(u), u)
endif
set loopA = loopA + 1
exitwhen loopA > refButtonCountUser
// body
endloop
set u = null
return validCounter
endfunction
public function updateHaveMats takes player p, integer data returns nothing
local integer playerIndex = GetPlayerId(p)
local integer mat
local integer offset = CurrentOffSetMaterial[playerIndex]
local integer loopA = 1
local integer buttonIndex
call TempTable.flush()
//call TasItemFusionGetUseableMaterial(p, data, true, true)
loop
set buttonIndex = loopA + RefButtonMaterialStart
if BlzFrameIsVisible(RefButton[buttonIndex]) then
set mat = TasItemFusion_BuiltWay[data][loopA + offset]
set TempTable[mat] = TempTable[mat] + 1
call BlzFrameSetVisible(RefButtonOverlay[buttonIndex], TempTable[mat] <= TasItemFusion_PlayerItems[playerIndex][mat])
call BlzFrameSetVisible(RefButtonOverlay2[buttonIndex], not BlzFrameIsVisible(RefButtonOverlay[buttonIndex]) and not CanBuyItem(mat, LocalShopObject, p))
endif
set loopA = loopA + 1
exitwhen loopA > refButtonCountMats
endloop
endfunction
public function updateOverLayMainSelected takes player p returns nothing
local integer playerIndex = GetPlayerId(p)
local integer loopA = 1
local integer offset = CurrentOffSetUser[playerIndex]
local integer buttonIndex
loop
exitwhen loopA > refButtonCountUser
set buttonIndex = loopA + RefButtonUserStart
call BlzFrameSetVisible(RefButtonOverlay[buttonIndex], BlzFrameIsVisible(RefButton[buttonIndex]) and ShoperMain[playerIndex] == BlzGroupUnitAt(Shoper[playerIndex], loopA - 1 + offset))
set loopA = loopA + 1
endloop
endfunction
public function GiveItem takes unit u, item i, integer undo returns nothing
local integer oldCharges = GetItemCharges(i)
local integer itemCode = GetItemTypeId(i)
local integer loopA = 0
local item i2
//call BJDebugMsg("GiveItem: "+ GetUnitName(u) + " give " + GetItemName(i))
call UnitAddItem(u, i)
// when there are charges and undo
if oldCharges > 0 and undo > 0 then
// when the item's charges changed then it probably was stacked
if GetItemCharges(i) != oldCharges then
loop
set i2 = UnitItemInSlot(u, loopA)
if GetItemTypeId(i2) == itemCode and i2 != i then
set UndoStackGainer[undo] = i2
set UndoStackGained[undo] = oldCharges - GetItemCharges(i)
endif
set loopA = loopA + 1
exitwhen loopA >= bj_MAX_INVENTORY
endloop
endif
endif
set i2 = null
endfunction
public function GiveItemGroup takes player p, item i, integer undoIndex returns nothing
local boolean found
local unit u
local integer playerIndex = GetPlayerId(p)
local integer loopA
call SetItemPlayer(i, p, true)
call GiveItem(ShoperMain[playerIndex], i, undoIndex)
// other units can get the item when the mainShopper can not hold it?
// Check if item still exists and mainshopper does not have it.
if canProviderGetItem and GetHandleId(i) > 0 and not UnitHasItem(ShoperMain[playerIndex], i) then
// loop all mat provider try to give it to each, when that succeds finished.
set found = false
set loopA = BlzGroupGetSize(Shoper[playerIndex]) - 1
loop
exitwhen loopA <= 0
set u = BlzGroupUnitAt(Shoper[playerIndex], loopA)
call GiveItem(u, i, undoIndex)
if GetHandleId(i) == 0 or UnitHasItem(u, i) then
if canUndo then
set UndoResults[undoIndex][0] = UndoResults[undoIndex][0] + 1
set UndoResults[undoIndex].item[UndoResults[undoIndex][0]] = i
set UndoResults[undoIndex].unit[-UndoResults[undoIndex][0]] = u
endif
set found = true
exitwhen true
endif
set loopA = loopA - 1
endloop
if not found and canUndo then
set UndoResults[undoIndex][0] = UndoResults[undoIndex][0] + 1
set UndoResults[undoIndex].item[UndoResults[undoIndex][0]] = i
set UndoResults[undoIndex].unit[-UndoResults[undoIndex][0]] = u
endif
else
if canUndo then
set UndoResults[undoIndex][0] = UndoResults[undoIndex][0] + 1
set UndoResults[undoIndex].item[UndoResults[undoIndex][0]] = i
set UndoResults[undoIndex].unit[-UndoResults[undoIndex][0]] = ShoperMain[playerIndex]
endif
endif
set u = null
endfunction
public function setSelected takes player p, integer data returns nothing
local integer playerIndex = GetPlayerId(p)
local integer oldData = Selected[playerIndex]
local integer loopA
local integer buttonIndex
set Selected[playerIndex] = data
// Reset RefPage only when a new data is selected
if oldData != data then
//call BJDebugMsg(GetObjectName(oldData) + " -> " + GetObjectName(data))
set CurrentOffSetUpgrade[playerIndex] = 0
set CurrentOffSetMaterial[playerIndex] = 0
set SelectedItem[playerIndex] = null
if p == GetLocalPlayer() then
if canDefuse then
call BlzFrameSetEnable(FrameDefuseButton, false)
endif
if canSellItems then
call BlzFrameSetEnable(FrameSellButton, false)
endif
set MarkedItemCodes.boolean[oldData] = false
set MarkedItemCodes.boolean[data] = true
endif
endif
if p == GetLocalPlayer() then
if refButtonCountUp > 0 then
if TasItemFusion_UsedIn[data][0] > 0 then
call updateRefButtonsUpgrades(p, data)
else
call BlzFrameSetVisible(FrameUpgradeBox, false)
endif
endif
if refButtonCountMats > 0 then
if TasItemFusion_BuiltWay[data][0] > 0 then
call updateRefButtonsMaterial(p, data)
call updateHaveMats(p, data)
else
call BlzFrameSetVisible(FrameMaterialBox, false)
endif
endif
if refButtonCountInv > 0 then
if TasItemFusion_PlayerItems[playerIndex][0] > 0 then
call updateRefButtonsInventory(p)
else
call BlzFrameSetVisible(FrameInventoryBox, false)
endif
endif
if refButtonCountQuickLink > 0 then
call updateRefButtonsQuickLink(p)
endif
if refButtonCountUser > 0 then
call updateRefButtonsUser(p)
call updateOverLayMainSelected(p)
endif
call updateItemFrame(CREATE_CONTEXT_CURRENT, data, buyButtonShowGold, buyButtonShowLumber)
if (buyButtonShowGold or buyButtonShowLumber) and not flexibleShop and (not CanBuyItem(data, LocalShopObject, p) or (TasItemFusion_BuiltWay[data][0] > 0 and not AllMatsProvided(p, data, LocalShopObject))) then
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextGold", CREATE_CONTEXT_CURRENT), GetLocalizedString(textUnBuyable))
call BlzFrameSetText(BlzGetFrameByName("TasButtonTextLumber", CREATE_CONTEXT_CURRENT), GetLocalizedString(textUnBuyable))
endif
endif
endfunction
public function setSelectedItem takes player p, item i returns nothing
local integer playerIndex = GetPlayerId(p)
local integer itemCode = GetItemTypeId(i)
set SelectedItem[playerIndex] = i
if i != null then
if GetLocalPlayer() == p then
if canDefuse then
call BlzFrameSetText(FrameDefuseText, GetLocalizedString(textDefuse)+"\n"+BlzGetAbilityTooltip(itemCode, 0))
call BlzFrameSetEnable(FrameDefuseButton, TasItemFusion_BuiltWay[itemCode][0] > 0)
endif
if canSellItems then
call GetItemSellCosts(ShoperMain[playerIndex], CurrentShop[playerIndex], i)
call BlzFrameSetText(FrameSellText, GetLocalizedString(textSell)+ " " + GetItemName(i) + "\n"+GetLocalizedString("GOLD")+" "+ I2S(TempGold) + "\n"+GetLocalizedString("LUMBER")+" "+ I2S(TempLumber))
call BlzFrameSetEnable(FrameSellButton, true)
endif
endif
endif
endfunction
function TasItemShopUIShow takes player p, unit shop, group shopperGroup, unit mainShoper returns nothing
local boolean flag = (shop != null)
local integer playerIndex = GetPlayerId(p)
local boolean isNewShopType = GetUnitTypeId(CurrentShop[playerIndex]) != GetUnitTypeId(shop)
local integer oldSize = TasItemFusion_PlayerItems[playerIndex][0]
local integer loopA
local integer loopB
local integer undoPlayerIndex
local integer index
local integer shopObject
if p == GetLocalPlayer() then
call BlzFrameSetVisible(FrameParentSuper, flag)
if flag then
call BlzFrameSetVisible(BlzFrameGetParent(FrameParentSuper), true)
endif
endif
if flag then
set CurrentShop[playerIndex] = shop
if mainShoper != null then
set ShoperMain[playerIndex] = mainShoper
elseif shopperGroup != null then
set ShoperMain[playerIndex] = FirstOfGroup(shopperGroup)
endif
if shopperGroup != null then
call GroupClear(Shoper[playerIndex])
// when a group was given
call BlzGroupAddGroupFast(shopperGroup, Shoper[playerIndex])
endif
call GroupAddUnit(Shoper[playerIndex], mainShoper)
call TasItemFusionGetUseableItems(p, Shoper[playerIndex], not sharedItems)
if oldSize != TasItemFusion_PlayerItems[playerIndex][0] then
set CurrentOffSetInventory[playerIndex] = 0
endif
if isNewShopType then
//call BJDebugMsg("isNewShopType")
// has to unmark buyAble
set shopObject = GetUnitTypeId(shop)
call BuyAbleMarked[playerIndex].flush()
call TasButtonListClearDataEx(ButtonListIndex, playerIndex)
// has custom Shop Data?
if Shops.has(shopObject) then
// WhiteListMode?
if ShopWhiteList[Shops[shopObject]] then
set loopA = 1
set loopB = ShopsItems[shopObject][0]
loop
exitwhen loopA > loopB
call TasButtonListAddDataEx(ButtonListIndex, ShopsItems[shopObject][loopA], playerIndex)
set BuyAbleMarked[playerIndex].boolean[ShopsItems[shopObject][loopA]] = true
set loopA = loopA + 1
endloop
else
// BlackListMode
set loopA = 1
loop
exitwhen loopA > BUY_ABLE_ITEMS_Count
if not ShopsItems[shopObject].boolean[BUY_ABLE_ITEMS[loopA]] then
call TasButtonListAddDataEx(ButtonListIndex, BUY_ABLE_ITEMS[loopA], playerIndex)
set BuyAbleMarked[playerIndex].boolean[BUY_ABLE_ITEMS[loopA]] = true
endif
set loopA = loopA + 1
endloop
endif
else
// none custom Shop, add all data.
set loopA = 1
loop
exitwhen loopA > BUY_ABLE_ITEMS_Count
call TasButtonListAddDataEx(ButtonListIndex, BUY_ABLE_ITEMS[loopA], playerIndex)
set BuyAbleMarked[playerIndex].boolean[BUY_ABLE_ITEMS[loopA]] = true
set loopA = loopA + 1
endloop
endif
endif
if GetLocalPlayer() == p then
if IsUnitType(ShoperMain[playerIndex], UNIT_TYPE_HERO) then
call BlzFrameSetText(FrameTitelText, GetUnitName(shop) + " - "+ GetHeroProperName(ShoperMain[playerIndex]))
else
call BlzFrameSetText(FrameTitelText, GetUnitName(shop) + " - "+ GetUnitName(ShoperMain[playerIndex]))
endif
set LocalShopObject = GetUnitTypeId(shop)
if isNewShopType then
call TasButtonListSearch(ButtonListIndex, null)
endif
endif
call UpdateTasButtonList(ButtonListIndex)
call setSelected(p, Selected[playerIndex])
call setSelectedItem(p, SelectedItem[playerIndex])
else
set CurrentShop[playerIndex] = null
if canUndo then
// loop the undo of that player from last to first
set loopA = 1
//call BJDebugMsg("LoopA:"+I2S(loopA))
set undoPlayerIndex = playerIndex*UndoPlayerSize
loop
exitwhen loopA > UndoPlayerCount[playerIndex]
set index = undoPlayerIndex + loopA
//call BJDebugMsg(UndoActionName[index])
set loopB = UndoItems[index][0]
loop
exitwhen loopB <= 0
// call BJDebugMsg("LoopB:"+I2S(loopB))
// call BJDebugMsg("Remove:"+GetItemName(UndoItems[index].item[loopB]))
call SetItemVisible(UndoItems[index].item[loopB], true)
call RemoveItem(UndoItems[index].item[loopB])
set loopB = loopB - 1
endloop
set UndoStackGainer[index] = null
call UndoResults[index].flush()
call UndoItems[index].flush()
set loopA = loopA + 1
endloop
if GetLocalPlayer() == p then
call BlzFrameSetVisible(FrameUndoBox, false)
endif
set UndoPlayerCount[playerIndex] = 0
endif
endif
endfunction
public function BuyItem takes player p, integer itemCode returns nothing
local integer playerIndex = GetPlayerId(p)
local integer gold
local integer lumber
local integer shopObject = GetUnitTypeId(CurrentShop[playerIndex])
local integer loopA
local integer undoIndex
local item i
local unit u
local item newItem
local boolean isFusion = TasItemFusion_BuiltWay[itemCode][0] > 0
//call BJDebugMsg(GetPlayerName(p) + " Wana Buy " + GetObjectName(itemCode) + " with " + GetUnitName(ShoperMain[playerIndex]))
if BlzGroupGetSize(Shoper[playerIndex]) == 0 then
if GetLocalPlayer() == p then
call BJDebugMsg(GetLocalizedString(textNoValidShopper))
endif
return
endif
// can not buy this?
if not flexibleShop and not CanBuyItem(itemCode, shopObject, p) then
if GetLocalPlayer() == p then
call BJDebugMsg(GetObjectName(itemCode) + " " + GetLocalizedString(textCanNotBuySufix))
endif
return
endif
// has material -> Fusion
if isFusion then
call TasItemFusionCalc(p, itemCode, false)
set gold = TasItemFusionGold
set lumber = TasItemFusionLumber
else
set gold = TasItemGetCostGold(itemCode)
set lumber = TasItemGetCostLumber(itemCode)
endif
call CostModifier(gold, lumber, itemCode, ShoperMain[playerIndex], CurrentShop[playerIndex], shopObject)
set gold = TempGold
set lumber = TempLumber
// only items buyable in the shop can be replaced by Gold? Also ignore non fusion items.
if not flexibleShop and isFusion then
if not AllMatsProvided(p, itemCode, shopObject) then
if GetLocalPlayer() == p then
call BJDebugMsg(GetLocalizedString(textCanNotBuyPrefix) + " " + GetObjectName(itemCode))
set loopA = MissingCount
loop
exitwhen loopA <= 0
call BJDebugMsg(GetObjectName(MissingItemCode[loopA]) + " " + GetLocalizedString(textCanNotBuySufix))
set loopA = loopA - 1
endloop
endif
return
endif
endif
if GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) >= gold then
if GetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER) >= lumber then
//call BJDebugMsg("Accept Request")
if canUndo then
set undoIndex = CreateUndo(p, itemCode, gold, lumber, " Buy")
if isFusion and TasItemFusion_PlayerMaterial[playerIndex][0] > 0 then
set loopA = TasItemFusion_PlayerMaterial[playerIndex][0]
set UndoItems[undoIndex][0] = loopA
loop
set i = TasItemFusion_PlayerMaterial[playerIndex].item[loopA]
set u = ItemHolder_get(i)
set UndoItems[undoIndex].unit[-loopA] = u
set UndoItems[undoIndex].item[loopA] = i
//call BJDebugMsg("Hide Item")
call UnitRemoveItem(u, i)
call SetItemVisible(i, false)
set loopA = loopA - 1
exitwhen loopA <= 0
endloop
endif
else
if isFusion and TasItemFusion_PlayerMaterial[playerIndex][0] > 0 then
set loopA = TasItemFusion_PlayerMaterial[playerIndex][0]
loop
call RemoveItem(TasItemFusion_PlayerMaterial[playerIndex].item[loopA])
set loopA = loopA - 1
exitwhen loopA <= 0
endloop
endif
endif
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_GOLD, -gold)
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_LUMBER, -lumber)
set newItem = CreateItem(itemCode, GetUnitX(ShoperMain[playerIndex]), GetUnitY(ShoperMain[playerIndex]))
//call BJDebugMsg("NewItem: "+ I2S(GetHandleId(newItem)))
call GiveItemGroup(p, newItem, undoIndex)
//CreateItem(itemCode, GetPlayerStartLocationX(player), GetPlayerStartLocationY(player))
call TasItemShopUIShow(p, CurrentShop[playerIndex], null, null)
elseif not GetSoundIsPlaying(SoundNoLumber[GetHandleId(GetPlayerRace(p))]) then
call StartSoundForPlayerBJ(p, SoundNoLumber[GetHandleId(GetPlayerRace(p))])
endif
elseif not GetSoundIsPlaying(SoundNoGold[GetHandleId(GetPlayerRace(p))]) then
call StartSoundForPlayerBJ(p, SoundNoGold[GetHandleId(GetPlayerRace(p))])
endif
set newItem = null
set i = null
set u = null
// call BJDebugMsg("BuyItem Done")
endfunction
public function SellItem takes player p, item i returns nothing
local integer playerIndex = GetPlayerId(p)
local integer itemCode
local integer gold
local integer lumber
local integer undoIndex
local integer loopA
local boolean wasSelectedItem = (i == SelectedItem[playerIndex])
if i == null then
return
endif
set itemCode = GetItemTypeId(i)
call GetItemSellCosts(ShoperMain[playerIndex], CurrentShop[playerIndex], i)
set gold = TempGold
set lumber = TempLumber
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_GOLD, gold)
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_LUMBER, lumber)
if canUndo then
set undoIndex = CreateUndo(p, itemCode, -gold, -lumber, GetLocalizedString(textSell))
set UndoItems[undoIndex][0] = 1
set UndoItems[undoIndex].item[1] = i
set UndoItems[undoIndex].unit[-1] = ItemHolder_get(i)
call UnitRemoveItem(ItemHolder_get(i), i)
call SetItemVisible(i, false)
if GetLocalPlayer() == p then
call BlzFrameSetVisible(FrameUndoBox, true)
call updateUndoButton(UndoResultCode[undoIndex], GetLocalizedString(textSell))
endif
else
call RemoveItem(i)
endif
if wasSelectedItem then
if GetLocalPlayer() == p then
call BlzFrameSetEnable(FrameSellButton, false)
endif
set SelectedItem[playerIndex] = null
endif
endfunction
private function ButtonListFunction_Search takes nothing returns boolean
//TasButtonListText
//TasButtonListData
//TasButtonListIndex
return FindIndex(StringCase(GetObjectName(TasButtonListData),false), StringCase(TasButtonListText, false)) >= 0
endfunction
private function ButtonListFunction_Filter takes nothing returns boolean
//TasButtonListText
//TasButtonListData
//TasButtonListIndex
//TasButtonListIsSearching
local integer selected = SelectedCategory[GetPlayerId(GetLocalPlayer())]
if ToggleIconButtonGetValue(CategoryModButtonIndex, GetLocalPlayer()) == 0 then
return selected == 0 or BlzBitAnd(TasItemCategory[TasButtonListData], selected) >= selected
else
return selected == 0 or BlzBitAnd(TasItemCategory[TasButtonListData], selected) > 0
endif
endfunction
private function ButtonListFunction_LeftClick takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local real time
if p == GetLocalPlayer() then
set time = TimerGetElapsed(Timer)
if Selected[playerIndex] == TasButtonListData and time - DoubleClickStamp <= doubleClickTimeOut then
// finish the timer, so the player has to do 2 clicks again to trigger a DoubleClick
set DoubleClickStamp = 0
call BlzFrameClick(BlzGetFrameByName("TasButton", CREATE_CONTEXT_CURRENT))
else
set DoubleClickStamp = time
endif
endif
if QuickLinkKeyActive[playerIndex] then
call SetQuickLink(p, TasButtonListData)
endif
call setSelected(p, TasButtonListData)
endfunction
private function ButtonListFunction_RightClick takes nothing returns nothing
call BuyItem(GetTriggerPlayer(), TasButtonListData)
endfunction
private function ButtonListFunction_AsyncRightClick takes nothing returns nothing
call ShowSprite(TasButtonListFrame, GetTriggerPlayer())
endfunction
private function ButtonListFunction_AsyncLeftClick takes nothing returns nothing
endfunction
private function ButtonListFunction_CategoryAction takes nothing returns nothing
set SelectedCategory[GetPlayerId(ToggleIconButton_Player)] = ToggleIconButtonGroup_Value
if GetLocalPlayer() == ToggleIconButton_Player then
call TasButtonListSearch(TasButtonListIndex, "")
endif
endfunction
public function AddClearFocus takes framehandle frame returns nothing
call BlzTriggerRegisterFrameEvent(ButtonTriggerClearFocus, frame, FRAMEEVENT_CONTROL_CLICK)
endfunction
public function CreateRefButton takes framehandle parent, trigger t, boolean advancedTooltip returns integer
local framehandle frame
set RefButtonCount = RefButtonCount + 1
set frame = BlzCreateFrame("TasItemShopRefButton", parent, 0, RefButtonCount)
set RefButton[RefButtonCount] = frame
set RefButtonIcon[RefButtonCount] = BlzGetFrameByName("TasItemShopRefButtonBackdrop", RefButtonCount)
set RefButtonIconPushed[RefButtonCount] = BlzGetFrameByName("TasItemShopRefButtonBackdropPushed", RefButtonCount)
set RefButtonOverlay[RefButtonCount] = BlzGetFrameByName("TasItemShopRefButtonBackdropBackdrop", RefButtonCount)
set RefButtonOverlay2[RefButtonCount] = BlzGetFrameByName("TasItemShopRefButtonBackdropBackdrop2", RefButtonCount)
call BlzFrameSetSize(frame, refButtonSize, refButtonSize)
call BlzFrameSetVisible(RefButtonOverlay[RefButtonCount], false)
call BlzFrameSetVisible(RefButtonOverlay2[RefButtonCount], false)
if advancedTooltip then
call CreateTasButtonTooltip(frame, FrameParentSuper, 0)
set RefButtonToolTip[RefButtonCount] = BlzGetFrameByName("TasButtonListTooltipBox" ,0)
set RefButtonToolTipName[RefButtonCount] = BlzGetFrameByName("TasButtonListTooltipName" ,0)
set RefButtonToolTipIcon[RefButtonCount] = BlzGetFrameByName("TasButtonListTooltipIcon" ,0)
set RefButtonToolTipText[RefButtonCount] = BlzGetFrameByName("TasButtonListTooltipText" ,0)
call BlzFrameClearAllPoints(RefButtonToolTipText[RefButtonCount])
if toolTipPosPointParent != null then
call BlzFrameSetPoint(RefButtonToolTipText[RefButtonCount], toolTipPosPoint, frame, toolTipPosPointParent, toolTipPosX, toolTipPosY)
else
call BlzFrameSetAbsPoint(RefButtonToolTipText[RefButtonCount], toolTipPosPoint, toolTipPosX, toolTipPosY)
endif
else
set RefButtonToolTipName[RefButtonCount] = CreateSimpleTooltip(frame, "User")
set RefButtonToolTipText[RefButtonCount] = RefButtonToolTipName[RefButtonCount]
set RefButtonToolTip[RefButtonCount] = BlzGetFrameByName("EscMenuControlBackdropTemplate" ,0) // this has to match the used box for tooltips from Tooltip buttons
endif
call BlzTriggerRegisterFrameEvent(t, frame, FRAMEEVENT_CONTROL_CLICK)
call BlzTriggerRegisterFrameEvent(t, frame, FRAMEEVENT_MOUSE_UP)
call AddClearFocus(frame)
set frame = null
return RefButtonCount
endfunction
public function CreateRefButtons takes integer amount, framehandle parent, framehandle textFrame, trigger t, boolean advancedTooltip returns integer
local integer loopA = 1
loop
exitwhen loopA > amount
call CreateRefButton(parent, t, advancedTooltip)
if loopA == 1 then
call BlzFrameSetPoint(RefButton[RefButtonCount], FRAMEPOINT_TOPLEFT, textFrame, FRAMEPOINT_BOTTOMLEFT, 0.0, -0.003)
//elseif index == 5 then
// BlzFrameSetPoint(frame, FRAMEPOINT_BOTTOMLEFT, frames[index - 4].Button, FRAMEPOINT_TOPLEFT, 0, 0.003)
else
call BlzFrameSetPoint(RefButton[RefButtonCount], FRAMEPOINT_BOTTOMLEFT, RefButton[RefButtonCount - 1], FRAMEPOINT_BOTTOMRIGHT, refButtonGap, 0)
endif
call BlzFrameSetText(RefButton[RefButtonCount], I2S(loopA))
set loopA = loopA + 1
endloop
return RefButtonCount
endfunction
public function CreateRefPage takes framehandle parent, framehandle textFrame, trigger t, integer pageSize returns nothing
local framehandle array frames
set frames[1] = BlzCreateFrameByType("FRAME", "TasItemShopUIPageControl", parent, "", 0)
set frames[2] = BlzCreateFrame("TasItemShopCatButton", frames[1], 0, 0)
set frames[3] = BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0)
set frames[4] = BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0)
set frames[5] = BlzCreateFrame("TasItemShopCatButton", frames[1], 0, 1)
set frames[6] = BlzGetFrameByName("TasItemShopCatButtonBackdrop", 1)
set frames[7] = BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 1)
set frames[8] = BlzCreateFrame("TasButtonTextTemplate", frames[1], 0, 0)
call BlzFrameSetText(frames[8], "00")
call BlzFrameSetSize(frames[2], refButtonPageSize, refButtonPageSize)
call BlzFrameSetSize(frames[5], refButtonPageSize, refButtonPageSize)
call BlzTriggerRegisterFrameEvent(t, frames[2], FRAMEEVENT_CONTROL_CLICK)
call AddClearFocus(frames[2])
call AddClearFocus(frames[5])
call BlzTriggerRegisterFrameEvent(t, frames[2], FRAMEEVENT_MOUSE_UP)
call BlzTriggerRegisterFrameEvent(t, frames[5], FRAMEEVENT_CONTROL_CLICK)
call BlzTriggerRegisterFrameEvent(t, frames[5], FRAMEEVENT_MOUSE_UP)
call BlzFrameSetTexture(frames[3], refButtonPageUp, 0, false)
call BlzFrameSetTexture(frames[4], refButtonPageUp, 0, false)
call BlzFrameSetTexture(frames[6], refButtonPageDown, 0, false)
call BlzFrameSetTexture(frames[7], refButtonPageDown, 0, false)
//call BlzFrameSetPoint(frames[2], FRAMEPOINT_TOPLEFT, textFrame, FRAMEPOINT_TOPRIGHT, 0.003, 0)
//call BlzFrameSetPoint(frames[8], FRAMEPOINT_TOPLEFT, frames[2], FRAMEPOINT_TOPRIGHT, 0.003, 0)
//call BlzFrameSetPoint(frames[5], FRAMEPOINT_TOPLEFT, frames[8], FRAMEPOINT_TOPRIGHT, 0.003, 0)
call BlzFrameSetPoint(frames[2], FRAMEPOINT_TOPRIGHT, frames[8], FRAMEPOINT_TOPLEFT, -0.003, 0)
call BlzFrameSetPoint(frames[8], FRAMEPOINT_TOPRIGHT, frames[5], FRAMEPOINT_TOPLEFT, -0.003, 0)
call BlzFrameSetPoint(frames[5], FRAMEPOINT_TOPRIGHT, parent, FRAMEPOINT_TOPRIGHT, -boxFrameBorderGap, -boxFrameBorderGap)
//call BlzFrameSetPoint(frames[2], FRAMEPOINT_TOPLEFT, textFrame, FRAMEPOINT_BOTTOMLEFT, 0, -0.003)
//call BlzFrameSetPoint(frames[8], FRAMEPOINT_TOPLEFT, textFrame, FRAMEPOINT_TOPRIGHT, 0.003, 0)
//call BlzFrameSetPoint(frames[5], FRAMEPOINT_TOPLEFT, frames[2], FRAMEPOINT_BOTTOMLEFT, 0, -0.003)
//CreateTasButtonTooltip(frames[index], FrameSuperBox)
call BlzFrameSetText(frames[2], I2S(pageSize))
call BlzFrameSetText(frames[5], I2S(-pageSize))
//refButtons.Page = frames[1]
//refButtons.PageUp = frames[2]
//refButtons.PageDown = frames[5]
//refButtons.PageText = frames[8]
//return frames
endfunction
public function PlaceRefButtonBox takes framehandle box returns nothing
local integer loopA
local boolean found
if RefButtonBoxRows == 0 then
call BlzFrameSetPoint(box, FRAMEPOINT_TOPRIGHT, FrameTasButtonList, FRAMEPOINT_BOTTOMRIGHT, 0, 0)
set RefButtonBoxRows = RefButtonBoxRows + 1
set RefButtonBoxFrameFirst[RefButtonBoxRows] = box
set RefButtonBoxFrameLast[RefButtonBoxRows] = box
set RefButtonBoxSize[RefButtonBoxRows] = xSize - BlzFrameGetWidth(box)
set ySize = ySize + refButtonBoxSizeY
call BlzFrameSetSize(FrameParentSuperUI, xSize, ySize)
else
set found = false
set loopA = 1
loop
exitwhen loopA > RefButtonBoxRows
if RefButtonBoxSize[loopA] - BlzFrameGetWidth(box) >= 0 then
set found = true
call BlzFrameSetPoint(box, FRAMEPOINT_TOPRIGHT, RefButtonBoxFrameLast[loopA], FRAMEPOINT_TOPLEFT, 0, 0)
set RefButtonBoxFrameLast[loopA] = box
set RefButtonBoxSize[loopA] = RefButtonBoxSize[loopA] - BlzFrameGetWidth(box)
exitwhen true
endif
set loopA = loopA + 1
endloop
if not found then
call BlzFrameSetPoint(box, FRAMEPOINT_TOPRIGHT, RefButtonBoxFrameFirst[RefButtonBoxRows], FRAMEPOINT_BOTTOMRIGHT, 0, 0)
set RefButtonBoxRows = RefButtonBoxRows + 1
set RefButtonBoxFrameFirst[RefButtonBoxRows] = box
set RefButtonBoxFrameLast[RefButtonBoxRows] = box
set RefButtonBoxSize[RefButtonBoxRows] = xSize - BlzFrameGetWidth(box)
set ySize = ySize + refButtonBoxSizeY
call BlzFrameSetSize(FrameParentSuperUI, xSize, ySize)
endif
endif
endfunction
function TasItemShopUICreate takes nothing returns nothing
local framehandle frame
local framehandle parent
local integer loopA
local integer groupObject
local framehandle array frames
local integer array categoryIndexes
local integer buttonsInRow
local integer rows
local framehandle clearButton
set RefButtonCount = 0
set RefButtonBoxRows = 0
call BlzLoadTOCFile("war3mapImported\\Templates.toc")
call BlzLoadTOCFile("war3mapImported\\TasItemShop.toc")
//set UpdateCounterText = BlzCreateFrame("TasButtonTextTemplate", parent, 0, 0)
//call BlzFrameSetAbsPoint(UpdateCounterText, FRAMEPOINT_TOPLEFT, 0.2, 0.55)
set parent = GetParent()
if posScreenRelative then
set frame = BlzCreateFrameByType("FRAME", "Fullscreen", parent, "", 0)
call BlzFrameSetVisible(frame, false)
call BlzFrameSetSize(frame, 0.8, 0.6)
call BlzFrameSetAbsPoint(frame, FRAMEPOINT_BOTTOM, 0.4, 0)
set FrameFullscreen = frame
endif
set xSize = 0.02 + buttonListCols*buttonListButtonSizeX + buttonListButtonGapCol * (buttonListCols - 1)
//ySize = 0.1285 + buttonListRows*buttonListButtonSizeY + refButtonBoxSizeY
//set ySize = 0.0815 + buttonListRows*buttonListButtonSizeY
set ySize = 0.0815 + buttonListRows*buttonListButtonSizeY + buttonListButtonGapRow * (buttonListRows - 1)
// super
set FrameParentSuper = BlzCreateFrameByType("FRAME", "TasItemShopUI", parent, "", 0)
call BlzFrameSetSize(FrameParentSuper, 0.001, 0.001)
set parent = BlzCreateFrameByType("BUTTON", "TasItemShopUI", FrameParentSuper, "", 0)
call BlzFrameSetSize(parent, xSize, ySize)
call BlzTriggerRegisterFrameEvent(ButtonTriggerParentScroll, parent, FRAMEEVENT_MOUSE_WHEEL)
call AddClearFocus(parent)
if posScreenRelative then
call BlzFrameSetPoint(parent, posPoint, FrameFullscreen, posPoint, xPos, yPos)
else
call BlzFrameSetAbsPoint(parent, posPoint, xPos, yPos)
endif
set FrameParentSuperUI = parent
set frame = BlzCreateFrame(boxFrameName, parent, 0, 0)
call BlzFrameSetAllPoints(frame, parent)
set FrameSuperBox = frame
// round down, boxSize - 2times gap to border / buttonSize + gap between buttons
set buttonsInRow = R2I((xSize - (boxCatBorderGap)*2)/(categoryButtonSize + 0.003))
// round up
set rows = R2I(1+ (CategoryCount/buttonsInRow))
//call BJDebugMsg(I2S(buttonsInRow)+ ", " + I2S(rows))
//print(#TasItemShopUI.Categories, buttonsInRow, rows)
set ySize = ySize + rows * categoryButtonSize
// ButtonList
set parent = BlzCreateFrame(boxButtonListFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetPoint(parent, FRAMEPOINT_TOPRIGHT, FrameSuperBox, FRAMEPOINT_TOPRIGHT, 0, 0)
// baseSizeY = 0.0455
call BlzFrameSetSize(parent, xSize, 0.0455 + buttonListRows*buttonListButtonSizeY + rows * categoryButtonSize + buttonListButtonGapRow * (buttonListRows - 1))
set ButtonListIndex = CreateTasButtonList10(buttonListButtonName, buttonListCols, buttonListRows, parent, function ButtonListFunction_LeftClick, function ButtonListFunction_RightClick, function updateItemFrameAction, function ButtonListFunction_Search, function ButtonListFunction_Filter, function ButtonListFunction_AsyncLeftClick, function ButtonListFunction_AsyncRightClick, buttonListButtonGapCol, buttonListButtonGapRow)
set FrameTasButtonList = parent
set loopA = buttonListRows*buttonListCols
loop
exitwhen loopA <= 0
set frame = BlzGetFrameByName("TasButtonListTooltipText", TasButtonListCreateContext[ButtonListIndex] + loopA)
call BlzFrameClearAllPoints(frame)
if toolTipPosPointParent != null then
call BlzFrameSetPoint(frame, toolTipPosPoint, BlzGetFrameByName(TasButtonListButtonName[ButtonListIndex], TasButtonListCreateContext[ButtonListIndex] + loopA), toolTipPosPointParent, toolTipPosX, toolTipPosY)
else
call BlzFrameSetAbsPoint(frame, toolTipPosPoint, toolTipPosX, toolTipPosY)
endif
if buttonListHighLightFrameName != null and buttonListHighLightFrameName != "" then
set frame = BlzCreateFrame(buttonListHighLightFrameName, BlzGetFrameByName(TasButtonListButtonName[ButtonListIndex], TasButtonListCreateContext[ButtonListIndex] + loopA), 0, TasButtonListCreateContext[ButtonListIndex] + loopA)
call BlzFrameSetAllPoints(frame, BlzGetFrameByName(TasButtonListButtonName[ButtonListIndex], TasButtonListCreateContext[ButtonListIndex] + loopA))
call BlzFrameSetVisible(frame, false)
endif
set loopA = loopA - 1
endloop
// category
set frame = BlzCreateFrame(boxCatFrameName, parent, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPRIGHT, TasButtonListInputFrame[ButtonListIndex], FRAMEPOINT_BOTTOMRIGHT, 0, 0)
call BlzFrameSetSize(frame, xSize, 0.0135 + rows * categoryButtonSize)
set FrameCategoryBox = frame
set parent = frame
set groupObject = CreateToggleIconButtonGroup(function ButtonListFunction_CategoryAction)
set ToggleIconButton_DefaultSizeX = categoryButtonSize
set ToggleIconButton_DefaultSizeY = categoryButtonSize
//frame = ToggleIconButtonGroupModeButton(groupObject, parent).Button
set frame = ToggleIconButtonGroupClearButton(groupObject, parent, "ReplaceableTextures\\CommandButtons\\BTNCancel")
//BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, FrameSuperBox, FRAMEPOINT_TOPLEFT, boxFrameBorderGap, -boxFrameBorderGap)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, FrameSuperBox, FRAMEPOINT_TOPLEFT, boxFrameBorderGap, -boxFrameBorderGap)
call BlzTriggerRegisterFrameEvent(ButtonTriggerClear, frame, FRAMEEVENT_CONTROL_CLICK)
call AddClearFocus(frame)
set clearButton = frame
set CategoryModButtonIndex = CreateToggleIconButton(parent, 1, GetLocalizedString(categoryModeTextOr), categoryModeIconOr, 0, GetLocalizedString(categoryModeTextAnd), categoryModeIconAnd)
call BlzFrameSetPoint(ToggleIconButton_Button[CategoryModButtonIndex], FRAMEPOINT_BOTTOMLEFT, clearButton, FRAMEPOINT_BOTTOMRIGHT, 0.003, 0)
call BlzTriggerRegisterFrameEvent(ButtonTriggerCategoryMode, ToggleIconButton_Button[CategoryModButtonIndex], FRAMEEVENT_CONTROL_CLICK)
set loopA = 1
loop
exitwhen loopA > CategoryCount
set categoryIndexes[loopA] = CreateToggleIconButtonSimple(parent, CategoryValues[loopA], GetLocalizedString(CategoryText[loopA]), CategoryIcon[loopA])
if loopA == 1 then
call BlzFrameSetPoint(ToggleIconButton_Button[categoryIndexes[loopA]], FRAMEPOINT_TOPLEFT, parent, FRAMEPOINT_TOPLEFT, boxCatBorderGap, -boxCatBorderGap)
else
call BlzFrameSetPoint(ToggleIconButton_Button[categoryIndexes[loopA]], FRAMEPOINT_TOPLEFT, ToggleIconButton_Button[categoryIndexes[loopA - 1]], FRAMEPOINT_TOPRIGHT, 0.003, 0)
endif
call ToggleIconButtonGroupAddButton(groupObject, categoryIndexes[loopA])
set loopA = loopA + 1
endloop
set loopA = 2
loop
exitwhen loopA > rows
// print((index-1)*buttonsInRow + 1, "->", (index-2)*buttonsInRow + 1)
call BlzFrameSetPoint(ToggleIconButton_Button[categoryIndexes[(loopA-1)*buttonsInRow + 1]], FRAMEPOINT_TOPLEFT, ToggleIconButton_Button[categoryIndexes[(loopA-2)*buttonsInRow + 1]], FRAMEPOINT_BOTTOMLEFT, 0, -0.001)
//BlzFrameSetPoint(frames[(index-1)*buttonsInRow + 1].Button, FRAMEPOINT_TOPLEFT, frames[(index-2)*buttonsInRow + 1].Button, FRAMEPOINT_BOTTOMLEFT, 0, -0.001)
set loopA = loopA + 1
endloop
set frame = BlzGetFrameByName(TasButtonListButtonName[ButtonListIndex], TasButtonListCreateContext[ButtonListIndex] + 1)
call BlzFrameClearAllPoints(frame)
//call BlzFrameSetPoint(frame, FRAMEPOINT_TOPRIGHT, FrameCategoryBox, FRAMEPOINT_BOTTOMRIGHT, -0.014, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, FrameCategoryBox, FRAMEPOINT_BOTTOMLEFT, 0.0045, 0)
// built from
if refButtonCountMats > 0 then
set parent = BlzCreateFrame(boxRefFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, (refButtonSize + refButtonGap)*refButtonCountMats + boxFrameBorderGap*2, refButtonBoxSizeY)
call PlaceRefButtonBox(parent)
set FrameMaterialBox = parent
set frame = BlzCreateFrame("TasButtonTextTemplate", parent, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, parent, FRAMEPOINT_TOPLEFT, boxRefBorderGap, -boxRefBorderGap)
call BlzFrameSetText(frame, GetLocalizedString(textMats))
set FrameMaterialText = frame
set RefButtonMaterialStart = RefButtonCount
set RefButtonMaterialEnd = CreateRefButtons(refButtonCountMats, parent, frame, ButtonTriggerMaterial, true)
call CreateRefPage(parent, FrameMaterialText, ButtonTriggerMaterialPage, refButtonCountMats)
set FrameMaterialPage = BlzGetFrameByName("TasItemShopUIPageControl", 0)
set FrameMaterialPageUp = BlzGetFrameByName("TasItemShopCatButton", 0)
set FrameMaterialPageDown = BlzGetFrameByName("TasItemShopCatButton", 1)
set FrameMaterialPageText = BlzGetFrameByName("TasButtonTextTemplate", 0)
endif
// possible upgrades
if refButtonCountUp > 0 then
set parent = BlzCreateFrame(boxRefFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, (refButtonSize + refButtonGap)*refButtonCountUp + boxFrameBorderGap*2, refButtonBoxSizeY)
call PlaceRefButtonBox(parent)
set FrameUpgradeBox = parent
set frame = BlzCreateFrame("TasButtonTextTemplate", parent, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, parent, FRAMEPOINT_TOPLEFT, boxRefBorderGap, -boxRefBorderGap)
call BlzFrameSetText(frame, GetLocalizedString(textUpgrades))
set FrameUpgradeText = frame
set RefButtonUpgradeStart = RefButtonCount
set RefButtonUpgradeEnd = CreateRefButtons(refButtonCountUp, parent, frame, ButtonTriggerUpgrade, true)
call CreateRefPage(parent, FrameUpgradeText, ButtonTriggerUpgradePage, refButtonCountUp)
set FrameUpgradePage = BlzGetFrameByName("TasItemShopUIPageControl", 0)
set FrameUpgradePageUp = BlzGetFrameByName("TasItemShopCatButton", 0)
set FrameUpgradePageDown = BlzGetFrameByName("TasItemShopCatButton", 1)
set FrameUpgradePageText = BlzGetFrameByName("TasButtonTextTemplate", 0)
endif
if refButtonCountQuickLink > 0 then
set parent = BlzCreateFrame(boxRefFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, (refButtonSize + refButtonGap)*refButtonCountUp + boxFrameBorderGap*2, refButtonBoxSizeY)
call PlaceRefButtonBox(parent)
set FrameQuickLinkBox = parent
set frame = BlzCreateFrame("TasButtonTextTemplate", parent, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, parent, FRAMEPOINT_TOPLEFT, boxRefBorderGap, -boxRefBorderGap)
call BlzFrameSetText(frame, GetLocalizedString(textQuickLink))
set FrameQuickLinkText = frame
set FrameQuickLinkBoxHighLight = BlzCreateFrame(buttonListHighLightFrameName, parent, 0, 0)
call BlzFrameSetAllPoints(FrameQuickLinkBoxHighLight, parent)
call BlzFrameSetVisible(FrameQuickLinkBoxHighLight, false)
set RefButtonQuickLinkStart = RefButtonCount
set RefButtonQuickLinkEnd = CreateRefButtons(refButtonCountQuickLink, parent, frame, ButtonTriggerQuickLink, true)
call CreateRefPage(parent, FrameQuickLinkText, ButtonTriggerQuickLinkPage, refButtonCountUp)
set FrameQuickLinkPage = BlzGetFrameByName("TasItemShopUIPageControl", 0)
set FrameQuickLinkPageUp = BlzGetFrameByName("TasItemShopCatButton", 0)
set FrameQuickLinkPageDown = BlzGetFrameByName("TasItemShopCatButton", 1)
set FrameQuickLinkPageText = BlzGetFrameByName("TasButtonTextTemplate", 0)
endif
// Inventory
if refButtonCountInv > 0 then
set parent = BlzCreateFrame(boxRefFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, (refButtonSize + refButtonGap)*refButtonCountInv + boxFrameBorderGap*2, refButtonBoxSizeY)
call PlaceRefButtonBox(parent)
set FrameInventoryBox = parent
set frame = BlzCreateFrame("TasButtonTextTemplate", parent, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, parent, FRAMEPOINT_TOPLEFT, boxRefBorderGap, -boxRefBorderGap)
call BlzFrameSetText(frame, GetLocalizedString(textInventory))
set FrameInventoryText = frame
set RefButtonInventoryStart = RefButtonCount
set RefButtonInventoryEnd = CreateRefButtons(refButtonCountInv, parent, frame, ButtonTriggerInventory, true)
set loopA = RefButtonInventoryStart
loop
exitwhen loopA > RefButtonInventoryEnd
call BlzFrameSetTexture(RefButtonOverlay[loopA], MainItemTexture, 0, true)
set loopA = loopA + 1
endloop
call CreateRefPage(parent, FrameInventoryText, ButtonTriggerInventoryPage, refButtonCountInv)
set FrameInventoryPage = BlzGetFrameByName("TasItemShopUIPageControl", 0)
set FrameInventoryPageUp = BlzGetFrameByName("TasItemShopCatButton", 0)
set FrameInventoryPageDown = BlzGetFrameByName("TasItemShopCatButton", 1)
set FrameInventoryPageText = BlzGetFrameByName("TasButtonTextTemplate", 0)
endif
// User
if refButtonCountUser > 0 then
set parent = BlzCreateFrame(boxRefFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, (refButtonSize + refButtonGap)*refButtonCountUser + boxFrameBorderGap*2, refButtonBoxSizeY)
call PlaceRefButtonBox(parent)
set FrameUserBox = parent
set frame = BlzCreateFrame("TasButtonTextTemplate", parent, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, parent, FRAMEPOINT_TOPLEFT, boxRefBorderGap, -boxRefBorderGap)
call BlzFrameSetText(frame, GetLocalizedString(textUser))
set FrameUserText = frame
set RefButtonUserStart = RefButtonCount
set RefButtonUserEnd = CreateRefButtons(refButtonCountUser, parent, frame, ButtonTriggerUser, false)
set loopA = RefButtonUserStart
loop
exitwhen loopA > RefButtonUserEnd
call BlzFrameSetTexture(RefButtonOverlay[loopA], MainUserTexture, 0, true)
set loopA = loopA + 1
endloop
call CreateRefPage(parent, FrameUserText, ButtonTriggerUserPage, refButtonCountUser)
set FrameUserPage = BlzGetFrameByName("TasItemShopUIPageControl", 0)
set FrameUserPageUp = BlzGetFrameByName("TasItemShopCatButton", 0)
set FrameUserPageDown = BlzGetFrameByName("TasItemShopCatButton", 1)
set FrameUserPageText = BlzGetFrameByName("TasButtonTextTemplate", 0)
endif
set frame = BlzCreateFrame("TasButton", FrameSuperBox, 0, CREATE_CONTEXT_CURRENT)
call CreateTasButtonTooltip(frame, FrameSuperBox, CREATE_CONTEXT_CURRENT)
call BlzGetFrameByName("TasButtonIcon", CREATE_CONTEXT_CURRENT)
call BlzGetFrameByName("TasButtonText", CREATE_CONTEXT_CURRENT)
call BlzGetFrameByName("TasButtonIconGold", CREATE_CONTEXT_CURRENT)
call BlzGetFrameByName("TasButtonTextGold", CREATE_CONTEXT_CURRENT)
call BlzGetFrameByName("TasButtonIconLumber", CREATE_CONTEXT_CURRENT)
call BlzGetFrameByName("TasButtonTextLumber", CREATE_CONTEXT_CURRENT)
call BlzFrameSetPoint(frame, FRAMEPOINT_BOTTOM, FrameSuperBox, FRAMEPOINT_BOTTOM, 0, boxFrameBorderGap)
call BlzTriggerRegisterFrameEvent(ButtonTriggerBuy, frame, FRAMEEVENT_CONTROL_CLICK)
call AddClearFocus(frame)
set frame = BlzCreateFrame("TasButtonTextTemplate", FrameSuperBox, 0, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_BOTTOMRIGHT, TasButtonListInputFrame[ButtonListIndex], FRAMEPOINT_BOTTOMLEFT, -boxFrameBorderGap, 0)
call BlzFrameSetPoint(frame, FRAMEPOINT_TOPLEFT, ToggleIconButton_Button[CategoryModButtonIndex], FRAMEPOINT_TOPRIGHT, boxFrameBorderGap, 0)
call BlzFrameSetTextAlignment(frame, TEXT_JUSTIFY_CENTER, TEXT_JUSTIFY_MIDDLE)
call BlzFrameSetText(frame, "Name")
set FrameTitelText = frame
call BlzFrameClearAllPoints(BlzGetFrameByName("TasButtonListTooltipText", CREATE_CONTEXT_CURRENT))
if toolTipPosPointParent != null then
call BlzFrameSetPoint(BlzGetFrameByName("TasButtonListTooltipText", CREATE_CONTEXT_CURRENT), toolTipPosPoint, BlzGetFrameByName("TasButton", CREATE_CONTEXT_CURRENT), toolTipPosPointParent, toolTipPosX, toolTipPosY)
else
call BlzFrameSetAbsPoint(BlzGetFrameByName("TasButtonListTooltipText", CREATE_CONTEXT_CURRENT), toolTipPosPoint, toolTipPosX, toolTipPosY)
endif
if canUndo then
set parent = BlzCreateFrame(boxUndoFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, refButtonSize + boxUndoBorderGap*2, refButtonSize + boxUndoBorderGap*2)
call BlzFrameSetPoint(parent, FRAMEPOINT_BOTTOMLEFT, FrameSuperBox, FRAMEPOINT_BOTTOMLEFT, 0.00, 0.00)
set FrameUndoBox = parent
set FrameUndoButton = BlzCreateFrame("TasItemShopCatButton", parent, 0, 0)
set FrameUndoButtonIcon = BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0)
set FrameUndoButtonIconPushed = BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0)
set FrameUndoText = CreateSimpleTooltip(FrameUndoButton, textUndo)
set frame = FrameUndoButton
call BlzFrameSetSize(frame, refButtonSize, refButtonSize)
call BlzFrameSetPoint(frame, FRAMEPOINT_CENTER, parent, FRAMEPOINT_CENTER, 0, 0)
call BlzTriggerRegisterFrameEvent(ButtonTriggerUndo, frame, FRAMEEVENT_CONTROL_CLICK)
call AddClearFocus(frame)
call BlzFrameSetVisible(FrameUndoBox, false)
endif
if canDefuse then
set parent = BlzCreateFrame(boxDefuseFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, refButtonSize + boxDefuseBorderGap*2, refButtonSize + boxDefuseBorderGap*2)
call BlzFrameSetPoint(parent, FRAMEPOINT_BOTTOMRIGHT, FrameSuperBox, FRAMEPOINT_BOTTOMRIGHT, 0.00, 0.00)
set FrameDefuseBox = parent
set FrameDefuseButton = BlzCreateFrame("TasItemShopCatButton", parent, 0, 0)
set FrameDefuseText = CreateSimpleTooltip(FrameDefuseButton, textDefuse)
call BlzFrameClearAllPoints(FrameDefuseText)
call BlzFrameSetPoint(FrameDefuseText, FRAMEPOINT_BOTTOMRIGHT, FrameDefuseButton, FRAMEPOINT_TOPRIGHT, 0, 0.008)
set frame = FrameDefuseButton
call BlzFrameSetTexture(BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0), DefuseButtonIcon, 0, false)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0), DefuseButtonIcon, 0, false)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemShopCatButtonBackdropDisabled", 0), DefuseButtonIconDisabled, 0, false)
call BlzFrameSetSize(frame, refButtonSize, refButtonSize)
call BlzFrameSetPoint(frame, FRAMEPOINT_CENTER, parent, FRAMEPOINT_CENTER, 0, 0)
call BlzTriggerRegisterFrameEvent(ButtonTriggerDefuse, frame, FRAMEEVENT_CONTROL_CLICK)
call AddClearFocus(frame)
call BlzFrameSetEnable(FrameDefuseButton, false)
endif
if canSellItems then
set parent = BlzCreateFrame(boxDefuseFrameName, FrameSuperBox, 0, 0)
call BlzFrameSetSize(parent, refButtonSize + boxSellBorderGap*2, refButtonSize + boxSellBorderGap*2)
if canDefuse then
call BlzFrameSetPoint(parent, FRAMEPOINT_BOTTOMRIGHT, FrameDefuseBox, FRAMEPOINT_BOTTOMLEFT, 0.00, 0.00)
else
call BlzFrameSetPoint(parent, FRAMEPOINT_BOTTOMRIGHT, FrameSuperBox, FRAMEPOINT_BOTTOMRIGHT, 0.00, 0.00)
endif
set FrameSellBox = parent
set FrameSellButton = BlzCreateFrame("TasItemShopCatButton", parent, 0, 0)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemShopCatButtonBackdrop", 0), SellButtonIcon, 0, false)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemShopCatButtonBackdropPushed", 0), SellButtonIcon, 0, false)
call BlzFrameSetTexture(BlzGetFrameByName("TasItemShopCatButtonBackdropDisabled", 0), SellButtonIconDisabled, 0, false)
set frame = FrameSellButton
call BlzFrameSetSize(frame, refButtonSize, refButtonSize)
call BlzFrameSetPoint(frame, FRAMEPOINT_CENTER, parent, FRAMEPOINT_CENTER, 0, 0)
call BlzTriggerRegisterFrameEvent(ButtonTriggerSell, frame, FRAMEEVENT_CONTROL_CLICK)
call AddClearFocus(frame)
call BlzFrameSetEnable(FrameSellButton, false)
set FrameSellText = CreateSimpleTooltip(frame, textSell)
call BlzFrameClearAllPoints(FrameSellText)
call BlzFrameSetPoint(FrameSellText, FRAMEPOINT_BOTTOMRIGHT, FrameSellButton, FRAMEPOINT_TOPRIGHT, 0, 0.008)
endif
set parent = BlzCreateFrameByType("BUTTON", "TasRightClickSpriteParent", FrameSuperBox, "", 0)
call BlzFrameSetLevel(parent, 99)
set frame = BlzCreateFrameByType("SPRITE", "TasRightClickSprite", parent, "", 0)
call BlzFrameSetSize(frame, refButtonSize, refButtonSize)
call BlzFrameSetScale(frame, spriteScale)
call BlzFrameSetModel(frame, spriteModel, 0)
call BlzFrameSetVisible(parent, false)
set FrameSpriteParent = parent
set FrameSprite = frame
//fitRefBoxes()
call BlzFrameSetSize(FrameParentSuperUI, xSize, ySize)
call BlzFrameSetVisible(FrameParentSuper, false)
endfunction
public function RefButtonPageChange takes integer current, integer add, integer min, integer max, player p returns integer
local integer remain
local integer size = IAbsBJ(add)
if BlzGetTriggerFrameEvent() == FRAMEEVENT_CONTROL_CLICK then
set current = current + add
if not refButtonPageRotate then
if current < min then
set current = min
endif
if current >= max then
set current = max - add
endif
else
if add > 0 then
if current >= max then
set current = min
endif
else
if current < min then
set remain = ModuloInteger(max, size)
// last page is incomplete?
if remain > 0 then
set current = max - remain
else
set current = max - size
endif
endif
endif
endif
elseif IsRightClick(p) then
call StartSoundForPlayerBJ(p, ToggleIconButton_Sound)
// right clicks jump to the first or last Page
if add > 0 then
set current = max - size
else
set current = min
endif
endif
return current
endfunction
public function RefButtonAction takes integer itemCode returns nothing
local player p = GetTriggerPlayer()
local framehandle frame = BlzGetTriggerFrame()
if BlzGetTriggerFrameEvent() == FRAMEEVENT_CONTROL_CLICK then
// print(GetPlayerName(player), "Clicked Material", index)
call setSelected(p, itemCode)
else
if IsRightClick(p) then
call ShowSprite(frame, p)
call StartSoundForPlayerBJ(p, ToggleIconButton_Sound)
call BuyItem(p, itemCode)
endif
endif
endfunction
private function TriggerFuctionDefuse takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode
local item i
local integer gold
local integer lumber
local integer undoIndex
local integer loopA
local integer loopB
local unit u
if SelectedItem[playerIndex] == null then
return
endif
set i = SelectedItem[playerIndex]
set itemCode = GetItemTypeId(i)
set SelectedItem[playerIndex] = null
set gold = TasItemGetCostGold(itemCode)
set lumber = TasItemGetCostLumber(itemCode)
set loopA = TasItemFusion_BuiltWay[itemCode][0]
loop
exitwhen loopA <= 0
set gold = gold - TasItemGetCostGold(TasItemFusion_BuiltWay[itemCode][loopA])
set lumber = lumber - TasItemGetCostLumber(TasItemFusion_BuiltWay[itemCode][loopA])
set loopA = loopA - 1
// body
endloop
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_GOLD, gold)
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_LUMBER, lumber)
if canUndo then
set undoIndex = CreateUndo(p, itemCode, -gold, -lumber, " Defuse")
set UndoItems[undoIndex][0] = 1
set UndoItems[undoIndex].item[1] = i
set UndoItems[undoIndex].unit[-1] = ItemHolder_get(i)
call UnitRemoveItem(ItemHolder_get(i), i)
call SetItemVisible(i, false)
if GetLocalPlayer() == p then
call BlzFrameSetVisible(FrameUndoBox, true)
call updateUndoButton(UndoResultCode[undoIndex], " Defuse")
endif
else
call RemoveItem(i)
endif
set loopA = TasItemFusion_BuiltWay[itemCode][0]
loop
exitwhen loopA <= 0
set i = CreateItem(TasItemFusion_BuiltWay[itemCode][loopA], GetUnitX(ShoperMain[playerIndex]), GetUnitY(ShoperMain[playerIndex]))
call GiveItemGroup(p, i, undoIndex)
set loopA = loopA - 1
endloop
if GetLocalPlayer() == p then
call BlzFrameSetEnable(FrameDefuseButton, false)
endif
endfunction
private function TriggerFuctionSell takes nothing returns nothing
call SellItem(GetTriggerPlayer(), SelectedItem[GetPlayerId(GetTriggerPlayer())])
endfunction
private function TriggerFuctionBuy takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
call ShowSprite(BlzGetTriggerFrame(), p)
call BuyItem(p, itemCode)
set p = null
endfunction
public function ShopSelectionActionGroupEnum takes nothing returns nothing
if not IsValidShopper(TempPlayer, TempUnit, GetEnumUnit(), TempRange) then
call GroupRemoveUnit(TempGroup, GetEnumUnit())
endif
endfunction
public function ShopSelectionAction takes player p, unit shop, unit target returns nothing
local integer playerIndex = GetPlayerId(p)
local integer shopObject = GetUnitTypeId(shop)
local real oldRange = shopRange
local integer shopIndex = Shops[shopObject]
// is a registered shop UnitType?
if shopIndex != 0 then
set TempPlayer = p
set TempRange = ShopRange[shopObject]
if TempRange < 1 then
set TempRange = oldRange
endif
call GroupEnumUnitsInRange(TempGroup, GetUnitX(shop), GetUnitY(shop), TempRange + 400, null)
// remove unallowed shoppers
set TempUnit = shop
call ForGroup(TempGroup, function ShopSelectionActionGroupEnum)
set shopRange = oldRange
if target == null and IsUnitInGroup(ShoperMain[playerIndex], TempGroup) then
set target = ShoperMain[playerIndex]
endif
call TasItemShopUIShow(p, shop, TempGroup, target)
// no, end shopping!
elseif CurrentShop[playerIndex] != null then
call TasItemShopUIShow(p, null, null, null)
endif
endfunction
private function TriggerFuctionUser takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
local integer index = S2I(BlzFrameGetText(BlzGetTriggerFrame())) + CurrentOffSetUser[playerIndex]
local unit u = BlzGroupUnitAt(Shoper[playerIndex], index - 1)
if BlzGetTriggerFrameEvent() == FRAMEEVENT_CONTROL_CLICK then
call IssueNeutralTargetOrder(p, CurrentShop[playerIndex], "smart", u)
if not userButtonOrder then
call ShopSelectionAction(p, CurrentShop[playerIndex], u)
endif
else
if IsRightClick(p) then
call SelectUnitForPlayerSingle(u, p)
endif
endif
endfunction
private function TriggerFuctionUserPage takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
local integer max = BlzGroupGetSize(Shoper[playerIndex])
local integer min = 0
local integer add = S2I(BlzFrameGetText(BlzGetTriggerFrame()))
set CurrentOffSetUser[playerIndex] = RefButtonPageChange(CurrentOffSetUser[playerIndex], add, min, max, p)
if GetLocalPlayer() == p then
call updateRefButtonsUser(p)
call updateOverLayMainSelected(p)
//fitRefBoxes()
endif
endfunction
private function TriggerFuctionInventory takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local framehandle frame = BlzGetTriggerFrame()
local integer index = S2I(BlzFrameGetText(BlzGetTriggerFrame())) + CurrentOffSetInventory[playerIndex]
local item i
local integer itemCode
if inventoryShowMainOnly then
// warcraft inventory starts with 0 but button indexes with 1
set i = UnitItemInSlot(ShoperMain[playerIndex], index - 1)
else
set i = TasItemFusion_PlayerItems[playerIndex].item[index]
endif
set itemCode = GetItemTypeId(i)
// prevent a possible desync when the inventory item was not given to TasItemCost yet. TasItemCost creates and destroys an item when a new type is given.
call TasItemCaclCost(itemCode)
if BlzGetTriggerFrameEvent() == FRAMEEVENT_CONTROL_CLICK then
// print(GetPlayerName(player), "Clicked Material", index)
call setSelected(p, itemCode)
call setSelectedItem(p, i)
else
if IsRightClick(p) then
call ShowSprite(frame, p)
call StartSoundForPlayerBJ(p, ToggleIconButton_Sound)
if canSellItems and inventoryRightClickSell then
call SellItem(p, i)
else
call BuyItem(p, itemCode)
endif
endif
endif
set i = null
set frame = null
set p = null
endfunction
private function TriggerFuctionInventoryPage takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer max = TasItemFusion_PlayerItems[playerIndex][0]
local integer min = 0
local integer add = S2I(BlzFrameGetText(BlzGetTriggerFrame()))
set CurrentOffSetInventory[playerIndex] = RefButtonPageChange(CurrentOffSetInventory[playerIndex], add, min, max, p)
if GetLocalPlayer() == p then
call updateRefButtonsInventory(p)
//fitRefBoxes()
endif
endfunction
private function TriggerFuctionUpgrade takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
local integer index = S2I(BlzFrameGetText(BlzGetTriggerFrame())) + CurrentOffSetUpgrade[playerIndex]
call RefButtonAction(TasItemFusion_UsedIn[itemCode][index])
endfunction
private function TriggerFuctionUpgradePage takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
local integer max = TasItemFusion_UsedIn[itemCode][0]
local integer min = 0
local integer add = S2I(BlzFrameGetText(BlzGetTriggerFrame()))
set CurrentOffSetUpgrade[playerIndex] = RefButtonPageChange(CurrentOffSetUpgrade[playerIndex], add, min, max, p)
if GetLocalPlayer() == p then
call updateRefButtonsUpgrades(p, itemCode)
call updateHaveMats(p, itemCode)
//fitRefBoxes()
endif
endfunction
private function TriggerFuctionQuickLink takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer index = S2I(BlzFrameGetText(BlzGetTriggerFrame())) + CurrentOffSetQuickLink[playerIndex]
local integer itemCode = QuickLink[playerIndex][index]
if QuickLinkKeyActive[playerIndex] and BlzGetTriggerFrameEvent() == FRAMEEVENT_CONTROL_CLICK then
call SetQuickLink(p, itemCode)
else
call RefButtonAction(itemCode)
endif
endfunction
private function TriggerFuctionQuickLinkPage takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer max = QuickLink[playerIndex][0]
local integer min = 0
local integer add = S2I(BlzFrameGetText(BlzGetTriggerFrame()))
set CurrentOffSetQuickLink[playerIndex] = RefButtonPageChange(CurrentOffSetQuickLink[playerIndex], add, min, max, p)
if GetLocalPlayer() == p then
call updateRefButtonsQuickLink(p)
endif
endfunction
private function TriggerFuctionMaterial takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
local integer index = S2I(BlzFrameGetText(BlzGetTriggerFrame())) + CurrentOffSetMaterial[playerIndex]
call RefButtonAction(TasItemFusion_BuiltWay[itemCode][index])
endfunction
private function TriggerFuctionMaterialPage takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer itemCode = Selected[playerIndex]
local integer max = TasItemFusion_BuiltWay[itemCode][0]
local integer min = 0
local integer add = S2I(BlzFrameGetText(BlzGetTriggerFrame()))
set CurrentOffSetMaterial[playerIndex] = RefButtonPageChange(CurrentOffSetMaterial[playerIndex], add, min, max, p)
if GetLocalPlayer() == p then
call updateRefButtonsMaterial(p, itemCode)
call updateHaveMats(p, itemCode)
//fitRefBoxes()
endif
endfunction
private function TriggerFuctionUndo takes nothing returns nothing
local player p = GetTriggerPlayer()
local integer playerIndex = GetPlayerId(p)
local integer loopA
local integer undoIndex = UndoPlayerSize*playerIndex + UndoPlayerCount[playerIndex]
// there is something to undo?
if UndoPlayerCount[playerIndex] <= 0 then
return
endif
set undoIndex = UndoPlayerSize*playerIndex + UndoPlayerCount[playerIndex]
//print("Use Undo:",#TasItemShopUI.Undo[player] + 1, GetObjectName(undo.Result))
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_GOLD, UndoGold[undoIndex])
call AdjustPlayerStateSimpleBJ(p, PLAYER_STATE_RESOURCE_LUMBER, UndoLumber[undoIndex])
// find the result and destroy it, this assumes that the shoper TempGroup not changed since the buying
set loopA = UndoResults[undoIndex][0]
loop
exitwhen loopA <= 0
call RemoveItem(UndoResults[undoIndex].item[loopA])
set UndoResults[undoIndex].item[loopA] = null
set UndoResults[undoIndex].unit[-loopA] = null
set loopA = loopA - 1
// body
endloop
// reset the counter
set UndoResults[undoIndex][0] = 0
if UndoStackGainer[undoIndex] != null then
call SetItemCharges(UndoStackGainer[undoIndex], GetItemCharges(UndoStackGainer[undoIndex]) - UndoStackGained[undoIndex])
set UndoStackGainer[undoIndex] = null
endif
// show the used material and give them back
set loopA = UndoItems[undoIndex][0]
loop
exitwhen loopA <= 0
call SetItemVisible(UndoItems[undoIndex].item[loopA], true)
call UnitAddItem(UndoItems[undoIndex].unit[-loopA], UndoItems[undoIndex].item[loopA])
set UndoItems[undoIndex].item[loopA] = null
set UndoItems[undoIndex].unit[-loopA] = null
set loopA = loopA - 1
// body
endloop
// reset the counter
set UndoItems[undoIndex][0] = 0
set UndoPlayerCount[playerIndex] = UndoPlayerCount[playerIndex] - 1
call TasItemShopUIShow(p, CurrentShop[playerIndex], null, null)
if GetLocalPlayer() == p then
if UndoPlayerCount[playerIndex] > 0 then
call BlzFrameSetVisible(FrameUndoBox, true)
call updateUndoButton(UndoResultCode[undoIndex - 1], UndoActionName[undoIndex - 1])
else
call BlzFrameSetVisible(FrameUndoBox, false)
endif
endif
endfunction
private function TriggerFuctionClear takes nothing returns nothing
if GetTriggerPlayer() == GetLocalPlayer() then
call BlzFrameSetText(TasButtonListInputFrame[ButtonListIndex], "")
endif
endfunction
private function TriggerFuctionSelect takes nothing returns nothing
call ShopSelectionAction(GetTriggerPlayer(), GetTriggerUnit(), null)
endfunction
private function TriggerFuctionOrder takes nothing returns nothing
if Shops[GetUnitTypeId(GetTriggerUnit())] != 0 then
call ShopSelectionAction(GetOwningPlayer(GetOrderTargetUnit()), GetTriggerUnit(), GetOrderTargetUnit())
endif
endfunction
private function TriggerFuctionESC takes nothing returns nothing
call TasItemShopUIShow(GetTriggerPlayer(), null, null, null)
endfunction
private function TriggerFuctionClearFocus takes nothing returns nothing
local framehandle frame = BlzGetTriggerFrame()
if GetTriggerPlayer() == GetLocalPlayer() then
call BlzFrameSetEnable(frame, false)
call BlzFrameSetEnable(frame, true)
endif
set frame = null
endfunction
private function TriggerFuctionParentScroll takes nothing returns nothing
local framehandle frame = TasButtonListSlider[ButtonListIndex]
if GetLocalPlayer() == GetTriggerPlayer() then
if BlzGetTriggerFrameValue() > 0 then
call BlzFrameSetValue(frame, BlzFrameGetValue(frame) + TasButtonListStepSize[ButtonListIndex])
else
call BlzFrameSetValue(frame, BlzFrameGetValue(frame) - TasButtonListStepSize[ButtonListIndex])
endif
endif
set frame = null
endfunction
private function TriggerFuctionCategoryMode takes nothing returns nothing
if GetTriggerPlayer() == GetLocalPlayer() then
call TasButtonListSearch(ButtonListIndex, null)
endif
endfunction
private function TriggerFuctionReleaseQuickLinkKey takes nothing returns nothing
set QuickLinkKeyActive[GetPlayerId(GetTriggerPlayer())] = false
if refButtonCountQuickLink > 0 and GetTriggerPlayer() == GetLocalPlayer() then
call BlzFrameSetVisible(FrameQuickLinkBoxHighLight, false)
endif
endfunction
private function TriggerFuctionPressQuickLinkKey takes nothing returns nothing
set QuickLinkKeyActive[GetPlayerId(GetTriggerPlayer())] = true
if refButtonCountQuickLink > 0 and GetTriggerPlayer() == GetLocalPlayer() then
call BlzFrameSetVisible(FrameQuickLinkBoxHighLight, true)
endif
endfunction
public function TimerUpdate takes nothing returns nothing
// xpcall(function()
local player p
local unit u
local integer loopA
if posScreenRelative then
//credits to ScrewTheTrees(Fred) & Niklas
call BlzFrameSetSize(FrameFullscreen, I2R(BlzGetLocalClientWidth())/BlzGetLocalClientHeight()*0.6, 0.6)
endif
set loopA = 0
loop
exitwhen loopA >= bj_MAX_PLAYER_SLOTS
set p = Player(loopA)
if CurrentShop[loopA] != null then
call ShopSelectionAction(p, CurrentShop[loopA], null)
endif
set loopA = loopA +1
endloop
endfunction
private function At0s takes nothing returns nothing
local integer loopA
local player p
call TimerStart(Timer, 9999999999, false, null)
call TimerStart(CreateTimer(), updateTime, true, function TimerUpdate)
//call UserInit()
//call ExecuteFunc("TasItemShopUserInit")
//precalc any added Item
set loopA = BUY_ABLE_ITEMS_Count
loop
exitwhen loopA <= 0
call TasItemCaclCost(BUY_ABLE_ITEMS[loopA])
set loopA = loopA - 1
// body
endloop
set loopA = 0
loop
exitwhen loopA >= bj_MAX_PLAYER_SLOTS
set Shoper[loopA] = CreateGroup()
set loopA = loopA +1
endloop
call TasItemShopUICreate()
endfunction
public function CreateTriggerEx takes code action returns trigger
local trigger t = CreateTrigger()
call TriggerAddAction(t, action)
return t
endfunction
private function init_function takes nothing returns nothing
local integer loopA
local integer loopB
set IsReforged = (GetLocalizedString("REFORGED") != "REFORGED")
set Shops = Table.create()
set ShopsItems = HashTable.create()
set ShopsGold = HashTable.create()
set ShopsLumber = HashTable.create()
set TasItemCategory = Table.create()
set TempTable = Table.create()
set TempHashTable = HashTable.create()
set BuyAbleMarked = HashTable.create()
set MarkedItemCodes = Table.create()
set ButtonTriggerInventory = CreateTriggerEx(function TriggerFuctionInventory)
set ButtonTriggerInventoryPage = CreateTriggerEx(function TriggerFuctionInventoryPage)
set ButtonTriggerMaterial = CreateTriggerEx(function TriggerFuctionMaterial)
set ButtonTriggerMaterialPage = CreateTriggerEx(function TriggerFuctionMaterialPage)
set ButtonTriggerUser = CreateTriggerEx(function TriggerFuctionUser)
set ButtonTriggerUserPage = CreateTriggerEx(function TriggerFuctionUserPage)
set ButtonTriggerUpgrade = CreateTriggerEx(function TriggerFuctionUpgrade)
set ButtonTriggerUpgradePage = CreateTriggerEx(function TriggerFuctionUpgradePage)
set ButtonTriggerSell = CreateTriggerEx(function TriggerFuctionSell)
set ButtonTriggerDefuse = CreateTriggerEx(function TriggerFuctionDefuse)
set ButtonTriggerBuy = CreateTriggerEx(function TriggerFuctionBuy)
set ButtonTriggerUndo = CreateTriggerEx(function TriggerFuctionUndo)
set ButtonTriggerClear = CreateTriggerEx(function TriggerFuctionClear)
set ButtonTriggerSelect = CreateTriggerEx(function TriggerFuctionSelect)
set ButtonTriggerESC = CreateTriggerEx(function TriggerFuctionESC)
set ButtonTriggerClearFocus = CreateTriggerEx(function TriggerFuctionClearFocus)
set ButtonTriggerParentScroll = CreateTriggerEx(function TriggerFuctionParentScroll)
set ButtonTriggerCategoryMode = CreateTriggerEx(function TriggerFuctionCategoryMode)
set ButtonTriggerQuickLinkKeyPress = CreateTriggerEx(function TriggerFuctionPressQuickLinkKey)
set ButtonTriggerQuickLinkKeyRelease = CreateTriggerEx(function TriggerFuctionReleaseQuickLinkKey)
set ButtonTriggerQuickLink = CreateTriggerEx(function TriggerFuctionQuickLink)
set ButtonTriggerQuickLinkPage = CreateTriggerEx(function TriggerFuctionQuickLinkPage)
if userButtonOrder then
set ButtonTriggerOrder = CreateTriggerEx(function TriggerFuctionOrder)
call TriggerRegisterAnyUnitEventBJ(ButtonTriggerOrder, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
endif
call TriggerRegisterAnyUnitEventBJ(ButtonTriggerSelect, EVENT_PLAYER_UNIT_SELECTED)
set loopA = 0
loop
call TriggerRegisterPlayerEventEndCinematic(ButtonTriggerESC, Player(loopA))
set QuickLink[loopA] = Table.create()
if quickLinkKey != null then
set loopB = 0
loop
call BlzTriggerRegisterPlayerKeyEvent(ButtonTriggerQuickLinkKeyPress, Player(loopA), quickLinkKey, loopB, true)
call BlzTriggerRegisterPlayerKeyEvent(ButtonTriggerQuickLinkKeyRelease, Player(loopA), quickLinkKey, loopB, false)
set loopB = loopB + 1
exitwhen loopB >= 16
//"none"(0), "shift"(1), "control"(2), "alt"(4) and "META"(8) (windows key)
//1 + 2 + 4 + 8 = 15
endloop
endif
set loopA = loopA + 1
exitwhen loopA >= bj_MAX_PLAYER_SLOTS
// body
endloop
// init_body
set Timer = CreateTimer()
call TimerStart(Timer,0 ,false, function At0s)
// Frame related code actions are not saved/Loaded, probably repeat them after Loading the game
static if LIBRARY_FrameLoader then
call FrameLoaderAdd(function TasItemShopUICreate)
endif
endfunction
endlibrary
library TasItemShopUserInit initializer TasItemShopUserInit requires TasItemShop
// This script is meant to be used by vjass user to write init data for TasItemShop
private function ShopCostFunction_ngme takes nothing returns nothing
endfunction
// This runs right before the actually UI is created.
// this is a good place to add items, categories, fusions shops etc.
function TasItemShopUserInit takes nothing returns nothing
local integer shopObject
// this can all be done in GUI aswell, enable the next Line or remove all Text of this function if you only want to use GUI
//if true then return end
// define Categories: Icon, Text
// the Categories are displayed in the order added.
// it is a good idea to save the returned Value in a local to make the category setup later much easier to understand.
// you can only have 31 categories
local integer catDmg = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNSteelMelee", "COLON_DAMAGE")
local integer catArmor = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNHumanArmorUpOne", "COLON_ARMOR")
local integer catStr = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNGauntletsOfOgrePower", "STRENGTH")
local integer catAgi = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNSlippersOfAgility", "AGILITY")
local integer catInt = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNMantleOfIntelligence", "INTELLECT")
local integer catLife = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNPeriapt", "Life")
local integer catLifeReg = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNRegenerate", "LifeRegeneration")
local integer catMana = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNPendantOfMana", "Mana")
local integer catManaReg = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNSobiMask", "ManaRegeneration")
local integer catOrb = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNOrbOfDarkness", "Orb")
local integer catAura = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNLionHorn", "Aura")
local integer catActive = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNStaffOfSilence", "Active")
local integer catPower = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNControlMagic", "SpellPower")
local integer catCooldown = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNHumanMissileUpOne", "Cooldown")
local integer catAtkSpeed = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNHumanMissileUpOne", "Attackspeed")
local integer catMress = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNRunedBracers", "Magic-Resistence")
local integer catConsum = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNPotionGreenSmall", "ConsumAble")
local integer catMoveSpeed = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNBootsOfSpeed", "COLON_MOVE_SPEED")
local integer catCrit = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNCriticalStrike", "Crit")
local integer catLifeSteal = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNVampiricAura", "Lifesteal")
local integer catEvade = TasItemShopAddCategory("ReplaceableTextures\\CommandButtons\\BTNEvasion", "Evasion")
call TasItemShopAdd5('rst1', 'bgst', 'rin1', 'ciri', 'belv')
call TasItemShopAdd('rag1', catAgi)
call TasItemShopAdd5('rlif', 'ajen', 'clfm', 'ward', 'kpin')
call TasItemShopAdd5('lgdh', 'rde4', 'pmna', 'rhth', 'ssil')
call TasItemShopAdd5('spsh', 'lhst', 'afac', 'sbch', 'brac')
call TasItemShopAdd5('rwiz', 'evtl', 'penr', 'prvt', 'rde3')
call TasItemShopAdd5('hval', 'hcun', 'mcou', 'cnob', 'ckng')
call TasItemShopAdd5('rat6', 'rat9', 'ratf', 'bspd', 'gcel')
call TasItemShopAdd5('rde2', 'clsd', 'dsum', 'stel', 'desc')
call TasItemShopAdd5('modt', 'ofro', 'thdm', 'hlst', 'mnst')
call TasItemShopAdd5('pghe', 'pgma', 'pnvu', 'pres', 'ankh')
call TasItemShopAdd5('shas', 'stwp', 'ofir', 'oli2', 'odef')
call TasItemShopAdd5('oven', 'oslo', 'ocor', 'shtm', 'I001')
call TasItemShopAdd5('klmm', 'crdt', 0, 0, 0)
// setup custom shops
// custom Shops are optional.
// They can have a White or Blacklist of items they can(n't) sell and have a fixed cost modifier for Gold, Lumber aswell as a function for more dynamic things for Gold and Lumber.
set shopObject = 'n000'
// 'n000' can only sell this items (this items don't have to be in the pool of items)
call TasItemShopAddShop5(shopObject, 'hlst', 'mnst', 'pghe', 'pgma', 'pnvu')
call TasItemShopAddShop5(shopObject, 'pres', 'ankh', 'stwp', 'shas', 0)
// enable WhiteListMode
call TasItemShopSetMode(shopObject, true)
// 'n001' can't sell this items (from the default pool of items)
set shopObject = 'n001'
call TasItemShopAddShop5(shopObject, 'hlst', 'mnst', 'pghe', 'pgma', 'pnvu')
call TasItemShopAddShop5(shopObject, 'pres', 'ankh', 'stwp', 'shas', 0)
// enable BlackListMode
call TasItemShopSetMode(shopObject, false)
// create an shopObject for 'ngme', has to pay 20% more than normal, beaware that this can be overwritten by GUI Example
call TasItemShopCreateShop('ngme', false, 1.2, 1.2, function ShopCostFunction_ngme)
//'I002' crown +100 was never added to the database but this shop can craft/sell it.
set shopObject = 'n002'
call TasItemShopAddShop5(shopObject, 'ckng', 'I001', 'I002', 'arsh', 0)
call TasItemShopSetMode(shopObject, true)
// Define skills/Buffs that change the costs in the shop
// cursed Units have to pay +25%
call TasItemShopAddHaggleSkill('Bcrs', 1.25, 1.25, 0, 0)
// define Fusions
// result created by 'xxx', 'xx' , 'x'+.
// item can only be crafted by one way
// can add any amount of material in the Lua version
call TasItemFusionAdd2('bgst', 'rst1', 'rst1')
call TasItemFusionAdd2('ciri', 'rin1', 'rin1')
call TasItemFusionAdd2('belv', 'rag1', 'rag1')
call TasItemFusionAdd2('hval', 'rag1', 'rst1')
call TasItemFusionAdd2('hcun', 'rag1', 'rin1')
call TasItemFusionAdd2('mcou', 'rst1', 'rin1')
call TasItemFusionAdd2('ckng', 'cnob', 'cnob')
call TasItemFusionAdd2('rat9', 'rat6', 'rat6')
call TasItemFusionAdd2('ratf', 'rat9', 'rat9')
call TasItemFusionAdd('rde4', 'rde3')
call TasItemFusionAdd('rde3', 'rde2')
call TasItemFusionAdd('rhth', 'prvt')
call TasItemFusionAdd('pmna', 'penr')
call TasItemFusionAdd2('arsh', 'rde3', 'rde2')
call TasItemFusionAdd('lhst', 'sfog')
// crown of Kings + 50
call TasItemFusionAdd4('I001', 'ckng', 'ckng', 'ckng', 'ckng')
call TasItemFusionAdd4('I001', 'ckng', 'ckng', 'bgst', 'bgst')
call TasItemFusionAdd6('I001', 'ciri', 'ciri', 'belv', 'belv', 'cnob', 'cnob')
// crown of Kings + 100, this is a joke you can not craft it because it was not added to buyAble Items
call TasItemFusionAdd2('I002', 'I001', 'I001')
call TasItemFusionAdd('modt', 'rst1')
call TasItemFusionAdd('ofro', 'rst1')
call TasItemFusionAdd('thdm', 'rst1')
call TasItemFusionAdd('hlst', 'rst1')
call TasItemFusionAdd('mnst', 'rst1')
call TasItemFusionAdd('ocor', 'rst1')
// define item Categories
// uses the locals from earlier.
// An item can have multiple categories just add them together like this: catStr + catAgi + catInt
call TasItemSetCategory('rst1', catStr)
call TasItemSetCategory('bgst', catStr)
call TasItemSetCategory('rin1', catInt)
call TasItemSetCategory('ciri', catInt)
call TasItemSetCategory('rag1', catAgi)
call TasItemSetCategory('belv', catAgi)
call TasItemSetCategory('I001', catStr + catAgi + catInt)
call TasItemSetCategory('ckng', catStr + catAgi + catInt)
call TasItemSetCategory('mcou', catStr + catInt)
call TasItemSetCategory('hval', catStr + catAgi)
call TasItemSetCategory('hcun', catAgi + catInt)
call TasItemSetCategory('cnob', catStr + catAgi + catInt)
call TasItemSetCategory('rat9', catDmg)
call TasItemSetCategory('rat6', catDmg)
call TasItemSetCategory('ratf', catDmg)
call TasItemSetCategory('rlif', catLifeReg)
call TasItemSetCategory('ajen', catAura + catAtkSpeed + catMoveSpeed)
call TasItemSetCategory('clfm', catAura + catDmg)
call TasItemSetCategory('ward', catAura + catDmg)
call TasItemSetCategory('kpin', catAura + catManaReg)
call TasItemSetCategory('lgdh', catAura + catMoveSpeed + catLifeReg)
call TasItemSetCategory('rde4', catArmor)
call TasItemSetCategory('pmna', catMana)
call TasItemSetCategory('rhth', catLife)
call TasItemSetCategory('ssil', catActive)
call TasItemSetCategory('lhst', catAura + catArmor)
call TasItemSetCategory('afac', catAura + catDmg)
call TasItemSetCategory('sbch', catAura + catDmg)
call TasItemSetCategory('sbch', catAura + catLifeSteal)
call TasItemSetCategory('brac', catMress)
call TasItemSetCategory('spsh', catMress + catActive)
call TasItemSetCategory('rwiz', catManaReg)
call TasItemSetCategory('crys', catActive)
call TasItemSetCategory('evtl', catEvade)
call TasItemSetCategory('penr', catMana)
call TasItemSetCategory('prvt', catLife)
call TasItemSetCategory('rde3', catArmor)
call TasItemSetCategory('bspd', catMoveSpeed)
call TasItemSetCategory('gcel', catAtkSpeed)
call TasItemSetCategory('rde2', catArmor)
call TasItemSetCategory('clsd', catActive)
call TasItemSetCategory('dsum', catActive + catMoveSpeed)
call TasItemSetCategory('stel', catActive + catMoveSpeed)
call TasItemSetCategory('desc', catActive + catMoveSpeed)
call TasItemSetCategory('ofro', catDmg + catOrb)
call TasItemSetCategory('modt', catLifeSteal + catOrb)
call TasItemSetCategory('thdm', catActive)
call TasItemSetCategory('hlst', catActive + catConsum + catLifeReg)
call TasItemSetCategory('mnst', catActive + catConsum + catManaReg)
call TasItemSetCategory('pghe', catActive + catConsum)
call TasItemSetCategory('pgma', catActive + catConsum)
call TasItemSetCategory('pnvu', catActive + catConsum)
call TasItemSetCategory('pres', catActive + catConsum)
call TasItemSetCategory('ankh', catConsum)
call TasItemSetCategory('stwp', catActive + catConsum + catMoveSpeed)
call TasItemSetCategory('shas', catActive + catConsum + catMoveSpeed)
call TasItemSetCategory('ofir', catOrb + catDmg)
call TasItemSetCategory('oli2', catOrb + catDmg)
call TasItemSetCategory('odef', catOrb + catDmg)
call TasItemSetCategory('oven', catOrb + catDmg)
call TasItemSetCategory('oslo', catOrb + catDmg)
call TasItemSetCategory('ocor', catOrb + catDmg)
call TasItemSetCategory('shtm', catActive)
endfunction
endlibrary