diff --git a/lib/accounts.js b/lib/accounts.js index 5429bae..03d0df3 100644 --- a/lib/accounts.js +++ b/lib/accounts.js @@ -61,6 +61,7 @@ const USER_VAR_SETTINGS = 363; // the settings menu's switches, a bit each (gui. // the chat filter an account starts with: level 1 slurs and threats, mode 1 // the whole message left out (see account.filter below). const DEFAULT_FILTER = {level: 1, mode: 1, words: ""}; +const chatStyles = require("./chatstyles.js"); const MAX_PASSWORD_LENGTH = 100; const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // parts of the game a player can switch off for their own account, each @@ -250,6 +251,9 @@ const normalize = account => { // the name tag: colour in the low byte, badge above it, bit 16 hides the // adventure level shape (avatar.NameBar.setColorAndBadge). account.nameBarData = Number.isInteger(account.nameBarData) ? account.nameBarData : 0; + // Personal chat appearance. The renderer receives it with each spoken line + // (lib/world.js), never as a client-controlled packet field. + account.chatStyle = chatStyles.normalize(account.chatStyle); account.disguise = Number.isInteger(account.disguise) ? account.disguise : 0; // NPC id, see lib/disguises.js // shown on the player's card: lib/badges.js. account.discord = typeof account.discord === "string" ? account.discord : ""; // their Discord username, as Discord gave it (lib/discord.js) diff --git a/lib/chatstyles.js b/lib/chatstyles.js new file mode 100644 index 0000000..4198032 --- /dev/null +++ b/lib/chatstyles.js @@ -0,0 +1,79 @@ +"use strict"; + +// The style travels with a chat line, rather than with an avatar-create +// packet, so a new choice takes effect immediately and is seen by everybody +// who sees that line. Keep it small and entirely server-generated: clients +// never get to choose the fields sent to other players. +const DEFAULT = Object.freeze({background: "ffffff", accent: "dfe8ff", text: "445559", border: "9aabb0", opacity: 75, + animation: "none", speed: 100, gradient: "linear", angle: 45, strength: 100, outline: 1, + stops: "ffffff:0;dfe8ff:100"}); +const ANIMATIONS = new Set(["none", "pulse", "shimmer", "flow", "rainbow"]); +const GRADIENTS = new Set(["solid", "linear", "radial"]); +const COLOR = /^[0-9a-f]{6}$/i; + +const color = (value, fallback) => typeof value === "string" && COLOR.test(value) ? value.toLowerCase() : fallback; +const number = (value, fallback, low, high) => Number.isInteger(value) && value >= low && value <= high ? value : fallback; +const direction = value => { + const angle = number(value, DEFAULT.angle, 0, 315); + return angle % 45 === 0 ? angle : DEFAULT.angle; +}; + +const stops = (value, background, accent) => { + if (typeof value === "string") { + const parsed = value.split(";").map(stop => { + const match = /^([0-9a-f]{6}):(100|[1-9]?\d)$/i.exec(stop); + return match ? {color: match[1].toLowerCase(), position: Number(match[2])} : null; + }); + if (parsed.length >= 2 && parsed.length <= 5 && parsed.every(Boolean) + && parsed[0].position === 0 && parsed.at(-1).position === 100 + && parsed.every((stop, index) => index === 0 || stop.position > parsed[index - 1].position)) { + return parsed.map(stop => `${stop.color}:${stop.position}`).join(";"); + } + } + return `${background}:0;${accent}:100`; +}; + +const normalize = value => { + const source = value && typeof value === "object" && !Array.isArray(value) ? value : {}; + let background = color(source.background, DEFAULT.background); + let accent = color(source.accent, DEFAULT.accent); + const gradientStops = stops(source.stops, background, accent); + const stopParts = gradientStops.split(";"); + background = stopParts[0].slice(0, 6); + accent = stopParts.at(-1).slice(0, 6); + return { + background, + accent, + text: color(source.text, DEFAULT.text), + border: color(source.border, DEFAULT.border), + opacity: number(source.opacity, DEFAULT.opacity, 25, 100), + animation: ANIMATIONS.has(source.animation) ? source.animation : DEFAULT.animation, + speed: number(source.speed, DEFAULT.speed, 40, 300), + gradient: GRADIENTS.has(source.gradient) ? source.gradient : DEFAULT.gradient, + angle: direction(source.angle), + strength: number(source.strength, DEFAULT.strength, 0, 100), + outline: number(source.outline, DEFAULT.outline, 0, 4), + stops: gradientStops, + }; +}; + +const same = (one, two) => Object.keys(DEFAULT).every(key => one[key] === two[key]); + +// `normalize` is intentionally forgiving when old account data is loaded. +// Incoming editor requests are not: every field must already be canonical. +const valid = value => Boolean(value) && typeof value === "object" && !Array.isArray(value) + && Object.keys(DEFAULT).every(key => value[key] === normalize(value)[key]); + +const fields = value => { + const style = normalize(value); + return [style.background, style.accent, style.text, style.border, style.opacity, style.animation, style.speed, + style.gradient, style.angle, style.strength, style.outline, style.stops]; +}; + +// Twelve comma-separated, URL-safe fields; empty means the original game bubble. +const packet = value => { + const style = normalize(value); + return same(style, DEFAULT) ? "" : fields(style).join(","); +}; + +module.exports = {DEFAULT, normalize, valid, fields, packet}; diff --git a/lib/manage.js b/lib/manage.js index 79655ce..6f38084 100644 --- a/lib/manage.js +++ b/lib/manage.js @@ -24,6 +24,7 @@ const support = require("./support.js"); const totp = require("./totp.js"); const recoveryMail = require("./recoverymail.js"); const world = require("./world.js"); +const chatStyles = require("./chatstyles.js"); // the account page at /account: what a player can do about their own // account from a browser. they sign in with the game's username and @@ -168,6 +169,7 @@ const profile = (account, from) => { logins: account.numLogins || 0, playtime: account.playtime, playtimePublic: account.playtimePublic, + chatStyle: chatStyles.normalize(account.chatStyle), animals: account.avatars.length, animalType: avatar ? avatar.type : null, items: account.items.length, @@ -428,6 +430,17 @@ const act = (account, body, req, from, res) => { account.playtimePublic = body.on === true; accounts.save(account); return {ok: account.playtimePublic ? "Others can see your playtime on your card." : "Your playtime is private."}; + // A player can choose every colour, opacity, animation and animation + // speed. Validation is deliberately here as well as in the page: saved + // state is not trusted just because it came from our own browser UI. + case "chatStyle": { + if (!chatStyles.valid(body.style)) { + return {error: "Choose valid chat colours and animation settings."}; + } + account.chatStyle = chatStyles.normalize(body.style); + accounts.save(account); + return {ok: "Chat style saved. Your next message will use it."}; + } // their Discord account, for their card in the game: it is linked by // signing in to Discord (GET /account/discord/link), and only taken off // here, with the booster badge it brought. diff --git a/lib/world.js b/lib/world.js index 296695f..b64ca02 100644 --- a/lib/world.js +++ b/lib/world.js @@ -21,6 +21,7 @@ const devices = require("./devices.js"); const chatlog = require("./chatlog.js"); const chatFilter = require("./chatfilter.js"); const chatSpam = require("./chatspam.js"); +const chatStyles = require("./chatstyles.js"); const buddyModule = require("./buddies.js"); const dens = require("./dens.js"); const disguises = require("./disguises.js"); @@ -627,6 +628,10 @@ const sendFilter = session => { session.sendXt("xfl", -1, filter.chosen ? 1 : 0, filter.level, filter.mode, filter.words); }; +// The in-game editor asks for this on demand too. It receives only canonical +// values, so the Flash client never has to guess at a missing account field. +const sendChatStyle = session => session.sendXt("xcs", -1, ...chatStyles.fields(session.account.chatStyle)); + // the player called `username` as the senders above take one: their session // when they are playing, else just their account. A player's card can be // opened for anybody (the buddy list, the player search), and it asks for @@ -653,6 +658,25 @@ const handlers = { sendFilter(session); }, + // The Settings > Chat Bubble popup. An empty request just reloads the + // saved setting; a complete twelve-field request replaces it. Older custom + // clients remain accepted and receive a two-stop gradient automatically. + xcs(session, roomId, params) { + if (params.length === 0) { + sendChatStyle(session); + return; + } + if (![7, 10, 11, 12].includes(params.length)) return; + const [background, accent, text, border, opacity, animation, speed, gradient = "linear", angle = 45, strength = 100, outline = 1, + stops = `${background}:0;${accent}:100`] = params; + const style = {background, accent, text, border, opacity: Number(opacity), animation, speed: Number(speed), + gradient, angle: Number(angle), strength: Number(strength), outline: Number(outline), stops}; + if (!chatStyles.valid(style)) return; + session.account.chatStyle = style; + accounts.save(session.account); + sendChatStyle(session); + }, + // the patched client's hex colour picker (gui.ColorTable): [rgb1, rgb2, // rgb3, rgb4], the four colours of one layer. everyone online is told the // entry's id, the asker included, who then uses it as that layer's colour. @@ -1918,12 +1942,18 @@ module.exports = { // nobody hears a player they have blocked, and with chat switched // off nobody's typed lines arrive at all. // an invisible staff member's emotes and the like reach staff only. + // Typed chat always gets a third (stock "extra") field, followed by + // its style. Keeping message and type at their original indexes is + // what clears the local "..." bubble; carrying the style on the + // same packet prevents it being lost or applied to a later line. + const style = echo ? chatStyles.packet(session.account.chatStyle) : ""; for (const recipient of (echo || attachmentEcho) ? session.room.sessions : others(session)) { if (session.invisible && recipient !== session && !roles.isActiveStaff(recipient.account)) { continue; } if (recipient === session || (!blocks.has(recipient.account, session.account) && (!echo || accounts.featureOn(recipient.account, "chat")))) { - recipient.sendXt("uc", session.room.id, session.id, ...fields); + recipient.sendXt("uc", session.room.id, session.id, + ...(echo && style ? [fields[0], fields[1], fields[2] || "", style] : fields)); } } } diff --git a/public/account.html b/public/account.html index 65bfe24..9638209 100644 --- a/public/account.html +++ b/public/account.html @@ -116,7 +116,7 @@ line-height: 17px; text-align: center; } - @media (prefers-reduced-motion: reduce) { * { transition: none !important; } } + @media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } } .wrap { max-width: 760px; margin: 0 auto; } label.check { display: flex; align-items: center; color: var(--text); font-size: 14px; cursor: pointer; } /* dark on white whatever the page: that is what a phone's camera reads. */ @@ -175,6 +175,26 @@ .ban-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; } .ban-head img { width: 44px; height: 44px; flex: none; } .ban-head h2 { margin: 0; font-size: 22px; } + .chat-style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; } + .chat-style-grid input[type="color"] { width: 100%; height: 42px; padding: 3px; cursor: pointer; } + .gradient-editor { margin: 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: 12px; } + .gradient-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; } + .gradient-stops { display: grid; gap: 8px; } + .gradient-ramp { height: 22px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 999px; } + .gradient-stop { display: grid; grid-template-columns: 50px minmax(100px, 1fr) 72px auto; align-items: center; gap: 8px; } + .gradient-stop input[type="color"] { width: 50px; height: 36px; padding: 2px; cursor: pointer; } + .gradient-stop input[type="range"] { margin: 0; } + .gradient-stop output { color: var(--muted); font-size: 12px; text-align: right; } + .chat-preview { min-height: 74px; display: grid; place-items: center; margin-top: 14px; padding: 12px 18px; border: 1px solid var(--line); border-radius: 18px; text-align: center; font-weight: 700; background: linear-gradient(120deg, #fff, #dfe8ff); color: #445559; } + .chat-preview.pulse { animation: chatPulse 1.5s ease-in-out infinite alternate; } + .chat-preview.shimmer { background-size: 250% 100%; animation: chatShimmer 1.5s linear infinite; } + .chat-preview.flow { background-size: 220% 220%; animation: chatFlow 1.5s linear infinite alternate; } + .chat-preview.rainbow { animation: chatRainbow 2s linear infinite; } + @keyframes chatPulse { to { opacity: .55; } } + @keyframes chatShimmer { to { background-position: 100% 0; } } + @keyframes chatFlow { to { background-position: 100% 100%; } } + @keyframes chatRainbow { to { filter: hue-rotate(360deg); } } + @media (max-width: 440px) { .chat-style-grid { grid-template-columns: 1fr; } } #ban-section pre { margin: 0 0 12px; font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; } #ban-section h3 { margin: 18px 0 0; } @@ -354,6 +374,35 @@

