From fcd85c0dfd4ca4126ab1fb89db13f10057f86154 Mon Sep 17 00:00:00 2001 From: Christopher Tse Date: Tue, 28 Jul 2020 15:23:49 +1000 Subject: [PATCH] Added the ability to choose the color of the text --- ChatBubblePool.lua | 4 ++- MainFrame.lua | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++- MainFrame.xml | 28 +++++++++++++++---- Settings.lua | 7 +++++ TotalRP3.lua | 6 ++--- 5 files changed, 111 insertions(+), 10 deletions(-) diff --git a/ChatBubblePool.lua b/ChatBubblePool.lua index 836a5f5..77c85d3 100644 --- a/ChatBubblePool.lua +++ b/ChatBubblePool.lua @@ -417,7 +417,9 @@ function ChatBubblePool.getChatBubble() newChatBubble.GetMessage = editBox.GetText; newChatBubble.SetMessage = function(self,message) editBox:SetText(message) end; newChatBubble.GetNameColor = function(self) return nameBox:GetTextColor() end; - newChatBubble.SetNameColor = function(self,r,g,b) nameBox:SetTextColor(r,g,b) nameBox.colorPickerTex:SetColorTexture(r,g,b) end; + newChatBubble.SetNameColor = function(self,r,g,b) nameBox:SetTextColor(r,g,b); nameBox.colorPickerTex:SetColorTexture(r,g,b) end; + newChatBubble.GetTextColor = function(self) return editBox:GetTextColor() end; + newChatBubble.SetTextColor = function(self,r,g,b) editBox:SetTextColor(r,g,b) end; local origR,origG,origB = nameBox:GetTextColor(); newChatBubble.ResetNameColor = function(self) self:SetNameColor(origR,origG,origB); end; diff --git a/MainFrame.lua b/MainFrame.lua index b856f32..e781820 100644 --- a/MainFrame.lua +++ b/MainFrame.lua @@ -26,11 +26,15 @@ function RPChatBubbles_OnEvent(self, event, ...) moduleStructure:OnStart(); end SetVisibility(self, settings.isFrameVisible); + initColorDropdown(); end end function RPChatBubbles_createChatBubble() - return ChatBubblePool.getChatBubble() + local bubble = ChatBubblePool.getChatBubble(); + local textColor = settings.textColor; + local selectedColor = settings.selectedColor; + bubble:SetTextColor(textColor.r,textColor.g,textColor.b); end function RPChatBubbles_toggleVisibility() @@ -46,6 +50,74 @@ function RPChatBubbles_showSettingsPanel(self, event, ...) Import.ShowSettingsPanel(); end +function initColorDropdown() + local dropdown = ColorDropdownButton; + UIDropDownMenu_SetWidth(dropdown, 28); + UIDropDownMenu_Initialize(dropdown, function(self, menu, level) + addMenuItem("Say",ChatTypeInfo["SAY"]); + addMenuItem("Say (NPC)",ChatTypeInfo["MONSTER_SAY"]); + addMenuItem("Yell",ChatTypeInfo["YELL"]); + addMenuItem("Whisper",ChatTypeInfo["WHISPER"]); + addMenuItem("Custom",nil,true); + end) + local rgb = settings.textColor; + if rgb then + ColorSwatchTex:SetColorTexture(rgb.r,rgb.g,rgb.b); + end +end + +function addMenuItem(text, color, custom) + local info = UIDropDownMenu_CreateInfo(); + info.text, info.arg1, info.arg2 = text, text, color; + if custom then + info.hasColorSwatch = true; + local rgb = settings.customColor; + info.r, info.g, info.b = rgb.r, rgb.g, rgb.b; + info.swatchFunc = setCustomColor; + info.cancelFunc = cancelCustomColor; + info.func = startCustomColorPicking; + else + info.colorCode = "|cFF" .. rgbToHex(color); + info.func = selectColor + end + if settings.selectedColor == text then + info.checked = true; + end + UIDropDownMenu_AddButton(info); +end + +function rgbToHex(color) + return string.format("%02x%02x%02x", color.r*255, color.g*255, color.b*255) +end + +function selectColor(self,channelColor,rgb,checked) + settings.selectedColor = channelColor; + settings.textColor = rgb; + ColorSwatchTex:SetColorTexture(rgb.r,rgb.g,rgb.b); +end + +function startCustomColorPicking(self) + previousSelection = settings.selectedColor; + previousColor = settings.textColor; + UIDropDownMenuButton_OpenColorPicker(self); +end + +function setCustomColor(previousSelection) + local rgb = {} + if previousSelection then + rgb = previousSelection + else + rgb.r, rgb.g, rgb.b = ColorPickerFrame:GetColorRGB() + end + selectColor(nil,"Custom",rgb); + settings.customColor = rgb; +end + +function cancelCustomColor() + settings.selectedColor = previousSelection; + settings.textColor = previousColor; +end + function SetVisibility(self, visible) if visible then self:SetAlpha(1.0); @@ -53,6 +125,7 @@ function SetVisibility(self, visible) removeVisibilityScripts(CreateButton); removeVisibilityScripts(SettingsButton); removeVisibilityScripts(HideButton); + removeVisibilityScripts(ColorDropdownButton); HideButtonTexture:SetTexture("Interface/Addons/RoleplayChatBubbles/button/UI-hideButton"); else self:SetAlpha(0.5); @@ -60,6 +133,7 @@ function SetVisibility(self, visible) addVisibilityScripts(CreateButton); addVisibilityScripts(SettingsButton); addVisibilityScripts(HideButton); + addVisibilityScripts(ColorDropdownButton); HideButtonTexture:SetTexture("Interface/Addons/RoleplayChatBubbles/button/UI-showButton"); end end diff --git a/MainFrame.xml b/MainFrame.xml index 62dc5cb..6e1b46c 100644 --- a/MainFrame.xml +++ b/MainFrame.xml @@ -3,9 +3,9 @@