Skip to content

Commit

Permalink
Some more editor house keeping
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Dec 29, 2024
1 parent 11043cd commit e172cd4
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 91 deletions.
52 changes: 31 additions & 21 deletions scripts/editor/brushes/BaseBrush.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
--[[
Basic brush, that manipulates waypoints.
]]
---@class CpBrush : ConstructionBrush
CpBrush = {
TRANSLATION_PREFIX = "CP_editor_",
radius = 0.5,
primaryButtonText = "primary_text",
primaryAxisText = "primary_axis_text",
secondaryButtonText = "secondary_text",
secondaryAxisText = "secondary_axis_text",
tertiaryButtonText = "tertiary_text",
inputTitle = "input_title",
yesNoTitle = "yesNo_title",
errMessage = "err",
ERR_MESSAGE_DURATION = 15 * 1000 -- 15 sec
}
local CpBrush_mt = Class(CpBrush, ConstructionBrush)
function CpBrush.new(customMt, cursor)
local self = ConstructionBrush.new(customMt or CpBrush_mt, cursor)
---@class CpBrush
CpBrush = CpObject(ConstructionBrush)
CpBrush.TRANSLATION_PREFIX = "CP_editor_"
CpBrush.radius = 2
CpBrush.primaryButtonText = "primary_text"
CpBrush.primaryAxisText = "primary_axis_text"
CpBrush.secondaryButtonText = "secondary_text"
CpBrush.secondaryAxisText = "secondary_axis_text"
CpBrush.tertiaryButtonText = "tertiary_text"
CpBrush.inputTitle = "input_title"
CpBrush.yesNoTitle = "yesNo_title"
CpBrush.errMessage = "err"
CpBrush.ERR_MESSAGE_DURATION = 15 * 1000 -- 15 sec
function CpBrush:init(cursor, editor)
self.isActive = false
self.cursor = cursor
self.supportsPrimaryButton = false
self.supportsPrimaryDragging = false
self.supportsSecondaryButton = false
self.supportsSecondaryDragging = false
self.supportsTertiaryButton = false
self.supportsPrimaryAxis = false
self.supportsSecondaryAxis = false
self.primaryAxisIsContinuous = false
self.secondaryAxisIsContinuous = false
self.inputTextDirty = true
self.activeSoundId = ConstructionSound.ID.NONE
self.activeSoundPitchModifier = nil
self.cursor:setShapeSize(self.radius)
self.cursor:setShape(GuiTopDownCursor.SHAPES.CIRCLE)
self.lastHoveredIx = nil
self.errorMsgTimer = CpTemporaryObject(false)
return self
self.editor = editor
self.courseWrapper = editor:getCourseWrapper()
end

function CpBrush:isAtPos(position, x, y, z)
Expand All @@ -43,10 +55,8 @@ function CpBrush:getHoveredWaypointIx()
end
end

function CpBrush:setParameters(editor, translation)
self.editor = editor
function CpBrush:setParameters(translation)
self.translation = translation
self.courseWrapper = editor:getCourseWrapper()
end

function CpBrush:update(dt)
Expand Down
11 changes: 4 additions & 7 deletions scripts/editor/brushes/advanced/CurveWaypoints.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@

--- Moves a new waypoint at the mouse position.
---@class CpBrushCurveInsertWP : CpBrush
CpBrushCurveInsertWP = {
DELAY = 100,
}
local CpBrushMoveWP_mt = Class(CpBrushCurveInsertWP, CpBrush)
function CpBrushCurveInsertWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushMoveWP_mt, cursor)
CpBrushCurveInsertWP = CpObject(CpBrush)
CpBrushCurveInsertWP.DELAY = 100
function CpBrushCurveInsertWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.supportsSecondaryButton = true
self.delay = g_time

self.selectedFirstIx = nil
self.selectedSecondIx = nil
return self
end

function CpBrushCurveInsertWP:onButtonPrimary(isDown, isDrag, isUp)
Expand Down
11 changes: 4 additions & 7 deletions scripts/editor/brushes/advanced/MoveWaypoint.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@

