Skip to content
Snippets Groups Projects
Commit dbec6f68 authored by dg's avatar dg
Browse files

Updated the music & sounds dialog to be able to disable all sounds and control...

Updated the music & sounds dialog to be able to disable all sounds and control music & effects volumes independantly


git-svn-id: http://svn.net-core.org/repos/t-engine4@3721 51575b47-30f0-44d4-a5cc-537603b46e54
parent b3ef6618
No related branches found
No related tags found
No related merge requests found
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010, 2011 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Dialog = require "engine.ui.Dialog"
local Textzone = require "engine.ui.Textzone"
local Checkbox = require "engine.ui.Checkbox"
local Numberbox = require "engine.ui.Numberbox"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(Dialog))
function _M:init()
Dialog.init(self, "Audio Options", 400, 300)
self.c_enable = Checkbox.new{title="Enable audio", default=config.settings.audio.enable, fct=function() end, on_change=function(s) self:sfxEnable(s) end}
self.c_music_vol = Numberbox.new{title="Music volume: ", number=config.settings.audio.music_volume, max=100, min=0, chars=5, fct=function() end, on_change=function(v) self:sfxVolume("music", v) end}
self.c_effects_vol = Numberbox.new{title="Sound effects volume: ", number=config.settings.audio.effects_volume, max=100, min=0, chars=5, fct=function() end, on_change=function(v) self:sfxVolume("effects", v) end}
self:loadUI{
{left=0, top=0, ui=self.c_enable},
{left=0, top=self.c_enable.h + 10, ui=self.c_music_vol},
{left=0, top=self.c_enable.h + 10 + self.c_music_vol.h, ui=self.c_effects_vol},
}
self:setupUI(true, true)
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:sfxEnable(s)
config.settings.audio.enable = s and true or false
core.sound.enable(s)
game:audioSaveSettings()
end
function _M:sfxVolume(what, s)
if what == "music" and game.volumeMusic then game:volumeMusic(s)
elseif what == "effects" and game.volumeSoundEffects then game:volumeSoundEffects(s) end
end
......@@ -73,9 +73,9 @@ function _M:generateList(actions)
local menu = require("engine.dialogs.ShowAchievements").new(nil, game:getPlayer())
game:registerDialog(menu)
end },
sound = { "Sound & Music", function()
sound = { "Audio Options", function()
game:unregisterDialog(self)
local menu = require("engine.dialogs.SoundMusic").new()
local menu = require("engine.dialogs.AudioOptions").new()
game:registerDialog(menu)
end },
save = { "Save Game", function() game:unregisterDialog(self) game:saveGame() end },
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010, 2011 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.Dialog"
module(..., package.seeall, class.inherit(engine.Dialog))
function _M:init()
self:generateList()
engine.Dialog.init(self, "Sound & Music", 300, #self.list * 30 + 40)
self.sel = 1
self.scroll = 1
self.max = math.floor((self.ih - 5) / self.font_h) - 1
self:keyCommands({
__TEXTINPUT = function(c)
if c:find("^[a-z]$") then
self.sel = util.bound(1 + string.byte(c) - string.byte('a'), 1, #self.list)
self:use()
end
end,
},{
MOVE_UP = function() self.sel = util.boundWrap(self.sel - 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_DOWN = function() self.sel = util.boundWrap(self.sel + 1, 1, #self.list) self.scroll = util.scroll(self.sel, self.scroll, self.max) self.changed = true end,
MOVE_LEFT = function() self:changeVol(-5) self.changed = true end,
MOVE_RIGHT = function() self:changeVol(5) self.changed = true end,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=0, y=0, w=game.w, h=game.h, mode={button=true}, norestrict=true, fct=function(button) if button == "left" then game:unregisterDialog(self) end end},
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty, event)
self.changed = true
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "left" and event == "button" then self:use(true)
elseif button == "right" and event == "button" then self:use(false)
end
end },
}
end
function _M:changeVol(v)
if self.list[self.sel].act == "music_volume" then
game:volumeMusic(game:volumeMusic() + v)
self:generateList()
elseif self.list[self.sel].act == "sound_volume" then
-- self:changeVol(v and 5 or -5)
end
end
function _M:use(v)
if self.list[self.sel].act == "enable" then
game:soundSystemStatus(true)
self:generateList()
elseif self.list[self.sel].act == "disable" then
game:soundSystemStatus(false)
self:generateList()
elseif self.list[self.sel].act == "music_volume" then
self:changeVol(v and 5 or -5)
elseif self.list[self.sel].act == "sound_volume" then
self:changeVol(v and 5 or -5)
end
-- game:unregisterDialog(self)
end
function _M:generateList()
-- Makes up the list
local list = {}
local i = 0
if game:soundSystemStatus() then
list[#list+1] = { name=string.char(string.byte('a') + i)..") Disable sound & music", act="disable" } i = i + 1
else
list[#list+1] = { name=string.char(string.byte('a') + i)..") Enable sound & music", act="enable" } i = i + 1
end
list[#list+1] = { name=string.char(string.byte('a') + i)..") Music volume ("..game:volumeMusic().."%)", act="music_volume" } i = i + 1
-- list[#list+1] = { name=string.char(string.byte('a') + i)..") Sound volume", act="sound_volume" } i = i + 1
self.list = list
self.changed = true
end
function _M:drawDialog(s)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
self.changed = false
end
......@@ -47,9 +47,9 @@ fs.setWritePath(fs.getHomePath())
-- Loads default config & user config
fs.mount(engine.homepath, "/")
config.loadString[[
sound.enabled = true
audio.music_volume = 60
audio.effects_volume = 100
audio.enable = true
aa_text = true
fbo_active = true
shaders_active = true
......@@ -76,6 +76,9 @@ if not config.settings.window or not config.settings.window.size then
config.settings.window.size = math.floor(r.w * 0.9).."x"..math.floor(r.h*0.9)
end
-- Audio
core.sound.enable(config.settings.audio.enable)
-- Load default keys
engine.KeyBind:load("move,hotkeys,inventory,actions,interface,debug")
......
......@@ -77,11 +77,23 @@ end
function _M:volumeMusic(vol)
vol = util.bound(vol, 0, 100)
if vol then
self:saveSettings("audio", ("audio.music_volume = %q\n"):format(vol))
config.settings.audio = config.settings.audio or {}
config.settings.audio.music_volume = vol
game:audioSaveSettings()
end
for name, m in pairs(self.playing_musics) do
m.source:volume(vol / 100)
end
end
function _M:audioSaveSettings()
self:saveSettings("audio", ([[audio.music_volume = %d
audio.effects_volume = %d
audio.enable = %s
]]):
format(config.settings.audio.music_volume,
config.settings.audio.effects_volume,
tostring(config.settings.audio.enable)
))
end
......@@ -81,9 +81,9 @@ end
function _M:volumeSoundEffects(vol)
vol = util.bound(vol, 0, 100)
if vol then
self:saveSettings("audio", ("audio.effects_volume = %q\n"):format(vol))
config.settings.audio = config.settings.audio or {}
config.settings.audio.effects_volume = vol
game:audioSaveSettings()
end
for source, _ in pairs(self.playing_sounds) do
source:volume(vol / 100)
......
......@@ -28,6 +28,7 @@ function _M:init(t)
self.title = assert(t.title, "no numberbox title")
self.number = t.number or 0
self.min = t.min or 0
self.on_change = t.on_change
self.max = t.max or 9999999
self.fct = assert(t.fct, "no numberbox fct")
self.chars = assert(t.chars, "no numberbox chars")
......@@ -130,6 +131,7 @@ function _M:generate()
end
function _M:updateText(v)
local old = self.number
local text = ""
if not v then
self.number = tonumber(table.concat(self.tmp)) or 0
......@@ -150,6 +152,7 @@ function _M:updateText(v)
self.text_surf:erase(0, 0, 0, 0)
self.text_surf:drawStringBlended(self.font_mono, text, 0, 0, 255, 255, 255, true)
self.text_surf:updateTexture(self.text_tex)
if self.on_change and old ~= self.number then self.on_change(self.number) end
end
function _M:display(x, y, nb_keyframes)
......
......@@ -92,7 +92,6 @@ function _M:run()
self:registerDialog(MainMenu.new())
-- Run the current music if any
self:volumeMusic(config.settings.music.volume)
self:playMusic("The saga begins.ogg")
-- Get news
......
......@@ -758,7 +758,7 @@ end
function _M:selectTileNoDonations()
Dialog:yesnoLongPopup("Custom tiles",
[[Custom Tiles have been added as a thank you to everyone that has donated to ToME.
They are a fun cosmetic feature that allows you to choose a tile for your character from a list of nearly 180, ranging from special humanoid tiles to downright wonky ones!
They are a fun cosmetic feature that allows you to choose a tile for your character from a list of nearly 180 (with more to be added over time), ranging from special humanoid tiles to downright wonky ones!
If you'd like to use this feature and find this game good you should consider donating, it will help ensure its survival.
While this is a free game that I am doing for fun, if it can help feeding my family a bit I certainly will not complain as real life can be harsh sometimes.
......
......@@ -70,8 +70,47 @@ static ov_callbacks physfsOvCallbacks = {
physfsOvTell
};
void openal_get_devices()
{
char deviceName[256];
char *defaultDevice=NULL;
char *deviceList=NULL;
if (alcIsExtensionPresent(NULL, (ALubyte*)"ALC_ENUMERATION_EXT") == AL_TRUE)
{ // try out enumeration extension
deviceList = (char *)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
if (strlen(deviceList))
{
defaultDevice = (char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
int numDevices;
for (numDevices = 0; numDevices < 16; numDevices++)
{
if (defaultDevice && strcmp(deviceList, defaultDevice) == 0)
{
// devList.numDefaultDevice = numDevices;
}
deviceList += strlen(deviceList);
if (deviceList[0] == 0)
{
if (deviceList[1] == 0)
{
break;
}
else
{
deviceList++;
}
}
}
}
}
}
int init_openal() {
// openal_get_devices();
audioDevice = alcOpenDevice(NULL);
if (audioDevice == NULL) return 0;
audioContext = alcCreateContext(audioDevice, NULL);
......@@ -245,8 +284,18 @@ static int loadsoundLua(lua_State *L) {
return 1;
}
static int audio_enable(lua_State *L) {
bool v = lua_toboolean(L, 1);
if (v)
alListenerf(AL_GAIN, 1);
else
alListenerf(AL_GAIN, 0);
return 0;
}
const luaL_reg soundlib[] = {
{"load", loadsoundLua},
{"enable", audio_enable},
{NULL, NULL}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment