Skip to content

Commit 780bac6

Browse files
committed
Ctrl+f to jump to dat search box
1 parent 4f86ea4 commit 780bac6

1 file changed

Lines changed: 84 additions & 2 deletions

File tree

src/Export/Main.lua

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,47 @@ function main:Init()
274274
self.controls.colRefTo = new("EditControl", {"TOPLEFT",self.controls.colType,"BOTTOMLEFT"}, {0, 26, 150, 18}, nil, nil, nil, nil, function(buf)
275275
self.curSpecCol.refTo = buf
276276
self.curDatFile:OnSpecChanged()
277+
local refFile = self.datFileByName[buf:lower()]
278+
if refFile and refFile.spec and self.controls.colRefCol then
279+
local colNames = {}
280+
for _, specCol in ipairs(refFile.spec) do
281+
t_insert(colNames, (specCol.name and specCol.name ~= "") and specCol.name or "???")
282+
end
283+
self.controls.colRefCol.list = colNames
284+
local selectedIndex = tonumber(self.curSpecCol.refColIndex) or 1
285+
if selectedIndex < 1 or selectedIndex > #colNames then
286+
selectedIndex = 1
287+
end
288+
self.controls.colRefCol.selIndex = selectedIndex
289+
self.curSpecCol.refColIndex = selectedIndex
290+
self.controls.colRefCol.enabled = true
291+
else
292+
-- Clear and DISABLE dropdown if invalid ref or no spec
293+
self.controls.colRefCol.list = {}
294+
self.controls.colRefCol.selIndex = nil
295+
self.controls.colRefCol.enabled = false
296+
end
277297
end) {
278298
tooltipFunc = function(tooltip)
279299
tooltip:Clear()
280-
tooltip:AddLine(16, "^7Reference to another dat file")
300+
tooltip:AddLine(16, "^7Which .dat file this column references for additional data")
281301
end
282302
}
283303

284-
self.controls.colWidth = new("EditControl", {"TOPLEFT",self.controls.colRefTo,"BOTTOMLEFT"}, {0, 4, 100, 18}, nil, nil, "%D", nil, function(buf)
304+
self.controls.colRefCol = new("DropDownControl", {"TOPLEFT",self.controls.colRefTo,"BOTTOMLEFT"}, {0, 4, 150, 18}, {}, function(index, _)
305+
if self.curSpecCol then
306+
self.curSpecCol.refColIndex = index
307+
self.curDatFile:OnSpecChanged()
308+
end
309+
end) {
310+
tooltipFunc = function(tooltip)
311+
tooltip:Clear()
312+
tooltip:AddLine(16, "^7Which column to use from the referenced .dat file")
313+
end,
314+
enabled = false -- start disabled until a valid ref is set
315+
}
316+
317+
self.controls.colWidth = new("EditControl", {"TOPLEFT",self.controls.colRefCol,"BOTTOMLEFT"}, {0, 4, 100, 18}, nil, nil, "%D", nil, function(buf)
285318
self.curSpecCol.width = m_max(tonumber(buf) or 150, 20)
286319
self.controls.rowList:BuildColumns()
287320
end) {
@@ -526,6 +559,42 @@ function main:SetCurrentCol(index)
526559
end
527560
end
528561

562+
function main:PopulateRefColDropdown()
563+
local col = self.curDatFile.cols[self.curSpecColIndex]
564+
local specCol = self.curSpecCol
565+
566+
if col and col.isRef and specCol and specCol.refTo then
567+
local refFile = self.datFileByName[specCol.refTo:lower()]
568+
if refFile and refFile.spec and self.controls.colRefCol then
569+
local colNames = {}
570+
for _, refSpec in ipairs(refFile.spec) do
571+
t_insert(colNames, (refSpec.name and refSpec.name ~= "") and refSpec.name or "???")
572+
end
573+
574+
self.controls.colRefCol.list = colNames
575+
576+
-- Ensure refColIndex is a valid number within range
577+
local selectedIndex = tonumber(specCol.refColIndex) or 1
578+
if selectedIndex < 1 or selectedIndex > #colNames then
579+
selectedIndex = 1
580+
end
581+
582+
self.controls.colRefCol.selIndex = selectedIndex
583+
specCol.refColIndex = selectedIndex -- save it back just in case
584+
585+
self.controls.colRefCol.enabled = true
586+
return
587+
end
588+
end
589+
590+
-- Fallback: disable and clear dropdown
591+
if self.controls.colRefCol then
592+
self.controls.colRefCol.list = {}
593+
self.controls.colRefCol.selIndex = nil
594+
self.controls.colRefCol.enabled = false
595+
end
596+
end
597+
529598
function main:UpdateCol()
530599
self.controls.colName:SetText(self.curSpecCol.name)
531600
self.controls.colType:SelByValue(self.curSpecCol.type)
@@ -535,6 +604,8 @@ function main:UpdateCol()
535604
self.controls.colWidth:SetText(self.curSpecCol.width)
536605
self.controls.enumBase:SetText(self.curSpecCol.enumBase or 0)
537606
self.controls.rowList:BuildColumns()
607+
-- Populate refCol dropdown on UI update
608+
self:PopulateRefColDropdown()
538609
end
539610

540611
function main:LoadSettings()
@@ -591,6 +662,17 @@ function main:SaveSettings()
591662
end
592663
end
593664

665+
function main:OnKeyDown(key, doubleClick)
666+
-- Ctrl+F shortcut for focusing dat file Search
667+
if key == "f" and IsKeyDown("CTRL") then
668+
if self.controls and self.controls.datSearch and self.SelectControl then
669+
self:SelectControl(self.controls.datSearch)
670+
end
671+
return
672+
end
673+
t_insert(self.inputEvents, { type = "KeyDown", key = key, doubleClick = doubleClick })
674+
end
675+
594676
function main:DrawArrow(x, y, width, height, dir)
595677
local x1 = x - width / 2
596678
local x2 = x + width / 2

0 commit comments

Comments
 (0)