Skip to content

editor: fixes, random rotation func, getCurrentMapName func, updated scale func #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions [admin]/admin/conf/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@
<all>Chatbox cleared$by_admin_4all.</all>
<log>ADMIN: $admin has cleared the chatbox.</log>
</group>
<group action="setfpslimit" r="225" g="170" b="90">
<all>FPS limit set to '$data'$by_admin_4all.</all>
<log>ADMIN: $admin has set FPS limit to '$data'</log>
</group>
</server>
<bans>

Expand Down
6 changes: 3 additions & 3 deletions [admin]/admin/server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,9 @@ function aAction ( type, action, admin, player, data, more )

if ( node ) then
local r, g, b = node["r"], node["g"], node["b"]
if ( node["all"] ) then outputChatBox ( aStripString ( node["all"] ), root, r, g, b ) end
if ( node["admin"] ) and ( admin ~= player ) then outputChatBox ( aStripString ( node["admin"] ), admin, r, g, b ) end
if ( node["player"] ) then outputChatBox ( aStripString ( node["player"] ), player, r, g, b ) end
if ( node["all"] ) then outputChatBox ( aStripString ( node["all"] ), root, r, g, b, true ) end
if ( node["admin"] ) and ( admin ~= player ) then outputChatBox ( aStripString ( node["admin"] ), admin, r, g, b, true ) end
if ( node["player"] ) then outputChatBox ( aStripString ( node["player"] ), player, r, g, b, true ) end
if ( node["log"] ) then outputServerLog ( aStripString ( node["log"] ) ) end
end
end
Expand Down
87 changes: 48 additions & 39 deletions [editor]/edf/edf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -884,23 +884,29 @@ end

--Returns an element's scale, or its scale element data, or false
function edfGetElementScale(element)
local etype = getElementType(element)
if etype == "object" then
scale = getObjectScale(element)
else
local handle = edfGetHandle(element)
if handle then
scale = getObjectScale(handle)
else
scale = tonumber(getElementData(element,"scale"))
end
end

if scale then
return scale
else
return false
end
local etype = getElementType(element)
if etype == "object" then
scale = getObjectScale(element)
if type(scale) ~= "table" then
scale = select(1, scale) or 1
end
else
local handle = edfGetHandle(element)
if handle then
scale = getObjectScale(handle)
if type(scale) == "table" then
scale = select(1, scale) or 1
end
else
scale = tonumber(getElementData(element,"scale"))
end
end

if scale then
return scale
else
return false
end
end

--Sets an element's position, or its posX/Y/Z element data
Expand Down Expand Up @@ -965,28 +971,31 @@ end

--Sets an element's scale, or its scale element data
function edfSetElementScale(element, scale)
local ancestor = edfGetAncestor(element) or element
setElementData(ancestor, "scale", scale)
local etype = getElementType(element)
if etype == "object" then
if setObjectScale(element, scale) then
triggerEvent ( "onElementPropertyChanged", ancestor, "scale" )
return true
end
else
local handle = edfGetHandle(element)
if handle then
if setObjectScale(handle, scale) then
triggerEvent ( "onElementPropertyChanged", ancestor, "scale" )
return true
end
else
setElementData(element, "scale", scale or 1)
triggerEvent ( "onElementPropertyChanged", ancestor, "scale" )
return true
end
end
return false
local ancestor = edfGetAncestor(element) or element
setElementData(ancestor, "scale", scale)
local etype = getElementType(element)
if type(scale) == "table" then
scale = scale[1]
end
if etype == "object" then
if setObjectScale(element, scale) then
triggerEvent ( "onElementPropertyChanged", ancestor, "scale" )
return true
end
else
local handle = edfGetHandle(element)
if handle then
if setObjectScale(handle, scale) then
triggerEvent ( "onElementPropertyChanged", ancestor, "scale" )
return true
end
else
setElementData(element, "scale", scale or 1)
triggerEvent ( "onElementPropertyChanged", ancestor, "scale" )
return true
end
end
return false
end

function edfGetElementInterior(element)
Expand Down
3 changes: 3 additions & 0 deletions [editor]/edf/edf_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ end
--Sets an element's scale, or its scale element data
function edfSetElementScale(element, scale)
if scale then
if type(scale) == "table" then
scale = scale[1]
end
if isBasic[getElementType(element)] then
return setElementData(element, "scale", scale)
else
Expand Down
3 changes: 2 additions & 1 deletion [editor]/editor_gui/client/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ function openSearch()
guiGridListSetItemText ( loadDialog.mapsList, row, 3, res["version"], false, false )
end
else
local escapedText = string.gsub(string.lower(text), "([%-%.%+%*%?%[%]%^%$%(%)%%])", "%%%1")
for i,res in ipairs(openResources) do
if string.find(res["friendlyName"],text) then
if string.find(res["friendlyName"], escapedText) then
local row = guiGridListAddRow ( loadDialog.mapsList )
guiGridListSetItemText ( loadDialog.mapsList, row, 1, res["friendlyName"], false, false )
guiGridListSetItemText ( loadDialog.mapsList, row, 2, res["gamemodes"], false, false )
Expand Down
7 changes: 5 additions & 2 deletions [editor]/editor_gui/client/mapsettings_gamemodesettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ function refreshGamemodeSettings()
mapsettings.rowValues[subRow] = dataInfo.default
if currentMapSettings.newSettings and currentMapSettings.newSettings[dataName] then
mapsettings.rowValues[subRow] = currentMapSettings.newSettings[dataName]
mapsettings.gamemodeSettings = copyTable ( mapsettings.rowValues )
end

