Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 12222 was 7928, checked in by landauf, 14 years ago

more improvements for keyboard control of menus:

  • added setSelectionNear(r, c) function which tries to select the button closest to the given row/column
  • no initialization required anymore, the button-table grows dynamically if new buttons are inserted
  • Property svn:eol-style set to native
File size: 5.9 KB
RevLine 
[6363]1-- AudioMenu.lua
2
[6746]3local P = createMenuSheet("AudioMenu")
[6363]4
[6746]5function P.onLoad()
[6363]6    soundMgr = orxonox.SoundManager:getInstance()
7    block = false
8    masterscrollbar_active = false
9    musicscrollbar_active = false
10    effectsscrollbar_active = false
[6370]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)
[6363]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
[6388]35        item = CEGUI.createListboxTextItem(v)
[6746]36        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[6363]37        CEGUI.toListbox(listboxwindow):addItem(item)
38    end
[6406]39    if orxonox.getConfig("MoodManager", "mood_") == "dnb" then
40        listboxwindow:setItemSelectState(1,true)
41    else
42        listboxwindow:setItemSelectState(0,true)
43    end
[7689]44
[7922]45    P:setButton(1, 1, {
[7689]46            ["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
[7922]47            ["callback"]  = P.AudioBackButton_clicked
48    })
[6363]49end
50
51function P.AudioMasterScrollbar_changed(e)
52    if mastermute then
53        block = true
54        mastermutewindow:setSelected(false)
55        block = false
56        mastermute = false
57    end
58    if masterscrollbar_active == false then
59        mastervolume = masterscrollbarwindow:getScrollPosition()
[6403]60        orxonox.config("SoundManager", "soundVolume_", mastervolume)
[6363]61    end
62end
63
64function P.AudioMasterScrollbar_started(e)
65    masterscrollbar_active = true
66end
67
68function P.AudioMasterScrollbar_ended(e)
69    mastervolume = masterscrollbarwindow:getScrollPosition()
[6403]70    orxonox.config("SoundManager", "soundVolume_", mastervolume)
[6363]71    masterscrollbar_active = false
72end
73
74function P.AudioMusicScrollbar_changed(e)
75    if musicmute then
76        block = true
77        musicmutewindow:setSelected(false)
78        block = false
79        musicmute = false
80    end
81    if musicscrollbar_active == false then
82        musicvolume = musicscrollbarwindow:getScrollPosition()
[6403]83        orxonox.config("SoundManager", "ambientVolume_", musicvolume)
[6363]84    end
85end
86
87function P.AudioMusicScrollbar_started(e)
88    musicscrollbar_active = true
89end
90
91function P.AudioMusicScrollbar_ended(e)
92    musicmutewindow:setSelected(false)
93    musicvolume = musicscrollbarwindow:getScrollPosition()
[6403]94    orxonox.config("SoundManager", "ambientVolume_", musicvolume)
[6363]95    musicscrollbar_active = false
96end
97
98function P.AudioEffectsScrollbar_changed(e)
99    if effectsmute then
100        block = true
101        effectsmutewindow:setSelected(false)
102        block = false
103        effectsmute = false
104    end
105    if effectsscrollbar_active == false then
106        effectsvolume = effectsscrollbarwindow:getScrollPosition()
[6403]107        orxonox.config("SoundManager", "effectsVolume_", effectsvolume)
[6363]108    end
109end
110
111function P.AudioEffectsScrollbar_started(e)
112    effectsscrollbar_active = true
113end
114
115function P.AudioEffectsScrollbar_ended(e)
116    effectsmutewindow:setSelected(false)
117    effectsvolume = effectsscrollbarwindow:getScrollPosition()
[6403]118    orxonox.config("SoundManager", "effectsVolume_", effectsvolume)
[6363]119    effectsscrollbar_active = false
120end
121
122function P.AudioMuteMasterCheckbox_clicked(e)
123    if block == false then
124        if mastermute then
125            masterscrollbarwindow:setScrollPosition(mastervolume)
126            mastermute = false
127        else
128            temp = masterscrollbarwindow:getScrollPosition()
129            masterscrollbarwindow:setScrollPosition(0)
130            mastervolume = temp
131            mastermute = true
132        end
133    end
[6370]134    soundMgr:toggleMute(orxonox.SoundType.All)
[6363]135end
136
137function P.AudioMuteMusicCheckbox_clicked(e)
138    if block == false then
139        if musicmute then
140            musicscrollbarwindow:setScrollPosition(musicvolume)
141            musicmute = false
142        else
143            temp = musicscrollbarwindow:getScrollPosition()
144            musicscrollbarwindow:setScrollPosition(0)
145            musicvolume = temp
146            musicmute = true
147        end
148    end
[6370]149    soundMgr:toggleMute(orxonox.SoundType.Music)
[6363]150end
151
152function P.AudioMuteEffectsCheckbox_clicked(e)
153    if block == false then
154        if effectsmute then
155            effectsscrollbarwindow:setScrollPosition(effectsvolume)
156            effectsmute = false
157        else
158            temp = effectsscrollbarwindow:getScrollPosition()
159            effectsscrollbarwindow:setScrollPosition(0)
160            effectsvolume = temp
161            effectsmute = true
162        end
163    end
[6370]164    soundMgr:toggleMute(orxonox.SoundType.Effects)
[6363]165end
166
167function P.AudioThemeListbox_changed(e)
168    if listboxwindow:isItemSelected(1) then
[6406]169        orxonox.config("MoodManager", "mood_", "dnb")
[6363]170    else
[6406]171        orxonox.config("MoodManager", "mood_", "default")
[6363]172    end
173end
174
175function P.AudioBackButton_clicked(e)
[6746]176    hideMenuSheet(P.name)
[6363]177end
178
179return P
180
Note: See TracBrowser for help on using the repository browser.