Skip to content

Commit

Permalink
Updated Grid to build 813 fixing #3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmcwatters committed May 16, 2015
1 parent d5335d5 commit 4fee4a3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/engine/client/bind.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ function readBinds()
end
end

function readDefaultBinds()
local config = "cfg/binds_default.cfg"
if ( not filesystem.exists( config ) ) then
return
end

local binds = {}
for line in filesystem.lines( config ) do
for k, v in string.gmatch( line, "(.+)%s(.+)" ) do
binds[ string.trim( k ) ] = string.trim( v )
end
end
return binds
end

function saveBinds()
local config = {}
for k, v in pairs( binds ) do
Expand Down
33 changes: 29 additions & 4 deletions src/engine/client/gui/optionsmenu/bindlistpanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function bindlistpanel:onBindChange( item, key, oldKey, concommand )
}
end

function bindlistpanel:readBinds()
function bindlistpanel:readBinds( binds )
if ( not filesystem.exists( "cfg/binds.lst" ) ) then
return
end
Expand All @@ -99,21 +99,46 @@ function bindlistpanel:readBinds()
self:addHeader( line )
elseif ( string.find( line, "[^=]" ) ) then
local name, concommand = string.match( line, "\"(.+)\"%s(.+)" )
concommand = string.trim( concommand )
local key = bind.getKeyForBind( concommand )
concommand = string.trim( concommand )

local key
if ( binds ) then
key = table.hasvalue( binds, concommand )
else
key = bind.getKeyForBind( concommand )
end
self:addBinding( name, key or '', concommand )
end
end
end
end

function bindlistpanel:saveBinds()
local i = 0
for concommand, keys in pairs( self.changedBinds ) do
i = i + 1
bind.setBind( keys.oldKey, nil )
bind.setBind( keys.key, concommand )
end

bind.saveBinds()
if ( i >= 1 ) then
bind.saveBinds()
self.changedBinds = {}
end
end

function bindlistpanel:useDefaults()
local defaultBinds = bind.readDefaultBinds()
for key, concommand in pairs( defaultBinds ) do
self.changedBinds[ concommand ] = {
key = key,
oldKey = bind.getKeyForBind( concommand )
}
end

local innerPanel = self:getInnerPanel()
innerPanel:removeChildren()
self:readBinds( defaultBinds )
end

gui.register( bindlistpanel, "bindlistpanel" )
2 changes: 1 addition & 1 deletion src/engine/client/gui/optionsmenu/keyboardoptionspanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function keyboardoptionspanel:keyboardoptionspanel()
local buttonName = name .. " Use Defaults Button"
self.useDefaultsButton = gui.commandbutton( group, buttonName, "Use Defaults" )
self.useDefaultsButton.onClick = function( commandbutton )
print( "TODO: Default bindings." )
self.bindList:useDefaults()
end
buttonName = name .. " Advanced Button"
self.advancedButton = gui.commandbutton( group, buttonName, "Advanced" )
Expand Down
1 change: 0 additions & 1 deletion src/engine/shared/require.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require( "engine.shared.filesystem" )

local error = error
local filesystem = filesystem
local hook = hook
local ipairs = ipairs
local pairs = pairs
local pcall = pcall
Expand Down

0 comments on commit 4fee4a3

Please # to comment.