Name | Type | is_array | initial_value |
Ability | abilcode | No | |
CurrentPage | integer | No | |
Enabled | boolean | No | |
ItemType | itemcode | No | |
PageName | string | No | |
PreviousPage | integer | No | |
Shop | unit | No | |
Shop2 | unit | No | |
UnitType | unitcode | 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 ItemTypeUtils
globals
// Barade: Cache all the values for better performance.
private hashtable h = InitHashtable()
private constant integer SHOP = 'ngme' // Goblin Shop
private constant integer SELL_UNIT = 'Hpal' // Paladin
endglobals
// https://www.hiveworkshop.com/threads/detecting-item-price.120355/
// This is the x position where we create the dummy units. Dont place it in the water.
private function GetShopDummyX takes nothing returns real
return GetRectCenterX(gg_rct_dummy_sell_item)
endfunction
// This is the y position where we create the dummy units. Dont place it in the water.
private function GetShopDummyY takes nothing returns real
return GetRectCenterY(gg_rct_dummy_sell_item)
endfunction
function GetItemValueGoldFresh takes integer i returns integer
local real x = GetShopDummyX()
local real y = GetShopDummyY()
local unit u1 = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),SHOP,x,y,0)
local unit u2 = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),SELL_UNIT,x,y-100,90)
local item a = UnitAddItemByIdSwapped(i,u2)
local integer g1 = GetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_GOLD)
local integer g2 = 0
call UnitDropItemTarget(u2,a,u1)
set g2 = GetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_GOLD) - g1
call SetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_GOLD)-g2)
call RemoveUnit(u1)
call RemoveUnit(u2)
set u1 = null
set u2 = null
set a = null
return g2
endfunction
function GetItemValueGold takes integer i returns integer
if (not HaveSavedInteger(h, i, 0)) then
call SaveInteger(h, i, 0, GetItemValueGoldFresh(i))
endif
return LoadInteger(h, i, 0)
endfunction
function GetItemValueLumberFresh takes integer i returns integer
local real x = GetShopDummyX()
local real y = GetShopDummyY()
local unit u1 = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),SHOP,x,y,0)
local unit u2 = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),SELL_UNIT,x,y-100,90)
local item a = UnitAddItemByIdSwapped(i,u2)
local integer g1 = GetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_LUMBER)
local integer g2 = 0
call UnitDropItemTarget(u2,a,u1)
set g2 = GetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_LUMBER) - g1
call SetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(Player(PLAYER_NEUTRAL_PASSIVE),PLAYER_STATE_RESOURCE_LUMBER)-g2)
call RemoveUnit(u1)
call RemoveUnit(u2)
set u1 = null
set u2 = null
set a = null
return g2
endfunction
function GetItemValueLumber takes integer i returns integer
if (not HaveSavedInteger(h, i, 1)) then
call SaveInteger(h, i, 1, GetItemValueLumberFresh(i))
endif
return LoadInteger(h, i, 1)
endfunction
function GetItemTypePerishableFresh takes integer i returns boolean
local item tmpItem = CreateItem(i, 0.0, 0.0)
local boolean result = BlzGetItemBooleanField(tmpItem, ITEM_BF_PERISHABLE)
call RemoveItem(tmpItem)
set tmpItem = null
return result
endfunction
function GetItemTypePerishable takes integer i returns boolean
if (not HaveSavedBoolean(h, i, 2)) then
call SaveBoolean(h, i, 2, GetItemTypePerishableFresh(i))
endif
return LoadBoolean(h, i, 2)
endfunction
function GetItemTypeModelFresh takes integer i returns string
local item tmpItem = CreateItem(i, 0.0, 0.0)
local string result = BlzGetItemStringField(tmpItem, ITEM_SF_MODEL_USED)
call RemoveItem(tmpItem)
set tmpItem = null
return result
endfunction
function GetItemTypeModel takes integer i returns string
if (not HaveSavedBoolean(h, i, 3)) then
call SaveStr(h, i, 3, GetItemTypeModelFresh(i))
endif
return LoadStr(h, i, 3)
endfunction
endlibrary
library PagedButtons initializer Init requires optional PagedButtonsConfig
/*
Baradé's Paged Buttons System 1.4
Allows using multiple pages of command buttons in shops for unit and items which can be purchased.
Changing the pages is also done by purchasing units to change to the next or previous page.
This helps to reduce the number of shop buildings while providing a huge number of units and items to be purchased.
The page is shown for all players together in multiplayer.
Download: https://www.hiveworkshop.com/threads/barad%C3%A9s-paged-buttons-system-1-2.348173/
Usage:
call EnablePagedButtons(shop)
call NextPagedButtonsPage(shop, "Page 1")
call AddPagedButtonsUnitType(shop, 'nrdr')
call AddPagedButtonsItemType(shop, 'stwp')
call NextPagedButtonsPage(shop, "Page 2")
call AddPagedButtonsUnitType(shop, 'nrwm')
call AddPagedButtonsItemType(shop, 'dust')
###################################################################################################
API:
###################################################################################################
function GetPagedButtonsShop takes unit shop returns Shop
###################################################################################################
function SetPagedButtonsShop takes unit shop, Shop s returns nothing
###################################################################################################
function GetPagedButtonsCount takes unit shop returns integer
Returns the number of paged buttons for the given shop.
###################################################################################################
function GetPagedButtonsNonSpaceButtonsCount takes unit shop returns integer
Returns the number of paged buttons which are not spaces for the given shop.
###################################################################################################
function GetPagedButton takes unit shop, integer index returns Type
Returns the page button data for the given shop at the given index.
###################################################################################################
function GetPagedButtonIndex takes unit shop, integer id returns integer
Returns the page button index for the given shop at the given ID.
Returns -1 if it does not exist.
###################################################################################################
function GetPagedButtonIndexEx takes unit shop, integer id, integer index returns integer
Returns the page button index for the given shop at the given ID with the given index.
This can be useful if the ID exists multiple times.
Returns -1 if it does not exist.
###################################################################################################
function GetPagedButtonsCountEx takes unit shop, integer id returns integer
Returns the number of paged buttons with the given ID for the given shop.
Returns 0 if the given ID is not part of the given shop.
###################################################################################################
function IsPagedButtonShown takes unit shop, integer index returns boolean
###################################################################################################
function IsPagedButtonEnabled takes unit shop, integer index returns boolean
Returns true if the button is enabled which means it is shown when its page is shown.
Otherwise, it returns false which means that the button won't be shown when its page is shown.
###################################################################################################
function SetPagedButtonEnabled takes unit shop, integer index, boolean enabled returns nothing
###################################################################################################
function GetPagedButtonId takes unit shop, integer index returns integer
###################################################################################################
function IsPagedButtonUnit takes unit shop, integer index returns boolean
Returns true if the paged button is a unit type. Otherwise, it returns false.
###################################################################################################
function IsPagedButtonItem takes unit shop, integer index returns boolean
Returns true if the paged button is an item type. Otherwise, it returns false.
###################################################################################################
function IsPagedButtonAbility takes unit shop, integer index returns boolean
Returns true if the paged button is an ability. Otherwise, it returns false.
###################################################################################################
function IsPagedButtonSpacer takes unit shop, integer index returns boolean
Returns true if the paged button is a spacer. Otherwise, it returns false.
###################################################################################################
function GetPagedButtonType takes unit shop, integer id returns Type
###################################################################################################
function RemovePagedButtonsIndex takes unit shop, integer index returns boolean
Removes the button for the given index from the given shop.
Returns true, if it has been removed successfully.
Otherwise, for example if the index was not part of the given shop, it returns false.
###################################################################################################
function RemovePagedButtonsId takes unit shop, integer id returns boolean
Removes the button for the given ID from the given shop.
Returns true, if it has been removed successfully.
Otherwise, for example if the ID was not part of the given shop, it returns false.
###################################################################################################
function HasPagedButtonsId takes unit shop, integer id returns boolean
###################################################################################################
function IsPagedButtonsIdUnit takes unit shop, integer id returns boolean
###################################################################################################
function GetPagedButtonsPageByIndex takes unit shop, integer index returns integer
Returns the matching page for the given button index of the given shop.
It depends on the slots per page for the given shop.
###################################################################################################
function GetPagedButtonsSlotsPerPage takes unit shop returns integer
###################################################################################################
function GetPagedButtonsPage takes unit shop returns integer
Returns the current page of the given shop. It starts with page 0 by default.
###################################################################################################
function GetPagedButtonsMaxPages takes unit shop returns integer
Returns the maximum number pages for the given shop. Adding more buttons might increase this number.
###################################################################################################
function GetPagedButtonsShopPage takes unit shop, integer page returns Page
Returns the page data object for the given shop and given page index.
Returns 0 if it does not exist.
###################################################################################################
function GetPagedButtonsPageName takes unit shop, integer page returns string
Returns the name of the given page of the given shop. The name has to be specified by the user.
###################################################################################################
function SetPagedButtonsPageName takes unit shop, integer page, string name returns nothing
Sets the name for the given page of the given shop.
The name will be shown in the shop's unit's name by default to identify the currently shown page.
###################################################################################################
function SetPagedButtonsCurrentPageName takes unit shop, string name returns nothing
Sets the name for the current page of the given shop.
The name will be shown in the shop's unit's name by default to identify the currently shown page.
###################################################################################################
function SetPagedButtonsPage takes unit shop, integer page returns nothing
Changes the given shop's current page to the given page if possible.
###################################################################################################
function SetPagedButtonsSlotsPerPage takes unit shop, integer slots returns nothing
###################################################################################################
function AddPagedButtonsId takes unit shop, integer id, integer whichType returns integer
Adds a paged button to the given shop with the given ID of the given type and returns its index.
The parameter whichType can have the following values:
PagedButtons_BUTTON_TYPE_UNIT
PagedButtons_BUTTON_TYPE_ITEM
PagedButtons_BUTTON_TYPE_ABILITY
PagedButtons_BUTTON_TYPE_SPACER
For the spacer tyoe the given ID has no effect.
###################################################################################################
function AddPagedButtonsUnitType takes unit shop, integer id returns integer
Adds a unit of the type with the given id to the given shop which can be purchased from the shop.
Returns the index of the added button for the given shop.
###################################################################################################
function AddPagedButtonsItemType takes unit shop, integer id returns integer
Adds an item of the type with the given id to the given shop which can be purchased from the shop.
Returns the index of the added button for the given shop.
###################################################################################################
function AddPagedButtonsAbility takes unit shop, integer id returns integer
Adds an ability of the type with the given id to the given shop which can be used from the shop.
Returns the index of the added button for the given shop.
###################################################################################################
function AddPagedButtonsSpacer takes unit shop returns integer
Adds a spacer button to the given shop.
Spacer buttons are just empty and have only the functionality to indicate different pages.
###################################################################################################
function AddPagedButtonsSpacers takes unit shop, integer counter returns nothing
Adds n spacer buttons to the given shop where n is equal to the given counter.
###################################################################################################
function AddPagedButtonsSpacersRemaining takes unit shop returns nothing
Adds spacers for all remaining empty slots on the current page.
###################################################################################################
function NextPagedButtonsPage takes takes unit shop, string name returns integer
Starts the next page if there is already a name for the current page or set the name for the current
page. Returns the started page number starting with 0.
###################################################################################################
function HasPagedButtons takes unit shop returns boolean
###################################################################################################
function EnablePagedButtons takes unit shop returns boolean
###################################################################################################
function DisablePagedButtons takes unit shop returns boolean
###################################################################################################
function ChangePagedButtonsToNextPage takes unit shop returns nothing
###################################################################################################
function ChangePagedButtonsToPreviousPage takes unit shop returns nothing
###################################################################################################
function GetTriggerShop takes nothing returns unit
Returns the shop which the page was changed for.
###################################################################################################
function GetTriggerPreviousPage takes nothing returns integer
Returns the previous page of the shop before changing its page.
###################################################################################################
function TriggerRegisterChangePagedButtons takes trigger whichTrigger returns nothing
Registers the event of changing the page of a paged button shop.
The trigger wil be conditionally evaluated and executed whenever any shop changes its page.
Use the GetTriggerXXX functions to retrieve event data.
The trigger is only evaluated and executed if it is enabled.
###################################################################################################
function GetTriggerAvailableObject takes nothing returns integer
Returns the unit type or item type ID of the available object in the shop.
###################################################################################################
function TriggerRegisterObjectAvailable takes trigger whichTrigger returns nothing
Registers the event of an object becoming available in a shop after its stock delay.
The trigger will be conditionally evaluated and executed whenever any stock in any paged buttons
shop is refilled.
Use the GetTriggerXXX functions to retrieve event data.
The trigger is only evaluated and executed if it is enabled.
###################################################################################################
*/
globals
public constant integer NEXT_PAGE_ID = 'h001'
public constant integer PREVIOUS_PAGE_ID = 'h000'
public constant integer SLOTS_PER_PAGE = 9
public constant integer ABILITY_ID_SELL_UNITS = 'Asud'
public constant integer ABILITY_ID_SELL_ITEMS = 'Asid'
// The shops will be disabled automatically when a shop unit dies.
public constant boolean DISABLE_SHOPS_ON_DEATH = true
public constant boolean CHANGE_PAGE_UNIT_NAME = true
public constant boolean SHOW_PAGE_MESSAGE = false
public constant boolean HIDE_PAGE_BUTTONS_FOR_ONE_PAGE = true
public constant boolean SHOW_PAGE_NUMBER_IN_PAGE_BUTTONS = true
// Shows the number of the next and previous pages in the page buttons. Otherwise, it will show the current page number.
public constant boolean SHOW_NEXT_AND_PREVIOUS_PAGE_NUMBER = false
/*
Set this to true to fake the stock intervals which have been configured in PagedButtonsConfig.
Note that this cannot be exact and therefore double refills shortly after each other are possible
when this system refills a stock shortly after the game does.
*/
public constant boolean AUTO_UPDATE_STOCKS = true
// Define this as true to prevent items from being removed completely from non-marketplace shops.
public constant boolean ENABLE_FAKE_MARKETPLACE_ITEM_REMOVAL = true
public constant boolean HOOK_REMOVE_UNIT = true
// This delay hreshold is required to avoid wrong item or unit types being removed due to still refilling stocks.
public constant integer STOCK_DELAY_THRESHOLD = 1
public constant integer BUTTON_TYPE_UNIT = 0
public constant integer BUTTON_TYPE_ITEM = 1
public constant integer BUTTON_TYPE_ABILITY = 2
public constant integer BUTTON_TYPE_SPACER = 3
private constant integer KEY_NAME = 3
private constant integer KEY_COUNTER = 4
private constant integer KEY_TYPE = 5
private constant integer KEY_PAGE_NAME = 1000
private constant integer KEY_SHOP = 5000
private hashtable h = InitHashtable()
private group shops = CreateGroup()
private trigger deathTrigger = null
private trigger sellUnitTrigger = CreateTrigger()
private trigger sellItemTrigger = CreateTrigger()
private timer autoUpdateStockTimer = CreateTimer()
// callbacks
private trigger array callbackTriggersChangePageButtons
private integer callbackTriggersChangePageButtonsCounter = 0
private trigger array callbackTriggersObjectAvailable
private integer callbackTriggersObjectAvailableCounter = 0
private unit triggerShop = null
private integer triggerPreviousPage = 0
private integer triggerAvailableObject = 0
endglobals
function GetTriggerShop takes nothing returns unit
return triggerShop
endfunction
function GetTriggerPreviousPage takes nothing returns integer
return triggerPreviousPage
endfunction
function GetTriggerAvailableObject takes nothing returns integer
return triggerAvailableObject
endfunction
function TriggerRegisterChangePagedButtons takes trigger whichTrigger returns nothing
set callbackTriggersChangePageButtons[callbackTriggersChangePageButtonsCounter] = whichTrigger
set callbackTriggersChangePageButtonsCounter = callbackTriggersChangePageButtonsCounter + 1
endfunction
function TriggerRegisterObjectAvailable takes trigger whichTrigger returns nothing
set callbackTriggersObjectAvailable[callbackTriggersObjectAvailableCounter] = whichTrigger
set callbackTriggersObjectAvailableCounter = callbackTriggersObjectAvailableCounter + 1
endfunction
private function ExecuteChangedPageButtonsCallbacks takes unit shop, integer previousPage returns nothing
local integer i = 0
set triggerShop = shop
set triggerPreviousPage = previousPage
set i = 0
loop
exitwhen (i == callbackTriggersChangePageButtonsCounter)
if (IsTriggerEnabled(callbackTriggersChangePageButtons[i])) then
call ConditionalTriggerExecute(callbackTriggersChangePageButtons[i])
endif
set i = i + 1
endloop
endfunction
private function ExecuteObjectAvailableCallbacks takes unit shop, integer objectId returns nothing
local integer i = 0
set triggerShop = shop
set triggerAvailableObject = objectId
set i = 0
loop
exitwhen (i == callbackTriggersObjectAvailableCounter)
if (IsTriggerEnabled(callbackTriggersObjectAvailable[i])) then
call ConditionalTriggerExecute(callbackTriggersObjectAvailable[i])
endif
set i = i + 1
endloop
endfunction
public struct Type
boolean shown = false
boolean enabled = true
integer whichType
public method isSpacer takes nothing returns boolean
return whichType == BUTTON_TYPE_SPACER
endmethod
endstruct
// Use a separate type for spacers to save memory.
public struct SpacerType extends Type
public static method create takes nothing returns thistype
local thistype this = thistype.allocate()
set this.whichType = BUTTON_TYPE_SPACER
return this
endmethod
public stub method onDestroy takes nothing returns nothing
endmethod
endstruct
public struct SlotType extends Type
unit shop
integer id
integer startStock
integer maxStock
integer currentStock
integer startDelay
integer replenishInterval
integer elapsedTimeStartDelay
integer elapsedTimeReplenishInterval
boolean startDelayDone = false
private static thistype array list
private static integer listCounter = 0
public static method create takes unit shop, integer id, integer whichType, integer currentStock, integer startStock, integer maxStock, integer startDelay, integer replenishInterval returns thistype
local thistype this = thistype.allocate()
set this.shop = shop
set this.id = id
set this.whichType = whichType
set this.currentStock = currentStock
set this.startStock = startStock
set this.maxStock = maxStock
set this.startDelay = startDelay
set this.replenishInterval = replenishInterval
set this.elapsedTimeStartDelay = 0
set this.elapsedTimeReplenishInterval = 0
set list[listCounter] = this
set listCounter = listCounter + 1
return this
endmethod
public method onDestroy takes nothing returns nothing
local boolean found = false
local integer i = 0
loop
exitwhen (i >= thistype.listCounter)
if (thistype.list[i] == this) then
set found = true
endif
if (found) then
set thistype.list[i] = thistype.list[i + 1]
set thistype.list[i + 1] = 0
endif
set i = i + 1
endloop
if (found) then
set thistype.listCounter = thistype.listCounter - 1
endif
endmethod
public static method timerFunctionUpdateTime takes nothing returns nothing
local boolean updated = false
local integer elapsedSeconds = 1
local integer i = 0
local thistype this = 0
loop
exitwhen (i >= thistype.listCounter)
set this = thistype.list[i]
set updated = false
if (not startDelayDone) then
set this.elapsedTimeStartDelay = this.elapsedTimeStartDelay + elapsedSeconds
if (this.elapsedTimeStartDelay >= this.startDelay) then
if (this.currentStock < this.maxStock) then
set this.currentStock = this.currentStock + 1
set updated = true
endif
set this.elapsedTimeStartDelay = 0
set this.startDelayDone = true
endif
endif
if (this.currentStock < this.maxStock) then
set this.elapsedTimeReplenishInterval = this.elapsedTimeReplenishInterval + elapsedSeconds
//if (this.id == BOOTS_OF_SPEED) then
// call BJDebugMsg("Elapsed seconds for " + GetObjectName(this.id) + " - " + I2S(elapsedSeconds) + " resulting in total elapsed: " + I2S(this.elapsedTimeReplenishInterval))
//endif
if (this.elapsedTimeReplenishInterval >= this.replenishInterval) then
if (this.currentStock < this.maxStock) then
set this.currentStock = this.currentStock + 1
set updated = true
endif
set this.elapsedTimeReplenishInterval = 0
endif
endif
if (updated) then
if (this.shown and this.enabled) then
if (this.whichType == BUTTON_TYPE_UNIT) then
// TODO Removes different unit when the stock is still in delay.
call AddUnitToStock(this.shop, this.id, this.currentStock, this.maxStock)
elseif (this.whichType == BUTTON_TYPE_ITEM) then
// TODO Removes different item when the stock is still in delay.
//call BJDebugMsg("Making item available again: " + GetObjectName(this.id))
call AddItemToStock(this.shop, this.id, this.currentStock, this.maxStock)
else
// Do nothing for abilities.
endif
endif
call ExecuteObjectAvailableCallbacks(this.shop, this.id)
endif
set i = i + 1
endloop
endmethod
endstruct
public struct Page
string name
endstruct
public struct Shop
integer slotsPerPage = SLOTS_PER_PAGE
integer currentPage = 0
string name
integer whichType
Type array buttons[1000]
integer buttonsCount = 0
Page array pages[500]
integer maxPages = 0
public method removeButton takes integer index returns nothing
loop
exitwhen (index >= this.buttonsCount)
set this.buttons[index] = this.buttons[index + 1]
set this.buttons[index + 1] = 0
set index = index + 1
endloop
set this.buttonsCount = this.buttonsCount - 1
endmethod
public static method create takes string name returns thistype
local thistype this = thistype.allocate()
set this.name = name
return this
endmethod
endstruct
function GetPagedButtonsShop takes unit shop returns Shop
return LoadInteger(h, GetHandleId(shop), KEY_SHOP)
endfunction
function SetPagedButtonsShop takes unit shop, Shop s returns nothing
call SaveInteger(h, GetHandleId(shop), KEY_SHOP, s)
endfunction
function GetPagedButtonsCount takes unit shop returns integer
local Shop s = GetPagedButtonsShop(shop)
if (s != 0) then
return s.buttonsCount
endif
return 0
endfunction
function GetPagedButtonsNonSpacerButtonsCount takes unit shop returns integer
local Shop x = GetPagedButtonsShop(shop)
local integer result = 0
local Type t = 0
local integer i = 0
loop
exitwhen (i >= x.buttonsCount)
set t = x.buttons[i]
if (not t.isSpacer()) then
set result = result + 1
endif
set i = i + 1
endloop
return result
endfunction
function GetPagedButton takes unit shop, integer index returns Type
local Shop x = GetPagedButtonsShop(shop)
return x.buttons[index]
endfunction
function GetPagedButtonIndex takes unit shop, integer id returns integer
local Shop x = GetPagedButtonsShop(shop)
local Type t = 0
local SlotType s = 0
local integer i = 0
loop
exitwhen (i >= x.buttonsCount)
set t = x.buttons[i]
if (not t.isSpacer()) then
set s = SlotType(t)
if (s.id == id) then
return i
endif
endif
set i = i + 1
endloop
return -1
endfunction
function GetPagedButtonIndexEx takes unit shop, integer id, integer index returns integer
local Shop x = GetPagedButtonsShop(shop)
local Type t = 0
local SlotType s = 0
local integer i = 0
local integer currentIndex = 0
loop
exitwhen (i >= x.buttonsCount)
set t = x.buttons[i]
if (not t.isSpacer()) then
set s = SlotType(t)
if (s.id == id) then
if (currentIndex == index) then
return i
endif
set currentIndex = currentIndex + 1
endif
endif
set i = i + 1
endloop
return -1
endfunction
function GetPagedButtonsCountEx takes unit shop, integer id returns integer
local Shop x = GetPagedButtonsShop(shop)
local Type t = 0
local SlotType s = 0
local integer i = 0
local integer count = 0
loop
exitwhen (i >= x.buttonsCount)
set t = x.buttons[i]
if (not t.isSpacer()) then
set s = SlotType(t)
if (s.id == id) then
set count = count + 1
endif
endif
set i = i + 1
endloop
return count
endfunction
function IsPagedButtonShown takes unit shop, integer index returns boolean
return GetPagedButton(shop, index).shown
endfunction
function IsPagedButtonEnabled takes unit shop, integer index returns boolean
return GetPagedButton(shop, index).enabled
endfunction
function GetPagedButtonId takes unit shop, integer index returns integer
if (GetPagedButton(shop, index) == 0) then
return 0
endif
return SlotType(GetPagedButton(shop, index)).id
endfunction
function IsPagedButtonUnit takes unit shop, integer index returns boolean
return GetPagedButton(shop, index).whichType == BUTTON_TYPE_UNIT
endfunction
function IsPagedButtonItem takes unit shop, integer index returns boolean
return GetPagedButton(shop, index).whichType == BUTTON_TYPE_ITEM
endfunction
function IsPagedButtonAbility takes unit shop, integer index returns boolean
return GetPagedButton(shop, index).whichType == BUTTON_TYPE_ABILITY
endfunction
function IsPagedButtonSpacer takes unit shop, integer index returns boolean
return GetPagedButton(shop, index).whichType == BUTTON_TYPE_SPACER
endfunction
function GetPagedButtonType takes unit shop, integer id returns SlotType
local Shop x = GetPagedButtonsShop(shop)
local Type result = 0
local Type t = 0
local SlotType s = 0
local integer i = 0
loop
exitwhen (i >= x.buttonsCount or result != 0)
set t = x.buttons[i]
if (not t.isSpacer()) then
set s = SlotType(t)
if (s.id == id) then
set result = t
endif
endif
set i = i + 1
endloop
return result
endfunction
function HasPagedButtonsId takes unit shop, integer id returns boolean
return GetPagedButtonType(shop, id) != 0
endfunction
function IsPagedButtonsIdUnit takes unit shop, integer id returns boolean
local SlotType s = GetPagedButtonType(shop, id)
if (s != 0) then
return s.whichType == BUTTON_TYPE_UNIT
endif
return false
endfunction
function GetPagedButtonsSlotsPerPage takes unit shop returns integer
local Shop s = GetPagedButtonsShop(shop)
if (s != 0) then
return s.slotsPerPage
endif
return 0
endfunction
function GetPagedButtonsPage takes unit shop returns integer
local Shop s = GetPagedButtonsShop(shop)
if (s != 0) then
return s.currentPage
endif
return 0
endfunction
function GetPagedButtonsMaxPages takes unit shop returns integer
local Shop s = GetPagedButtonsShop(shop)
if (s != 0) then
return s.maxPages
endif
return 0
endfunction
function GetPagedButtonsShopPage takes unit shop, integer page returns Page
local Shop s = GetPagedButtonsShop(shop)
if (s != 0 and page >= 0 and page < s.maxPages) then
return s.pages[page]
endif
return 0
endfunction
private function PrintPages takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local Page p = 0
local integer i = 0
if (s != 0) then
//call BJDebugMsg("Pages count: " + I2S(s.maxPages))
loop
exitwhen (i >= s.maxPages)
set p = s.pages[i]
//call BJDebugMsg("Page name: " + p.name)
set i = i + 1
endloop
endif
endfunction
function GetPagedButtonsPageName takes unit shop, integer page returns string
local Page p = GetPagedButtonsShopPage(shop, page)
if (p != 0) then
//call BJDebugMsg("Shop " + GetUnitName(shop) + " page name of page " + I2S(page) + ": " + p.name)
return p.name
endif
//call BJDebugMsg("Shop " + GetUnitName(shop) + " page name of page " + I2S(page) + " is not set.")
return null
endfunction
function SetPagedButtonsPageName takes unit shop, integer page, string name returns nothing
local Page p = GetPagedButtonsShopPage(shop, page)
if (p != 0) then
set p.name = name
endif
//call PrintPages(shop)
endfunction
function SetPagedButtonsCurrentPageName takes unit shop, string name returns nothing
call SetPagedButtonsPageName(shop, GetPagedButtonsPage(shop), name)
endfunction
private function ChangeShopUnitName takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer currentPage = GetPagedButtonsPage(shop)
local string pageName = GetPagedButtonsPageName(shop, s.currentPage)
local string unitName = s.name
//call BJDebugMsg("Change shop unit name to page " + I2S(s.currentPage) + ": " + pageName)
if (unitName == null) then
set unitName = ""
endif
if (pageName != null) then
if (StringLength(unitName) > 0 and unitName != " ") then
call BlzSetUnitName(shop, unitName + " " + pageName)
else
call BlzSetUnitName(shop, pageName)
endif
else
call BlzSetUnitName(shop, unitName)
endif
endfunction
private function ResetShopUnitName takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local string unitName = s.name
if (unitName == null) then
set unitName = ""
endif
call BlzSetUnitName(shop, unitName)
endfunction
private function HidePagedButtonsCurrentPage takes unit shop returns nothing
local Shop x = GetPagedButtonsShop(shop)
local integer maxPages = x.maxPages
local integer totalCounter = x.buttonsCount
local integer countUnits = 0
local integer countItems = 0
local integer slotsPerPage = x.slotsPerPage
local integer currentPage = x.currentPage
local integer i = currentPage * slotsPerPage
local integer count = i + IMinBJ(slotsPerPage, totalCounter - currentPage * slotsPerPage)
local Type t = GetPagedButton(shop, i)
local SlotType s = 0
loop
exitwhen (i >= count)
set t = x.buttons[i]
if (not t.isSpacer() and t.enabled) then
set s = SlotType(t)
if (s.whichType == BUTTON_TYPE_UNIT) then
call RemoveUnitFromStock(shop, s.id)
elseif (s.whichType == BUTTON_TYPE_ITEM) then
call RemoveItemFromStock(shop, s.id)
else
call UnitRemoveAbility(shop, s.id)
endif
endif
set t.shown = false
set i = i + 1
endloop
call SetUnitTypeSlots(shop, 0)
call SetItemTypeSlots(shop, 0)
endfunction
private function ShowPagedButtonsCurrentPage takes unit shop returns nothing
local Shop x = GetPagedButtonsShop(shop)
local integer maxPages = x.maxPages
local integer currentPage = x.currentPage
local integer totalCounter = x.buttonsCount
local integer countUnits = 0
local integer countItems = 0
local integer nextPage = 0
local integer previousPage = 0
local integer slotsPerPage = GetPagedButtonsSlotsPerPage(shop)
local integer i = currentPage * slotsPerPage
local integer count = i + IMinBJ(slotsPerPage, totalCounter - currentPage * slotsPerPage)
local Type t = GetPagedButton(shop, i)
local SlotType s = 0
if (not HIDE_PAGE_BUTTONS_FOR_ONE_PAGE or maxPages > 1) then
call SetUnitTypeSlots(shop, 2)
static if (not SHOW_PAGE_NUMBER_IN_PAGE_BUTTONS) then
call AddUnitToStock(shop, NEXT_PAGE_ID, 1, 1)
call AddUnitToStock(shop, PREVIOUS_PAGE_ID, 1, 1)
else
static if (SHOW_PAGE_NUMBER_IN_PAGE_BUTTONS and SHOW_NEXT_AND_PREVIOUS_PAGE_NUMBER) then
if (currentPage == maxPages - 1) then
set nextPage = 1
else
set nextPage = currentPage + 2
endif
if (currentPage == 0) then
set previousPage = maxPages
else
set previousPage = currentPage
endif
else
set nextPage = currentPage + 1
set previousPage = currentPage + 1
endif
call AddUnitToStock(shop, NEXT_PAGE_ID, nextPage, nextPage)
call AddUnitToStock(shop, PREVIOUS_PAGE_ID, previousPage, previousPage)
endif
else
call RemoveUnitFromStock(shop, NEXT_PAGE_ID)
call RemoveUnitFromStock(shop, PREVIOUS_PAGE_ID)
call SetUnitTypeSlots(shop, 0)
endif
if (not HIDE_PAGE_BUTTONS_FOR_ONE_PAGE or maxPages > 1) then
set countUnits = 2
endif
//call BJDebugMsg("Showing page " + I2S(currentPage) + " with buttons " + I2S(count - i) + " starting at index " + I2S(i) + " and ending at index " + I2S(count) + " and starting with button instance " + I2S(t) + " with max pages " + I2S(maxPages))
loop
exitwhen (i >= count)
set t = x.buttons[i]
//call BJDebugMsg("Checking instance " + I2S(t))
if (not t.isSpacer() and t.enabled) then
set s = SlotType(t)
//call BJDebugMsg("Adding " + GetObjectName(s.id))
if (s.whichType == BUTTON_TYPE_UNIT) then
set countUnits = countUnits + 1
call SetUnitTypeSlots(shop, countUnits)
call AddUnitToStock(shop, s.id, s.currentStock, s.maxStock)
elseif (s.whichType == BUTTON_TYPE_ITEM) then
set countItems = countItems + 1
call SetItemTypeSlots(shop, countItems)
call AddItemToStock(shop, s.id, s.currentStock, s.maxStock)
else
call UnitAddAbility(shop, s.id)
endif
else
//call BJDebugMsg("Not enabled or spacer.")
endif
set t.shown = true
set i = i + 1
endloop
static if (CHANGE_PAGE_UNIT_NAME) then
call ChangeShopUnitName(shop)
endif
// show the page buttons afterwards to make sure that they have a higher priority than the unit buttons
if (not HIDE_PAGE_BUTTONS_FOR_ONE_PAGE or maxPages > 1) then
static if (not SHOW_PAGE_NUMBER_IN_PAGE_BUTTONS) then
call AddUnitToStock(shop, NEXT_PAGE_ID, 1, 1)
call AddUnitToStock(shop, PREVIOUS_PAGE_ID, 1, 1)
else
call AddUnitToStock(shop, NEXT_PAGE_ID, nextPage, nextPage)
call AddUnitToStock(shop, PREVIOUS_PAGE_ID, previousPage, previousPage)
endif
endif
endfunction
function SetPagedButtonsPage takes unit shop, integer page returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer currentPage = s.currentPage
call HidePagedButtonsCurrentPage(shop)
set s.currentPage = page
call ShowPagedButtonsCurrentPage(shop)
static if (CHANGE_PAGE_UNIT_NAME) then
call ChangeShopUnitName(shop)
endif
call ExecuteChangedPageButtonsCallbacks(shop, currentPage)
endfunction
function SetPagedButtonEnabled takes unit shop, integer index, boolean enabled returns nothing
set GetPagedButton(shop, index).enabled = enabled
// refresh
call SetPagedButtonsPage(shop, GetPagedButtonsPage(shop))
endfunction
private function RefreshMaxPagesEx takes unit shop, integer maxPages returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer oldMaxPages = s.maxPages
local integer i = 0
set s.maxPages = maxPages
// create all missing pages instances
if (maxPages > oldMaxPages) then
set i = oldMaxPages
loop
exitwhen (i >= maxPages)
if (s.pages[i] == 0) then
set s.pages[i] = Page.create()
if (i > 0) then
set s.pages[i].name = s.pages[i - 1].name // copy the previous page name
endif
endif
set i = i + 1
endloop
// remove too many pages instances
elseif (maxPages < oldMaxPages) then
set i = oldMaxPages
loop
exitwhen (i < maxPages)
if (s.pages[i] == 0) then
set s.pages[i] = 0
call s.pages[i].destroy()
endif
set i = i - 1
endloop
endif
endfunction
private function RefreshMaxPages takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer count = s.buttonsCount
local integer slots = s.slotsPerPage
local integer maxPages = count / slots
if (ModuloInteger(count, slots) > 0) then
set maxPages = maxPages + 1
endif
set maxPages = IMaxBJ(maxPages, 1)
call RefreshMaxPagesEx(shop, maxPages)
endfunction
function RemovePagedButtonsIndex takes unit shop, integer index returns boolean
local Shop s = GetPagedButtonsShop(shop)
local Type t = 0
if (s != 0 and index >= 0 and index <= s.buttonsCount) then
set t = s.buttons[index]
if (t.shown) then
if (t.whichType == BUTTON_TYPE_UNIT) then
call RemoveUnitFromStock(shop, SlotType(t).id)
elseif (t.whichType == BUTTON_TYPE_ITEM) then
call RemoveItemFromStock(shop, SlotType(t).id)
elseif (t.whichType == BUTTON_TYPE_ITEM) then
call UnitRemoveAbility(shop, SlotType(t).id)
endif
endif
call s.removeButton(index)
call t.destroy()
// update buttons
call RefreshMaxPages(shop)
call SetPagedButtonsPage(shop, IMaxBJ(0, IMinBJ(GetPagedButtonsPage(shop), s.maxPages - 1)))
return true
endif
return false
endfunction
function RemovePagedButtonsId takes unit shop, integer id returns boolean
local integer index = GetPagedButtonIndex(shop, id)
if (index != -1) then
return RemovePagedButtonsIndex(shop, index)
endif
return false
endfunction
function SetPagedButtonsSlotsPerPage takes unit shop, integer slots returns nothing
local Shop s = GetPagedButtonsShop(shop)
set s.slotsPerPage = slots
call RefreshMaxPages(shop)
call SetPagedButtonsPage(shop, GetPagedButtonsPage(shop))
endfunction
private function AddPageButtonsIdType takes unit shop, integer id, integer whichType returns Type
local integer startStock = 1
local integer currentStock = 1
local integer maxStock = 1
local integer startDelay = 0
local integer replenishInterval = 30
static if (LIBRARY_PagedButtonsConfig) then
set startStock = PagedButtonsConfig_GetStockInitialAfterStartDelay(id)
set maxStock = PagedButtonsConfig_GetStockMaximum(id)
set startDelay = PagedButtonsConfig_GetStockStartDelay(id)
if (startDelay > 0) then
set startDelay = startDelay + STOCK_DELAY_THRESHOLD
endif
set replenishInterval = PagedButtonsConfig_GetStockReplenishInterval(id)
if (replenishInterval > 0) then
set replenishInterval = replenishInterval + STOCK_DELAY_THRESHOLD
endif
if (startDelay > 0) then
set currentStock = 0
endif
endif
return SlotType.create(shop, id, whichType, currentStock, startStock, maxStock, startDelay, replenishInterval)
endfunction
function AddPagedButtonsId takes unit shop, integer id, integer whichType returns integer
local Shop s = GetPagedButtonsShop(shop)
local Type t = 0
local integer index = 0
if (s == 0) then
return -1
endif
set index = s.buttonsCount
if (whichType == BUTTON_TYPE_SPACER) then
set t = SpacerType.create()
else
set t = AddPageButtonsIdType(shop, id, whichType)
endif
set s.buttons[index] = t
set s.buttonsCount = index + 1
call RefreshMaxPages(shop)
call SetPagedButtonsPage(shop, GetPagedButtonsPage(shop))
//call BJDebugMsg("Added ID " + GetObjectName(id) + " to shop " + GetUnitName(shop) + " resulting in " + I2S(s.buttons.getSize()) + " buttons and " + I2S(s.maxPages) + " max pages.")
return index
endfunction
function AddPagedButtonsUnitType takes unit shop, integer id returns integer
return AddPagedButtonsId(shop, id, BUTTON_TYPE_UNIT)
endfunction
function AddPagedButtonsItemType takes unit shop, integer id returns integer
return AddPagedButtonsId(shop, id, BUTTON_TYPE_ITEM)
endfunction
function AddPagedButtonsAbility takes unit shop, integer id returns integer
return AddPagedButtonsId(shop, id, BUTTON_TYPE_ABILITY)
endfunction
function AddPagedButtonsSpacer takes unit shop returns integer
return AddPagedButtonsId(shop, 0, BUTTON_TYPE_SPACER)
endfunction
function AddPagedButtonsSpacers takes unit shop, integer counter returns nothing
local integer i = 0
loop
exitwhen (i == counter)
call AddPagedButtonsSpacer(shop)
set i = i + 1
endloop
endfunction
function GetPagedButtonsPageByIndex takes unit shop, integer index returns integer
local Shop s = GetPagedButtonsShop(shop)
if (s != 0) then
return index / s.slotsPerPage
endif
return 0
endfunction
function AddPagedButtonsSpacersRemaining takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer mod = 0
if (s != 0) then
set mod = ModuloInteger(s.buttonsCount, s.slotsPerPage)
if (mod > 0) then
call AddPagedButtonsSpacers(shop, s.slotsPerPage - mod)
endif
endif
endfunction
function NextPagedButtonsPage takes unit shop, string name returns integer
local Shop s = GetPagedButtonsShop(shop)
local integer nextPage = 0
if (s != 0) then
// find the next page
loop
exitwhen (nextPage > s.maxPages or StringLength(s.pages[nextPage].name) == 0)
set nextPage = nextPage + 1
endloop
if (nextPage > 0) then
//call BJDebugMsg("Adding remaining spacers for page " + I2S(nextPage))
call AddPagedButtonsSpacersRemaining(shop)
endif
call RefreshMaxPagesEx(shop, nextPage + 1)
//call BJDebugMsg("Setting name for next page " + I2S(nextPage) + ": " + name)
call SetPagedButtonsPageName(shop, nextPage, name)
static if (CHANGE_PAGE_UNIT_NAME) then
call ChangeShopUnitName(shop)
endif
//call BJDebugMsg("Set name for next page " + I2S(nextPage) + " to name " + name)
return nextPage
endif
return -1
endfunction
function HasPagedButtons takes unit shop returns boolean
return IsUnitInGroup(shop, shops)
endfunction
function EnablePagedButtons takes unit shop returns boolean
if (not HasPagedButtons(shop)) then
call UnitAddAbility(shop, ABILITY_ID_SELL_UNITS)
call UnitAddAbility(shop, ABILITY_ID_SELL_ITEMS)
call GroupAddUnit(shops, shop)
call SetPagedButtonsShop(shop, Shop.create(GetUnitName(shop)))
call SetPagedButtonsSlotsPerPage(shop, SLOTS_PER_PAGE)
return true
endif
return false
endfunction
private function DestroyPagedButtonsShopTypes takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
call s.destroy()
endfunction
function DisablePagedButtons takes unit shop returns boolean
if (HasPagedButtons(shop)) then
static if (CHANGE_PAGE_UNIT_NAME) then
call ResetShopUnitName(shop)
endif
call RemoveUnitFromStock(shop, NEXT_PAGE_ID)
call RemoveUnitFromStock(shop, PREVIOUS_PAGE_ID)
call GroupRemoveUnit(shops, shop)
call HidePagedButtonsCurrentPage(shop)
call DestroyPagedButtonsShopTypes(shop)
call FlushChildHashtable(h, GetHandleId(shop))
return true
endif
return false
endfunction
function ChangePagedButtonsToNextPage takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer currentPage = s.currentPage
local integer maxPages = s.maxPages
if (currentPage == maxPages - 1) then
call SetPagedButtonsPage(shop, 0)
else
call SetPagedButtonsPage(shop, currentPage + 1)
endif
endfunction
function ChangePagedButtonsToPreviousPage takes unit shop returns nothing
local Shop s = GetPagedButtonsShop(shop)
local integer currentPage = s.currentPage
local integer maxPages = s.maxPages
if (currentPage == 0) then
call SetPagedButtonsPage(shop, maxPages - 1)
else
call SetPagedButtonsPage(shop, currentPage - 1)
endif
endfunction
private function TriggerConditionDeath takes nothing returns boolean
static if (DISABLE_SHOPS_ON_DEATH) then
call DisablePagedButtons(GetTriggerUnit())
endif
return false
endfunction
private function TriggerConditionSell takes nothing returns boolean
return HasPagedButtons(GetSellingUnit())
endfunction
private function DisplayMsg takes unit shop, unit buyingUnit returns nothing
local player owner = GetOwningPlayer(buyingUnit)
local integer currentPage = GetPagedButtonsPage(shop)
local string msg = "Page " + I2S(currentPage + 1)
local force whichForce = CreateForce()
local player slotPlayer = null
local integer i = 0
loop
exitwhen (i == bj_MAX_PLAYERS)
set slotPlayer = Player(i)
if (owner == slotPlayer or GetPlayerAlliance(owner, slotPlayer, ALLIANCE_SHARED_ADVANCED_CONTROL) or GetPlayerAlliance(owner, slotPlayer, ALLIANCE_SHARED_CONTROL)) then
call ForceAddPlayer(whichForce, slotPlayer)
endif
set slotPlayer = null
set i = i + 1
endloop
if (GetPagedButtonsPageName(shop, currentPage) != null) then
set msg = msg + ": " + GetPagedButtonsPageName(shop, currentPage)
endif
call DisplayTextToForce(whichForce, msg)
call ForceClear(whichForce)
call DestroyForce(whichForce)
set whichForce = null
set owner = null
endfunction
private function UpdateStocksById takes unit shop, integer id returns nothing
local SlotType s = GetPagedButtonType(shop, id)
if (s != 0) then
set s.currentStock = IMaxBJ(s.currentStock - 1, 0)
endif
endfunction
private function TriggerActionSellUnit takes nothing returns nothing
local unit shop = GetSellingUnit()
local integer unitTypeId = GetUnitTypeId(GetSoldUnit())
if (unitTypeId == NEXT_PAGE_ID or unitTypeId == PREVIOUS_PAGE_ID) then
call RemoveUnit(GetSoldUnit())
if (unitTypeId == NEXT_PAGE_ID) then
call ChangePagedButtonsToNextPage(shop)
else
call ChangePagedButtonsToPreviousPage(shop)
endif
static if (SHOW_PAGE_MESSAGE) then
call DisplayMsg(shop, GetBuyingUnit())
endif
else
static if (AUTO_UPDATE_STOCKS) then
call UpdateStocksById(shop, unitTypeId)
endif
endif
set shop = null
endfunction
private function TriggerActionSellItem takes nothing returns nothing
static if (AUTO_UPDATE_STOCKS) then
call UpdateStocksById(GetSellingUnit(), GetItemTypeId(GetSoldItem()))
endif
endfunction
private function TriggerConditionIsMarketplace takes nothing returns boolean
return GetUnitTypeId(GetSellingUnit()) == 'nmrk'
endfunction
private function Init takes nothing returns nothing
static if (DISABLE_SHOPS_ON_DEATH) then
set deathTrigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(deathTrigger, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(deathTrigger, Condition(function TriggerConditionDeath))
endif
call TriggerRegisterAnyUnitEventBJ(sellUnitTrigger, EVENT_PLAYER_UNIT_SELL)
call TriggerAddCondition(sellUnitTrigger, Condition(function TriggerConditionSell))
call TriggerAddAction(sellUnitTrigger, function TriggerActionSellUnit)
call TriggerRegisterAnyUnitEventBJ(sellItemTrigger, EVENT_PLAYER_UNIT_SELL_ITEM)
call TriggerAddCondition(sellItemTrigger, Condition(function TriggerConditionSell))
call TriggerAddAction(sellItemTrigger, function TriggerActionSellItem)
static if (AUTO_UPDATE_STOCKS) then
call TimerStart(autoUpdateStockTimer, 1.0, true, function SlotType.timerFunctionUpdateTime)
endif
static if (ENABLE_FAKE_MARKETPLACE_ITEM_REMOVAL) then
call TriggerAddCondition(bj_stockItemPurchased, Condition(function TriggerConditionIsMarketplace))
endif
endfunction
static if (HOOK_REMOVE_UNIT) then
hook RemoveUnit DisablePagedButtons
endif
/*
ChangeLog:
1.4
- GetPagedButtonId returns 0 for empty page buttons now.
- Add function GetPagedButtonsPageByIndex.
- Add optional UI to show more buttons at once which requires the FrameLoader and ItemTypeUtils dependencies.
- Function NextPagedButtonsPage changes the shop's name now even without adding any buttons.
- Add option DISABLE_SHOPS_ON_DEATH which is true by default.
- Change buttons page event is triggered from SetPagedButtonsPage now.
- Add function GetPagedButtonsNonSpacerButtonsCount.
- Switch "Next Page" and "Previous Page" unit types in demo map.
- Make sure that the "Next Page" and "Previous Page" buttons have a higher priority for shops than all other buttons.
- Mention the slow linked list traversal in the documentation.
- Remove LinkedList dependency and use custom arrays to improve the performance.
- Add function RemovePagedButtonsIndex.
- Fix function AddPagedButtonsSpacersRemaining.
- Add API documentation.
1.3
- Only execute callback triggers if they are enabled.
- Add struct Shop and Page to manage data internally with less hashtable keys.
- Add function GetPagedButtonsShop.
- Add function SetPagedButtonsShop.
- Add function GetPagedButtonsShopPage.
- Add function GetPagedButtonIndexEx.
- Add function GetPagedButtonsCountEx.
- Add function IsPagedButtonSpacer.
- Add constant BUTTON_TYPE_SPACER.
- Store the paged buttons type in T and remove method isSpacer to improve the performance and simplify
the code.
- Function NextPagedButtonsPage checks if the page exists now instead of checking the page name for
being null.
- Rename function GetPagedButtonsIndex into GetPagedButtonIndex.
- Rename function GetPagedButtonsType into GetPagedButtonType.
- Simplify implementation of function RemovePagedButtonsId.
- Function RemovePagedButtonsId removes the ID from the shop if it is shown.
- Remove the word System from libraries.
- Add paged buttons to race shops in example map.
- Add building Advanced Marketplace to example map.
- Only evaluate and execute callback triggers used with TriggerRegisterChangePagedButtons when the
player changes the page.
1.2
- Improve API documentation.
- Implement function RemovePagedButtonsId.
- Add function IsPagedButtonItem.
- Add function IsPagedButtonAbility.
- Add function AddPagedButtonsAbility.
- Add Advanced Goblin Laboratory to example map to demonstrate abilities.
- Add function NextPagedButtonsPage.
- Add function IsPagedButtonEnabled.
- Add function SetPagedButtonEnabled.
- Show next and previous page numbers as stock charges for the next and previous page buttons.
- Add option SHOW_NEXT_AND_PREVIOUS_PAGE_NUMBER.
- Add option STOCK_DELAY_THRESHOLD to fix removing wrong unit or item types on refreshing their stocks.
- Fix used page number in function SetPagedButtonsCurrentPageName.
- TriggerRegisterObjectAvailable works now even if the ID is not visible in the shop.
1.1 (thanks for Wrda's feedback on Hive):
- Fix GetPagedButtonsType.
- Mention that RemovePagedButtonsId is incomplete.
- Remove function RefreshPagedButtonsPage.
- Make option constants public.
- Add separators in API documentation comment.
- Add callback functions GetTriggerChangingShop, GetTriggerPreviousPage, GetTriggerAvailableObject,
TriggerRegisterChangePagedButtons and TriggerRegisterObjectAvailable and use them in the example map.
- Use different structs for spacers than for actual object IDs to save memory.
- Configure unit and item types in the example map config to show how it can be used.
- Only apply start delay once to refresh the stock.
- Only apply replenish delay if the current stock is smaller than maximum stock.
- Fix traversing list in method timerFunctionUpdateTime.
- Fix setting elapsedTimeReplenishInterval to 0 in method timerFunctionUpdateTime.
*/
endlibrary
native GetUnitGoldCost takes integer unitid returns integer
native GetUnitWoodCost takes integer unitid returns integer
library PagedButtonsUI initializer Init requires FrameLoader, ItemTypeUtils, PagedButtons, optional PagedButtonsConfig
globals
public constant string BUY_TEXT = "|n|n|cff808080Click to buy and open the page.|R|n"
public constant string OPEN_TEXT = "|n|n|cff808080Click to open the page.|R|n"
public constant string PREFIX = "PagedButtonsUI"
public constant real UI_SIZE_X = 0.80
public constant real UI_SIZE_Y = 0.42
public constant real UI_BUTTON_SIZE = 0.02818
public constant real UI_CHARGES_BACKGROUND_SIZE = 0.011
public constant real UI_CHARGES_POS = 0.003
public constant real UI_CHARGES_SIZE = 0.02
public constant real UI_BUTTON_SPACE = 0.005
public constant integer HERO_GOLD_COST = 425
public constant integer HERO_LUMBER_COST = 100
public constant real TOOLTIP_X = 0.64
public constant real TOOLTIP_ICON_X = TOOLTIP_X
public constant real TOOLTIP_ICON_Y = 0.52
public constant real TOOLTIP_ICON_SIZE = 0.03
public constant real TOOLTIP_PAGE_NAME_X = TOOLTIP_ICON_X + TOOLTIP_ICON_SIZE + 0.012
public constant real TOOLTIP_PAGE_NAME_Y = 0.52
public constant real TOOLTIP_PAGE_NAME_WIDTH = 0.08
public constant real TOOLTIP_PAGE_NAME_HEIGHT = 0.02
public constant real SUMMON_Y = TOOLTIP_ICON_Y - TOOLTIP_ICON_SIZE - 0.005
public constant real SUMMON_HEIGHT = 0.02
public constant real SUMMON_WIDTH = 0.12
public constant real COST_Y = SUMMON_Y - SUMMON_HEIGHT - 0.005
public constant real COST_HEIGHT = 0.01
public constant real COST_ICON_SIZE = 0.01
public constant real COST_GOLD_X = TOOLTIP_X + COST_ICON_SIZE + 0.005
public constant real COST_WIDTH = 0.03
public constant real COST_ICON_LUMBER_X = COST_GOLD_X + COST_WIDTH + 0.005
public constant real COST_LUMBER_X = COST_ICON_LUMBER_X + COST_ICON_SIZE + 0.005
public constant real COST_ICON_FOOD_X = COST_LUMBER_X + COST_WIDTH + 0.005
public constant real COST_FOOD_X = COST_ICON_FOOD_X + COST_ICON_SIZE + 0.005
public constant real TOOLTIP_WIDTH = 0.12
public constant real TOOLTIP_Y = COST_Y - COST_HEIGHT - 0.005
public constant real TOOLTIP_HEIGHT = 0.4
public constant integer MAX_SLOTS = 180
public constant integer MAX_SLOTS_PER_LINE = 18
private boolean array enabledForPlayer
private boolean array UIVisible
private unit array UIShop
private integer array PagesIndex
private framehandle array BackgroundFrame
private framehandle array TitleFrame
private framehandle array SlotFrame
private framehandle array SlotBackdropFrame
private framehandle array SlotChargesBackgroundFrame
private framehandle array SlotChargesFrame
private framehandle array SlotPageBackgroundFrame
private framehandle array SlotPageFrame
private trigger array SlotClickTrigger
private trigger array SlotTooltipOnTrigger
private trigger array SlotTooltipOffTrigger
private framehandle array TooltipFrame
private framehandle array PageNameText
private framehandle array TooltipIcon
private framehandle array SummonFrame
private framehandle array ItemGoldFrame
private framehandle array ItemGoldIconFrame
private framehandle array ItemLumberFrame
private framehandle array ItemLumberIconFrame
private framehandle array ItemFoodFrame
private framehandle array ItemFoodIconFrame
private framehandle array TooltipText
private framehandle array NextPagesButton
private trigger array NextPagesTrigger
private framehandle array PreviousPagesButton
private trigger array PreviousPagesTrigger
private framehandle array CloseButton
private trigger array CloseTrigger
private trigger array SyncTrigger
private hashtable h = InitHashtable()
private trigger array selectionTrigger
private trigger changePageButtonsTrigger = CreateTrigger()
private trigger deathTrigger = CreateTrigger()
endglobals
function SetPagedButtonsUIEnabledForPlayer takes player whichPlayer, boolean enabled returns nothing
set enabledForPlayer[GetPlayerId(whichPlayer)] = enabled
endfunction
function IsPagedButtonsUIEnabledForPlayer takes player whichPlayer returns boolean
return enabledForPlayer[GetPlayerId(whichPlayer)]
endfunction
private function Index2D takes integer Value1,integer Value2,integer MaxValue2 returns integer
return ((Value1 * MaxValue2) + Value2)
endfunction
private function GetButtonIndex takes integer index, integer playerId returns integer
return Index2D(index, playerId, bj_MAX_PLAYERS)
endfunction
private function GetButtonSlotIcon takes unit shop, integer index returns string
return BlzGetAbilityIcon(GetPagedButtonId (shop, index))
endfunction
private function GetMaxPageIndex takes integer playerId returns integer
return GetPagedButtonsNonSpacerButtonsCount(UIShop[playerId]) / MAX_SLOTS
endfunction
private function UpdateItemsForUI takes player whichPlayer returns nothing
local integer playerId = GetPlayerId(whichPlayer)
local integer objectId = 0
local integer index = 0
local integer i = 0
local unit shop = UIShop[playerId]
local integer slot = 0
local integer nonSpacerSlots = 0
local integer startSlot = PagesIndex[playerId] * MAX_SLOTS
local integer maxSlots = GetPagedButtonsCount(shop)
local integer page = GetPagedButtonsPage(shop)
local string pageName = GetPagedButtonsPageName(shop, page)
local integer maxPageIndex = GetMaxPageIndex(playerId)
local integer handleId = 0
if (pageName == null or StringLength(pageName) == 0) then
set pageName = GetUnitName(shop)
endif
if (maxPageIndex > 0) then
set pageName = pageName + " (" + I2S(PagesIndex[playerId] + 1) + "/" + I2S(maxPageIndex + 1) + ")"
if (whichPlayer == GetLocalPlayer()) then
call BlzFrameSetVisible(NextPagesButton[playerId], true)
call BlzFrameSetVisible(PreviousPagesButton[playerId], true)
endif
else
if (whichPlayer == GetLocalPlayer()) then
call BlzFrameSetVisible(NextPagesButton[playerId], false)
call BlzFrameSetVisible(PreviousPagesButton[playerId], false)
endif
endif
//call BJDebugMsg("max page index " + I2S(maxPageIndex))
// set UIShop[playerId] = shop
call BlzFrameSetText(TitleFrame[playerId], pageName)
loop
exitwhen (slot >= maxSlots or i >= MAX_SLOTS)
if (not IsPagedButtonSpacer(shop, slot)) then
set nonSpacerSlots = nonSpacerSlots + 1
if (nonSpacerSlots > startSlot) then
set objectId = GetPagedButtonId(shop, slot)
set index = GetButtonIndex(i, playerId)
//call BlzFrameSetTexture(SlotFrame[index], GetIconByItemType(udg_RucksackItemType[index]), 0, true)
call BlzFrameSetTexture(SlotBackdropFrame[index], BlzGetAbilityIcon(objectId), 0, true)
call BlzFrameSetText(SlotChargesFrame[index], "1") // I2S(GetItemCharges(index))
call BlzFrameSetText(SlotPageFrame[index], I2S(GetPagedButtonsPageByIndex(shop, slot) + 1))
if (UIVisible[playerId]) then // and GetItemCharges(index) > 0
if (whichPlayer == GetLocalPlayer()) then
call BlzFrameSetVisible(SlotChargesBackgroundFrame[index], true)
call BlzFrameSetVisible(SlotChargesFrame[index], true)
call BlzFrameSetVisible(SlotPageBackgroundFrame[index], true)
call BlzFrameSetVisible(SlotPageFrame[index], true)
call BlzFrameSetVisible(SlotFrame[index], true)
call BlzFrameSetVisible(SlotBackdropFrame[index], true)
endif
endif
set handleId = GetHandleId(SlotClickTrigger[index])
call SaveInteger(h, handleId, 2, slot)
set handleId = GetHandleId(SlotTooltipOnTrigger[index])
call SaveInteger(h, handleId, 2, slot)
set handleId = GetHandleId(SlotTooltipOffTrigger[index])
call SaveInteger(h, handleId, 2, slot)
set i = i + 1
endif
endif
set slot = slot + 1
endloop
loop
exitwhen (i >= MAX_SLOTS)
set index = GetButtonIndex(i, playerId)
call BlzFrameSetTexture(SlotBackdropFrame[index], "UI\\Widgets\\Console\\Human\\human-inventory-slotfiller.blp", 0, true)
call BlzFrameSetVisible(SlotChargesBackgroundFrame[index], false)
call BlzFrameSetVisible(SlotChargesFrame[index], false)
call BlzFrameSetVisible(SlotPageBackgroundFrame[index], false)
call BlzFrameSetVisible(SlotPageFrame[index], false)
call BlzFrameSetVisible(SlotFrame[index], false)
call BlzFrameSetVisible(SlotBackdropFrame[index], false)
set i = i + 1
endloop
endfunction
private function UIExists takes player whichPlayer returns boolean
return BackgroundFrame[GetPlayerId(whichPlayer)] != null
endfunction
private function SyncedData takes nothing returns nothing
local player whichPlayer = GetTriggerPlayer()
local integer playerId = GetPlayerId(whichPlayer)
local string data = BlzGetTriggerSyncData()
local integer slot = S2I(data)
local unit shop = UIShop[playerId]
local integer slotsPerPage = GetPagedButtonsSlotsPerPage(shop)
local integer id = GetPagedButtonId(shop, slot)
local integer newPage = GetPagedButtonsPageByIndex(shop, slot)
if (newPage < GetPagedButtonsMaxPages(shop) and newPage >= 0) then
call SetPagedButtonsPage(shop, GetPagedButtonsPageByIndex(shop, slot))
if (id != 0 and (IsPagedButtonUnit(shop, slot) or IsPagedButtonItem(shop, slot))) then
call IssueNeutralImmediateOrderById(whichPlayer, shop, id)
endif
endif
set whichPlayer = null
set shop = null
endfunction
private function UITriggerActionSyncData takes nothing returns nothing
if (BlzGetTriggerSyncPrefix() == PREFIX) then
call SyncedData()
endif
endfunction
private function GetPagesIndexFromPagedButtonsShopEx takes unit shop returns integer
local integer currentPage = GetPagedButtonsPage(shop)
local integer i = 0
local integer max = GetPagedButtonsCount(shop)
local integer countNonSpacerButtons = 0
loop
exitwhen (i >= max)
if (GetPagedButtonsPageByIndex(shop, i) >= currentPage) then
return countNonSpacerButtons / MAX_SLOTS
endif
if (not IsPagedButtonSpacer(shop, i)) then
set countNonSpacerButtons = countNonSpacerButtons + 1
endif
set i = i + 1
endloop
return 0
endfunction
private function GetPagesIndexFromPagedButtonsShop takes unit shop returns integer
if (HasPagedButtons(shop)) then
return GetPagesIndexFromPagedButtonsShopEx(shop)
endif
return 0
endfunction
function ShowPagedButtonsUI takes player whichPlayer, unit shop returns nothing
local integer playerId = GetPlayerId(whichPlayer)
if (not UIExists(whichPlayer)) then
return
endif
set UIVisible[playerId] = true
set UIShop[playerId] = shop
set PagesIndex[playerId] = GetPagesIndexFromPagedButtonsShop(shop)
call UpdateItemsForUI(whichPlayer)
if (whichPlayer == GetLocalPlayer()) then
call BlzFrameSetVisible(BackgroundFrame[playerId], true)
call BlzFrameSetVisible(TitleFrame[playerId], true)
call BlzFrameSetVisible(PageNameText[playerId], false)
call BlzFrameSetVisible(SummonFrame[playerId], false)
call BlzFrameSetVisible(ItemGoldFrame[playerId], false)
call BlzFrameSetVisible(ItemGoldIconFrame[playerId], false)
call BlzFrameSetVisible(ItemLumberFrame[playerId], false)
call BlzFrameSetVisible(ItemLumberIconFrame[playerId], false)
call BlzFrameSetVisible(TooltipIcon[playerId], false)
endif
endfunction
function HidePagedButtonsUI takes player whichPlayer returns nothing
local integer playerId = GetPlayerId(whichPlayer)
local integer i = 0
local integer index = 0
if (not UIExists(whichPlayer)) then
return
endif
set UIVisible[playerId] = false
set UIShop[playerId] = null
set PagesIndex[playerId] = 0
call BlzFrameSetVisible(BackgroundFrame[playerId], false)
call BlzFrameSetVisible(TitleFrame[playerId], false)
call BlzFrameSetVisible(PageNameText[playerId], false)
call BlzFrameSetVisible(SummonFrame[playerId], false)
call BlzFrameSetVisible(ItemGoldFrame[playerId], false)
call BlzFrameSetVisible(ItemGoldIconFrame[playerId], false)
call BlzFrameSetVisible(ItemLumberFrame[playerId], false)
call BlzFrameSetVisible(ItemLumberIconFrame[playerId], false)
call BlzFrameSetVisible(TooltipIcon[playerId], false)
set i = 0
loop
exitwhen (i == MAX_SLOTS)
set index = GetButtonIndex(i, playerId)
call BlzFrameSetVisible(SlotFrame[index], false)
call BlzFrameSetVisible(SlotBackdropFrame[index], false)
call BlzFrameSetVisible(SlotPageBackgroundFrame[index], false)
call BlzFrameSetVisible(SlotPageFrame[index], false)
call BlzFrameSetVisible(SlotChargesBackgroundFrame[index], false)
call BlzFrameSetVisible(SlotChargesFrame[index], false)
set i = i + 1
endloop
endfunction
private function ClickItemFunction takes nothing returns nothing
local integer handleId = GetHandleId(GetTriggeringTrigger())
local integer playerId = LoadInteger(h, handleId, 0)
local integer index = LoadInteger(h, handleId, 1)
local integer slot = LoadInteger(h, handleId, 2)
local unit shop = UIShop[playerId]
local integer page = GetPagedButtonsPageByIndex(shop, slot)
if (GetLocalPlayer() == GetTriggerPlayer()) then
call BlzSendSyncData(PREFIX, I2S(slot))
endif
endfunction
private function EnterItemFunction takes nothing returns nothing
local integer handleId = GetHandleId(GetTriggeringTrigger())
local integer playerId = LoadInteger(h, handleId, 0)
local integer index = LoadInteger(h, handleId, 1)
local integer slot = LoadInteger(h, handleId, 2)
local unit shop = UIShop[playerId]
local integer id = GetPagedButtonId(shop, slot)
local integer page = GetPagedButtonsPageByIndex(shop, slot)
local string pageName = ""
local string tooltip = ""
local player whichPlayer = Player(playerId)
local integer goldCost = 0
local integer lumberCost = 0
local integer foodCost = 0
local string summonText = ""
if (slot >= 0 and slot < GetPagedButtonsCount(shop)) then
set pageName = GetPagedButtonsPageName(shop, page)
set summonText = BlzGetAbilityTooltip(id, 0)
if (IsPagedButtonUnit(shop, slot)) then
if (IsUnitIdType(id, UNIT_TYPE_HERO)) then
//call BJDebugMsg("Hero code " + A2S(id))
static if (LIBRARY_PagedButtonsConfig) then
set goldCost = GetHeroGoldCost(id)
set lumberCost = GetHeroLumberCost(id)
else
set goldCost = HERO_GOLD_COST
set lumberCost = HERO_LUMBER_COST
endif
else
set goldCost = GetUnitGoldCost(id)
set lumberCost = GetUnitWoodCost(id)
endif
set foodCost = GetFoodUsed(id)
elseif (IsPagedButtonItem(shop, slot)) then
set goldCost = GetItemValueGold(id)
set lumberCost = GetItemValueLumber(id)
endif
if (summonText != null and StringLength(summonText) > 0) then
call BlzFrameSetText(SummonFrame[playerId], summonText)
if (GetLocalPlayer() == whichPlayer) then
call BlzFrameSetVisible(SummonFrame[playerId], true)
endif
endif
if (goldCost > 0) then
call BlzFrameSetText(ItemGoldFrame[playerId], "|cffffcc00" + I2S(goldCost) + "|r")
if (GetLocalPlayer() == whichPlayer) then
call BlzFrameSetVisible(ItemGoldIconFrame[playerId], true)
call BlzFrameSetVisible(ItemGoldFrame[playerId], true)
endif
endif
if (lumberCost > 0) then
call BlzFrameSetText(ItemLumberFrame[playerId], "|cffffcc00" + I2S(lumberCost) + "|r")
if (GetLocalPlayer() == whichPlayer) then
call BlzFrameSetVisible(ItemLumberIconFrame[playerId], true)
call BlzFrameSetVisible(ItemLumberFrame[playerId], true)
endif
endif
if (foodCost > 0) then
call BlzFrameSetText(ItemFoodFrame[playerId], "|cffffcc00" + I2S(foodCost) + "|r")
if (GetLocalPlayer() == whichPlayer) then
call BlzFrameSetVisible(ItemFoodIconFrame[playerId], true)
call BlzFrameSetVisible(ItemFoodFrame[playerId], true)
endif
endif
//call BJDebugMsg("Entering item " + I2S(index))
if (pageName != null) then
call BlzFrameSetText(PageNameText[playerId], "(" + pageName + ")")
if (GetLocalPlayer() == whichPlayer) then
call BlzFrameSetVisible(PageNameText[playerId], true)
endif
endif
if (id != 0) then
set tooltip = tooltip + BlzGetAbilityExtendedTooltip(id, 0)
else
set tooltip = tooltip + "Empty slot " + I2S(slot + 1) + " at page " + I2S(page + 1) + "."
//call BlzFrameSetVisible(ItemGoldIconFrame[playerId], false)
endif
if (id != 0) then
call BlzFrameSetTexture(TooltipIcon[playerId], GetButtonSlotIcon(shop, slot), 0, false)
call BlzFrameSetVisible(TooltipIcon[playerId], true)
set tooltip = tooltip + BUY_TEXT
else
call BlzFrameSetVisible(TooltipIcon[playerId], false)
set tooltip = tooltip + OPEN_TEXT
endif
call BlzFrameSetText(TooltipText[playerId], tooltip)
if (GetLocalPlayer() == whichPlayer) then
call BlzFrameSetVisible(TooltipText[playerId], true)
endif
endif
set whichPlayer = null
set shop = null
endfunction
private function LeaveItemFunction takes nothing returns nothing
local integer handleId = GetHandleId(GetTriggeringTrigger())
local integer playerId = LoadInteger(h, handleId, 0)
local integer index = LoadInteger(h, handleId, 1)
//call BJDebugMsg("Leave item " + I2S(index))
call BlzFrameSetTexture(TooltipIcon[playerId], "", 0, false)
call BlzFrameSetVisible(TooltipIcon[playerId], false)
call BlzFrameSetVisible(PageNameText[playerId], false)
call BlzFrameSetText(PageNameText[playerId], "")
call BlzFrameSetVisible(SummonFrame[playerId], false)
call BlzFrameSetText(SummonFrame[playerId], "")
call BlzFrameSetVisible(TooltipText[playerId], false)
call BlzFrameSetText(TooltipText[playerId], "")
call BlzFrameSetVisible(ItemGoldFrame[playerId], false)
call BlzFrameSetVisible(ItemGoldIconFrame[playerId], false)
call BlzFrameSetVisible(ItemLumberFrame[playerId], false)
call BlzFrameSetVisible(ItemLumberIconFrame[playerId], false)
call BlzFrameSetVisible(ItemFoodFrame[playerId], false)
call BlzFrameSetVisible(ItemFoodIconFrame[playerId], false)
endfunction
private function PreviousPagesFunction takes nothing returns nothing
local integer handleId = GetHandleId(GetTriggeringTrigger())
local integer playerId = LoadInteger(h, handleId, 0)
if (PagesIndex[playerId] == 0) then
set PagesIndex[playerId] = GetMaxPageIndex(playerId)
else
set PagesIndex[playerId] = PagesIndex[playerId] - 1
endif
call UpdateItemsForUI(Player(playerId))
//call BJDebugMsg("Previous pages button with index " + I2S(PagesIndex[playerId]))
endfunction
private function NextPagesFunction takes nothing returns nothing
local integer handleId = GetHandleId(GetTriggeringTrigger())
local integer playerId = LoadInteger(h, handleId, 0)
if (PagesIndex[playerId] < GetMaxPageIndex(playerId)) then
set PagesIndex[playerId] = PagesIndex[playerId] + 1
else
set PagesIndex[playerId] = 0
endif
call UpdateItemsForUI(Player(playerId))
//call BJDebugMsg("Next pages button with index " + I2S(PagesIndex[playerId]))
endfunction
private function CloseFunction takes nothing returns nothing
local integer handleId = GetHandleId(GetTriggeringTrigger())
local integer playerId = LoadInteger(h, handleId, 0)
call HidePagedButtonsUI(Player(playerId))
endfunction
public function CreateUI takes player whichPlayer returns nothing
local integer i = 0
local integer handleId = 0
local real x = 0.0
local real y = 0.0
local integer index = 0
local integer playerId = GetPlayerId(whichPlayer)
set BackgroundFrame[playerId] = BlzCreateFrame("EscMenuBackdrop", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0),0,0)
call BlzFrameSetAbsPoint(BackgroundFrame[playerId], FRAMEPOINT_TOPLEFT, 0.0, 0.57)
call BlzFrameSetAbsPoint(BackgroundFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, UI_SIZE_X, 0.57 - UI_SIZE_Y)
set y = 0.548
set TitleFrame[playerId] = BlzCreateFrameByType("TEXT", "Title" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(TitleFrame[playerId], FRAMEPOINT_TOPLEFT, 0.0, y)
call BlzFrameSetAbsPoint(TitleFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, UI_SIZE_X, y - 0.1)
call BlzFrameSetTextAlignment(TitleFrame[playerId], TEXT_JUSTIFY_TOP, TEXT_JUSTIFY_CENTER)
call BlzFrameSetScale(TitleFrame[playerId], 1.0)
call BlzFrameSetVisible(TitleFrame[playerId], false)
set x = 0.03
set y = 0.53
set i = 0
loop
exitwhen (i == MAX_SLOTS)
set index = GetButtonIndex(i, playerId)
set SlotFrame[index] = BlzCreateFrame("ScriptDialogButton", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 0, 0)
call BlzFrameSetAbsPoint(SlotFrame[index], FRAMEPOINT_TOPLEFT, x, y)
call BlzFrameSetAbsPoint(SlotFrame[index], FRAMEPOINT_BOTTOMRIGHT, x + UI_BUTTON_SIZE, y - UI_BUTTON_SIZE)
//call BlzFrameSetTexture(SlotFrame[index], GetIconByItemType(0), 0, true)
//call BlzFrameSetText(SlotFrame[index], I2S(index))
call BlzFrameSetScale(SlotFrame[index], 1.00)
call BlzFrameSetVisible(SlotFrame[index], false)
set SlotBackdropFrame[index] = BlzCreateFrameByType("BACKDROP", "BackdropFrame" + I2S(index), SlotFrame[index], "", 1)
call BlzFrameSetAllPoints(SlotBackdropFrame[index], SlotFrame[index])
// call BlzFrameSetTexture(SlotBackdropFrame[index], "UI\\Widgets\\Console\\Human\\human-inventory-slotfiller.blp", 0, true)
call BlzFrameSetVisible(SlotBackdropFrame[index], false)
set SlotClickTrigger[index] = CreateTrigger()
call BlzTriggerRegisterFrameEvent(SlotClickTrigger[index], SlotFrame[index], FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(SlotClickTrigger[index], function ClickItemFunction)
set handleId = GetHandleId(SlotClickTrigger[index])
call SaveInteger(h, handleId, 0, playerId)
call SaveInteger(h, handleId, 1, index)
call SaveInteger(h, handleId, 2, i)
set SlotTooltipOnTrigger[index] = CreateTrigger()
call BlzTriggerRegisterFrameEvent(SlotTooltipOnTrigger[index], SlotFrame[index], FRAMEEVENT_MOUSE_ENTER)
call TriggerAddAction(SlotTooltipOnTrigger[index], function EnterItemFunction)
set handleId = GetHandleId(SlotTooltipOnTrigger[index])
call SaveInteger(h, handleId, 0, playerId)
call SaveInteger(h, handleId, 1, index)
call SaveInteger(h, handleId, 2, i)
set SlotTooltipOffTrigger[index] = CreateTrigger()
call BlzTriggerRegisterFrameEvent(SlotTooltipOffTrigger[index], SlotFrame[index], FRAMEEVENT_MOUSE_LEAVE)
call TriggerAddAction(SlotTooltipOffTrigger[index], function LeaveItemFunction)
call SaveInteger(h, handleId, 0, playerId)
call SaveInteger(h, handleId, 1, index)
// TODO Mouse down and mouse up to drag & drop to another bag or switch or do it like Warcraft's inventory with right click and left click. Add the icon of the item to the mouse cursor. If you click on the map it is dropped, if you click on the inventory it is dropped there.
set SlotPageBackgroundFrame[index] = BlzCreateFrameByType("BACKDROP", "ItemBagBackrgroundFrame" + I2S(index), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(SlotPageBackgroundFrame[index], FRAMEPOINT_TOPLEFT, x, y)
call BlzFrameSetAbsPoint(SlotPageBackgroundFrame[index], FRAMEPOINT_BOTTOMRIGHT, x + UI_CHARGES_BACKGROUND_SIZE, y - UI_CHARGES_BACKGROUND_SIZE)
call BlzFrameSetTexture(SlotPageBackgroundFrame[index], "ui\\widgets\\console\\human\\commandbutton\\human-button-lvls-overlay.blp", 0, true)
call BlzFrameSetVisible(SlotPageBackgroundFrame[index], false)
call BlzFrameSetLevel(SlotPageBackgroundFrame[index], 1)
set SlotPageFrame[index] = BlzCreateFrameByType("TEXT", "bag" + I2S(index), SlotPageBackgroundFrame[index], "", 0)
call BlzFrameSetAllPoints(SlotPageFrame[index], SlotPageBackgroundFrame[index])
call BlzFrameSetText(SlotPageFrame[index], I2S(i + 1))
call BlzFrameSetTextAlignment(SlotPageFrame[index], TEXT_JUSTIFY_CENTER, TEXT_JUSTIFY_CENTER)
call BlzFrameSetScale(SlotPageFrame[index], 0.7)
call BlzFrameSetVisible(SlotPageFrame[index], false)
call BlzFrameSetEnable(SlotPageFrame[index], false)
call BlzFrameSetLevel(SlotPageFrame[index], 2)
set SlotChargesBackgroundFrame[index] = BlzCreateFrameByType("BACKDROP", "ItemChargesBackrgroundFrame" + I2S(index), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(SlotChargesBackgroundFrame[index], FRAMEPOINT_TOPLEFT, x + UI_BUTTON_SIZE - UI_CHARGES_BACKGROUND_SIZE, y - UI_BUTTON_SIZE + UI_CHARGES_BACKGROUND_SIZE)
call BlzFrameSetAbsPoint(SlotChargesBackgroundFrame[index], FRAMEPOINT_BOTTOMRIGHT, x + UI_BUTTON_SIZE, y - UI_BUTTON_SIZE)
call BlzFrameSetTexture(SlotChargesBackgroundFrame[index], "ui\\widgets\\console\\human\\commandbutton\\human-button-lvls-overlay.blp", 0, true)
call BlzFrameSetVisible(SlotChargesBackgroundFrame[index], false)
call BlzFrameSetLevel(SlotChargesBackgroundFrame[index], 1)
set SlotChargesFrame[index] = BlzCreateFrameByType("TEXT", "charges" + I2S(index), SlotChargesBackgroundFrame[index], "", 0)
call BlzFrameSetAllPoints(SlotChargesFrame[index], SlotChargesBackgroundFrame[index])
call BlzFrameSetText(SlotChargesFrame[index], "|cffFFFFFFCharges|r")
call BlzFrameSetTextAlignment(SlotChargesFrame[index], TEXT_JUSTIFY_CENTER, TEXT_JUSTIFY_CENTER)
call BlzFrameSetScale(SlotChargesFrame[index], 0.7)
call BlzFrameSetVisible(SlotChargesFrame[index], false)
call BlzFrameSetEnable(SlotChargesFrame[index], false)
call BlzFrameSetLevel(SlotChargesFrame[index], 2)
set x = x + UI_BUTTON_SIZE + UI_BUTTON_SPACE
set i = i + 1
// every 3 bags start another line
if (ModuloInteger(i, MAX_SLOTS_PER_LINE) == 0) then
set x = 0.03
set y = y - UI_BUTTON_SIZE - UI_BUTTON_SPACE
endif
endloop
set TooltipFrame[playerId] = BlzCreateFrame("EscMenuBackdrop", BackgroundFrame[playerId], 0, 0)
call BlzFrameSetAbsPoint(TooltipFrame[playerId], FRAMEPOINT_TOPLEFT, 0.62, 0.54)
call BlzFrameSetAbsPoint(TooltipFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, 0.78, 0.20)
set TooltipIcon[playerId] = BlzCreateFrameByType("BACKDROP", "TooltipIconFrame" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(TooltipIcon[playerId], FRAMEPOINT_TOPLEFT, TOOLTIP_ICON_X, TOOLTIP_ICON_Y)
call BlzFrameSetAbsPoint(TooltipIcon[playerId], FRAMEPOINT_BOTTOMRIGHT, TOOLTIP_ICON_X + TOOLTIP_ICON_SIZE, TOOLTIP_ICON_Y - TOOLTIP_ICON_SIZE)
call BlzFrameSetTexture(TooltipIcon[playerId], "ReplaceableTextures\\WorldEditUI\\Editor-Random-Item.blp", 0, true)
call BlzFrameSetVisible(TooltipIcon[playerId], false)
set PageNameText[playerId] = BlzCreateFrameByType("TEXT", "TooltipPageName" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(PageNameText[playerId], FRAMEPOINT_TOPLEFT, TOOLTIP_PAGE_NAME_X, TOOLTIP_PAGE_NAME_Y)
call BlzFrameSetAbsPoint(PageNameText[playerId], FRAMEPOINT_BOTTOMRIGHT, TOOLTIP_PAGE_NAME_X + TOOLTIP_PAGE_NAME_WIDTH, TOOLTIP_PAGE_NAME_Y - TOOLTIP_PAGE_NAME_HEIGHT)
call BlzFrameSetVisible(PageNameText[playerId], false)
set SummonFrame[playerId] = BlzCreateFrameByType("TEXT", "TooltipSummon" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(SummonFrame[playerId], FRAMEPOINT_TOPLEFT, TOOLTIP_X, SUMMON_Y)
call BlzFrameSetAbsPoint(SummonFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, TOOLTIP_X + SUMMON_WIDTH, SUMMON_Y - SUMMON_HEIGHT)
call BlzFrameSetVisible(SummonFrame[playerId], false)
set ItemGoldIconFrame[playerId] = BlzCreateFrameByType("BACKDROP", "TooltipGoldFrame" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(ItemGoldIconFrame[playerId], FRAMEPOINT_TOPLEFT, TOOLTIP_X, COST_Y)
call BlzFrameSetAbsPoint(ItemGoldIconFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, TOOLTIP_X + COST_ICON_SIZE, COST_Y - COST_ICON_SIZE)
call BlzFrameSetTexture(ItemGoldIconFrame[playerId], "UI\\Feedback\\Resources\\ResourceGold.blp", 0, true)
call BlzFrameSetVisible(ItemGoldIconFrame[playerId], false)
set ItemGoldFrame[playerId] = BlzCreateFrameByType("TEXT", "TooltipGold" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(ItemGoldFrame[playerId], FRAMEPOINT_TOPLEFT, COST_GOLD_X, COST_Y)
call BlzFrameSetAbsPoint(ItemGoldFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, COST_GOLD_X + COST_WIDTH, COST_Y - COST_HEIGHT)
call BlzFrameSetVisible(ItemGoldFrame[playerId], false)
set ItemLumberIconFrame[playerId] = BlzCreateFrameByType("BACKDROP", "TooltipLumberFrame" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(ItemLumberIconFrame[playerId], FRAMEPOINT_TOPLEFT, COST_ICON_LUMBER_X, COST_Y)
call BlzFrameSetAbsPoint(ItemLumberIconFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, COST_ICON_LUMBER_X + COST_ICON_SIZE, COST_Y - COST_ICON_SIZE)
call BlzFrameSetTexture(ItemLumberIconFrame[playerId], "UI\\Feedback\\Resources\\ResourceLumber.blp", 0, true)
call BlzFrameSetVisible(ItemLumberIconFrame[playerId], false)
set ItemLumberFrame[playerId] = BlzCreateFrameByType("TEXT", "TooltipLumber" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(ItemLumberFrame[playerId], FRAMEPOINT_TOPLEFT, COST_LUMBER_X, COST_Y)
call BlzFrameSetAbsPoint(ItemLumberFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, COST_LUMBER_X + COST_WIDTH, COST_Y - COST_ICON_SIZE)
call BlzFrameSetVisible(ItemLumberFrame[playerId], false)
set ItemFoodIconFrame[playerId] = BlzCreateFrameByType("BACKDROP", "TooltipFoodFrame" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(ItemFoodIconFrame[playerId], FRAMEPOINT_TOPLEFT, COST_ICON_FOOD_X, COST_Y)
call BlzFrameSetAbsPoint(ItemFoodIconFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, COST_ICON_FOOD_X + COST_ICON_SIZE, COST_Y - COST_ICON_SIZE)
call BlzFrameSetTexture(ItemFoodIconFrame[playerId], "UI\\Feedback\\Resources\\ResourceSupply.blp", 0, true)
call BlzFrameSetVisible(ItemFoodIconFrame[playerId], false)
set ItemFoodFrame[playerId] = BlzCreateFrameByType("TEXT", "TooltipFood" + I2S(playerId), BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
call BlzFrameSetAbsPoint(ItemFoodFrame[playerId], FRAMEPOINT_TOPLEFT, COST_FOOD_X, COST_Y)
call BlzFrameSetAbsPoint(ItemFoodFrame[playerId], FRAMEPOINT_BOTTOMRIGHT, COST_FOOD_X + COST_WIDTH, COST_Y - COST_ICON_SIZE)
call BlzFrameSetVisible(ItemFoodFrame[playerId], false)
set TooltipText[playerId] = BlzCreateFrameByType("TEXT", "TooltipText" + I2S(playerId), BackgroundFrame[playerId], "", 0)
call BlzFrameSetAbsPoint(TooltipText[playerId], FRAMEPOINT_TOPLEFT, TOOLTIP_X, TOOLTIP_Y)
call BlzFrameSetAbsPoint(TooltipText[playerId], FRAMEPOINT_BOTTOMRIGHT, TOOLTIP_X + TOOLTIP_WIDTH, TOOLTIP_Y - TOOLTIP_HEIGHT)
call BlzFrameSetText(TooltipText[playerId], "")
call BlzFrameSetEnable(TooltipText[playerId], false)
call BlzFrameSetTextAlignment(TooltipText[playerId], TEXT_JUSTIFY_TOP, TEXT_JUSTIFY_LEFT)
set NextPagesButton[playerId] = BlzCreateFrame("ScriptDialogButton", BackgroundFrame[playerId], 0, 0)
set x = 0.18
set y = 0.20
call BlzFrameSetAbsPoint(NextPagesButton[playerId], FRAMEPOINT_TOPLEFT, x, y)
call BlzFrameSetAbsPoint(NextPagesButton[playerId], FRAMEPOINT_BOTTOMRIGHT, x + 0.12, y - 0.03)
call BlzFrameSetText(NextPagesButton[playerId], "|cffFCD20DNext Page|r")
call BlzFrameSetScale(NextPagesButton[playerId], 1.00)
set NextPagesTrigger[playerId] = CreateTrigger()
call BlzTriggerRegisterFrameEvent(NextPagesTrigger[playerId], NextPagesButton[playerId], FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(NextPagesTrigger[playerId], function NextPagesFunction)
set handleId = GetHandleId(NextPagesTrigger[playerId])
call SaveInteger(h, handleId, 0, playerId)
set PreviousPagesButton[playerId] = BlzCreateFrame("ScriptDialogButton", BackgroundFrame[playerId], 0, 0)
set x = 0.06
set y = 0.20
call BlzFrameSetAbsPoint(PreviousPagesButton[playerId], FRAMEPOINT_TOPLEFT, x, y)
call BlzFrameSetAbsPoint(PreviousPagesButton[playerId], FRAMEPOINT_BOTTOMRIGHT, x + 0.12, y - 0.03)
call BlzFrameSetText(PreviousPagesButton[playerId], "|cffFCD20DPrevious Page|r")
set PreviousPagesTrigger[playerId] = CreateTrigger()
call BlzTriggerRegisterFrameEvent(PreviousPagesTrigger[playerId], PreviousPagesButton[playerId], FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(PreviousPagesTrigger[playerId], function PreviousPagesFunction)
set handleId = GetHandleId(PreviousPagesTrigger[playerId])
call SaveInteger(h, handleId, 0, playerId)
set CloseButton[playerId] = BlzCreateFrame("ScriptDialogButton", BackgroundFrame[playerId], 0, 0)
set x = 0.34
set y = 0.20
call BlzFrameSetAbsPoint(CloseButton[playerId], FRAMEPOINT_TOPLEFT, x, y)
call BlzFrameSetAbsPoint(CloseButton[playerId], FRAMEPOINT_BOTTOMRIGHT, x + 0.12, y - 0.03)
call BlzFrameSetText(CloseButton[playerId], "|cffFCD20DClose|r")
set CloseTrigger[playerId] = CreateTrigger()
call BlzTriggerRegisterFrameEvent(CloseTrigger[playerId], CloseButton[playerId], FRAMEEVENT_CONTROL_CLICK)
call TriggerAddAction(CloseTrigger[playerId], function CloseFunction)
set handleId = GetHandleId(CloseTrigger[playerId])
call SaveInteger(h, handleId, 0, playerId)
// sync trigger
set SyncTrigger[playerId] = CreateTrigger()
call BlzTriggerRegisterPlayerSyncEvent(SyncTrigger[playerId], Player(playerId), PREFIX, false)
call TriggerAddAction(SyncTrigger[playerId], function UITriggerActionSyncData)
call BlzFrameSetVisible(BackgroundFrame[playerId], false)
endfunction
public function DestroyUI takes player whichPlayer returns nothing
local integer i = 0
local integer index = 0
local integer handleId = 0
local integer playerId = GetPlayerId(whichPlayer)
call BlzDestroyFrame(BackgroundFrame[playerId])
set BackgroundFrame[playerId] = null
call BlzDestroyFrame(TitleFrame[playerId])
set TitleFrame[playerId] = null
set i = 0
loop
exitwhen (i == MAX_SLOTS)
set index = GetButtonIndex(i, playerId)
call BlzDestroyFrame(SlotFrame[index])
set SlotFrame[index] = null
call BlzDestroyFrame(SlotBackdropFrame[index])
set SlotBackdropFrame[index] = null
set handleId = GetHandleId(SlotClickTrigger[index])
call FlushChildHashtable(h, handleId)
call DestroyTrigger(SlotClickTrigger[index])
set SlotClickTrigger[index] = null
set handleId = GetHandleId(SlotTooltipOnTrigger[index])
call FlushChildHashtable(h, handleId)
call DestroyTrigger(SlotTooltipOnTrigger[index])
set SlotTooltipOnTrigger[index] = null
set handleId = GetHandleId(SlotTooltipOffTrigger[index])
call FlushChildHashtable(h, handleId)
call DestroyTrigger(SlotTooltipOffTrigger[index])
set SlotTooltipOffTrigger[index] = null
call BlzDestroyFrame(SlotChargesBackgroundFrame[index])
set SlotChargesBackgroundFrame[index] = null
call BlzDestroyFrame(SlotChargesFrame[index])
set SlotChargesFrame[index] = null
call BlzDestroyFrame(SlotPageBackgroundFrame[index])
set SlotPageBackgroundFrame[index] = null
call BlzDestroyFrame(SlotPageFrame[index])
set SlotPageFrame[index] = null
set i = i + 1
endloop
call BlzDestroyFrame(TooltipFrame[playerId])
set TooltipFrame[playerId] = null
call BlzDestroyFrame(PageNameText[playerId])
set PageNameText[playerId] = null
call BlzDestroyFrame(SummonFrame[playerId])
set SummonFrame[playerId] = null
call BlzDestroyFrame(ItemGoldFrame[playerId])
set ItemGoldFrame[playerId] = null
call BlzDestroyFrame(ItemGoldIconFrame[playerId])
set ItemGoldIconFrame[playerId] = null
call BlzDestroyFrame(ItemLumberFrame[playerId])
set ItemLumberFrame[playerId] = null
call BlzDestroyFrame(ItemLumberIconFrame[playerId])
set ItemLumberIconFrame[playerId] = null
call BlzDestroyFrame(ItemFoodFrame[playerId])
set ItemFoodFrame[playerId] = null
call BlzDestroyFrame(ItemFoodIconFrame[playerId])
set ItemFoodIconFrame[playerId] = null
call BlzDestroyFrame(TooltipText[playerId])
set TooltipText[playerId] = null
call BlzDestroyFrame(NextPagesButton[playerId])
set NextPagesButton[playerId] = null
set handleId = GetHandleId(NextPagesTrigger[index])
call FlushChildHashtable(h, handleId)
call DestroyTrigger(NextPagesTrigger[playerId])
set NextPagesTrigger[playerId] = null
call BlzDestroyFrame(PreviousPagesButton[playerId])
set PreviousPagesButton[playerId] = null
set handleId = GetHandleId(PreviousPagesTrigger[index])
call FlushChildHashtable(h, handleId)
call DestroyTrigger(PreviousPagesTrigger[playerId])
set PreviousPagesTrigger[playerId] = null
call BlzDestroyFrame(CloseButton[playerId])
set CloseButton[playerId] = null
set handleId = GetHandleId(CloseTrigger[index])
call FlushChildHashtable(h, handleId)
call DestroyTrigger(CloseTrigger[playerId])
set CloseTrigger[playerId] = null
endfunction
private function TriggerConditionSelected takes nothing returns boolean
if (HasPagedButtons(GetTriggerUnit()) and GetPagedButtonsCount(GetTriggerUnit()) > 0 and IsPagedButtonsUIEnabledForPlayer(GetTriggerPlayer())) then
call ShowPagedButtonsUI(GetTriggerPlayer(), GetTriggerUnit())
endif
return false
endfunction
private function TriggerConditionChangePage takes nothing returns boolean
local unit shop = GetTriggerShop()
local integer i = 0
loop
exitwhen (i == bj_MAX_PLAYERS)
if (shop == UIShop[i]) then
call UpdateItemsForUI(Player(i))
endif
set i = i + 1
endloop
set shop = null
return false
endfunction
private function TriggerConditionDeath takes nothing returns boolean
local unit shop = GetTriggerUnit()
local integer i = 0
loop
exitwhen (i == bj_MAX_PLAYERS)
if (shop == UIShop[i]) then
call HidePagedButtonsUI(Player(i))
endif
set i = i + 1
endloop
set shop = null
return false
endfunction
private function TimerFunctionStart takes nothing returns nothing
local integer i = 0
local player slotPlayer = null
loop
exitwhen (i == bj_MAX_PLAYERS)
set slotPlayer = Player(i)
if (GetPlayerSlotState(slotPlayer) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(slotPlayer) == MAP_CONTROL_USER) then
call CreateUI(slotPlayer)
set selectionTrigger[i] = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(selectionTrigger[i], EVENT_PLAYER_UNIT_SELECTED)
call TriggerAddCondition(selectionTrigger[i], Condition(function TriggerConditionSelected))
set enabledForPlayer[i] = true
endif
set slotPlayer = null
set i = i + 1
endloop
call TriggerRegisterChangePagedButtons(changePageButtonsTrigger)
call TriggerAddCondition(changePageButtonsTrigger, Condition(function TriggerConditionChangePage))
call TriggerRegisterAnyUnitEventBJ(deathTrigger, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(deathTrigger, Condition(function TriggerConditionDeath))
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(), 0.0, false, function TimerFunctionStart)
call FrameLoaderAdd(function TimerFunctionStart)
endfunction
endlibrary
library PagedButtonsConfig
globals
constant integer BLACK_DRAGON_WHELP = 'nbdr'
constant integer BLACK_DRAKE = 'nbdk'
constant integer BLACK_DRAGON = 'nbwm'
constant integer BOOTS_OF_SPEED = 'bspd'
endglobals
function GetHeroGoldCost takes integer id returns integer
return 425
endfunction
function GetHeroLumberCost takes integer id returns integer
return 100
endfunction
// isit
// usit
public function GetStockInitialAfterStartDelay takes integer id returns integer
if (id == BLACK_DRAGON_WHELP) then
return 1
elseif (id == BLACK_DRAKE) then
return 1
elseif (id == BLACK_DRAGON) then
return 1
elseif (id == BOOTS_OF_SPEED) then
return 1
endif
return 1
endfunction
// isto
// usma
public function GetStockMaximum takes integer id returns integer
if (id == BLACK_DRAGON_WHELP) then
return 1
elseif (id == BLACK_DRAKE) then
return 1
elseif (id == BLACK_DRAGON) then
return 1
elseif (id == BOOTS_OF_SPEED) then
return 1
endif
return 1
endfunction
// istr
// usrg
public function GetStockReplenishInterval takes integer id returns integer
if (id == BLACK_DRAGON_WHELP) then
return 160
elseif (id == BLACK_DRAKE) then
return 310
elseif (id == BLACK_DRAGON) then
return 510
elseif (id == BOOTS_OF_SPEED) then
return 5 //60
endif
return 30
endfunction
// isst
// usst
public function GetStockStartDelay takes integer id returns integer
if (id == BLACK_DRAGON_WHELP) then
return 440
elseif (id == BLACK_DRAKE) then
return 440
elseif (id == BLACK_DRAGON) then
return 920
elseif (id == BOOTS_OF_SPEED) then
return 0
endif
return 0
endfunction
endlibrary
hook UnitDropItem AddItemToMarketplaceUnit
hook WidgetDropItem AddItemToMarketplaceWidget
function AddItemToMarketplaceUnit takes unit inUnit, integer inItemID returns nothing
set udg_ItemType = inItemID
call ConditionalTriggerExecute(gg_trg_Marketplace_Add_Item)
endfunction
function AddItemToMarketplaceWidget takes widget inWidget, integer inItemID returns nothing
set udg_ItemType = inItemID
call ConditionalTriggerExecute(gg_trg_Marketplace_Add_Item)
endfunction