/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-05-09 01:26:36 UTC
  • Revision ID: josh@9ix.org-20130509012636-1hgzcgai2xtj0lfw
dead zone with no acceleration

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
9
 
              local boxR = boxL + 400
10
 
 
11
 
              local lh = 17 -- line height
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,
33
 
                    y = boxT + 10 + (i-1) * lh,
34
 
                    width = 380
35
 
                 }
36
 
 
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 },
52
 
                 }
53
 
                 local tw, th = b.label:getSize()
54
 
                 b.background = Fill:new{
55
 
                    fill = {100,100,100},
56
 
                    width = tw + 3,
57
 
                    height = th
58
 
                 }
59
 
                 self:add(b)
60
 
 
61
 
                 b = Button:new{
62
 
                    x = boxR - 40,
63
 
                    y = boxT + 10 + (i-1) * lh - 1,
64
 
                    label = Text:new{ text = 'SELL', x = 1 },
65
 
                 }
66
 
                 local tw, th = b.label:getSize()
67
 
                 b.background = Fill:new{
68
 
                    fill = {100,100,100},
69
 
                    width = tw + 3,
70
 
                    height = th
71
 
                 }
72
 
                 self:add(b)
73
 
              end
74
 
 
75
 
              local b = Button:new{
76
 
                 x = boxL, y = boxT,
77
 
                 label = Text:new{ text = 'Close', x = 3, y = 2 },
78
 
                 onMouseDown = function()
79
 
                                  self:close()
80
 
                               end
81
 
              }
82
 
 
83
 
              local tw, th = b.label:getSize()
84
 
              b.background = Fill:new{
85
 
                 fill = {100,100,100},
86
 
                 width = tw + 7,
87
 
                 height = th + 4
88
 
              }
89
 
              b.x = boxR - b.background.width - 10
90
 
              b.y = boxT + 400 - b.background.height - 10
91
 
 
92
 
              self:add(b)
93
 
 
94
 
              self.playerMoney = Text:new{
95
 
                 text = 'Your money: ',
96
 
                 width = 200,
97
 
                 x = boxL + 10,
98
 
                 y = boxT + 400 - th - 10
99
 
              }
100
 
              self:add(self.playerMoney)
101
 
 
102
 
              -- give the buttons a cycle to get out of the T/L corner
103
 
              self:update(0)
104
 
           end,
105
 
   activate = function (self)
106
 
                 the.cursor.visible = false
107
 
                 love.mouse.setVisible(true)
108
 
                 love.mouse.setGrab(false)
109
 
 
110
 
                 Subview.activate(self)
111
 
              end,
112
 
   close = function (self)
113
 
              the.cursor.visible = true
114
 
              love.mouse.setVisible(false)
115
 
              love.mouse.setGrab(true)
116
 
 
117
 
              self:deactivate()
118
 
           end,
119
 
   onUpdate = function (self)
120
 
                 if the.keys:justPressed('escape') then
121
 
                    self:close()
122
 
                 end
123
 
 
124
 
                 self.playerMoney.text = 'Your money: ' .. the.player.money
125
 
              end
126
 
}
 
 
b'\\ No newline at end of file'