From 483487ab09eac2cb71e04a6e08246e36f3fd5a87 Mon Sep 17 00:00:00 2001 From: BeniS Date: Sat, 21 Jul 2012 06:20:06 +1200 Subject: [PATCH] More work on Market functionality and UI * Now loads all market items. * Can filter market items. * Will load market offers on items. * Edited some UI images. --- modules/client_entergame/entergame.lua | 2 +- .../skins/default/images/combobox_rounded.png | Bin 0 -> 3114 bytes .../{combobox.png => combobox_square.png} | Bin .../{tabbutton.png => tabbutton_rounded.png} | Bin .../skins/default/images/tabbutton_square.png | Bin 0 -> 2962 bytes .../skins/default/styles/buttons.otui | 2 +- .../skins/default/styles/checkboxes.otui | 2 +- .../skins/default/styles/comboboxes.otui | 6 +- .../skins/default/styles/tabbars.otui | 2 +- modules/corelib/table.lua | 4 + modules/game_market/market.lua | 155 ++++++++++++++---- modules/game_market/market.otui | 6 +- modules/game_market/marketprotocol.lua | 11 +- .../game_market/ui/general/marketbuttons.otui | 4 +- .../ui/general/marketcombobox.otui | 45 +++++ .../game_market/ui/general/markettabs.otui | 2 +- modules/game_market/ui/marketoffers.otui | 11 +- .../game_market/ui/marketoffers/browse.otui | 16 +- .../ui/marketoffers/itemoffers.otui | 83 +++++++++- modules/gamelib/gamelib.otmod | 1 + modules/gamelib/market.lua | 57 +++++++ modules/gamelib/thing.lua | 48 ++++++ src/otclient/luafunctions.cpp | 1 + 23 files changed, 394 insertions(+), 64 deletions(-) create mode 100644 modules/client_skins/skins/default/images/combobox_rounded.png rename modules/client_skins/skins/default/images/{combobox.png => combobox_square.png} (100%) rename modules/client_skins/skins/default/images/{tabbutton.png => tabbutton_rounded.png} (100%) create mode 100644 modules/client_skins/skins/default/images/tabbutton_square.png create mode 100644 modules/game_market/ui/general/marketcombobox.otui create mode 100644 modules/gamelib/thing.lua diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index 5fc0a76e..2524d4ed 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -84,7 +84,7 @@ function EnterGame.init() enterGame:getChildById('accountNameTextEdit'):focus() protocolBox = enterGame:getChildById('protocolComboBox') - for _i,proto in pairs(g_game.getSupportedProtocols()) do + for _i, proto in pairs(g_game.getSupportedProtocols()) do protocolBox:addOption(proto) end protocolBox:setCurrentOption(protocol) diff --git a/modules/client_skins/skins/default/images/combobox_rounded.png b/modules/client_skins/skins/default/images/combobox_rounded.png new file mode 100644 index 0000000000000000000000000000000000000000..067b8669e3ed48c6ab0fae8c5c7d37cb2ff058e3 GIT binary patch literal 3114 zcmV+_4At|AP);M1?PiaF#P*7-ZbZ>KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#b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^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z00041NklRN`N+KD|DG;(``#;XZ+dh{j?pY%@!Y zGd6p^asw$2m)V8O#FSFl-9Je|RqEO%#>sS+*2kMPGJVZI{`?a)}l}_C1GO2s#H0xe#<8Fyx9y2V|dckOdj?V2jpIb?e$DjzS1w zYkP-A%}G8yyG-K^JHA}=Pdh#@K0$^IS&$(QFgv~#dc3>I{&swEZIVm02(s@vB2_?D*c_UTM^vWcT>`bC1u9Pmm!) z7G%hS%#Lq`+~adxI4-ng%Umln$&L%if(#k5>g66^<+`?sCiy=mc`}`uVrMdBL52)j zkRb~)WXOUH8L}Wl7G%f+LGIcnVyIWwHt`z(0RR630CtB&B@q`r=Kufz07*qoM6N<$ Ef_!4cssI20 literal 0 HcmV?d00001 diff --git a/modules/client_skins/skins/default/images/combobox.png b/modules/client_skins/skins/default/images/combobox_square.png similarity index 100% rename from modules/client_skins/skins/default/images/combobox.png rename to modules/client_skins/skins/default/images/combobox_square.png diff --git a/modules/client_skins/skins/default/images/tabbutton.png b/modules/client_skins/skins/default/images/tabbutton_rounded.png similarity index 100% rename from modules/client_skins/skins/default/images/tabbutton.png rename to modules/client_skins/skins/default/images/tabbutton_rounded.png diff --git a/modules/client_skins/skins/default/images/tabbutton_square.png b/modules/client_skins/skins/default/images/tabbutton_square.png new file mode 100644 index 0000000000000000000000000000000000000000..87268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@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0002JNklD{81S`EjDr-9nQ$$b% z#Zn849AF1QnRkE>-typQgFMe)AWjGXZdy{X!@l}}0B|`sUf3W>0RSD4N1#A~0>1-> z0PuX=(TgGq7|;`7jNz|b&X*Ld+HKmVG1CVrw}~DT;#Ilv_9E zuk02p&Oc?lZr|{FI(lJtJkenb6e#d7n$jO8oTiN2jM|j<0KAACfKt6mY5)KL07*qo IM6N<$f`{^VmjD0& literal 0 HcmV?d00001 diff --git a/modules/client_skins/skins/default/styles/buttons.otui b/modules/client_skins/skins/default/styles/buttons.otui index 51a5a8aa..bbbcb629 100644 --- a/modules/client_skins/skins/default/styles/buttons.otui +++ b/modules/client_skins/skins/default/styles/buttons.otui @@ -21,7 +21,7 @@ Button < UIButton TabButton < UIButton size: 20 20 - image-source: /images/tabbutton.png + image-source: /images/tabbutton_rounded.png image-color: white image-clip: 0 0 20 20 image-border: 2 diff --git a/modules/client_skins/skins/default/styles/checkboxes.otui b/modules/client_skins/skins/default/styles/checkboxes.otui index 96144653..509648e2 100644 --- a/modules/client_skins/skins/default/styles/checkboxes.otui +++ b/modules/client_skins/skins/default/styles/checkboxes.otui @@ -45,7 +45,7 @@ ButtonBox < UICheckBox size: 106 22 text-offset: 0 0 text-align: center - image-source: /images/tabbutton.png + image-source: /images/tabbutton_rounded.png image-color: white image-clip: 0 0 20 20 image-border: 2 diff --git a/modules/client_skins/skins/default/styles/comboboxes.otui b/modules/client_skins/skins/default/styles/comboboxes.otui index 77530a5d..062d58c3 100644 --- a/modules/client_skins/skins/default/styles/comboboxes.otui +++ b/modules/client_skins/skins/default/styles/comboboxes.otui @@ -14,14 +14,14 @@ ComboBoxPopupMenuButton < UIButton color: #555555 ComboBoxPopupMenuSeparator < UIWidget - image-source: /images/combobox.png + image-source: /images/combobox_square.png image-repeated: true image-clip: 1 59 89 1 height: 1 phantom: true ComboBoxPopupMenu < UIPopupMenu - image-source: /images/combobox.png + image-source: /images/combobox_square.png image-clip: 0 60 89 20 image-border: 1 image-border-top: 0 @@ -33,7 +33,7 @@ ComboBox < UIComboBox size: 86 20 text-offset: 3 0 text-align: left - image-source: /images/combobox.png + image-source: /images/combobox_square.png image-border: 1 image-border-right: 17 image-clip: 0 0 89 20 diff --git a/modules/client_skins/skins/default/styles/tabbars.otui b/modules/client_skins/skins/default/styles/tabbars.otui index 1f4f35bb..d968af98 100644 --- a/modules/client_skins/skins/default/styles/tabbars.otui +++ b/modules/client_skins/skins/default/styles/tabbars.otui @@ -3,7 +3,7 @@ TabBar < UITabBar TabBarPanel < Panel TabBarButton < UIButton size: 20 20 - image-source: /images/tabbutton.png + image-source: /images/tabbutton_rounded.png image-color: white image-clip: 0 0 20 20 image-border: 2 diff --git a/modules/corelib/table.lua b/modules/corelib/table.lua index 3e8adaca..78498421 100644 --- a/modules/corelib/table.lua +++ b/modules/corelib/table.lua @@ -41,6 +41,10 @@ function table.find(t, value) end end +function table.contains(t, value) + return table.find(t, value) ~= nil +end + function table.findKey(t, key) if t and type(t) == 'table' then for k,v in pairs(t) do diff --git a/modules/game_market/market.lua b/modules/game_market/market.lua index 841dedb7..e19fefcf 100644 --- a/modules/game_market/market.lua +++ b/modules/game_market/market.lua @@ -3,6 +3,7 @@ Market = {} g_ui.importStyle('market.otui') g_ui.importStyle('ui/general/markettabs.otui') g_ui.importStyle('ui/general/marketbuttons.otui') +g_ui.importStyle('ui/general/marketcombobox.otui') local marketWindow local mainTabBar @@ -23,25 +24,62 @@ local currentOffersPanel local offerHistoryPanel local marketOffers = {} +local marketItems = {} local depot = {} local information ={} local selectedItem local nameLabel +local currentItems = {} local itemsPanel -local radioItems +local radioItemSet +local filterBox + +local function getMarketCategoryName(category) + if table.hasKey(MarketCategoryStrings, category) then + return MarketCategoryStrings[category] + end +end + +local function getMarketCategoryId(name) + local id = table.find(MarketCategoryStrings, name) + if id then + return id + end +end local function clearSelectedItem() - if selectedItem then + if selectedItem and selectedItem.item.ptr then + Market.updateOffers({}) + radioItemSet:selectWidget(nil) nameLabel:clearText() - radioItems:selectWidget(nil) - selectedItem.setItem(nil) + selectedItem:setItem(nil) + selectedItem.item = {} end end -local function loadMarketItems() - itemsPanel = marketWindow:recursiveGetChildById('itemsPanel') +local function initMarketItems() + -- populate all market items + marketItems = {} + local types = g_things.findThingTypeByAttr(ThingAttrMarket) + for k,t in pairs(types) do + local newItem = Item.create(t:getId()) + if newItem then + local item = { + ptr = newItem, + marketData = t:getMarketData() + } + table.insert(marketItems, item) + end + end +end +local function updateItemsWidget() + if table.empty(currentItems) then + return + end + + itemsPanel = marketWindow:recursiveGetChildById('itemsPanel') local layout = itemsPanel:getLayout() layout:disableUpdates() @@ -53,8 +91,15 @@ local function loadMarketItems() end radioItemSet = UIRadioGroup.create() - -- TODO: populate with dat items - + for _, item in pairs(currentItems) do + local itemBox = g_ui.createWidget('MarketItemBox', itemsPanel) + local itemWidget = itemBox:getChildById('item') + + itemBox.item = item + itemWidget:setItem(item.ptr) + + radioItemSet:addWidget(itemBox) + end layout:enableUpdates() layout:update() @@ -84,7 +129,7 @@ function Market.init() marketWindow = g_ui.createWidget('MarketWindow', rootWidget) marketWindow:hide() - nameLabel = marketWindow:recursiveGetChildById('nameLabel') + initMarketItems() -- TODO: clean this up into functions -- setup main tabs @@ -128,6 +173,20 @@ function Market.init() offerHistoryPanel = g_ui.loadUI('ui/myoffers/offerhistory.otui') offersTabBar:addTab(tr('Offer History'), offerHistoryPanel) + + nameLabel = marketWindow:recursiveGetChildById('nameLabel') + selectedItem = marketWindow:recursiveGetChildById('selectedItem') + selectedItem.item = {} + + filterBox = browsePanel:getChildById('filterComboBox') + for i = MarketCategory.First, MarketCategory.Last do + filterBox:addOption(getMarketCategoryName(i)) + end + filterBox:setCurrentOption(getMarketCategoryName(MarketCategory.First)) + + filterBox.onOptionChange = function(combobox, option) + Market.loadMarketItems(getMarketCategoryId(option)) + end end function Market.terminate() @@ -150,66 +209,101 @@ function Market.terminate() currentOffersPanel = nil offerHistoryPanel = nil marketOffers = {} + marketItems = {} depotItems = {} information = {} + currentItems = {} itemsPanel = nil nameLabel = nil - radioItems = nil + radioItemSet = nil selectedItem = nil + filterBox = nil Market = nil end +function Market.loadMarketItems(_category) + if table.empty(marketItems) then + initMarketItems() + end + + currentItems = {} + for _, item in pairs(marketItems) do + -- filter items here + local category = item.marketData.category + if category == _category or _category == MarketCategory[0] then + table.insert(currentItems, item) + end + end + + updateItemsWidget() +end + function Market.updateOffers(offers) + marketOffers[MarketAction.Buy] = {} + marketOffers[MarketAction.Sell] = {} + + local buyOfferList = marketWindow:recursiveGetChildById('buyingList') + buyOfferList:destroyChildren() + + local sellOfferList = marketWindow:recursiveGetChildById('sellingList') + sellOfferList: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()) 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()) table.insert(marketOffers[MarketAction.Sell], offer) end end - - for _, offers in pairs(marketOffers) do - for _, offer in pairs(offers) do - print(' counter: '..offer:getCounter()..' | timestamp: '..offer:getTimeStamp()..' | item: '..offer:getItem():getId()..' | action: '..offer:getAction()..' | amount: '..offer:getAmount()..' | price: '..offer:getPrice()..' | player: '..offer:getPlayer()..' | state: '..offer:getState()) - end - end - -- TODO: refresh all widget windows end function Market.updateDetails(itemId, descriptions, purchaseStats, saleStats) - -- TODO: refresh all widget windows + if not selectedItem then + return + end + selectedItem.item.details = { + serverItemId = itemId, + descriptions = descriptions, + purchaseStats = purchaseStats, + saleStats = saleStats + } + -- TODO: refresh all widget windows end function Market.updateSelectedItem(newItem) - local itemDisplay = marketWindow:recursiveGetChildById('selectedItem') - local itemName = marketWindow:recursiveGetChildById('nameLabel') - selectedItem = newItem - if not table.empty(selectedItem) then - if selectedItem.ptr then - itemDisplay:setItem(selectedItem.ptr) - itemName:setText(tr(selectedItem.name)) - MarketProtocol.sendMarketBrowse(selectedItem.ptr:getId()) -- send sprite id browsed + selectedItem.item = newItem + if selectedItem and not table.empty(selectedItem.item) then + if selectedItem.item.ptr then + selectedItem:setItem(selectedItem.item.ptr) + nameLabel:setText(selectedItem.item.marketData.name) + MarketProtocol.sendMarketBrowse(selectedItem.item.ptr:getId()) -- send sprite id browsed end else - itemDisplay:setItem(nil) - itemName:setText(tr('No item selected.')) + selectedItem:setItem(nil) + nameLabel:setText(tr('No item selected.')) end end function Market.onMarketEnter(depotItems, offers, balance) - -- TODO: populate market? if marketWindow:isVisible() then return end + marketWindow:lock() marketOffers[MarketAction.Buy] = {} marketOffers[MarketAction.Sell] = {} information.balance = balance information.totalOffers = offers - loadMarketItems() + if table.empty(currentItems) then + Market.loadMarketItems(MarketCategory.First) + end loadDepotItems(depotItems) -- TODO: if you are already viewing an item on market enter it must recheck the current item @@ -217,7 +311,6 @@ function Market.onMarketEnter(depotItems, offers, balance) selectedItem:setChecked(false) selectedItem:setChecked(true) end - --MarketProtocol.sendMarketBrowse(645) marketWindow:show() end diff --git a/modules/game_market/market.otui b/modules/game_market/market.otui index 837b7e73..2250fc30 100644 --- a/modules/game_market/market.otui +++ b/modules/game_market/market.otui @@ -1,10 +1,10 @@ MarketWindow < MainWindow id: marketWindow !text: tr('Market') - size: 680 460 + size: 700 510 - @onEnter: self:hide() - @onEscape: self:hide() + @onEnter: self:hide() self:unlock() + @onEscape: self:hide() self:unlock() // Main Panel Window diff --git a/modules/game_market/marketprotocol.lua b/modules/game_market/marketprotocol.lua index 7fe7baab..e8690f54 100644 --- a/modules/game_market/marketprotocol.lua +++ b/modules/game_market/marketprotocol.lua @@ -7,7 +7,6 @@ local protocol local function send(msg) if protocol then print(msg:getMessageSize()) - --protocol:safeSend(msg) protocol:send(msg) end end @@ -53,7 +52,7 @@ local function parseMarketEnter(msg) table.insert(depotItems, {itemId, itemCount}) end - Market.onMarketEnter(depotItems, offers, balance) + signalcall(Market.onMarketEnter, depotItems, offers, balance) return true end @@ -81,7 +80,7 @@ local function parseMarketDetail(msg) local highestPrice = msg:getU32() -- highest price local lowestPrice = msg: getU32() -- lowest price - table.insert(purchaseStats, {transaction, totalPrice, highestPrice, lowestPrice}) + table.insert(purchaseStats, {transactions, totalPrice, highestPrice, lowestPrice}) end local saleStats = {} @@ -91,10 +90,10 @@ local function parseMarketDetail(msg) local highestPrice = msg:getU32() -- highest price local lowestPrice = msg: getU32() -- lowest price - table.insert(saleStats, {transaction, totalPrice, highestPrice, lowestPrice}) + table.insert(saleStats, {transactions, totalPrice, highestPrice, lowestPrice}) end - Market.onMarketDetail(itemId, descriptions, purchaseStats, saleStats) + signalcall(Market.onMarketDetail, itemId, descriptions, purchaseStats, saleStats) return true end @@ -112,7 +111,7 @@ local function parseMarketBrowse(msg) table.insert(offers, readMarketOffer(msg, MarketAction.Sell, var)) end - Market.onMarketBrowse(offers) + signalcall(Market.onMarketBrowse, offers) return true end diff --git a/modules/game_market/ui/general/marketbuttons.otui b/modules/game_market/ui/general/marketbuttons.otui index 5a737563..35215e4c 100644 --- a/modules/game_market/ui/general/marketbuttons.otui +++ b/modules/game_market/ui/general/marketbuttons.otui @@ -1,10 +1,10 @@ MarketButtonBox < UICheckBox font: verdana-11px-antialised - color: #ffffffff + color: #f55e5ecc size: 106 22 text-offset: 0 0 text-align: center - image-source: /images/tabbutton.png + image-source: /images/tabbutton_rounded.png image-clip: 0 0 20 20 image-border: 2 diff --git a/modules/game_market/ui/general/marketcombobox.otui b/modules/game_market/ui/general/marketcombobox.otui new file mode 100644 index 00000000..db1c3b14 --- /dev/null +++ b/modules/game_market/ui/general/marketcombobox.otui @@ -0,0 +1,45 @@ +MarketComboBoxPopupMenuButton < UIButton + height: 18 + font: verdana-11px-antialised + text-align: left + text-offset: 2 0 + color: #aaaaaa + background-color: alpha + + $hover !disabled: + color: #ffffff + background-color: #ffffff44 + + $disabled: + color: #555555 + +MarketComboBoxPopupMenuSeparator < UIWidget + image-source: /images/combobox_rounded.png + image-repeated: true + image-clip: 1 59 89 1 + height: 1 + phantom: true + +MarketComboBoxPopupMenu < UIPopupMenu + image-source: /images/combobox_rounded.png + image-clip: 0 60 89 20 + image-border: 1 + image-border-top: 0 + padding: 1 + +MarketComboBox < UIComboBox + font: verdana-11px-antialised + color: #aaaaaa + size: 86 20 + text-offset: 3 0 + text-align: left + image-source: /images/combobox_rounded.png + image-border: 1 + image-border-right: 17 + image-clip: 0 0 89 20 + + $hover !disabled: + image-clip: 0 20 89 20 + + $on: + image-clip: 0 40 89 20 diff --git a/modules/game_market/ui/general/markettabs.otui b/modules/game_market/ui/general/markettabs.otui index 8e1ffd1c..dce725ed 100644 --- a/modules/game_market/ui/general/markettabs.otui +++ b/modules/game_market/ui/general/markettabs.otui @@ -3,7 +3,7 @@ MarketTabBar < UITabBar MarketTabBarPanel < Panel MarketTabBarButton < UIButton size: 20 25 - image-source: /images/tabbutton.png + image-source: /images/tabbutton_square.png image-clip: 0 0 20 20 image-border: 2 icon-color: white diff --git a/modules/game_market/ui/marketoffers.otui b/modules/game_market/ui/marketoffers.otui index 62b9d234..205b7bb1 100644 --- a/modules/game_market/ui/marketoffers.otui +++ b/modules/game_market/ui/marketoffers.otui @@ -33,17 +33,22 @@ Panel border-width: 1 border-color: #000000 - Item + UIItem id: selectedItem phantom: true + size: 34 34 + padding: 1 + font: verdana-11px-rounded + border-color: white anchors.top: rightTabBar.bottom anchors.left: rightTabContent.left - margin-top: 3 - margin-left: 3 + margin-top: 6 + margin-left: 6 Label id: nameLabel !text: tr('No item selected.') anchors.top: prev.top anchors.left: prev.right + anchors.right: parent.right margin-left: 5 diff --git a/modules/game_market/ui/marketoffers/browse.otui b/modules/game_market/ui/marketoffers/browse.otui index c8641ab8..cd059bc2 100644 --- a/modules/game_market/ui/marketoffers/browse.otui +++ b/modules/game_market/ui/marketoffers/browse.otui @@ -11,7 +11,7 @@ MarketItemBox < UICheckBox phantom: true anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter - margin-top: 5 + margin: 1 $checked: border-color: #ffffff @@ -27,7 +27,7 @@ Panel background-color: #22283399 margin: 1 - ComboBox + MarketComboBox id: filterComboBox anchors.top: parent.top anchors.left: parent.left @@ -36,7 +36,7 @@ Panel margin-right: 3 margin-left: 3 - ComboBox + MarketComboBox id: weaponComboBox anchors.top: prev.bottom anchors.left: parent.left @@ -72,7 +72,7 @@ Panel height: 20 //@onClick: Market.filterMatchVocation() - ComboBox + MarketComboBox id: typeComboBox anchors.top: prev.top anchors.left: prev.right @@ -88,7 +88,7 @@ Panel anchors.top: prev.bottom anchors.left: parent.left anchors.right: parent.right - margin-top: 3 + margin-top: 6 margin-right: 3 margin-left: 3 //@onClick: Market.setDisplayDepot() @@ -100,7 +100,7 @@ Panel anchors.bottom: parent.bottom margin-top: 10 margin-left: 3 - margin-bottom: 10 + margin-bottom: 5 margin-right: 3 VerticalScrollBar @@ -108,7 +108,7 @@ Panel anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right - step: 16 + step: 28 pixels-scroll: true ScrollablePanel @@ -120,6 +120,6 @@ Panel vertical-scrollbar: itemsPanelListScrollBar layout: type: grid - cell-size: 34 34 + cell-size: 36 36 flow: true auto-spacing: true \ No newline at end of file diff --git a/modules/game_market/ui/marketoffers/itemoffers.otui b/modules/game_market/ui/marketoffers/itemoffers.otui index 8c105075..94f143d3 100644 --- a/modules/game_market/ui/marketoffers/itemoffers.otui +++ b/modules/game_market/ui/marketoffers/itemoffers.otui @@ -1,10 +1,87 @@ +OfferListLabel < Label + font: verdana-11px-monochrome + background-color: alpha + text-offset: 2 0 + focusable: true + color: #cccccc + + $focus: + background-color: #294f6d + color: #ffffff + Panel background-color: #22283399 margin: 1 + Button + !text: tr('Buy Now') + anchors.right: parent.right + anchors.bottom: next.bottom + margin-right: 6 + width: 80 + //@onClick: g_game.closeNpcTrade() + Label - !text: tr('Item Offers') + !text: tr('Sell Offers') anchors.top: parent.top anchors.left: parent.left - margin-top: 45 - margin-left: 3 \ No newline at end of file + margin-top: 44 + margin-left: 6 + + TextList + id: sellingList + anchors.top: prev.bottom + anchors.left: prev.left + anchors.right: parent.right + height: 120 + margin-top: 5 + margin-bottom: 5 + margin-right: 6 + padding: 1 + focusable: false + vertical-scrollbar: sellingListScrollBar + + VerticalScrollBar + id: sellingListScrollBar + anchors.top: prev.top + anchors.bottom: prev.bottom + anchors.right: prev.right + step: 28 + pixels-scroll: true + + Button + !text: tr('Sell Now') + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 5 + margin-right: 6 + width: 80 + //@onClick: g_game.closeNpcTrade() + + Label + !text: tr('Buy Offers') + anchors.top: prev.top + anchors.left: parent.left + margin-top: 9 + margin-left: 6 + + TextList + id: buyingList + anchors.top: prev.bottom + anchors.left: prev.left + anchors.right: parent.right + margin-top: 5 + margin-bottom: 5 + margin-right: 6 + height: 120 + padding: 1 + focusable: false + vertical-scrollbar: buyingListScrollBar + + VerticalScrollBar + id: buyingListScrollBar + anchors.top: prev.top + anchors.bottom: prev.bottom + anchors.right: prev.right + step: 28 + pixels-scroll: true \ No newline at end of file diff --git a/modules/gamelib/gamelib.otmod b/modules/gamelib/gamelib.otmod index 555133c0..05fdb1e4 100644 --- a/modules/gamelib/gamelib.otmod +++ b/modules/gamelib/gamelib.otmod @@ -18,3 +18,4 @@ Module dofile 'creature' dofile 'player' dofile 'market' + dofile 'thing' diff --git a/modules/gamelib/market.lua b/modules/gamelib/market.lua index cc1d5e0f..77d83079 100644 --- a/modules/gamelib/market.lua +++ b/modules/gamelib/market.lua @@ -1,3 +1,60 @@ +MarketCategory = { + All = 0, + Armors = 1, + Amulets = 2, + Boots = 3, + Containers = 4, + Decoration = 5, + Food = 6, + HelmetsHats = 7, + Legs = 8, + Others = 9, + Potions = 10, + Rings = 11, + Runes = 12, + Shields = 13, + Tools = 14, + Valuables = 15, + Ammunition = 16, + Axes = 17, + Clubs = 18, + DistanceWeapons = 19, + Swords = 20, + WandsRods = 21, + PremiumScrolls = 22, + MetaWeapons = 255 +} + +MarketCategory.First = MarketCategory.Armors +MarketCategory.Last = MarketCategory.PremiumScrolls + +MarketCategoryStrings = { + [0] = 'All', + [1] = 'Armors', + [2] = 'Amulets', + [3] = 'Boots', + [4] = 'Containers', + [5] = 'Decoration', + [6] = 'Food', + [7] = 'Helmets and Hats', + [8] = 'Legs', + [9] = 'Others', + [10] = 'Potions', + [11] = 'Rings', + [12] = 'Runes', + [13] = 'Shields', + [14] = 'Tools', + [15] = 'Valuables', + [16] = 'Ammunition', + [17] = 'Axes', + [18] = 'Clubs', + [19] = 'Distance Weapons', + [20] = 'Swords', + [21] = 'Wands and Rods', + [22] = 'Premium Scrolls', + [255] = 'Meta Weapons' +} + MarketAction = { Buy = 0, Sell = 1 diff --git a/modules/gamelib/thing.lua b/modules/gamelib/thing.lua new file mode 100644 index 00000000..c49eba1f --- /dev/null +++ b/modules/gamelib/thing.lua @@ -0,0 +1,48 @@ +ThingCategoryItem = 0 +ThingCategoryCreature = 1 +ThingCategoryEffect = 2 +ThingCategoryMissile = 3 +ThingInvalidCategory = 4 +ThingLastCategory = ThingInvalidCategory + +ThingAttrGround = 0 +ThingAttrGroundBorder = 1 +ThingAttrOnBottom = 2 +ThingAttrOnTop = 3 +ThingAttrContainer = 4 +ThingAttrStackable = 5 +ThingAttrForceUse = 6 +ThingAttrMultiUse = 7 +ThingAttrWritable = 8 +ThingAttrWritableOnce = 9 +ThingAttrFluidContainer = 10 +ThingAttrSplash = 11 +ThingAttrNotWalkable = 12 +ThingAttrNotMoveable = 13 +ThingAttrBlockProjectile = 14 +ThingAttrNotPathable = 15 +ThingAttrPickupable = 16 +ThingAttrHangable = 17 +ThingAttrHookSouth = 18 +ThingAttrHookEast = 19 +ThingAttrRotateable = 20 +ThingAttrLight = 21 +ThingAttrDontHide = 22 +ThingAttrTranslucent = 23 +ThingAttrDisplacement = 24 +ThingAttrElevation = 25 +ThingAttrLyingCorpse = 26 +ThingAttrAnimateAlways = 27 +ThingAttrMinimapColor = 28 +ThingAttrLensHelp = 29 +ThingAttrFullGround = 30 +ThingAttrLook = 31 +ThingAttrCloth = 32 +ThingAttrMarket = 33 +ThingAttrChargeable = 254 -- deprecated +ThingLastAttr = 255 + +SpriteMaskRed = 1 +SpriteMaskGreen = 2 +SpriteMaskBlue = 3 +SpriteMaskYellow = 4 \ No newline at end of file diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index d214b379..03b08229 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -338,6 +338,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getClientId", &ItemType::getClientId); g_lua.registerClass(); + g_lua.bindClassMemberFunction("getId", &ThingType::getId); g_lua.bindClassMemberFunction("getMarketData", &ThingType::getMarketData); g_lua.registerClass();