Replace ScrollFrame with Messages queue and refactor speeches options

This commit is contained in:
Roman Jaroš 2025-03-07 17:11:59 +01:00
parent b6d64d65b5
commit b17f37ee42
5 changed files with 87 additions and 152 deletions

View file

@ -25,13 +25,13 @@ local function RegisterProxySettings(name, title, setter)
function()
return CzechQuestsAddon_Store.config[name]
end,
setter
function(value) setter(name, value) end
)
end
local function CreateCheckbox(name, title, setter)
local register = RegisterAddOnSettings(name, title)
register:SetValueChangedCallback(setter)
register:SetValueChangedCallback(function(_, value) setter(name, value) end)
Settings.CreateCheckbox(Options.category, register)
end
@ -47,7 +47,7 @@ end
local function CreateButton(title, label, setter)
Options.layout:AddInitializer(
CreateSettingsButtonInitializer(title, label, setter, nil, title)
CreateSettingsButtonInitializer(title, label, function(value) setter(name, value) end, nil, title)
)
end
@ -57,86 +57,67 @@ local function InitQuests()
addon.QuestFrame:UpdateSettings()
end
local function CreateQuestCheckbox(name, title)
CreateCheckbox(name, title, function (_, value) Update(name, value) end)
end
local function CreateQuestDropdown(name, title, items)
CreateDropdown(name, title, items, function (value) Update(name, value) end)
end
local function CreateQuestSlider(name, title, min, max, step)
CreateSlider(name, title, min, max, step, function (value) Update(name, value) end)
end
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Questy"))
CreateQuestCheckbox("QUEST_ENABLED", "Zapnout")
CreateCheckbox("QUEST_ENABLED", "Zapnout", Update)
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
CreateQuestCheckbox("QUEST_DARK_MODE", "Pouzit tmavy rezim")
CreateCheckbox("QUEST_DARK_MODE", "Pouzit tmavy rezim", Update)
end
CreateQuestDropdown("QUEST_HEADER_FONT_NAME", "Pismo nadpisu", addon.API.GetFontContainer)
CreateQuestDropdown("QUEST_TEXT_FONT_NAME", "Pismo textu", addon.API.GetFontContainer)
CreateDropdown("QUEST_HEADER_FONT_NAME", "Pismo nadpisu", addon.API.GetFontContainer, Update)
CreateQuestSlider("QUEST_HEADER_FONT_SIZE", "Velikost nadpisu", 10, 30, 1)
CreateQuestSlider("QUEST_TEXT_FONT_SIZE", "Velikost textu", 10, 30, 1)
CreateDropdown("QUEST_TEXT_FONT_NAME", "Pismo textu", addon.API.GetFontContainer, Update)
CreateQuestSlider("QUEST_TEXTURE_ALPHA", "Pruhlednost pozadi", 10, 100, 10)
CreateQuestCheckbox("QUEST_TEXTURE_ALPHA_ONLY_MOVING", "Pruhlednost pouze pri chuzi")
CreateSlider("QUEST_HEADER_FONT_SIZE", "Velikost nadpisu", 10, 30, 1, Update)
CreateSlider("QUEST_TEXT_FONT_SIZE", "Velikost textu", 10, 30, 1, Update)
CreateSlider("QUEST_TEXTURE_ALPHA", "Pruhlednost pozadi", 10, 100, 10, Update)
CreateCheckbox("QUEST_TEXTURE_ALPHA_ONLY_MOVING", "Pruhlednost pouze pri chuzi", Update)
end
local function InitSpeeches()
local function CreateSpeechCheckbox(name, title)
CreateCheckbox(name, title, function (_, value)
local function Update(name, value)
CzechQuestsAddon_Store.config[name] = value
addon.SpeechFrame:UpdateSettings()
end)
end
local function CreateSpeechDropdown(name, title, items)
CreateDropdown(name, title, items, function (value)
CzechQuestsAddon_Store.config[name] = value
addon.SpeechFrame:UpdateSettings()
end)
end
local function CreateSpeechSlider(name, title, min, max, step)
CreateSlider(name, title, min, max, step, function (value)
CzechQuestsAddon_Store.config[name] = value
addon.SpeechFrame:UpdateSettings()
end)
end
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Bubliny"))
CreateSpeechCheckbox("SPEECH_ENABLED", "Zapnout")
CreateCheckbox("SPEECH_ENABLED", "Zapnout", Update)
CreateSpeechDropdown("SPEECH_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer)
CreateSpeechSlider("SPEECH_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1)
CreateDropdown("SPEECH_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer, Update)
CreateSpeechSlider("SPEECH_FRAME_WIDTH", "Sirka okna", 200, 1000, 10)
CreateSlider("SPEECH_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1, Update)
CreateSpeechCheckbox("SPEECH_ORIGINAL_WHEN_MISSING", "Original pokud není preklad ")
CreateSlider("SPEECH_FRAME_WIDTH", "Sirka okna", 200, 1000, 10, Update)
CreateCheckbox("SPEECH_ORIGINAL_WHEN_MISSING", "Original pokud není preklad", Update)
CreateSlider("SPEECH_MESSAGE_TEXTURE_ALPHA", "Pruhlednost pozadi zpravy", 0, 100, 10, Update)
CreateSlider("SPEECH_FRAME_POSITION_X", "Pozice okna X", 0, math.floor(GetScreenWidth()), 1, Update)
CreateSlider("SPEECH_FRAME_POSITION_Y", "Pozice okna Y", 0, math.floor(GetScreenHeight()), 1, Update)
CreateButton('Resetovat pozici okna', "RESET", function()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = { x = 0, y = 0}
addon.SpeechFrame:SetPoint(
"TOPLEFT", UIParent, "TOPLEFT",
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.x,
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.y
)
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = 0
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = 0
addon.SpeechFrame:UpdateSettings()
end)
end
local function InitOthers()
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Ostatni"))
CreateCheckbox("DEBUG_MODE", "Zapnout DEBUG", function() end)
CreateCheckbox("DEBUG_MODE", "Zapnout DEBUG", function()
end)
end
local function InitOptions()

View file

@ -1,32 +1,21 @@
local _, addon = ...
local messages = {}
local GAP = 2
local function ReflowMessages()
local offsetY = 5
local offsetY = 0
for i = #messages, 1, -1 do
local Frame = messages[i]
Frame:ClearAllPoints()
Frame:SetPoint("BOTTOMLEFT", addon.SpeechFrame.ContentFrame, "BOTTOMLEFT", 5, offsetY)
Frame:SetPoint("BOTTOMLEFT", addon.SpeechFrame, "BOTTOMLEFT", 0, offsetY)
Frame:Show()
offsetY = offsetY + Frame:GetHeight()
offsetY = offsetY + Frame:GetHeight() + GAP
end
if #messages == 0 then
addon.SpeechFrame:Hide()
end
-- calculate Content height
-- cannot be smaller then SpeechFrame
offsetY = offsetY + 5
if offsetY < 150 then
offsetY = 150
end
addon.SpeechFrame.ContentFrame:SetHeight(offsetY)
-- Scroll down
--addon.SpeechFrame:UpdateScrollChildRect()
--local maxScroll = addon.SpeechFrame:GetVerticalScrollRange()
--addon.SpeechFrame:SetVerticalScroll(maxScroll)
end
local function RemoveMessage(frame)
@ -51,7 +40,7 @@ end
local function AddMessage(sender, message)
local text = string.format("|cffffd200%s|r\n%s", sender, message)
local MessageFrame = addon.SpeechFrame.ContentFrame:CreateMessage(text)
local MessageFrame = addon.SpeechFrame:CreateMessage(text)
-- put into table and rerender while queue
table.insert(messages, MessageFrame)
@ -68,10 +57,8 @@ local function ShowSpeechTranslation(sender, message)
if text == nil and CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING then
text = message
end
if text ~= nil then
addon.SpeechFrame:Show()
addon.SpeechFrame.ContentFrame:Show()
AddMessage(sender, text)
end
end

View file

@ -1,75 +1,46 @@
local _, addon = ...
local SpeechFrame = CreateFrame("ScrollFrame", "CzechQuestsSpeechFrame", UIParent, "UIPanelScrollFrameTemplate")
local SpeechFrame = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
SpeechFrame:Hide()
local ContentFrame = CreateFrame("Frame", nil, SpeechFrame)
ContentFrame:Hide()
addon.SpeechFrame = SpeechFrame
SpeechFrame.ContentFrame = ContentFrame
function SpeechFrame:Init()
local frame = self
-- Default style
self:SetSize(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH, 150)
frame:SetHeight(50)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
-- Make movable
self:SetMovable(true)
self:EnableMouse(true)
self:RegisterForDrag("LeftButton")
-- Hide sidebar
self.ScrollBar:Hide()
-- Register drag event
self:SetScript("OnDragStart", function()
frame:StartMoving()
end)
self:SetScript("OnDragStop", function(self)
frame:SetScript("OnDragStart", function() frame:StartMoving() end)
frame:SetScript("OnDragStop", function(self)
frame:StopMovingOrSizing()
local finalLeft, finalTop = self:GetLeft(), self:GetTop()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = {
x = finalLeft,
y = finalTop
}
local finalLeft = self:GetLeft() local finalBottom = self:GetBottom()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = math.floor(finalLeft)
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = math.floor(finalBottom)
end)
-- Create ContentFrame
ContentFrame:Init()
SpeechFrame:SetScrollChild(SpeechFrame.ContentFrame)
-- Register hover events
self:SetScript("OnEnter", function() self.ContentFrame.Texture:SetAlpha(0.8) end)
self:SetScript("OnLeave", function() self.ContentFrame.Texture:SetAlpha(0.2) end)
self:UpdateSettings()
frame:UpdateSettings()
end
function ContentFrame:Init()
-- Default style
self:SetSize(SpeechFrame:GetWidth(), 1)
function SpeechFrame:UpdateSettings()
self:SetWidth(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH)
-- Texture for control color and alpha
self.Texture = self:CreateTexture(nil, "ARTWORK")
self.Texture:SetTexture("Interface\\Buttons\\WHITE8x8")
self.Texture:SetVertexColor(0, 0, 0, 0.2)
-- Set points to edges
self.Texture:SetPoint("TOPLEFT", self ,"TOPLEFT", 0, 0)
self.Texture:SetPoint("BOTTOMRIGHT", self ,"BOTTOMRIGHT", 0, 0)
-- Set ContentFrame position
self:SetPoint("BOTTOMLEFT", SpeechFrame, "BOTTOMLEFT", 0, 0)
-- Set position
self:SetPoint(
"BOTTOMLEFT", UIParent, "BOTTOMLEFT",
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X,
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y
)
end
function ContentFrame:CreateMessage(message)
-- Default style
local MessageFrame = CreateFrame("Frame", nil, SpeechFrame.ContentFrame)
MessageFrame:SetSize(SpeechFrame.ContentFrame:GetWidth() - 20, 1)
function SpeechFrame:CreateMessage(message)
local frame = self
local MessageFrame = CreateFrame("Frame", nil, frame)
MessageFrame:SetSize(frame:GetWidth(), 1)
-- Define Message
MessageFrame.Message = addon.API.CreateCzechFont(
MessageFrame,
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME,
@ -80,22 +51,15 @@ function ContentFrame:CreateMessage(message)
MessageFrame.Message:SetPoint("TOPLEFT", MessageFrame, "TOPLEFT", 5, -5)
MessageFrame.Message:SetPoint("BOTTOMRIGHT", MessageFrame, "BOTTOMRIGHT", -5, 5)
-- Set text and height
-- Create Texture
MessageFrame.Texture = MessageFrame:CreateTexture(nil, "ARTWORK")
MessageFrame.Texture:SetTexture("Interface\\Buttons\\WHITE8x8")
MessageFrame.Texture:SetVertexColor(0, 0, 0, CzechQuestsAddon_Store.config.SPEECH_MESSAGE_TEXTURE_ALPHA / 100)
MessageFrame.Texture:SetPoint("TOPLEFT", MessageFrame ,"TOPLEFT", 0, 0)
MessageFrame.Texture:SetPoint("BOTTOMRIGHT", MessageFrame ,"BOTTOMRIGHT", 0, 0)
MessageFrame.Message:SetText(message)
MessageFrame:SetHeight(MessageFrame.Message:GetHeight() + 10)
return MessageFrame
end
function SpeechFrame:UpdateSettings()
self:SetWidth(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH)
self.ContentFrame:SetWidth(self:GetWidth())
-- Set position
self:ClearAllPoints()
self:SetPoint(
"TOPLEFT", UIParent, "TOPLEFT",
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.x,
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.y
)
end

View file

@ -32,11 +32,13 @@ local function InitStore()
-- Speech Settings
CzechQuestsAddon_Store.config.SPEECH_ENABLED = CzechQuestsAddon_Store.config.SPEECH_ENABLED or true
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE or 15
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE or 13
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME = CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME or 'frizquadratatt_cz.ttf'
CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH = CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH or 320
CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING = CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING or false
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION or { x = 0, y = 0}
CzechQuestsAddon_Store.config.SPEECH_MESSAGE_TEXTURE_ALPHA = CzechQuestsAddon_Store.config.SPEECH_MESSAGE_TEXTURE_ALPHA or 40
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X or 0
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y or 0
end
-- Event handler frame

19
sync.sh
View file

@ -1,19 +1,20 @@
#!/bin/bash
#wow_source_folder="retail"
#wow_destiny_folder="retail"
#wow_destiny_folder="retail"
#wow_destiny_folder="beta"
wow_source_folder="classic_era"
wow_destiny_folder="classic_era"
src_folder="."
wow_source_folder="retail"
wow_destiny_folder="retail"
wow_destiny_folder="beta"
#wow_source_folder="classic_era"
#wow_destiny_folder="classic_era"
# CLASSIC ERA
dest_folder="/Applications/World of Warcraft/_${wow_destiny_folder}_/Interface/AddOns/CzechQuests"
fswatch -o "$src_folder" | while read -r change; do
rsync -avu --delete "$src_folder" "$dest_folder" --exclude={'.*','*.png','*.sh','*.md','Addon/Data/**','downloader/**'}
rsync -au --delete "$src_folder/Addon/Data/$wow_source_folder/" "$dest_folder/Addon/Data/"
echo "Dest: $dest_folder"
cp "$src_folder/Addon/Data/other.lua" "$dest_folder/Addon/Data/"
done