Commit 85f2a329af43d431909cb534783c847f5acc9a57

Authored by dg
1 parent 5ebc92a9

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
... ... @@ -58,6 +58,11 @@ function _M:generateList(actions)
58 58 local menu = require("engine.dialogs.KeyBinder").new(game.normal_key, true)
59 59 game:registerDialog(menu)
60 60 end },
  61 + video = { "Video Options", function()
  62 + game:unregisterDialog(self)
  63 + local menu = require("engine.dialogs.VideoOptions").new()
  64 + game:registerDialog(menu)
  65 + end },
61 66 resolution = { "Display Resolution", function()
62 67 game:unregisterDialog(self)
63 68 local menu = require("engine.dialogs.DisplayResolution").new()
... ...
  1 +-- TE4 - T-Engine 4
  2 +-- Copyright (C) 2009, 2010 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +require "engine.class"
  21 +local Dialog = require "engine.ui.Dialog"
  22 +local TreeList = require "engine.ui.TreeList"
  23 +local Textzone = require "engine.ui.Textzone"
  24 +local Separator = require "engine.ui.Separator"
  25 +
  26 +module(..., package.seeall, class.inherit(Dialog))
  27 +
  28 +function _M:init()
  29 + Dialog.init(self, "Video Options", game.w * 0.8, game.h * 0.8)
  30 +
  31 + self.c_desc = Textzone.new{width=math.floor(self.iw / 2 - 10), height=self.ih, text=""}
  32 +
  33 + self:generateList()
  34 +
  35 + self.c_list = TreeList.new{width=math.floor(self.iw / 2 - 10), height=self.ih - 10, scrollbar=true, columns={
  36 + {width=40, display_prop="name"},
  37 + {width=20, display_prop="status"},
  38 + }, tree=self.list, fct=function(item) end, select=function(item, sel) self:select(item) end}
  39 +
  40 + self:loadUI{
  41 + {left=0, top=0, ui=self.c_list},
  42 + {right=0, top=0, ui=self.c_desc},
  43 + {hcenter=0, top=5, ui=Separator.new{dir="horizontal", size=self.ih - 10}},
  44 + }
  45 + self:setFocus(self.c_list)
  46 + self:setupUI()
  47 +
  48 + self.key:addBinds{
  49 + EXIT = function() game:unregisterDialog(self) end,
  50 + }
  51 +end
  52 +
  53 +function _M:select(item)
  54 + if item and self.uis[2] then
  55 + self.uis[2].ui = item.zone
  56 + end
  57 +end
  58 +
  59 +function _M:generateList()
  60 + -- Makes up the list
  61 + local list = {}
  62 + local i = 0
  63 +
  64 + 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#"}
  65 + list[#list+1] = { zone=zone, name="Antialiased texts", status=function(item)
  66 + return tostring(core.display.getTextBlended() and "enabled" or "disabled")
  67 + end, fct=function(item)
  68 + local state = not core.display.getTextBlended()
  69 + core.display.setTextBlended(state)
  70 + game:saveSettings("aa_text", ("aa_text = %s\n"):format(tostring(state)))
  71 + self.c_list:drawItem(item)
  72 + end,}
  73 +
  74 + 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#"}
  75 + list[#list+1] = { zone=zone, name="Framebuffers", status=function(item)
  76 + return tostring(config.settings.fbo_active and "enabled" or "disabled")
  77 + end, fct=function(item)
  78 + config.settings.fbo_active = not config.settings.fbo_active
  79 + game:saveSettings("fbo_active", ("fbo_active = %s\n"):format(tostring(config.settings.fbo_active)))
  80 + self.c_list:drawItem(item)
  81 + end,}
  82 +
  83 + 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#"}
  84 + list[#list+1] = { zone=zone, name="OpenGL Shaders", status=function(item)
  85 + return tostring(config.settings.shaders_active and "enabled" or "disabled")
  86 + end, fct=function(item)
  87 + config.settings.shaders_active = not config.settings.shaders_active
  88 + game:saveSettings("shaders_active", ("shaders_active = %s\n"):format(tostring(config.settings.shaders_active)))
  89 + self.c_list:drawItem(item)
  90 + end,}
  91 +
  92 + self.list = list
  93 +end
... ...
... ... @@ -50,6 +50,9 @@ config.loadString[[
50 50 window.size = "800x600"
51 51 sound.enabled = true
52 52 music.volume = 60
  53 +aa_text = true
  54 +fbo_active = true
  55 +shaders_active = true
53 56 ]]
54 57 for i, file in ipairs(fs.list("/settings/")) do
55 58 if file:find(".cfg$") then
... ... @@ -76,6 +79,9 @@ game = false
76 79
77 80 -- Setup resolution
78 81 engine.Game:setResolution(config.settings.window.size, true)
  82 +core.display.setTextBlended(config.settings.aa_text)
  83 +if not config.settings.fbo_active then core.display.disableFBO() print("Disabling FBO") end
  84 +if not config.settings.shaders_active then core.shader.disable() print("Disabling Shaders") end
79 85
80 86 -- Setup musics
81 87 engine.interface.GameMusic:soundSystemStatus(config.settings.sound.enabled, true)
... ...
... ... @@ -129,7 +129,7 @@ function _M:generate()
129 129
130 130 -- Draw the list items
131 131 for i, item in ipairs(self.list) do
132   - local text = tostring(item[col.display_prop or col.sort])
  132 + local text = tostring(util.getval(item[col.display_prop or col.sort], item))
133 133 local color = item.color or {255,255,255}
134 134 local ss = core.display.newSurface(fw, fh)
135 135 local sus = core.display.newSurface(fw, fh)
... ...
... ... @@ -18,7 +18,7 @@
18 18 -- darkgod@te4.org
19 19
20 20 -- Engine Version
21   -engine.version = {0,9,12,"te4",3}
  21 +engine.version = {0,9,12,"te4",4}
22 22 engine.require_c_core = engine.version[5]
23 23 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])
24 24
... ...
... ... @@ -35,6 +35,7 @@ function _M:init()
35 35 local menu menu = require("engine.dialogs.GameMenu").new{
36 36 "resume",
37 37 "keybinds_all",
  38 + "video",
38 39 "resolution",
39 40 "sound",
40 41 }
... ...
... ... @@ -448,6 +448,7 @@ static const struct luaL_reg gamelib[] =
448 448 * Display *
449 449 ******************************************************************
450 450 ******************************************************************/
  451 +static bool no_text_aa = FALSE;
