Skip to content
Snippets Groups Projects
GameMenu.lua 4.67 KiB
Newer Older
DarkGod's avatar
DarkGod committed
-- Copyright (C) 2009 - 2018 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"
dg's avatar
dg committed
local Dialog = require "engine.ui.Dialog"
local List = require "engine.ui.List"
--- Main game menu
-- @classmod engine.dialogs.GameMenu
dg's avatar
dg committed
module(..., package.seeall, class.inherit(Dialog))

function _M:init(actions)
	self:generateList(actions)

dg's avatar
dg committed
	Dialog.init(self, "Game Menu", 300, 20)
dg's avatar
dg committed
	self.c_list = List.new{width=self.iw, nb_items=#self.list, list=self.list, fct=function(item) self:use(item) end}
dg's avatar
dg committed
	self:loadUI{
		{left=0, top=0, ui=self.c_list},
	}
	self:setFocus(self.c_list)
	self:setupUI(false, true)

	self.key:addBinds{
		EXIT = function() game:unregisterDialog(self) end,
	}
end

dg's avatar
dg committed
function _M:use(item)
	item.fct()
end

function _M:generateList(actions)
	local default_actions = {
		resume = { "Resume", function() game:unregisterDialog(self) end },
		keybinds = { "Key Bindings", function()
			game:unregisterDialog(self)
			local menu = require("engine.dialogs.KeyBinder").new(game.normal_key, nil, game.gestures)
dg's avatar
dg committed
		keybinds_all = { "Key Bindings", function()
			game:unregisterDialog(self)
			local menu = require("engine.dialogs.KeyBinder").new(game.normal_key, true, game.gestures)
dg's avatar
dg committed
			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()
			game:registerDialog(menu)
		end },
		achievements = { "Show Achievements", function()
			game:unregisterDialog(self)
			local menu = require("engine.dialogs.ShowAchievements").new(nil, game:getPlayer())
		sound = { "Audio Options", function()
			local menu = require("engine.dialogs.AudioOptions").new()
DarkGod's avatar
DarkGod committed
		-- highscores = { "View High Scores", function()
		-- 	game:unregisterDialog(self)
		-- 	local menu = require("engine.dialogs.ViewHighScores").new()
		-- 	game:registerDialog(menu)
		-- end },
DarkGod's avatar
DarkGod committed
		steam = { "Steam", function()
			game:unregisterDialog(self)
			local menu = require("engine.dialogs.SteamOptions").new()
			game:registerDialog(menu)
		end },
		cheatmode = { "#GREY#Developer Mode", function()
			game:unregisterDialog(self)
			if config.settings.cheat then
				Dialog:yesnoPopup("Developer Mode", "Disable developer mode?", function(ret) if ret then
					config.settings.cheat = false
					game:saveSettings("cheat", "cheat = nil\n")
					util.showMainMenu()
				end end, nil, nil, true)
			else
				Dialog:yesnoLongPopup("Developer Mode", [[Enable developer mode?
Developer Mode is a special game mode used to debug and create addons.
Using it will #CRIMSON#invalidate#LAST# any savefiles loaded.
When activated you will have access to special commands:
- CTRL+L: bring up a lua console that lets you explore and alter all the game objects, enter arbitrary lua commands, ...
- CTRL+A: bring up a menu to easily do many tasks (create NPCs, teleport to zones, ...)
- CTRL+left click: teleport to the clicked location
]], 500, function(ret) if not ret then
					config.settings.cheat = true
					game:saveSettings("cheat", "cheat = true\n")
					util.showMainMenu()
				end end, "No", "Yes", true)
		
			end
		end },
dg's avatar
dg committed
		save = { "Save Game", function() game:unregisterDialog(self) game:saveGame() end },
dg's avatar
dg committed
		quit = { "Main Menu", function() game:unregisterDialog(self) game:onQuit() end },
		exit = { "Exit Game", function() game:unregisterDialog(self) game:onExit() end },
	}

	-- Makes up the list
	local list = {}
	local i = 0
	for _, act in ipairs(actions) do
		if type(act) == "string" then
DarkGod's avatar
DarkGod committed
			if act ~= "steam" or core.steam then
				local a = default_actions[act]
DarkGod's avatar
DarkGod committed
				if a then
					list[#list+1] = { name=a[1], fct=a[2] }
					i = i + 1
				end
DarkGod's avatar
DarkGod committed
			end
dg's avatar
dg committed
			list[#list+1] = { name=a[1], fct=a[2] }