/traderous

To get this branch, use:
bzr branch http://9ix.org/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
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 },
                 }
                 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 },
                 }
                 local tw, th = b.label:getSize()
                 b.background = Fill:new{
                    fill = {100,100,100},
                    width = tw + 3,
                    height = th
                 }
                 self:add(b)

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

                 Subview.activate(self)
              end,

}