Add OptionsFrame with debug option and add fix quest file
This commit is contained in:
parent
0b8d0cdb7c
commit
f2641af379
7 changed files with 243 additions and 65 deletions
150
Frames/OptionsFrame.lua
Normal file
150
Frames/OptionsFrame.lua
Normal file
|
@ -0,0 +1,150 @@
|
|||
local defaultOptions = {
|
||||
DEBUG_MODE = false,
|
||||
SELECTED_INTERACTION = 'hover',
|
||||
SELECTED_HOTKEY = nil
|
||||
}
|
||||
|
||||
local addonName = ...
|
||||
local optionsFrame = CreateFrame("Frame")
|
||||
|
||||
local function CreateCheckBox(parent, optionsPanel, text, onClick)
|
||||
local checkbox = CreateFrame("CheckButton", nil, optionsPanel, "InterfaceOptionsCheckButtonTemplate")
|
||||
checkbox.Text:SetText(text)
|
||||
checkbox:SetScript("OnClick", onClick)
|
||||
|
||||
return checkbox
|
||||
end
|
||||
|
||||
local function createOptionCheckbox(parent, optionsPanel, text, optionKey)
|
||||
local checkbox = CreateCheckBox(parent, optionsPanel, text, function(self)
|
||||
local checked = self:GetChecked()
|
||||
CzechQuestsOptions[optionKey] = checked
|
||||
end)
|
||||
|
||||
checkbox:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -8)
|
||||
checkbox:SetChecked(CzechQuestsOptions[optionKey])
|
||||
return checkbox
|
||||
end
|
||||
|
||||
local function InitializeOptions()
|
||||
local optionsPanel = CreateFrame("Frame", "CzechQuestsOptionsPanel", UIParent)
|
||||
optionsPanel.name = "CzechQuests"
|
||||
|
||||
local title = optionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
|
||||
title:SetPoint("TOPLEFT", 16, -16)
|
||||
title:SetText("CzechQuests")
|
||||
|
||||
local enableDebugModeCheckbox = createOptionCheckbox(title, optionsPanel,"Enable DEBUG mode", "DEBUG_MODE")
|
||||
enableDebugModeCheckbox:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 16, -8)
|
||||
|
||||
local interactionDropdownDescription = optionsPanel:CreateFontString(nil, "ARTWORK", "GameFontnormalSmall")
|
||||
interactionDropdownDescription:SetPoint("TOPLEFT", enableDebugModeCheckbox, "BOTTOMLEFT", 0, -8)
|
||||
interactionDropdownDescription:SetText("Select interaction:")
|
||||
|
||||
local interactionDropdown = CreateFrame("Frame", "CzechQuestsInteractionDropdown", optionsPanel, "UIDropDownMenuTemplate")
|
||||
interactionDropdown:SetPoint("TOPLEFT", interactionDropdownDescription, "BOTTOMLEFT", -16, -4)
|
||||
|
||||
local function SetSelectedInteractionText(interactionText, selectedInteractionText, checked)
|
||||
if checked then
|
||||
return selectedInteractionText
|
||||
end
|
||||
|
||||
return interactionText
|
||||
end
|
||||
|
||||
local function OnInteractionDropdownValueChanged(self, arg1, arg2, checked)
|
||||
CzechQuestsOptions.SELECTED_INTERACTION = arg1
|
||||
UIDropDownMenu_SetText(interactionDropdown, arg2)
|
||||
end
|
||||
|
||||
local function InitializeInteractionDropdown()
|
||||
local info = UIDropDownMenu_CreateInfo()
|
||||
local interactionText = "Hover"
|
||||
|
||||
info.text = "Hover"
|
||||
info.value = "hover"
|
||||
info.arg1 = info.value
|
||||
info.arg2 = info.text
|
||||
info.checked = CzechQuestsOptions.SELECTED_INTERACTION == "hover"
|
||||
info.func = OnInteractionDropdownValueChanged
|
||||
info.minWidth = 145
|
||||
interactionText = SetSelectedInteractionText(interactionText, info.text, info.checked)
|
||||
UIDropDownMenu_AddButton(info)
|
||||
|
||||
info.text = "Hover + hotkey"
|
||||
info.value = "hover-hotkey"
|
||||
info.arg1 = info.value
|
||||
info.arg2 = info.text
|
||||
info.checked = CzechQuestsOptions.SELECTED_INTERACTION == "hover-hotkey"
|
||||
info.func = OnInteractionDropdownValueChanged
|
||||
info.minWidth = 145
|
||||
interactionText = SetSelectedInteractionText(interactionText, info.text, info.checked)
|
||||
UIDropDownMenu_AddButton(info)
|
||||
|
||||
UIDropDownMenu_SetText(interactionDropdown, interactionText)
|
||||
UIDropDownMenu_SetAnchor(interactionDropdown, 16, 4, "TOPLEFT", interactionDropdown, "BOTTOMLEFT")
|
||||
end
|
||||
|
||||
UIDropDownMenu_SetWidth(interactionDropdown, 150)
|
||||
UIDropDownMenu_Initialize(interactionDropdown, InitializeInteractionDropdown)
|
||||
|
||||
local hotkeyDescription = optionsPanel:CreateFontString(nil, "ARTWORK", "GameFontnormalSmall")
|
||||
hotkeyDescription:SetPoint("TOPLEFT", interactionDropdown, "BOTTOMLEFT", 16, -8)
|
||||
hotkeyDescription:SetText("Register Hotkey (right-click to unbind):")
|
||||
|
||||
local registerHotkeyButton = CreateFrame("Button", "CzechQuestsRegisterHotkeyButton", optionsPanel, "UIPanelButtonTemplate")
|
||||
registerHotkeyButton:SetWidth(120)
|
||||
registerHotkeyButton:SetHeight(25)
|
||||
registerHotkeyButton:SetPoint("TOPLEFT", hotkeyDescription, "TOPLEFT", 0, -12)
|
||||
|
||||
if CzechQuestsOptions.SELECTED_HOTKEY then
|
||||
registerHotkeyButton:SetText(CzechQuestsOptions.SELECTED_HOTKEY)
|
||||
else
|
||||
registerHotkeyButton:SetText("Not Bound")
|
||||
end
|
||||
|
||||
local waitingForKey = false
|
||||
|
||||
registerHotkeyButton:SetScript("OnMouseDown", function(self, button)
|
||||
if button == "LeftButton" then
|
||||
if not waitingForKey then
|
||||
waitingForKey = true
|
||||
registerHotkeyButton:SetText("Press button..")
|
||||
end
|
||||
elseif button == "RightButton" then
|
||||
waitingForKey = false
|
||||
registerHotkeyButton:SetText("Not Bound")
|
||||
CzechQuestsOptions.SELECTED_HOTKEY = nil
|
||||
end
|
||||
end)
|
||||
|
||||
local function SetHotkeyButton(self, key)
|
||||
if waitingForKey then
|
||||
CzechQuestsOptions.SELECTED_HOTKEY = key
|
||||
registerHotkeyButton:SetText(CzechQuestsOptions.SELECTED_HOTKEY)
|
||||
waitingForKey = false
|
||||
end
|
||||
end
|
||||
|
||||
registerHotkeyButton:SetScript("OnKeyDown", SetHotkeyButton)
|
||||
registerHotkeyButton:SetPropagateKeyboardInput(true)
|
||||
|
||||
InterfaceOptions_AddCategory(optionsPanel)
|
||||
end
|
||||
|
||||
local function addonLoaded(self, event, addonLoadedName)
|
||||
if addonLoadedName == addonName then
|
||||
CzechQuestsOptions = CzechQuestsOptions or defaultOptions
|
||||
|
||||
for key, value in pairs(defaultOptions) do
|
||||
if CzechQuestsOptions[key] == nil then
|
||||
CzechQuestsOptions[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
InitializeOptions()
|
||||
end
|
||||
end
|
||||
|
||||
optionsFrame:RegisterEvent("ADDON_LOADED")
|
||||
optionsFrame:SetScript("OnEvent", addonLoaded)
|
Loading…
Add table
Add a link
Reference in a new issue