--- Moves a new waypoint at the mouse position.
---@class CpBrushAdvancedMoveWP : CpBrush
CpBrushAdvancedMoveWP = {
DELAY = 100
}
local CpBrushMoveWP_mt = Class(CpBrushAdvancedMoveWP, CpBrush)
function CpBrushAdvancedMoveWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushMoveWP_mt, cursor)
CpBrushAdvancedMoveWP = CpObject(CpBrush)
CpBrushAdvancedMoveWP.DELAY = 100
function CpBrushAdvancedMoveWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.supportsSecondaryButton = true
self.delay = g_time

self.selectedFirstIx = nil
self.selectedSecondIx = nil
return self
end

function CpBrushAdvancedMoveWP:onButtonPrimary(isDown, isDrag, isUp)
Expand Down
8 changes: 3 additions & 5 deletions scripts/editor/brushes/basic/DeleteWaypoint.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

--- Deletes a new waypoint at the mouse position.
---@class CpBrushDeleteWP : CpBrush
CpBrushDeleteWP = {}
local CpBrushDeleteWP_mt = Class(CpBrushDeleteWP, CpBrush)
function CpBrushDeleteWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushDeleteWP_mt, cursor)
CpBrushDeleteWP = CpObject(CpBrush)
function CpBrushDeleteWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.supportsSecondaryButton = true
self.supportsTertiaryButton = true
return self
end

function CpBrushDeleteWP:onButtonPrimary()
Expand Down
8 changes: 3 additions & 5 deletions scripts/editor/brushes/basic/InsertWaypoint.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

--- Inserts a new waypoint at the mouse position.
---@class CpBrushInsertWP : CpBrush
CpBrushInsertWP = {}
local CpBrushInsertWP_mt = Class(CpBrushInsertWP, CpBrush)
function CpBrushInsertWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushInsertWP_mt, cursor)
CpBrushInsertWP = CpObject(CpBrush)
function CpBrushInsertWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsSecondaryButton = true
return self
end

function CpBrushInsertWP:onButtonPrimary()
Expand Down
11 changes: 4 additions & 7 deletions scripts/editor/brushes/basic/MoveWaypoint.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@

--- Moves a new waypoint at the mouse position.
---@class CpBrushMoveWP : CpBrush
CpBrushMoveWP = {
DELAY = 100
}
local CpBrushMoveWP_mt = Class(CpBrushMoveWP, CpBrush)
function CpBrushMoveWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushMoveWP_mt, cursor)
CpBrushMoveWP = CpObject(CpBrush)
CpBrushMoveWP.DELAY = 100
function CpBrushMoveWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.delay = g_time
return self
end

function CpBrushMoveWP:onButtonPrimary(isDown, isDrag, isUp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

--- Changes a new waypoint at the mouse position.
---@class CpBrushChangeConnectingPathWP : CpBrush
CpBrushChangeConnectingPathWP = {}
local CpBrushChangeWP_mt = Class(CpBrushChangeConnectingPathWP, CpBrush)
function CpBrushChangeConnectingPathWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushChangeWP_mt, cursor)
CpBrushChangeConnectingPathWP = CpObject(CpBrush)
function CpBrushChangeConnectingPathWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.supportsSecondaryButton = true
self.supportsSecondaryDragging = true
return self
end

function CpBrushChangeConnectingPathWP:onButtonPrimary()
Expand Down
18 changes: 7 additions & 11 deletions scripts/editor/brushes/changeAttributes/ChangeHeadlandWaypoint.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@

