/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-06-16 00:13:58 UTC
  • Revision ID: josh@9ix.org-20130616001358-dw3n864y37fgw1hs
buy/sell

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
TradeView = Subview:extend {
2
2
   drawParent = true, --default?
3
 
   have = {},
4
3
   onNew = function (self)
5
4
              -- create all the interface bits from the planet
6
5
              -- and add them to the view
7
6
 
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
12
10
 
13
11
              local lh = 17 -- line height
14
12
 
16
14
                          fill = {255,255,255},
17
15
                          x = boxL - 1,
18
16
                          y = boxT - 1,
19
 
                          width = 452,
20
 
                          height = 302,
 
17
                          width = 402,
 
18
                          height = 402,
21
19
                       })
22
20
 
23
21
              self:add(Fill:new{
24
22
                          fill = {0,0,0},
25
23
                          x = boxL,
26
24
                          y = boxT,
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
 
25
                          width = 400,
 
26
                          height = 400,
51
27
                       })
52
28
 
53
29
              for i, good in ipairs(self.planet.goods) do
54
30
                 local t = Text:new{
55
31
                    text = good[1],
56
32
                    x = boxL + 10,
57
 
                    y = boxT + 10 + i * lh,
 
33
                    y = boxT + 10 + (i-1) * lh,
58
34
                    width = 380
59
35
                 }
60
36
 
63
39
                 t = Text:new{
64
40
                    text = good[2],
65
41
                    x = boxL + 10,
66
 
                    y = boxT + 10 + i * lh,
 
42
                    y = boxT + 10 + (i-1) * lh,
67
43
                    width = 300,
68
44
                    align = 'right'
69
45
                 }
70
46
                 self:add(t)
71
47
 
72
48
                 local b = Button:new{
73
 
                    x = boxR - 130,
74
 
                    y = boxT + 10 + i * lh - 1,
 
49
                    x = boxR - 80,
 
50
                    y = boxT + 10 + (i-1) * lh - 1,
75
51
                    label = Text:new{ text = 'BUY', x = 1 },
76
52
                    onMouseDown = function (self)
77
53
                                     the.player:buy(good[1], good[2])
86
62
                 self:add(b)
87
63
 
88
64
                 b = Button:new{
89
 
                    x = boxR - 90,
90
 
                    y = boxT + 10 + i * lh - 1,
 
65
                    x = boxR - 40,
 
66
                    y = boxT + 10 + (i-1) * lh - 1,
91
67
                    label = Text:new{ text = 'SELL', x = 1 },
92
68
                    onMouseDown = function (self)
93
69
                                     the.player:sell(good[1], good[2])
100
76
                    height = th
101
77
                 }
102
78
                 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
 
 
113
79
              end
114
80
 
115
81
              local b = Button:new{
127
93
                 height = th + 4
128
94
              }
129
95
              b.x = boxR - b.background.width - 10
130
 
              b.y = boxB - b.background.height - 10
 
96
              b.y = boxT + 400 - b.background.height - 10
131
97
 
132
98
              self:add(b)
133
99
 
135
101
                 text = 'Your money: ',
136
102
                 width = 200,
137
103
                 x = boxL + 10,
138
 
                 y = boxB - th - 10
 
104
                 y = boxT + 400 - th - 10
139
105
              }
140
106
              self:add(self.playerMoney)
141
107
 
146
112
                 the.cursor.visible = false
147
113
                 love.mouse.setVisible(true)
148
114
                 love.mouse.setGrab(false)
149
 
                 love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
150
115
 
151
116
                 Subview.activate(self)
152
117
              end,
154
119
              the.cursor.visible = true
155
120
              love.mouse.setVisible(false)
156
121
              love.mouse.setGrab(true)
157
 
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
158
122
 
159
123
              self:deactivate()
160
124
           end,
164
128
                 end
165
129
 
166
130
                 self.playerMoney.text = 'Your money: ' .. the.player.money
167
 
 
168
 
                 for good, have in pairs(self.have) do
169
 
                    have.text = the.player.goods[good] or 0
170
 
                 end
171
131
              end
172
132
}
 
 
b'\\ No newline at end of file'