From d2d243520e6070f90a5f70305200a4d0ab2394f6 Mon Sep 17 00:00:00 2001 From: Christopher Tse Date: Sat, 29 Aug 2020 23:05:05 +1000 Subject: [PATCH] Added the ability to automatically add the name of yourself or your target if you hold shift or control while creating a new bubble --- BlizzChatIntegration.lua | 2 +- ChatBubblePool.lua | 6 +- MainFrame.lua | 143 ++++++++++++++++++++++++++++++++++++++-------- Settings.lua | 57 ++++++++++++------ Settings.xml | 58 +++++++++++++------ TotalRP3.lua | 120 +++++++++++++++++++++++++++++++++++++- 6 files changed, 317 insertions(+), 69 deletions(-) diff --git a/BlizzChatIntegration.lua b/BlizzChatIntegration.lua index af1b211..75108a2 100644 --- a/BlizzChatIntegration.lua +++ b/BlizzChatIntegration.lua @@ -182,7 +182,7 @@ end local function onStart(self) settings = Import.settings; - if settings.dressBlizzBubbles then + if settings.get("DRESS_BLIZZ_BUBBLE") then for _, channel in pairs(MANAGED_CHANNELS) do ChatFrame_AddMessageEventFilter(channel, onChatMessage); end diff --git a/ChatBubblePool.lua b/ChatBubblePool.lua index 77c85d3..c2f5224 100644 --- a/ChatBubblePool.lua +++ b/ChatBubblePool.lua @@ -240,7 +240,7 @@ function ChatBubblePool.getChatBubble() newChatBubble:SetWidth(300) newChatBubble:SetHeight(300) newChatBubble:SetMovable(true) - newChatBubble:SetFrameStrata("LOW") + newChatBubble:SetFrameStrata("LOW"); newChatBubble.isAvailable = false table.insert(pool, newChatBubble); @@ -324,8 +324,8 @@ function ChatBubblePool.getChatBubble() nameBox:SetScript("OnTabPressed",function(self) editBox:SetFocus() end); nameBox:SetScript("OnEscapePressed",clearFocusAndSelection); nameBox:SetAlpha(0); - nameBox:SetScript("OnEditFocusGained", function(self) self:SetAlpha(1) end); - nameBox:SetScript("OnEditFocusLost", function(self) if self:GetText() == "" then self:SetAlpha(0.01) end end); + nameBox:SetScript("OnEditFocusGained", function(self) self:SetAlpha(1); nameBox:SetPropagateKeyboardInput(false); end); + nameBox:SetScript("OnEditFocusLost", function(self) if self:GetText() == "" then self:SetAlpha(0.01); end; nameBox:SetPropagateKeyboardInput(true); end); --nameBox:SetScript("OnClick", function(self) nameBox:SetFocus() end); nameBox:SetScript("OnEnter", function(self) if nameBox:GetText() == "" and not nameBox:HasFocus() then nameBox:SetAlpha(0.5) end end); nameBox:SetScript("OnLeave", function(self) if nameBox:GetText() == "" and not nameBox:HasFocus() then nameBox:SetAlpha(0) end end); diff --git a/MainFrame.lua b/MainFrame.lua index e781820..35248d8 100644 --- a/MainFrame.lua +++ b/MainFrame.lua @@ -3,64 +3,157 @@ local ADDON_NAME, Import = ...; -local ChatBubblePool = Import.ChatBubblePool +local ChatBubblePool = Import.ChatBubblePool; local settings; +local smartTargetColoringActive = false; +local savedColor; +local savedRGB; + +Import.SharedFunctions = {}; + function RPChatBubbles_OnLoad(self, event,...) self:SetClampedToScreen(true); self:RegisterEvent("ADDON_LOADED"); + self:RegisterEvent("MODIFIER_STATE_CHANGED"); + self:RegisterEvent("PLAYER_TARGET_CHANGED"); end function RPChatBubbles_OnEvent(self, event, ...) if event == "ADDON_LOADED" and ... == ADDON_NAME then Import:initSettings(); settings = Import.settings; - self:RegisterForDrag("LeftButton"); - self:SetScript("OnDragStart", function(self) - self:StartMoving(); - end); - self:SetScript("OnDragStop", function(self) - self:StopMovingOrSizing(); - end); + sharedFunctions = Import.SharedFunctions; + initMainFrame(self); for moduleName, moduleStructure in pairs(Import.modules) do moduleStructure:OnStart(); end - SetVisibility(self, settings.isFrameVisible); initColorDropdown(); + elseif event == "MODIFIER_STATE_CHANGED" then + handleKeyPress(); + elseif event == "PLAYER_TARGET_CHANGED" then + checkSmartTargetColoring(); end end function RPChatBubbles_createChatBubble() local bubble = ChatBubblePool.getChatBubble(); - local textColor = settings.textColor; - local selectedColor = settings.selectedColor; + local textColor = settings.get("SELECTED_COLOR_RGB"); + local selectedColor = settings.get("SELECTED_COLOR"); + local GetUnitNameAndColor = Import.SharedFunctions.GetUnitNameAndColor; + + + local unitID = nil; + + if IsShiftKeyDown() then + unitID = "player"; + elseif IsControlKeyDown() then + unitID = "target"; + end + bubble:SetTextColor(textColor.r,textColor.g,textColor.b); + + --If we are trying to populate the name field using shift or control, then enter this block. + --The method used will depend on whether TotalRP3 is installed or not + if unitID then + name, color = GetUnitNameAndColor(unitID); + if name then + bubble:SetName(name); + -- The Color will only be populated if TotalRP3 is enabled. + -- The variable type is the Ellyb Color() class. + if color then + bubble:SetNameColor(color:GetRGB()); + end + end + end end function RPChatBubbles_toggleVisibility() - if settings.isFrameVisible then - settings.isFrameVisible = false; + if settings.get("IS_FRAME_VISIBLE") then + settings.set("IS_FRAME_VISIBLE", false); else - settings.isFrameVisible = true + settings.set("IS_FRAME_VISIBLE", true); end - SetVisibility(MainFrame, settings.isFrameVisible); + SetVisibility(MainFrame, settings.get("IS_FRAME_VISIBLE")); end function RPChatBubbles_showSettingsPanel(self, event, ...) Import.ShowSettingsPanel(); end +function Import.SharedFunctions.GetUnitNameAndColor(unitID) + return UnitName(unitID), nil; +end + +---------------------------------------------------------- + +function initMainFrame(self) + self:RegisterForDrag("LeftButton"); + self:SetScript("OnDragStart", function(self) + self:StartMoving(); + end); + self:SetScript("OnDragStop", function(self) + self:StopMovingOrSizing(); + end); + SetVisibility(self, settings.get("IS_FRAME_VISIBLE")); +end + +function handleKeyPress() + if settings.get("CREATE_BUTTON_EXTRA_TEXT") then + if IsShiftKeyDown() then + CreateButton:SetText("Create (Self)"); + elseif IsControlKeyDown() then + CreateButton:SetText("Create (Target)"); + else + CreateButton:SetText("Create"); + end + end + checkSmartTargetColoring(); +end + +function checkSmartTargetColoring() + if not settings.get("SMART_COLORING") then + return + end + if IsControlKeyDown() and SayColorSelected() then + if not smartTargetColoringActive then + smartTargetColoringActive = true; + savedColor = settings.get("SELECTED_COLOR"); + savedRGB = settings.get("SELECTED_COLOR_RGB"); + end + + if UnitExists("target") then + if UnitIsPlayer("target") then + selectColor(nil,"Say",ChatTypeInfo["SAY"],nil); + else + selectColor(nil,"Say (NPC)",ChatTypeInfo["MONSTER_SAY"],nil); + end + else + selectColor(nil,savedColor,savedRGB,nil); + end + elseif smartTargetColoringActive and not IsControlKeyDown() then + smartTargetColoringActive = false; + selectColor(nil,savedColor,savedRGB,nil); + end +end + +function SayColorSelected() + selectedColor = settings.get("SELECTED_COLOR"); + return selectedColor == "Say" or selectedColor == "Say (NPC)"; +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("Emote",ChatTypeInfo["EMOTE"]); addMenuItem("Yell",ChatTypeInfo["YELL"]); addMenuItem("Whisper",ChatTypeInfo["WHISPER"]); addMenuItem("Custom",nil,true); end) - local rgb = settings.textColor; + local rgb = settings.get("SELECTED_COLOR_RGB"); if rgb then ColorSwatchTex:SetColorTexture(rgb.r,rgb.g,rgb.b); end @@ -71,7 +164,7 @@ function addMenuItem(text, color, custom) info.text, info.arg1, info.arg2 = text, text, color; if custom then info.hasColorSwatch = true; - local rgb = settings.customColor; + local rgb = settings.get("CUSTOM_COLOR"); info.r, info.g, info.b = rgb.r, rgb.g, rgb.b; info.swatchFunc = setCustomColor; info.cancelFunc = cancelCustomColor; @@ -80,7 +173,7 @@ function addMenuItem(text, color, custom) info.colorCode = "|cFF" .. rgbToHex(color); info.func = selectColor end - if settings.selectedColor == text then + if settings.get("SELECTED_COLOR") == text then info.checked = true; end UIDropDownMenu_AddButton(info); @@ -91,14 +184,14 @@ function rgbToHex(color) end function selectColor(self,channelColor,rgb,checked) - settings.selectedColor = channelColor; - settings.textColor = rgb; + settings.set("SELECTED_COLOR", channelColor); + settings.set("SELECTED_COLOR_RGB", rgb); ColorSwatchTex:SetColorTexture(rgb.r,rgb.g,rgb.b); end function startCustomColorPicking(self) - previousSelection = settings.selectedColor; - previousColor = settings.textColor; + previousSelection = settings.get("SELECTED_COLOR"); + previousColor = settings.get("SELECTED_COLOR_RGB"); UIDropDownMenuButton_OpenColorPicker(self); end @@ -110,12 +203,12 @@ function setCustomColor(previousSelection) rgb.r, rgb.g, rgb.b = ColorPickerFrame:GetColorRGB() end selectColor(nil,"Custom",rgb); - settings.customColor = rgb; + settings.set("CUSTOM_COLOR", rgb); end function cancelCustomColor() - settings.selectedColor = previousSelection; - settings.textColor = previousColor; + settings.set("SELECTED_COLOR", previousSelection); + settings.set("SELECTED_COLOR_RGB", previousColor); end function SetVisibility(self, visible) diff --git a/Settings.lua b/Settings.lua index 036d1bc..ac12893 100644 --- a/Settings.lua +++ b/Settings.lua @@ -3,25 +3,38 @@ local ADDON_NAME, Import = ...; +defaultValue = { + IS_FRAME_VISIBLE = true, + DRESS_BLIZZ_BUBBLE = true, + SMART_COLORING = true, + CREATE_BUTTON_EXTRA_TEXT = true, + + SELECTED_COLOR_RGB = { r = 1.0, g = 1.0, b = 1.0 }, + SELECTED_COLOR = "Say", + CUSTOM_COLOR = { r = 1.0, g = 1.0, b = 1.0 }, + + GENERATE_TOTAL_RP3_BUBBLES = true, + GENERATE_TOTAL_RP3_BUBBLES_FOR_OTHER_PLAYERS = true +} + function initSettings() if settings == nil then settings = {} - settings.isFrameVisible = true; - settings.dressBlizzBubbles = true; - settings.generateTotalRP3Bubbles = true; - settings.generateTotalRP3BubblesForOtherPlayers = true; end - if settings.selectedColor == nil then - c = {}; - c.r, c.g, c.b = 1.0, 1.0, 1.0 - settings.textColor = c; - settings.selectedColor = "Say" - settings.customColor = c; + settings.get = function(key) + if settings[key] == nil then + settings[key] = defaultValue[key]; + end + return settings[key]; + end + settings.set = function(key, value) + settings[key] = value; end Import.settings = settings; end function ConfigureFrameOnRuntime(self, event, ...) + --Check if TRP3 is installed and turn off the TRP3 options if it's not there. if TRP3_API == nil then totalRP3Header:SetFontObject("GameFontDisableLarge"); totalRP3GenerateOptionLabel:SetFontObject("GameFontDisable"); @@ -39,9 +52,12 @@ function ShowSettingsPanel() if not SettingsPanel:IsVisible() then SettingsPanel:Show() - DressBlizzBubbleCheck:SetChecked(settings.dressBlizzBubbles); - totalRP3GenerateCheck:SetChecked(settings.generateTotalRP3Bubbles); - totalRP3GenerateOtherCheck:SetChecked(settings.generateTotalRP3BubblesForOtherPlayers); + DressBlizzBubbleCheck:SetChecked(settings.get("DRESS_BLIZZ_BUBBLE")); + ExtraTextCheck:SetChecked(settings.get("CREATE_BUTTON_EXTRA_TEXT")); + SmartColoringCheck:SetChecked(settings.get("SMART_COLORING")); + totalRP3GenerateCheck:SetChecked(settings.get("GENERATE_TOTAL_RP3_BUBBLES")); + totalRP3GenerateOtherCheck:SetChecked(settings.get("GENERATE_TOTAL_RP3_BUBBLES_FOR_OTHER_PLAYERS")); + TotalRP3_onStart(); else CancelSettings(); @@ -49,7 +65,8 @@ function ShowSettingsPanel() end function ToggleReloadWarning(self, event, ...) - if settings.dressBlizzBubbles ~= DressBlizzBubbleCheck:GetChecked() then + --This function detects if the user has changed the Dress Blizz Bubble setting, which will show a reload required message on changed. + if settings.DRESS_BLIZZ_BUBBLE ~= DressBlizzBubbleCheck:GetChecked() then if not UIReloadWarningLabel:IsVisible() then UIReloadWarningLabel:Show(); SettingsPanel:SetSize(SettingsPanel:GetWidth(),SettingsPanel:GetHeight()+UIReloadWarningLabel:GetHeight()+5); @@ -63,12 +80,14 @@ function ToggleReloadWarning(self, event, ...) end function SaveSettings(self, event, ...) - local reloadRequired = settings.dressBlizzBubbles ~= DressBlizzBubbleCheck:GetChecked() + local reloadRequired = settings.DRESS_BLIZZ_BUBBLE ~= DressBlizzBubbleCheck:GetChecked() - settings.dressBlizzBubbles = DressBlizzBubbleCheck:GetChecked(); - settings.generateTotalRP3Bubbles = totalRP3GenerateCheck:GetChecked(); - settings.generateTotalRP3BubblesForOtherPlayers = totalRP3GenerateOtherCheck:GetChecked(); - + settings.DRESS_BLIZZ_BUBBLE = DressBlizzBubbleCheck:GetChecked(); + settings.GENERATE_TOTAL_RP3_BUBBLES = totalRP3GenerateCheck:GetChecked(); + settings.GENERATE_TOTAL_RP3_BUBBLES_FOR_OTHER_PLAYERS = totalRP3GenerateOtherCheck:GetChecked(); + settings.SMART_COLORING = SmartColoringCheck:GetChecked(); + settings.CREATE_BUTTON_EXTRA_TEXT = ExtraTextCheck:GetChecked(); + SettingsPanel:Hide(); if reloadRequired then ReloadUI() diff --git a/Settings.xml b/Settings.xml index 41aa1e9..de4ab98 100644 --- a/Settings.xml +++ b/Settings.xml @@ -2,10 +2,10 @@