1
1
TradeView = Subview:extend {
2
2
drawParent = true, --default?
3
4
onNew = function (self)
4
5
-- create all the interface bits from the planet
5
6
-- and add them to the view
7
local boxL = the.app.width / 2 - 200
8
local boxT = the.app.height / 2 - 200
9
local boxR = boxL + 400
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
11
13
local lh = 17 -- line height
42
y = boxT + 10 + (i-1) * lh,
66
y = boxT + 10 + i * lh,
48
72
local b = Button:new{
50
y = boxT + 10 + (i-1) * lh - 1,
74
y = boxT + 10 + i * lh - 1,
51
75
label = Text:new{ text = 'BUY', x = 1 },
76
onMouseDown = function (self)
77
the.player:buy(good[1], good[2])
53
80
local tw, th = b.label:getSize()
54
81
b.background = Fill:new{
63
y = boxT + 10 + (i-1) * lh - 1,
90
y = boxT + 10 + i * lh - 1,
64
91
label = Text:new{ text = 'SELL', x = 1 },
92
onMouseDown = function (self)
93
the.player:sell(good[1], good[2])
66
96
local tw, th = b.label:getSize()
67
97
b.background = Fill:new{
89
129
b.x = boxR - b.background.width - 10
90
b.y = boxT + 400 - b.background.height - 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
94
164
self.playerMoney = Text:new{
95
165
text = 'Your money: ',
98
y = boxT + 400 - th - 10
100
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
if the.player.kills > 0 then
181
local award = the.player.kills * 100
183
text = 'You have been awarded ' ..
185
' credits for killing bandits.',
189
y = boxB - 4 * th - 12
192
the.player.money = the.player.money + award
102
195
-- give the buttons a cycle to get out of the T/L corner
106
199
the.cursor.visible = false
107
200
love.mouse.setVisible(true)
108
201
love.mouse.setGrab(false)
202
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
110
204
Subview.activate(self)
112
206
close = function (self)
113
209
the.cursor.visible = true
114
210
love.mouse.setVisible(false)
115
211
love.mouse.setGrab(true)
212
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
117
214
self:deactivate()
124
221
self.playerMoney.text = 'Your money: ' .. the.player.money
222
self.availSpace.text = 'Available cargo space: ' .. the.player:availableSpace()
224
for good, have in pairs(self.have) do
225
have.text = the.player.goods[good] or 0
b'\\ No newline at end of file'