- Joined
- Oct 12, 2011
- Messages
- 3,449
I'm currently writing a full screen inventory system. As always I will try to make it the best around. Not hoping to get DC actually (bcs I guess it's just impossible these days), I just have a plan to work on ORPG game, my dream from the first place.
okay..
it will be:
- MUI
- Supports multiple pages
- Near unlimited inventory slots
- Not supports bonusmod, but easy to implement any bonusmod
additional feature:
- Item macro
- Equipment system
- Drag icon feature
I will think the other things later, so here is the current code..
I guess it's still 5% done, some parts are still scratch (debuging purpose)
I'm currently wondering how to spread out small trackables around inventory window. If you got any idea please share.. thanks..
okay..
it will be:
- MUI
- Supports multiple pages
- Near unlimited inventory slots
- Not supports bonusmod, but easy to implement any bonusmod
additional feature:
- Item macro
- Equipment system
- Drag icon feature
I will think the other things later, so here is the current code..
I guess it's still 5% done, some parts are still scratch (debuging purpose)
JASS:
library UltimateInventory initializer ini requires Table, Track
globals
// Miscs
private constant real CAMERA_DISTANCE = 2500.0
private constant real LOCATION_X = -5600.0
private constant real LOCATION_Y = -6200.0
private constant real LOCATION_Z = 100.0
private constant real TOOLTIP_SIZE = 0.5
private constant string TRACKABLE_PATH = "war3mapImported\\32x32-Track.mdx"
private constant real TRACKABLE_SIZE = 32.0
private constant real TRACKABLE_AREA_MAX_X = 512.0
private constant real TRACKABLE_AREA_MIN_X = -5600.0
private constant real TRACKABLE_AREA_MAX_Y = 512.0
private constant real TRACKABLE_AREA_MIN_Y = -6200.0
private constant real WINDOW_DISTANCE = 800.0
// Destructables
private constant integer UI_BORDER_LEFT = 'SIS5'
private constant integer UI_BORDER_RIGHT = 'SIS6'
private constant integer UI_BORDER_UP = 'SIS7'
private constant integer UI_BORDER_DOWN = 'SIS8'
private constant integer UI_CORNER_UPPER_RIGHT = 'SIS1'
private constant integer UI_CORNER_UPPER_LEFT = 'SIS2'
private constant integer UI_CORNER_BOTTOM_RIGHT = 'SIS3'
private constant integer UI_CORNER_BOTTOM_LEFT = 'SIS4'
private constant integer UI_SLOT_EMPTY = 'SIS9'
private constant real UI_SPACE = 64.0
// Interfaces
private constant integer ITEM_SLOT_WIDTH = 5
private constant integer ITEM_SLOT_HEIGHT = 4
private constant integer ITEM_SLOT_PAGES = 5
private constant integer SPECIAL_SLOT_TOTAL = 4
private constant integer TOOLTIP_MAX_LENGTH = 32
endglobals
globals
public unit array CameraUnit
public real array CameraX
public real array CameraY
private integer SlotTotal = ITEM_SLOT_WIDTH * ITEM_SLOT_HEIGHT * ITEM_SLOT_PAGES
private integer ItemTotal = 0
private force PlayerForce = CreateForce()
private trigger OnClick = CreateTrigger()
private trigger OnHover = CreateTrigger()
private trigger ItemPickup = CreateTrigger()
private rect TrackArea
public Table array SlotX[11]
public Table array SlotY[11]
private Table array SlotIndex
private Table array SlotCategory
private Table array SlotCharge
private Table array SlotCooldown
private Table EmptySlot
private Table ItemIndex
private Table ItemIcon
private Table ItemCategory
private Table ItemCooldown
private Table ItemCharge
private Table TrackableX
private Table TrackableY
endglobals
private function GetEmptySlot takes integer hand returns integer
local integer i = 0
loop
exitwhen i == SlotTotal
if ItemIndex[hand].integer[i] == 0 then
return i
endif
set i = i + 1
endloop
return i
endfunction
function RegisterInventoryUnit takes unit whichUnit, boolean enableEquip, boolean enableMacro returns nothing
set EmptySlot.integer[GetHandleId(whichUnit)] = 1
endfunction
function RemoveInventoryUnit takes unit whichUnit returns nothing
local integer hand = GetHandleId(whichUnit)
set EmptySlot.integer[hand] = 0
endfunction
function OpenInventoryWindow takes unit whichUnit, boolean isOpen returns boolean
if EmptySlot.integer[GetHandleId(whichUnit)] > 0 then
if isOpen then
else
endif
endif
return false
endfunction
function RegisterInventoryItem takes integer itemID, integer itemIcon, integer itemCategory, integer itemMaxCharge, real itemCooldown, boolean itemUseable returns nothing
set ItemTotal = ItemTotal + 1
set ItemIndex.integer[itemID] = ItemTotal
set ItemIcon.integer[ItemTotal] = itemIcon
set ItemCategory.integer[ItemTotal] = itemCategory
set ItemCharge.integer[ItemTotal] = itemMaxCharge
set ItemCooldown.real[ItemTotal] = itemCooldown
endfunction
function SetItemBonus takes integer itemID, integer bonusDex, real bonusAmount returns nothing
endfunction
function SetItemDescription takes integer itemID, string itemDescription returns nothing
endfunction
function AddItemToInventory takes unit whichUnit, integer itemID returns boolean
local integer dex = ItemIndex.integer[itemID]
local integer hand = GetHandleId(whichUnit)
local integer slot = EmptySlot[hand] - 1
if EmptySlot.integer[hand] > 0 and EmptySlot.integer[hand] <= SlotTotal then
set SlotIndex[hand].integer[slot] = dex
set EmptySlot.integer[hand] = GetEmptySlot(hand) + 1
return true
endif
return false
endfunction
function AddItemToInventoryAtSlot takes unit whichUnit, integer itemID, integer slotIndex returns boolean
local integer dex = ItemIndex.integer[itemID]
local integer hand = GetHandleId(whichUnit)
set EmptySlot.integer[hand] = slotIndex
if AddItemToInventory(whichUnit, itemID) then
return true
endif
return false
endfunction
private function onPickup takes nothing returns boolean
local integer id = GetItemTypeId(GetManipulatedItem())
call AddItemToInventory(GetTriggerUnit(), id)
return false
endfunction
private function onClick takes nothing returns boolean
return false
endfunction
private function onHover takes nothing returns boolean
return false
endfunction
private function initInterface takes integer pn returns nothing
local integer i = 0
local integer j
local integer ext_i = 8 + ITEM_SLOT_HEIGHT
local integer ext_j = 1 + ITEM_SLOT_WIDTH
local integer dex
local real x = LOCATION_X + ((ext_j + 4) * UI_SPACE * pn) + WINDOW_DISTANCE * pn
loop
exitwhen i > ext_i
set j = 0
loop
exitwhen j > ext_j
if i == 0 then
if j == 0 then
call CreateDeadDestructableZ(UI_CORNER_BOTTOM_LEFT, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
elseif j == ext_j then
call CreateDeadDestructableZ(UI_CORNER_BOTTOM_RIGHT, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
else
call CreateDeadDestructableZ(UI_BORDER_DOWN, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
endif
elseif i == ext_i then
if j == 0 then
call CreateDeadDestructableZ(UI_CORNER_UPPER_LEFT, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
elseif j == ext_j then
call CreateDeadDestructableZ(UI_CORNER_UPPER_RIGHT, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
else
call CreateDeadDestructableZ(UI_BORDER_UP, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
endif
else
if j == 0 then
call CreateDeadDestructableZ(UI_BORDER_LEFT, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
elseif j == ext_j then
call CreateDeadDestructableZ(UI_BORDER_RIGHT, x + UI_SPACE * j, LOCATION_Y + UI_SPACE * i, LOCATION_Z, 270., 1., 0)
endif
if i < 1 + ITEM_SLOT_HEIGHT then
if j > 0 and j <= ITEM_SLOT_WIDTH then
set dex = ITEM_SLOT_HEIGHT * ITEM_SLOT_WIDTH - ITEM_SLOT_WIDTH * i + j - 1
set SlotX[pn].real[dex] = x + UI_SPACE * j
set SlotY[pn].real[dex] = LOCATION_Y + UI_SPACE * i
call CreateDeadDestructableZ(UI_SLOT_EMPTY, SlotX[pn].real[dex], SlotY[pn].real[dex], LOCATION_Z + 32., 270., 1., 0)
endif
endif
endif
set j = j + 1
endloop
set i = i + 1
endloop
endfunction
private function initTrackable takes nothing returns nothing
local integer i = 0
local integer j
local integer hand
local real x// = LOCATION_X - TRACKABLE_EXPAND_AREA
local real y// = LOCATION_Y - TRACKABLE_EXPAND_AREA
local trackable track
loop
set j = 0
loop
set track = CreateTrackable(TRACKABLE_PATH, x + TRACKABLE_SIZE * j, y + TRACKABLE_SIZE * i, 270.)
call TriggerRegisterTrackableHitEvent(OnClick, track)
call TriggerRegisterTrackableTrackEvent(OnHover, track)
set track = null
set j = j + 1
endloop
set i = i + 1
endloop
endfunction
private function ini takes nothing returns nothing
local integer i = 0
loop
exitwhen i > 11
//if GetPlayerController(Player(i)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
call ForceAddPlayer(PlayerForce, Player(i))
set SlotX[i] = Table.create()
set SlotY[i] = Table.create()
call initInterface(i)
//endif
set i = i + 1
endloop
call TriggerRegisterUnitEvent(ItemPickup, null, EVENT_UNIT_PICKUP_ITEM)
call TriggerAddCondition(OnClick, Condition(function onClick))
call TriggerAddCondition(OnHover, Condition(function onHover))
call TriggerAddCondition(ItemPickup, Condition(function onPickup))
set TrackableX[i] = Table.create()
set TrackableY[i] = Table.create()
set EmptySlot = Table.create()
set ItemIndex = Table.create()
set ItemIcon = Table.create()
set ItemCategory = Table.create()
set ItemCooldown = Table.create()
set ItemCharge = Table.create()
call initTrackable()
endfunction
endlibrary
I'm currently wondering how to spread out small trackables around inventory window. If you got any idea please share.. thanks..