/* ----------------------------------- *//*
Version: 0.1
Author: Anachron
Date: 04th Jan 2010
Release information:
Do not use this library without
copyright information.
Copyright 2009
This is the general container.
*/
/* ----------------------------------- */
library CIAll requires Table, AdvancedTable, CIWindow, CustomWindow, CIContent,
//! textmacro CIAll_NewButton takes DEST_ID, X, Y, DESTSAFE, TRACKSAFE, WINDOW, PLAYER, SIZE
set $TRACKSAFE$ = $WINDOW$.createTrack($PLAYER$, "CustomWindow\\Track75.mdx", CI_UI_BASE_X +$X$, CI_UI_BASE_Y +$Y$, 0., 0.)
set $DESTSAFE$ = $WINDOW$.createDestructable($PLAYER$, $DEST_ID$, $SIZE$ +.01, CI_UI_BASE_X +$X$, CI_UI_BASE_Y +$Y$, 0., 270)
//! endtextmacro
struct CIAll
public IntegerTable Buttons = 0
public IntegerTable Tracks = 0
public BooleanTable HasItem = 0
public ItemTable Items = 0
public CustomWindow window = 0
public CustomInventory inventory = 0
public CIContent content = 0
public Table ItemToSlot = 0
public Table SlotToItem = 0
public integer maximum = 0
public stub method init takes nothing returns nothing
endmethod
public stub method refresh takes nothing returns nothing
endmethod
public stub method pick takes CustomItem ci returns nothing
endmethod
public stub method pickCond takes CustomItem ci, integer slot returns boolean
return true
endmethod
public stub method drop takes CustomItem ci returns nothing
endmethod
public stub method dropCond takes CustomItem ci, integer slot returns boolean
return true
endmethod
public stub method getSlotIcon takes integer slot returns integer
return -1
endmethod
public static method create takes integer m, CustomWindow w, CustomInventory i, CIContent c returns thistype
local thistype this = thistype.allocate()
set .maximum = m
set .window = w
set .inventory = i
set .content = c
set Buttons = IntegerTable.create()
set Tracks = IntegerTable.create()
set HasItem = BooleanTable.create()
set Items = ItemTable.create()
set ItemToSlot = Table.create()
set SlotToItem = Table.create()
return this
endmethod
public method refreshSlot takes integer slot returns nothing
local real x = CWTrackAble(.Tracks[slot]).getX()
local real y = CWTrackAble(.Tracks[slot]).getY()
local player slotPlayer = GetOwningPlayer(.inventory.getOwner())
local integer slotDest = .getSlotIcon(slot)
call CWDestructable(.Buttons[slot]).destroy()
set .Buttons[slot] = .window.createDestructable(slotPlayer, slotDest, .76, x, y, .1, 270)
endmethod
public method addItemToSlot takes CustomItem ci, integer slot returns boolean
local integer ID = GetHandleId(ci.getHandle())
if not .HasItem[slot] then
if .pickCond(ci, slot) then
set .ItemToSlot[ID] = slot
set .SlotToItem[slot] = ID
set .Items[slot] = ci.getHandle()
set .HasItem[slot] = true
call .refreshSlot(slot)
call .pick(ci)
return true
else
static if LIBRARY_CIError then
call CIError.create(4, 1, GetOwningPlayer(.inventory.getOwner()), "You can't equip this item.")
else
debug call BJDebugMsg("|cffffcc00" + SCOPE_PREFIX + "Error|r: " + "Can't equip item!")
endif
endif
else
static if LIBRARY_CIError then
call CIError.create(4, 1, GetOwningPlayer(.inventory.getOwner()), "This slot is already in use.")
else
debug call BJDebugMsg("|cffffcc00" + SCOPE_PREFIX + "Error|r: " + "This slot is already in use!")
endif
endif
return false
endmethod
public method addItem takes CustomItem ci returns boolean
local integer i = 0
loop
exitwhen i >= .maximum
if not .HasItem[i] then
return .addItemToSlot(ci, i)
endif
set i = i +1
endloop
return false
endmethod
public method moveItemToSlot takes CustomItem ci, integer targ returns boolean
local integer id = GetHandleId(ci.getHandle())
local integer slot = .ItemToSlot[id]
if .HasItem[targ] then
return false
endif
call .removeItemFromSlot(slot)
call .addItemToSlot(ci, targ)
return true
endmethod
public method switchItems takes CustomItem left, CustomItem right returns boolean
local integer slotOne = getItemSlot(left)
local integer idOne = GetHandleId(left.getHandle())
local integer slotTwo = getItemSlot(right)
local integer idTwo = GetHandleId(right.getHandle())
if slotOne != -1 and slotTwo != -1 then
set .ItemToSlot[idOne] = slotTwo
set .SlotToItem[slotOne] = idTwo
set .Items[slotOne] = right.getHandle()
set .HasItem[slotOne] = true
set .ItemToSlot[idTwo] = slotOne
set .SlotToItem[slotTwo] = idOne
set .Items[slotTwo] = left.getHandle()
set .HasItem[slotTwo] = true
call .refreshSlot(slotOne)
call .refreshSlot(slotTwo)
return true
endif
return false
endmethod
public method removeItemFromSlot takes integer slot returns boolean
local CustomItem slotItem = CustomItem.load(.SlotToItem[slot])
if not .HasItem[slot] then
return false
endif
if not .dropCond(slotItem, slot) then
static if LIBRARY_CIError then
call CIError.create(4, 1, GetOwningPlayer(.inventory.getOwner()), "You can't drop this item.")
else
debug call BJDebugMsg("|cffffcc00" + SCOPE_PREFIX + "Error|r: " + "You can't drop this item.")
endif
return false
endif
call .ItemToSlot.flush(GetHandleId(.Items[slot]))
call .SlotToItem.flush(slot)
set .HasItem[slot] = false
set .Items[slot] = null
call .refreshSlot(slot)
call .drop(slotItem)
return true
endmethod
public method removeItem takes CustomItem ci returns boolean
return .removeItemFromSlot(.getItemSlot(ci))
endmethod
public method getItemSlot takes CustomItem ci returns integer
local integer id = GetHandleId(ci.getHandle())
if not .ItemToSlot.exists(id) then
return -1
endif
return .ItemToSlot[id]
endmethod
public method getSlotItem takes integer slot returns CustomItem
return CustomItem.load(.SlotToItem[slot])
endmethod
public method hasItem takes CustomItem ci returns boolean
return .getItemSlot(ci) != -1
endmethod
public method hasSlotItem takes integer slot returns boolean
return .SlotToItem[slot] != 0
endmethod
public method check takes CustomItem ci returns boolean
return not .hasItem(ci)
endmethod
public method compareTracks takes CWTrackAble eventTrack, integer slot returns boolean
return .Tracks[slot] == eventTrack
endmethod
endstruct
endlibrary