Skip to content

Commit

Permalink
Merge branch 'release/v0.6.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
nczempin committed May 11, 2014
2 parents dff153f + 49d7708 commit e7feef2
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 47 deletions.
6 changes: 4 additions & 2 deletions love2d/libraries/comboBox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ function love.gui.newComboBox(x, y, width, height, list)
--G.printf(o.text, o.x + 2, o.y + 6, o.width, "center")
G.setBlendMode("additive")
G.setColor(color[1], color[2], color[3], color[4])
G.printf(o.list[o.selection], o.x, o.y + 4, o.width, "center")
local text = o.list[o.selection] or "???"
G.printf(text, o.x, o.y + 4, o.width, "center")
if o.active then
G.setLineWidth(2)
local j = 0
for i = 1, #o.list do
if i ~= o.selection then
j = j + 1
G.printf(o.list[i], o.x, o.y + 4+BOUNDING_HEIGHT*(j), o.width, "center")
local text = o.list[i] or "???"
G.printf(text, o.x, o.y + 4+BOUNDING_HEIGHT*(j), o.width, "center")
G.rectangle("line", o.x, o.y+BOUNDING_HEIGHT*(j), o.width, o.height)
end
end
Expand Down
45 changes: 15 additions & 30 deletions love2d/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,47 @@ require "spawn"
require "towerType"
require "sound"

require "settings"

require "util"

-- states
stateMainMenu = require("state/main_menu")
stateIntro = require("state/intro")
stateWorldMenu = require("state/world_menu")
stateCredits = require("state/credits")
stateSettings = require("state/settings")
stateSettings = require("state/settings_menu")
stateSettingsVideo = require("state/settings_video")
stateSettingsVideoShaders = require("state/settings_video_shaders")
stateSettingsVideoDisplay = require("state/settings_video_display")
stateSettingsAudio = require("state/settings_audio")

function loadOptions()
local optionsIni = "options.ini"

if (FS.exists(optionsIni))then
local option = "display.large"
local optionLines = {}
local lines = {}
function love.filesystem.rename(from, to)
assert(type(from) == "string", "bad argument #1 to rename (string expected, got "..type(from)..")")
assert(type(to) == "string", "bad argument #2 to rename (string expected, got "..type(to)..")")

for line in love.filesystem.lines(optionsIni) do
table.insert(lines, line)
end
local writeDir = love.filesystem.getSaveDirectory().."/"

for i,line in ipairs(lines)do
local m1, m2 = string.find(line, option.."=")
print (i, m1,m2)
if m2 then

local setting = string.sub(line, m2+1)
--TODO: can/should we change the options in conf.lua from here?
if string.find(setting, "true")then
print "large"
stateSettingsVideoDisplay.optionLarge = stateSettingsVideoDisplay.resolutionStrings[2] --TODO: this should really be handled inside the display settings module
else
print "not large"
stateSettingsVideoDisplay.optionLarge = stateSettingsVideoDisplay.resolutionStrings[3]--TODO: this should really be handled inside the display settings module
end
stateSettingsVideoDisplay.checkOptionsLarge() --TODO: provide a function that changes the option and immediately switches
end
end
if not os.rename(writeDir..from, writeDir..to) then
return false
end
end

return true
end
function love.load()
G = love.graphics
W = love.window
T = love.turris
S = love.sounds
FS = love.filesystem
loadOptions()
--saveOptions() --TODO temporarily added for testing
FONT = G.newFont(32)
FONT_SMALL = G.newFont(24)

currentgamestate = 12 -- TODO: make "skip intro" an option

stateMainMenu.setVersion("v0.6.2")
stateMainMenu.setVersion("v0.6.3")
end

function love.getgamestate()
Expand Down Expand Up @@ -211,6 +194,8 @@ function love.keypressed(key, code)
love.sounds.playSound("sounds/button_pressed.wav")
love.setgamestate(0)
end
-- elseif key == "f1" then
-- saveOptions()
end
end

Expand Down
59 changes: 59 additions & 0 deletions love2d/settings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

function loadOptions()
local optionsIni = "options.ini"

if (FS.exists(optionsIni))then
local f1 = function(setting)
local param = string.find(setting, "true")
stateSettingsVideoDisplay.optionFullscreen = param
stateSettingsVideoDisplay.chkFullscreen.checked = param --TODO: this should be done inside the settings page
end
local f2= function(setting)
stateSettingsVideoDisplay.optionLarge=setting --TODO this needs to be sanitized
local resolutionIndex = stateSettingsVideoDisplay.findResolution(setting)
stateSettingsVideoDisplay.comboLarge.updateSelection(resolutionIndex)
end
local options = {{name="display.video.fullscreen", execute= f1},{name="display.video.resolution",execute = f2}}
local optionLines = {}
local lines = {}

