summaryrefslogtreecommitdiffstats
path: root/scripts/menu_functions.lua
blob: 8d302e9fea3914708fb80c4b05b1ecca6113b04c (plain)
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
GetMenuValue = {}
MenuAction = {}

GetMenuValue[ MenuC.type.menu ] = function ( menu )
   -- return "(menu)"
   return ""
end

MenuAction[ MenuC.type.menu ] = function ( menu )
   Menu.current = menu 
   Menu.active = 1
end

GetMenuValue[ MenuC.type.list ] = function ( menu )
   local value
   if Menu[menu].read then value = Menu[menu].read() end
   if not value then value = "undef" end

   -- script_print(menu .. " --> " .. value )
   local i
   for i=1,getn(Menu[menu].values) do
      if Menu[menu].values[i] == value then return Menu[menu].labels[i] end
   end
   return "unknown (" .. value .. ")"
end

MenuAction[ MenuC.type.list ] = function ( menu )
   local value
   if Menu[menu].read then 
      value = Menu[menu].read()
   else
      value = "undef"
   end

   local nValues = getn(Menu[menu].values)
   local i
   for i=1,nValues do
      if Menu[menu].values[i] == value then
	 if i < nValues then
	    value = Menu[menu].values[i + 1]
	 else
	    value = Menu[menu].values[1]
	 end
	 return Menu[menu].store( value ) 
      end
   end
   return Menu[menu].store( Menu[menu].values[1] )
end

MenuAction[ MenuC.type.action ] = function ( menu )
   Menu[menu].action()
end

GetMenuValue[ MenuC.type.slider ] = function ( menu )
   return Menu[menu].read()
end

MenuAction[ MenuC.type.slider ] = function( menu )
   if Menu[menu].action then
      Menu[menu].action()
   end
end

MenuAction[ MenuC.type.key ] = function ( menu )
   local player = Menu[menu].player
   local event = Menu[menu].event
   configure_player = player
   configure_event = event
   c_configureKeyboard()
end

GetMenuValue[ MenuC.type.key ] = function ( menu )
   local player = Menu[menu].player
   local event = Menu[menu].event
   return c_getKeyName( settings.keys[ player ][ event ] )
end

GetMenuValue[ MenuC.type.action ] = function ( menu )
   -- return "(action)"
   return ""
end

GetMenuValueWidth = function ( menu )
   return strlen( GetMenuValue[ Menu[menu].type ]( menu ) )
end

GetMenuValueString = function ( menu )
   -- write(format("GetMenuValueString: '%s'\n", menu));
   return GetMenuValue[ Menu[menu].type ]( menu )
end