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

menu for sound & music disabling

git-svn-id: http://svn.net-core.org/repos/t-engine4@585 51575b47-30f0-44d4-a5cc-537603b46e54
parent e5722a13
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,11 @@ function _M:generateList(actions)
local menu = require("engine.dialogs.ShowAchievements").new()
game:registerDialog(menu)
end },
sound = { "Sound & Music", function()
game:unregisterDialog(self)
local menu = require("engine.dialogs.SoundMusic").new()
game:registerDialog(menu)
end },
save = { "Save Game", function() game:saveGame() end },
quit = { "Save and Exit", function() game:onQuit() end },
}
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 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,
ACCEPT = function() self:use() end,
EXIT = function() game:unregisterDialog(self) end,
})
self:mouseZones{
{ x=2, y=5, w=350, h=self.font_h*self.max, fct=function(button, x, y, xrel, yrel, tx, ty)
self.sel = util.bound(self.scroll + math.floor(ty / self.font_h), 1, #self.list)
if button == "left" then self:use()
elseif button == "right" then
end
end },
}
end
function _M:use()
if self.list[self.sel].act == "enable" then
game:soundSystemStatus(true)
else
game:soundSystemStatus(false)
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
self.list = list
end
function _M:drawDialog(s)
self:drawSelectionList(s, 2, 5, self.font_h, self.list, self.sel, "name", self.scroll, self.max)
end
......@@ -26,6 +26,7 @@ dofile("/engine/resolvers.lua")
require "config"
require "engine.Game"
require "engine.interface.GameMusic"
require "engine.KeyBind"
require "engine.Savefile"
require "engine.Tiles"
......@@ -46,6 +47,7 @@ fs.setWritePath(fs.getHomePath())
fs.mount(engine.homepath, "/")
config.loadString[[
window.size = "800x600"
sound.enabled = true
]]
for i, file in ipairs(fs.list("/settings/")) do
if file:find(".cfg$") then
......@@ -71,5 +73,6 @@ key:setCurrent()
game = false
engine.Game:setResolution(config.settings.window.size)
engine.interface.GameMusic:soundSystemStatus(config.settings.sound.enabled, true)
util.showMainMenu()
......@@ -61,3 +61,21 @@ end
function _M:volumeMusic(vol)
core.sound.musicVolume(vol or 100)
end
function _M:soundSystemStatus(act, init_setup)
if type(act) == "boolean" then
core.sound.soundSystemStatus(act)
if not init_setup then
self:saveSettings("sound", ("sound.enabled = %s\n"):format(act and "true" or "false"))
if act then
self:playMusic()
else
local o = self.current_music
self:stopMusic()
self.current_music = o
end
end
else
return core.sound.soundSystemStatus()
end
end
......@@ -588,6 +588,7 @@ function _M:setupCommands()
"keybinds",
{"Graphic Mode", function() game:unregisterDialog(menu) game:registerDialog(require("mod.dialogs.GraphicMode").new()) end},
"resolution",
"sound",
"save",
"quit"
}
......
......@@ -28,6 +28,8 @@
#include <SDL.h>
#include <SDL_mixer.h>
bool sound_active = TRUE;
static int music_new(lua_State *L)
{
if (no_sound) return 0;
......@@ -57,6 +59,7 @@ static int music_free(lua_State *L)
static int music_play(lua_State *L)
{
if (!sound_active) return 0;
Mix_Music **m = (Mix_Music**)auxiliar_checkclass(L, "core{music}", 1);
int loop = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : 1;
int fadein = lua_isnumber(L, 3) ? lua_tonumber(L, 3) : 0;
......@@ -113,6 +116,7 @@ static int sound_free(lua_State *L)
static int sound_play(lua_State *L)
{
if (!sound_active) return 0;
Mix_Chunk **m = (Mix_Chunk**)auxiliar_checkclass(L, "core{sound}", 1);
int loop = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : 0;
int ms = lua_isnumber(L, 3) ? lua_tonumber(L, 3) : 0;
......@@ -144,8 +148,24 @@ static int channel_fadeout(lua_State *L)
return 0;
}
static int sound_status(lua_State *L)
{
if (lua_isboolean(L, 1))
{
int act = lua_toboolean(L, 1);
sound_active = act;
return 0;
}
else
{
lua_pushboolean(L, sound_active);
return 1;
}
}
static const struct luaL_reg soundlib[] =
{
{"soundSystemStatus", sound_status},
{"newMusic", music_new},
{"newSound", sound_new},
{"musicStop", music_stop},
......
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