2024-07-05 02:26:56 +01:00
|
|
|
import { EggTier } from "#enums/egg-type";
|
|
|
|
import { UiTheme } from "#enums/ui-theme";
|
|
|
|
import Phaser from "phaser";
|
2023-12-20 04:51:48 +00:00
|
|
|
import BBCodeText from "phaser3-rex-plugins/plugins/gameobjects/tagtext/bbcodetext/BBCodeText";
|
2023-12-30 23:41:25 +00:00
|
|
|
import InputText from "phaser3-rex-plugins/plugins/inputtext";
|
2024-04-01 02:14:35 +01:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-06-02 00:53:13 +01:00
|
|
|
import { ModifierTier } from "../modifier/modifier-tier";
|
2023-12-20 04:51:48 +00:00
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
export enum TextStyle {
|
|
|
|
MESSAGE,
|
|
|
|
WINDOW,
|
2024-04-01 02:14:35 +01:00
|
|
|
WINDOW_ALT,
|
2023-04-02 01:06:44 +01:00
|
|
|
BATTLE_INFO,
|
2023-04-07 03:24:13 +01:00
|
|
|
PARTY,
|
2023-10-03 17:50:31 +01:00
|
|
|
PARTY_RED,
|
2023-04-07 03:24:13 +01:00
|
|
|
SUMMARY,
|
2024-04-01 02:14:35 +01:00
|
|
|
SUMMARY_ALT,
|
2023-04-24 00:41:32 +01:00
|
|
|
SUMMARY_RED,
|
2024-01-06 03:24:05 +00:00
|
|
|
SUMMARY_BLUE,
|
2024-01-05 16:29:34 +00:00
|
|
|
SUMMARY_PINK,
|
2023-10-22 01:23:43 +01:00
|
|
|
SUMMARY_GOLD,
|
2024-04-13 23:59:58 +01:00
|
|
|
SUMMARY_GRAY,
|
2024-05-01 01:32:02 +01:00
|
|
|
SUMMARY_GREEN,
|
2023-10-26 21:33:59 +01:00
|
|
|
MONEY,
|
2024-05-27 12:58:20 +01:00
|
|
|
STATS_LABEL,
|
|
|
|
STATS_VALUE,
|
2023-10-26 21:33:59 +01:00
|
|
|
SETTINGS_LABEL,
|
2023-11-02 04:55:20 +00:00
|
|
|
SETTINGS_SELECTED,
|
2024-06-01 13:56:32 +01:00
|
|
|
SETTINGS_LOCKED,
|
2023-11-02 04:55:20 +00:00
|
|
|
TOOLTIP_TITLE,
|
2024-05-10 04:30:24 +01:00
|
|
|
TOOLTIP_CONTENT,
|
2024-06-10 18:30:02 +01:00
|
|
|
MOVE_INFO_CONTENT,
|
|
|
|
MOVE_PP_FULL,
|
|
|
|
MOVE_PP_HALF_FULL,
|
|
|
|
MOVE_PP_NEAR_EMPTY,
|
2024-07-05 02:26:56 +01:00
|
|
|
MOVE_PP_EMPTY,
|
2024-07-05 20:50:19 +01:00
|
|
|
SMALLER_WINDOW_ALT,
|
|
|
|
BGM_BAR
|
2024-05-23 16:03:10 +01:00
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-12-20 04:51:48 +00:00
|
|
|
export function addTextObject(scene: Phaser.Scene, x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): Phaser.GameObjects.Text {
|
2024-06-11 02:36:09 +01:00
|
|
|
const [ scale, styleOptions, shadowColor, shadowXpos, shadowYpos ] = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions);
|
2023-12-20 04:51:48 +00:00
|
|
|
|
|
|
|
const ret = scene.add.text(x, y, content, styleOptions);
|
2024-06-11 02:36:09 +01:00
|
|
|
ret.setScale(scale);
|
2024-05-21 16:00:33 +01:00
|
|
|
ret.setShadow(shadowXpos, shadowYpos, shadowColor);
|
2024-05-23 16:03:10 +01:00
|
|
|
if (!(styleOptions as Phaser.Types.GameObjects.Text.TextStyle).lineSpacing) {
|
2023-12-20 04:51:48 +00:00
|
|
|
ret.setLineSpacing(5);
|
2024-05-23 16:03:10 +01:00
|
|
|
}
|
2023-12-20 04:51:48 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-06-01 13:56:32 +01:00
|
|
|
export function setTextStyle(obj: Phaser.GameObjects.Text, scene: Phaser.Scene, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle) {
|
2024-06-11 02:36:09 +01:00
|
|
|
const [ scale, styleOptions, shadowColor, shadowXpos, shadowYpos ] = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions);
|
|
|
|
obj.setScale(scale);
|
2024-06-01 13:56:32 +01:00
|
|
|
obj.setShadow(shadowXpos, shadowYpos, shadowColor);
|
|
|
|
if (!(styleOptions as Phaser.Types.GameObjects.Text.TextStyle).lineSpacing) {
|
|
|
|
obj.setLineSpacing(5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-20 04:51:48 +00:00
|
|
|
export function addBBCodeTextObject(scene: Phaser.Scene, x: number, y: number, content: string, style: TextStyle, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): BBCodeText {
|
2024-06-11 02:36:09 +01:00
|
|
|
const [ scale, styleOptions, shadowColor, shadowXpos, shadowYpos ] = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions);
|
2023-12-20 04:51:48 +00:00
|
|
|
|
|
|
|
const ret = new BBCodeText(scene, x, y, content, styleOptions as BBCodeText.TextStyle);
|
|
|
|
scene.add.existing(ret);
|
2024-06-11 02:36:09 +01:00
|
|
|
ret.setScale(scale);
|
2024-05-21 16:00:33 +01:00
|
|
|
ret.setShadow(shadowXpos, shadowYpos, shadowColor);
|
2024-05-23 16:03:10 +01:00
|
|
|
if (!(styleOptions as BBCodeText.TextStyle).lineSpacing) {
|
2024-03-15 01:49:49 +00:00
|
|
|
ret.setLineSpacing(10);
|
2024-05-23 16:03:10 +01:00
|
|
|
}
|
2023-12-20 04:51:48 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
export function addTextInputObject(scene: Phaser.Scene, x: number, y: number, width: number, height: number, style: TextStyle, extraStyleOptions?: InputText.IConfig): InputText {
|
2024-06-11 02:36:09 +01:00
|
|
|
const [ scale, styleOptions ] = getTextStyleOptions(style, (scene as BattleScene).uiTheme, extraStyleOptions);
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
const ret = new InputText(scene, x, y, width, height, styleOptions as InputText.IConfig);
|
|
|
|
scene.add.existing(ret);
|
2024-06-11 02:36:09 +01:00
|
|
|
ret.setScale(scale);
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-07-04 21:40:54 +01:00
|
|
|
export function getTextStyleOptions(style: TextStyle, uiTheme: UiTheme, extraStyleOptions?: Phaser.Types.GameObjects.Text.TextStyle): [ number, Phaser.Types.GameObjects.Text.TextStyle | InputText.IConfig, string, number, number ] {
|
2024-05-21 16:00:33 +01:00
|
|
|
let shadowXpos = 4;
|
|
|
|
let shadowYpos = 5;
|
2024-06-11 02:36:09 +01:00
|
|
|
const scale = 0.1666666667;
|
|
|
|
const defaultFontSize = 96;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-04-24 00:41:32 +01:00
|
|
|
let styleOptions: Phaser.Types.GameObjects.Text.TextStyle = {
|
2024-06-20 16:28:47 +01:00
|
|
|
fontFamily: "emerald",
|
2024-06-11 02:36:09 +01:00
|
|
|
fontSize: 96,
|
2024-04-01 02:14:35 +01:00
|
|
|
color: getTextColor(style, false, uiTheme),
|
2023-04-24 00:41:32 +01:00
|
|
|
padding: {
|
|
|
|
bottom: 6
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
switch (style) {
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.SUMMARY:
|
|
|
|
case TextStyle.SUMMARY_ALT:
|
|
|
|
case TextStyle.SUMMARY_BLUE:
|
|
|
|
case TextStyle.SUMMARY_RED:
|
|
|
|
case TextStyle.SUMMARY_PINK:
|
|
|
|
case TextStyle.SUMMARY_GOLD:
|
|
|
|
case TextStyle.SUMMARY_GRAY:
|
|
|
|
case TextStyle.SUMMARY_GREEN:
|
|
|
|
case TextStyle.WINDOW:
|
|
|
|
case TextStyle.WINDOW_ALT:
|
2024-05-27 12:58:20 +01:00
|
|
|
case TextStyle.STATS_VALUE:
|
|
|
|
shadowXpos = 3;
|
|
|
|
shadowYpos = 3;
|
|
|
|
break;
|
2024-06-11 02:36:09 +01:00
|
|
|
case TextStyle.STATS_LABEL:
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.MESSAGE:
|
|
|
|
case TextStyle.SETTINGS_LABEL:
|
2024-06-01 13:56:32 +01:00
|
|
|
case TextStyle.SETTINGS_LOCKED:
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.SETTINGS_SELECTED:
|
|
|
|
break;
|
|
|
|
case TextStyle.BATTLE_INFO:
|
|
|
|
case TextStyle.MONEY:
|
|
|
|
case TextStyle.TOOLTIP_TITLE:
|
2024-06-11 02:36:09 +01:00
|
|
|
styleOptions.fontSize = defaultFontSize - 24;
|
2024-05-23 16:03:10 +01:00
|
|
|
shadowXpos = 3.5;
|
|
|
|
shadowYpos = 3.5;
|
|
|
|
break;
|
|
|
|
case TextStyle.PARTY:
|
|
|
|
case TextStyle.PARTY_RED:
|
2024-06-11 02:36:09 +01:00
|
|
|
styleOptions.fontSize = defaultFontSize - 30;
|
2024-05-23 16:03:10 +01:00
|
|
|
styleOptions.fontFamily = "pkmnems";
|
|
|
|
break;
|
|
|
|
case TextStyle.TOOLTIP_CONTENT:
|
2024-06-11 02:36:09 +01:00
|
|
|
styleOptions.fontSize = defaultFontSize - 32;
|
2024-05-23 16:03:10 +01:00
|
|
|
shadowXpos = 3;
|
|
|
|
shadowYpos = 3;
|
|
|
|
break;
|
|
|
|
case TextStyle.MOVE_INFO_CONTENT:
|
2024-06-11 02:36:09 +01:00
|
|
|
styleOptions.fontSize = defaultFontSize - 40;
|
2024-05-23 16:03:10 +01:00
|
|
|
shadowXpos = 3;
|
|
|
|
shadowYpos = 3;
|
|
|
|
break;
|
2024-07-05 02:26:56 +01:00
|
|
|
case TextStyle.SMALLER_WINDOW_ALT:
|
|
|
|
styleOptions.fontSize = defaultFontSize - 36;
|
|
|
|
shadowXpos = 3;
|
|
|
|
shadowYpos = 3;
|
|
|
|
break;
|
2024-07-05 20:50:19 +01:00
|
|
|
case TextStyle.BGM_BAR:
|
|
|
|
styleOptions.fontSize = defaultFontSize - 24;
|
|
|
|
shadowXpos = 3;
|
|
|
|
shadowYpos = 3;
|
|
|
|
break;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2024-05-23 16:03:10 +01:00
|
|
|
const shadowColor = getTextColor(style, true, uiTheme);
|
2023-04-24 00:41:32 +01:00
|
|
|
|
2023-04-26 17:50:21 +01:00
|
|
|
if (extraStyleOptions) {
|
|
|
|
if (extraStyleOptions.fontSize) {
|
2024-02-07 04:11:00 +00:00
|
|
|
const sizeRatio = parseInt(extraStyleOptions.fontSize.toString().slice(0, -2)) / parseInt(styleOptions.fontSize.toString().slice(0, -2));
|
2024-05-21 16:00:33 +01:00
|
|
|
shadowXpos *= sizeRatio;
|
2023-04-26 17:50:21 +01:00
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
styleOptions = Object.assign(styleOptions, extraStyleOptions);
|
2023-04-26 17:50:21 +01:00
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2024-06-11 02:36:09 +01:00
|
|
|
return [ scale, styleOptions, shadowColor, shadowXpos, shadowYpos ];
|
2023-04-24 00:41:32 +01:00
|
|
|
}
|
|
|
|
|
2024-04-05 01:33:08 +01:00
|
|
|
export function getBBCodeFrag(content: string, textStyle: TextStyle, uiTheme: UiTheme = UiTheme.DEFAULT): string {
|
|
|
|
return `[color=${getTextColor(textStyle, false, uiTheme)}][shadow=${getTextColor(textStyle, true, uiTheme)}]${content}`;
|
2024-01-05 16:29:34 +00:00
|
|
|
}
|
|
|
|
|
2024-07-10 02:26:24 +01:00
|
|
|
/**
|
|
|
|
* Should only be used with BBCodeText (see addBBCodeTextObject())
|
|
|
|
* This does NOT work with UI showText() or showDialogue() methods.
|
|
|
|
* Method will do pattern match/replace and apply BBCode color/shadow styling to substrings within the content:
|
|
|
|
* @[<TextStyle>]{<text to color>}
|
|
|
|
*
|
|
|
|
* Example: passing a content string of "@[SUMMARY_BLUE]{blue text} primaryStyle text @[SUMMARY_RED]{red text}" will result in:
|
|
|
|
* - "blue text" with TextStyle.SUMMARY_BLUE applied
|
|
|
|
* - " primaryStyle text " with primaryStyle TextStyle applied
|
|
|
|
* - "red text" with TextStyle.SUMMARY_RED applied
|
|
|
|
* @param content - string with styling that need to be applied for BBCodeTextObject
|
|
|
|
* @param primaryStyle - primary style is required in order to escape BBCode styling properly.
|
|
|
|
* @param uiTheme
|
|
|
|
*/
|
|
|
|
export function getTextWithColors(content: string, primaryStyle: TextStyle, uiTheme: UiTheme = UiTheme.DEFAULT): string {
|
|
|
|
// Apply primary styling before anything else
|
|
|
|
let text = getBBCodeFrag(content, primaryStyle, uiTheme) + "[/color][/shadow]";
|
|
|
|
const primaryStyleString = [...text.match(new RegExp(/\[color=[^\[]*\]\[shadow=[^\[]*\]/i))][0];
|
|
|
|
|
|
|
|
// Set custom colors
|
|
|
|
text = text.replace(/@\[([^{]*)\]{([^}]*)}/gi, (substring, textStyle: string, textToColor: string) => {
|
|
|
|
return "[/color][/shadow]" + getBBCodeFrag(textToColor, TextStyle[textStyle], uiTheme) + "[/color][/shadow]" + primaryStyleString;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Remove extra style block at the end
|
|
|
|
return text.replace(/\[color=[^\[]*\]\[shadow=[^\[]*\]\[\/color\]\[\/shadow\]/gi, "");
|
|
|
|
}
|
|
|
|
|
2024-04-01 02:14:35 +01:00
|
|
|
export function getTextColor(textStyle: TextStyle, shadow?: boolean, uiTheme: UiTheme = UiTheme.DEFAULT): string {
|
2023-04-24 00:41:32 +01:00
|
|
|
switch (textStyle) {
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.MESSAGE:
|
|
|
|
return !shadow ? "#f8f8f8" : "#6b5a73";
|
|
|
|
case TextStyle.WINDOW:
|
|
|
|
case TextStyle.MOVE_INFO_CONTENT:
|
2024-06-10 18:30:02 +01:00
|
|
|
case TextStyle.MOVE_PP_FULL:
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.TOOLTIP_CONTENT:
|
|
|
|
if (uiTheme) {
|
|
|
|
return !shadow ? "#484848" : "#d0d0c8";
|
|
|
|
}
|
|
|
|
return !shadow ? "#f8f8f8" : "#6b5a73";
|
2024-06-10 18:30:02 +01:00
|
|
|
case TextStyle.MOVE_PP_HALF_FULL:
|
|
|
|
if (uiTheme) {
|
|
|
|
return !shadow ? "#a68e17" : "#ebd773";
|
|
|
|
}
|
|
|
|
return !shadow ? "#ccbe00" : "#6e672c";
|
|
|
|
case TextStyle.MOVE_PP_NEAR_EMPTY:
|
|
|
|
if (uiTheme) {
|
|
|
|
return !shadow ? "#d64b00" : "#f7b18b";
|
|
|
|
}
|
|
|
|
return !shadow ? "#d64b00" : "#69402a";
|
|
|
|
case TextStyle.MOVE_PP_EMPTY:
|
|
|
|
if (uiTheme) {
|
|
|
|
return !shadow ? "#e13d3d" : "#fca2a2";
|
|
|
|
}
|
|
|
|
return !shadow ? "#e13d3d" : "#632929";
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.WINDOW_ALT:
|
|
|
|
return !shadow ? "#484848" : "#d0d0c8";
|
|
|
|
case TextStyle.BATTLE_INFO:
|
|
|
|
if (uiTheme) {
|
|
|
|
return !shadow ? "#404040" : "#ded6b5";
|
|
|
|
}
|
|
|
|
return !shadow ? "#f8f8f8" : "#6b5a73";
|
|
|
|
case TextStyle.PARTY:
|
|
|
|
return !shadow ? "#f8f8f8" : "#707070";
|
|
|
|
case TextStyle.PARTY_RED:
|
|
|
|
return !shadow ? "#f89890" : "#984038";
|
|
|
|
case TextStyle.SUMMARY:
|
2024-06-22 00:04:25 +01:00
|
|
|
return !shadow ? "#f8f8f8" : "#636363";
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.SUMMARY_ALT:
|
|
|
|
if (uiTheme) {
|
2024-06-22 00:04:25 +01:00
|
|
|
return !shadow ? "#f8f8f8" : "#636363";
|
2024-05-23 16:03:10 +01:00
|
|
|
}
|
|
|
|
return !shadow ? "#484848" : "#d0d0c8";
|
|
|
|
case TextStyle.SUMMARY_RED:
|
|
|
|
case TextStyle.TOOLTIP_TITLE:
|
|
|
|
return !shadow ? "#e70808" : "#ffbd73";
|
|
|
|
case TextStyle.SUMMARY_BLUE:
|
|
|
|
return !shadow ? "#40c8f8" : "#006090";
|
|
|
|
case TextStyle.SUMMARY_PINK:
|
|
|
|
return !shadow ? "#f89890" : "#984038";
|
|
|
|
case TextStyle.SUMMARY_GOLD:
|
|
|
|
case TextStyle.MONEY:
|
|
|
|
return !shadow ? "#e8e8a8" : "#a0a060";
|
2024-06-01 13:56:32 +01:00
|
|
|
case TextStyle.SETTINGS_LOCKED:
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.SUMMARY_GRAY:
|
|
|
|
return !shadow ? "#a0a0a0" : "#636363";
|
2024-05-27 12:58:20 +01:00
|
|
|
case TextStyle.STATS_LABEL:
|
|
|
|
return !shadow ? "#f8b050" : "#c07800";
|
|
|
|
case TextStyle.STATS_VALUE:
|
|
|
|
return !shadow ? "#f8f8f8" : "#6b5a73";
|
2024-05-23 16:03:10 +01:00
|
|
|
case TextStyle.SUMMARY_GREEN:
|
|
|
|
return !shadow ? "#78c850" : "#306850";
|
|
|
|
case TextStyle.SETTINGS_LABEL:
|
|
|
|
return !shadow ? "#f8b050" : "#c07800";
|
|
|
|
case TextStyle.SETTINGS_SELECTED:
|
|
|
|
return !shadow ? "#f88880" : "#f83018";
|
2024-07-05 02:26:56 +01:00
|
|
|
case TextStyle.SMALLER_WINDOW_ALT:
|
|
|
|
return !shadow ? "#484848" : "#d0d0c8";
|
2024-07-05 20:50:19 +01:00
|
|
|
case TextStyle.BGM_BAR:
|
|
|
|
return !shadow ? "#f8f8f8" : "#6b5a73";
|
2023-04-24 00:41:32 +01:00
|
|
|
}
|
2023-11-02 04:55:20 +00:00
|
|
|
}
|
|
|
|
|
2024-02-29 04:13:05 +00:00
|
|
|
export function getModifierTierTextTint(tier: ModifierTier): integer {
|
2023-11-02 04:55:20 +00:00
|
|
|
switch (tier) {
|
2024-05-23 16:03:10 +01:00
|
|
|
case ModifierTier.COMMON:
|
2024-06-22 00:04:25 +01:00
|
|
|
return 0xf8f8f8;
|
2024-05-23 16:03:10 +01:00
|
|
|
case ModifierTier.GREAT:
|
2024-06-22 00:04:25 +01:00
|
|
|
return 0x4998f8;
|
2024-05-23 16:03:10 +01:00
|
|
|
case ModifierTier.ULTRA:
|
|
|
|
return 0xf8d038;
|
|
|
|
case ModifierTier.ROGUE:
|
2024-06-22 00:04:25 +01:00
|
|
|
return 0xdb4343;
|
2024-05-23 16:03:10 +01:00
|
|
|
case ModifierTier.MASTER:
|
2024-06-22 00:04:25 +01:00
|
|
|
return 0xe331c5;
|
2024-05-23 16:03:10 +01:00
|
|
|
case ModifierTier.LUXURY:
|
2024-06-22 00:04:25 +01:00
|
|
|
return 0xe74c18;
|
2023-11-02 04:55:20 +00:00
|
|
|
}
|
2024-02-29 04:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getEggTierTextTint(tier: EggTier): integer {
|
|
|
|
switch (tier) {
|
2024-05-23 16:03:10 +01:00
|
|
|
case EggTier.COMMON:
|
|
|
|
return getModifierTierTextTint(ModifierTier.COMMON);
|
|
|
|
case EggTier.GREAT:
|
|
|
|
return getModifierTierTextTint(ModifierTier.GREAT);
|
|
|
|
case EggTier.ULTRA:
|
|
|
|
return getModifierTierTextTint(ModifierTier.ULTRA);
|
|
|
|
case EggTier.MASTER:
|
|
|
|
return getModifierTierTextTint(ModifierTier.MASTER);
|
2024-02-29 04:13:05 +00:00
|
|
|
}
|
2024-05-23 16:03:10 +01:00
|
|
|
}
|