| 1 |
-- ____ _ __ |
| 2 |
-- / __ )____ _____ | | / /___ ___________ |
| 3 |
-- / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
-- / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
-- /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
-- |
| 7 |
-- A futuristic real-time strategy game. |
| 8 |
-- This file is part of Bos Wars. |
| 9 |
-- |
| 10 |
-- options.lua - The option menus |
| 11 |
-- |
| 12 |
-- (c) Copyright 2005-2010 by Francois Beerten |
| 13 |
-- |
| 14 |
-- This program is free software; you can redistribute it and/or modify |
| 15 |
-- it under the terms of the GNU General Public License as published by |
| 16 |
-- the Free Software Foundation; only version 2 of the License. |
| 17 |
-- |
| 18 |
-- This program is distributed in the hope that it will be useful, |
| 19 |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
-- GNU General Public License for more details. |
| 22 |
-- |
| 23 |
-- You should have received a copy of the GNU General Public License |
| 24 |
-- along with this program; if not, write to the Free Software |
| 25 |
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
-- 02111-1307, USA. |
| 27 |
-- |
| 28 |
|
| 29 |
|
| 30 |
function RunSpeedOptionsMenu(s) |
| 31 |
local menu |
| 32 |
local b |
| 33 |
local offx = (Video.Width - 256) / 2 |
| 34 |
local offy = (Video.Height - 288) / 2 |
| 35 |
local speed |
| 36 |
|
| 37 |
menu = BosMenu(_("Speed Options")) |
| 38 |
|
| 39 |
b = Label(_("Game Speed")) |
| 40 |
b:setFont(CFont:Get("game")) |
| 41 |
b:adjustSize(); |
| 42 |
menu:add(b, offx + 16, offy + 36 * 1) |
| 43 |
|
| 44 |
local gamespeedslider = Slider(15, 75) |
| 45 |
gamespeedslider:setValue(GetGameSpeed()) |
| 46 |
gamespeedslider:setActionCallback(function() SetGameSpeed(gamespeedslider:getValue()) end) |
| 47 |
gamespeedslider:setWidth(198) |
| 48 |
gamespeedslider:setHeight(18) |
| 49 |
gamespeedslider:setBaseColor(dark) |
| 50 |
gamespeedslider:setForegroundColor(clear) |
| 51 |
gamespeedslider:setBackgroundColor(clear) |
| 52 |
menu:add(gamespeedslider, offx + 32, offy + 36 * 1.5) |
| 53 |
|
| 54 |
b = Label(_("slow")) |
| 55 |
b:setFont(CFont:Get("game")) |
| 56 |
b:adjustSize(); |
| 57 |
menu:add(b, offx + 32, offy + 36 * 2 + 6) |
| 58 |
|
| 59 |
b = Label(_("fast")) |
| 60 |
b:setFont(CFont:Get("game")) |
| 61 |
b:adjustSize(); |
| 62 |
menu:add(b, offx + 230 - b:getWidth(), offy + 36 * 2 + 6) |
| 63 |
|
| 64 |
menu:addButton(_("~!OK"), offx + 128 - (200 / 2), offy + 245, |
| 65 |
function() |
| 66 |
preferences.GameSpeed = GetGameSpeed() |
| 67 |
SavePreferences() |
| 68 |
menu:stop() |
| 69 |
end) |
| 70 |
|
| 71 |
menu:run() |
| 72 |
end |
| 73 |
|
| 74 |
function AddSoundOptions(menu, offx, offy, centerx, bottom) |
| 75 |
local b |
| 76 |
|
| 77 |
b = Label(_("Effects Volume")) |
| 78 |
b:setFont(CFont:Get("game")) |
| 79 |
b:adjustSize(); |
| 80 |
menu:add(b, offx + 16, offy + 36 * 1) |
| 81 |
|
| 82 |
-- FIXME: disable if effects turned off |
| 83 |
local soundslider = Slider(0, 255) |
| 84 |
soundslider:setValue(GetEffectsVolume()) |
| 85 |
soundslider:setActionCallback(function() SetEffectsVolume(soundslider:getValue()) end) |
| 86 |
soundslider:setWidth(198) |
| 87 |
soundslider:setHeight(18) |
| 88 |
soundslider:setBaseColor(dark) |
| 89 |
soundslider:setForegroundColor(clear) |
| 90 |
soundslider:setBackgroundColor(clear) |
| 91 |
menu:add(soundslider, offx + 32, offy + 36 * 1.5) |
| 92 |
|
| 93 |
b = Label(_("min")) |
| 94 |
b:setFont(CFont:Get("game")) |
| 95 |
b:adjustSize(); |
| 96 |
menu:add(b, offx + 32, offy + 36 * 2 + 6) |
| 97 |
|
| 98 |
b = Label(_("max")) |
| 99 |
b:setFont(CFont:Get("game")) |
| 100 |
b:adjustSize(); |
| 101 |
menu:add(b, offx + 230 - b:getWidth(), offy + 36 * 2 + 6) |
| 102 |
|
| 103 |
local effectscheckbox = {} |
| 104 |
effectscheckbox = menu:addCheckBox(_("Enabled"), offx + 32, offy + 36 * 3, |
| 105 |
function() SetEffectsEnabled(effectscheckbox:isMarked()) end) |
| 106 |
effectscheckbox:setMarked(IsEffectsEnabled()) |
| 107 |
effectscheckbox:adjustSize(); |
| 108 |
|
| 109 |
b = Label(_("Music Volume")) |
| 110 |
b:setFont(CFont:Get("game")) |
| 111 |
b:adjustSize(); |
| 112 |
menu:add(b, offx + 16, offy + 36 * 4) |
| 113 |
|
| 114 |
-- FIXME: disable if music turned off |
| 115 |
local musicslider = Slider(0, 255) |
| 116 |
musicslider:setValue(GetMusicVolume()) |
| 117 |
musicslider:setActionCallback(function() SetMusicVolume(musicslider:getValue()) end) |
| 118 |
musicslider:setWidth(198) |
| 119 |
musicslider:setHeight(18) |
| 120 |
musicslider:setBaseColor(dark) |
| 121 |
musicslider:setForegroundColor(clear) |
| 122 |
musicslider:setBackgroundColor(clear) |
| 123 |
menu:add(musicslider, offx + 32, offy + 36 * 4.5) |
| 124 |
|
| 125 |
b = Label(_("min")) |
| 126 |
b:setFont(CFont:Get("game")) |
| 127 |
b:adjustSize(); |
| 128 |
menu:add(b, offx + 32, offy + 36 * 5 + 6) |
| 129 |
|
| 130 |
b = Label(_("max")) |
| 131 |
b:setFont(CFont:Get("game")) |
| 132 |
b:adjustSize(); |
| 133 |
menu:add(b, offx + 230 - b:getWidth(), offy + 36 * 5 + 6) |
| 134 |
|
| 135 |
local musiccheckbox = {} |
| 136 |
musiccheckbox = menu:addCheckBox(_("Enabled"), offx + 32, offy + 36 * 6, |
| 137 |
function() SetMusicEnabled(musiccheckbox:isMarked()) end) |
| 138 |
musiccheckbox:setMarked(IsMusicEnabled()) |
| 139 |
musiccheckbox:adjustSize(); |
| 140 |
|
| 141 |
b = menu:addButton(_("~!OK"), centerx, bottom - 11 - 27, |
| 142 |
function() |
| 143 |
preferences.EffectsVolume = GetEffectsVolume() |
| 144 |
preferences.EffectsEnabled = IsEffectsEnabled() |
| 145 |
preferences.MusicVolume = GetMusicVolume() |
| 146 |
preferences.MusicEnabled = IsMusicEnabled() |
| 147 |
SavePreferences() |
| 148 |
menu:stop() |
| 149 |
end) |
| 150 |
end |
| 151 |
|
| 152 |
function RunSoundOptionsMenu(s) |
| 153 |
local menu |
| 154 |
local offx = (Video.Width - 260) / 2 |
| 155 |
local offy = (Video.Height - 352) / 2 |
| 156 |
|
| 157 |
menu = BosMenu(_("Sound Options")) |
| 158 |
|
| 159 |
AddSoundOptions(menu, offx, offy, offx + 130 - 200/2, offy + 352) |
| 160 |
|
| 161 |
menu:run() |
| 162 |
end |
| 163 |
|
| 164 |
function SetVideoSize(width, height) |
| 165 |
if (Video:ResizeScreen(width, height) == false) then |
| 166 |
return |
| 167 |
end |
| 168 |
bckground:Resize(Video.Width, Video.Height) |
| 169 |
backgroundWidget = ImageWidget(bckground) |
| 170 |
Load("scripts/ui.lua") |
| 171 |
preferences.VideoWidth = Video.Width |
| 172 |
preferences.VideoHeight = Video.Height |
| 173 |
SavePreferences() |
| 174 |
end |
| 175 |
|
| 176 |
function BuildVideoOptionsMenu(menu) |
| 177 |
local b |
| 178 |
local x1 = (Video.Width / 3) - 100 |
| 179 |
local x2 = (Video.Width / 3) * 2 - 100 |
| 180 |
local offy = (Video.Height - 388) / 2 |
| 181 |
|
| 182 |
local modes = { |
| 183 |
-- 4:3, 5:4 aspect ratio modes |
| 184 |
{ 640, 480 }, -- 4:3 |
| 185 |
{ 800, 600 }, -- 4:3 |
| 186 |
{ 1024, 768 }, -- 4:3 |
| 187 |
{ 1280, 1024 }, -- 5:4 |
| 188 |
{ 1600, 1200 }, -- 4:3 |
| 189 |
-- 16:9, 8:5 (widescreen) aspect ratio modes |
| 190 |
{ 1024, 600 }, -- 5.12:3 = 15.36:9 |
| 191 |
{ 1280, 720 }, -- 16:9 |
| 192 |
{ 1366, 768 }, -- 16:9 inexact |
| 193 |
{ 1440, 900 }, -- 8:5 |
| 194 |
{ 1680, 1050 }, -- 8:5 |
| 195 |
{ 1920, 1080 }, -- 16:9 |
| 196 |
{ 1920, 1200 } -- 8:5 |
| 197 |
} |
| 198 |
|
| 199 |
local modes2 = math.ceil (#modes / 2); |
| 200 |
local offybot = offy + 36 * modes2; |
| 201 |
|
| 202 |
for i, size in ipairs (modes) do |
| 203 |
local sx, sy = size[1], size[2]; |
| 204 |
local t = sx .. " x " .. sy; |
| 205 |
local f = function () |
| 206 |
SetVideoSize (sx, sy); |
| 207 |
menu:stop (1); |
| 208 |
end; |
| 209 |
local x; |
| 210 |
if (i <= modes2) then x = x1; else x = x2; end; |
| 211 |
local y1 = offy + 36 * (i + .5); |
| 212 |
if (i <= modes2) then y = y1; else y = y1 - 36 * modes2; end; |
| 213 |
local b = menu:addRadioButton (t, "video", x, y, f); |
| 214 |
|
| 215 |
if (Video.Width == sx and Video.Height == sy) then |
| 216 |
b:setMarked (true); |
| 217 |
end |
| 218 |
end |
| 219 |
|
| 220 |
fullScreen = menu:addCheckBox(_("Fullscreen"), x1, offybot + 36 * 1.5, |
| 221 |
function() |
| 222 |
ToggleFullScreen() |
| 223 |
preferences.VideoFullScreen = Video.FullScreen |
| 224 |
SavePreferences() |
| 225 |
end) |
| 226 |
fullScreen:setMarked(Video.FullScreen) |
| 227 |
|
| 228 |
useopengl = menu:addCheckBox(_("Use OpenGL (restart required)"), x1, offybot + 36 * 2.5, |
| 229 |
function() |
| 230 |
preferences.UseOpenGL = useopengl:isMarked() |
| 231 |
SavePreferences() |
| 232 |
end) |
| 233 |
useopengl:setMarked(UseOpenGL) |
| 234 |
end |
| 235 |
|
| 236 |
function RunVideoOptionsMenu(s) |
| 237 |
local menu |
| 238 |
local continue = 1 |
| 239 |
|
| 240 |
while continue == 1 do |
| 241 |
menu = BosMenu(_("Video Options")) |
| 242 |
BuildVideoOptionsMenu(menu) |
| 243 |
menu:addButton(_("~!OK"), |
| 244 |
Video.Width / 2 - 100, |
| 245 |
Video.Height - 100, |
| 246 |
function() menu:stop() end) |
| 247 |
continue = menu:run() |
| 248 |
end |
| 249 |
end |
| 250 |
|
| 251 |
function RunLanguageOptionsMenu(s) |
| 252 |
local menu |
| 253 |
local b |
| 254 |
local grid = {{}, {}, {}, {}, {}, {}} |
| 255 |
local offy = (Video.Height - 300) / 2 |
| 256 |
local i = 1 |
| 257 |
|
| 258 |
menu = BosMenu(_("Language Selection")) |
| 259 |
local function AddLanguage(language, po, enginepo, bospo) |
| 260 |
if enginepo == nil then |
| 261 |
enginepo = "languages/" .. po .. ".po" |
| 262 |
bospo = "languages/bos-" .. po .. ".po" |
| 263 |
end |
| 264 |
local function SetLanguage() |
| 265 |
SetTranslationsFiles(enginepo, bospo) |
| 266 |
preferences.StratagusTranslation = StratagusTranslation |
| 267 |
preferences.GameTranslation = GameTranslation |
| 268 |
SavePreferences() |
| 269 |
end |
| 270 |
local rb = menu:addRadioButton(language, "lang", |
| 271 |
0, offy + i * 36, SetLanguage) |
| 272 |
grid[i][#grid[i] + 1] = rb |
| 273 |
i = i + 1 |
| 274 |
if i > #grid then |
| 275 |
i = 1 |
| 276 |
end |
| 277 |
if StratagusTranslation == enginepo then |
| 278 |
rb:setMarked(true) |
| 279 |
end |
| 280 |
return rb |
| 281 |
end |
| 282 |
|
| 283 |
b = AddLanguage("English", "en", |
| 284 |
"languages/engine.pot", "languages/bos.pot") |
| 285 |
if StratagusTranslation == "" then |
| 286 |
b:setMarked(true) |
| 287 |
end |
| 288 |
AddLanguage("Français", "fr") |
| 289 |
AddLanguage("Suomi", "fi") |
| 290 |
AddLanguage("Deutsch", "de") |
| 291 |
AddLanguage("Polski", "pl") |
| 292 |
AddLanguage("Dansk", "da") |
| 293 |
AddLanguage("Türkçe", "tr") |
| 294 |
AddLanguage("Español", "es") |
| 295 |
AddLanguage("Czech", "cs") |
| 296 |
AddLanguage("Português (Br)", "pt-br") |
| 297 |
AddLanguage("Português (Pt)", "pt-pt") |
| 298 |
AddLanguage("Nederlands", "nl") |
| 299 |
AddLanguage("Svenska", "sv") |
| 300 |
AddLanguage("Italiano", "it") |
| 301 |
AddLanguage("Magyar", "hu") |
| 302 |
AddLanguage("Lietuviškai", "lt") |
| 303 |
menu:adjustColumnWidths(grid) |
| 304 |
|
| 305 |
menu:addButton(_("~!OK"), Video.Width / 2 - 100, Video.Height - 100, |
| 306 |
function() menu:stop() end) |
| 307 |
menu:run() |
| 308 |
end |
| 309 |
|
| 310 |
function BuildOptionsMenu(menu) |
| 311 |
local x = Video.Width / 2 - 100 |
| 312 |
menu:addButton(_("~!Sound"), x, 140, RunSoundOptionsMenu) |
| 313 |
menu:addButton(_("~!Video"), x, 180, function() RunVideoOptionsMenu() menu:stop(1) end) |
| 314 |
menu:addButton(_("S~!peed"), x, 220, RunSpeedOptionsMenu) |
| 315 |
menu:addButton(_("~!Language"), x, 260, function() RunLanguageOptionsMenu() menu:stop(1) end) |
| 316 |
|
| 317 |
menu:addButton(_("Main Menu (~<Esc~>)"), x, Video.Height - 100, function() menu:stop() end) |
| 318 |
end |
| 319 |
|
| 320 |
function RunOptionsMenu(s) |
| 321 |
local menu |
| 322 |
local continue = 1 |
| 323 |
|
| 324 |
while continue == 1 do |
| 325 |
menu = BosMenu(_("Options")) |
| 326 |
BuildOptionsMenu(menu) |
| 327 |
continue = menu:run() |
| 328 |
end |
| 329 |
end |
| 330 |
|