📄 game.lua
字号:
-- ____ _ __ -- / __ )____ _____ | | / /___ ___________-- / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/-- / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) -- /_____/\____/____/ |__/|__/\__,_/_/ /____/ -- -- A futuristic real-time strategy game.-- This file is part of Bos Wars.---- game.lua - In-game menus.---- (c) Copyright 2006 by Jimmy Salmon and Francois Beerten---- 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; only version 2 of the License.---- 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, write to the Free Software-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA-- 02111-1307, USA.---- $Id: game.lua 8619 2007-03-15 22:24:40Z feb $function BosGameMenu() local menu = MenuScreen() menu:setSize(256, 288) menu:setPosition((Video.Width - menu:getWidth()) / 2, (Video.Height - menu:getHeight()) / 2) menu:setBorderSize(1) menu:setOpaque(true) menu:setBaseColor(dark) AddMenuHelpers(menu) -- FIXME: not a good solution -- default size is 200,24 but we want 224,28 so we override these functions menu.addButtonOrig = menu.addButton function menu:addButton(caption, hotkey, x, y, callback, size) return self:addButtonOrig(caption, hotkey, x, y, callback, {224, 28}) end function menu:addSmallButton(caption, hotkey, x, y, callback) return self:addButtonOrig(caption, hotkey, x, y, callback, {100, 24}) end return menuendfunction RunGameMenu(s) local menu = BosGameMenu() menu:addLabel(_("Game Menu"), 128, 11) local b = menu:addButton(_("Save (~<F11~>)"), "f11", 16, 40, function() RunSaveMenu() end) if (IsReplayGame() or IsNetworkGame()) then b:setEnabled(false) end menu:addButton(_("Options (~<F5~>)"), "f5", 16, 40 + (36 * 1), function() RunGameOptionsMenu() end) menu:addButton(_("Help (~<F1~>)"), "f1", 16, 40 + (36 * 2), function() RunHelpMenu() end) menu:addButton(_("~!Objectives"), "o", 16, 40 + (36 * 3), function() RunObjectivesMenu() end) menu:addButton(_("~!End Game"), "e", 16, 40 + (36 * 4), function() RunEndGameMenu() end) menu:addButton(_("Return to Game (~<Esc~>)"), "escape", 16, 248, function() menu:stop() end) menu:run(false)endfunction RunSaveMenu() local menu = BosGameMenu() menu:addLabel(_("Save Game"), 128, 11) local t = menu:addTextInputField("game.sav", 16, 40, 224) local browser = menu:addBrowser("~save", ".sav.gz$", 16, 70, 224, 166) local function cb(s) t:setText(browser:getSelectedItem()) end browser:setActionCallback(cb) menu:addSmallButton(_("Save"), 0, 16, 248, -- FIXME: use a confirm menu if the file exists already function() local name = t:getText() -- strip .gz if (string.find(name, ".gz$") ~= nil) then name = string.sub(name, 1, string.len(name) - 3) end -- append .sav if (string.find(name, ".sav$") == nil) then name = name .. ".sav" end -- replace invalid chars with underscore local t = {"\\", "/", ":", "*", "?", "\"", "<", ">", "|"} table.foreachi(t, function(k,v) name = string.gsub(name, v, "_") end) SaveGame(name) UI.StatusLine:Set("Saved game to: " .. name) menu:stop() end) menu:addSmallButton(_("Cancel"), 0, 16 + 12 + 106, 248, function() menu:stop() end) menu:run(false)endfunction RunGameSoundOptionsMenu() local menu = BosGameMenu() menu:addLabel(_("Sound Options"), 128, 11) AddSoundOptions(menu, 0, 0, 128 - 224/2, 280) menu:run(false)endfunction RunGameOptionsMenu() local menu = BosGameMenu() menu:addLabel(_("Game Options"), 128, 11) menu:addButton(_("Sound (~<F7~>)"), "f7", 16, 40 + (36 * 0), function() RunGameSoundOptionsMenu() end) menu:addButton(_("Game (~<F9~>)"), "f9", 16, 40 + (36 * 1), function() RunPreferencesMenu() end) menu:addButton(_("~!Diplomacy"), "d", 16, 40 + (36 * 2), function() RunDiplomacyMenu() end) menu:addButton(_("Previous (~<Esc~>)"), "escape", 128 - (224 / 2), 248, function() menu:stop() end) menu:run(false)endfunction RunPreferencesMenu() local menu = BosGameMenu() menu:addLabel(_("Game Options"), 128, 11) local fog = {} fog = menu:addCheckBox(_("Fog of War Enabled"), 16, 36 * 1, function() SetFogOfWar(fog:isMarked()) end) fog:setMarked(GetFogOfWar()) if (IsReplayGame() or IsNetworkGame()) then fog:setEnabled(false) end local ckey = {} ckey = menu:addCheckBox(_("Show command key"), 16, 36 * 2, function() UI.ButtonPanel.ShowCommandKey = ckey:isMarked() end) ckey:setMarked(UI.ButtonPanel.ShowCommandKey) local l = Label(_("Game Speed")) l:setFont(Fonts["game"]) l:adjustSize() menu:add(l, 16, 36 * 3) local gamespeed = {} gamespeed = menu:addSlider(15, 75, 198, 18, 32, 36 * 3.5, function() SetGameSpeed(gamespeed:getValue()) end) gamespeed:setValue(GetGameSpeed()) l = Label(_("slow")) l:setFont(Fonts["small"]) l:adjustSize() menu:add(l, 32, (36 * 4) + 6) l = Label(_("fast")) l:setFont(Fonts["small"]) l:adjustSize() menu:add(l, 230 - l:getWidth(), (36 * 4) + 6) menu:addSmallButton(_("~!OK"), "o", 128 - (106 / 2), 245, function() preferences.FogOfWar = GetFogOfWar() preferences.ShowCommandKey = UI.ButtonPanel.ShowCommandKey preferences.GameSpeed = GetGameSpeed() SavePreferences() menu:stop() end) menu:run(false)endfunction RunDiplomacyMenu() local menu = BosGameMenu() menu:setSize(384, 384) menu:setPosition((Video.Width - menu:getWidth()) / 2, (Video.Height - menu:getHeight()) / 2) menu:addLabel(_("Diplomacy"), 192, 11) menu:addLabel(_("Allied"), 136, 30, Fonts["game"]) menu:addLabel(_("Enemy"), 208, 30, Fonts["game"]) menu:addLabel(_("Shared Vision"), 310, 30, Fonts["game"]) local allied = {} local enemy = {} local sharedvision = {} local j = 0 for i=0,6 do if (Players[i].Type ~= PlayerNobody and ThisPlayer.Index ~= i) then j = j + 1 local l = Label(Players[i].Name) l:setFont(Fonts["game"]) l:adjustSize() menu:add(l, 16, (21 * j) + 27) local alliedcb = {} local enemycb = {} local sharedvisioncb = {} alliedcb = menu:addCheckBox("", 126, (21 * j) + 24, function() if (alliedcb:isMarked() and enemycb:isMarked()) then enemycb:setMarked(false) end end) alliedcb:setMarked(ThisPlayer:IsAllied(Players[i])) allied[j] = alliedcb allied[j].index = i enemycb = menu:addCheckBox("", 198, (21 * j) + 24, function() if (alliedcb:isMarked() and enemycb:isMarked()) then alliedcb:setMarked(false) end end) enemycb:setMarked(ThisPlayer:IsEnemy(Players[i])) enemy[j] = enemycb sharedvisioncb = menu:addCheckBox("", 300, (21 * j) + 24, function() end) sharedvisioncb:setMarked(ThisPlayer:IsSharedVision(Players[i])) sharedvision[j] = sharedvisioncb if (IsReplayGame() or ThisPlayer:IsTeamed(Players[i])) then alliedcb:setEnabled(false) enemycb:setEnabled(false) sharedvisioncb:setEnabled(false) end end end menu:addSmallButton(_("~!OK"), "o", 75, 384 - 40, function() for j=1,table.getn(allied) do local i = allied[j].index -- allies if (allied[j]:isMarked() and enemy[j]:isMarked() == false) then if (ThisPlayer:IsAllied(Players[i]) == false or ThisPlayer:IsEnemy(Players[i])) then SetDiplomacy(ThisPlayer.Index, "allied", i) end end -- enemies if (allied[j]:isMarked() == false and enemy[j]:isMarked()) then if (ThisPlayer:IsAllied(Players[i]) or ThisPlayer:IsEnemy(Players[i]) == false) then SetDiplomacy(ThisPlayer.Index, "enemy", i) end end -- neutral if (allied[j]:isMarked() == false and enemy[j]:isMarked() == false) then if (ThisPlayer:IsAllied(Players[i]) or ThisPlayer:IsEnemy(Players[i])) then SetDiplomacy(ThisPlayer.Index, "neutral", i) end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -