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() function()
return CzechQuestsAddon_Store.config[name] return CzechQuestsAddon_Store.config[name]
end, end,
setter function(value) setter(name, value) end
) )
end end
local function CreateCheckbox(name, title, setter) local function CreateCheckbox(name, title, setter)
local register = RegisterAddOnSettings(name, title) local register = RegisterAddOnSettings(name, title)
register:SetValueChangedCallback(setter) register:SetValueChangedCallback(function(_, value) setter(name, value) end)
Settings.CreateCheckbox(Options.category, register) Settings.CreateCheckbox(Options.category, register)
end end
@ -47,7 +47,7 @@ end
local function CreateButton(title, label, setter) local function CreateButton(title, label, setter)
Options.layout:AddInitializer( Options.layout:AddInitializer(
CreateSettingsButtonInitializer(title, label, setter, nil, title) CreateSettingsButtonInitializer(title, label, function(value) setter(name, value) end, nil, title)
) )
end end
@ -57,86 +57,67 @@ local function InitQuests()
addon.QuestFrame:UpdateSettings() addon.QuestFrame:UpdateSettings()
end 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 local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Questy")) layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Questy"))
CreateQuestCheckbox("QUEST_ENABLED", "Zapnout") CreateCheckbox("QUEST_ENABLED", "Zapnout", Update)
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
CreateQuestCheckbox("QUEST_DARK_MODE", "Pouzit tmavy rezim") CreateCheckbox("QUEST_DARK_MODE", "Pouzit tmavy rezim", Update)
end end
CreateQuestDropdown("QUEST_HEADER_FONT_NAME", "Pismo nadpisu", addon.API.GetFontContainer) CreateDropdown("QUEST_HEADER_FONT_NAME", "Pismo nadpisu", addon.API.GetFontContainer, Update)
CreateQuestDropdown("QUEST_TEXT_FONT_NAME", "Pismo textu", addon.API.GetFontContainer)
CreateQuestSlider("QUEST_HEADER_FONT_SIZE", "Velikost nadpisu", 10, 30, 1) CreateDropdown("QUEST_TEXT_FONT_NAME", "Pismo textu", addon.API.GetFontContainer, Update)
CreateQuestSlider("QUEST_TEXT_FONT_SIZE", "Velikost textu", 10, 30, 1)
CreateQuestSlider("QUEST_TEXTURE_ALPHA", "Pruhlednost pozadi", 10, 100, 10) CreateSlider("QUEST_HEADER_FONT_SIZE", "Velikost nadpisu", 10, 30, 1, Update)
CreateQuestCheckbox("QUEST_TEXTURE_ALPHA_ONLY_MOVING", "Pruhlednost pouze pri chuzi")
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 end
local function InitSpeeches() local function InitSpeeches()
local function CreateSpeechCheckbox(name, title) local function Update(name, value)
CreateCheckbox(name, title, function (_, value) CzechQuestsAddon_Store.config[name] = value
CzechQuestsAddon_Store.config[name] = value addon.SpeechFrame:UpdateSettings()
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 end
local layout = Options.layout local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Bubliny")) layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Bubliny"))
CreateSpeechCheckbox("SPEECH_ENABLED", "Zapnout") CreateCheckbox("SPEECH_ENABLED", "Zapnout", Update)
CreateSpeechDropdown("SPEECH_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer) CreateDropdown("SPEECH_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer, Update)
CreateSpeechSlider("SPEECH_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1)
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() CreateButton('Resetovat pozici okna', "RESET", function()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = { x = 0, y = 0} CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = 0
addon.SpeechFrame:SetPoint( CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = 0
"TOPLEFT", UIParent, "TOPLEFT", addon.SpeechFrame:UpdateSettings()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.x,
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.y
)
end) end)
end end
local function InitOthers() local function InitOthers()
local layout = Options.layout local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Ostatni")) layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Ostatni"))
CreateCheckbox("DEBUG_MODE", "Zapnout DEBUG", function() end) CreateCheckbox("DEBUG_MODE", "Zapnout DEBUG", function()
end)
end end
local function InitOptions() local function InitOptions()

View file

