Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/AudioMenu.lua @ 7922

Last change on this file since 7922 was 7922, checked in by landauf, 13 years ago

implemented new keyboard control of menu buttons with these new features:

  • more intuitive placement of buttons in table (row/column format instead of linear index)
  • no need to overwrite onShow() and onKeyPressed() functions, no need for P.buttonList
  • highlights the selected button in a different layout than mouse hovering
  • remembers the selection while moving through the menu hierarchy, but resets it if the menu is closed
  • allows preselected button (for example "Yes" in decision popup)
  • when opening a menu, the first selected button is not always the upper left, but instead depends on the pressed key (e.g. the 'up' key selects the button at the bottom, while the 'down' key selects the button at the top. once a button is selected, the keys behave as usual)

+ fixed wrong callback function in ingame menu

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1-- AudioMenu.lua
2
3local P = createMenuSheet("AudioMenu")
4
5function P.onLoad()
6    soundMgr = orxonox.SoundManager:getInstance()
7    block = false
8    masterscrollbar_active = false
9    musicscrollbar_active = false
10    effectsscrollbar_active = false
11    mastervolume = soundMgr:getVolume(orxonox.SoundType.All)
12    musicvolume = soundMgr:getVolume(orxonox.SoundType.Music)
13    effectsvolume = soundMgr:getVolume(orxonox.SoundType.Effects)
14    mastermute = soundMgr:getMute(orxonox.SoundType.All)
15    musicmute = soundMgr:getMute(orxonox.SoundType.Music)
16    effectsmute = soundMgr:getMute(orxonox.SoundType.Effects)
17    masterscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MasterScrollbar"),"CEGUI::Scrollbar")
18    musicscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MusicScrollbar"),"CEGUI::Scrollbar")
19    effectsscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/EffectsScrollbar"),"CEGUI::Scrollbar")
20    mastermutewindow = tolua.cast(winMgr:getWindow("orxonox/MasterCheckbox"),"CEGUI::Checkbox")
21    musicmutewindow = tolua.cast(winMgr:getWindow("orxonox/MusicCheckbox"),"CEGUI::Checkbox")
22    effectsmutewindow = tolua.cast(winMgr:getWindow("orxonox/EffectsCheckbox"),"CEGUI::Checkbox")
23    masterscrollbarwindow:setScrollPosition(mastervolume)
24    musicscrollbarwindow:setScrollPosition(musicvolume)
25    effectsscrollbarwindow:setScrollPosition(effectsvolume)
26    mastermutewindow:setSelected(mastermute)
27    musicmutewindow:setSelected(musicmute)
28    effectsmutewindow:setSelected(effectsmute)
29    choice = "Default"
30    listboxwindow = winMgr:getWindow("orxonox/AudioThemeListbox")
31    local themeList = {}
32    table.insert(themeList, "Default")
33    table.insert(themeList, "Drum n' Bass")
34    for k,v in pairs(themeList) do
35        item = CEGUI.createListboxTextItem(v)
36        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
37        CEGUI.toListbox(listboxwindow):addItem(item)
38    end
39    if orxonox.getConfig("MoodManager", "mood_") == "dnb" then
40        listboxwindow:setItemSelectState(1,true)
41    else
42        listboxwindow:setItemSelectState(0,true)
43    end
44
45    P:initButtons(1, 1)
46    P:setButton(1, 1, {
47            ["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
48            ["callback"]  = P.AudioBackButton_clicked
49    })
50end
51
52function P.AudioMasterScrollbar_changed(e)
53    if mastermute then
54        block = true
55        mastermutewindow:setSelected(false)
56        block = false
57        mastermute = false
58    end
59    if masterscrollbar_active == false then
60        mastervolume = masterscrollbarwindow:getScrollPosition()
61        orxonox.config("SoundManager", "soundVolume_", mastervolume)
62    end
63end
64
65function P.AudioMasterScrollbar_started(e)
66    masterscrollbar_active = true
67end
68
69function P.AudioMasterScrollbar_ended(e)
70    mastervolume = masterscrollbarwindow:getScrollPosition()
71    orxonox.config("SoundManager", "soundVolume_", mastervolume)
72    masterscrollbar_active = false
73end
74
75function P.AudioMusicScrollbar_changed(e)
76    if musicmute then
77        block = true
78        musicmutewindow:setSelected(false)
79        block = false
80        musicmute = false
81    end
82    if musicscrollbar_active == false then
83        musicvolume = musicscrollbarwindow:getScrollPosition()
84        orxonox.config("SoundManager", "ambientVolume_", musicvolume)
85    end
86end
87
88function P.AudioMusicScrollbar_started(e)
89    musicscrollbar_active = true
90end
91
92function P.AudioMusicScrollbar_ended(e)
93    musicmutewindow:setSelected(false)
94    musicvolume = musicscrollbarwindow:getScrollPosition()
95    orxonox.config("SoundManager", "ambientVolume_", musicvolume)
96    musicscrollbar_active = false
97end
98
99function P.AudioEffectsScrollbar_changed(e)
100    if effectsmute then
101        block = true
102        effectsmutewindow:setSelected(false)
103        block = false
104        effectsmute = false
105    end
106    if effectsscrollbar_active == false then
107        effectsvolume = effectsscrollbarwindow:getScrollPosition()
108        orxonox.config("SoundManager", "effectsVolume_", effectsvolume)
109    end
110end
111
112function P.AudioEffectsScrollbar_started(e)
113    effectsscrollbar_active = true
114end
115
116function P.AudioEffectsScrollbar_ended(e)
117    effectsmutewindow:setSelected(false)
118    effectsvolume = effectsscrollbarwindow:getScrollPosition()
119    orxonox.config("SoundManager", "effectsVolume_", effectsvolume)
120    effectsscrollbar_active = false
121end
122
123function P.AudioMuteMasterCheckbox_clicked(e)
124    if block == false then
125        if mastermute then
126            masterscrollbarwindow:setScrollPosition(mastervolume)
127            mastermute = false
128        else
129            temp = masterscrollbarwindow:getScrollPosition()
130            masterscrollbarwindow:setScrollPosition(0)
131            mastervolume = temp
132            mastermute = true
133        end
134    end
135    soundMgr:toggleMute(orxonox.SoundType.All)
136end
137
138function P.AudioMuteMusicCheckbox_clicked(e)
139    if block == false then
140        if musicmute then
141            musicscrollbarwindow:setScrollPosition(musicvolume)
142            musicmute = false
143        else
144            temp = musicscrollbarwindow:getScrollPosition()
145            musicscrollbarwindow:setScrollPosition(0)
146            musicvolume = temp
147            musicmute = true
148        end
149    end
150    soundMgr:toggleMute(orxonox.SoundType.Music)
151end
152
153function P.AudioMuteEffectsCheckbox_clicked(e)
154    if block == false then
155        if effectsmute then
156            effectsscrollbarwindow:setScrollPosition(effectsvolume)
157            effectsmute = false
158        else
159            temp = effectsscrollbarwindow:getScrollPosition()
160            effectsscrollbarwindow:setScrollPosition(0)
161            effectsvolume = temp
162            effectsmute = true
163        end
164    end
165    soundMgr:toggleMute(orxonox.SoundType.Effects)
166end
167
168function P.AudioThemeListbox_changed(e)
169    if listboxwindow:isItemSelected(1) then
170        orxonox.config("MoodManager", "mood_", "dnb")
171    else
172        orxonox.config("MoodManager", "mood_", "default")
173    end
174end
175
176function P.AudioBackButton_clicked(e)
177    hideMenuSheet(P.name)
178end
179
180return P
181
Note: See TracBrowser for help on using the repository browser.