/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous

« back to all changes in this revision

Viewing changes to trade_view.lua

  • Committer: Josh C
  • Date: 2013-10-21 18:31:55 UTC
  • Revision ID: josh@9ix.org-20131021183155-vl7pxaor2u3pw0t0
have enemies disengage when you land

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
TradeView = Subview:extend {
2
2
   drawParent = true, --default?
 
3
   have = {},
3
4
   onNew = function (self)
4
5
              -- create all the interface bits from the planet
5
6
              -- and add them to the view
6
7
 
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
10
12
 
11
13
              local lh = 17 -- line height
12
14
 
14
16
                          fill = {255,255,255},
15
17
                          x = boxL - 1,
16
18
                          y = boxT - 1,
17
 
                          width = 402,
18
 
                          height = 402,
 
19
                          width = 452,
 
20
                          height = 302,
19
21
                       })
20
22
 
21
23
              self:add(Fill:new{
22
24
                          fill = {0,0,0},
23
25
                          x = boxL,
24
26
                          y = boxT,
25
 
                          width = 400,
26
 
                          height = 400,
 
27
                          width = 450,
 
28
                          height = 300,
 
29
                       })
 
30
 
 
31
              self:add(Text:new{
 
32
                          text = 'Name',
 
33
                          x = boxL + 10,
 
34
                          y = boxT + 10,
 
35
                          width = 380
 
36
                       })
 
37
 
 
38
              self:add(Text:new{
 
39
                          text = 'Price',
 
40
                          x = boxL + 10,
 
41
                          y = boxT + 10,
 
42
                          width = 300,
 
43
                          align = 'right'
 
44
                       })
 
45
 
 
46
              self:add(Text:new{
 
47
                          text = 'Have',
 
48
                          align = 'right',
 
49
                          y = boxT + 10,
 
50
                          x = boxR - 40
27
51
                       })
28
52
 
29
53
              for i, good in ipairs(self.planet.goods) do
30
54
                 local t = Text:new{
31
55
                    text = good[1],
32
56
                    x = boxL + 10,
33
 
                    y = boxT + 10 + (i-1) * lh,
 
57
                    y = boxT + 10 + i * lh,
34
58
                    width = 380
35
59
                 }
36
60
 
39
63
                 t = Text:new{
40
64
                    text = good[2],
41
65
                    x = boxL + 10,
42
 
                    y = boxT + 10 + (i-1) * lh,
 
66
                    y = boxT + 10 + i * lh,
43
67
                    width = 300,
44
68
                    align = 'right'
45
69
                 }
46
70
                 self:add(t)
47
71
 