+
+

Chat bubble

+

Choose how your spoken chat bubbles look for everyone using Burrow's current client.

+
+
+
Gradient colours
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
Your chat bubble preview
+
+
+
+

+
+

Playtime

@@ -504,8 +553,12 @@ ]; const VIA = {game: "Game", launcher: "Client", web: "This page", mod: "Moderator panel"}; const ANIMALS = {1: "Tiger", 4: "Wolf", 5: "Koala", 6: "Panda", 7: "Monkey", 8: "Bunny", 13: "Rhino", 18: "Seal", 24: "Penguin"}; + const DEFAULT_CHAT_STYLE = {background: "ffffff", accent: "dfe8ff", text: "445559", border: "9aabb0", opacity: 75, + animation: "none", speed: 100, gradient: "linear", angle: 45, strength: 100, outline: 1, + stops: "ffffff:0;dfe8ff:100"}; let account = null; + let chatStops = []; let twoStepSetup = null; // {secret, uri} while two-step sign-in is being turned on let twoStepCodes = null; // the recovery codes, until the player says they kept them @@ -527,6 +580,126 @@ $(id).classList.toggle("bad", bad); }; + const parseChatStops = style => { + const parsed = String(style.stops || "").split(";").map(value => { + const match = /^([0-9a-f]{6}):(100|[1-9]?\d)$/i.exec(value); + return match ? {color: match[1].toLowerCase(), position: Number(match[2])} : null; + }); + return parsed.length >= 2 && parsed.length <= 5 && parsed.every(Boolean) + ? parsed : [{color: style.background, position: 0}, {color: style.accent, position: 100}]; + }; + + const styleValue = () => { + if (chatStops.length < 2) chatStops = parseChatStops(DEFAULT_CHAT_STYLE); + chatStops.sort((one, two) => one.position - two.position); + chatStops[0].position = 0; + chatStops.at(-1).position = 100; + const background = chatStops[0].color; + const accent = chatStops.at(-1).color; + $("chat-background").value = `#${background}`; + $("chat-accent").value = `#${accent}`; + return { + background, accent, + text: $("chat-text-colour").value.slice(1).toLowerCase(), + border: $("chat-border").value.slice(1).toLowerCase(), + opacity: Number($("chat-opacity").value), + animation: $("chat-animation").value, + speed: Number($("chat-speed").value), + gradient: $("chat-gradient").value, + angle: Number($("chat-angle").value), + strength: Number($("chat-strength").value), + outline: Number($("chat-outline").value), + stops: chatStops.map(stop => `${stop.color}:${stop.position}`).join(";"), + }; + }; + + const paintChatPreview = () => { + const style = styleValue(); + const preview = $("chat-preview"); + preview.className = `chat-preview ${style.animation}`; + const mix = (one, two, amount) => one.map((part, index) => Math.round(part + (two[index] - part) * amount)); + const rgb = hex => [0, 2, 4].map(at => parseInt(hex.slice(at, at + 2), 16)); + const stops = parseChatStops(style).map((stop, index) => { + const colour = index ? mix(rgb(style.background), rgb(stop.color), style.strength / 100) : rgb(stop.color); + return `#${colour.map(part => part.toString(16).padStart(2, "0")).join("")} ${stop.position}%`; + }).join(", "); + preview.style.background = style.gradient === "solid" ? `#${style.background}` : style.gradient === "radial" + ? `radial-gradient(circle, ${stops})` + : `linear-gradient(${style.angle}deg, ${stops})`; + preview.style.color = `#${style.text}`; + preview.style.borderColor = `#${style.border}`; + preview.style.borderWidth = `${style.outline}px`; + preview.style.opacity = String(style.opacity / 100); + preview.style.animationDuration = `${Math.max(.25, 1.5 * 100 / style.speed)}s`; + $("chat-opacity-value").textContent = `${style.opacity}%`; + $("chat-speed-value").textContent = `${style.speed}%`; + $("chat-strength-value").textContent = `${style.strength}%`; + $("chat-outline-value").textContent = `${style.outline}px`; + }; + + const renderChatStops = () => { + chatStops.sort((one, two) => one.position - two.position); + const holder = $("chat-stops"); + holder.replaceChildren(); + $("chat-ramp").style.background = `linear-gradient(90deg, ${chatStops.map(stop => `#${stop.color} ${stop.position}%`).join(", ")})`; + chatStops.forEach((stop, index) => { + const row = el("div", undefined, "gradient-stop"); + const colour = document.createElement("input"); + colour.type = "color"; + colour.value = `#${stop.color}`; + colour.setAttribute("aria-label", `Gradient colour ${index + 1}`); + const position = document.createElement("input"); + position.type = "range"; + position.min = String(index ? chatStops[index - 1].position + 1 : 0); + position.max = String(index < chatStops.length - 1 ? chatStops[index + 1].position - 1 : 100); + position.value = String(stop.position); + position.disabled = index === 0 || index === chatStops.length - 1; + const value = document.createElement("output"); + value.textContent = index === 0 ? "Start" : index === chatStops.length - 1 ? "End" : `${stop.position}%`; + const remove = document.createElement("button"); + remove.type = "button"; + remove.textContent = "Remove"; + remove.disabled = chatStops.length <= 2; + colour.addEventListener("input", () => { + stop.color = colour.value.slice(1).toLowerCase(); + renderChatStops(); + paintChatPreview(); + }); + position.addEventListener("input", () => { + stop.position = Number(position.value); + value.textContent = `${stop.position}%`; + $("chat-ramp").style.background = `linear-gradient(90deg, ${chatStops.map(item => `#${item.color} ${item.position}%`).join(", ")})`; + paintChatPreview(); + }); + remove.addEventListener("click", () => { + chatStops.splice(index, 1); + renderChatStops(); + paintChatPreview(); + }); + row.append(colour, position, value, remove); + holder.append(row); + }); + $("chat-stop-add").disabled = chatStops.length >= 5; + }; + + const fillChatStyle = style => { + style = {...DEFAULT_CHAT_STYLE, ...style}; + chatStops = parseChatStops(style); + $("chat-background").value = `#${style.background}`; + $("chat-accent").value = `#${style.accent}`; + $("chat-text-colour").value = `#${style.text}`; + $("chat-border").value = `#${style.border}`; + $("chat-opacity").value = String(style.opacity); + $("chat-animation").value = style.animation; + $("chat-speed").value = String(style.speed); + $("chat-gradient").value = style.gradient; + $("chat-angle").value = String(style.angle); + $("chat-strength").value = String(style.strength); + $("chat-outline").value = String(style.outline); + renderChatStops(); + paintChatPreview(); + }; + const api = async (path, body) => { try { const response = await fetch(`/account/api/${path}`, body === undefined ? {} : { @@ -757,6 +930,9 @@ } renderMyItems(); $("lock-notice").hidden = !account.locked; + if (!$("chat-style-form").contains(document.activeElement)) { + fillChatStyle(account.chatStyle); + } const tiles = [ [account.online ? "Playing now" : account.lastSeen ? when(account.lastSeen) : "Not played yet", "Last seen"], @@ -1343,6 +1519,44 @@ }); $("bio-remove").addEventListener("click", () => act({action: "bio", text: ""}, "bio-status")); + ["chat-background", "chat-accent", "chat-text-colour", "chat-border", "chat-opacity", "chat-gradient", "chat-angle", "chat-strength", "chat-outline", "chat-animation", "chat-speed"].forEach(id => { + $(id).addEventListener("input", paintChatPreview); + $(id).addEventListener("change", paintChatPreview); + }); + $("chat-style-form").addEventListener("submit", async event => { + event.preventDefault(); + await act({action: "chatStyle", style: styleValue()}, "chat-style-status"); + }); + $("chat-stop-add").addEventListener("click", () => { + if (chatStops.length >= 5) return; + let gapAt = 0; + for (let index = 1; index < chatStops.length - 1; index++) { + if (chatStops[index + 1].position - chatStops[index].position > chatStops[gapAt + 1].position - chatStops[gapAt].position) gapAt = index; + } + const before = chatStops[gapAt]; + const after = chatStops[gapAt + 1]; + const rgb = hex => [0, 2, 4].map(at => parseInt(hex.slice(at, at + 2), 16)); + const mixed = rgb(before.color).map((part, index) => Math.round((part + rgb(after.color)[index]) / 2).toString(16).padStart(2, "0")).join(""); + chatStops.splice(gapAt + 1, 0, {color: mixed, position: Math.round((before.position + after.position) / 2)}); + renderChatStops(); + paintChatPreview(); + }); + $("chat-style-swap").addEventListener("click", () => { + chatStops = chatStops.slice().reverse().map(stop => ({color: stop.color, position: 100 - stop.position})); + renderChatStops(); + paintChatPreview(); + }); + $("chat-style-random").addEventListener("click", () => { + const randomColour = () => Math.floor(Math.random() * 0x1000000).toString(16).padStart(6, "0"); + chatStops.forEach(stop => { stop.color = randomColour(); }); + renderChatStops(); + paintChatPreview(); + }); + $("chat-style-reset").addEventListener("click", async () => { + fillChatStyle(DEFAULT_CHAT_STYLE); + await act({action: "chatStyle", style: DEFAULT_CHAT_STYLE}, "chat-style-status"); + }); + // off to Discord's sign-in; it comes back to /account?discord= $("discord-link").addEventListener("click", () => { location.href = "/account/discord/link"; diff --git a/swf-src/AvatarWorldView.as b/swf-src/AvatarWorldView.as index f3db3b9..61bbcbf 100644 --- a/swf-src/AvatarWorldView.as +++ b/swf-src/AvatarWorldView.as @@ -229,6 +229,11 @@ package avatar private var _chatBalloon:ChatBalloon; + // Set while the normal uc packet is handled, immediately before its + // message is drawn. Keeping setMessage's original arguments preserves + // the game's pending-message and chat-history behaviour. + private var _nextChatStyle:String = ""; + // "..." where the chat bubble goes, while the player is typing // (AJClient.onTyping). gone when a line arrives, when they stop, or // TYPING_SHOWN ms after they last said they were, if a "stopped" is lost. @@ -1176,6 +1181,11 @@ package avatar } } + public function setChatStyle(param1:String) : void + { + _nextChatStyle = param1; + } + public function setMessage(param1:String, param2:int) : void { var _loc3_:Boolean = false; @@ -1191,8 +1201,9 @@ package avatar } _loc3_ = true; } - _chatBalloon.setText(param1,_loc3_); - updateOffScreenChat(param1,_loc3_); + _chatBalloon.setText(param1,_loc3_,true,_nextChatStyle); + updateOffScreenChat(param1,_loc3_,_nextChatStyle); + _nextChatStyle = ""; } public function setCustomAdventureMessage(param1:String, param2:String, param3:int, param4:int, param5:Boolean = false) : void @@ -2593,11 +2604,11 @@ package avatar _secondaryEmot.y = -235 * _loc1_; } - private function updateOffScreenChat(param1:String, param2:Boolean) : void + private function updateOffScreenChat(param1:String, param2:Boolean, param3:String = "") : void { if(shouldShowOffscreen() && gMainFrame.userInfo.myUserName != _avatar.userName && _hudViewHolder) { - _hudViewHolder.questChatBalloon.setText(param1,param2,false); + _hudViewHolder.questChatBalloon.setText(param1,param2,false,param3); } } diff --git a/swf-src/ChatBalloon.as b/swf-src/ChatBalloon.as index b4d0d69..1884b06 100644 --- a/swf-src/ChatBalloon.as +++ b/swf-src/ChatBalloon.as @@ -1,12 +1,19 @@ package gui { + import flash.display.Bitmap; + import flash.display.BitmapData; import flash.display.MovieClip; + import flash.display.DisplayObject; import flash.display.Sprite; + import flash.display.GradientType; + import flash.display.SpreadMethod; import flash.events.MouseEvent; import flash.events.TextEvent; + import flash.filters.ConvolutionFilter; import flash.geom.ColorTransform; import flash.geom.Point; import flash.geom.Rectangle; + import flash.geom.Matrix; import flash.text.TextField; import flash.utils.setTimeout; import loader.MediaHelper; @@ -71,13 +78,36 @@ package gui // emoji panel, say), which the game's font has none of: each is drawn // as a picture of it, from the server (/emoji/.png, // Twemoji's). each is {at, clip}: where its gap starts in the text shown. - // Three spaces fit the line-height-sized emoji without the noticeably - // wide hole four spaces left between neighbouring words or emoji. - private static const INLINE_GAP:String = " "; + // Four spaces reserve a full inline cell. placeInline() scales wide + // artwork to this measured slot with a one-pixel gutter on each side, + // so consecutive emoji neither overlap nor touch surrounding text. + private static const INLINE_GAP:String = " "; private static const LONGEST_EMOTE_CODE:int = 16; private var _inline:Array = []; + + // The server appends this compact style to spoken chat packets. It is + // deliberately drawn over the stock balloon rather than requiring new + // artwork, so every combination of the account-page colour controls is + // available at once. + private var _styleFill:Sprite; + private var _styleMask:Bitmap; + private var _styleBorderLayer:Bitmap; + private var _styleBackground:uint; + private var _styleAccent:uint; + private var _styleText:uint; + private var _styleBorder:uint; + private var _styleOpacity:Number; + private var _styleAnimation:String = "none"; + private var _styleSpeed:Number = 100; + private var _styleGradient:String = "linear"; + private var _styleAngle:Number = 45; + private var _styleStrength:Number = 100; + private var _styleOutline:Number = 1; + private var _styleStops:Array = []; + private var _styleElapsed:int = 0; + private var _hasStyle:Boolean = false; public function ChatBalloon() { @@ -112,7 +142,7 @@ package gui setEmoteBgOffsets(); } - public function setText(param1:String, param2:Boolean = false, param3:Boolean = true) : void + public function setText(param1:String, param2:Boolean = false, param3:Boolean = true, param4:String = "") : void { if(_emote) { @@ -142,7 +172,8 @@ package gui _msgTxt.height; // AJClient.whisperNext is set by the server's "xw" just ahead of a // whispered line. - _balloonBG.transform.colorTransform = AJClient.whisperNext ? AJClient.whisperTint() : new ColorTransform(); + var _loc10_:Boolean = AJClient.whisperNext; + _balloonBG.transform.colorTransform = _loc10_ ? AJClient.whisperTint() : new ColorTransform(); AJClient.whisperNext = false; if(!_hasSbTextfield) { @@ -172,6 +203,10 @@ package gui { _msgTxt.textColor = 4477529; } + // Emoji-window choices are inline chat content, so even a lone one + // keeps the selected chat style. Standalone game emotes use + // setEmote(), where any previous custom bubble is cleared. + applyStyle(param4,param2,_loc10_); // tags (AJClient.resolveMentions): once the server says which "@"s // are players', light blue and underlined, each a link to that // player's card, if the balloon still says the same. (the field is @@ -199,6 +234,12 @@ package gui } }); } + // The stock balloon has now stretched to the measured text height; + // redraw the custom body at its final size (also for still styles). + if(_hasStyle) + { + drawStyle(); + } _timeout = 8000; if(param3 && this.parent) { @@ -212,6 +253,311 @@ package gui setTimeout(placeInline,42); } } + + // `background,accent,text,border,opacity,animation,speed,gradient,angle, + // strength,outline,stops`, emitted by + // lib/chatstyles.js. Staff warnings and whispers intentionally retain + // their existing colours, so those states are never made ambiguous. + private function applyStyle(param1:String, param2:Boolean, param3:Boolean) : void + { + clearStyle(); + if(param1 == "" || param2 || param3 || !GuiManager.customChatBubblesEnabled()) + { + return; + } + var _loc4_:Array = param1.split(","); + if((_loc4_.length != 7 && _loc4_.length != 10 && _loc4_.length != 11 && _loc4_.length != 12) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[0]) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[1]) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[2]) || !/^[0-9a-fA-F]{6}$/.test(_loc4_[3]) || !/^(?:2[5-9]|[3-9][0-9]|100)$/.test(_loc4_[4]) || !/^(?:[4-9][0-9]|[12][0-9]{2}|300)$/.test(_loc4_[6])) + { + return; + } + _styleBackground = uint(parseInt(_loc4_[0],16)); + _styleAccent = uint(parseInt(_loc4_[1],16)); + _styleText = uint(parseInt(_loc4_[2],16)); + _styleBorder = uint(parseInt(_loc4_[3],16)); + _styleOpacity = Math.max(0.25,Math.min(1,Number(_loc4_[4]) / 100)); + _styleAnimation = _loc4_[5] == "pulse" || _loc4_[5] == "shimmer" || _loc4_[5] == "flow" || _loc4_[5] == "rainbow" ? _loc4_[5] : "none"; + _styleSpeed = Math.max(40,Math.min(300,Number(_loc4_[6]))); + _styleGradient = _loc4_.length > 7 && (_loc4_[7] == "solid" || _loc4_[7] == "radial") ? _loc4_[7] : "linear"; + _styleAngle = _loc4_.length > 8 && int(_loc4_[8]) >= 0 && int(_loc4_[8]) <= 315 && int(_loc4_[8]) % 45 == 0 ? int(_loc4_[8]) : 45; + _styleStrength = _loc4_.length > 9 ? Math.max(0,Math.min(100,int(_loc4_[9]))) : 100; + _styleOutline = _loc4_.length > 10 ? Math.max(0,Math.min(4,int(_loc4_[10]))) : 1; + _styleStops = parseStyleStops(_loc4_.length > 11 ? String(_loc4_[11]) : ""); + _styleElapsed = 0; + _hasStyle = true; + _msgTxt.textColor = _styleText; + // The native artwork remains underneath as the exact outer border; + // drawStyle masks the custom fill to that artwork's silhouette. + _balloonBG.transform.colorTransform = colourTransform(_styleBorder,1); + } + + private function clearStyle() : void + { + if(_styleFill) + { + _styleFill.mask = null; + } + if(_styleFill && _styleFill.parent) + { + _styleFill.parent.removeChild(_styleFill); + } + if(_styleMask) + { + if(_styleMask.parent) + { + _styleMask.parent.removeChild(_styleMask); + } + if(_styleMask.bitmapData) + { + _styleMask.bitmapData.dispose(); + } + } + if(_styleBorderLayer) + { + if(_styleBorderLayer.parent) + { + _styleBorderLayer.parent.removeChild(_styleBorderLayer); + } + if(_styleBorderLayer.bitmapData) + { + _styleBorderLayer.bitmapData.dispose(); + } + } + _styleFill = null; + _styleMask = null; + _styleBorderLayer = null; + _styleAnimation = "none"; + _styleGradient = "linear"; + _styleStops = []; + _hasStyle = false; + } + + private static function colourTransform(param1:uint, param2:Number) : ColorTransform + { + return new ColorTransform(0,0,0,param2,param1 >> 16 & 255,param1 >> 8 & 255,param1 & 255,0); + } + + private static function blendColour(param1:uint, param2:uint, param3:Number) : uint + { + var _loc4_:Number = 1 - param3; + var _loc5_:uint = uint((param1 >> 16 & 255) * _loc4_ + (param2 >> 16 & 255) * param3); + var _loc6_:uint = uint((param1 >> 8 & 255) * _loc4_ + (param2 >> 8 & 255) * param3); + var _loc7_:uint = uint((param1 & 255) * _loc4_ + (param2 & 255) * param3); + return _loc5_ << 16 | _loc6_ << 8 | _loc7_; + } + + private static function rainbowColour(param1:Number) : uint + { + var _loc2_:int = int(param1 * 6) % 6; + var _loc3_:Number = param1 * 6 - int(param1 * 6); + var _loc4_:uint = uint(255 * _loc3_); + var _loc5_:uint = 255 - _loc4_; + if(_loc2_ == 0) + { + return 0xFF0000 | _loc4_ << 8; + } + if(_loc2_ == 1) + { + return _loc5_ << 16 | 0xFF00; + } + if(_loc2_ == 2) + { + return 0x00FF00 | _loc4_; + } + if(_loc2_ == 3) + { + return _loc5_ << 8 | 0xFF; + } + if(_loc2_ == 4) + { + return _loc4_ << 16 | 0xFF; + } + return 0xFF0000 | _loc5_ << 8; + } + + private function parseStyleStops(param1:String) : Array + { + var _loc1_:Array = []; + var _loc2_:Array = String(param1 || "").split(";"); + var _loc3_:int = 0; + var _loc4_:Array = null; + var _loc5_:int = -1; + while(_loc3_ < _loc2_.length && _loc2_.length >= 2 && _loc2_.length <= 5) + { + _loc4_ = String(_loc2_[_loc3_]).split(":"); + if(_loc4_.length != 2 || !/^[0-9a-fA-F]{6}$/.test(String(_loc4_[0])) || !/^100$|^[1-9]?\d$/.test(String(_loc4_[1])) || int(_loc4_[1]) <= _loc5_) + { + _loc1_ = []; + break; + } + _loc5_ = int(_loc4_[1]); + _loc1_.push({"color":uint(parseInt(_loc4_[0],16)),"position":_loc5_}); + _loc3_++; + } + if(_loc1_.length < 2 || int(_loc1_[0].position) != 0 || int(_loc1_[_loc1_.length - 1].position) != 100) + { + _loc1_ = [{"color":_styleBackground,"position":0},{"color":_styleAccent,"position":100}]; + } + return _loc1_; + } + + private function drawStyle() : void + { + if(!_hasStyle || !_balloonBG || !_msgTxt) + { + return; + } + if(_styleFill == null) + { + _styleFill = new Sprite(); + _styleFill.mouseEnabled = false; + _styleFill.mouseChildren = false; + // Flash uses a Bitmap mask's alpha channel only when both sides + // are cached. Without this it masks to the bitmap's rectangle. + _styleFill.cacheAsBitmap = true; + // The stock background contains masks and nested timeline layers. + // Put this beside it, directly below the text, so those masks + // cannot hide custom colours or animated gradients. + var _loc8_:DisplayObject = _msgTxt as DisplayObject; + while(_loc8_ && _loc8_.parent != this) + { + _loc8_ = _loc8_.parent; + } + if(_loc8_ && _loc8_.parent == this) + { + addChildAt(_styleFill,getChildIndex(_loc8_)); + } + else + { + addChildAt(_styleFill,Math.min(numChildren,getChildIndex(_balloonBG) + 1)); + } + } + var _loc9_:Rectangle = _balloonBG.getBounds(this); + if(_styleMask == null) + { + // Snapshot only the native bubble's alpha and use it as a mask. + // Eroding that silhouette by the chosen outline width leaves the + // tinted native artwork visible as an even border, including the + // speech tail. A rounded-rectangle inset cannot match that shape. + var _loc10_:BitmapData = new BitmapData(Math.max(1,Math.ceil(_loc9_.width)),Math.max(1,Math.ceil(_loc9_.height)),true,0); + var _loc11_:Matrix = _balloonBG.transform.matrix.clone(); + _loc11_.translate(-_loc9_.x,-_loc9_.y); + _loc10_.draw(_balloonBG,_loc11_,null,null,null,true); + var _loc20_:BitmapData = new BitmapData(_loc10_.width,_loc10_.height,true,0); + _loc20_.threshold(_loc10_,_loc10_.rect,new Point(),">",0x08000000,0xFFFFFFFF,0xFF000000,false); + _loc10_.dispose(); + var _loc32_:BitmapData = _loc20_.clone(); + if(_styleOutline > 0) + { + var _loc21_:int = int(_styleOutline) * 2 + 1; + var _loc22_:Array = []; + var _loc23_:int = 0; + var _loc24_:int = 0; + var _loc25_:int = 0; + while(_loc24_ < _loc21_) + { + _loc25_ = 0; + while(_loc25_ < _loc21_) + { + if(Math.abs(_loc24_ - int(_styleOutline)) + Math.abs(_loc25_ - int(_styleOutline)) <= _styleOutline) + { + _loc22_.push(1); + _loc23_++; + } + else + { + _loc22_.push(0); + } + _loc25_++; + } + _loc24_++; + } + var _loc26_:BitmapData = new BitmapData(_loc20_.width,_loc20_.height,true,0); + // Outside the snapshot must be transparent. Clamping repeats + // opaque edge pixels and prevents the top/side of the mask + // from shrinking, which made thick outlines appear only at + // the lower edge and corners. + _loc26_.applyFilter(_loc20_,_loc20_.rect,new Point(),new ConvolutionFilter(_loc21_,_loc21_,_loc22_,_loc23_,0,false,false,0,0)); + _loc20_.fillRect(_loc20_.rect,0); + _loc20_.threshold(_loc26_,_loc26_.rect,new Point(),">",0xFE000000,0xFFFFFFFF,0xFF000000,false); + _loc26_.dispose(); + // Keep only the pixels removed from the inner mask. This is a + // solid, even ring and does not inherit the stock art's uneven + // border opacity. + _loc32_.threshold(_loc20_,_loc20_.rect,new Point(),">",0x00000000,0x00000000,0xFF000000,false); + _loc32_.colorTransform(_loc32_.rect,colourTransform(_styleBorder,1)); + _styleBorderLayer = new Bitmap(_loc32_,"auto",true); + _styleBorderLayer.x = _loc9_.x; + _styleBorderLayer.y = _loc9_.y; + _styleBorderLayer.cacheAsBitmap = true; + addChildAt(_styleBorderLayer,getChildIndex(_styleFill)); + } + else + { + _loc32_.dispose(); + } + _styleMask = new Bitmap(_loc20_,"auto",true); + _styleMask.x = _loc9_.x; + _styleMask.y = _loc9_.y; + _styleMask.cacheAsBitmap = true; + addChildAt(_styleMask,getChildIndex(_styleFill)); + _styleFill.mask = _styleMask; + } + var _loc1_:Number = _loc9_.x; + var _loc2_:Number = _loc9_.y; + var _loc3_:Number = Math.max(12,_loc9_.width); + var _loc4_:Number = Math.max(12,_loc9_.height); + var _loc5_:Number = (_styleElapsed * _styleSpeed / 100000) % 1; + var _loc27_:Array = []; + var _loc28_:Array = []; + var _loc29_:Array = []; + var _loc30_:int = 0; + var _loc31_:uint = 0; + while(_loc30_ < _styleStops.length) + { + _loc31_ = uint(_styleStops[_loc30_].color); + if(_loc30_ > 0) + { + _loc31_ = blendColour(_styleBackground,_loc31_,_styleStrength / 100); + } + if(_styleAnimation == "shimmer") + { + _loc31_ = blendColour(_loc31_,_styleBackground,(Math.sin(_loc5_ * Math.PI * 2) + 1) * 0.5); + } + _loc27_.push(_loc31_); + _loc28_.push(_styleOpacity); + _loc29_.push(int(Number(_styleStops[_loc30_].position) * 2.55)); + _loc30_++; + } + _styleFill.graphics.clear(); + var _loc7_:Matrix = new Matrix(); + var _loc12_:Number = _styleAngle * Math.PI / 180; + var _loc13_:String = _styleGradient == "radial" ? GradientType.RADIAL : GradientType.LINEAR; + _loc7_.createGradientBox(_loc3_,_loc4_,_loc12_,_loc1_,_loc2_); + if(_styleGradient == "solid" && _styleAnimation != "rainbow") + { + _styleFill.graphics.beginFill(_styleBackground,_styleOpacity); + } + else if(_styleAnimation == "flow") + { + _loc7_.createGradientBox(_loc3_ * 0.75,_loc4_ * 0.75,_loc12_,_loc1_ + Math.cos(_loc12_) * (_loc5_ * 2 - 1) * _loc3_,_loc2_ + Math.sin(_loc12_) * (_loc5_ * 2 - 1) * _loc4_); + _styleFill.graphics.beginGradientFill(_loc13_,_loc27_,_loc28_,_loc29_,_loc7_,SpreadMethod.REFLECT); + } + else if(_styleAnimation == "rainbow" && _styleGradient == "solid") + { + _styleFill.graphics.beginFill(rainbowColour(_loc5_),_styleOpacity); + } + else if(_styleAnimation == "rainbow") + { + _styleFill.graphics.beginGradientFill(_loc13_,[rainbowColour(_loc5_),rainbowColour((_loc5_ + 0.18) % 1),rainbowColour((_loc5_ + 0.36) % 1)],[_styleOpacity,_styleOpacity,_styleOpacity],[0,128,255],_loc7_); + } + else + { + _styleFill.graphics.beginGradientFill(_loc13_,_loc27_,_loc28_,_loc29_,_loc7_); + } + _styleFill.graphics.drawRect(_loc1_,_loc2_,_loc3_,_loc4_); + _styleFill.graphics.endFill(); + _styleFill.alpha = _styleAnimation == "pulse" ? 0.55 + 0.45 * (Math.sin(_loc5_ * Math.PI * 2) + 1) * 0.5 : 1; + } // the text with each emote code and emoji (above) replaced by a gap, the // picture for it kept in _inline. what is neither stays as typed. @@ -428,6 +774,8 @@ package gui var _loc1_:Object = null; var _loc2_:Rectangle = null; var _loc3_:Rectangle = null; + var _loc4_:Number = 0; + var _loc5_:Number = 1; for each(_loc1_ in _inline) { _loc2_ = _msgTxt.getCharBoundaries(_loc1_.at); @@ -445,6 +793,13 @@ package gui _loc1_.clip.scaleX = _loc1_.clip.scaleY = 1; _loc1_.clip.height = _loc2_.height; _loc1_.clip.scaleX = _loc1_.clip.scaleY; + _loc4_ = Math.max(1,_loc3_.x + _loc3_.width - _loc2_.x - 2); + if(_loc1_.clip.width > _loc4_) + { + _loc5_ = _loc4_ / _loc1_.clip.width; + _loc1_.clip.scaleX *= _loc5_; + _loc1_.clip.scaleY *= _loc5_; + } _loc1_.clip.x = _msgTxt.x + (_loc2_.x + _loc3_.x + _loc3_.width) / 2; _loc1_.clip.y = _msgTxt.y + _loc2_.y + _loc2_.height / 2; if(_loc1_.clip.parent != this) @@ -662,6 +1017,10 @@ package gui public function setEmote(param1:Sprite, param2:int = -1) : void { + // Native one-emote messages hide balloon_bg. Remove any independent + // custom fill left by the preceding text message as well. + clearStyle(); + _balloonBG.transform.colorTransform = new ColorTransform(); clearMentionBacks(); if(this.currentFrameLabel != "advBtn") { @@ -718,6 +1077,11 @@ package gui public function heartbeat(param1:int) : void { + if(_styleAnimation != "none" && visible) + { + _styleElapsed += param1; + drawStyle(); + } if(_timeout && _permEmoteMediaId < 0) { if(param1 >= _timeout) diff --git a/swf-src/GuiManager.as b/swf-src/GuiManager.as index aee20e4..6af0ea3 100644 --- a/swf-src/GuiManager.as +++ b/swf-src/GuiManager.as @@ -270,6 +270,8 @@ package gui private static var _namebarBadgeList:Array; private static var _sharedObj:SharedObject; + + private static var _customChatBubbles:Boolean = true; private static var _giftGemsMediaHelper:MediaHelper; @@ -365,11 +367,13 @@ package gui public static function setupSharedObject() : void { _sharedObj = null; + _customChatBubbles = true; if(gMainFrame.myFlashVarUserName != null) { try { _sharedObj = SharedObject.getLocal(gMainFrame.myFlashVarUserName); + _customChatBubbles = _sharedObj.data.customChatBubbles !== false; if(_sharedObj.data.cursor == null || _sharedObj.data.cursor == "custom") { CursorManager.switchToCursor("custom_cursor"); @@ -459,6 +463,31 @@ package gui { return _sharedObj; } + + // A local accessibility/preference switch: players can keep their own + // saved style visible to others while rendering every bubble normally + // on this installation. + public static function customChatBubblesEnabled() : Boolean + { + return _customChatBubbles; + } + + public static function setCustomChatBubblesEnabled(param1:Boolean) : void + { + _customChatBubbles = param1; + if(_sharedObj == null) + { + return; + } + _sharedObj.data.customChatBubbles = param1; + try + { + _sharedObj.flush(); + } + catch(e:Error) + { + } + } public static function startFFM(param1:Boolean = false) : void { diff --git a/swf-src/ItemWindowToggle.as b/swf-src/ItemWindowToggle.as index 39f85e8..2d57f02 100644 --- a/swf-src/ItemWindowToggle.as +++ b/swf-src/ItemWindowToggle.as @@ -7,12 +7,20 @@ package gui.itemWindows import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.DisplayObject; + import flash.display.GradientType; + import flash.display.SpreadMethod; import flash.display.MovieClip; + import flash.display.Sprite; import flash.geom.Matrix; import flash.events.MouseEvent; + import flash.events.Event; import flash.geom.Rectangle; import flash.net.URLRequest; import flash.net.navigateToURL; + import flash.text.TextField; + import flash.text.TextFieldType; + import flash.text.TextFormat; + import flash.utils.getTimer; import gamePlayFlow.GamePlay; import gui.CursorManager; import gui.GuiHud; @@ -24,9 +32,49 @@ package gui.itemWindows public class ItemWindowToggle extends ItemWindowBase { - + private static const SLIDER_RECT:Rectangle = new Rectangle(15,15.5,82,0); + // A lightweight editor made from native Flash display objects. Keeping it + // here lets the existing Settings button open it without a browser bridge. + private static const CHAT_COLOUR_KEYS:Array = ["background","accent","text","border"]; + private static const CHAT_ANIMATIONS:Array = ["none","pulse","shimmer","flow","rainbow"]; + private static const CHAT_GRADIENTS:Array = ["linear","radial","solid"]; + private static const CHAT_ANGLES:Array = [0,45,90,135,180,225,270,315]; + private static const CHAT_STRENGTHS:Array = [0,25,50,75,100]; + private static const CHAT_OUTLINES:Array = [0,1,2,3,4]; + private static const CHAT_OPACITIES:Array = [25,40,55,70,85,100]; + private static const CHAT_SPEEDS:Array = [40,70,100,150,200,300]; + private static const CHAT_PALETTE:Array = [ + "ffffff","f3ead1","ffd6d6","ffe0b2","fff3b0","dff2bd","bcebcf","b9efff", + "cbd5ff","e1d0ff","ffd6f3","d6d6d6","9aabb0","ff5a68","ff8a3d","ffd23f", + "54a96b","26c6da","41a9df","5b7cfa","734fd1","ef5da8","8f5a3c","445559", + "1f2937","5b203e","214d31","16435b","18264b","342018","000000","ff0069" + ]; + private static const CHAT_PRESETS:Array = [ + {"name":"Ocean","background":"d9fbff","accent":"41a9df","text":"16435b","border":"237ba9","opacity":85,"gradient":"linear","angle":45,"strength":100,"animation":"shimmer","speed":100,"outline":1}, + {"name":"Sunset","background":"ffcf70","accent":"ef5da8","text":"5b203e","border":"d74277","opacity":85,"gradient":"linear","angle":135,"strength":100,"animation":"flow","speed":100,"outline":1}, + {"name":"Forest","background":"dff2bd","accent":"54a96b","text":"214d31","border":"387747","opacity":85,"gradient":"radial","angle":45,"strength":75,"animation":"pulse","speed":70,"outline":1}, + {"name":"Midnight","background":"18264b","accent":"734fd1","text":"ffffff","border":"9c83ef","opacity":85,"gradient":"radial","angle":45,"strength":100,"animation":"shimmer","speed":100,"outline":2}, + {"name":"Candy","background":"ffe1f1","accent":"9ce7ff","text":"8f1f63","border":"ef6bb2","opacity":85,"gradient":"linear","angle":90,"strength":100,"animation":"flow","speed":150,"outline":1}, + {"name":"Rainbow","background":"ff5a68","accent":"7b67ff","text":"ffffff","border":"ff3d94","opacity":85,"gradient":"linear","angle":0,"strength":100,"animation":"rainbow","speed":100,"outline":1} + ]; + private static var _chatStyle:Object = {"background":"ffffff","accent":"dfe8ff","text":"445559","border":"9aabb0","opacity":75,"animation":"none","speed":100,"gradient":"linear","angle":45,"strength":100,"outline":1,"stops":"ffffff:0;dfe8ff:100"}; + private static var _chatPopup:Sprite; + private static var _chatFields:Array; + private static var _chatButtons:Object; + private static var _chatStatus:TextField; + private static var _chatPreview:Sprite; + private static var _chatSwatches:Array; + private static var _chatPanel:Sprite; + private static var _chatPalette:Sprite; + private static var _chatColourIndex:int = -1; + private static var _chatStops:Array = [{"color":"ffffff","position":0},{"color":"dfe8ff","position":100}]; + private static var _chatSelectedStop:int = 0; + private static var _chatStopSprites:Array; + private static var _chatTrack:Sprite; + private static var _chatPreset:int = -1; + private var _lock:MovieClip; private var _currHeight:int; @@ -173,6 +221,7 @@ package gui.itemWindows case "itemFinder": case "itemMaker": case "chatFilter": + case "chatBubble": case "themeMenu": case "themePick": case "savedMenu": @@ -181,6 +230,10 @@ package gui.itemWindows _window.goNowBtn.mouse.mouse.txt.text = _currItem.btnLabel; _window.goNowBtn.mouse.up.txt.text = _currItem.btnLabel; _window.labelTxtCont.labelTxt.text = _currItem.labelLabel; + if(_currItem.frame == "chatBubble") + { + _window.icon["" + _window.icon.currentFrameLabel].gotoAndStop("startingOn"); + } break; case "hideBlocked": showHideBlocked(); @@ -525,6 +578,855 @@ package gui.itemWindows showExpandedInventory(); } + // `xcs` is the account's saved chat style: [background, accent, text, + // border, opacity, animation, speed, gradient, angle, strength, outline, + // stops]. The server sends it when this + // popup opens and whenever it saves, so its state remains authoritative. + public static function chatStyleState(param1:Object) : void + { + if(param1 == null || param1.length < 9) + { + return; + } + _chatStyle = { + "background":String(param1[2]).toLowerCase(), + "accent":String(param1[3]).toLowerCase(), + "text":String(param1[4]).toLowerCase(), + "border":String(param1[5]).toLowerCase(), + "opacity":int(param1[6]), + "animation":String(param1[7]), + "speed":int(param1[8]), + "gradient":param1.length > 9 ? String(param1[9]) : "linear", + "angle":param1.length > 10 ? int(param1[10]) : 45, + "strength":param1.length > 11 ? int(param1[11]) : 100, + "outline":param1.length > 12 ? int(param1[12]) : 1, + "stops":param1.length > 13 ? String(param1[13]) : String(param1[2]) + ":0;" + String(param1[3]) + ":100" + }; + _chatStops = parseChatStops(_chatStyle.stops); + _chatSelectedStop = 0; + _chatPreset = findChatPreset(); + if(_chatPopup != null) + { + refreshChatPopup(); + _chatStatus.text = "Saved. Send a chat message to see it in the room."; + } + } + + private static function showChatBubbleEditor() : void + { + var _loc1_:Sprite = null; + var _loc2_:Sprite = null; + var _loc3_:TextField = null; + var _loc4_:int = 0; + var _loc5_:String = null; + var _loc6_:Number = NaN; + var _loc7_:Number = NaN; + if(_chatPopup != null || GuiManager.guiLayer == null) + { + return; + } + _chatPopup = new Sprite(); + // guiLayer uses the SWF's design coordinates even when the browser + // stretches the Stage. Using stageWidth here scaled the popup twice. + _loc6_ = 900; + _loc7_ = 550; + _chatPopup.mouseEnabled = false; + _chatPopup.graphics.beginFill(0,0.48); + _chatPopup.graphics.drawRect(0,0,_loc6_,_loc7_); + _chatPopup.graphics.endFill(); + _loc1_ = new Sprite(); + _loc1_.x = (_loc6_ - 660) * 0.5; + _loc1_.y = (_loc7_ - 500) * 0.5; + _loc1_.mouseEnabled = false; + _loc1_.graphics.lineStyle(5,0x73431F,1,true); + _loc1_.graphics.beginFill(0xF2E2B9,1); + _loc1_.graphics.drawRoundRect(0,0,660,500,28,28); + _loc1_.graphics.endFill(); + _chatPopup.addChild(_loc1_); + _chatPanel = _loc1_; + _loc3_ = chatText("Chat Bubble",28,22,390,28,0x5A2C19,true); + _loc1_.addChild(_loc3_); + _loc1_.addChild(chatText("Click a colour square for the palette, or type a six-digit hex.",28,58,590,15,0x5A2C19,false)); + _chatFields = []; + _chatSwatches = []; + _loc4_ = 0; + while(_loc4_ < CHAT_COLOUR_KEYS.length) + { + _loc5_ = String(CHAT_COLOUR_KEYS[_loc4_]); + _loc1_.addChild(chatText(_loc4_ == 0 ? "Gradient start" : _loc4_ == 1 ? "Gradient end" : _loc5_.charAt(0).toUpperCase() + _loc5_.substr(1),30,95 + _loc4_ * 44,130,15,0x5A2C19,false)); + _loc3_ = chatText("",155,90 + _loc4_ * 44,105,17,0x342018,false); + _loc3_.type = TextFieldType.INPUT; + _loc3_.selectable = true; + _loc3_.restrict = "0-9a-fA-F"; + _loc3_.maxChars = 6; + _loc3_.background = true; + _loc3_.backgroundColor = 0xFFFFFF; + _loc3_.border = true; + _loc3_.borderColor = 0x9A6A45; + _loc3_.addEventListener(Event.CHANGE,onChatFieldChange,false,0,true); + _loc1_.addChild(_loc3_); + _chatFields.push(_loc3_); + _loc2_ = new Sprite(); + _loc2_.x = 270; + _loc2_.y = 92 + _loc4_ * 44; + _loc2_.name = "chat-colour-" + _loc4_; + _loc2_.mouseEnabled = true; + _loc2_.buttonMode = true; + _loc2_.addEventListener("mouseDown",onChatPopupMouse,false,0,true); + _loc1_.addChild(_loc2_); + _chatSwatches.push(_loc2_); + _loc4_++; + } + _chatButtons = {}; + _chatPreview = new Sprite(); + _chatPreview.x = 335; + _chatPreview.y = 92; + _chatPreview.mouseEnabled = false; + _chatPreview.mouseChildren = false; + _chatPreview.addChild(chatText("Preview message",5,29,280,17,0x445559,true,"center")); + _chatPreview.addEventListener(Event.ENTER_FRAME,onChatPreviewFrame,false,0,true); + _loc1_.addChild(_chatPreview); + _chatTrack = new Sprite(); + _chatTrack.x = 335; + _chatTrack.y = 181; + _loc1_.addChild(_chatTrack); + _chatStopSprites = []; + _loc2_ = chatButton("",335,215,175,"chat-preset"); + _loc1_.addChild(_loc2_); + _chatButtons.preset = _loc2_; + _loc2_ = chatButton("",520,215,115,"chat-position"); + _loc1_.addChild(_loc2_); + _chatButtons.position = _loc2_; + _loc1_.addChild(chatButton("Add",335,259,68,"chat-stop-add")); + _loc1_.addChild(chatButton("Remove",410,259,68,"chat-stop-remove")); + _loc1_.addChild(chatButton("Swap",485,259,68,"chat-swap")); + _loc1_.addChild(chatButton("Random",560,259,75,"chat-random")); + _loc2_ = chatButton("",30,307,180,"chat-gradient"); + _loc1_.addChild(_loc2_); + _chatButtons.gradient = _loc2_; + _loc2_ = chatButton("",240,307,180,"chat-angle"); + _loc1_.addChild(_loc2_); + _chatButtons.angle = _loc2_; + _loc2_ = chatButton("",450,307,180,"chat-strength"); + _loc1_.addChild(_loc2_); + _chatButtons.strength = _loc2_; + _loc2_ = chatButton("",30,351,180,"chat-animation"); + _loc1_.addChild(_loc2_); + _chatButtons.animation = _loc2_; + _loc2_ = chatButton("",240,351,180,"chat-opacity"); + _loc1_.addChild(_loc2_); + _chatButtons.opacity = _loc2_; + _loc2_ = chatButton("",450,351,180,"chat-speed"); + _loc1_.addChild(_loc2_); + _chatButtons.speed = _loc2_; + _loc2_ = chatButton("",30,397,190,"chat-enabled"); + _loc1_.addChild(_loc2_); + _chatButtons.enabled = _loc2_; + _loc2_ = chatButton("",235,397,130,"chat-outline"); + _loc1_.addChild(_loc2_); + _chatButtons.outline = _loc2_; + _loc1_.addChild(chatButton("Reset",380,397,110,"chat-reset")); + _loc1_.addChild(chatButton("Save",505,397,125,"chat-save")); + _chatStatus = chatText("",30,451,590,14,0x5A2C19,false); + _loc1_.addChild(_chatStatus); + _loc1_.addChild(chatButton("X",600,18,36,"chat-close")); + GuiManager.guiLayer.addChild(_chatPopup); + refreshChatPopup(); + // A request also handles a popup opened before the login response. + gMainFrame.server.setXtObject_Str("xcs",[]); + } + + private static function chatText(param1:String, param2:Number, param3:Number, param4:Number, param5:int, param6:uint, param7:Boolean, param8:String = null) : TextField + { + var _loc8_:TextField = new TextField(); + var _loc9_:TextFormat = new TextFormat("Arial",param5,param6,param7); + _loc8_.x = param2; + _loc8_.y = param3; + _loc8_.width = param4; + _loc8_.height = param5 + 8; + if(param8 != null) + { + _loc9_.align = param8; + } + _loc8_.defaultTextFormat = _loc9_; + _loc8_.text = param1; + _loc8_.setTextFormat(_loc9_); + _loc8_.selectable = false; + return _loc8_; + } + + private static function chatButton(param1:String, param2:Number, param3:Number, param4:Number, param5:String) : Sprite + { + var _loc6_:Sprite = new Sprite(); + var _loc7_:TextField = null; + _loc6_.name = param5; + _loc6_.x = param2; + _loc6_.y = param3; + _loc6_.buttonMode = true; + _loc6_.mouseChildren = false; + _loc6_.graphics.lineStyle(2,0x73431F,1,true); + _loc6_.graphics.beginFill(0xE7C779,1); + _loc6_.graphics.drawRoundRect(0,0,param4,37,14,14); + _loc6_.graphics.endFill(); + _loc7_ = chatText(param1,5,7,param4 - 10,16,0x5A2C19,true,"center"); + _loc7_.mouseEnabled = false; + _loc6_.addChild(_loc7_); + _loc6_.addEventListener("mouseDown",onChatPopupMouse,false,0,true); + return _loc6_; + } + + private static function setChatButton(param1:Sprite, param2:String) : void + { + TextField(param1.getChildAt(0)).text = param2; + } + + private static function refreshChatPopup(param1:Boolean = true) : void + { + var _loc1_:int = 0; + if(_chatFields == null) + { + return; + } + if(param1) + { + while(_loc1_ < CHAT_COLOUR_KEYS.length) + { + TextField(_chatFields[_loc1_]).text = String(_chatStyle[CHAT_COLOUR_KEYS[_loc1_]]); + _loc1_++; + } + } + setChatButton(_chatButtons.preset,"Preset: " + (_chatPreset >= 0 ? CHAT_PRESETS[_chatPreset].name : "Custom")); + setChatButton(_chatButtons.gradient,"Gradient: " + _chatStyle.gradient); + setChatButton(_chatButtons.angle,"Direction: " + _chatStyle.angle + " degrees"); + setChatButton(_chatButtons.strength,"Strength: " + _chatStyle.strength + "%"); + setChatButton(_chatButtons.animation,"Animation: " + _chatStyle.animation); + setChatButton(_chatButtons.opacity,"Opacity: " + _chatStyle.opacity + "%"); + setChatButton(_chatButtons.speed,"Speed: " + _chatStyle.speed + "%"); + setChatButton(_chatButtons.outline,"Outline: " + _chatStyle.outline + " px"); + setChatButton(_chatButtons.enabled,"Custom bubbles: " + (GuiManager.customChatBubblesEnabled() ? "On" : "Off")); + if(_chatSelectedStop < 0 || _chatSelectedStop >= _chatStops.length) + { + _chatSelectedStop = 0; + } + setChatButton(_chatButtons.position,(_chatSelectedStop + 1) + "/" + _chatStops.length + (_chatSelectedStop == 0 || _chatSelectedStop == _chatStops.length - 1 ? ": fixed" : ": " + _chatStops[_chatSelectedStop].position + "%")); + drawChatGradientTrack(); + drawChatSwatches(); + drawChatPreview(); + _chatStatus.text = ""; + } + + private static function onChatFieldChange(param1:Event) : void + { + var _loc1_:int = 0; + while(_loc1_ < CHAT_COLOUR_KEYS.length) + { + if(validChatHex(TextField(_chatFields[_loc1_]).text)) + { + _chatStyle[CHAT_COLOUR_KEYS[_loc1_]] = TextField(_chatFields[_loc1_]).text.toLowerCase(); + } + _loc1_++; + } + if(_chatStops && _chatStops.length >= 2) + { + _chatStops[0].color = _chatStyle.background; + _chatStops[_chatStops.length - 1].color = _chatStyle.accent; + syncChatStops(); + } + _chatPreset = -1; + setChatButton(_chatButtons.preset,"Preset: Custom"); + drawChatSwatches(); + drawChatPreview(); + } + + private static function parseChatStops(param1:String) : Array + { + var _loc1_:Array = []; + var _loc2_:Array = String(param1 || "").split(";"); + var _loc3_:int = 0; + var _loc4_:Array = null; + while(_loc3_ < _loc2_.length && _loc2_.length >= 2 && _loc2_.length <= 5) + { + _loc4_ = String(_loc2_[_loc3_]).split(":"); + if(_loc4_.length != 2 || !validChatHex(String(_loc4_[0])) || isNaN(Number(_loc4_[1]))) + { + _loc1_ = []; + break; + } + _loc1_.push({"color":String(_loc4_[0]).toLowerCase(),"position":Math.max(0,Math.min(100,int(_loc4_[1])))}); + _loc3_++; + } + if(_loc1_.length < 2) + { + _loc1_ = [{"color":String(_chatStyle.background),"position":0},{"color":String(_chatStyle.accent),"position":100}]; + } + _loc1_.sortOn("position",Array.NUMERIC); + _loc1_[0].position = 0; + _loc1_[_loc1_.length - 1].position = 100; + return _loc1_; + } + + private static function syncChatStops() : void + { + var _loc1_:Array = []; + var _loc2_:int = 0; + if(_chatStops == null || _chatStops.length < 2) + { + _chatStops = [{"color":String(_chatStyle.background),"position":0},{"color":String(_chatStyle.accent),"position":100}]; + } + _chatStops.sortOn("position",Array.NUMERIC); + _chatStops[0].position = 0; + _chatStops[_chatStops.length - 1].position = 100; + while(_loc2_ < _chatStops.length) + { + _loc1_.push(String(_chatStops[_loc2_].color) + ":" + int(_chatStops[_loc2_].position)); + _loc2_++; + } + _chatStyle.background = String(_chatStops[0].color); + _chatStyle.accent = String(_chatStops[_chatStops.length - 1].color); + _chatStyle.stops = _loc1_.join(";"); + } + + private static function drawChatGradientTrack() : void + { + var _loc1_:Array = []; + var _loc2_:Array = []; + var _loc3_:Array = []; + var _loc4_:int = 0; + var _loc5_:Sprite = null; + var _loc6_:Matrix = null; + if(_chatTrack == null) + { + return; + } + while(_chatTrack.numChildren > 0) + { + _chatTrack.removeChildAt(0); + } + _chatTrack.graphics.clear(); + while(_loc4_ < _chatStops.length) + { + _loc1_.push(uint(parseInt(_chatStops[_loc4_].color,16))); + _loc2_.push(1); + _loc3_.push(int(Number(_chatStops[_loc4_].position) * 2.55)); + _loc4_++; + } + _loc6_ = new Matrix(); + _loc6_.createGradientBox(300,14,0,0,0); + _chatTrack.graphics.lineStyle(2,0x73431F,1,true); + _chatTrack.graphics.beginGradientFill(GradientType.LINEAR,_loc1_,_loc2_,_loc3_,_loc6_); + _chatTrack.graphics.drawRoundRect(0,0,300,14,8,8); + _chatTrack.graphics.endFill(); + _chatStopSprites = []; + _loc4_ = 0; + while(_loc4_ < _chatStops.length) + { + _loc5_ = new Sprite(); + _loc5_.name = "chat-stop-" + _loc4_; + _loc5_.x = Number(_chatStops[_loc4_].position) * 3 - 8; + _loc5_.y = 14; + _loc5_.buttonMode = true; + _loc5_.graphics.lineStyle(_loc4_ == _chatSelectedStop ? 3 : 1,_loc4_ == _chatSelectedStop ? 0xFFFFFF : 0x73431F,1,true); + _loc5_.graphics.beginFill(uint(parseInt(_chatStops[_loc4_].color,16)),1); + _loc5_.graphics.drawCircle(8,8,7); + _loc5_.graphics.endFill(); + _loc5_.addEventListener("mouseDown",onChatPopupMouse,false,0,true); + _chatTrack.addChild(_loc5_); + _chatStopSprites.push(_loc5_); + _loc4_++; + } + } + + private static function chatBlend(param1:uint, param2:uint, param3:Number) : uint + { + var _loc4_:Number = 1 - param3; + return uint((param1 >> 16 & 255) * _loc4_ + (param2 >> 16 & 255) * param3) << 16 | + uint((param1 >> 8 & 255) * _loc4_ + (param2 >> 8 & 255) * param3) << 8 | + uint((param1 & 255) * _loc4_ + (param2 & 255) * param3); + } + + private static function chatHex(param1:uint) : String + { + var _loc2_:String = param1.toString(16); + while(_loc2_.length < 6) + { + _loc2_ = "0" + _loc2_; + } + return _loc2_.substr(-6); + } + + private static function chatRainbow(param1:Number) : uint + { + var _loc2_:int = int(param1 * 6) % 6; + var _loc3_:Number = param1 * 6 - int(param1 * 6); + var _loc4_:uint = uint(255 * _loc3_); + var _loc5_:uint = 255 - _loc4_; + if(_loc2_ == 0) return 0xFF0000 | _loc4_ << 8; + if(_loc2_ == 1) return _loc5_ << 16 | 0xFF00; + if(_loc2_ == 2) return 0x00FF00 | _loc4_; + if(_loc2_ == 3) return _loc5_ << 8 | 0xFF; + if(_loc2_ == 4) return _loc4_ << 16 | 0xFF; + return 0xFF0000 | _loc5_ << 8; + } + + private static function onChatPreviewFrame(param1:Event) : void + { + if(_chatStyle.animation != "none") + { + drawChatPreview(); + } + } + + private static function drawChatSwatches() : void + { + var _loc1_:int = 0; + while(_chatSwatches && _loc1_ < _chatSwatches.length) + { + Sprite(_chatSwatches[_loc1_]).graphics.clear(); + Sprite(_chatSwatches[_loc1_]).graphics.lineStyle(1,0x73431F,1,true); + Sprite(_chatSwatches[_loc1_]).graphics.beginFill(uint(parseInt(_chatStyle[CHAT_COLOUR_KEYS[_loc1_]],16)),1); + Sprite(_chatSwatches[_loc1_]).graphics.drawRoundRect(0,0,24,24,7,7); + Sprite(_chatSwatches[_loc1_]).graphics.endFill(); + _loc1_++; + } + } + + private static function closeChatPalette() : void + { + if(_chatPalette && _chatPalette.parent) + { + _chatPalette.parent.removeChild(_chatPalette); + } + _chatPalette = null; + _chatColourIndex = -1; + } + + private static function openChatPalette(param1:int) : void + { + var _loc1_:int = 0; + var _loc2_:String = null; + var _loc3_:Sprite = null; + if(_chatPanel == null || param1 < 0 || param1 > CHAT_COLOUR_KEYS.length) + { + return; + } + closeChatPalette(); + _chatColourIndex = param1; + _chatPalette = new Sprite(); + _chatPalette.x = 296; + _chatPalette.y = 76; + _chatPalette.graphics.lineStyle(3,0x73431F,1,true); + _chatPalette.graphics.beginFill(0xF8EDCE,1); + _chatPalette.graphics.drawRoundRect(0,0,342,166,18,18); + _chatPalette.graphics.endFill(); + _chatPalette.addChild(chatText("Choose " + (param1 == CHAT_COLOUR_KEYS.length ? "selected stop" : param1 == 0 ? "gradient start" : param1 == 1 ? "gradient end" : CHAT_COLOUR_KEYS[param1]),14,10,275,16,0x5A2C19,true)); + _chatPalette.addChild(chatButton("X",298,8,30,"chat-palette-close")); + while(_loc1_ < CHAT_PALETTE.length) + { + _loc2_ = String(CHAT_PALETTE[_loc1_]); + _loc3_ = new Sprite(); + _loc3_.name = "chat-pick-" + _loc2_; + _loc3_.x = 15 + _loc1_ % 8 * 40; + _loc3_.y = 46 + int(_loc1_ / 8) * 28; + _loc3_.buttonMode = true; + _loc3_.graphics.lineStyle(2,0x73431F,1,true); + _loc3_.graphics.beginFill(uint(parseInt(_loc2_,16)),1); + _loc3_.graphics.drawRoundRect(0,0,31,21,7,7); + _loc3_.graphics.endFill(); + _loc3_.addEventListener("mouseDown",onChatPopupMouse,false,0,true); + _chatPalette.addChild(_loc3_); + _loc1_++; + } + _chatPanel.addChild(_chatPalette); + } + + private static function drawChatPreview() : void + { + var _loc1_:uint = 0; + var _loc2_:uint = 0; + var _loc3_:uint = 0; + var _loc4_:Matrix = null; + var _loc5_:String = null; + var _loc7_:Number = 0; + var _loc8_:Array = []; + var _loc9_:Array = []; + var _loc10_:Array = []; + var _loc11_:int = 0; + var _loc12_:uint = 0; + if(_chatPreview == null) + { + return; + } + _loc1_ = uint(parseInt(_chatStyle.background,16)); + _loc2_ = chatBlend(_loc1_,uint(parseInt(_chatStyle.accent,16)),Number(_chatStyle.strength) / 100); + _loc3_ = uint(parseInt(_chatStyle.border,16)); + _loc7_ = (getTimer() * Number(_chatStyle.speed) / 100000) % 1; + while(_loc11_ < _chatStops.length) + { + _loc12_ = uint(parseInt(_chatStops[_loc11_].color,16)); + if(_loc11_ > 0) + { + _loc12_ = chatBlend(_loc1_,_loc12_,Number(_chatStyle.strength) / 100); + } + if(_chatStyle.animation == "shimmer") + { + _loc12_ = chatBlend(_loc12_,_loc1,(Math.sin(_loc7_ * Math.PI * 2) + 1) * 0.5); + } + _loc8_.push(_loc12_); + _loc9_.push(Number(_chatStyle.opacity) / 100); + _loc10_.push(int(Number(_chatStops[_loc11_].position) * 2.55)); + _loc11_++; + } + _chatPreview.graphics.clear(); + _chatPreview.graphics.lineStyle(Math.max(0,Number(_chatStyle.outline)),_loc3_,1,true); + if(_chatStyle.gradient == "solid") + { + _chatPreview.graphics.beginFill(_chatStyle.animation == "rainbow" ? chatRainbow(_loc7_) : _loc1_,Number(_chatStyle.opacity) / 100); + } + else + { + _loc4_ = new Matrix(); + _loc4_.createGradientBox(280,82,Number(_chatStyle.angle) * Math.PI / 180,0,0); + _loc5_ = _chatStyle.gradient == "radial" ? GradientType.RADIAL : GradientType.LINEAR; + if(_chatStyle.animation == "rainbow") + { + _chatPreview.graphics.beginGradientFill(_loc5_,[chatRainbow(_loc7_),chatRainbow((_loc7_ + 0.18) % 1),chatRainbow((_loc7_ + 0.36) % 1)],[Number(_chatStyle.opacity) / 100,Number(_chatStyle.opacity) / 100,Number(_chatStyle.opacity) / 100],[0,128,255],_loc4_); + } + else if(_chatStyle.animation == "flow") + { + _loc4_.createGradientBox(210,62,Number(_chatStyle.angle) * Math.PI / 180,(_loc7_ * 2 - 1) * 280,(_loc7_ * 2 - 1) * 82); + _chatPreview.graphics.beginGradientFill(_loc5_,_loc8_,_loc9_,_loc10_,_loc4_,SpreadMethod.REFLECT); + } + else + { + _chatPreview.graphics.beginGradientFill(_loc5_,_loc8_,_loc9_,_loc10_,_loc4_); + } + } + _chatPreview.graphics.drawRoundRect(0,0,280,82,22,22); + _chatPreview.graphics.endFill(); + _chatPreview.alpha = _chatStyle.animation == "pulse" ? 0.6 + 0.4 * (Math.sin(_loc7_ * Math.PI * 2) + 1) * 0.5 : 1; + TextField(_chatPreview.getChildAt(0)).textColor = uint(parseInt(_chatStyle.text,16)); + } + + private static function nextChatValue(param1:Array, param2:*) : * + { + var _loc3_:int = param1.indexOf(param2); + return param1[(_loc3_ + 1 + param1.length) % param1.length]; + } + + private static function findChatPreset() : int + { + var _loc1_:int = 0; + var _loc2_:String = null; + var _loc3_:Boolean = false; + while(_loc1_ < CHAT_PRESETS.length) + { + _loc3_ = true; + for(_loc2_ in CHAT_PRESETS[_loc1_]) + { + if(_loc2_ != "name" && String(CHAT_PRESETS[_loc1_][_loc2_]) != String(_chatStyle[_loc2_])) + { + _loc3_ = false; + break; + } + } + if(_loc3_ && String(_chatStyle.stops) != String(CHAT_PRESETS[_loc1_].background) + ":0;" + String(CHAT_PRESETS[_loc1_].accent) + ":100") + { + _loc3_ = false; + } + if(_loc3_) + { + return _loc1_; + } + _loc1_++; + } + return -1; + } + + private static function validChatHex(param1:String) : Boolean + { + return /^[0-9a-fA-F]{6}$/.test(param1); + } + + public static function closeChatBubbleEditor() : void + { + closeChatPalette(); + if(_chatPopup != null) + { + if(_chatPopup.parent != null) + { + _chatPopup.parent.removeChild(_chatPopup); + } + } + _chatPopup = null; + _chatFields = null; + _chatButtons = null; + _chatStatus = null; + if(_chatPreview) + { + _chatPreview.removeEventListener(Event.ENTER_FRAME,onChatPreviewFrame); + } + _chatPreview = null; + _chatSwatches = null; + _chatPanel = null; + _chatTrack = null; + _chatStopSprites = null; + } + + private static function onChatPopupMouse(param1:MouseEvent) : void + { + var _loc2_:DisplayObject = param1.target as DisplayObject; + var _loc3_:String = null; + var _loc4_:int = 0; + var _loc9_:int = 0; + var _loc10_:String = null; + var _loc11_:int = 0; + var _loc12_:int = 0; + var _loc13_:int = 0; + var _loc14_:int = 0; + var _loc15_:String = null; + var _loc16_:int = 0; + var _loc17_:int = 0; + var _loc18_:int = 0; + var _loc19_:Array = null; + param1.stopPropagation(); + while(_loc2_ != null && _loc2_ != _chatPopup && _loc2_.name.indexOf("chat-") != 0) + { + _loc2_ = _loc2_.parent; + } + if(_loc2_ == null || _loc2_ == _chatPopup) + { + return; + } + _loc3_ = _loc2_.name; + if(_loc3_.indexOf("chat-stop-") == 0) + { + _chatSelectedStop = Math.max(0,Math.min(_chatStops.length - 1,int(_loc3_.substr(10)))); + refreshChatPopup(false); + openChatPalette(CHAT_COLOUR_KEYS.length); + } + else if(_loc3_.indexOf("chat-colour-") == 0) + { + _loc9_ = int(_loc3_.substr(12)); + openChatPalette(_loc9_); + } + else if(_loc3_.indexOf("chat-pick-") == 0) + { + _loc10_ = _loc3_.substr(10).toLowerCase(); + if(_chatColourIndex >= 0 && _chatColourIndex <= CHAT_COLOUR_KEYS.length && validChatHex(_loc10_)) + { + if(_chatColourIndex == CHAT_COLOUR_KEYS.length) + { + _chatStops[_chatSelectedStop].color = _loc10_; + } + else + { + _chatStyle[CHAT_COLOUR_KEYS[_chatColourIndex]] = _loc10_; + TextField(_chatFields[_chatColourIndex]).text = _loc10_; + if(_chatColourIndex == 0) + { + _chatStops[0].color = _loc10_; + } + else if(_chatColourIndex == 1) + { + _chatStops[_chatStops.length - 1].color = _loc10_; + } + } + syncChatStops(); + TextField(_chatFields[0]).text = _chatStyle.background; + TextField(_chatFields[1]).text = _chatStyle.accent; + _chatPreset = -1; + closeChatPalette(); + refreshChatPopup(false); + setChatButton(_chatButtons.preset,"Preset: Custom"); + } + } + else if(_loc3_ == "chat-palette-close") + { + closeChatPalette(); + } + else if(_loc3_ == "chat-close") + { + closeChatBubbleEditor(); + } + else if(_loc3_ == "chat-reset") + { + _chatStyle = {"background":"ffffff","accent":"dfe8ff","text":"445559","border":"9aabb0","opacity":75,"animation":"none","speed":100,"gradient":"linear","angle":45,"strength":100,"outline":1,"stops":"ffffff:0;dfe8ff:100"}; + _chatStops = parseChatStops(_chatStyle.stops); + _chatSelectedStop = 0; + _chatPreset = -1; + refreshChatPopup(); + } + else if(_loc3_ == "chat-preset") + { + _chatPreset = (_chatPreset + 1) % CHAT_PRESETS.length; + var _loc5_:Object = CHAT_PRESETS[_chatPreset]; + for(var _loc6_:String in _loc5_) + { + if(_loc6_ != "name") + { + _chatStyle[_loc6_] = _loc5_[_loc6_]; + } + } + _chatStyle.stops = String(_chatStyle.background) + ":0;" + String(_chatStyle.accent) + ":100"; + _chatStops = parseChatStops(_chatStyle.stops); + _chatSelectedStop = 0; + refreshChatPopup(); + } + else if(_loc3_ == "chat-stop-add") + { + if(_chatStops.length >= 5) + { + _chatStatus.text = "A gradient can have up to five colours."; + return; + } + _loc11_ = 0; + _loc12_ = -1; + _loc4_ = 0; + while(_loc4_ < _chatStops.length - 1) + { + _loc13_ = int(_chatStops[_loc4_ + 1].position) - int(_chatStops[_loc4_].position); + if(_loc13_ > _loc12_) + { + _loc12_ = _loc13_; + _loc11_ = _loc4_; + } + _loc4_++; + } + _loc14_ = int((int(_chatStops[_loc11_].position) + int(_chatStops[_loc11_ + 1].position)) * 0.5); + _loc15_ = chatHex(chatBlend(uint(parseInt(_chatStops[_loc11_].color,16)),uint(parseInt(_chatStops[_loc11_ + 1].color,16)),0.5)); + _chatStops.splice(_loc11_ + 1,0,{"color":_loc15_,"position":_loc14_}); + _chatSelectedStop = _loc11_ + 1; + syncChatStops(); + _chatPreset = -1; + refreshChatPopup(); + openChatPalette(CHAT_COLOUR_KEYS.length); + } + else if(_loc3_ == "chat-stop-remove") + { + if(_chatStops.length <= 2) + { + _chatStatus.text = "A gradient needs at least two colours."; + return; + } + _chatStops.splice(_chatSelectedStop,1); + _chatSelectedStop = Math.max(0,Math.min(_chatSelectedStop,_chatStops.length - 1)); + syncChatStops(); + _chatPreset = -1; + refreshChatPopup(); + } + else if(_loc3_ == "chat-position") + { + if(_chatSelectedStop == 0 || _chatSelectedStop == _chatStops.length - 1) + { + _chatStatus.text = "The first and last colours stay at 0% and 100%."; + return; + } + _loc16_ = int(_chatStops[_chatSelectedStop - 1].position) + 5; + _loc17_ = int(_chatStops[_chatSelectedStop + 1].position) - 5; + _loc18_ = int(_chatStops[_chatSelectedStop].position) + 5; + _chatStops[_chatSelectedStop].position = _loc18_ > _loc17_ ? _loc16_ : _loc18_; + syncChatStops(); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-swap") + { + _loc19_ = []; + _loc4_ = _chatStops.length - 1; + while(_loc4_ >= 0) + { + _loc19_.push({"color":String(_chatStops[_loc4_].color),"position":100 - int(_chatStops[_loc4_].position)}); + _loc4_--; + } + _chatStops = _loc19_; + _chatSelectedStop = _chatStops.length - 1 - _chatSelectedStop; + syncChatStops(); + _chatPreset = -1; + refreshChatPopup(); + } + else if(_loc3_ == "chat-random") + { + _loc4_ = 0; + while(_loc4_ < _chatStops.length) + { + _chatStops[_loc4_].color = chatHex(uint(Math.random() * 0x1000000)); + _loc4_++; + } + syncChatStops(); + _chatStyle.border = chatHex(uint(Math.random() * 0x1000000)); + var _loc8_:uint = uint(parseInt(_chatStyle.background,16)); + _chatStyle.text = ((_loc8_ >> 16 & 255) * 299 + (_loc8_ >> 8 & 255) * 587 + (_loc8_ & 255) * 114) / 1000 > 145 ? "342018" : "ffffff"; + _chatPreset = -1; + refreshChatPopup(); + } + else if(_loc3_ == "chat-gradient") + { + _chatStyle.gradient = nextChatValue(CHAT_GRADIENTS,_chatStyle.gradient); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-angle") + { + _chatStyle.angle = nextChatValue(CHAT_ANGLES,_chatStyle.angle); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-strength") + { + _chatStyle.strength = nextChatValue(CHAT_STRENGTHS,_chatStyle.strength); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-animation") + { + _chatStyle.animation = nextChatValue(CHAT_ANIMATIONS,_chatStyle.animation); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-opacity") + { + _chatStyle.opacity = nextChatValue(CHAT_OPACITIES,_chatStyle.opacity); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-speed") + { + _chatStyle.speed = nextChatValue(CHAT_SPEEDS,_chatStyle.speed); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-outline") + { + _chatStyle.outline = nextChatValue(CHAT_OUTLINES,_chatStyle.outline); + _chatPreset = -1; + refreshChatPopup(false); + } + else if(_loc3_ == "chat-enabled") + { + GuiManager.setCustomChatBubblesEnabled(!GuiManager.customChatBubblesEnabled()); + refreshChatPopup(false); + _chatStatus.text = GuiManager.customChatBubblesEnabled() ? "Custom bubbles are visible on this client." : "Custom bubbles are hidden only on this client."; + } + else if(_loc3_ == "chat-save") + { + _loc4_ = 0; + while(_loc4_ < CHAT_COLOUR_KEYS.length) + { + if(!validChatHex(TextField(_chatFields[_loc4_]).text)) + { + _chatStatus.text = "Each colour must be exactly six hexadecimal characters."; + return; + } + _chatStyle[CHAT_COLOUR_KEYS[_loc4_]] = TextField(_chatFields[_loc4_]).text.toLowerCase(); + _loc4_++; + } + _chatStatus.text = "Saving…"; + _chatStops[0].color = _chatStyle.background; + _chatStops[_chatStops.length - 1].color = _chatStyle.accent; + syncChatStops(); + gMainFrame.server.setXtObject_Str("xcs",[_chatStyle.background,_chatStyle.accent,_chatStyle.text,_chatStyle.border,_chatStyle.opacity,_chatStyle.animation,_chatStyle.speed,_chatStyle.gradient,_chatStyle.angle,_chatStyle.strength,_chatStyle.outline,_chatStyle.stops]); + } + } private function handleMouseDown(param1:MouseEvent) : void { @@ -720,6 +1622,9 @@ package gui.itemWindows } AJClient.openTool(1); break; + case "chatBubble": + showChatBubbleEditor(); + break; case "themeMenu": if(_mySettingsThemesFunction != null) { diff --git a/swf-src/MySettings.as b/swf-src/MySettings.as index 5ba5949..4805f6a 100644 --- a/swf-src/MySettings.as +++ b/swf-src/MySettings.as @@ -77,6 +77,9 @@ package gui public function destroy() : void { + // Never leave the editor's full-screen layer behind to swallow + // clicks after Settings is closed by another path. + ItemWindowToggle.closeChatBubbleEditor(); removeEventListeners(); _popupLayer.removeChild(_mySettings); _closeCallback = null; @@ -174,6 +177,15 @@ package gui "iconFrame":"buddyRequest", "labelLabel":"Chat Filter", "btnLabel":"Open" + },{ + // Chat appearance is account-wide; this opens the centered + // in-game editor rather than burying it in the emoji picker. + "type":TOGGLE_TYPE_JOIN, + "frame":"chatBubble", + // Reuse Predict Chat's ABC artwork and keep it in its on state. + "iconFrame":"predictTxt", + "labelLabel":"Chat Bubble", + "btnLabel":"Customize" },{ "type":TOGGLE_TYPE_JOIN, "frame":"themeMenu", diff --git a/swf-src/UserCommXtCommManager.as b/swf-src/UserCommXtCommManager.as index 340a28a..27489ce 100644 --- a/swf-src/UserCommXtCommManager.as +++ b/swf-src/UserCommXtCommManager.as @@ -762,6 +762,13 @@ package avatar { _loc2_ = reverseSpecialWords(_loc2_); } + // Burrow appends a style after the normal extra field. + // Message and type remain at their stock indexes, so + // pending chat and every unpatched client still work. + if(param1.length > 6 && AvatarManager.avatarViewList[_loc19_]) + { + AvatarManager.avatarViewList[_loc19_].setChatStyle(String(param1[6])); + } AvatarManager.addAvatarMessage(_loc2_,_loc19_,int(param1[5])); break; case 2: diff --git a/swf-src/XtReplyDemuxer.as b/swf-src/XtReplyDemuxer.as index b52d486..dc960c3 100644 --- a/swf-src/XtReplyDemuxer.as +++ b/swf-src/XtReplyDemuxer.as @@ -7,6 +7,7 @@ package import flash.events.TimerEvent; import flash.utils.Timer; import flash.utils.getTimer; + import gui.itemWindows.ItemWindowToggle; public class XtReplyDemuxer { @@ -159,6 +160,11 @@ package AJClient.onFilterState(param1.obj); return; } + if(param1.obj[0] == "xcs") + { + ItemWindowToggle.chatStyleState(param1.obj); + return; + } if(param1.obj[0] == "xfa") { AJClient.onFilterAsk(param1.obj); diff --git a/swf/ajclient.swf b/swf/ajclient.swf index 452734b..9194fbc 100644 Binary files a/swf/ajclient.swf and b/swf/ajclient.swf differ diff --git a/test/smoke.js b/test/smoke.js index 5dbd1c5..a9438da 100644 --- a/test/smoke.js +++ b/test/smoke.js @@ -158,6 +158,17 @@ const run = async () => { assert.deepStrictEqual((await b.nextXt("uc")).slice(1), [roomId, String(bobId), "hi & bye", "0"]); b.send(``); // emote: not echoed assert.deepStrictEqual((await a.nextXt("uc")).slice(3), ["7", "2"]); + + // A saved bubble style is acknowledged with every customization field and + // travels with the next public line so every patched client renders it. + const chatStyle = ["112233", "445566", "ffffff", "abcdef", "85", "flow", "150", "radial", "225", "75", "2", "112233:0;ff0069:45;445566:100"]; + b.xt("xcs", roomId, ...chatStyle); + assert.deepStrictEqual((await b.nextXt("xcs")).slice(2), chatStyle); + b.send(``); + const styledPacket = [roomId, String(bobId), "styled", "0", "", chatStyle.join(",")]; + assert.deepStrictEqual((await a.nextXt("uc")).slice(1), styledPacket); + assert.deepStrictEqual((await b.nextXt("uc")).slice(1), styledPacket); + // Actions are sent to every other player in the room. The sender has // already applied the action locally, so it is not echoed back to them. b.send(``);