diff --git a/.gitignore b/.gitignore index ec27d68..459d8a7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ /out *.iml #VS Code -/.vscode \ No newline at end of file +/.vscode + +#Custom +/dev diff --git a/Clock.lua b/Clock.lua index bb8b3df..1971722 100644 --- a/Clock.lua +++ b/Clock.lua @@ -3,7 +3,7 @@ ------------------------------------------- cl = {} -cl.VERSION = "0.7.5" +cl.VERSION = "0.7.6" cl.SAV_VERSION = 0.7 cl.LAM = LibStub:GetLibrary("LibAddonMenu-2.0") diff --git a/Clock.txt b/Clock.txt index d15009e..8e532d9 100644 --- a/Clock.txt +++ b/Clock.txt @@ -12,10 +12,10 @@ ## Manifest ## ################################### -## Title: Clock |cFFA4000.7.5|r +## Title: Clock |cFFA4000.7.6|r ## Description: Adds a fully customizable notice about time and date in Tamriel and Earth. ## Author: |c0080ffTyx|r -## Version 0.7.5 +## Version 0.7.6 ## APIVersion: 100017 ## SavedVariables: Clock_Settings ## OptionalDependsOn: LibAddonMenu-2.0 @@ -26,22 +26,23 @@ ## Source: http://www.esoui.com/downloads/info7-LibAddonMenu.html ## Source_Author: sirinsidiator, Seerah -## Source_Version: 2.0 r20 +## Source_Version: 2.0 r23 libs\LibStub\LibStub.lua libs\LibAddonMenu-2.0\LibAddonMenu-2.0.lua -libs\LibAddonMenu-2.0\controls\panel.lua -libs\LibAddonMenu-2.0\controls\submenu.lua libs\LibAddonMenu-2.0\controls\button.lua libs\LibAddonMenu-2.0\controls\checkbox.lua libs\LibAddonMenu-2.0\controls\colorpicker.lua libs\LibAddonMenu-2.0\controls\custom.lua libs\LibAddonMenu-2.0\controls\description.lua +libs\LibAddonMenu-2.0\controls\divider.lua libs\LibAddonMenu-2.0\controls\dropdown.lua libs\LibAddonMenu-2.0\controls\editbox.lua libs\LibAddonMenu-2.0\controls\header.lua +libs\LibAddonMenu-2.0\controls\iconpicker.lua +libs\LibAddonMenu-2.0\controls\panel.lua libs\LibAddonMenu-2.0\controls\slider.lua +libs\LibAddonMenu-2.0\controls\submenu.lua libs\LibAddonMenu-2.0\controls\texture.lua -libs\LibAddonMenu-2.0\controls\iconpicker.lua ## Source: http://www.esoui.com/downloads/info56-LibMediaProvider.html ## Source_Author: Garkin, Seerah diff --git a/data/gui.lua b/data/gui.lua index 69a556e..072d070 100644 --- a/data/gui.lua +++ b/data/gui.lua @@ -104,20 +104,27 @@ local function AddToggle() }, [8] = { type = "checkbox", + name = loc.sJap, + getFunc = function() return cl.st.ShowJap() end, + setFunc = function(value) cl.st.SetShowJap(value) end, + disabled = function() return not cl.st.IsUSTime() or not cl.st.IsActive() end, + }, + [9] = { + type = "checkbox", name = loc.sNum, tooltip = loc.tNum, getFunc = function() return cl.st.ShowNum() end, setFunc = function(value) cl.st.SetShowNum(value) end, disabled = function() return not cl.st.IsActive() end, }, - [9] = { + [10] = { type = "checkbox", name = loc.sSec, getFunc = function() return cl.st.ShowSec() end, setFunc = function(value) cl.st.SetShowSec(value) end, disabled = function() return not cl.st.IsActive() end, }, - [10] = { + [11] = { type = "checkbox", name = loc.sMoon, tooltip = loc.tMoon, @@ -125,7 +132,7 @@ local function AddToggle() setFunc = function(value) cl.st.SetShowMoon(value) end, disabled = function() return not cl.st.IsActive() end, }, - [11] = { + [12] = { type = "checkbox", name = loc.sLDate, tooltip = loc.tLDate, @@ -138,7 +145,7 @@ local function AddToggle() end, disabled = function() return not cl.st.IsActive() end, }, - [12] = { + [13] = { type = "checkbox", name = loc.sFLDate, tooltip = loc.tFLDate, @@ -151,7 +158,7 @@ local function AddToggle() end, disabled = function() return not cl.st.IsActive() end, }, - [13] = { + [14] = { type = "checkbox", name = loc.sRT, tooltip = loc.tRT, @@ -159,7 +166,7 @@ local function AddToggle() setFunc = function(value) cl.st.SetShowRT(value) end, disabled = function() return not cl.st.IsActive() end, }, - [14] = { + [15] = { type = "checkbox", name = loc.sDate, tooltip = loc.tDate, @@ -167,7 +174,7 @@ local function AddToggle() setFunc = function(value) cl.st.SetShowDate(value) end, disabled = function() return not cl.st.IsActive() end, }, - [15] = { + [16] = { type = "checkbox", name = loc.sHor, tooltip = loc.tHor, diff --git a/data/settings.lua b/data/settings.lua index a5842a4..f6d5056 100644 --- a/data/settings.lua +++ b/data/settings.lua @@ -15,6 +15,7 @@ local defaults = { auto_hide = true, us_time = false, show_us = false, + show_jap = false, show_num = true, show_sec = true, show_moon = true, @@ -107,6 +108,10 @@ function st.SetShowUS(us) cl.settings.show_us = us end +function st.SetShowJap(jap) + cl.settings.show_us = jap +end + function st.SetShowNum(num) cl.settings.show_num = num end @@ -255,6 +260,14 @@ function st.ShowUS() return cl.settings.show_us end +function st.ShowJap() + -- Not part of previous (<0.7.6) saved variable + if cl.settings.show_jap == nil then + cl.settings.show_jap = false + end + return cl.settings.show_jap +end + function st.ShowNum() return cl.settings.show_num end diff --git a/data/view.lua b/data/view.lua index d6324c2..0c32e91 100644 --- a/data/view.lua +++ b/data/view.lua @@ -186,13 +186,14 @@ function vi.ParseFormat(year, month, day, hour, minute, second, isLore) -- hour -- {0,11} am : {12,11} pm -- {12,1,...,11} am : {12,1,...,11} pm + -- Japanese: {0,1,...,11} am : {12,1,...,11} pm if cl.st.IsUSTime() then if hour > 12 then hour = hour - 12 am = false elseif hour == 12 then am = false - elseif hour == 0 then + elseif hour == 0 and not cl.st.ShowJap() then hour = 12 am = true else diff --git a/libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua b/libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua index 2b5ceec..cb97a2e 100644 --- a/libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua +++ b/libs/LibAddonMenu-2.0/LibAddonMenu-2.0.lua @@ -4,7 +4,7 @@ --Register LAM with LibStub -local MAJOR, MINOR = "LibAddonMenu-2.0", 22 +local MAJOR, MINOR = "LibAddonMenu-2.0", 23 local lam, oldminor = LibStub:NewLibrary(MAJOR, MINOR) if not lam then return end --the same or newer version of this lib is already loaded into memory @@ -43,6 +43,8 @@ local HALF_WIDTH_LINE_SPACING = 2 local OPTIONS_CREATION_RUNNING = 1 local OPTIONS_CREATED = 2 local LAM_CONFIRM_DIALOG = "LAM_CONFIRM_DIALOG" +local LAM_DEFAULTS_DIALOG = "LAM_DEFAULTS" +local LAM_RELOAD_DIALOG = "LAM_RELOAD_DIALOG" local addonsForList = {} local addonToOptionsMap = {} @@ -51,6 +53,8 @@ lam.widgets = lam.widgets or {} local widgets = lam.widgets lam.util = lam.util or {} local util = lam.util +lam.controlsForReload = lam.controlsForReload or {} +local controlsForReload = lam.controlsForReload local function GetDefaultValue(default) if type(default) == "function" then @@ -114,12 +118,6 @@ local function CreateLabelAndContainerControl(parent, controlData, controlName) return control end -local function RequestRefreshIfNeeded(control) - if control.panel.data.registerForRefresh then - cm:FireCallbacks("LAM-RefreshPanel", control) - end -end - local function GetTopPanel(panel) while panel.panel and panel.panel ~= panel do panel = panel.panel @@ -127,12 +125,51 @@ local function GetTopPanel(panel) return panel end +local function IsSame(objA, objB) + if #objA ~= #objB then return false end + for i = 1, #objA do + if objA[i] ~= objB[i] then return false end + end + return true +end + +local function RefreshReloadUIButton() + lam.requiresReload = false + + for i = 1, #controlsForReload do + local reloadControl = controlsForReload[i] + if not IsSame(reloadControl.startValue, {reloadControl.data.getFunc()}) then + lam.requiresReload = true + break + end + end + + lam.applyButton:SetHidden(not lam.requiresReload) +end + +local function RequestRefreshIfNeeded(control) + -- if our parent window wants to refresh controls, then fire the callback + local panel = GetTopPanel(control.panel) + local panelData = panel.data + if panelData.registerForRefresh then + cm:FireCallbacks("LAM-RefreshPanel", control) + end + RefreshReloadUIButton() +end + local function RegisterForRefreshIfNeeded(control) -- if our parent window wants to refresh controls, then add this to the list local panel = GetTopPanel(control.panel) local panelData = panel.data if panelData.registerForRefresh or panelData.registerForDefaults then - tinsert(panel.controlsToRefresh, control) + tinsert(panel.controlsToRefresh or {}, control) -- prevent errors on custom panels + end +end + +local function RegisterForReloadIfNeeded(control) + if control.data.requiresReload then + tinsert(controlsForReload, control) + control.startValue = {control.data.getFunc()} end end @@ -168,8 +205,120 @@ local function ShowConfirmationDialog(title, body, callback) ZO_Dialogs_ShowDialog(LAM_CONFIRM_DIALOG) end +local function GetDefaultsDialog() + if(not ESO_Dialogs[LAM_DEFAULTS_DIALOG]) then + ESO_Dialogs[LAM_DEFAULTS_DIALOG] = { + canQueue = true, + title = { + text = SI_INTERFACE_OPTIONS_RESET_TO_DEFAULT_TOOLTIP, + }, + mainText = { + text = SI_OPTIONS_RESET_PROMPT, + }, + buttons = { + [1] = { + text = SI_OPTIONS_RESET, + callback = function(dialog) end, + }, + [2] = { + text = SI_DIALOG_CANCEL, + } + } + } + end + return ESO_Dialogs[LAM_DEFAULTS_DIALOG] +end + +local function ShowDefaultsDialog(panel) + local dialog = GetDefaultsDialog() + dialog.buttons[1].callback = function() + panel:ForceDefaults() + RefreshReloadUIButton() + end + ZO_Dialogs_ShowDialog(LAM_DEFAULTS_DIALOG) +end + +local function DiscardChangesOnReloadControls() + for i = 1, #controlsForReload do + local reloadControl = controlsForReload[i] + if not IsSame(reloadControl.startValue, {reloadControl.data.getFunc()}) then + reloadControl:UpdateValue(false, unpack(reloadControl.startValue)) + end + end + lam.requiresReload = false + lam.applyButton:SetHidden(true) +end + +local function StorePanelForReopening() + local saveData = ZO_Ingame_SavedVariables["LAM"] or {} + saveData.reopenPanel = lam.currentAddonPanel:GetName() + ZO_Ingame_SavedVariables["LAM"] = saveData +end + +local function RetrievePanelForReopening() + local saveData = ZO_Ingame_SavedVariables["LAM"] + if(saveData) then + ZO_Ingame_SavedVariables["LAM"] = nil + return _G[saveData.reopenPanel] + end +end + +local function HandleReloadUIPressed() + StorePanelForReopening() + ReloadUI() +end + +local function HandleLoadDefaultsPressed() + ShowDefaultsDialog(lam.currentAddonPanel) +end + +local function GetReloadDialog() + if(not ESO_Dialogs[LAM_RELOAD_DIALOG]) then + ESO_Dialogs[LAM_RELOAD_DIALOG] = { + canQueue = true, + title = { + text = util.L["RELOAD_DIALOG_TITLE"], + }, + mainText = { + text = util.L["RELOAD_DIALOG_TEXT"], + }, + buttons = { + [1] = { + text = util.L["RELOAD_DIALOG_RELOAD_BUTTON"], + callback = function() ReloadUI() end, + }, + [2] = { + text = util.L["RELOAD_DIALOG_DISCARD_BUTTON"], + callback = DiscardChangesOnReloadControls, + } + }, + noChoiceCallback = DiscardChangesOnReloadControls, + } + end + return ESO_Dialogs[LAM_CONFIRM_DIALOG] +end + +local function ShowReloadDialogIfNeeded() + if lam.requiresReload then + local dialog = GetReloadDialog() + ZO_Dialogs_ShowDialog(LAM_RELOAD_DIALOG) + end +end + local function UpdateWarning(control) - local warning = util.GetStringFromValue(control.data.warning) + local warning + if control.data.warning ~= nil then + warning = util.GetStringFromValue(control.data.warning) + end + + if control.data.requiresReload then + if not warning then + warning = string.format("|cff0000%s", util.L["RELOAD_UI_WARNING"]) + else + warning = string.format("%s\n\n|cff0000%s", warning, util.L["RELOAD_UI_WARNING"]) + end + end + if not warning then control.warning:SetHidden(true) else @@ -185,14 +334,29 @@ local localization = { VERSION = "Version: <<X:1>>", WEBSITE = "Visit Website", PANEL_INFO_FONT = "$(CHAT_FONT)|14|soft-shadow-thin", + RELOAD_UI_WARNING = "Changes to this setting require an UI reload in order to take effect.", + RELOAD_DIALOG_TITLE = "UI Reload required", + RELOAD_DIALOG_TEXT = "Some changes require an UI reload in order to take effect. Do you want to reload now or discard the changes?", + RELOAD_DIALOG_RELOAD_BUTTON = "Reload", + RELOAD_DIALOG_DISCARD_BUTTON = "Discard", }, fr = { -- provided by Ayantir PANEL_NAME = "Extensions", WEBSITE = "Visiter le site Web", + RELOAD_UI_WARNING = "La modification de ce paramètre requiert un rechargement de l'UI pour qu'il soit pris en compte.", + RELOAD_DIALOG_TITLE = "Reload UI requis", + RELOAD_DIALOG_TEXT = "Certaines modifications requièrent un rechargement de l'UI pour qu'ils soient pris en compte. Souhaitez-vous recharger l'interface maintenant ou annuler les modifications ?", + RELOAD_DIALOG_RELOAD_BUTTON = "Recharger", + RELOAD_DIALOG_DISCARD_BUTTON = "Annuler", }, de = { -- provided by sirinsidiator PANEL_NAME = "Erweiterungen", WEBSITE = "Webseite besuchen", + RELOAD_UI_WARNING = "Änderungen an dieser Option werden erst übernommen nachdem die Benutzeroberfläche neu geladen wird.", + RELOAD_DIALOG_TITLE = "Neuladen benötigt", + RELOAD_DIALOG_TEXT = "Einige Änderungen werden erst übernommen nachdem die Benutzeroberfläche neu geladen wird. Wollt Ihr sie jetzt neu laden oder die Änderungen verwerfen?", + RELOAD_DIALOG_RELOAD_BUTTON = "Neu laden", + RELOAD_DIALOG_DISCARD_BUTTON = "Verwerfen", }, ru = { -- provided by TERAB1T PANEL_NAME = "Дополнения", @@ -207,6 +371,12 @@ local localization = { PANEL_NAME = "アドオン設定", WEBSITE = "ウェブサイトを見る", }, + zh = { -- provided by bssthu + PANEL_NAME = "插件", + VERSION = "版本: <<X:1>>", + WEBSITE = "访问网站", + PANEL_INFO_FONT = "EsoZh/fonts/univers57.otf|14|soft-shadow-thin", + }, } util.L = ZO_ShallowTableCopy(localization[GetCVar("Language.2")], localization["en"]) @@ -217,6 +387,7 @@ util.CreateBaseControl = CreateBaseControl util.CreateLabelAndContainerControl = CreateLabelAndContainerControl util.RequestRefreshIfNeeded = RequestRefreshIfNeeded util.RegisterForRefreshIfNeeded = RegisterForRefreshIfNeeded +util.RegisterForReloadIfNeeded = RegisterForReloadIfNeeded util.GetTopPanel = GetTopPanel util.ShowConfirmationDialog = ShowConfirmationDialog util.UpdateWarning = UpdateWarning @@ -341,17 +512,41 @@ function lam:RegisterWidget(widgetType, widgetVersion) end end +-- INTERNAL METHOD: hijacks the handlers for the actions in the OptionsWindow layer if not already done +local function InitKeybindActions() + if not lam.keybindsInitialized then + lam.keybindsInitialized = true + ZO_PreHook(KEYBOARD_OPTIONS, "ApplySettings", function() + if lam.currentPanelOpened then + if not lam.applyButton:IsHidden() then + HandleReloadUIPressed() + end + return true + end + end) + ZO_PreHook("ZO_Dialogs_ShowDialog", function(dialogName) + if lam.currentPanelOpened and dialogName == "OPTIONS_RESET_TO_DEFAULTS" then + if not lam.defaultButton:IsHidden() then + HandleLoadDefaultsPressed() + end + return true + end + end) + end +end + -- INTERNAL METHOD: fires the LAM-PanelOpened callback if not already done local function OpenCurrentPanel() - if(lam.currentAddonPanel and not lam.currentPanelOpened) then + if lam.currentAddonPanel and not lam.currentPanelOpened then lam.currentPanelOpened = true + lam.defaultButton:SetHidden(not lam.currentAddonPanel.data.registerForDefaults) cm:FireCallbacks("LAM-PanelOpened", lam.currentAddonPanel) end end -- INTERNAL METHOD: fires the LAM-PanelClosed callback if not already done local function CloseCurrentPanel() - if(lam.currentAddonPanel and lam.currentPanelOpened) then + if lam.currentAddonPanel and lam.currentPanelOpened then lam.currentPanelOpened = false cm:FireCallbacks("LAM-PanelClosed", lam.currentAddonPanel) end @@ -911,6 +1106,17 @@ local function CreateAddonSettingsWindow() panelContainer:SetAnchor(TOPLEFT, nil, TOPLEFT, 365, 120) panelContainer:SetDimensions(645, 675) + local defaultButton = wm:CreateControlFromVirtual("$(parent)ResetToDefaultButton", tlw, "ZO_DialogButton") + ZO_KeybindButtonTemplate_Setup(defaultButton, "OPTIONS_LOAD_DEFAULTS", HandleLoadDefaultsPressed, GetString(SI_OPTIONS_DEFAULTS)) + defaultButton:SetAnchor(TOPLEFT, panelContainer, BOTTOMLEFT, 0, 2) + lam.defaultButton = defaultButton + + local applyButton = wm:CreateControlFromVirtual("$(parent)ApplyButton", tlw, "ZO_DialogButton") + ZO_KeybindButtonTemplate_Setup(applyButton, "OPTIONS_APPLY_CHANGES", HandleReloadUIPressed, GetString(SI_ADDON_MANAGER_RELOAD)) + applyButton:SetAnchor(TOPRIGHT, panelContainer, BOTTOMRIGHT, 0, 2) + applyButton:SetHidden(true) + lam.applyButton = applyButton + return tlw end @@ -927,9 +1133,14 @@ local function OnLoad(_, addonName) end em:RegisterForEvent(eventHandle, EVENT_ADD_ON_LOADED, OnLoad) -local function OnActivated(_, addonName) +local function OnActivated(_, initial) em:UnregisterForEvent(eventHandle, EVENT_PLAYER_ACTIVATED) FlushMessages() + + local reopenPanel = RetrievePanelForReopening() + if not initial and reopenPanel then + lam:OpenToPanel(reopenPanel) + end end em:RegisterForEvent(eventHandle, EVENT_PLAYER_ACTIVATED, OnActivated) @@ -960,9 +1171,13 @@ function lam:GetAddonSettingsFragment() LAMAddonSettingsFragment = ZO_FadeSceneFragment:New(window, true, 100) LAMAddonSettingsFragment:RegisterCallback("StateChange", function(oldState, newState) if(newState == SCENE_FRAGMENT_SHOWN) then + InitKeybindActions() + PushActionLayerByName("OptionsWindow") OpenCurrentPanel() elseif(newState == SCENE_FRAGMENT_HIDDEN) then CloseCurrentPanel() + RemoveActionLayerByName("OptionsWindow") + ShowReloadDialogIfNeeded() end end) CreateAddonSettingsMenuEntry() diff --git a/libs/LibAddonMenu-2.0/controls/checkbox.lua b/libs/LibAddonMenu-2.0/controls/checkbox.lua index 5a55267..6696dd7 100644 --- a/libs/LibAddonMenu-2.0/controls/checkbox.lua +++ b/libs/LibAddonMenu-2.0/controls/checkbox.lua @@ -6,13 +6,14 @@ tooltip = "Checkbox's tooltip text.", -- or string id or function returning a string (optional) width = "full", -- or "half" (optional) disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "Will need to reload the UI.", -- or string id or function returning a string (optional) + warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) + requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) default = defaults.var, -- a boolean or function that returns a boolean (optional) reference = "MyAddonCheckbox", -- unique global reference to control (optional) } ]] -local widgetVersion = 13 +local widgetVersion = 14 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("checkbox", widgetVersion) then return end @@ -118,7 +119,7 @@ function LAMCreateControl.checkbox(parent, checkboxData, controlName) control.checkedText = GetString(SI_CHECK_BUTTON_ON):upper() control.uncheckedText = GetString(SI_CHECK_BUTTON_OFF):upper() - if checkboxData.warning ~= nil then + if checkboxData.warning ~= nil or checkboxData.requiresReload then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, checkbox, LEFT, -5, 0) control.UpdateWarning = LAM.util.UpdateWarning @@ -135,6 +136,7 @@ function LAMCreateControl.checkbox(parent, checkboxData, controlName) end LAM.util.RegisterForRefreshIfNeeded(control) + LAM.util.RegisterForReloadIfNeeded(control) return control end diff --git a/libs/LibAddonMenu-2.0/controls/colorpicker.lua b/libs/LibAddonMenu-2.0/controls/colorpicker.lua index 3d06f5e..a57aab0 100644 --- a/libs/LibAddonMenu-2.0/controls/colorpicker.lua +++ b/libs/LibAddonMenu-2.0/controls/colorpicker.lua @@ -6,13 +6,14 @@ tooltip = "Color Picker's tooltip text.", -- or string id or function returning a string (optional) width = "full", --or "half" (optional) disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "Will need to reload the UI.", -- or string id or function returning a string (optional) + warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) + requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) default = {r = defaults.r, g = defaults.g, b = defaults.b, a = defaults.a}, --(optional) table of default color values (or default = defaultColor, where defaultColor is a table with keys of r, g, b[, a]) or a function that returns the color reference = "MyAddonColorpicker" -- unique global reference to control (optional) } ]] -local widgetVersion = 12 +local widgetVersion = 13 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("colorpicker", widgetVersion) then return end @@ -82,7 +83,7 @@ function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) end end) - if colorpickerData.warning ~= nil then + if colorpickerData.warning ~= nil or colorpickerData.requiresReload then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, control.color, LEFT, -5, 0) control.UpdateWarning = LAM.util.UpdateWarning @@ -99,6 +100,7 @@ function LAMCreateControl.colorpicker(parent, colorpickerData, controlName) end LAM.util.RegisterForRefreshIfNeeded(control) + LAM.util.RegisterForReloadIfNeeded(control) return control end diff --git a/libs/LibAddonMenu-2.0/controls/divider.lua b/libs/LibAddonMenu-2.0/controls/divider.lua index f54eb32..8089539 100644 --- a/libs/LibAddonMenu-2.0/controls/divider.lua +++ b/libs/LibAddonMenu-2.0/controls/divider.lua @@ -7,29 +7,34 @@ } ]] -local widgetVersion = 1 +local widgetVersion = 2 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("divider", widgetVersion) then return end local wm = WINDOW_MANAGER local MIN_HEIGHT = 10 +local MAX_HEIGHT = 50 +local MIN_ALPHA = 0 +local MAX_ALPHA = 1 local DEFAULT_ALPHA = 0.25 + +local function GetValueInRange(value, min, max, default) + if not value or type(value) ~= "number" then + return default + end + return math.min(math.max(min, value), max) +end + function LAMCreateControl.divider(parent, dividerData, controlName) local control = LAM.util.CreateBaseControl(parent, dividerData, controlName) local isHalfWidth = control.isHalfWidth local width = control:GetWidth() - local height = dividerData.height - if not height or type(height) ~= "numeric" or height < MIN_HEIGHT then - height = MIN_HEIGHT - end + local height = GetValueInRange(dividerData.height, MIN_HEIGHT, MAX_HEIGHT, MIN_HEIGHT) + local alpha = GetValueInRange(dividerData.alpha, MIN_ALPHA, MAX_ALPHA, DEFAULT_ALPHA) + control:SetDimensions(isHalfWidth and width / 2 or width, height) - - local alpha = dividerData.alpha - if not alpha or type(alpha) ~= "numeric" or alpha > 1 or alpha < 0 then - alpha = DEFAULT_ALPHA - end control.divider = wm:CreateControlFromVirtual(nil, control, "ZO_Options_Divider") local divider = control.divider divider:SetWidth(isHalfWidth and width / 2 or width) diff --git a/libs/LibAddonMenu-2.0/controls/dropdown.lua b/libs/LibAddonMenu-2.0/controls/dropdown.lua index 6d32954..2349ba6 100644 --- a/libs/LibAddonMenu-2.0/controls/dropdown.lua +++ b/libs/LibAddonMenu-2.0/controls/dropdown.lua @@ -2,23 +2,38 @@ type = "dropdown", name = "My Dropdown", -- or string id or function returning a string choices = {"table", "of", "choices"}, + choicesValues = {"foo", 2, "three"}, -- if specified, these values will get passed to setFunc instead (optional) getFunc = function() return db.var end, setFunc = function(var) db.var = var doStuff() end, tooltip = "Dropdown's tooltip text.", -- or string id or function returning a string (optional) - sort = "name-up", --or "name-down", "numeric-up", "numeric-down" (optional) - if not provided, list will not be sorted + choicesTooltips = {"tooltip 1", "tooltip 2", "tooltip 3"}, -- or array of string ids or array of functions returning a string (optional) + sort = "name-up", --or "name-down", "numeric-up", "numeric-down", "value-up", "value-down", "numericvalue-up", "numericvalue-down" (optional) - if not provided, list will not be sorted width = "full", --or "half" (optional) disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "Will need to reload the UI.", -- or string id or function returning a string (optional) + warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) + requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) default = defaults.var, -- default value or function that returns the default value (optional) reference = "MyAddonDropdown" -- unique global reference to control (optional) } ]] -local widgetVersion = 14 +local widgetVersion = 16 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("dropdown", widgetVersion) then return end local wm = WINDOW_MANAGER +local SORT_BY_VALUE = { ["value"] = {} } +local SORT_BY_VALUE_NUMERIC = { ["value"] = { isNumeric = true } } +local SORT_TYPES = { + name = ZO_SORT_BY_NAME, + numeric = ZO_SORT_BY_NAME_NUMERIC, + value = SORT_BY_VALUE, + numericvalue = SORT_BY_VALUE_NUMERIC, +} +local SORT_ORDERS = { + up = ZO_SORT_ORDER_UP, + down = ZO_SORT_ORDER_DOWN, +} local function UpdateDisabled(control) local disable @@ -40,29 +55,86 @@ local function UpdateValue(control, forceDefault, value) if forceDefault then --if we are forcing defaults value = LAM.util.GetDefaultValue(control.data.default) control.data.setFunc(value) - control.dropdown:SetSelectedItem(value) + control.dropdown:SetSelectedItem(control.choices[value]) elseif value then control.data.setFunc(value) --after setting this value, let's refresh the others to see if any should be disabled or have their settings changed LAM.util.RequestRefreshIfNeeded(control) else value = control.data.getFunc() - control.dropdown:SetSelectedItem(value) + control.dropdown:SetSelectedItem(control.choices[value]) end end local function DropdownCallback(control, choiceText, choice) - choice.control:UpdateValue(false, choiceText) + choice.control:UpdateValue(false, choice.value or choiceText) end -local function UpdateChoices(control, choices) +local function SetupTooltips(comboBox, choicesTooltips) + local function ShowTooltip(control) + InitializeTooltip(InformationTooltip, control, TOPLEFT, 0, 0, BOTTOMRIGHT) + SetTooltipText(InformationTooltip, LAM.util.GetStringFromValue(control.tooltip)) + InformationTooltipTopLevel:BringWindowToTop() + end + local function HideTooltip(control) + ClearTooltip(InformationTooltip) + end + + -- allow for tooltips on the drop down entries + local originalShow = comboBox.ShowDropdownInternal + comboBox.ShowDropdownInternal = function(comboBox) + originalShow(comboBox) + local entries = ZO_Menu.items + for i = 1, #entries do + local entry = entries[i] + local control = entries[i].item + control.tooltip = choicesTooltips[i] + entry.onMouseEnter = control:GetHandler("OnMouseEnter") + entry.onMouseExit = control:GetHandler("OnMouseExit") + ZO_PreHookHandler(control, "OnMouseEnter", ShowTooltip) + ZO_PreHookHandler(control, "OnMouseExit", HideTooltip) + end + end + + local originalHide = comboBox.HideDropdownInternal + comboBox.HideDropdownInternal = function(self) + local entries = ZO_Menu.items + for i = 1, #entries do + local entry = entries[i] + local control = entries[i].item + control:SetHandler("OnMouseEnter", entry.onMouseEnter) + control:SetHandler("OnMouseExit", entry.onMouseExit) + control.tooltip = nil + end + originalHide(self) + end +end + +local function UpdateChoices(control, choices, choicesValues, choicesTooltips) control.dropdown:ClearItems() --remove previous choices --(need to call :SetSelectedItem()?) + ZO_ClearTable(control.choices) --build new list of choices local choices = choices or control.data.choices + local choicesValues = choicesValues or control.data.choicesValues + local choicesTooltips = choicesTooltips or control.data.choicesTooltips + + if choicesValues then + assert(#choices == #choicesValues, "choices and choicesValues need to have the same size") + end + + if choicesTooltips then + assert(#choices == #choicesTooltips, "choices and choicesTooltips need to have the same size") + SetupTooltips(control.dropdown, choicesTooltips) + end + for i = 1, #choices do local entry = control.dropdown:CreateItemEntry(choices[i], DropdownCallback) entry.control = control + if choicesValues then + entry.value = choicesValues[i] + end + control.choices[entry.value or entry.name] = entry.name control.dropdown:AddItem(entry, not control.data.sort and ZO_COMBOBOX_SUPRESS_UPDATE) --if sort type/order isn't specified, then don't sort end end @@ -79,6 +151,7 @@ end function LAMCreateControl.dropdown(parent, dropdownData, controlName) local control = LAM.util.CreateLabelAndContainerControl(parent, dropdownData, controlName) + control.choices = {} local countControl = parent local name = parent:GetName() @@ -97,13 +170,25 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) combobox:SetHandler("OnMouseExit", function() ZO_Options_OnMouseExit(control) end) control.dropdown = ZO_ComboBox_ObjectFromContainer(combobox) local dropdown = control.dropdown + dropdown:SetSortsItems(false) -- need to sort ourselves in order to be able to sort by value + + ZO_PreHook(dropdown, "UpdateItems", function(self) + assert(not self.m_sortsItems, "built-in dropdown sorting was reactivated, sorting is handled by LAM") + if control.m_sortOrder ~= nil and control.m_sortType then + local sortKey = next(control.m_sortType) + local sortFunc = function(item1, item2) return ZO_TableOrderingFunction(item1, item2, sortKey, control.m_sortType, control.m_sortOrder) end + table.sort(self.m_sortedItems, sortFunc) + end + end) + if dropdownData.sort then local sortInfo = GrabSortingInfo(dropdownData.sort) - local sortType, sortOrder = sortInfo[1], sortInfo[2] - dropdown:SetSortOrder(sortOrder == "up" and ZO_SORT_ORDER_UP or ZO_SORT_ORDER_DOWN, sortType == "name" and ZO_SORT_BY_NAME or ZO_SORT_BY_NAME_NUMERIC) + control.m_sortType, control.m_sortOrder = SORT_TYPES[sortInfo[1]], SORT_ORDERS[sortInfo[2]] + elseif dropdownData.choicesValues then + control.m_sortType, control.m_sortOrder = ZO_SORT_ORDER_UP, SORT_BY_VALUE end - if dropdownData.warning ~= nil then + if dropdownData.warning ~= nil or dropdownData.requiresReload then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, combobox, LEFT, -5, 0) control.UpdateWarning = LAM.util.UpdateWarning @@ -111,7 +196,7 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) end control.UpdateChoices = UpdateChoices - control:UpdateChoices(dropdownData.choices) + control:UpdateChoices(dropdownData.choices, dropdownData.choicesValues) control.UpdateValue = UpdateValue control:UpdateValue() if dropdownData.disabled ~= nil then @@ -120,6 +205,7 @@ function LAMCreateControl.dropdown(parent, dropdownData, controlName) end LAM.util.RegisterForRefreshIfNeeded(control) + LAM.util.RegisterForReloadIfNeeded(control) return control end diff --git a/libs/LibAddonMenu-2.0/controls/editbox.lua b/libs/LibAddonMenu-2.0/controls/editbox.lua index 3f307f7..d6baf11 100644 --- a/libs/LibAddonMenu-2.0/controls/editbox.lua +++ b/libs/LibAddonMenu-2.0/controls/editbox.lua @@ -8,13 +8,14 @@ isExtraWide = true, --boolean (optional) width = "full", --or "half" (optional) disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "Will need to reload the UI.", -- or string id or function returning a string (optional) + warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) + requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) default = defaults.text, -- default value or function that returns the default value (optional) reference = "MyAddonEditbox" -- unique global reference to control (optional) } ]] -local widgetVersion = 13 +local widgetVersion = 14 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("editbox", widgetVersion) then return end @@ -130,7 +131,7 @@ function LAMCreateControl.editbox(parent, editboxData, controlName) editbox:SetAnchor(TOPLEFT, container, TOPLEFT, 2, 2) editbox:SetAnchor(BOTTOMRIGHT, container, BOTTOMRIGHT, -2, -2) - if editboxData.warning ~= nil then + if editboxData.warning ~= nil or editboxData.requiresReload then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") if editboxData.isExtraWide then control.warning:SetAnchor(BOTTOMRIGHT, control.bg, TOPRIGHT, 2, 0) @@ -149,6 +150,7 @@ function LAMCreateControl.editbox(parent, editboxData, controlName) end LAM.util.RegisterForRefreshIfNeeded(control) + LAM.util.RegisterForReloadIfNeeded(control) return control end diff --git a/libs/LibAddonMenu-2.0/controls/iconpicker.lua b/libs/LibAddonMenu-2.0/controls/iconpicker.lua index 7042b30..65c7782 100644 --- a/libs/LibAddonMenu-2.0/controls/iconpicker.lua +++ b/libs/LibAddonMenu-2.0/controls/iconpicker.lua @@ -13,12 +13,13 @@ width = "full", --or "half" (optional) beforeShow = function(control, iconPicker) return preventShow end, --(optional) disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "Will need to reload the UI.", -- or string id or function returning a string (optional) + warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) + requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) default = defaults.var, -- default value or function that returns the default value (optional) reference = "MyAddonIconPicker" -- unique global reference to control (optional) } ]] -local widgetVersion = 7 +local widgetVersion = 8 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("iconpicker", widgetVersion) then return end @@ -408,7 +409,7 @@ function LAMCreateControl.iconpicker(parent, iconpickerData, controlName) mungeOverlay:SetAddressMode(TEX_MODE_WRAP) mungeOverlay:SetAnchorFill() - if iconpickerData.warning ~= nil then + if iconpickerData.warning ~= nil or iconpickerData.requiresReload then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, control.container, LEFT, -5, 0) control.UpdateWarning = LAM.util.UpdateWarning @@ -429,6 +430,7 @@ function LAMCreateControl.iconpicker(parent, iconpickerData, controlName) end LAM.util.RegisterForRefreshIfNeeded(control) + LAM.util.RegisterForReloadIfNeeded(control) return control end diff --git a/libs/LibAddonMenu-2.0/controls/panel.lua b/libs/LibAddonMenu-2.0/controls/panel.lua index 2bf9dfa..1404686 100644 --- a/libs/LibAddonMenu-2.0/controls/panel.lua +++ b/libs/LibAddonMenu-2.0/controls/panel.lua @@ -13,7 +13,7 @@ } ]] -local widgetVersion = 11 +local widgetVersion = 13 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("panel", widgetVersion) then return end @@ -55,25 +55,6 @@ local function ForceDefaults(panel) cm:FireCallbacks("LAM-RefreshPanel", panel) end -ESO_Dialogs["LAM_DEFAULTS"] = { - title = { - text = SI_INTERFACE_OPTIONS_RESET_TO_DEFAULT_TOOLTIP, - }, - mainText = { - text = SI_OPTIONS_RESET_PROMPT, - align = TEXT_ALIGN_CENTER, - }, - buttons = { - [1] = { - text = SI_OPTIONS_RESET, - callback = function(dialog) ForceDefaults(dialog.data[1]) end, - }, - [2] = { - text = SI_DIALOG_CANCEL, - }, - }, -} - local callbackRegistered = false LAMCreateControl.scrollCount = LAMCreateControl.scrollCount or 1 local SEPARATOR = " - " @@ -132,24 +113,12 @@ function LAMCreateControl.panel(parent, panelData, controlName) control.scroll = GetControl(control.container, "ScrollChild") control.scroll:SetResizeToFitPadding(0, 20) - if panelData.registerForDefaults then - control.defaultButton = wm:CreateControlFromVirtual(nil, control, "ZO_DefaultTextButton") - local defaultButton = control.defaultButton - defaultButton:SetFont("ZoFontDialogKeybindDescription") - defaultButton:SetHorizontalAlignment(TEXT_ALIGN_LEFT) - defaultButton:SetText(GetString(SI_OPTIONS_DEFAULTS)) - defaultButton:SetDimensions(200, 30) - defaultButton:SetAnchor(TOPLEFT, control, BOTTOMLEFT, 0, 2) - defaultButton:SetHandler("OnClicked", function() - ZO_Dialogs_ShowDialog("LAM_DEFAULTS", {control}) - end) - end - if panelData.registerForRefresh and not callbackRegistered then --don't want to register our callback more than once cm:RegisterCallback("LAM-RefreshPanel", RefreshPanel) callbackRegistered = true end + control.ForceDefaults = ForceDefaults control.data = panelData control.controlsToRefresh = {} diff --git a/libs/LibAddonMenu-2.0/controls/slider.lua b/libs/LibAddonMenu-2.0/controls/slider.lua index fe339ba..bd721c5 100644 --- a/libs/LibAddonMenu-2.0/controls/slider.lua +++ b/libs/LibAddonMenu-2.0/controls/slider.lua @@ -13,12 +13,13 @@ tooltip = "Slider's tooltip text.", -- or string id or function returning a string (optional) width = "full", --or "half" (optional) disabled = function() return db.someBooleanSetting end, --or boolean (optional) - warning = "Will need to reload the UI.", -- or string id or function returning a string (optional) + warning = "May cause permanent awesomeness.", -- or string id or function returning a string (optional) + requiresReload = false, -- boolean, if set to true, the warning text will contain a notice that changes are only applied after an UI reload and any change to the value will make the "Apply Settings" button appear on the panel which will reload the UI when pressed (optional) default = defaults.var, -- default value or function that returns the default value (optional) reference = "MyAddonSlider" -- unique global reference to control (optional) } ]] -local widgetVersion = 11 +local widgetVersion = 12 local LAM = LibStub("LibAddonMenu-2.0") if not LAM:RegisterWidget("slider", widgetVersion) then return end @@ -189,7 +190,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) control:UpdateValue(false, new_value) end) - if sliderData.warning ~= nil then + if sliderData.warning ~= nil or sliderData.requiresReload then control.warning = wm:CreateControlFromVirtual(nil, control, "ZO_Options_WarningIcon") control.warning:SetAnchor(RIGHT, slider, LEFT, -5, 0) control.UpdateWarning = LAM.util.UpdateWarning @@ -205,6 +206,7 @@ function LAMCreateControl.slider(parent, sliderData, controlName) end LAM.util.RegisterForRefreshIfNeeded(control) + LAM.util.RegisterForReloadIfNeeded(control) return control end diff --git a/local/de.lua b/local/de.lua index b02def8..226331d 100644 --- a/local/de.lua +++ b/local/de.lua @@ -64,6 +64,7 @@ cl.ln = { tAHide = "Wähle ob die Clock versteckt werden soll, falls das menü geöffnet wird.", sFormat = "12h Format", sAMPM = "Zeige AM/PM", + sJap = "Zeige Mitternacht als 0", sNum = "Ergänze Nullen", tNum = "Ergänzt Nullen vor eine einstellige Zahl: 1:24 -> 01:24", sSec = "Zeige Sekunden", diff --git a/local/en.lua b/local/en.lua index 3d1c8a9..e9e8cda 100644 --- a/local/en.lua +++ b/local/en.lua @@ -85,6 +85,7 @@ cl.ln = { tAHide = "Select if the Clock should be hidden when a menu is open.", sFormat = "12h format", sAMPM = "Show AM/PM", + sJap = "Show midngiht as 0", sNum = "Add zeros", tNum = "Add zeros before a single number: 1:24 -> 01:24", sSec = "Show Seconds",