for line in love.filesystem.lines(optionsIni) do
table.insert(lines, line)
end

for i,line in ipairs(lines)do
for j,option in ipairs(options) do
local m1, m2 = string.find(line, option.name.."=")
print (i, m1,m2)
if m2 then

local setting = string.sub(line, m2+1)
option.execute(setting)
end
end
end
end
stateSettingsVideoDisplay.checkOptionsLarge() --TODO: provide a function that changes the option and immediately switches
end
function saveOptions()
local optionsIni = "options.ini"
local data = ""
local f1 = function(setting)
local param =stateSettingsVideoDisplay.optionFullscreen or false
data = data..setting.."="..tostring(param).."\n"
end
local f2= function(setting)
local width, height, flags = love.window.getMode()
local param = width.."x"..height

data = data..setting.."="..tostring(param).."\n"
end
local options = {{name="display.video.fullscreen", execute= f1},{name="display.video.resolution",execute = f2}}
for _, option in ipairs(options) do
option.execute(option.name)
end

love.filesystem.rename(optionsIni,optionsIni.."_old")
local success = love.filesystem.write( optionsIni, data )
print ("options saved successfully: ", success)
end
File renamed without changes.
45 changes: 30 additions & 15 deletions love2d/state/settings_video_display.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
local o = {}
o.findResolution = function(tmp)
local found = 0
for i = 1, #o.resolutionStrings do
if o.resolutionStrings[i] == tmp then
print ("found: "..i)
found = i
end
end
if found == 0 then
table.insert(o.resolutionStrings,1,tmp)
found = 1
end
return found
end

local startx = love.window.getWidth() * 0.5 - 191 * 0.5
local starty = 80
Expand All @@ -14,22 +28,15 @@ o.effectTimer = 0
o.chromaticEffect = 0

o.guiMenu = love.gui.newGui()
o.chkFullscreen = o.guiMenu.newCheckbox(startx, starty + 64 * 0, 191, 32, false, "Fullscreen")

o.chkFullscreen = o.guiMenu.newCheckbox(startx, starty + 64 * 0, 191, 32, o.optionFullscreen, "Fullscreen")
o.resolutionStrings = {"1920x1080", "1280x720", "800x600", "640x480"}

local width, height, flags = love.window.getMode()
local tmp = width.."x"..height
local found = 0
for i = 1, #o.resolutionStrings do
if o.resolutionStrings[i] == tmp then
print ("found: "..i)
found = i
end
end
if found == 0 then
table.insert(o.resolutionStrings,1,tmp)
found = 1
end

local found = o.findResolution(tmp)

o.comboLarge = o.guiMenu.newComboBox(startx, starty + 64 * 1, 191, 32, o.resolutionStrings)
for i = 1, #o.resolutionStrings do
print (o.resolutionStrings[i])
Expand All @@ -46,7 +53,11 @@ o.reset = function()
o.guiMenu.flushMouse()
end
o.checkOptionsLarge = function()
local iterator = o.optionLarge:gmatch('%d+')
local option = o.optionLarge
if not option then
return --TODO log warning?
end
local iterator = option:gmatch('%d+')
local numbers = {}
local i = 1
for number in iterator do
Expand All @@ -55,9 +66,12 @@ o.checkOptionsLarge = function()
end
--TODO we are assuming that x will always have 2 elements. This is unsafe to assume.
local width, height, flags = love.window.getMode()
if (numbers[1] ~= width and numbers[2] ~= height)then
local isFullscreen = flags["fullscreen"]
if (numbers[1] ~= width or numbers[2] ~= height or isFullscreen ~= o.optionFullscreen)then
local success = love.window.setMode( numbers[1], numbers[2], {fullscreen=o.optionFullscreen,vsync=false})--TODO: make vsync an option
if success then
saveOptions()
--TODO this needs to be done more elegantly
love.postshader.refreshScreenSize()
lightWorld.refreshScreenSize()
stateMainMenu.refreshScreenSize()
Expand All @@ -76,10 +90,11 @@ o.update = function(dt)

o.guiMenu.update(dt)

if o.chkFullscreen.isHit() then
if o.chkFullscreen.isHit() then --TODO: we should switch on button release, not click
love.sounds.playSound("sounds/button_pressed.wav")
o.optionFullscreen = o.chkFullscreen.isChecked()
local success = love.window.setFullscreen( o.optionFullscreen )
saveOptions()
end

if o.comboLarge.active then
Expand Down

0 comments on commit e7feef2

Please sign in to comment.