@ -1,32 +1,21 @@
local _, addon = ... local _, addon = ...
local messages = {} local messages = {}
local GAP = 2
local function ReflowMessages() local function ReflowMessages()
local offsetY = 5 local offsetY = 0
for i = #messages, 1, -1 do for i = #messages, 1, -1 do
local Frame = messages[i] local Frame = messages[i]
Frame:ClearAllPoints() Frame:ClearAllPoints()
Frame:SetPoint("BOTTOMLEFT", addon.SpeechFrame.ContentFrame, "BOTTOMLEFT", 5, offsetY) Frame:SetPoint("BOTTOMLEFT", addon.SpeechFrame, "BOTTOMLEFT", 0, offsetY)
Frame:Show() Frame:Show()
offsetY = offsetY + Frame:GetHeight() offsetY = offsetY + Frame:GetHeight() + GAP
end end
if #messages == 0 then if #messages == 0 then
addon.SpeechFrame:Hide() addon.SpeechFrame:Hide()
end 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 end
local function RemoveMessage(frame) local function RemoveMessage(frame)
@ -51,7 +40,7 @@ end
local function AddMessage(sender, message) local function AddMessage(sender, message)
local text = string.format("|cffffd200%s|r\n%s", 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 -- put into table and rerender while queue
table.insert(messages, MessageFrame) 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 if text == nil and CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING then
text = message text = message
end end
if text ~= nil then if text ~= nil then
addon.SpeechFrame:Show() addon.SpeechFrame:Show()
addon.SpeechFrame.ContentFrame:Show()
AddMessage(sender, text) AddMessage(sender, text)
end end
end end

View file

@ -1,75 +1,46 @@
local _, addon = ... local _, addon = ...
local SpeechFrame = CreateFrame("ScrollFrame", "CzechQuestsSpeechFrame", UIParent, "UIPanelScrollFrameTemplate") local SpeechFrame = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
SpeechFrame:Hide() SpeechFrame:Hide()
local ContentFrame = CreateFrame("Frame", nil, SpeechFrame)
ContentFrame:Hide()
addon.SpeechFrame = SpeechFrame addon.SpeechFrame = SpeechFrame
SpeechFrame.ContentFrame = ContentFrame
function SpeechFrame:Init() function SpeechFrame:Init()
local frame = self local frame = self
-- Default style frame:SetHeight(50)
self:SetSize(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH, 150) frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
-- Make movable frame:SetScript("OnDragStart", function() frame:StartMoving() end)
self:SetMovable(true) frame:SetScript("OnDragStop", function(self)
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:StopMovingOrSizing() frame:StopMovingOrSizing()
local finalLeft, finalTop = self:GetLeft(), self:GetTop() local finalLeft = self:GetLeft() local finalBottom = self:GetBottom()
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = { CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X = math.floor(finalLeft)
x = finalLeft, CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y = math.floor(finalBottom)
y = finalTop
}
end) end)
-- Create ContentFrame frame:UpdateSettings()
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()
end end
function ContentFrame:Init() function SpeechFrame:UpdateSettings()
-- Default style self:SetWidth(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH)
self:SetSize(SpeechFrame:GetWidth(), 1)
-- Texture for control color and alpha -- Set position
self.Texture = self:CreateTexture(nil, "ARTWORK") self:SetPoint(
self.Texture:SetTexture("Interface\\Buttons\\WHITE8x8") "BOTTOMLEFT", UIParent, "BOTTOMLEFT",
self.Texture:SetVertexColor(0, 0, 0, 0.2) CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_X,
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION_Y
-- 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)
end end
function ContentFrame:CreateMessage(message) function SpeechFrame:CreateMessage(message)
-- Default style local frame = self
local MessageFrame = CreateFrame("Frame", nil, SpeechFrame.ContentFrame)
MessageFrame:SetSize(SpeechFrame.ContentFrame:GetWidth() - 20, 1) local MessageFrame = CreateFrame("Frame", nil, frame)
MessageFrame:SetSize(frame:GetWidth(), 1)
-- Define Message
MessageFrame.Message = addon.API.CreateCzechFont( MessageFrame.Message = addon.API.CreateCzechFont(
MessageFrame, MessageFrame,
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME, 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("TOPLEFT", MessageFrame, "TOPLEFT", 5, -5)
MessageFrame.Message:SetPoint("BOTTOMRIGHT", MessageFrame, "BOTTOMRIGHT", -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.Message:SetText(message)
MessageFrame:SetHeight(MessageFrame.Message:GetHeight() + 10) MessageFrame:SetHeight(MessageFrame.Message:GetHeight() + 10)
return MessageFrame return MessageFrame
end 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 -- Speech Settings
CzechQuestsAddon_Store.config.SPEECH_ENABLED = CzechQuestsAddon_Store.config.SPEECH_ENABLED or true 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_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_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_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 end
-- Event handler frame -- Event handler frame

21
sync.sh
View file

@ -1,19 +1,20 @@
#!/bin/bash #!/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="." 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" dest_folder="/Applications/World of Warcraft/_${wow_destiny_folder}_/Interface/AddOns/CzechQuests"
fswatch -o "$src_folder" | while read -r change; do fswatch -o "$src_folder" | while read -r change; do
rsync -avu --delete "$src_folder" "$dest_folder" --exclude={'.*','*.png','*.sh','*.md','Addon/Data/**','downloader/**'} 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/" 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/" cp "$src_folder/Addon/Data/other.lua" "$dest_folder/Addon/Data/"
done done