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

Added a Video Options in the game menu, it allows to enable/disable...

Added a Video Options in the game menu, it allows to enable/disable antialiased texts, framebuffers & shaders


git-svn-id: http://svn.net-core.org/repos/t-engine4@1418 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5ebc92a9
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,11 @@ function _M:generateList(actions)
local menu = require("engine.dialogs.KeyBinder").new(game.normal_key, true)
game:registerDialog(menu)
end },
video = { "Video Options", function()
game:unregisterDialog(self)
local menu = require("engine.dialogs.VideoOptions").new()
game:registerDialog(menu)
end },
resolution = { "Display Resolution", function()
game:unregisterDialog(self)
local menu = require("engine.dialogs.DisplayResolution").new()
......
-- 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"
local Dialog = require "engine.ui.Dialog"
local TreeList = require "engine.ui.TreeList"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
module(..., package.seeall, class.inherit(Dialog))
function _M:init()
Dialog.init(self, "Video Options", game.w * 0.8, game.h * 0.8)
self.c_desc = Textzone.new{width=math.floor(self.iw / 2 - 10), height=self.ih, text=""}
self:generateList()
self.c_list = TreeList.new{width=math.floor(self.iw / 2 - 10), height=self.ih - 10, scrollbar=true, columns={
{width=40, display_prop="name"},
{width=20, display_prop="status"},
}, tree=self.list, fct=function(item) end, select=function(item, sel) self:select(item) end}
self:loadUI{
{left=0, top=0, ui=self.c_list},
{right=0, top=0, ui=self.c_desc},
{hcenter=0, top=5, ui=Separator.new{dir="horizontal", size=self.ih - 10}},
}
self:setFocus(self.c_list)
self:setupUI()
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:select(item)
if item and self.uis[2] then
self.uis[2].ui = item.zone
end
end
function _M:generateList()
-- Makes up the list
local list = {}
local i = 0
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Activates antialiased texts.\nTexts will look nicer but it can be slower on some computers.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"}
list[#list+1] = { zone=zone, name="Antialiased texts", status=function(item)
return tostring(core.display.getTextBlended() and "enabled" or "disabled")
end, fct=function(item)
local state = not core.display.getTextBlended()
core.display.setTextBlended(state)
game:saveSettings("aa_text", ("aa_text = %s\n"):format(tostring(state)))
self.c_list:drawItem(item)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Activates framebuffers.\nThis option allows for some special graphical effects.\nIf you encounter weird graphical glitches try to disable it.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"}
list[#list+1] = { zone=zone, name="Framebuffers", status=function(item)
return tostring(config.settings.fbo_active and "enabled" or "disabled")
end, fct=function(item)
config.settings.fbo_active = not config.settings.fbo_active
game:saveSettings("fbo_active", ("fbo_active = %s\n"):format(tostring(config.settings.fbo_active)))
self.c_list:drawItem(item)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Activates OpenGL Shaders.\nThis option allows for some special graphical effects.\nIf you encounter weird graphical glitches try to disable it.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"}
list[#list+1] = { zone=zone, name="OpenGL Shaders", status=function(item)
return tostring(config.settings.shaders_active and "enabled" or "disabled")
end, fct=function(item)
config.settings.shaders_active = not config.settings.shaders_active
game:saveSettings("shaders_active", ("shaders_active = %s\n"):format(tostring(config.settings.shaders_active)))
self.c_list:drawItem(item)
end,}
self.list = list
end
......@@ -50,6 +50,9 @@ config.loadString[[
window.size = "800x600"
sound.enabled = true
music.volume = 60
aa_text = true
fbo_active = true
shaders_active = true
]]
for i, file in ipairs(fs.list("/settings/")) do
if file:find(".cfg$") then
......@@ -76,6 +79,9 @@ game = false
-- Setup resolution
engine.Game:setResolution(config.settings.window.size, true)
core.display.setTextBlended(config.settings.aa_text)
if not config.settings.fbo_active then core.display.disableFBO() print("Disabling FBO") end
if not config.settings.shaders_active then core.shader.disable() print("Disabling Shaders") end
-- Setup musics
engine.interface.GameMusic:soundSystemStatus(config.settings.sound.enabled, true)
......
......@@ -129,7 +129,7 @@ function _M:generate()
-- Draw the list items
for i, item in ipairs(self.list) do
local text = tostring(item[col.display_prop or col.sort])
local text = tostring(util.getval(item[col.display_prop or col.sort], item))
local color = item.color or {255,255,255}
local ss = core.display.newSurface(fw, fh)
local sus = core.display.newSurface(fw, fh)
......
......@@ -18,7 +18,7 @@
-- darkgod@te4.org
-- Engine Version
engine.version = {0,9,12,"te4",3}
engine.version = {0,9,12,"te4",4}
engine.require_c_core = engine.version[5]
engine.version_id = ("%s-%d_%d.%d.%d"):format(engine.version[4], engine.require_c_core, engine.version[1], engine.version[2], engine.version[3])
......
......@@ -35,6 +35,7 @@ function _M:init()
local menu menu = require("engine.dialogs.GameMenu").new{
"resume",
"keybinds_all",
"video",
"resolution",
"sound",
}
......
......@@ -448,6 +448,7 @@ static const struct luaL_reg gamelib[] =
* Display *
******************************************************************
******************************************************************/
static bool no_text_aa = FALSE;
static int sdl_fullscreen(lua_State *L)
{
......@@ -550,6 +551,7 @@ static int sdl_surface_drawstring(lua_State *L)
static int sdl_surface_drawstring_aa(lua_State *L)
{
if (no_text_aa) return sdl_surface_drawstring(L);
SDL_Surface **s = (SDL_Surface**)auxiliar_checkclass(L, "sdl{surface}", 1);
TTF_Font **f = (TTF_Font**)auxiliar_checkclass(L, "sdl{font}", 2);
const char *str = luaL_checkstring(L, 3);
......@@ -598,6 +600,7 @@ static int sdl_surface_drawstring_newsurface(lua_State *L)
static int sdl_surface_drawstring_newsurface_aa(lua_State *L)
{
if (no_text_aa) return sdl_surface_drawstring_newsurface(L);
TTF_Font **f = (TTF_Font**)auxiliar_checkclass(L, "sdl{font}", 1);
const char *str = luaL_checkstring(L, 2);
int r = luaL_checknumber(L, 3);
......@@ -1409,9 +1412,29 @@ static int gl_fbo_is_active(lua_State *L)
return 1;
}
static int gl_fbo_disable(lua_State *L)
{
fbo_active = FALSE;
return 0;
}
static int set_text_aa(lua_State *L)
{
bool active = !lua_toboolean(L, 1);
no_text_aa = active;
return 0;
}
static int get_text_aa(lua_State *L)
{
lua_pushboolean(L, !no_text_aa);
return 1;
}
static const struct luaL_reg displaylib[] =
{
{"setTextBlended", set_text_aa},
{"getTextBlended", get_text_aa},
{"forceRedraw", sdl_redraw_screen},
{"fullscreen", sdl_fullscreen},
{"size", sdl_screen_size},
......@@ -1421,6 +1444,7 @@ static const struct luaL_reg displaylib[] =
{"newFBO", gl_new_fbo},
{"drawQuad", gl_draw_quad},
{"FBOActive", gl_fbo_is_active},
{"disableFBO", gl_fbo_disable},
{"drawStringNewSurface", sdl_surface_drawstring_newsurface},
{"drawStringBlendedNewSurface", sdl_surface_drawstring_newsurface_aa},
{"loadImage", sdl_load_image},
......@@ -2206,7 +2230,7 @@ int luaopen_core(lua_State *L)
luaL_openlib(L, "core.game", gamelib, 0);
lua_pushstring(L, "VERSION");
lua_pushnumber(L, 3);
lua_pushnumber(L, 4);
lua_settable(L, -3);
luaL_openlib(L, "rng", rnglib, 0);
......
......@@ -257,12 +257,18 @@ static int shader_is_active(lua_State *L)
lua_pushboolean(L, shaders_active);
return 1;
}
static int shader_disable(lua_State *L)
{
shaders_active = FALSE;
return 0;
}
static const struct luaL_reg shaderlib[] =
{
{"newShader", shader_new},
{"newProgram", program_new},
{"active", shader_is_active},
{"disable", shader_disable},
{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