48
72
                 local b = Button:new{
49
 
                    x = boxR - 80,
50
 
                    y = boxT + 10 + (i-1) * lh - 1,
 
73
                    x = boxR - 130,
 
74
                    y = boxT + 10 + i * lh - 1,
51
75
                    label = Text:new{ text = 'BUY', x = 1 },
52
76
                    onMouseDown = function (self)
53
77
                                     the.player:buy(good[1], good[2])
62
86
                 self:add(b)
63
87
 
64
88
                 b = Button:new{
65
 
                    x = boxR - 40,
66
 
                    y = boxT + 10 + (i-1) * lh - 1,
 
89
                    x = boxR - 90,
 
90
                    y = boxT + 10 + i * lh - 1,
67
91
                    label = Text:new{ text = 'SELL', x = 1 },
68
92
                    onMouseDown = function (self)
69
93
                                     the.player:sell(good[1], good[2])
76
100
                    height = th
77
101
                 }
78
102
                 self:add(b)
 
103
 
 
104
                 local have = Text:new{
 
105
                    x = boxR - 110,
 
106
                    y = boxT + 10 + i * lh,
 
107
                    width = 100,
 
108
                    align = 'right',
 
109
                 }
 
110
                 self.have[good[1]] = have
 
111
                 self:add(have)
 
112
 
79
113
              end
80
114
 
81
115
              local b = Button:new{
93
127
                 height = th + 4
94
128
              }
95
129
              b.x = boxR - b.background.width - 10
96
 
              b.y = boxT + 400 - b.background.height - 10
 
130
              b.y = boxB - b.background.height - 10
97
131
 
98
132
              self:add(b)
99
133
 
 
134
              local sh = the.player.shield
 
135
              if sh.strength < sh.max then
 
136
                 sh.strength = sh.max
 
137
 
 
138
                 self:add(Text:new{
 
139
                             text = 'Your shield has been recharged',
 
140
                             width = 450,
 
141
                             align = 'center',
 
142
                             x = boxL,
 
143
                             y = boxB - 4 * th - 12
 
144
                          })
 
145
              end
 
146
 
 
147
              -- local cost = (sh.max - sh.strength) * sh.cost
 
148
              -- b = Button:new{
 
149
              --    x = boxL, y = boxT,
 
150
              --    width = 800,
 
151
              --    -- WTF: trailing space makes it not wrap?
 
152
              --    label = Text:new{ text = 'Repair shields (' .. cost .. ') ',
 
153
              --                      x = 3, y = 2 },
 
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
 
159
              --                     end
 
160
              --                  end
 
161
              -- }
 
162
 
 
163
              -- local tw, th = b.label:getSize()
 
164
              -- b.background = Fill:new{
 
165
              --    fill = {100,100,100},
 
166
              --    width = tw + 3,
 
167
              --    height = th + 4
 
168
              -- }
 
169
              -- b.x = boxR - b.background.width - 60
 
170
              -- b.y = boxB - b.background.height - 10
 
171
 
 
172
              -- if sh.strength < sh.max then
 
173
              --    self:add(b)
 
174
              -- end
 
175
 
100
176
              self.playerMoney = Text:new{
101
177
                 text = 'Your money: ',
102
178
                 width = 200,
103
179
                 x = boxL + 10,
104
 
                 y = boxT + 400 - th - 10
 
180
                 y = boxB - th - 10
105
181
              }
106
182
              self:add(self.playerMoney)
107
183
 
 
184
              self.availSpace = Text:new{
 
185
                 text = 'Available cargo space: ',
 
186
                 width = 200,
 
187
                 x = boxL + 10,
 
188
                 y = boxB - 2 * th - 12
 
189
              }
 
190
              self:add(self.availSpace)
 
191
 
 
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 ' ..
 
196
                 --                award ..
 
197
                 --                ' credits for killing bandits.',
 
198
                 --             width = 450,
 
199
                 --             align = 'center',
 
200
                 --             x = boxL,
 
201
                 --             y = boxB - 4 * th - 12
 
202
                 --          })
 
203
 
 
204
                 -- the.player.money = the.player.money + award
 
205
                 the.player.kills = 0
 
206
              end
 
207
 
108
208
              -- give the buttons a cycle to get out of the T/L corner
109
209
              self:update(0)
110
210
           end,
112
212
                 the.cursor.visible = false
113
213
                 love.mouse.setVisible(true)
114
214
                 love.mouse.setGrab(false)
 
215
                 love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
115
216
 
116
217
                 Subview.activate(self)
117
218
              end,
118
219
   close = function (self)
 
220
              the.player:save()
 
221
 
119
222
              the.cursor.visible = true
120
223
              love.mouse.setVisible(false)
121
224
              love.mouse.setGrab(true)
 
225
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
122
226
 
123
227
              self:deactivate()
124
228
           end,
128
232
                 end
129
233
 
130
234
                 self.playerMoney.text = 'Your money: ' .. the.player.money
 
235
                 self.availSpace.text = 'Available cargo space: ' .. the.player:availableSpace()
 
236
 
 
237
                 for good, have in pairs(self.have) do
 
238
                    have.text = the.player.goods[good] or 0
 
239
                 end
131
240
              end
132
241
}
 
 
b'\\ No newline at end of file'