Some performance fixes, added UITable widget for easy tables (needs more work still), Worked on Market order displaying.

This commit is contained in:
BeniS
2012-07-22 00:15:29 +12:00
parent 3461761739
commit 9c8134c8a6
6 changed files with 158 additions and 32 deletions

View File

@@ -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

View File

@@ -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