451 452
452 453 static int sdl_fullscreen(lua_State *L)
453 454 {
... ... @@ -550,6 +551,7 @@ static int sdl_surface_drawstring(lua_State *L)
550 551
551 552 static int sdl_surface_drawstring_aa(lua_State *L)
552 553 {
  554 + if (no_text_aa) return sdl_surface_drawstring(L);
553 555 SDL_Surface **s = (SDL_Surface**)auxiliar_checkclass(L, "sdl{surface}", 1);
554 556 TTF_Font **f = (TTF_Font**)auxiliar_checkclass(L, "sdl{font}", 2);
555 557 const char *str = luaL_checkstring(L, 3);
... ... @@ -598,6 +600,7 @@ static int sdl_surface_drawstring_newsurface(lua_State *L)
598 600
599 601 static int sdl_surface_drawstring_newsurface_aa(lua_State *L)
600 602 {
  603 + if (no_text_aa) return sdl_surface_drawstring_newsurface(L);
601 604 TTF_Font **f = (TTF_Font**)auxiliar_checkclass(L, "sdl{font}", 1);
602 605 const char *str = luaL_checkstring(L, 2);
603 606 int r = luaL_checknumber(L, 3);
... ... @@ -1409,9 +1412,29 @@ static int gl_fbo_is_active(lua_State *L)
1409 1412 return 1;
1410 1413 }
1411 1414
  1415 +static int gl_fbo_disable(lua_State *L)
  1416 +{
  1417 + fbo_active = FALSE;
  1418 + return 0;
  1419 +}
  1420 +
  1421 +static int set_text_aa(lua_State *L)
  1422 +{
  1423 + bool active = !lua_toboolean(L, 1);
  1424 + no_text_aa = active;
  1425 + return 0;
  1426 +}
  1427 +
  1428 +static int get_text_aa(lua_State *L)
  1429 +{
  1430 + lua_pushboolean(L, !no_text_aa);
  1431 + return 1;
  1432 +}
1412 1433
1413 1434 static const struct luaL_reg displaylib[] =
1414 1435 {
  1436 + {"setTextBlended", set_text_aa},
  1437 + {"getTextBlended", get_text_aa},
1415 1438 {"forceRedraw", sdl_redraw_screen},
1416 1439 {"fullscreen", sdl_fullscreen},
1417 1440 {"size", sdl_screen_size},
... ... @@ -1421,6 +1444,7 @@ static const struct luaL_reg displaylib[] =
1421 1444 {"newFBO", gl_new_fbo},
1422 1445 {"drawQuad", gl_draw_quad},
1423 1446 {"FBOActive", gl_fbo_is_active},
  1447 + {"disableFBO", gl_fbo_disable},
1424 1448 {"drawStringNewSurface", sdl_surface_drawstring_newsurface},
1425 1449 {"drawStringBlendedNewSurface", sdl_surface_drawstring_newsurface_aa},
1426 1450 {"loadImage", sdl_load_image},
... ... @@ -2206,7 +2230,7 @@ int luaopen_core(lua_State *L)
2206 2230
2207 2231 luaL_openlib(L, "core.game", gamelib, 0);
2208 2232 lua_pushstring(L, "VERSION");
2209   - lua_pushnumber(L, 3);
  2233 + lua_pushnumber(L, 4);
2210 2234 lua_settable(L, -3);
2211 2235
2212 2236 luaL_openlib(L, "rng", rnglib, 0);
... ...
... ... @@ -257,12 +257,18 @@ static int shader_is_active(lua_State *L)
257 257 lua_pushboolean(L, shaders_active);
258 258 return 1;
259 259 }
  260 +static int shader_disable(lua_State *L)
  261 +{
  262 + shaders_active = FALSE;
  263 + return 0;
  264 +}
260 265
261 266 static const struct luaL_reg shaderlib[] =
262 267 {
263 268 {"newShader", shader_new},
264 269 {"newProgram", program_new},
265 270 {"active", shader_is_active},
  271 + {"disable", shader_disable},
266 272 {NULL, NULL},
267 273 };
268 274
... ...