trade working
* use only mouse left release in checkboxes * remvoe duplicated code in radiogroup * implement player trade
This commit is contained in:
parent
2afa80b1cd
commit
fea34a41ea
|
@ -8,31 +8,24 @@ end
|
||||||
|
|
||||||
function RadioGroup:destroy()
|
function RadioGroup:destroy()
|
||||||
for k,widget in pairs(self.widgets) do
|
for k,widget in pairs(self.widgets) do
|
||||||
widget.onMousePress = nil
|
widget.onClick = nil
|
||||||
end
|
end
|
||||||
self.widgets = {}
|
self.widgets = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function RadioGroup:addWidget(widget)
|
function RadioGroup:addWidget(widget)
|
||||||
table.insert(self.widgets, widget)
|
table.insert(self.widgets, widget)
|
||||||
widget.onMousePress = function(widget) self:selectWidget(widget) end
|
widget.onClick = function(widget) self:selectWidget(widget) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function RadioGroup:removeWidget(widget)
|
function RadioGroup:removeWidget(widget)
|
||||||
if self.selectedWidget == widget then
|
if self.selectedWidget == widget then
|
||||||
self:selectWidget(nil)
|
self:selectWidget(nil)
|
||||||
end
|
end
|
||||||
widget.onMousePress = nil
|
widget.onClick = nil
|
||||||
table.removevalue(self.widgets, widget)
|
table.removevalue(self.widgets, widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
function RadioGroup:destroy()
|
|
||||||
for k,widget in pairs(self.widgets) do
|
|
||||||
widget.onMousePress = nil
|
|
||||||
end
|
|
||||||
self.widgets = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
function RadioGroup:selectWidget(selectedWidget)
|
function RadioGroup:selectWidget(selectedWidget)
|
||||||
if selectedWidget == self.selectedWidget then return end
|
if selectedWidget == self.selectedWidget then return end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ function UICheckBox.create()
|
||||||
return checkbox
|
return checkbox
|
||||||
end
|
end
|
||||||
|
|
||||||
function UICheckBox:onMousePress(mousePos, mouseButton)
|
function UICheckBox:onClick()
|
||||||
self:setChecked(not self:isChecked())
|
self:setChecked(not self:isChecked())
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,3 +7,7 @@ ScrollablePanel < UIScrollArea
|
||||||
FlatPanel < Panel
|
FlatPanel < Panel
|
||||||
image-source: /core_styles/styles/images/panel_flat.png
|
image-source: /core_styles/styles/images/panel_flat.png
|
||||||
image-border: 1
|
image-border: 1
|
||||||
|
|
||||||
|
ScrollableFlatPanel < ScrollablePanel
|
||||||
|
image-source: /core_styles/styles/images/panel_flat.png
|
||||||
|
image-border: 1
|
|
@ -4,3 +4,10 @@ HorizontalSeparator < UIWidget
|
||||||
height: 2
|
height: 2
|
||||||
phantom: true
|
phantom: true
|
||||||
focusable: false
|
focusable: false
|
||||||
|
|
||||||
|
VerticalSeparator < UIWidget
|
||||||
|
image-source: /core_styles/styles/images/horizontal_separator.png
|
||||||
|
image-border-left: 2
|
||||||
|
width: 2
|
||||||
|
phantom: true
|
||||||
|
focusable: false
|
||||||
|
|
|
@ -7,26 +7,55 @@ PlayerTrade = {}
|
||||||
local tradeWindow
|
local tradeWindow
|
||||||
|
|
||||||
local function createTrade()
|
local function createTrade()
|
||||||
if tradeWindow then
|
tradeWindow = createWidget('TradeWindow', GameInterface.getRightPanel())
|
||||||
tradeWindow:destroy()
|
tradeWindow.onClose = function()
|
||||||
tradeWindow = nil
|
g_game.rejectTrade()
|
||||||
|
tradeWindow:hide()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tradeWindow = createWidget('TradeWindow', rootWidget)
|
local function fillTrade(name, items, counter)
|
||||||
|
if not tradeWindow then
|
||||||
|
createTrade()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onOwnTrade(name, items)
|
|
||||||
local firstItem = items[1]
|
|
||||||
|
|
||||||
local tradeItemWidget = tradeWindow:getChildById('tradeItem')
|
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
|
end
|
||||||
|
|
||||||
local function onCounterTrade(name, items)
|
local function onGameOwnTrade(name, items)
|
||||||
|
fillTrade(name, items, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onCloseTrade()
|
local function onGameCounterTrade(name, items)
|
||||||
|
fillTrade(name, items, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onGameCloseTrade()
|
||||||
|
if not tradeWindow then return end
|
||||||
tradeWindow:destroy()
|
tradeWindow:destroy()
|
||||||
tradeWindow = nil
|
tradeWindow = nil
|
||||||
end
|
end
|
||||||
|
@ -36,11 +65,18 @@ function PlayerTrade.init()
|
||||||
|
|
||||||
connect(g_game, { onOwnTrade = onGameOwnTrade,
|
connect(g_game, { onOwnTrade = onGameOwnTrade,
|
||||||
onCounterTrade = onGameCounterTrade,
|
onCounterTrade = onGameCounterTrade,
|
||||||
onCloseTrade = onGameCloseTrade })
|
onCloseTrade = onGameCloseTrade,
|
||||||
|
onGameEnd = onGameCloseTrade })
|
||||||
end
|
end
|
||||||
|
|
||||||
function PlayerTrade.terminate()
|
function PlayerTrade.terminate()
|
||||||
disconnect(g_game, { onOwnTrade = onGameOwnTrade,
|
disconnect(g_game, { onOwnTrade = onGameOwnTrade,
|
||||||
onCounterTrade = onGameCounterTrade,
|
onCounterTrade = onGameCounterTrade,
|
||||||
onCloseTrade = onGameCloseTrade })
|
onCloseTrade = onGameCloseTrade,
|
||||||
|
onGameEnd = onGameCloseTrade })
|
||||||
|
|
||||||
|
if tradeWindow then
|
||||||
|
tradeWindow:destroy()
|
||||||
|
tradeWindow = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,24 +15,70 @@ TradeWindow < MiniWindow
|
||||||
MiniWindowContents
|
MiniWindowContents
|
||||||
padding: 6
|
padding: 6
|
||||||
|
|
||||||
FlatPanel
|
ScrollableFlatPanel
|
||||||
id: ownTradeContainer
|
id: ownTradeContainer
|
||||||
anchors.fill: parent
|
anchors.left: parent.left
|
||||||
anchors.right: parent.horizontalCenter
|
anchors.top: tradeScrollBar.top
|
||||||
margin-right: 2
|
anchors.right: tradeScrollBar.left
|
||||||
|
anchors.bottom: tradeScrollBar.bottom
|
||||||
layout:
|
layout:
|
||||||
type: grid
|
type: grid
|
||||||
cell-size: 40 40
|
cell-size: 36 36
|
||||||
|
flow: true
|
||||||
|
cell-spacing: 0
|
||||||
|
vertical-scrollbar: tradeScrollBar
|
||||||
|
|
||||||
|
ScrollableFlatPanel
|
||||||
|
id: counterTradeContainer
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.top: tradeScrollBar.top
|
||||||
|
anchors.left: tradeScrollBar.right
|
||||||
|
anchors.bottom: tradeScrollBar.bottom
|
||||||
|
layout:
|
||||||
|
type: grid
|
||||||
|
cell-size: 36 36
|
||||||
flow: true
|
flow: true
|
||||||
cell-spacing: 0
|
cell-spacing: 0
|
||||||
|
|
||||||
FlatPanel
|
VerticalScrollBar
|
||||||
id: counterTradeContainer
|
id: tradeScrollBar
|
||||||
anchors.fill: parent
|
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
|
anchors.left: parent.horizontalCenter
|
||||||
margin-left: 2
|
margin-left: 2
|
||||||
layout:
|
@onClick: g_game.rejectTrade()
|
||||||
type: grid
|
|
||||||
cell-size: 40 40
|
|
||||||
flow: true
|
|
||||||
cell-spacing: 0
|
|
|
@ -45,6 +45,7 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindGlobalFunction("pointtostring", [](const Point& v) { return Fw::tostring(v); });
|
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("colortostring", [](const Color& v) { return Fw::tostring(v); });
|
||||||
g_lua.bindGlobalFunction("sizetostring", [](const Size& 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
|
// Event
|
||||||
g_lua.registerClass<Event>();
|
g_lua.registerClass<Event>();
|
||||||
|
@ -334,7 +335,7 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UILayout>("asUIGridLayout", &UILayout::asUIGridLayout);
|
g_lua.bindClassMemberFunction<UILayout>("asUIGridLayout", &UILayout::asUIGridLayout);
|
||||||
|
|
||||||
// UIBoxLayout
|
// UIBoxLayout
|
||||||
g_lua.registerClass<UIBoxLayout>();
|
g_lua.registerClass<UIBoxLayout, UILayout>();
|
||||||
g_lua.bindClassMemberFunction<UIBoxLayout>("setSpacing", &UIBoxLayout::setSpacing);
|
g_lua.bindClassMemberFunction<UIBoxLayout>("setSpacing", &UIBoxLayout::setSpacing);
|
||||||
g_lua.bindClassMemberFunction<UIBoxLayout>("setFitChildren", &UIBoxLayout::setFitChildren);
|
g_lua.bindClassMemberFunction<UIBoxLayout>("setFitChildren", &UIBoxLayout::setFitChildren);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue