bzr branch
http://9ix.org/bzr/traderous
53
by Josh C
beginnings of trading interface |
1 |
TradeView = Subview:extend { |
2 |
drawParent = true, --default? |
|
3 |
onNew = function (self) |
|
4 |
-- create all the interface bits from the planet |
|
5 |
-- and add them to the view |
|
6 |
||
7 |
local boxL = the.app.width / 2 - 200 |
|
8 |
local boxT = the.app.height / 2 - 200 |
|
54
by Josh C
prices, buttons |
9 |
local boxR = boxL + 400 |
10 |
||
11 |
local lh = 17 -- line height |
|
53
by Josh C
beginnings of trading interface |
12 |
|
13 |
self:add(Fill:new{ |
|
14 |
fill = {255,255,255}, |
|
15 |
x = boxL - 1, |
|
16 |
y = boxT - 1, |
|
17 |
width = 402, |
|
18 |
height = 402, |
|
19 |
}) |
|
20 |
||
21 |
self:add(Fill:new{ |
|
22 |
fill = {0,0,0}, |
|
23 |
x = boxL, |
|
24 |
y = boxT, |
|
25 |
width = 400, |
|
26 |
height = 400, |
|
27 |
}) |
|
28 |
||
29 |
for i, good in ipairs(self.planet.goods) do |
|
30 |
local t = Text:new{ |
|
31 |
text = good[1], |
|
32 |
x = boxL + 10, |
|
54
by Josh C
prices, buttons |
33 |
y = boxT + 10 + (i-1) * lh, |
53
by Josh C
beginnings of trading interface |
34 |
width = 380 |
35 |
} |
|
36 |
||
54
by Josh C
prices, buttons |
37 |
self:add(t) |
38 |
||
39 |
t = Text:new{ |
|
40 |
text = good[2], |
|
41 |
x = boxL + 10, |
|
42 |
y = boxT + 10 + (i-1) * lh, |
|
43 |
width = 300, |
|
44 |
align = 'right' |
|
45 |
} |
|
46 |
self:add(t) |
|
47 |
||
48 |
local b = Button:new{ |
|
49 |
x = boxR - 80, |
|
50 |
y = boxT + 10 + (i-1) * lh - 1, |
|
51 |
label = Text:new{ text = 'BUY', x = 1 }, |
|
57
by Josh C
buy/sell |
52 |
onMouseDown = function (self) |
53 |
the.player:buy(good[1], good[2]) |
|
54 |
end |
|
54
by Josh C
prices, buttons |
55 |
} |
56 |
local tw, th = b.label:getSize() |
|
57 |
b.background = Fill:new{ |
|
58 |
fill = {100,100,100}, |
|
59 |
width = tw + 3, |
|
60 |
height = th |
|
61 |
} |
|
62 |
self:add(b) |
|
63 |
||
64 |
b = Button:new{ |
|
65 |
x = boxR - 40, |
|
66 |
y = boxT + 10 + (i-1) * lh - 1, |
|
67 |
label = Text:new{ text = 'SELL', x = 1 }, |
|
57
by Josh C
buy/sell |
68 |
onMouseDown = function (self) |
69 |
the.player:sell(good[1], good[2]) |
|
70 |
end |
|
54
by Josh C
prices, buttons |
71 |
} |
72 |
local tw, th = b.label:getSize() |
|
73 |
b.background = Fill:new{ |
|
74 |
fill = {100,100,100}, |
|
75 |
width = tw + 3, |
|
76 |
height = th |
|
77 |
} |
|
78 |
self:add(b) |
|
53
by Josh C
beginnings of trading interface |
79 |
end |
55
by Josh C
close button |
80 |
|
81 |
local b = Button:new{ |
|
82 |
x = boxL, y = boxT, |
|
83 |
label = Text:new{ text = 'Close', x = 3, y = 2 }, |
|
84 |
onMouseDown = function() |
|
85 |
self:close() |
|
86 |
end |
|
87 |
} |
|
88 |
||
89 |
local tw, th = b.label:getSize() |
|
90 |
b.background = Fill:new{ |
|
91 |
fill = {100,100,100}, |
|
92 |
width = tw + 7, |
|
93 |
height = th + 4 |
|
94 |
} |
|
95 |
b.x = boxR - b.background.width - 10 |
|
96 |
b.y = boxT + 400 - b.background.height - 10 |
|
97 |
||
98 |
self:add(b) |
|
99 |
||
56
by Josh C
money |
100 |
self.playerMoney = Text:new{ |
101 |
text = 'Your money: ', |
|
102 |
width = 200, |
|
103 |
x = boxL + 10, |
|
104 |
y = boxT + 400 - th - 10 |
|
105 |
} |
|
106 |
self:add(self.playerMoney) |
|
107 |
||
55
by Josh C
close button |
108 |
-- give the buttons a cycle to get out of the T/L corner |
109 |
self:update(0) |
|
53
by Josh C
beginnings of trading interface |
110 |
end, |
111 |
activate = function (self) |
|
112 |
the.cursor.visible = false |
|
113 |
love.mouse.setVisible(true) |
|
114 |
love.mouse.setGrab(false) |
|
115 |
||
116 |
Subview.activate(self) |
|
117 |
end, |
|
55
by Josh C
close button |
118 |
close = function (self) |
119 |
the.cursor.visible = true |
|
120 |
love.mouse.setVisible(false) |
|
121 |
love.mouse.setGrab(true) |
|
53
by Josh C
beginnings of trading interface |
122 |
|
55
by Josh C
close button |
123 |
self:deactivate() |
124 |
end, |
|
125 |
onUpdate = function (self) |
|
126 |
if the.keys:justPressed('escape') then |
|
127 |
self:close() |
|
128 |
end |
|
56
by Josh C
money |
129 |
|
130 |
self.playerMoney.text = 'Your money: ' .. the.player.money |
|
55
by Josh C
close button |
131 |
end |
53
by Josh C
beginnings of trading interface |
132 |
} |