69 lines
2.2 KiB
Lua
69 lines
2.2 KiB
Lua
local controlPressed = IsControlPressed
|
|
local disabledControlPressed = IsDisabledControlPressed
|
|
local getCursorHitCoords = Utils.getCursorHitCoords
|
|
local setEntityCoords = SetEntityCoords
|
|
local setEntityHeading = SetEntityHeading
|
|
|
|
mgizmo = {}
|
|
|
|
local rotateZCodes = ActionControls.rotate_z.codes
|
|
|
|
function mgizmo.selectEntity(self, entityHandle)
|
|
decorate:instructional({
|
|
{ key = "rotate_z", label = "Rotate Z +/-" }
|
|
})
|
|
self.entity = entityHandle
|
|
self.lastCoords = GetEntityCoords(entityHandle)
|
|
end
|
|
|
|
function mgizmo.deselectEntity(self)
|
|
if not self.entity then return end
|
|
self.entity = nil
|
|
self.decorateData = nil
|
|
decorate:instructional()
|
|
end
|
|
|
|
function mgizmo.updateEntity(self)
|
|
if not self.entity then return end
|
|
|
|
for i = 1, #rotateZCodes do
|
|
DisableControlAction(0, rotateZCodes[i], true)
|
|
end
|
|
|
|
if disabledControlPressed(0, rotateZCodes[1]) then
|
|
setEntityHeading(self.entity, GetEntityHeading(self.entity) + 0.3)
|
|
elseif disabledControlPressed(0, rotateZCodes[2]) then
|
|
setEntityHeading(self.entity, GetEntityHeading(self.entity) - 0.3)
|
|
end
|
|
|
|
local hitCoords, hitEntity = getCursorHitCoords(self.entity)
|
|
if not hitCoords or not hitEntity then
|
|
return Debug("mgizmo:updateEntity hitCoords or hitEntity is nil")
|
|
end
|
|
|
|
if self.lastCoords ~= hitCoords then
|
|
self.lastCoords = hitCoords
|
|
setEntityCoords(self.entity, hitCoords.x, hitCoords.y, hitCoords.z)
|
|
end
|
|
end
|
|
|
|
function mgizmo.loop(self)
|
|
CreateThread(function()
|
|
while decorate.active and decorate.mode == "mgizmo" do
|
|
Wait(0)
|
|
|
|
local leftClickJust = IsControlJustPressed(0, 24) or IsDisabledControlJustPressed(0, 24)
|
|
local leftClickPressed = controlPressed(0, 24) or disabledControlPressed(0, 24)
|
|
local leftClickRelease = IsControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 24)
|
|
|
|
if leftClickJust then
|
|
decorate:selectEntity(self.entity)
|
|
elseif leftClickPressed then
|
|
self:updateEntity()
|
|
elseif leftClickRelease then
|
|
self:deselectEntity()
|
|
end
|
|
end
|
|
end)
|
|
end
|