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{
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
self.playerMoney = Text:new{
135
text = 'Your money: ',
140
self:add(self.playerMoney)
142
-- give the buttons a cycle to get out of the T/L corner
145
76
activate = function (self)
146
77
the.cursor.visible = false
147
78
love.mouse.setVisible(true)
148
79
love.mouse.setGrab(false)
149
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
151
81
Subview.activate(self)
153
close = function (self)
154
the.cursor.visible = true
155
love.mouse.setVisible(false)
156
love.mouse.setGrab(true)
157
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
161
onUpdate = function (self)
162
if the.keys:justPressed('escape') then
166
self.playerMoney.text = 'Your money: ' .. the.player.money
168
for good, have in pairs(self.have) do
169
have.text = the.player.goods[good] or 0
b'\\ No newline at end of file'