diff --git a/src/Classes/ConfigAddCustomMod.lua b/src/Classes/ConfigAddCustomMod.lua new file mode 100644 index 0000000000..0f77e9068b --- /dev/null +++ b/src/Classes/ConfigAddCustomMod.lua @@ -0,0 +1,76 @@ +-- Path of Building +-- +-- Class: Config Set List +-- Config Set list control +-- +local t_insert = table.insert +local t_remove = table.remove +local m_max = math.max + +local ConfigAddCustomModClass = newClass("ConfigAddCustomMod", "ListControl", function(self, anchor, rect, configTab) + + local mods = {} + + -- format keys to allow for collisions and subsequent removal + local replacements = {"x", "y", "z", "w", "v"} + for key, _ in pairs(modLib.parseModCache) do + local strKey = tostring(key) + if strKey ~= "" then + local idx = 0 + -- replace ranges, decimals, dice numbers + local cleanKey = strKey:gsub("(%d+[%d%.d%-]*)", function() + idx = idx + 1 + return replacements[idx] or "{value}" + end) + -- remove parentheses that are left around single placeholders + cleanKey = cleanKey:gsub("%((%w+)%)", "%1") + mods[cleanKey] = {} + end + end + + -- convert keys to sequential array for ListControl + self.modStrings = {} + for k in pairs(mods) do + t_insert(self.modStrings, k) + end + table.sort(self.modStrings) + local keys = {} + for key, _ in pairs(mods) do + if keys[key] then + -- remove duplicate + mods[key] = nil + else + keys[key] = true + end + end + keys = nil + self.selValue = self.modStrings[1] + + self.controls = self.controls or {} + self.ListControl(anchor, rect, 16, "VERTICAL", true, self.modStrings) + self.configTab = configTab +end) + +function ConfigAddCustomModClass:OnSelClick(selIndex, selValue, doubleClick) + -- do whatever you want immediately when selection changes + print("New selection:", selValue) +end + +function ConfigAddCustomModClass:GetRowValue(column, index, modId) + local modStr = self.modStrings[index] or "Unknown Mod" + if column == 1 then + return modStr + end +end + +function ConfigAddCustomModClass:OnOrderChange() + self.configTab.modFlag = true +end + + + +function ConfigAddCustomModClass:OnSelKeyDown(index, configSetId, key) + if key == "F2" then + self:RenameSet(self.configTab.configSets[configSetId]) + end +end diff --git a/src/Classes/ConfigTab.lua b/src/Classes/ConfigTab.lua index 6c229be4dc..8863c35bc3 100644 --- a/src/Classes/ConfigTab.lua +++ b/src/Classes/ConfigTab.lua @@ -25,7 +25,9 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont -- Initialise config sets self.configSets = { } self.configSetOrderList = { 1 } + self.configAddCustomMod = { 2 } self:NewConfigSet(1) + self:NewConfigSet(2) self:SetActiveConfigSet(1, true) self.enemyLevel = 1 @@ -37,7 +39,7 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont self.controls.sectionAnchor = new("LabelControl", { "TOPLEFT", self, "TOPLEFT" }, { 0, 20, 0, 0 }, "") - -- Set selector + -- SetOrderList self.controls.setSelect = new("DropDownControl", { "TOPLEFT", self.controls.sectionAnchor, "TOPLEFT" }, { 76, -12, 210, 20 }, nil, function(index, value) self:SetActiveConfigSet(self.configSetOrderList[index]) self:AddUndoState() @@ -51,6 +53,20 @@ local ConfigTabClass = newClass("ConfigTab", "UndoHandler", "ControlHost", "Cont self:OpenConfigSetManagePopup() end) + -- AddCustomMod + self.controls.setSelect = new("DropDownControl", { "TOPLEFT", self.controls.sectionAnchor, "TOPLEFT" }, { 76, -12, 250, 20 }, nil, function(index, value) + self:SetActiveConfigSet(self.configAddCustomMod[index]) + self:AddUndoState() + end) + self.controls.setSelect.enableDroppedWidth = true + self.controls.setSelect.enabled = function() + return #self.configAddCustomMod > 1 + end + + self.controls.addCustomMod = new("ButtonControl", { "LEFT", self.controls.setSelect, "RIGHT" }, { 100, 0, 90, 20 }, "Add custom mod...", function() + self:OpenAddCustomModPopup() + end) + self.controls.search = new("EditControl", { "TOPLEFT", self.controls.sectionAnchor, "TOPLEFT" }, { 8, 15, 360, 20 }, "", "Search", "%c", 100, function() self:UpdateControls() end, nil, nil, true) @@ -955,6 +971,31 @@ function ConfigTabClass:OpenConfigSetManagePopup() }) end +function ConfigTabClass:OpenAddCustomModPopup() + local addCustomModCtrl = new("ConfigAddCustomMod", nil, {0, 50, 350, 200}, self) + main:OpenPopup(370, 290, "Add custom mod", { + addCustomModCtrl, + new("ButtonControl", nil, {0, 20, 90, 20}, "Add", function() + local selected = addCustomModCtrl.selValue + local modList = new("ModList") + local enemyModList = new("ModList") + local currentText = self.input.customMods + -- append the new selection + local newText = currentText .. (currentText ~= "" and "\n" or "") .. addCustomModCtrl.selValue + -- set the text box with the updated string + self.input.customMods = newText + self:BuildModList() + self.build.buildFlag = true + self:UpdateControls() + + end), + new("ButtonControl", nil, {0, 260, 90, 20}, "Done", function() + main:ClosePopup() + end), + }) +end + + -- Creates a new config set function ConfigTabClass:NewConfigSet(configSetId, title) local configSet = { id = configSetId, title = title, input = { }, placeholder = { } } diff --git a/src/Classes/ItemsTab.lua b/src/Classes/ItemsTab.lua index 2017698929..593baa3954 100644 --- a/src/Classes/ItemsTab.lua +++ b/src/Classes/ItemsTab.lua @@ -216,6 +216,7 @@ local ItemsTabClass = newClass("ItemsTab", "UndoHandler", "ControlHost", "Contro self.controls.itemList = new("ItemListControl", {"TOPRIGHT",self.lastSlot,"BOTTOMRIGHT"}, {0, 0, 360, 308}, self, true) else self.controls.itemList = new("ItemListControl", {"TOPLEFT",self.controls.setManage,"TOPRIGHT"}, {20, 20, 360, 308}, self, true) + self.controls.itemList = new("ItemListControl", {"TOPLEFT",self.controls.setManage,"TOPRIGHT"}, {20, 20, 360, 308}, self, true) end -- Database selector