Skip to content

added scaling via keybind (numpad +, -), undo/redo for scale property, model ids to current elements browser #604

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

Merged
merged 6 commits into from
Mar 1, 2025
Merged
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
56 changes: 56 additions & 0 deletions [editor]/edf/edf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ function edfRepresentElement(theElement, resource, parentData, editorMode, restr
-- get basic element properties
parentData.position = { edfGetElementPosition(theElement) }
parentData.rotation = { edfGetElementRotation(theElement) }
parentData.scale = edfGetElementScale(theElement)
parentData.dimension = edfGetElementDimension(theElement)
parentData.interior = edfGetElementInterior(theElement)
parentData.alpha = edfGetElementAlpha(theElement)
Expand Down Expand Up @@ -581,6 +582,7 @@ function edfCreateElement(elementType, creatorClient, fromResource, parametersTa
parametersTable = parametersTable or {}
parametersTable.position = parametersTable.position or {0,0,0}
parametersTable.rotation = parametersTable.rotation or {0,0,0}
parametersTable.scale = parametersTable.scale or 1
parametersTable.interior = parametersTable.interior or 0
parametersTable.dimension = parametersTable.dimension or 0
parametersTable.alpha = parametersTable.alpha or 255
Expand Down Expand Up @@ -619,6 +621,8 @@ function edfCreateElement(elementType, creatorClient, fromResource, parametersTa
edfSetElementPosition(newElement, dataValue[1], dataValue[2], dataValue[3])
elseif dataField == "rotation" then
edfSetElementRotation(newElement, dataValue[1], dataValue[2], dataValue[3], dataValue[4])
elseif dataField == "scale" then
edfSetElementScale(newElement, dataValue)
elseif dataField == "interior" then
if dataValue == -1 then
setElementInterior(newElement, 0) -- Interior -1 only works on removeWorldModel (But element data must be set to -1)
Expand Down Expand Up @@ -670,6 +674,7 @@ function edfCloneElement(theElement, editorMode )
parametersTable = {}
parametersTable.position = {edfGetElementPosition(theElement)} or {0,0,0}
parametersTable.rotation = {edfGetElementRotation(theElement)} or {0,0,0}
parametersTable.scale = edfGetElementScale(theElement) or 2
parametersTable.interior = edfGetElementInterior(theElement) or 0
parametersTable.dimension = edfGetElementDimension(theElement) or 0
parametersTable.alpha = edfGetElementAlpha(theElement) or 255
Expand Down Expand Up @@ -713,6 +718,8 @@ function edfCloneElement(theElement, editorMode )
edfSetElementPosition(newElement, dataValue[1], dataValue[2], dataValue[3])
elseif dataField == "rotation" then
edfSetElementRotation(newElement, dataValue[1], dataValue[2], dataValue[3])
elseif dataField == "scale" then
edfSetElementScale(newElement, dataValue)
else
setElementData(newElement, dataField, dataValue)
end
Expand Down Expand Up @@ -875,6 +882,27 @@ function edfGetElementRotation(element)
end
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
end

--Sets an element's position, or its posX/Y/Z element data
function edfSetElementPosition(element, px, py, pz)
local ancestor = edfGetAncestor(element) or element
Expand Down Expand Up @@ -935,6 +963,32 @@ function edfSetElementRotation(element, rx, ry, rz, rotOrder)
return false
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
end

function edfGetElementInterior(element)
return getElementInterior(element) or tonumber(getElementData(element, "interior")) or 0
end
Expand Down Expand Up @@ -1324,6 +1378,8 @@ function edfGetChildData(node, dataFields)
value[1] = xmlNodeGetAttribute(node, "rotX") or 0
value[2] = xmlNodeGetAttribute(node, "rotY") or 0
value[3] = xmlNodeGetAttribute(node, "rotZ") or 0
elseif dataField == "scale" then
value = xmlNodeGetAttribute(node, "scale") or 1
else
value = xmlNodeGetAttribute(node, dataField) or nil
if value then
Expand Down
38 changes: 38 additions & 0 deletions [editor]/edf/edf_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ function edfGetElementRotation(element)
end
end

--Returns an element's scale, or its scale element data, or 1
function edfGetElementScale(element)
local scale
if isBasic[getElementType(element)] then
scale = getElementData(element, "scale")
else
local handle = edfGetHandle(element)
if handle then
return getElementData(handle, "scale")
else
scale = getElementData(element, "scale")
end
end

if scale then
return scale
else
return 1
end
end

--Setsan element's position, or its posX/Y/Z element data
function edfSetElementPosition(element, px, py, pz)
if px and py and pz then
Expand Down Expand Up @@ -165,6 +186,23 @@ function edfSetElementRotation(element, rx, ry, rz)
end
end

--Sets an element's scale, or its scale element data
function edfSetElementScale(element, scale)
if scale then
if isBasic[getElementType(element)] then
return setElementData(element, "scale", scale)
else
local handle = edfGetHandle(element)
if handle then
return setElementData(handle, "scale", scale)
else
setElementData(element, "scale", scale)
return true
end
end
end
end

function edfGetElementInterior(element)
return getElementInterior(element) or tonumber(getElementData(element, "interior")) or 0
end
Expand Down
4 changes: 4 additions & 0 deletions [editor]/edf/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<export function="edfSetElementPosition" /> <!-- bool -->
<export function="edfGetElementRotation" /> <!-- number, number, number -->
<export function="edfSetElementRotation" /> <!-- bool -->
<export function="edfGetElementScale" /> <!-- number -->
<export function="edfSetElementScale" /> <!-- number -->
<export function="edfGetElementInterior" /> <!-- number -->
<export function="edfSetElementInterior" /> <!-- bool -->
<export function="edfGetElementDimension" /> <!-- number -->
Expand All @@ -61,6 +63,8 @@
<export function="edfSetElementPosition" type="client" /> <!-- bool -->
<export function="edfGetElementRotation" type="client" /> <!-- number, number, number -->
<export function="edfSetElementRotation" type="client" /> <!-- bool -->
<export function="edfGetElementScale" type="client" /> <!-- number -->
<export function="edfSetElementScale" type="client" /> <!-- number -->
<export function="edfGetElementInterior" type="client" /> <!-- number -->
<export function="edfSetElementInterior" type="client" /> <!-- bool -->
<export function="edfGetElementDimension" type="client" /> <!-- number -->
Expand Down
112 changes: 63 additions & 49 deletions [editor]/editor_gui/client/currentbrowser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function createCurrentBrowser ()
local windowWidth = screenX*width
local windowHeight = screenY*height
currentBrowserGUI.browser = guiCreateWindow ( 1 - width, 0, width, height, "Current Elements...", true )
currentBrowserGUI.gridlist = browserList:create(12, 85, windowWidth, windowHeight-128,{{["Name"]=0.85}},false, currentBrowserGUI.browser )
currentBrowserGUI.gridlist = browserList:create(12, 85, windowWidth, windowHeight-128,{{["Name [ID]"]=0.85}},false, currentBrowserGUI.browser )
currentBrowserGUI.search = guiCreateEdit ( 12, 50, windowWidth, 30, "Search...", false, currentBrowserGUI.browser )
currentBrowserGUI.dropdown = editingControl.dropdown:create{["x"]=12,["y"]=25,["width"]=windowWidth,["height"]=20,["dropWidth"]=windowWidth,["dropHeight"]=200,["relative"]=false,["parent"]=currentBrowserGUI.browser,["rows"]={""}}
--linked to options
Expand Down Expand Up @@ -178,25 +178,29 @@ function currentBrowser.isolateElement (element,bool)
end


function currentBrowser.gridlistClick (cellrow)
if cellrow ~= 0 then
local id = currentBrowserGUI.gridlist:getSelectedText()
cSelectedElement = getElementByID ( id )
editor_main.selectElement ( cSelectedElement, 2, false, cSelectedElement, cSelectedElement, true)
if ( dialog.autosnap:getValue() ) then
autoSnap ( cSelectedElement )
end
if ( dimensionElement ) then
setElementDimension ( dimensionElement, workingDimension )
setElementDimension ( cSelectedElement, hiddenDimension )
dimensionElement = cSelectedElement
end
elseif ( dimensionElement ) then
setElementDimension ( dimensionElement, workingDimension )
setElementDimension ( localPlayer, workingDimension )
guiCheckBoxSetSelected ( currentBrowserGUI.isolate, false )
dimensionElement = false
end
function currentBrowser.gridlistClick(cellrow)
if cellrow ~= 0 then
local fullText = currentBrowserGUI.gridlist:getSelectedText()
-- Extract just the element name portion (before the bracket)
local elementName = string.match(fullText, "^([^%[]+)")
-- Trim any spaces at the end
elementName = string.gsub(elementName, "%s+$", "")
cSelectedElement = getElementByID(elementName)
editor_main.selectElement(cSelectedElement, 2, false, cSelectedElement, cSelectedElement, true)
if (dialog.autosnap:getValue()) then
autoSnap(cSelectedElement)
end
if (dimensionElement) then
setElementDimension(dimensionElement, workingDimension)
setElementDimension(cSelectedElement, hiddenDimension)
dimensionElement = cSelectedElement
end
elseif (dimensionElement) then
setElementDimension(dimensionElement, workingDimension)
setElementDimension(localPlayer, workingDimension)
guiCheckBoxSetSelected(currentBrowserGUI.isolate, false)
dimensionElement = false
end
end

function currentBrowser.doubleClick()
Expand Down Expand Up @@ -303,10 +307,16 @@ function applySearch ( array, query )
end

function setTableElementIDs(elemTable)
for k,v in pairs (elemTable) do
elemTable[k] = tostring(getElementID(v))
end
return elemTable
local elementsWithIDs = {}
for k, v in pairs(elemTable) do
local elementID = getElementID(v)
local numericID = ""
if getElementType(v) == "object" or getElementType(v) == "vehicle" or getElementType(v) == "ped" then
numericID = "[" .. (getElementData(v, "model") or getElementModel(v) or "Unknown") .. "]"
end
elementsWithIDs[k] = tostring(elementID) .. " " .. tostring(numericID)
end
return elementsWithIDs
end

function clearReps ( elemTable )
Expand Down Expand Up @@ -429,31 +439,35 @@ function showCurrentBrowser ( elementArray, ignoredElements, elementType, resour
end

function closeCurrentBrowser()
if ( not currentBrowser.showing ) then return end
currentBrowser.showing = false
cSelectedElement = false
if ( callbackFunction ) then
local id = currentBrowserGUI.gridlist:getSelectedText()
if ( not id ) then
callbackFunction(false)
else
callbackFunction(id)
end
callbackFunction = nil
end
currentBrowserGUI.gridlist:disable()
guiCheckBoxSetSelected ( currentBrowserGUI.isolate, false )
if ( dimensionElement ) then
setElementDimension ( dimensionElement, workingDimension )
setElementDimension ( localPlayer, workingDimension )
dimensionElement = false
end
guiSetVisible ( currentBrowserGUI.browser, false )
dumpSettings()
xmlSaveFile ( settingsXML )
removeEventHandler ( "onClientGUIWorldClick", root, currentBrowser.searchClick )
removeEventHandler ( "onClientElementCreate",root,currentBrowser.prepareSearch )
removeEventHandler ( "onClientElementDestroyed",root,currentBrowser.prepareSearch )
if (not currentBrowser.showing) then return end
currentBrowser.showing = false
cSelectedElement = false
if (callbackFunction) then
local fullText = currentBrowserGUI.gridlist:getSelectedText()
if (not fullText) then
callbackFunction(false)
else
-- Extract just the element name portion (before the bracket)
local elementName = string.match(fullText, "^([^%[]+)")
-- Trim any spaces at the end
elementName = string.gsub(elementName, "%s+$", "")
callbackFunction(elementName)
end
callbackFunction = nil
end
currentBrowserGUI.gridlist:disable()
guiCheckBoxSetSelected(currentBrowserGUI.isolate, false)
if (dimensionElement) then
setElementDimension(dimensionElement, workingDimension)
setElementDimension(localPlayer, workingDimension)
dimensionElement = false
end
guiSetVisible(currentBrowserGUI.browser, false)
dumpSettings()
xmlSaveFile(settingsXML)
removeEventHandler("onClientGUIWorldClick", root, currentBrowser.searchClick)
removeEventHandler("onClientElementCreate", root, currentBrowser.prepareSearch)
removeEventHandler("onClientElementDestroyed", root, currentBrowser.prepareSearch)
end

function restoreSelectedElement()
Expand Down
6 changes: 6 additions & 0 deletions [editor]/editor_gui/client/options_action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function optionsActions.precisionRotLevel(value)
optionsData.precisionRotLevel = tonumber(value)
end

function optionsActions.elemScalingSnap(value)
optionsData.elemScalingSnap = tonumber(value)
end

function optionsActions.enableColPatch(value)
local success, isLoaded = editor_main.toggleColPatch(value)
if success then
Expand Down Expand Up @@ -166,6 +170,8 @@ 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.toggleAxesLock ( dialog.lockToAxes:getValue() )
end

Expand Down
6 changes: 6 additions & 0 deletions [editor]/editor_gui/client/options_backend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ local xmlVariants = {
["normalElemRotate"]="rotate_normal_speed",
["fastElemRotate"]="rotate_fast_speed",
["slowElemRotate"]="rotate_slow_speed",
["elemScaling"]="scaling_increment",
["lockToAxes"]="movement_lock_to_axes",
["autosnap"]="currentbrowser_autosnap",
["tutorialOnStart"]="tutorial_on_start",
["enableBox"]="enablebox",
["enableXYZlines"]="enablexyzlines",
["precisionLevel"]="precisionlevel",
["precisionRotLevel"]="precisionrotlevel",
["elemScalingSnap"]="scalingSnap",
["enablePrecisionSnap"]="enableprecisionsnap",
["enablePrecisionRotation"]="enableprecisionrotation",
["enableColPatch"]="enablecolpatch",
Expand All @@ -47,13 +49,15 @@ local nodeTypes = {
["normalElemRotate"]="progress",
["fastElemRotate"]="progress",
["slowElemRotate"]="progress",
["elemScaling"]="progress",
["lockToAxes"]="bool",
["autosnap"]="bool",
["tutorialOnStart"]="bool",
["enableDumpSave"]="bool",
["enableBox"]="bool",
["precisionLevel"]={"10","5","2","1","0.1","0.01","0.001","0.0001"},
["precisionRotLevel"]={"180","90","45","30","20","10","5","1"},
["elemScalingSnap"]={"1","0.1","0.01","0.001","0.0001"},
["enablePrecisionSnap"]="bool",
["enablePrecisionRotation"]="bool",
["enableXYZlines"]="bool",
Expand All @@ -78,12 +82,14 @@ local defaults = {
["normalElemRotate"]=2,
["fastElemRotate"]=10,
["slowElemRotate"]=.25,
["elemScaling"]=.1,
["lockToAxes"]=false,
["autosnap"]=true,
["tutorialOnStart"]=true,
["enableBox"]=true,
["precisionLevel"]="0.1",
["precisionRotLevel"]="30",
["elemScalingSnap"]="0.1",
["enablePrecisionSnap"]=true,
["enablePrecisionRotation"]=false,
["enableXYZlines"]=true,
Expand Down
Loading