/traderous

To get this branch, use:
bzr branch /bzr/traderous
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
TradeView = Subview:extend {
   drawParent = true, --default?
   onNew = function (self)
              -- create all the interface bits from the planet
              -- and add them to the view

              local boxL = the.app.width / 2 - 200
              local boxT = the.app.height / 2 - 200
              local boxR = boxL + 400

              local lh = 17 -- line height

              self:add(Fill:new{
                          fill = {255,255,255},
                          x = boxL - 1,
                          y = boxT - 1,
                          width = 402,
                          height = 402,
                       })

              self:add(Fill:new{
                          fill = {0,0,0},
                          x = boxL,
                          y = boxT,
                          width = 400,
                          height = 400,
                       })

              for i, good in ipairs(self.planet.goods) do
                 local t = Text:new{
                    text = good[1],
                    x = boxL + 10,
                    y = boxT + 10 + (i-1) * lh,
                    width = 380
                 }

                 self:add(t)

                 t = Text:new{
                    text = good[2],
                    x = boxL + 10,
                    y = boxT + 10 + (i-1) * lh,
                    width = 300,
                    align = 'right'
                 }
                 self:add(t)

                 local b = Button:new{
                    x = boxR - 80,
                    y = boxT + 10 + (i-1) * lh - 1,
                    label = Text:new{ text = 'BUY', x = 1 },
                    onMouseDown = function (self)
                                     the.player:buy(good[1], good[2])
                                  end
                 }
                 local tw, th = b.label:getSize()
                 b.background = Fill:new{
                    fill = {100,100,100},
                    width = tw + 3,
                    height = th
                 }
                 self:add(b)

                 b = Button:new{
                    x = boxR - 40,
                    y = boxT + 10 + (i-1) * lh - 1,
                    label = Text:new{ text = 'SELL', x = 1 },
                    onMouseDown = function (self)
                                     the.player:sell(good[1], good[2])
                                  end
                 }
                 local tw, th = b.label:getSize()
                 b.background = Fill:new{
                    fill = {100,100,100},
                    width = tw + 3,
                    height = th
                 }
                 self:add(b)
              end

              local b = Button:new{
                 x = boxL, y = boxT,
                 label = Text:new{ text = 'Close', x = 3, y = 2 },
                 onMouseDown = function()
                                  self:close()
                               end
              }

              local tw, th = b.label:getSize()
              b.background = Fill:new{
                 fill = {100,100,100},
                 width = tw + 7,
                 height = th + 4
              }
              b.x = boxR - b.background.width - 10
              b.y = boxT + 400 - b.background.height - 10

              self:add(b)

              self.playerMoney = Text:new{
                 text = 'Your money: ',
                 width = 200,
                 x = boxL + 10,
                 y = boxT + 400 - th - 10
              }
              self:add(self.playerMoney)

              -- give the buttons a cycle to get out of the T/L corner
              self:update(0)
           end,
   activate = function (self)
                 the.cursor.visible = false
                 love.mouse.setVisible(true)
                 love.mouse.setGrab(false)

                 Subview.activate(self)
              end,
   close = function (self)
              the.cursor.visible = true
              love.mouse.setVisible(false)
              love.mouse.setGrab(true)

              self:deactivate()
           end,
   onUpdate = function (self)
                 if the.keys:justPressed('escape') then
                    self:close()
                 end

                 self.playerMoney.text = 'Your money: ' .. the.player.money
              end
}