diff --git a/modules/core_lib/ui/radiogroup.lua b/modules/core_lib/ui/radiogroup.lua index ffc7d76f..f3415e83 100644 --- a/modules/core_lib/ui/radiogroup.lua +++ b/modules/core_lib/ui/radiogroup.lua @@ -8,31 +8,24 @@ end function RadioGroup:destroy() for k,widget in pairs(self.widgets) do - widget.onMousePress = nil + widget.onClick = nil end self.widgets = {} end function RadioGroup:addWidget(widget) table.insert(self.widgets, widget) - widget.onMousePress = function(widget) self:selectWidget(widget) end + widget.onClick = function(widget) self:selectWidget(widget) end end function RadioGroup:removeWidget(widget) if self.selectedWidget == widget then self:selectWidget(nil) end - widget.onMousePress = nil + widget.onClick = nil table.removevalue(self.widgets, widget) end -function RadioGroup:destroy() - for k,widget in pairs(self.widgets) do - widget.onMousePress = nil - end - self.widgets = {} -end - function RadioGroup:selectWidget(selectedWidget) if selectedWidget == self.selectedWidget then return end diff --git a/modules/core_lib/widgets/uicheckbox.lua b/modules/core_lib/widgets/uicheckbox.lua index 016551f5..38c235ba 100644 --- a/modules/core_lib/widgets/uicheckbox.lua +++ b/modules/core_lib/widgets/uicheckbox.lua @@ -7,7 +7,6 @@ function UICheckBox.create() return checkbox end -function UICheckBox:onMousePress(mousePos, mouseButton) +function UICheckBox:onClick() self:setChecked(not self:isChecked()) - return true end diff --git a/modules/core_styles/styles/panels.otui b/modules/core_styles/styles/panels.otui index 87b7fcd6..9646dced 100644 --- a/modules/core_styles/styles/panels.otui +++ b/modules/core_styles/styles/panels.otui @@ -7,3 +7,7 @@ ScrollablePanel < UIScrollArea FlatPanel < Panel image-source: /core_styles/styles/images/panel_flat.png image-border: 1 + +ScrollableFlatPanel < ScrollablePanel + image-source: /core_styles/styles/images/panel_flat.png + image-border: 1 \ No newline at end of file diff --git a/modules/core_styles/styles/separators.otui b/modules/core_styles/styles/separators.otui index 985518a5..bb0a83bf 100644 --- a/modules/core_styles/styles/separators.otui +++ b/modules/core_styles/styles/separators.otui @@ -4,3 +4,10 @@ HorizontalSeparator < UIWidget height: 2 phantom: true focusable: false + +VerticalSeparator < UIWidget + image-source: /core_styles/styles/images/horizontal_separator.png + image-border-left: 2 + width: 2 + phantom: true + focusable: false diff --git a/modules/game_playertrade/playertrade.lua b/modules/game_playertrade/playertrade.lua index eb85db3c..0caa937a 100644 --- a/modules/game_playertrade/playertrade.lua +++ b/modules/game_playertrade/playertrade.lua @@ -7,26 +7,55 @@ PlayerTrade = {} local tradeWindow local function createTrade() - if tradeWindow then - tradeWindow:destroy() - tradeWindow = nil + tradeWindow = createWidget('TradeWindow', GameInterface.getRightPanel()) + tradeWindow.onClose = function() + g_game.rejectTrade() + tradeWindow:hide() end - - tradeWindow = createWidget('TradeWindow', rootWidget) end -local function onOwnTrade(name, items) - local firstItem = items[1] +local function fillTrade(name, items, counter) + if not tradeWindow then + createTrade() + end local tradeItemWidget = tradeWindow:getChildById('tradeItem') - tradeItemWidget:setItem(firstItem) + tradeItemWidget:setItemId(items[1]:getId()) + + local tradeContainer + local label + if counter then + tradeContainer = tradeWindow:recursiveGetChildById('counterTradeContainer') + label = tradeWindow:recursiveGetChildById('counterTradeLabel') + + tradeWindow:recursiveGetChildById('acceptButton'):enable() + else + tradeContainer = tradeWindow:recursiveGetChildById('ownTradeContainer') + label = tradeWindow:recursiveGetChildById('ownTradeLabel') + end + label:setText(name) + + for index,item in ipairs(items) do + local itemWidget = createWidget('Item', tradeContainer) + itemWidget:setItem(item) + itemWidget:setVirtual(true) + itemWidget:setMargin(1) + itemWidget.onClick = function() + g_game.inspectTrade(counter, index-1) + end + end end -local function onCounterTrade(name, items) +local function onGameOwnTrade(name, items) + fillTrade(name, items, false) +end +local function onGameCounterTrade(name, items) + fillTrade(name, items, true) end -local function onCloseTrade() +local function onGameCloseTrade() + if not tradeWindow then return end tradeWindow:destroy() tradeWindow = nil end @@ -36,11 +65,18 @@ function PlayerTrade.init() connect(g_game, { onOwnTrade = onGameOwnTrade, onCounterTrade = onGameCounterTrade, - onCloseTrade = onGameCloseTrade }) + onCloseTrade = onGameCloseTrade, + onGameEnd = onGameCloseTrade }) end function PlayerTrade.terminate() disconnect(g_game, { onOwnTrade = onGameOwnTrade, onCounterTrade = onGameCounterTrade, - onCloseTrade = onGameCloseTrade }) + onCloseTrade = onGameCloseTrade, + onGameEnd = onGameCloseTrade }) + + if tradeWindow then + tradeWindow:destroy() + tradeWindow = nil + end end diff --git a/modules/game_playertrade/tradewindow.otui b/modules/game_playertrade/tradewindow.otui index 59664efe..ddd65b9a 100644 --- a/modules/game_playertrade/tradewindow.otui +++ b/modules/game_playertrade/tradewindow.otui @@ -15,24 +15,70 @@ TradeWindow < MiniWindow MiniWindowContents padding: 6 - FlatPanel + ScrollableFlatPanel id: ownTradeContainer - anchors.fill: parent - anchors.right: parent.horizontalCenter - margin-right: 2 + anchors.left: parent.left + anchors.top: tradeScrollBar.top + anchors.right: tradeScrollBar.left + anchors.bottom: tradeScrollBar.bottom layout: type: grid - cell-size: 40 40 + cell-size: 36 36 flow: true cell-spacing: 0 + vertical-scrollbar: tradeScrollBar - FlatPanel + ScrollableFlatPanel id: counterTradeContainer - anchors.fill: parent - anchors.left: parent.horizontalCenter - margin-left: 2 + anchors.right: parent.right + anchors.top: tradeScrollBar.top + anchors.left: tradeScrollBar.right + anchors.bottom: tradeScrollBar.bottom layout: type: grid - cell-size: 40 40 + cell-size: 36 36 flow: true - cell-spacing: 0 \ No newline at end of file + cell-spacing: 0 + + VerticalScrollBar + id: tradeScrollBar + anchors.top: parent.top + anchors.bottom: acceptButton.top + anchors.horizontalCenter: parent.horizontalCenter + margin-top: 14 + margin-bottom: 4 + step: 14 + pixels-scroll: true + + Label + id: ownTradeLabel + anchors.bottom: ownTradeContainer.top + anchors.left: ownTradeContainer.left + anchors.right: ownTradeContainer.right + margin-bottom: 2 + + Label + id: counterTradeLabel + anchors.bottom: counterTradeContainer.top + anchors.left: counterTradeContainer.left + anchors.right: counterTradeContainer.right + margin-bottom: 2 + + Button + !text: tr('Accept') + id: acceptButton + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.horizontalCenter + margin-right: 2 + enabled: false + @onClick: g_game.acceptTrade(); self:disable() + + Button + !text: tr('Reject') + id: rejectButton + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.left: parent.horizontalCenter + margin-left: 2 + @onClick: g_game.rejectTrade() \ No newline at end of file diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 0a271bb0..1925230f 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -45,6 +45,7 @@ void Application::registerLuaFunctions() g_lua.bindGlobalFunction("pointtostring", [](const Point& v) { return Fw::tostring(v); }); g_lua.bindGlobalFunction("colortostring", [](const Color& v) { return Fw::tostring(v); }); g_lua.bindGlobalFunction("sizetostring", [](const Size& v) { return Fw::tostring(v); }); + g_lua.bindGlobalFunction("getticks", []() { return g_clock.asyncTicks(); }); // Event g_lua.registerClass(); @@ -334,7 +335,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("asUIGridLayout", &UILayout::asUIGridLayout); // UIBoxLayout - g_lua.registerClass(); + g_lua.registerClass(); g_lua.bindClassMemberFunction("setSpacing", &UIBoxLayout::setSpacing); g_lua.bindClassMemberFunction("setFitChildren", &UIBoxLayout::setFitChildren);