mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
restore containers
* implemente Container class * restore module containers * add lua bindings for std::map * improve grid layout * fixes in UIItem rendering * changes in miniwindow design
This commit is contained in:
@@ -17,8 +17,9 @@ Module
|
||||
- game_skills
|
||||
- game_inventory
|
||||
- game_combatcontrols
|
||||
- game_battle
|
||||
- game_containers
|
||||
- game_viplist
|
||||
- game_battle
|
||||
- game_hotkeys
|
||||
|
||||
@onLoad: |
|
||||
|
@@ -140,10 +140,10 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu
|
||||
if useThing then
|
||||
if useThing:isContainer() then
|
||||
if useThing:getParentContainer() then
|
||||
menu:addOption('Open', function() g_game.open(useThing, useThing:getContainerId()) end)
|
||||
menu:addOption('Open in new window', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
menu:addOption('Open', function() g_game.open(useThing, useThing:getParentContainer()) end)
|
||||
menu:addOption('Open in new window', function() g_game.open(useThing, nil) end)
|
||||
else
|
||||
menu:addOption('Open', function() g_game.open(useThing, Containers.getFreeContainerId()) end)
|
||||
menu:addOption('Open', function() g_game.open(useThing, nil) end)
|
||||
end
|
||||
else
|
||||
if useThing:isMultiUse() then
|
||||
@@ -256,10 +256,10 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
|
||||
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||
if useThing:isContainer() then
|
||||
if useThing:getParentContainer() then
|
||||
g_game.open(useThing, useThing:getContainerId())
|
||||
g_game.open(useThing, useThing:getParentContainer())
|
||||
return true
|
||||
else
|
||||
g_game.open(useThing, Containers.getFreeContainerId())
|
||||
g_game.open(useThing, nil)
|
||||
return true
|
||||
end
|
||||
elseif useThing:isMultiUse() then
|
||||
@@ -281,10 +281,10 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
|
||||
return true
|
||||
elseif multiUseThing:isContainer() then
|
||||
if multiUseThing:getParentContainer() then
|
||||
g_game.open(multiUseThing, multiUseThing:getContainerId())
|
||||
g_game.open(multiUseThing, multiUseThing:getParentContainer())
|
||||
return true
|
||||
else
|
||||
g_game.open(multiUseThing, Containers.getFreeContainerId())
|
||||
g_game.open(multiUseThing, nil)
|
||||
return true
|
||||
end
|
||||
elseif multiUseThing:isMultiUse() then
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
Binary file not shown.
Before Width: | Height: | Size: 626 B After Width: | Height: | Size: 758 B |
@@ -1,5 +1,6 @@
|
||||
Item < UIItem
|
||||
size: 34 34
|
||||
padding: 1
|
||||
image-source: /core_styles/styles/images/item.png
|
||||
font: verdana-11px-rounded
|
||||
border-color: white
|
||||
|
@@ -3,7 +3,7 @@ MiniWindow < UIMiniWindow
|
||||
icon-rect: 4 4 16 16
|
||||
width: 192
|
||||
height: 200
|
||||
text-offset: 26 5
|
||||
text-offset: 24 5
|
||||
text-align: topLeft
|
||||
margin-bottom: 2
|
||||
move-policy: free updated
|
||||
@@ -82,7 +82,7 @@ MiniWindowContents < ScrollablePanel
|
||||
id: contentsPanel
|
||||
anchors.fill: parent
|
||||
margin-right: 14
|
||||
padding: 25 6 6 6
|
||||
padding: 24 3 3 5
|
||||
vertical-scrollbar: miniwindowScrollBar
|
||||
|
||||
BorderlessGameWindow < UIWindow
|
||||
|
@@ -36,7 +36,7 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
|
||||
|
||||
-- public functions
|
||||
function Battle.init()
|
||||
battleWindow = displayUI('battle.otui', GameInterface.getRightPanel())
|
||||
battleWindow = displayUI('battle.otui', GameInterface.getLeftPanel())
|
||||
battleButton = TopMenu.addGameToggleButton('battleButton', 'Battle (Ctrl+B)', 'battle.png', Battle.toggle)
|
||||
battleButton:setOn(true)
|
||||
Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)
|
||||
|
@@ -1,11 +1,35 @@
|
||||
MiniWindow
|
||||
size: 200 221
|
||||
ContainerWindow < MiniWindow
|
||||
height: 150
|
||||
|
||||
layout:
|
||||
type: grid
|
||||
cell-size: 34 34
|
||||
cell-spacing: 5
|
||||
num-columns: 4
|
||||
num-lines: 5
|
||||
UIItem
|
||||
id: containerItemWidget
|
||||
virtual: true
|
||||
item-id: 3253
|
||||
size: 32 32
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
margin-top: -6
|
||||
margin-left: -6
|
||||
|
||||
UIButton
|
||||
id: upButton
|
||||
anchors.top: minimizeButton.top
|
||||
anchors.right: minimizeButton.left
|
||||
margin-right: 3
|
||||
size: 14 14
|
||||
image-source: /game/images/miniwindowbuttons.png
|
||||
image-clip: 42 0 14 14
|
||||
|
||||
$hover:
|
||||
image-clip: 42 14 14 14
|
||||
|
||||
$pressed:
|
||||
image-clip: 42 28 14 14
|
||||
|
||||
MiniWindowContents
|
||||
padding: 27 6 6 8
|
||||
layout:
|
||||
type: grid
|
||||
cell-size: 34 34
|
||||
flow: true
|
||||
auto-spacing: true
|
||||
|
@@ -1,138 +1,90 @@
|
||||
Containers = {}
|
||||
|
||||
-- private variables
|
||||
local containers = {}
|
||||
|
||||
-- public functions
|
||||
function Containers.clean()
|
||||
containers = {}
|
||||
local function refreshContainerItems(container)
|
||||
for slot=0,container:getCapacity()-1 do
|
||||
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
||||
itemWidget:setItem(container:getItem(slot))
|
||||
end
|
||||
end
|
||||
|
||||
function Containers.getFreeContainerId()
|
||||
for i=0,15 do
|
||||
if not containers[i] then
|
||||
return i
|
||||
end
|
||||
local function onContainerOpen(container, previousContainer)
|
||||
local containerWindow
|
||||
if previousContainer then
|
||||
containerWindow = previousContainer.window
|
||||
previousContainer.window = nil
|
||||
previousContainer.itemsPanel = nil
|
||||
else
|
||||
containerWindow = createWidget('ContainerWindow', GameInterface.getRightPanel())
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- hooked events
|
||||
function Containers.onOpenContainer(containerId, itemId, name, capacity, hasParent, items)
|
||||
local container = containers[containerId]
|
||||
if container then
|
||||
GameInterface.getRightPanel():removeChild(container)
|
||||
containerWindow:setId('container' .. container:getId())
|
||||
local containerPanel = containerWindow:getChildById('contentsPanel')
|
||||
local containerItemWidget = containerWindow:getChildById('containerItemWidget')
|
||||
containerWindow.onClose = function()
|
||||
g_game.close(container)
|
||||
containerWindow:hide()
|
||||
end
|
||||
|
||||
container = displayUI('container.otui', GameInterface.getRightPanel())
|
||||
local upButton = containerWindow:getChildById('upButton')
|
||||
upButton.onClick = function()
|
||||
g_game.openParent(container)
|
||||
end
|
||||
upButton:setVisible(container:hasParent())
|
||||
|
||||
local name = container:getName()
|
||||
name = name:sub(1,1):upper() .. name:sub(2)
|
||||
container:setText(name)
|
||||
containerWindow:setText(name)
|
||||
|
||||
-- set icon, itemid
|
||||
-- closebutton
|
||||
-- resize
|
||||
if hasParent then
|
||||
-- parent button
|
||||
containerItemWidget:setItemId(container:getItemId())
|
||||
|
||||
containerPanel:destroyChildren()
|
||||
for slot=0,container:getCapacity()-1 do
|
||||
local itemWidget = createWidget('Item', containerPanel)
|
||||
itemWidget:setId('item' .. slot)
|
||||
itemWidget:setItem(container:getItem(slot))
|
||||
itemWidget.position = container:getSlotPosition(slot)
|
||||
end
|
||||
|
||||
container.itemCount = #items
|
||||
container.capacity = capacity
|
||||
|
||||
for i=1,capacity do
|
||||
local itemWidget = UIItem.create()
|
||||
itemWidget:setStyle('Item')
|
||||
container:addChild(itemWidget)
|
||||
itemWidget.position = {x=65535, y=containerId+64, z=i-1}
|
||||
|
||||
if i <= #items then
|
||||
local item = items[i]
|
||||
item:setPosition(itemWidget.position)
|
||||
itemWidget:setItem(item)
|
||||
end
|
||||
end
|
||||
|
||||
containers[containerId] = container
|
||||
container.window = containerWindow
|
||||
container.itemsPanel = containerPanel
|
||||
end
|
||||
|
||||
function Containers.onCloseContainer(containerId)
|
||||
local container = containers[containerId]
|
||||
if container then
|
||||
GameInterface.getRightPanel():removeChild(container)
|
||||
local function onContainerClose(container)
|
||||
local containerWindow = container.window
|
||||
if containerWindow then
|
||||
containerWindow:destroy()
|
||||
end
|
||||
containers[containerId] = nil
|
||||
end
|
||||
|
||||
function Containers.onContainerAddItem(containerId, item)
|
||||
local container = containers[containerId]
|
||||
if not container or not item or container.itemCount >= container.capacity then return end
|
||||
local function onContainerAddItem(container, slot, item)
|
||||
refreshContainerItems(container)
|
||||
end
|
||||
|
||||
local i = container.itemCount
|
||||
while i >= 1 do
|
||||
local itemWidget = container:getChildByIndex(i)
|
||||
if not itemWidget then return end
|
||||
|
||||
local nextItemWidget = container:getChildByIndex(i+1)
|
||||
if not nextItemWidget then return end
|
||||
|
||||
local swapItem = itemWidget:getItem()
|
||||
if swapItem then
|
||||
swapItem:setPosition(nextItemWidget.position)
|
||||
nextItemWidget:setItem(swapItem)
|
||||
end
|
||||
|
||||
i = i - 1
|
||||
end
|
||||
|
||||
local itemWidget = container:getChildByIndex(1)
|
||||
if not itemWidget then return end
|
||||
item:setPosition(itemWidget.position)
|
||||
local function onContainerUpdateItem(container, slot, item, oldItem)
|
||||
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
||||
itemWidget:setItem(item)
|
||||
|
||||
container.itemCount = container.itemCount + 1
|
||||
end
|
||||
|
||||
function Containers.onContainerUpdateItem(containerId, slot, item)
|
||||
local container = containers[containerId]
|
||||
if not container then return end
|
||||
|
||||
local itemWidget = container:getChildByIndex(slot + 1)
|
||||
if not itemWidget then return end
|
||||
itemWidget:setItem(item)
|
||||
item:setPosition(itemWidget.position)
|
||||
local function onContainerRemoveItem(container, slot, item)
|
||||
refreshContainerItems(container)
|
||||
end
|
||||
|
||||
function Containers.onContainerRemoveItem(containerId, slot)
|
||||
local container = containers[containerId]
|
||||
if not container then return end
|
||||
function Containers.init()
|
||||
importStyle 'container.otui'
|
||||
|
||||
local itemWidget = container:getChildByIndex(slot+1)
|
||||
if not itemWidget then return end
|
||||
itemWidget:setItem(nil)
|
||||
|
||||
for i=slot,container.itemCount-2 do
|
||||
local itemWidget = container:getChildByIndex(i+1)
|
||||
if not itemWidget then return end
|
||||
|
||||
local nextItemWidget = container:getChildByIndex(i+2)
|
||||
if not nextItemWidget then return end
|
||||
|
||||
local item = nextItemWidget:getItem()
|
||||
local pos = item:getPosition()
|
||||
pos.z = pos.z - 1
|
||||
item:setPosition(pos)
|
||||
|
||||
itemWidget:setItem(item)
|
||||
nextItemWidget:setItem(nil)
|
||||
end
|
||||
|
||||
container.itemCount = container.itemCount - 1
|
||||
connect(Container, { onOpen = onContainerOpen,
|
||||
onClose = onContainerClose,
|
||||
onAddItem = onContainerAddItem,
|
||||
onUpdateItem = onContainerUpdateItem,
|
||||
onRemoveItem = onContainerRemoveItem })
|
||||
end
|
||||
|
||||
connect(g_game, { onGameStart = Containers.clean,
|
||||
onGameEnd = Containers.clean,
|
||||
onOpenContainer = Containers.onOpenContainer,
|
||||
onCloseContainer = Containers.onCloseContainer,
|
||||
onContainerAddItem = Containers.onContainerAddItem,
|
||||
onContainerUpdateItem = Containers.onContainerUpdateItem,
|
||||
onContainerRemoveItem = Containers.onContainerRemoveItem })
|
||||
function Containers.terminate()
|
||||
disconnect(Container, { onOpen = onContainerOpen,
|
||||
onClose = onContainerClose,
|
||||
onAddItem = onContainerAddItem,
|
||||
onUpdateItem = onContainerUpdateItem,
|
||||
onRemoveItem = onContainerRemoveItem })
|
||||
end
|
||||
|
||||
function Containers.clean()
|
||||
|
||||
end
|
||||
|
@@ -4,5 +4,12 @@ Module
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
||||
dependecies:
|
||||
- game
|
||||
|
||||
@onLoad: |
|
||||
dofile 'containers'
|
||||
Containers.init()
|
||||
|
||||
@onUnload: |
|
||||
Containers.terminate()
|
||||
|
Reference in New Issue
Block a user