mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
Browse field, locked & paginated container support
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
PageButton < Button
|
||||
size: 30 18
|
||||
margin: 1
|
||||
|
||||
|
||||
ContainerWindow < MiniWindow
|
||||
height: 150
|
||||
|
||||
@@ -25,6 +30,35 @@ ContainerWindow < MiniWindow
|
||||
$pressed:
|
||||
image-clip: 42 28 14 14
|
||||
|
||||
Panel
|
||||
id: pagePanel
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: miniwindowTopBar.bottom
|
||||
height: 20
|
||||
margin: 2 3 0 3
|
||||
background: #00000066
|
||||
visible: false
|
||||
|
||||
Label
|
||||
id: pageLabel
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin-top: 2
|
||||
text-auto-resize: true
|
||||
|
||||
PageButton
|
||||
id: prevPageButton
|
||||
text: <
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
|
||||
PageButton
|
||||
id: nextPageButton
|
||||
text: >
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
|
||||
MiniWindowContents
|
||||
padding-right: 0
|
||||
layout:
|
||||
|
@@ -3,9 +3,8 @@ function init()
|
||||
|
||||
connect(Container, { onOpen = onContainerOpen,
|
||||
onClose = onContainerClose,
|
||||
onAddItem = onContainerAddItem,
|
||||
onUpdateItem = onContainerUpdateItem,
|
||||
onRemoveItem = onContainerRemoveItem })
|
||||
onSizeChange = onContainerChangeSize,
|
||||
onUpdateItem = onContainerUpdateItem })
|
||||
connect(Game, { onGameEnd = clean() })
|
||||
|
||||
reloadContainers()
|
||||
@@ -14,9 +13,8 @@ end
|
||||
function terminate()
|
||||
disconnect(Container, { onOpen = onContainerOpen,
|
||||
onClose = onContainerClose,
|
||||
onAddItem = onContainerAddItem,
|
||||
onUpdateItem = onContainerUpdateItem,
|
||||
onRemoveItem = onContainerRemoveItem })
|
||||
onSizeChange = onContainerChangeSize,
|
||||
onUpdateItem = onContainerUpdateItem })
|
||||
disconnect(Game, { onGameEnd = clean() })
|
||||
end
|
||||
|
||||
@@ -46,6 +44,38 @@ function refreshContainerItems(container)
|
||||
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
||||
itemWidget:setItem(container:getItem(slot))
|
||||
end
|
||||
|
||||
if container:hasPages() then
|
||||
refreshContainerPages(container)
|
||||
end
|
||||
end
|
||||
|
||||
function toggleContainerPages(containerWindow, pages)
|
||||
containerWindow:getChildById('miniwindowScrollBar'):setMarginTop(pages and 42 or 22)
|
||||
containerWindow:getChildById('contentsPanel'):setMarginTop(pages and 42 or 22)
|
||||
containerWindow:getChildById('pagePanel'):setVisible(pages)
|
||||
end
|
||||
|
||||
function refreshContainerPages(container)
|
||||
local currentPage = 1 + math.floor(container:getFirstIndex() / container:getCapacity())
|
||||
local pages = 1 + math.floor(math.max(0, (container:getSize() - 1)) / container:getCapacity())
|
||||
container.window:recursiveGetChildById('pageLabel'):setText(string.format('Page %i of %i', currentPage, pages))
|
||||
|
||||
local prevPageButton = container.window:recursiveGetChildById('prevPageButton')
|
||||
if currentPage == 1 then
|
||||
prevPageButton:setEnabled(false)
|
||||
else
|
||||
prevPageButton:setEnabled(true)
|
||||
prevPageButton.onClick = function() g_game.seekInContainer(container:getId(), container:getFirstIndex() - container:getCapacity()) end
|
||||
end
|
||||
|
||||
local nextPageButton = container.window:recursiveGetChildById('nextPageButton')
|
||||
if currentPage >= pages then
|
||||
nextPageButton:setEnabled(false)
|
||||
else
|
||||
nextPageButton:setEnabled(true)
|
||||
nextPageButton.onClick = function() g_game.seekInContainer(container:getId(), container:getFirstIndex() + container:getCapacity()) end
|
||||
end
|
||||
end
|
||||
|
||||
function onContainerOpen(container, previousContainer)
|
||||
@@ -88,11 +118,18 @@ function onContainerOpen(container, previousContainer)
|
||||
itemWidget:setItem(container:getItem(slot))
|
||||
itemWidget:setMargin(0)
|
||||
itemWidget.position = container:getSlotPosition(slot)
|
||||
|
||||
if not container:isUnlocked() then
|
||||
itemWidget:setBorderColor('red')
|
||||
end
|
||||
end
|
||||
|
||||
container.window = containerWindow
|
||||
container.itemsPanel = containerPanel
|
||||
|
||||
toggleContainerPages(containerWindow, container:hasPages())
|
||||
refreshContainerPages(container)
|
||||
|
||||
local layout = containerPanel:getLayout()
|
||||
local cellSize = layout:getCellSize()
|
||||
containerWindow:setContentMinimumHeight(cellSize.height)
|
||||
@@ -110,7 +147,7 @@ function onContainerClose(container)
|
||||
destroy(container)
|
||||
end
|
||||
|
||||
function onContainerAddItem(container, slot, item)
|
||||
function onContainerChangeSize(container, size)
|
||||
if not container.window then return end
|
||||
refreshContainerItems(container)
|
||||
end
|
||||
@@ -120,8 +157,3 @@ function onContainerUpdateItem(container, slot, item, oldItem)
|
||||
local itemWidget = container.itemsPanel:getChildById('item' .. slot)
|
||||
itemWidget:setItem(item)
|
||||
end
|
||||
|
||||
function onContainerRemoveItem(container, slot, item)
|
||||
if not container.window then return end
|
||||
refreshContainerItems(container)
|
||||
end
|
||||
|
@@ -467,6 +467,10 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||
if useThing:isRotateable() then
|
||||
menu:addOption(tr('Rotate'), function() g_game.rotate(useThing) end)
|
||||
end
|
||||
|
||||
if g_game.getFeature(GameBrowseField) and useThing:getPosition().x ~= 0xffff then
|
||||
menu:addOption(tr('Browse Field'), function() g_game.browseField(useThing:getPosition()) end)
|
||||
end
|
||||
end
|
||||
|
||||
if lookThing and not lookThing:isCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
|
||||
|
@@ -117,6 +117,8 @@ GamePVPMode = 50
|
||||
GameWritableDate = 51
|
||||
GameAdditionalVipInfo = 52
|
||||
GameSpritesAlphaChannel = 56
|
||||
GamePremiumExpiration = 57
|
||||
GameBrowseField = 58
|
||||
|
||||
TextColors = {
|
||||
red = '#f55e5e', --'#c83200'
|
||||
|
Reference in New Issue
Block a user