--- Changes a new waypoint at the mouse position.
---@class CpBrushChangeHeadlandWP : CpBrush
CpBrushChangeHeadlandWP = {
MAX_HEADLANDS = 40,
NO_HEADLANDS = 0,
TRANSLATIONS = {
NO_HEADLAND = "noHeadland"
}
}
local CpBrushChangeWP_mt = Class(CpBrushChangeHeadlandWP, CpBrush)
function CpBrushChangeHeadlandWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushChangeWP_mt, cursor)
CpBrushChangeHeadlandWP = CpObject(CpBrush)
CpBrushChangeHeadlandWP.MAX_HEADLANDS = 40
CpBrushChangeHeadlandWP.NO_HEADLANDS = 0
CpBrushChangeHeadlandWP.TRANSLATIONS = {
NO_HEADLAND = "noHeadland"}
function CpBrushChangeHeadlandWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.supportsSecondaryButton = true
self.supportsPrimaryAxis = true
self.mode = self.NO_HEADLANDS
return self
end

function CpBrushChangeHeadlandWP:onButtonPrimary()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@

--- Changes a new waypoint at the mouse position.
---@class CpBrushChangeRowNumberWP : CpBrush
CpBrushChangeRowNumberWP = {
NO_ROW = 0,
TRANSLATIONS = {
NO_ROW = "noRow"
}
}
local CpBrushChangeWP_mt = Class(CpBrushChangeRowNumberWP, CpBrush)
function CpBrushChangeRowNumberWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushChangeWP_mt, cursor)
CpBrushChangeRowNumberWP = CpObject(CpBrush)
CpBrushChangeRowNumberWP.NO_ROW = 0
CpBrushChangeRowNumberWP.TRANSLATIONS = {
NO_ROW = "noRow"}
function CpBrushChangeRowNumberWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
self.supportsPrimaryDragging = true
self.supportsSecondaryButton = true
self.supportsPrimaryAxis = true
self.mode = 0
return self
end

function CpBrushChangeRowNumberWP:onButtonPrimary()
Expand Down
19 changes: 8 additions & 11 deletions scripts/editor/brushes/changeAttributes/ChangeTurnWaypoint.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@

--- Changes a new waypoint at the mouse position.
---@class CpBrushChangeTurnWP : CpBrush
CpBrushChangeTurnWP = {
TYPES = {
NORMAL = 1,
TURN_START = 2,
TURN_END = 3
},
CpBrushChangeTurnWP = CpObject(CpBrush)
CpBrushChangeTurnWP.TYPES = {
NORMAL = 1,
TURN_START = 2,
TURN_END = 3
}

CpBrushChangeTurnWP.TYPES_TRANSLATIONS = {
[CpBrushChangeTurnWP.TYPES.NORMAL] = "type_normal",
[CpBrushChangeTurnWP.TYPES.TURN_START] = "type_turnStart",
[CpBrushChangeTurnWP.TYPES.TURN_END] = "type_turnEnd",
}

local CpBrushChangeWP_mt = Class(CpBrushChangeTurnWP, CpBrush)
function CpBrushChangeTurnWP.new(customMt, cursor)
local self = CpBrush.new(customMt or CpBrushChangeWP_mt, cursor)
function CpBrushChangeTurnWP:init(cursor, editor)
CpBrush.init(self, cursor, editor)
self.supportsPrimaryButton = true
return self
end

function CpBrushChangeTurnWP:onButtonPrimary()
Expand Down
3 changes: 1 addition & 2 deletions scripts/gui/pages/CpConstructionFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function CpConstructionFrame:loadBrushCategory()
iconSliceId = xmlFile:getValue(brushKey .. "#iconSliceId"),
isCourseOnly = xmlFile:getValue(brushKey .. "#isCourseOnly"),
brushParameters = {
g_courseEditor,
CourseEditor.TRANSLATION_PREFIX .. tab.name .. "_" .. name
}
}
Expand Down Expand Up @@ -484,7 +483,7 @@ end
function CpConstructionFrame:onClickItem(list, section, index, cell)
local item = self.brushCategory[self.subCategorySelector:getState()].brushes[index]
local class = CpUtil.getClassObject(item.class)
local brush = class.new(nil, self.cursor)
local brush = class(self.cursor, g_courseEditor)
if item.brushParameters ~= nil then
brush:setStoreItem(item.storeItem)
brush:setParameters(unpack(item.brushParameters))
Expand Down

0 comments on commit e172cd4

Please sign in to comment.