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
13
local lh = 17 -- line height
7
local boxL = the.app.width / 2 - 200
8
local boxT = the.app.height / 2 - 200
16
11
fill = {255,255,255},
53
26
for i, good in ipairs(self.planet.goods) do
54
27
local t = Text:new{
57
y = boxT + 10 + i * lh,
66
y = boxT + 10 + i * lh,
74
y = boxT + 10 + i * lh - 1,
75
label = Text:new{ text = 'BUY', x = 1 },
76
onMouseDown = function (self)
77
the.player:buy(good[1], good[2])
80
local tw, th = b.label:getSize()
81
b.background = Fill:new{
90
y = boxT + 10 + i * lh - 1,
91
label = Text:new{ text = 'SELL', x = 1 },
92
onMouseDown = function (self)
93
the.player:sell(good[1], good[2])
96
local tw, th = b.label:getSize()
97
b.background = Fill:new{
104
local have = Text:new{
106
y = boxT + 10 + i * lh,
110
self.have[good[1]] = have
115
local b = Button:new{
117
label = Text:new{ text = 'Close', x = 3, y = 2 },
118
onMouseDown = function()
123
local tw, th = b.label:getSize()
124
b.background = Fill:new{
125
fill = {100,100,100},
129
b.x = boxR - b.background.width - 10
130
b.y = boxB - b.background.height - 10
134
local sh = the.player.shield
135
local cost = (sh.max - sh.strength) * sh.cost
139
-- WTF: trailing space makes it not wrap?
140
label = Text:new{ text = 'Repair shields (' .. cost .. ') ',
142
onMouseDown = function(self)
143
if the.player.money >= cost and sh.strength < sh.max then
144
the.player.money = the.player.money - cost
151
local tw, th = b.label:getSize()
152
b.background = Fill:new{
153
fill = {100,100,100},
157
b.x = boxR - b.background.width - 60
158
b.y = boxB - b.background.height - 10
160
if sh.strength < sh.max then
164
self.playerMoney = Text:new{
165
text = 'Your money: ',
170
self:add(self.playerMoney)
172
self.availSpace = Text:new{
173
text = 'Available cargo space: ',
176
y = boxB - 2 * th - 12
178
self:add(self.availSpace)
180
-- give the buttons a cycle to get out of the T/L corner
33
local tw, th = t:getSize()
34
t.y = boxT + 10 + (i-1) * th -- (th + 2) -- for padding?
183
39
activate = function (self)
184
40
the.cursor.visible = false
185
41
love.mouse.setVisible(true)
186
42
love.mouse.setGrab(false)
187
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
189
44
Subview.activate(self)
191
close = function (self)
194
the.cursor.visible = true
195
love.mouse.setVisible(false)
196
love.mouse.setGrab(true)
197
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
201
onUpdate = function (self)
202
if the.keys:justPressed('escape') then
206
self.playerMoney.text = 'Your money: ' .. the.player.money
207
self.availSpace.text = 'Available cargo space: ' .. the.player:availableSpace()
209
for good, have in pairs(self.have) do
210
have.text = the.player.goods[good] or 0
b'\\ No newline at end of file'