if currentMapSettings.gamemodeSettings and currentMapSettings.gamemodeSettings[subRow] then
mapsettings.rowValues[subRow] = currentMapSettings.gamemodeSettings[subRow]
end
end
if count == 0 then
Expand All @@ -58,7 +61,7 @@ function refreshGamemodeSettings()
local row = guiGridListAddRow ( mapsettings.settingsList )
guiGridListSetItemText ( mapsettings.settingsList, row, 1, "No Settings definitions", true, false )
end
currentMapSettings.newSettings = nil
mapsettings.gamemodeSettings = copyTable ( mapsettings.rowValues )
end

local requiredText = { [true]="REQUIRED" }
Expand Down
10 changes: 9 additions & 1 deletion [editor]/editor_gui/client/options_action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ function optionsActions.elemScalingSnap(value)
optionsData.elemScalingSnap = tonumber(value)
end

function optionsActions.randomizeRotation(value)
optionsData.randomizeRotation = value
end

function optionsActions.randomizeRotationAxis(value)
optionsData.randomizeRotationAxis = value
end

function optionsActions.enableColPatch(value)
local success, isLoaded = editor_main.toggleColPatch(value)
if success then
Expand Down Expand Up @@ -170,7 +178,7 @@ function setEditorMoveSpeeds()
move_cursor.setRotateSpeeds ( dialog.slowElemRotate:getValue(), dialog.normalElemRotate:getValue(), dialog.fastElemRotate:getValue() )
move_freecam.setRotateSpeeds ( dialog.slowElemRotate:getValue(), dialog.normalElemRotate:getValue(), dialog.fastElemRotate:getValue() )

move_keyboard.setScaleIncrement ( dialog.elemScaling:getValue() )
move_keyboard.setScalingSpeeds ( dialog.slowElemScale:getValue(), dialog.normalElemScale:getValue(), dialog.fastElemScale:getValue() )

