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

Confirmation prompt to stores

git-svn-id: http://svn.net-core.org/repos/t-engine4@839 51575b47-30f0-44d4-a5cc-537603b46e54
parent f10cb053
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
require "engine.class"
local Entity = require "engine.Entity"
local Dialog = require "engine.Dialog"
local Inventory = require "engine.interface.ActorInventory"
local ShowStore = require "engine.dialogs.ShowStore"
local GetQuantity = require "engine.dialogs.GetQuantity"
......@@ -75,7 +76,7 @@ function _M:interact(who)
local d; d = ShowStore.new("Store: "..self.name, store, inven, nil, nil, function(what, o, item)
if what == "buy" then
if o:getNumber() > 1 then
local q = GetQuantity.new(nil, nil, function(qty) self:doBuy(who, o, item, qty) print(d) d:updateStore() end)
local q = GetQuantity.new(nil, nil, function(qty) self:doBuy(who, o, item, qty, d) end)
q.qty = o:getNumber()
game:registerDialog(q)
else
......@@ -84,7 +85,7 @@ function _M:interact(who)
else
if o:getNumber() > 1 then
local q
q = GetQuantity.new(nil, nil, function(qty) self:doSell(who, o, item, qty) d:updateStore() end)
q = GetQuantity.new(nil, nil, function(qty) self:doSell(who, o, item, qty, d) end)
q.qty = o:getNumber()
game:registerDialog(q)
else
......@@ -97,37 +98,43 @@ function _M:interact(who)
game:registerDialog(d)
end
function _M:doBuy(who, o, item, nb)
function _M:doBuy(who, o, item, nb, store_dialog)
local max_nb = o:getNumber()
nb = math.min(nb, max_nb)
nb = self:onBuy(who, o, item, nb)
if nb then
local store, inven = self:getInven("INVEN"), who:getInven("INVEN")
for i = 1, nb do
local o = self:removeObject(store, item)
who:addObject(inven, o)
end
self:sortInven(store)
who:sortInven(inven)
self.changed = true
who.changed = true
Dialog:yesnoPopup("Buy", ("Buy %d %s"):format(nb, o:getName{do_color=true, no_count=true}), function(ok) if ok then
local store, inven = self:getInven("INVEN"), who:getInven("INVEN")
for i = 1, nb do
local o = self:removeObject(store, item)
who:addObject(inven, o)
end
self:sortInven(store)
who:sortInven(inven)
self.changed = true
who.changed = true
if store_dialog then store_dialog:updateStore() end
end end)
end
end
function _M:doSell(who, o, item, nb)
function _M:doSell(who, o, item, nb, store_dialog)
local max_nb = o:getNumber()
nb = math.min(nb, max_nb)
nb = self:onSell(who, o, item, nb)
if nb then
local store, inven = self:getInven("INVEN"), who:getInven("INVEN")
for i = 1, nb do
local o = who:removeObject(inven, item)
self:addObject(store, o)
end
self:sortInven(store)
who:sortInven(inven)
self.changed = true
who.changed = true
Dialog:yesnoPopup("Sell", ("Sell %d %s"):format(nb, o:getName{do_color=true, no_count=true}), function(ok) if ok then
local store, inven = self:getInven("INVEN"), who:getInven("INVEN")
for i = 1, nb do
local o = who:removeObject(inven, item)
self:addObject(store, o)
end
self:sortInven(store)
who:sortInven(inven)
self.changed = true
who.changed = true
if store_dialog then store_dialog:updateStore() end
end end)
end
end
......
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