Quantcast

Made some fixes:

Christopher Tse [04-01-20 - 11:04]
Made some fixes:

- Fixed blizz chat bubble names being editable.
- Fixed blizz chat bubble to take into account the fact that the text
string is horizontally aligned with the center
- Fixed the RP Chat Bubble's name color so it resets on exit
- Fixed the RP Chat Bubble's name so it doesn't get reset when you try
to set another bubble's color.
Filename
BlizzChatIntegration.lua
ChatBubblePool.lua
diff --git a/BlizzChatIntegration.lua b/BlizzChatIntegration.lua
index a175441..a5d49fa 100644
--- a/BlizzChatIntegration.lua
+++ b/BlizzChatIntegration.lua
@@ -70,7 +70,7 @@ local function skinBubble(chatBubble)
 	NameText:SetFrameStrata("MEDIUM"); --This is the default but better to be explicit
 	--NameText:SetMultiLine(true);
 	NameText:SetAutoFocus(false);
-	--NameText:EnableMouse(false);
+	NameText:EnableMouse(false);
 	NameText:SetSize(700,11);
 	--NameText:SetPoint("CENTER");
 	NameText:SetPoint("BOTTOMLEFT",chatBubble,"TOPLEFT",13,2);
@@ -104,22 +104,25 @@ local function skinBubble(chatBubble)

 	local relativeTo, relativePoint, xOfs, yOfs = getNamedPoint(chatBubble,"BOTTOMRIGHT");
 	chatBubble.string = relativeTo;
+	--chatBubble.string:SetJustifyH("LEFT");
 	chatBubble.defaultXOfs = xOfs;
 	chatBubble.fixWidth = function(self)
 		local nameWidth = NameText.stringMeasure:GetWidth();
 		NameBg:SetWidth(nameWidth);
-		local stringWidth = self.string:GetStringWidth();
+		local stringWidth = self.string:GetWidth();
 		local expectedWidth = stringWidth + 32;
-		local requiredWidthForName = nameWidth + 14 + 2 + 16;
+		local requiredWidthForName = nameWidth + 13 + 2 + 16;
 		local defaultXOfs = self.defaultXOfs;
 		local relativeTo, relativePoint, xOfs, yOfs = getNamedPoint(self,"BOTTOMRIGHT");
 		local currHeight = self:GetHeight();
 		if ( expectedWidth < requiredWidthForName ) then
-			local diff = requiredWidthForName - expectedWidth;
-			self:SetPoint("BOTTOMRIGHT",relativeTo,relativePoint,defaultXOfs+diff,yOfs);
+			local adj = (requiredWidthForName - expectedWidth)/2;
+			self:SetPoint("TOPLEFT",relativeTo,"TOPLEFT",-(defaultXOfs+adj),-yOfs);
+			self:SetPoint("BOTTOMRIGHT",relativeTo,"BOTTOMRIGHT",defaultXOfs+adj,yOfs);
 		else
+			self:SetPoint("TOPLEFT",relativeTo,"TOPLEFT",-defaultXOfs,-yOfs);
 			self:SetPoint("BOTTOMRIGHT",relativeTo,relativePoint,defaultXOfs,yOfs);
-		end
+		end
 	end
 	chatBubble:fixWidth();

diff --git a/ChatBubblePool.lua b/ChatBubblePool.lua
index e6ffcf6..81022c0 100644
--- a/ChatBubblePool.lua
+++ b/ChatBubblePool.lua
@@ -49,10 +49,10 @@ end

 local function pickNameColor(chatBubble)
 	local r, g, b = chatBubble:GetNameColor()
-	ColorPickerFrame:SetColorRGB(r,g,b);
 	ColorPickerFrame.hasOpacity = false;
 	ColorPickerFrame.func = function(self) chatBubble:SetNameColor(ColorPickerFrame:GetColorRGB()) end;
 	ColorPickerFrame.cancelFunc = function(self) chatBubble:SetNameColor(r,g,b) end;
+	ColorPickerFrame:SetColorRGB(r,g,b);
 	ColorPickerFrame:Show();
 end

@@ -60,8 +60,10 @@ local function closeBubble(chatBubble)
 	chatBubble:Hide();
 	chatBubble:SetMessage("");
 	chatBubble:SetName("");
+
 	chatBubble.nameBox:SetAlpha(0.01)
 	chatBubble:ClearAllPoints();
+	chatBubble:ResetNameColor();
 	chatBubble:SetPoint("TOPLEFT",WorldFrame,"CENTER",-chatBubble.center.x,-chatBubble.center.y);
 	chatBubble.isAvailable = true;
 end
@@ -117,13 +119,13 @@ function ChatBubblePool.getChatBubble()
 		tile=true, tileSize=16, edgeSize=16,
 		insets={left=16, right=16, top=16, bottom=16}
 	})
-	chatBubbleBackground:EnableMouse(true)
-	chatBubbleBackground:SetPoint("TOPLEFT",editBox,"TOPLEFT",-16,16)
-	chatBubbleBackground:SetPoint("BOTTOMLEFT",editBox,"BOTTOMLEFT",-16,-16)
+	chatBubbleBackground:EnableMouse(true);
+	chatBubbleBackground:SetPoint("TOPLEFT",editBox,"TOPLEFT",-16,16);
+	chatBubbleBackground:SetPoint("BOTTOMLEFT",editBox,"BOTTOMLEFT",-16,-16);
 	chatBubbleBackground.padding = 32;
-	chatBubbleBackground:SetWidth(64 + chatBubbleBackground.padding)
-	chatBubbleBackground:SetFrameStrata("BACKGROUND")
-	chatBubbleBackground:EnableMouse(true)
+	chatBubbleBackground:SetWidth(64 + chatBubbleBackground.padding);
+	chatBubbleBackground:SetFrameStrata("BACKGROUND");
+	chatBubbleBackground:EnableMouse(true);
 	chatBubbleBackground:SetScript("OnMouseDown", function(self) newChatBubble:StartMoving() end )
 	chatBubbleBackground:SetScript("OnMouseUp", function(self) newChatBubble:StopMovingOrSizing() end )
 	editBox.background = chatBubbleBackground;
@@ -236,5 +238,8 @@ function ChatBubblePool.getChatBubble()
 	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;

+	local origR,origG,origB = nameBox:GetTextColor();
+	newChatBubble.ResetNameColor = function(self) self:SetNameColor(origR,origG,origB); end;
+
 	return newChatBubble
 end
\ No newline at end of file