设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 37|回复: 0
打印 上一主题 下一主题

[原创发布] 根据不同角色调整对话框颜色

[复制链接]

Lv1.梦旅人

梦石
0
星屑
66
在线时间
7 小时
注册时间
2025-4-29
帖子
8
跳转到指定楼层
1
发表于 19 小时前 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
做了一个这个插件,感觉对对话类游戏非常有用。
支持不同角色名字的对话框/ 名字框自定义颜色;还支持非角色的对话框的自定义颜色,非常好用,直接在编辑器里写名字即可。


代码有点长,在这里:

https://sekishiyo.itch.io/

https://github.com/SekiShiyo/RMMZ/tree/main/DialogueTint







/*:
* @target MZ
* @plugindesc Speaker-based message and name window background color v1.6 (no flash, preserves skin) by SekiShiyo
* @author SekiShiyo
*
* @param SpeakerColors
* @text Speaker Color Config
* @type struct<ColorConfig>[]
* @desc Set background colors for specific speakers
*
* @param DefaultColor
* @text Default Background Color
* @type string
* @default rgba(0,0,0,0.3)
* @desc Used when no speaker name matches; supports transparency
*
* @help
* ✅ Keeps default window skin and border
* ✅ Prevents white flash on name window open/close
* ✅ Auto-hides background if no speaker name is shown
*/

/*~struct~ColorConfig:
* @param name
* @text Speaker Name
* @type string
*
* @param color
* @text Background Color (RGBA)
* @type string
* @default rgba(0,0,0,180)
*/

(() => {
    const pluginName = "SpeakerWindowColor";
    const params = PluginManager.parameters(pluginName);
  
    const colorConfigs = JSON.parse(params["SpeakerColors"] || "[]").map(str => {
      const obj = JSON.parse(str);
      return { name: obj.name, color: obj.color };
    });
    const defaultColor = params["DefaultColor"] || "rgba(0,0,0,0.3)";
  
    function parseCssColor(text) {
      const vals = text.replace(/\s+/g, "").replace(/^rgba?\(/i, "").replace(/\)$/, "").split(",");
      if (vals.length >= 3) {
        const r = parseInt(vals[0]);
        const g = parseInt(vals[1]);
        const b = parseInt(vals[2]);
        let a = parseFloat(vals[3] ?? "255");
        if (a > 1) a = a / 255;
        return `rgba(${r},${g},${b},${a.toFixed(3)})`;
      }
      return text;
    }
  
    // ✅ Message window background
    const _Window_Message_startMessage = Window_Message.prototype.startMessage;
    Window_Message.prototype.startMessage = function () {
      const name = $gameMessage.speakerName();
      const match = colorConfigs.find(cfg => cfg.name === name);
      const color = match ? parseCssColor(match.color) : parseCssColor(defaultColor);
  
      if (!this._customBgSprite) {
        this._customBgSprite = new Sprite(new Bitmap(this.width, this.height));
        this._customBgSprite.z = -1;
        this.addChildToBack(this._customBgSprite);
      }
  
      const bmp = this._customBgSprite.bitmap;
      bmp.resize(this.width, this.height);
      bmp.clear();
      bmp.fillRect(0, 0, this.width, this.height, color);
  
      _Window_Message_startMessage.call(this);
    };
  
    // ✅ Name box with no flash and window skin
    const _Window_NameBox_start = Window_NameBox.prototype.start;
    Window_NameBox.prototype.start = function () {
      const name = $gameMessage.speakerName();
      const showBg = name && name.trim();
      this._lastSpeakerName = name;
  
      if (this._customNameBg) {
        this.removeChild(this._customNameBg);
        this._customNameBg.destroy();
        this._customNameBg = null;
      }
  
      _Window_NameBox_start.call(this); // ← run system layout first
  
      if (showBg && this.width > 0 && this.height > 0) {
        const match = colorConfigs.find(cfg => cfg.name === name);
        const color = match ? parseCssColor(match.color) : parseCssColor(defaultColor);
  
        const bmp = new Bitmap(this.width, this.height);
        bmp.fillRect(0, 0, this.width, this.height, color);
        this._customNameBg = new Sprite(bmp);
        this._customNameBg.z = -2;
        this.addChildToBack(this._customNameBg);
      }
  
      if (this.contentsBack) {
        this.contentsBack.clear(); //

评分

参与人数 1+1 收起 理由
马铃薯条 + 1 精品文章

查看全部评分

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-5-13 20:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表