Skip to content
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
66 changes: 62 additions & 4 deletions src/Classes/BuildListControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ local ipairs = ipairs
local s_format = string.format
local buildListHelpers = require("Modules.BuildListHelpers")

---@class BuildListControl: ListControl
---@class BuildListEntry
---@field subPath string
---@field fullFileName string
---@field fileName? string
---@field folderName? string
---@field buildName? string
---@field className? string
---@field ascendClassName? string
---@field level? integer

---@class BuildListMode: ControlHost
---@field subPath string
---@field list BuildListEntry[]
---@field BuildList fun(self: BuildListMode)

---@class BuildListControl: ListControl<BuildListEntry>
---@field listMode BuildListMode
local BuildListClass = newClass("BuildListControl", "ListControl")

---@param anchor Anchor?
---@param rect Rect?
---@param listMode any
---@param anchor? Anchor
---@param rect? Rect
---@param listMode BuildListMode
---@return BuildListControl
function BuildListClass:BuildListControl(anchor, rect, listMode)
self:ListControl(anchor, rect, 20, "VERTICAL", false, listMode.list)
self.listMode = listMode
Expand All @@ -30,9 +47,15 @@ function BuildListClass:BuildListControl(anchor, rect, listMode)
self.selDragActive = false
self.otherDragSource = false
end)
---@param type string
---@param build BuildListEntry
---@return boolean
function self.controls.path:CanReceiveDrag(type, build)
return type == "Build" and #self.folderList > 1
end
---@param type string
---@param build BuildListEntry
---@param source ListControl<unknown>
function self.controls.path:ReceiveDrag(type, build, source)
if type == "Build" then
for index, folder in ipairs(self.folderList) do
Expand Down Expand Up @@ -62,6 +85,7 @@ function BuildListClass:BuildListControl(anchor, rect, listMode)
return self
end

---@param fullFileName string
function BuildListClass:SelByFullFileName(fullFileName)
if fullFileName then
for index, build in ipairs(self.list) do
Expand All @@ -75,6 +99,7 @@ function BuildListClass:SelByFullFileName(fullFileName)
self.selValue = nil
end

---@param build BuildListEntry
function BuildListClass:LoadBuild(build)
if build.folderName then
self.controls.path:SetSubPath(build.subPath .. build.folderName .. "/")
Expand All @@ -92,6 +117,8 @@ function BuildListClass:NewFolder()
end)
end

---@param build BuildListEntry
---@param copyOnName? boolean
function BuildListClass:RenameBuild(build, copyOnName)
local controls = { }
controls.label = new("LabelControl"):LabelControl(nil, {0, 20, 0, 16}, "^7Enter the new name for this "..(build.folderName and "folder:" or "build:"))
Expand Down Expand Up @@ -159,6 +186,7 @@ function BuildListClass:RenameBuild(build, copyOnName)
main:OpenPopup(370, 100, (copyOnName and "Copy " or "Rename ")..(build.folderName and "Folder" or "Build"), controls, "save", "edit")
end

---@param build BuildListEntry
function BuildListClass:DeleteBuild(build)
if build.folderName then
if NewFileSearch(build.fullFileName.."/*") or NewFileSearch(build.fullFileName.."/*", true) then
Expand Down Expand Up @@ -188,6 +216,10 @@ function BuildListClass:DeleteBuild(build)
end
end

---@param column integer
---@param index integer
---@param build BuildListEntry
---@return string?
function BuildListClass:GetRowValue(column, index, build)
if column == 1 then
local label
Expand Down Expand Up @@ -223,14 +255,24 @@ function BuildListClass:GetRowValue(column, index, build)
end
end

---@param index integer
---@param build BuildListEntry
---@return string
---@return BuildListEntry
function BuildListClass:GetDragValue(index, build)
return "Build", build
end

---@param type string
---@param build BuildListEntry
---@return boolean
function BuildListClass:CanReceiveDrag(type, build)
return type == "Build"
end

---@param type string
---@param build BuildListEntry
---@param source? ListControl<unknown>
function BuildListClass:ReceiveDrag(type, build, source)
if type == "Build" then
if self.hoverValue and self.hoverValue.folderName then
Expand All @@ -252,10 +294,17 @@ function BuildListClass:ReceiveDrag(type, build, source)
end
end

---@param index integer
---@param build BuildListEntry
---@param source? ListControl<unknown>
---@return boolean
function BuildListClass:CanDragToValue(index, build, source)
return build.folderName and source.selValue ~= build and buildListHelpers.CanMoveToSubPath(source.selValue, build.subPath .. build.folderName .. "/")
end

---@param index integer
---@param build BuildListEntry
---@param doubleClick? boolean
function BuildListClass:OnSelClick(index, build, doubleClick)
if doubleClick then
self:LoadBuild(build)
Expand All @@ -264,20 +313,29 @@ function BuildListClass:OnSelClick(index, build, doubleClick)
end
end

---@param index integer
---@param build BuildListEntry
function BuildListClass:OnSelCopy(index, build)
self.copyBuild = build
self.cutBuild = nil
end

---@param index integer
---@param build BuildListEntry
function BuildListClass:OnSelCut(index, build)
self.copyBuild = nil
self.cutBuild = build
end

---@param index integer
---@param build BuildListEntry
function BuildListClass:OnSelDelete(index, build)
self:DeleteBuild(build)
end

---@param index integer
---@param build BuildListEntry
---@param key string
function BuildListClass:OnSelKeyDown(index, build, key)
if key == "RETURN" then
self:LoadBuild(build)
Expand Down
24 changes: 24 additions & 0 deletions src/Classes/ButtonControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@
-- Basic button control.
--
---@class ButtonControl: Control, TooltipHost
---@field label Prop<string>
---@field onClick fun(): Control?
---@field onHover? fun(): Control?
---@field forceTooltip? boolean
---@field image? ImageHandle
---@field clicked? boolean
---@field locked? Prop<boolean>
---@field enterFunc? fun()
local ButtonClass = newClass("ButtonControl", "Control", "TooltipHost")

---@param anchor? Anchor
---@param rect? Rect
---@param label Prop<string>
---@param onClick fun(): Control?
---@param onHover? fun(): Control?
---@param forceTooltip? boolean
---@return ButtonControl
function ButtonClass:ButtonControl(anchor, rect, label, onClick, onHover, forceTooltip)
self:Control(anchor, rect)
self:TooltipHost()
Expand All @@ -22,6 +37,7 @@ function ButtonClass:Click()
end
end

---@param path? string
function ButtonClass:SetImage(path)
if path then
self.image = NewImageHandle()
Expand All @@ -31,13 +47,17 @@ function ButtonClass:SetImage(path)
end
end

---@return boolean
function ButtonClass:IsMouseOver()
if not self:IsShown() then
return false
end
return self:IsMouseInBounds()
end

---@param viewPort Viewport
---@param noTooltip? boolean
---@return Control?
function ButtonClass:Draw(viewPort, noTooltip)
local x, y = self:GetPos()
local width, height = self:GetSize()
Expand Down Expand Up @@ -104,6 +124,8 @@ function ButtonClass:Draw(viewPort, noTooltip)
end
end

---@param key string
---@return ButtonControl?
function ButtonClass:OnKeyDown(key)
if not self:IsShown() or not self:IsEnabled() then
return
Expand All @@ -116,6 +138,8 @@ function ButtonClass:OnKeyDown(key)
return self
end

---@param key string
---@return Control?
function ButtonClass:OnKeyUp(key)
if not self:IsShown() or not self:IsEnabled() then
return
Expand Down
Loading