Quantcast

Added the ability to choose the color of the text

Christopher Tse [07-28-20 - 05:23]
Added the ability to choose the color of the text
Filename
ChatBubblePool.lua
MainFrame.lua
MainFrame.xml
Settings.lua
TotalRP3.lua
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 @@
 	<Script file="BlizzChatIntegration.lua" />
 	<Script file="TotalRP3.lua" />
 	<Frame name="MainFrame" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
-		<Size x="183" y="76" />
+		<Size x="187" y="76" />
 		<Anchors>
-			<Anchor point="CENTER" x="-9" y="29" />
+			<Anchor point="CENTER" x="-7" y="29" />
 		</Anchors>
 		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
 			<BackgroundInsets>
@@ -30,10 +30,28 @@
 		</Layers>
 		<Frames>
 			<Button name="CreateButton" inherits="UIPanelButtonTemplate" text="Create">
-				<Size x="152" y="23" />
+				<Size x="113" y="27" />
 				<Anchors>
 					<Anchor point="TOPLEFT" x="15" y="-35" />
 				</Anchors>
+				<Frames>
+					<Frame text="" name="ColorDropdownButton" inherits="UIDropDownMenuTemplate">
+						<Size x="20" y="23" />
+						<Anchors>
+							<Anchor point="TOPLEFT" relativeTo="CreateButton" relativePoint="TOPRIGHT" x="-16" y="0" />
+						</Anchors>
+						<Layers>
+							<Layer level="OVERLAY">
+								<Texture name="ColorSwatchTex" alpha="0.8">
+									<Size x="12" y="12" />
+									<Anchors>
+										<Anchor point="TOPLEFT" x="26" y="-8" />
+									</Anchors>
+								</Texture>
+							</Layer>
+						</Layers>
+					</Frame>
+				</Frames>
 				<Scripts>
 					<OnClick function="RPChatBubbles_createChatBubble">

@@ -43,7 +61,7 @@
 			<Button name="HideButton" inherits="UIPanelButtonTemplate" text="">
 				<Size x="20" y="20" />
 				<Anchors>
-					<Anchor point="TOPLEFT" x="149" y="-14" />
+					<Anchor point="TOPRIGHT" x="-14" y="-14" />
 				</Anchors>
 				<Layers>
 					<Layer>
@@ -64,7 +82,7 @@
 			<Button name="SettingsButton" inherits="UIPanelButtonTemplate" text="">
 				<Size x="20" y="20" />
 				<Anchors>
-					<Anchor point="TOPLEFT" x="127" y="-14" />
+					<Anchor point="TOPRIGHT" x="-36" y="-14" />
 				</Anchors>
 				<Layers>
 					<Layer>
diff --git a/Settings.lua b/Settings.lua
index e4e34d5..036d1bc 100644
--- a/Settings.lua
+++ b/Settings.lua
@@ -11,6 +11,13 @@ function initSettings()
 		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;
+	end
 	Import.settings = settings;
 end

diff --git a/TotalRP3.lua b/TotalRP3.lua
index a2ea1a2..5636b94 100644
--- a/TotalRP3.lua
+++ b/TotalRP3.lua
@@ -7,7 +7,7 @@ local _, Import = ...;
 local ellyb, loc, Color, ColorManager;
 local NPC_TALK_PATTERNS;
 local settings;
-
+local ChatBubblePool = Import.ChatBubblePool

 local function makeBubbleForNPCChat(_, event, message, ...)
 	if event == "CHAT_MSG_EMOTE" then
@@ -40,7 +40,7 @@ local function makeBubbleForNPCChat(_, event, message, ...)
 								npcName = npcName:sub(11);
 								npcName = npcName:sub(1,-3);
 							end
-						end
+						end
 						local len = talkType:len();
 						--Remove the "says:" from the beginning of the message.
 						if myMessage:sub(1, len) == talkType then
@@ -52,7 +52,7 @@ local function makeBubbleForNPCChat(_, event, message, ...)
 							end

 							actualMessage = color .. actualMessage;
-							local chatBubble = RPChatBubbles_createChatBubble()
+							local chatBubble = ChatBubblePool.getChatBubble()
 							chatBubble:SetName(npcName);
 							chatBubble:SetMessage(actualMessage);
 							if nameColor then