Skip to content
Snippets Groups Projects
Commit c38ef317 authored by dg's avatar dg
Browse files

Store shoulds the correct price

git-svn-id: http://svn.net-core.org/repos/t-engine4@1483 51575b47-30f0-44d4-a5cc-537603b46e54
parent 209db393
No related branches found
No related tags found
No related merge requests found
......@@ -92,6 +92,8 @@ function _M:interact(who)
end
end, function(what, o)
return self:descObject(who, what, o)
end, function(what, o)
return self:descObjectPrice(who, what, o)
end)
game:registerDialog(d)
end
......@@ -184,6 +186,15 @@ end
-- @param what either "sell" or "buy"
-- @param o the object
-- @return a string (possibly multiline) describing the object
function _M:descObject(what, o)
function _M:descObject(who, what, o)
return o:getDesc()
end
--- Called to describe an object's price, being to sell or to buy
-- @param who the actor
-- @param what either "sell" or "buy"
-- @param o the object
-- @return a string describing the price
function _M:descObjectPrice(who, what, o)
return ""
end
......@@ -26,9 +26,10 @@ local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(Dialog))
function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, action, desc)
function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, action, desc, descprice)
self.action = action
self.desc = desc
self.descprice = descprice
self.store_inven = store_inven
self.actor_inven = actor_inven
self.store_filter = store_filter
......@@ -43,14 +44,14 @@ function _M:init(title, store_inven, actor_inven, store_filter, actor_filter, ac
{name="", width={20,"fixed"}, display_prop="char", sort="id"},
{name="Inventory", width=72, display_prop="name", sort="name"},
{name="Category", width=20, display_prop="cat", sort="cat"},
{name="Price", width=8, display_prop="cost", sort="cost"},
{name="Price", width=8, display_prop="desc_price", sort=function(a, b) return descprice("sell", a.object) <descprice("sell", b.object) end},
}, list={}, fct=function(item, sel) self:use(item) end, select=function(item, sel) self:select(item) end}
self.c_store = ListColumns.new{width=math.floor(self.iw / 2 - 10), height=self.ih - self.max_h*self.font_h - 10, sortable=true, scrollbar=true, columns={
{name="", width={20,"fixed"}, display_prop="char", sort="id"},
{name="Store", width=72, display_prop="name"},
{name="Category", width=20, display_prop="cat"},
{name="Price", width=8, display_prop="cost", sort="cost"},
{name="Price", width=8, display_prop="desc_price", sort=function(a, b) return descprice("buy", a.object) <descprice("buy", b.object) end},
}, list={}, fct=function(item) self:use(item) end, select=function(item, sel) self:select(item) end}
self:generateList()
......@@ -125,7 +126,7 @@ function _M:generateList()
for item, o in ipairs(self.store_inven) do
if not self.store_filter or self.store_filter(o) then
local char = self:makeKeyChar(i)
list[#list+1] = { id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost, desc=o:getDesc() }
list[#list+1] = { id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost, desc=o:getDesc(), desc_price=self.descprice("buy", o) }
list.chars[char] = #list
i = i + 1
end
......@@ -139,7 +140,7 @@ function _M:generateList()
for item, o in ipairs(self.actor_inven) do
if not self.actor_filter or self.actor_filter(o) then
local char = self:makeKeyChar(i)
list[#list+1] = { id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost, desc=o:getDesc() }
list[#list+1] = { id=#list+1, char=char, name=o:getDisplayString()..o:getName(), color=o:getDisplayColor(), object=o, item=item, cat=o.subtype, cost=o.cost, desc=o:getDesc(), desc_price=self.descprice("sell", o) }
list.chars[char] = #list
i = i + 1
end
......
......@@ -111,6 +111,19 @@ function _M:descObject(who, what, o)
end
end
--- Called to describe an object's price, being to sell or to buy
-- @param who the actor
-- @param what either "sell" or "buy"
-- @param o the object
-- @return a string describing the price
function _M:descObjectPrice(who, what, o)
if what == "buy" then
return o:getPrice() * self.sell_percent / 100, who.money
else
return o:getPrice() * self.buy_percent / 100, who.money
end
end
--- Actor interacts with the store
-- @param who the actor who interracts
function _M:interact(who)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment