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

Added "Game Options" to the main menu

Autosave all the game on zone change is now configurable in the game options.
Saving each level individualy is now an option in the game options. This will make sure the game only keeps one level in memory (thus reducing the need for memory) but incur a small save/load on each level changes.


git-svn-id: http://svn.net-core.org/repos/t-engine4@1941 51575b47-30f0-44d4-a5cc-537603b46e54
parent 6bb4cb8e
No related branches found
No related tags found
No related merge requests found
......@@ -459,7 +459,7 @@ function _M:leaveLevel(no_close, lev, old_lev)
if not no_close and game.level and game.level.map then
game:leaveLevel(game.level, lev, old_lev)
if type(game.level.data.persistant) == "string" and game.level.data.persistant == "zone" then
if type(game.level.data.persistant) == "string" and game.level.data.persistant == "zone" and not self.save_per_level then
print("[LEVEL] persisting to zone memory", game.level.id)
self.memory_levels = self.memory_levels or {}
self.memory_levels[game.level.level] = game.level
......@@ -470,9 +470,6 @@ function _M:leaveLevel(no_close, lev, old_lev)
elseif game.level.data.persistant then
print("[LEVEL] persisting to disk file", game.level.id)
savefile_pipe:push(game.save_name, "level", game.level)
-- local save = Savefile.new(game.save_name)
-- save:saveLevel(game.level)
-- save:close()
else
game.level:removed()
end
......@@ -491,7 +488,7 @@ function _M:getLevel(game, lev, old_lev, no_close)
local level
-- Load persistant level?
if type(level_data.persistant) == "string" and level_data.persistant == "zone" then
if type(level_data.persistant) == "string" and level_data.persistant == "zone" and not self.save_per_level then
self.memory_levels = self.memory_levels or {}
level = self.memory_levels[lev]
......
......@@ -160,6 +160,7 @@ end
-- LOAD & SAVE
-- ---------------------------------------------------------------------
-- ---------------------------------------------------------------------
local basictableid = 0
local function basicSerialize(o, t)
if t == "number" or t == "boolean" then
return tostring(o)
......@@ -205,6 +206,10 @@ local function serialize_data(outf, name, value, saved, filter, allow, savefile,
if tk == "table" and k.__CLASSNAME then
savefile:addToProcess(k)
fieldname = string.format("%s[loadObject('%s')]", name, savefile:getFileName(k))
elseif tk == "table" and not k.__CLASSNAME then
basictableid = basictableid + 1
serialize_data(outf, "subdata"..basictableid, k, nil, {}, false, savefile, true)
fieldname = string.format("%s[subdata%d]", name, basictableid)
else
fieldname = string.format("%s[%s]", name, basicSerialize(k, tk))
end
......
......@@ -386,6 +386,7 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down)
else
self.zone = zone
end
if type(self.zone.save_per_level) == "nil" then self.zone.save_per_level = config.settings.tome.save_zone_levels and true or false end
end
self.zone:getLevel(self, lev, old_lev)
......@@ -472,7 +473,7 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down)
self.level.map:redisplay()
-- Autosave
if left_zone and left_zone.short_name ~= "wilderness" and left_zone.short_name ~= self.zone.short_name then self:saveGame() end
if config.settings.tome.autosave and left_zone and left_zone.short_name ~= "wilderness" and left_zone.short_name ~= self.zone.short_name then self:saveGame() end
end
function _M:getPlayer()
......@@ -706,7 +707,8 @@ function _M:setupCommands()
-- local m = game.zone:makeEntityByName(game.level, "actor", "TEST")
-- game.zone:addEntity(game.level, m, "actor", game.player.x, game.player.y+1)
-- self:changeLevel(2, "mark-spellblaze")
self.player:grantQuest("anti-antimagic")
-- self.player:grantQuest("anti-antimagic")
game.player[{foo=1,plop=4}]=3
end
end,
}
......@@ -893,6 +895,7 @@ function _M:setupCommands()
{ "Character Sheet", function() game:unregisterDialog(menu) self.key:triggerVirtual("SHOW_CHARACTER_SHEET") end },
"keybinds",
{"Graphic Mode", function() game:unregisterDialog(menu) game:registerDialog(require("mod.dialogs.GraphicMode").new()) end},
{"Game Options", function() game:unregisterDialog(menu) game:registerDialog(require("mod.dialogs.GameOptions").new()) end},
"video",
"sound",
"save",
......
-- ToME - Tales of Maj'Eyal
-- 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"
local GetQuantity = require "engine.dialogs.GetQuantity"
module(..., package.seeall, class.inherit(Dialog))
function _M:init()
Dialog.init(self, "Game 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=60, display_prop="name"},
{width=40, 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=string.toTString"Autosaves the whole game when switching zones. This is safer but can make playing a bit slower while it saves.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Autosave when leaving a zone#WHITE##{normal}#", status=function(item)
return tostring(config.settings.tome.autosave and "enabled" or "disabled")
end, fct=function(item)
config.settings.tome.autosave = not config.settings.tome.autosave
game:saveSettings("tome.autosave", ("tome.autosave = %s\n"):format(tostring(config.settings.tome.autosave)))
self.c_list:drawItem(item)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Forces the game to save each level instead of each zones.\nThis makes it save more often but the game will use less memory when deep in a dungeon.\n\n#LIGHT_RED#Changing this option will not affect already visited zones.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Zone save per level#WHITE##{normal}#", status=function(item)
return tostring(config.settings.tome.save_zone_levels and "enabled" or "disabled")
end, fct=function(item)
config.settings.tome.save_zone_levels = not config.settings.tome.save_zone_levels
game:saveSettings("tome.save_zone_levels", ("tome.save_zone_levels = %s\n"):format(tostring(config.settings.tome.save_zone_levels)))
self.c_list:drawItem(item)
end,}
self.list = list
end
......@@ -178,4 +178,7 @@ for i, t in ipairs(stype_tot) do
end
------------------------------------------------------------------------
-- Init autosaves
if type(config.settings.tome.autosave) == "nil" then config.settings.tome.autosave = true end
return {require "mod.class.Game", require "mod.class.World"}
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