move_keyboard.toggleAxesLock ( dialog.lockToAxes:getValue() )
end
Expand Down
124 changes: 92 additions & 32 deletions [editor]/editor_gui/client/options_backend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ local xmlVariants = {
["normalElemRotate"]="rotate_normal_speed",
["fastElemRotate"]="rotate_fast_speed",
["slowElemRotate"]="rotate_slow_speed",
["elemScaling"]="scaling_increment",
["normalElemScale"]="scaling_normal_speed",
["fastElemScale"]="scaling_fast_speed",
["slowElemScale"]="scaling_slow_speed",
["lockToAxes"]="movement_lock_to_axes",
["autosnap"]="currentbrowser_autosnap",
["tutorialOnStart"]="tutorial_on_start",
["enableBox"]="enablebox",
["enableXYZlines"]="enablexyzlines",
["precisionLevel"]="precisionlevel",
["precisionRotLevel"]="precisionrotlevel",
["elemScalingSnap"]="scalingSnap",
["elemScalingSnap"]="elemscalingsnap",
["enablePrecisionSnap"]="enableprecisionsnap",
["enablePrecisionRotation"]="enableprecisionrotation",
["enableColPatch"]="enablecolpatch",
["enableRotPatch"]="enablerotpatch",
["randomizeRotation"]="enablerandomrot",
["randomizeRotationAxis"]="randomizerotaxis",
["fov"]="fov",
}
local nodeTypes = {
Expand All @@ -49,7 +53,9 @@ local nodeTypes = {
["normalElemRotate"]="progress",
["fastElemRotate"]="progress",
["slowElemRotate"]="progress",
["elemScaling"]="progress",
["normalElemScale"]="progress",
["fastElemScale"]="progress",
["slowElemScale"]="progress",
["lockToAxes"]="bool",
["autosnap"]="bool",
["tutorialOnStart"]="bool",
Expand All @@ -63,6 +69,8 @@ local nodeTypes = {
["enableXYZlines"]="bool",
["enableColPatch"]="bool",
["enableRotPatch"]="bool",
["randomizeRotation"]="bool",
["randomizeRotationAxis"]={"X","Y","Z","XY","XZ","YZ","XYZ"},
["fov"]="progress",
}
local defaults = {
Expand All @@ -81,20 +89,24 @@ local defaults = {
["slowElemMove"]=.025,
["normalElemRotate"]=2,
["fastElemRotate"]=10,
["slowElemRotate"]=.25,
["elemScaling"]=.1,
["slowElemRotate"]=0.25,
["normalElemScale"]=0.1,
["fastElemScale"]=1,
["slowElemScale"]=0.01,
["lockToAxes"]=false,
["autosnap"]=true,
["tutorialOnStart"]=true,
["enableBox"]=true,
["precisionLevel"]="0.1",
["precisionRotLevel"]="30",
["elemScalingSnap"]="0.1",
["elemScalingSnap"]="0.0001",
["enablePrecisionSnap"]=true,
["enablePrecisionRotation"]=false,
["enableXYZlines"]=true,
["enableColPatch"]=false,
["enableRotPatch"]=true,
["randomizeRotation"]=false,
["randomizeRotationAxis"]="XYZ",
["fov"]=dxGetStatus()["SettingFOV"],
}

Expand All @@ -118,36 +130,74 @@ function loadXMLSettings()
outputMessage ( "Map editor settings could not be created!.", 255,0,0 )
return
end
--
local settingsNodes = {}
for gui,nodeName in pairs(xmlVariants) do
local node = xmlFindChild ( settingsXML, nodeName, 0 )
if node then
settingsNodes[gui] = node
else
settingsNodes[gui] = xmlCreateChild ( settingsXML, nodeName )
end
-- check if the entries in the XML are valid, and remove invalid ones
local validNodes = {}
for _, nodeName in pairs(xmlVariants) do
validNodes[nodeName] = true
end

local children = xmlNodeGetChildren(settingsXML)
for i = #children, 1, -1 do
local node = children[i]
local nodeName = xmlNodeGetName(node)
if not validNodes[nodeName] then
xmlDestroyNode(node)
end
end
xmlSaveFile(settingsXML)
--
local settingsTable = {}
for gui,node in pairs(settingsNodes) do
local value
if nodeTypes[gui] == "bool" then
nodeValue = getNodeValue ( node, defaults[gui] )
value = bools[xmlNodeGetValue ( node )]
elseif nodeTypes[gui] == "progress" then
value = tonumber(getNodeValue ( node, defaults[gui] ))
elseif type(nodeTypes[gui]) == "table" then
value = tostring(getNodeValue ( node, defaults[gui] ))
local valid = false
for key,valuePossibility in pairs(nodeTypes[gui]) do
if value == valuePossibility then
valid = true
for gui, nodeName in pairs(xmlVariants) do
local node = xmlFindChild(settingsXML, nodeName, 0)
-- Node should exist after validation, but check anyway
if node then
local value
if nodeTypes[gui] == "bool" then
local nodeValue = xmlNodeGetValue(node)
value = bools[nodeValue]
-- If value is nil (invalid boolean), use default
if value == nil then
value = defaults[gui]
xmlNodeSetValue(node, tostring(value))
outputDebugString("Fixed invalid boolean value for " .. nodeName)
end
elseif nodeTypes[gui] == "progress" then
local nodeValue = xmlNodeGetValue(node)
value = tonumber(nodeValue)
-- If value is nil or out of range, use default
if value == nil then
value = defaults[gui]
xmlNodeSetValue(node, tostring(value))
outputDebugString("Fixed invalid numeric value for " .. nodeName)
end
elseif type(nodeTypes[gui]) == "table" then
local nodeValue = xmlNodeGetValue(node)
value = tostring(nodeValue)
-- Validate enum values
local valid = false
for _, valuePossibility in pairs(nodeTypes[gui]) do
if value == valuePossibility then
valid = true
break
end
end
-- If invalid value, use default
if not valid then
value = defaults[gui]
xmlNodeSetValue(node, tostring(value))
outputDebugString("Fixed invalid enum value for " .. nodeName)
end
end
settingsTable[gui] = value
else
-- This should never happen after validation, but as a fallback
settingsTable[gui] = defaults[gui]
node = xmlCreateChild(settingsXML, nodeName)
xmlNodeSetValue(node, tostring(settingsTable[gui]))
if node then
xmlSaveFile(settingsXML)
end
if not valid then value = defaults[gui] end
end
settingsTable[gui] = value
end
inputSettings ( settingsTable )
doActions()
Expand All @@ -167,7 +217,10 @@ function createSettingsXML()
local xml = xmlCreateFile ( "settings.xml", "settings" )
for gui,nodeName in pairs(xmlVariants) do
local node = xmlCreateChild ( xml, nodeName )
xmlNodeSetValue ( node, tostring(defaults[gui]) )
if not node then
node = xmlCreateChild ( xml, nodeName )
xmlNodeSetValue ( node, tostring(defaults[gui]) )
end
end
xmlSaveFile ( xml )
xmlUnloadFile ( xml )
Expand All @@ -179,7 +232,14 @@ end

function inputSettings ( settingsTable )
for gui,value in pairs(settingsTable) do
dialog[gui]:setValue(value)
if dialog[gui] then
dialog[gui]:setValue(value)
if nodeTypes[gui] == "progress" then
if optionsActions[gui] then
optionsActions[gui](value)
end
end
end
end
optionsSettings = settingsTable
end
Expand Down
Loading
Loading