Some performance fixes, added UITable widget for easy tables (needs more work still), Worked on Market order displaying.
This commit is contained in:
parent
3461761739
commit
9c8134c8a6
|
@ -28,7 +28,8 @@ local skin = {
|
|||
'splitters.otui',
|
||||
'miniwindow.otui',
|
||||
'items.otui',
|
||||
'creatures.otui'
|
||||
'creatures.otui',
|
||||
'tables.otui'
|
||||
},
|
||||
|
||||
particles = {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
Table < UITable
|
||||
layout: verticalBox
|
||||
|
||||
TableRow < UIScrollArea
|
||||
layout: horizontalBox
|
||||
height: 10
|
||||
|
||||
TableColumn < UIScrollArea
|
||||
width: 30
|
|
@ -0,0 +1,86 @@
|
|||
-- @docclass
|
||||
UITable = extends(UIScrollArea)
|
||||
|
||||
function UITable.create()
|
||||
local table = UITable.internalCreate()
|
||||
table.rows = {}
|
||||
table.rows.columns = {}
|
||||
table.rowStyle = {}
|
||||
table.columStyle = {}
|
||||
return table
|
||||
end
|
||||
|
||||
function UITable:destroy()
|
||||
for k,row in pairs(self.rows) do
|
||||
row.onClick = nil
|
||||
end
|
||||
self.rows = {}
|
||||
end
|
||||
|
||||
function UITable:onStyleApply(styleName, styleNode)
|
||||
UIScrollArea.onStyleApply(self, styleName, styleNode)
|
||||
for name, value in pairs(styleNode) do
|
||||
if name == 'column-style' then
|
||||
addEvent(function()
|
||||
self:setRowStyle(self:getParent():getChildById(value))
|
||||
end)
|
||||
elseif name == 'row-style' then
|
||||
addEvent(function()
|
||||
self:setRowStyle(self:getParent():getChildById(value))
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UITable:addRow(columns, rowStyle, columStyle)
|
||||
local row = g_ui.createWidget(rowStyle, self)
|
||||
row.columns = {}
|
||||
|
||||
for k, data in pairs(columns) do
|
||||
local col = g_ui.createWidget(columStyle, row)
|
||||
col:setText(data)
|
||||
table.insert(row.columns, col)
|
||||
end
|
||||
row.onClick = function(row) self:selectRow(row) end
|
||||
table.insert(self.rows, row)
|
||||
return row
|
||||
end
|
||||
|
||||
function UITable:removeRow(row)
|
||||
if self.selectedRow == row then
|
||||
self:selectRow(nil)
|
||||
end
|
||||
row.onClick = nil
|
||||
table.removevalue(self.rows, row)
|
||||
end
|
||||
|
||||
function UITable:selectRow(selectedRow)
|
||||
if selectedRow == self.selectedRow then return end
|
||||
|
||||
local previousSelectedRow = self.selectedRow
|
||||
self.selectedRow = selectedRow
|
||||
|
||||
if previousSelectedRow then
|
||||
previousSelectedRow:setChecked(false)
|
||||
end
|
||||
|
||||
if selectedRow then
|
||||
selectedRow:setChecked(true)
|
||||
end
|
||||
|
||||
signalcall(self.onSelectionChange, self, selectedRow, previousSelectedRow)
|
||||
end
|
||||
|
||||
function UITable:setRowStyle(style)
|
||||
self.rowStyle = style
|
||||
for k, row in pairs(self.rows) do
|
||||
row:setStyle(style)
|
||||
end
|
||||
end
|
||||
|
||||
function UITable:setColumnStyle(style)
|
||||
self.columStyle = style
|
||||
for k, col in pairs(self.rows.columns) do
|
||||
col:setStyle(style)
|
||||
end
|
||||
end
|
|
@ -62,15 +62,15 @@ local function initMarketItems()
|
|||
-- populate all market items
|
||||
marketItems = {}
|
||||
local types = g_things.findThingTypeByAttr(ThingAttrMarket)
|
||||
for idx = 1, #types do
|
||||
local t = types[idx]
|
||||
for i = 1, #types do
|
||||
local t = types[i]
|
||||
local newItem = Item.create(t:getId())
|
||||
if newItem then
|
||||
local item = {
|
||||
ptr = newItem,
|
||||
marketData = t:getMarketData()
|
||||
}
|
||||
table.insert(marketItems, item)
|
||||
marketItems[#marketItems+1] = item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -92,7 +92,8 @@ local function updateItemsWidget()
|
|||
end
|
||||
radioItemSet = UIRadioGroup.create()
|
||||
|
||||
for _, item in pairs(currentItems) do
|
||||
for i = 1, #currentItems do
|
||||
local item = currentItems[i]
|
||||
local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel)
|
||||
local itemWidget = itemBox:getChildById('item')
|
||||
|
||||
|
@ -108,7 +109,8 @@ end
|
|||
|
||||
local function loadDepotItems(depotItems)
|
||||
information.depotItems = {}
|
||||
for _, data in pairs(depotItems) do
|
||||
for i = 1, #depotItems do
|
||||
local data = depotItems[i]
|
||||
local item = Item.create(data[1])
|
||||
if not item then
|
||||
break
|
||||
|
@ -229,8 +231,9 @@ function Market.loadMarketItems(_category)
|
|||
end
|
||||
|
||||
currentItems = {}
|
||||
for _, item in pairs(marketItems) do
|
||||
for i = 1, #marketItems do
|
||||
-- filter items here
|
||||
local item = marketItems[i]
|
||||
local category = item.marketData.category
|
||||
if category == _category or _category == MarketCategory[0] then
|
||||
table.insert(currentItems, item)
|
||||
|
@ -244,20 +247,32 @@ function Market.updateOffers(offers)
|
|||
marketOffers[MarketAction.Buy] = {}
|
||||
marketOffers[MarketAction.Sell] = {}
|
||||
|
||||
local buyOfferList = marketWindow:recursiveGetChildById('buyingList')
|
||||
buyOfferList:destroyChildren()
|
||||
local buyOfferTable = marketWindow:recursiveGetChildById('buyingTable')
|
||||
buyOfferTable:destroyChildren()
|
||||
|
||||
local sellOfferList = marketWindow:recursiveGetChildById('sellingList')
|
||||
sellOfferList:destroyChildren()
|
||||
local sellOfferTable = marketWindow:recursiveGetChildById('sellingTable')
|
||||
sellOfferTable:destroyChildren()
|
||||
|
||||
for k, offer in pairs(offers) do
|
||||
if offer and offer:getAction() == MarketAction.Buy then
|
||||
local label = g_ui.createWidget('OfferListLabel', buyOfferList)
|
||||
label:setText(offer:getPlayer()..' '..offer:getAmount()..' '..(offer:getPrice()*offer:getAmount())..' '..offer:getPrice()..' '..offer:getTimeStamp())
|
||||
local data = {
|
||||
offer:getPlayer(),
|
||||
offer:getAmount(),
|
||||
offer:getPrice()*offer:getAmount(),
|
||||
offer:getPrice(),
|
||||
offer:getTimeStamp()
|
||||
}
|
||||
local row = buyOfferTable:addRow(data, 'OfferTableRow', 'OfferTableColumn')
|
||||
table.insert(marketOffers[MarketAction.Buy], offer)
|
||||
else
|
||||
local label = g_ui.createWidget('OfferListLabel', sellOfferList)
|
||||
label:setText(offer:getPlayer()..' '..offer:getAmount()..' '..(offer:getPrice()*offer:getAmount())..' '..offer:getPrice()..' '..offer:getTimeStamp())
|
||||
local data = {
|
||||
offer:getPlayer(),
|
||||
offer:getAmount(),
|
||||
offer:getPrice()*offer:getAmount(),
|
||||
offer:getPrice(),
|
||||
offer:getTimeStamp()
|
||||
}
|
||||
local row = sellOfferTable:addRow(data, 'OfferTableRow', 'OfferTableColumn')
|
||||
table.insert(marketOffers[MarketAction.Sell], offer)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
OfferListLabel < Label
|
||||
OfferTableRow < TableRow
|
||||
font: verdana-11px-monochrome
|
||||
background-color: alpha
|
||||
text-offset: 2 0
|
||||
focusable: true
|
||||
color: #cccccc
|
||||
height: 25
|
||||
|
||||
$focus:
|
||||
background-color: #294f6d
|
||||
color: #ffffff
|
||||
|
||||
OfferTableColumn < TableColumn
|
||||
font: verdana-11px-monochrome
|
||||
background-color: alpha
|
||||
text-offset: 2 0
|
||||
color: #cccccc
|
||||
width: 80
|
||||
|
||||
Panel
|
||||
background-color: #22283399
|
||||
margin: 1
|
||||
|
@ -28,8 +36,8 @@ Panel
|
|||
margin-top: 44
|
||||
margin-left: 6
|
||||
|
||||
TextList
|
||||
id: sellingList
|
||||
Table
|
||||
id: sellingTable
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: prev.left
|
||||
anchors.right: parent.right
|
||||
|
@ -39,10 +47,13 @@ Panel
|
|||
margin-right: 6
|
||||
padding: 1
|
||||
focusable: false
|
||||
vertical-scrollbar: sellingListScrollBar
|
||||
background-color: #222833
|
||||
border-width: 1
|
||||
border-color: #191f27
|
||||
vertical-scrollbar: sellingTableScrollBar
|
||||
|
||||
VerticalScrollBar
|
||||
id: sellingListScrollBar
|
||||
id: sellingTableScrollBar
|
||||
anchors.top: prev.top
|
||||
anchors.bottom: prev.bottom
|
||||
anchors.right: prev.right
|
||||
|
@ -65,8 +76,8 @@ Panel
|
|||
margin-top: 9
|
||||
margin-left: 6
|
||||
|
||||
TextList
|
||||
id: buyingList
|
||||
Table
|
||||
id: buyingTable
|
||||
anchors.top: prev.bottom
|
||||
anchors.left: prev.left
|
||||
anchors.right: parent.right
|
||||
|
@ -76,10 +87,13 @@ Panel
|
|||
height: 120
|
||||
padding: 1
|
||||
focusable: false
|
||||
vertical-scrollbar: buyingListScrollBar
|
||||
background-color: #222833
|
||||
border-width: 1
|
||||
border-color: #191f27
|
||||
vertical-scrollbar: buyingTableScrollBar
|
||||
|
||||
VerticalScrollBar
|
||||
id: buyingListScrollBar
|
||||
id: buyingTableScrollBar
|
||||
anchors.top: prev.top
|
||||
anchors.bottom: prev.bottom
|
||||
anchors.right: prev.right
|
||||
|
|
|
@ -111,9 +111,10 @@ local function updateOutfit()
|
|||
end
|
||||
|
||||
outfit.addons = 0
|
||||
for k, addon in pairs(prevAddons) do
|
||||
if addon and addons[k].widget:isEnabled() then
|
||||
addons[k].widget:setChecked(true)
|
||||
for i = 1, #prevAddons do
|
||||
local addon = prevAddons[i]
|
||||
if addon and addons[i].widget:isEnabled() then
|
||||
addons[i].widget:setChecked(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -185,7 +186,7 @@ function Outfit.create(creatureOutfit, outfitList, creatureMount, mountList)
|
|||
[3] = {widget = outfitWindow:getChildById('addon3'), value = 4}
|
||||
}
|
||||
|
||||
for k, addon in pairs(addons) do
|
||||
for _, addon in pairs(addons) do
|
||||
addon.widget.onCheckChange = function(self) onAddonCheckChange(self, addon.value) end
|
||||
end
|
||||
|
||||
|
@ -216,7 +217,7 @@ function Outfit.create(creatureOutfit, outfitList, creatureMount, mountList)
|
|||
colorBox:setChecked(true)
|
||||
end
|
||||
colorBox.onCheckChange = onColorCheckChange
|
||||
table.insert(colorBoxes, colorBox)
|
||||
colorBoxes[#colorBoxes+1] = colorBox
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -260,10 +261,10 @@ function Outfit.randomize()
|
|||
outfitWindow:getChildById('detail')
|
||||
}
|
||||
|
||||
for k, section in pairs(outfitTemplate) do
|
||||
section:setChecked(true)
|
||||
for i = 1, #outfitTemplate do
|
||||
outfitTemplate[i]:setChecked(true)
|
||||
colorBoxes[math.random(1, #colorBoxes)]:setChecked(true)
|
||||
section:setChecked(false)
|
||||
outfitTemplate[i]:setChecked(false)
|
||||
end
|
||||
outfitTemplate[1]:setChecked(true)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue