diff --git a/lua/CORE.lua b/lua/CORE.lua index 7f53e6a..0f3ec89 100644 --- a/lua/CORE.lua +++ b/lua/CORE.lua @@ -54,6 +54,15 @@ function CRT.Info_Research(craft_type,id_craft) CRT.SV.data.Craft[CRT.playername][id_craft]["Simu_craft"] = Simu_craft end +function CRT.Char_sort() -- Produce a sorted list for display + CRT.CharsInOrder = {} + for k, _ in pairs(CRT.SV.data.Craft) do + table.insert(CRT.CharsInOrder,k) + end + if CRT.SortFunction ~= nil then + table.sort(CRT.CharsInOrder, CRT.SortFunction) + end +end function CRT.Research_started() -- erase all data for this character @@ -64,4 +73,5 @@ function CRT.Research_started() if (CRT.UI.GRID_WD[CRT.playername] == nil) then CRT.GRID_Create_Character(CRT.playername) end + CRT.Char_sort() end \ No newline at end of file diff --git a/lua/CraftResearchTimer.lua b/lua/CraftResearchTimer.lua index e9afadc..c49ffa7 100644 --- a/lua/CraftResearchTimer.lua +++ b/lua/CraftResearchTimer.lua @@ -2,6 +2,16 @@ -- v0.4.11 +--sorting functions for grid. Arguments are character names +local function SortAlphaD (a,b) return a>b + end + +local function SortAlphaA (a,b) return a<b +end + +local function SortTimeA (a,b) + return CRT.SV.data.Craft[a].shortest < CRT.SV.data.Craft[b].shortest +end function CRT.Init(eventCode, addOnName) @@ -19,6 +29,10 @@ function CRT.Init(eventCode, addOnName) -- Slash commands SLASH_COMMANDS[CRT.cmdsetup] = CRT.CommandText_setup + + -- Default sort + CRT.SortFunction = SortTimeA + -- Create Keybinds ZO_CreateStringId("SI_BINDING_NAME_CRT_ToggleUI", "|c96FF00Toggle craft windows|r") @@ -343,15 +357,6 @@ function BufferWait(BufferName, WaitTime) end end - -EVENT_MANAGER:RegisterForEvent(CRT.name, EVENT_ADD_ON_LOADED, CRT.Init) - ---EVENT_MANAGER:RegisterForEvent(CRT.name, EVENT_MAIL_OPEN_MAILBOX, CRT_Force_read) ---EVENT_MANAGER:RegisterForEvent(CRT.name, EVENT_MAIL_NUM_UNREAD_CHANGED, CRT_mail_check) - - - - function CRT.ToggleUI() if (CRT.SV.Settings.BS.craft == true and CRT.SV.Settings.BS.Hide_Type == "Toggle keybind") then if (CRT.UI.CRAFT_TLW[0]:IsHidden() == true) then @@ -467,20 +472,6 @@ function CRT.Converthms(timesec) end - function pairsByKeys (t, f) - local a = {} - for n in pairs(t) do table.insert(a, n) end - table.sort(a, f) - local i = 0 -- iterator variable - local iter = function () -- iterator function - i = i + 1 - if a[i] == nil then return nil - else return a[i], t[a[i]] - end - end - return iter - end - function CRT.Save_position(id_craft) if (id_craft == 0) then @@ -517,3 +508,6 @@ function CRT.CommandText_setup(lparam) end end +EVENT_MANAGER:RegisterForEvent(CRT.name, EVENT_ADD_ON_LOADED, CRT.Init) + + diff --git a/lua/GRID.lua b/lua/GRID.lua index d6e50a9..ff84e69 100644 --- a/lua/GRID.lua +++ b/lua/GRID.lua @@ -2,9 +2,10 @@ -- v0.4.8 local num_char --track character number drawing for, for positioning +local k,v function CRT.GRID_Create() - local k + -- Fenetre de base CRT.UI.GRID_TLW= WINDOW_MANAGER:CreateTopLevelWindow("CRT_GRID_TLW") CRT.UI.GRID_TLW:SetHidden(CRT.SV.Settings.GRID.hidden) @@ -31,13 +32,16 @@ function CRT.GRID_Create() CRT.UI.GRID_BTN:SetMouseOverTexture("/esoui/art/buttons/decline_up.dds") CRT.UI.GRID_BTN:SetHandler( "OnClicked" , function(self) CRT.UI.GRID_TLW:SetHidden(true); CRT.SV.Settings.GRID.hidden = true end ) - - for k, _ in pairs(CRT.SV.data.Craft) do - CRT.GRID_Create_Character(k) + CRT.Char_sort() + + for _, v in ipairs(CRT.CharsInOrder) do + CRT.GRID_Create_Character(v) end end function CRT.GRID_Create_Character(k) + local x, y + if (num_char == nil) then num_char = 0 end @@ -47,7 +51,7 @@ function CRT.GRID_Create_Character(k) CRT.UI.GRID_TLW:SetHidden(CRT.SV.Settings.GRID.hidden) - -- pseudo + -- label for chracter name CRT.UI.GRID_WD[k] = {} CRT.UI.GRID_WD[k][k] = WINDOW_MANAGER:CreateControl("CRT_GRID_"..k.."_"..k,CRT.UI.GRID_TLW,CT_LABEL) --CRT.UI.GRID_WD[k][k]:SetHidden(false) @@ -64,8 +68,9 @@ function CRT.GRID_Create_Character(k) y = 20 else x = 0 - y = 20+num_char*120 + y = 20+num_char*120 -- tab down 120 end + -- Create section headers with dummy text for each skill --blacksmithing CRT.UI.GRID_WD[k][0] = {} CRT.UI.GRID_WD[k][0][0] = {} @@ -227,4 +232,7 @@ function CRT.GRID_Update(timestamp) end end end -end \ No newline at end of file +end + + + \ No newline at end of file diff --git a/lua/Menu-function.lua b/lua/Menu-function.lua index 0f3c471..426df92 100644 --- a/lua/Menu-function.lua +++ b/lua/Menu-function.lua @@ -18,12 +18,12 @@ function CRT.SetLock(Newlock) end function CRT.SetMode(NewMode) -CRT.SV.Settings.mode = NewMode + CRT.SV.Settings.mode = NewMode ReloadUI() end function CRT.Settimer_format(Newtimer_format) -CRT.SV.Settings.timer_format = Newtimer_format + CRT.SV.Settings.timer_format = Newtimer_format end function CRT.Gettimer_format() @@ -171,7 +171,7 @@ function CRT.SetBSScale(NewBSScalePercent) end function CRT.GetBSColor() -return CRT.SV.Settings.BS.Color.r, CRT.SV.Settings.BS.Color.g, CRT.SV.Settings.BS.Color.b, CRT.SV.Settings.BS.Color.a + return CRT.SV.Settings.BS.Color.r, CRT.SV.Settings.BS.Color.g, CRT.SV.Settings.BS.Color.b, CRT.SV.Settings.BS.Color.a end function CRT.SetBSColor(r, g, b, a) @@ -182,10 +182,10 @@ function CRT.SetBSColor(r, g, b, a) end end -CRT.SV.Settings.BS.Color.r = r -CRT.SV.Settings.BS.Color.g = g -CRT.SV.Settings.BS.Color.b = b -CRT.SV.Settings.BS.Color.a = a + CRT.SV.Settings.BS.Color.r = r + CRT.SV.Settings.BS.Color.g = g + CRT.SV.Settings.BS.Color.b = b + CRT.SV.Settings.BS.Color.a = a end @@ -256,10 +256,10 @@ function CRT.SetCLColor(r, g, b, a) end end -CRT.SV.Settings.CL.Color.r = r -CRT.SV.Settings.CL.Color.g = g -CRT.SV.Settings.CL.Color.b = b -CRT.SV.Settings.CL.Color.a = a + CRT.SV.Settings.CL.Color.r = r + CRT.SV.Settings.CL.Color.g = g + CRT.SV.Settings.CL.Color.b = b + CRT.SV.Settings.CL.Color.a = a end -------------------------Woodworking Components--------------------------------------- @@ -319,7 +319,7 @@ function CRT.SetWOScale(NewWOScalePercent) end function CRT.GetWOColor() -return CRT.SV.Settings.WO.Color.r, CRT.SV.Settings.WO.Color.g, CRT.SV.Settings.WO.Color.b, CRT.SV.Settings.WO.Color.a + return CRT.SV.Settings.WO.Color.r, CRT.SV.Settings.WO.Color.g, CRT.SV.Settings.WO.Color.b, CRT.SV.Settings.WO.Color.a end function CRT.SetWOColor(r, g, b, a) @@ -330,10 +330,10 @@ function CRT.SetWOColor(r, g, b, a) end end -CRT.SV.Settings.WO.Color.r = r -CRT.SV.Settings.WO.Color.g = g -CRT.SV.Settings.WO.Color.b = b -CRT.SV.Settings.WO.Color.a = a + CRT.SV.Settings.WO.Color.r = r + CRT.SV.Settings.WO.Color.g = g + CRT.SV.Settings.WO.Color.b = b + CRT.SV.Settings.WO.Color.a = a end function CRT.Reset()