1
1
TradeView = Subview:extend {
2
2
drawParent = true, --default?
4
3
onNew = function (self)
5
4
-- create all the interface bits from the planet
6
5
-- and add them to the view
8
local boxL = the.app.width / 2 - 225
9
local boxT = the.app.height / 2 - 150
10
local boxR = boxL + 450
11
local boxB = boxT + 300
7
local boxL = the.app.width / 2 - 200
8
local boxT = the.app.height / 2 - 200
9
local boxR = boxL + 400
13
11
local lh = 17 -- line height
66
y = boxT + 10 + i * lh,
42
y = boxT + 10 + (i-1) * lh,
72
48
local b = Button:new{
74
y = boxT + 10 + i * lh - 1,
50
y = boxT + 10 + (i-1) * lh - 1,
75
51
label = Text:new{ text = 'BUY', x = 1 },
76
onMouseDown = function (self)
77
the.player:buy(good[1], good[2])
80
53
local tw, th = b.label:getSize()
81
54
b.background = Fill:new{
90
y = boxT + 10 + i * lh - 1,
63
y = boxT + 10 + (i-1) * lh - 1,
91
64
label = Text:new{ text = 'SELL', x = 1 },
92
onMouseDown = function (self)
93
the.player:sell(good[1], good[2])
96
66
local tw, th = b.label:getSize()
97
67
b.background = Fill:new{
129
89
b.x = boxR - b.background.width - 10
130
b.y = boxB - b.background.height - 10
90
b.y = boxT + 400 - b.background.height - 10
134
local sh = the.player.shield
135
if sh.strength < sh.max then
139
text = 'Your shield has been recharged',
143
y = boxB - 4 * th - 12
147
-- local cost = (sh.max - sh.strength) * sh.cost
149
-- x = boxL, y = boxT,
151
-- -- WTF: trailing space makes it not wrap?
152
-- label = Text:new{ text = 'Repair shields (' .. cost .. ') ',
154
-- onMouseDown = function(self)
155
-- if the.player.money >= cost and sh.strength < sh.max then
156
-- the.player.money = the.player.money - cost
157
-- sh.strength = sh.max
158
-- self.visible = false
163
-- local tw, th = b.label:getSize()
164
-- b.background = Fill:new{
165
-- fill = {100,100,100},
169
-- b.x = boxR - b.background.width - 60
170
-- b.y = boxB - b.background.height - 10
172
-- if sh.strength < sh.max then
176
94
self.playerMoney = Text:new{
177
95
text = 'Your money: ',
98
y = boxT + 400 - th - 10
182
100
self:add(self.playerMoney)
184
self.availSpace = Text:new{
185
text = 'Available cargo space: ',
188
y = boxB - 2 * th - 12
190
self:add(self.availSpace)
192
if the.player.kills > 0 then
193
-- local award = the.player.kills * 100
194
-- self:add(Text:new{
195
-- text = 'You have been awarded ' ..
197
-- ' credits for killing bandits.',
201
-- y = boxB - 4 * th - 12
204
-- the.player.money = the.player.money + award
208
102
-- give the buttons a cycle to get out of the T/L corner
212
106
the.cursor.visible = false
213
107
love.mouse.setVisible(true)
214
108
love.mouse.setGrab(false)
215
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
217
110
Subview.activate(self)
219
112
close = function (self)
222
113
the.cursor.visible = true
223
114
love.mouse.setVisible(false)
224
115
love.mouse.setGrab(true)
225
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
227
117
self:deactivate()
234
124
self.playerMoney.text = 'Your money: ' .. the.player.money
235
self.availSpace.text = 'Available cargo space: ' .. the.player:availableSpace()
237
for good, have in pairs(self.have) do
238
have.text = the.player.goods[good] or 0
b'\\ No newline at end of file'