查看: 1774|回复: 2

[有事请教] 如何新增控制碼 改變數組文字顏色與顯示圖標 求腳本修改

[复制链接]
梦石
0
星屑
2179
在线时间
379 小时
注册时间
2023-6-6
回帖
16
发表于 2023-7-18 01:16:38 | 显示全部楼层 |阅读模式
悬赏100星屑未解决
本帖最后由 xuprmpau 于 2023-7-20 01:04 编辑

首先此腳本功能請看
http://ytomy.sakura.ne.jp/tkool/rpgtech/php/tech.php?tool=XP&cat=tech_xp/menu&tech=outline#USAGE

接著想求 如何在此腳本的數組文字
新增兩項功能   
1.
如果寫\\C[N]文字
則文字會像內建的改變文字顏色一樣去改變顏色
2.
如果寫\\I[檔名]則顯示Icons資料夾裡相對應檔名的圖標圖案

以下腳本

[pre lang="ruby"]#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/    ◆ あらすじ - KGC_Outline ◆
#_/    ◇ Last update : 2007/05/28 ◇
#_/----------------------------------------------------------------------------
#_/  あらすじを閲覧する機能を追加します。
#_/  Provides the function to show "Outline".
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

#==============================================================================
# ★ カスタマイズ項目 - Customize ★
#==============================================================================

module KGC
  # ◆あらすじ画面背景透過
  OLINE_BACK_TRANSPARENT = true
  # ◆スクロール速度【単位:px】
  OLINE_SCROLL_SPEED = 8

  # ◆通し番号を描画
  OLINE_SERIAL_NUMBER = false
  # ◆通し番号の桁数
  OLINE_SERIAL_NUMBER_DIGITS = 3

  # ◆無効なあらすじのタイトル
  OLINE_DISABLED_TITLE = "- - - - - - - -"
  # ◆無効なあらすじは表示しない
  OLINE_HIDE_DISABLED  = true

  # ◆完了記号
  OLINE_COMPLETION_SYMBOL   = "★"
  # ◆未完記号
  OLINE_INCOMPLETION_SYMBOL = " "

  # ◆あらすじ内容
  #  ≪["タイトル", ["本文", ...]], ...≫
  #  本文は、配列の各要素が1行に相当。
  #    **** 制御コマンド ****
  #  \\V[n]  : 変数 ID:n
  #  \\G     : 所持金
  #  \\N[n]  : ID:n のアクター名
  #  \\EN[n] : ID:n のエネミー名
  #  \\IN[n] : ID:n のアイテム名
  #  \\WN[n] : ID:n の武器名
  #  \\AN[n] : ID:n の防具名
  OLINE_CONTENTS = [
    ["操作方法",  # No.0
      ["遊戲基本操作:",
      "ENTER、SPACE、C鍵:確認/調查/對話    ",
      "ESC、X鍵   :取消/呼叫選單",
      "↑↓←→     :方向移動",
      "同時按下ALT+ENTER鍵:切換全螢幕/視窗畫面",]],
    ["魔法屬性",  # No.1
      ["突然見知らぬ場所へ飛ばされてしまった。",
      "ここは一体どこなのだろうか?",
      "",
      "……むぅ。",
      "ここで腐っていても仕方が無いので、とりあえず周囲の",
      "探索をすることになってしまったらしい。",
      "はぁ、めんどくさ(´・ω・`)",
      "早く帰って風呂入って寝てぇ。",
      "",
      "\\N[2]「\\N[1]、真面目に書け。」",
      "",
      "\\N[2]…、見てたの?",
      "",
      "\\N[2]「当たり前だ。」",
      "",
      "いや、てか何でお前も書いてるんだ?",
      "今日は俺の当番 うわなにをするやめ(ry",
      "",
      "\\N[2]「まったく、お前に任せるとロクなことを書かないな。",
      "明日からお前抜きで書かせて貰うぞ。」",
      "",
      "そ、そりゃちっとヒドイんではないかい?",
      "",
      "\\N[2]「反省したか?」",
      "",
      "うぐ…、すいません。"]],
     ["狀態一覽表",  # No.0
      ["行動狀態:",
      "ENTER、SPACE、C鍵:確認/調查/對話    ",
      "ESC、X鍵:  取消/呼叫選單",
      "↑↓←→:  方向移動",
      "同時按下ALT+ENTER鍵: 切換全螢幕/視窗畫面",]]
  ]  # -- Don't delete this line! --
end

#### OLINE_BACK_TRANSPARENT
### Makes the background of "Outline" transparency.

#### OLINE_SCROLL_SPEED
### Scroll speed. {Unit : pixel}

#### OLINE_SERIAL_NUMBER
### Draws the serial number.

#### OLINE_SERIAL_NUMBER_DIGITS
### Digits of the serial number.

#### OLINE_HIDE_DISABLED
### Hides disabled "Outline".

#### OLINE_COMPLETION_SYMBOL
### Completion symbol.

#### OLINE_INCOMPLETION_SYMBOL
### Incompletion symbol.


#### OLINE_CONTENTS
### Contents of "Outline".
#  << ["Title", ["Body", ...]], ... >>
#  In the "Body", each element of the array corresponds to one line.
#    **** Control statement ****
#  \\V[n]  : Variable of ID:n
#  \\G     : Money
#  \\N[n]  : Actor's name of ID:n
#  \\EN[n] : Enemies' name of ID:n
#  \\IN[n] : Item's name of ID:n
#  \\WN[n] : Weapon's name of ID:n
#  \\AN[n] : Armor's name of ID:n

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

$imported = {} if $imported == nil
$imported["Outline"] = true

#--------------------------------------------------------------------------
# ● あらすじ画面呼び出し
#--------------------------------------------------------------------------
def call_outline
  # プレイヤーの姿勢を矯正
  $game_player.straighten
  # あらすじ画面に切り替え
  $scene = Scene_Outline.new(true)
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Module - KGC_Outline
#==============================================================================

module KGC::Outline
  #--------------------------------------------------------------------------
  # ● あらすじ有効化
  #     index : あらすじ番号
  #     value : 有効状態 (true | false)
  #--------------------------------------------------------------------------
  def self.set_enabled(index, value = true)
    if $game_system.outline_enable == nil
      $game_system.outline_enable = []
    end
    $game_system.outline_enable[index] = value
  end
  #--------------------------------------------------------------------------
  # ● あらすじ完了
  #     index : あらすじ番号
  #     value : 完了状態 (true | false)
  #--------------------------------------------------------------------------
  def self.set_completed(index, value = true)
    if $game_system.outline_complete == nil
      $game_system.outline_complete = []
    end
    $game_system.outline_complete[index] = value
  end
  #--------------------------------------------------------------------------
  # ● 制御コマンド処理
  #     string : 処理対象文字列
  #--------------------------------------------------------------------------
  def self.apply_control_statement(string)
    buf = string.dup
    buf.gsub!(/\\V\[(\d+)\]/i) { $game_variables[$1.to_i].to_s }
    buf.gsub!(/\\G/i) { $game_party.gold.to_s }
    buf.gsub!(/\\N\[(\d+)\]/i) { $game_actors[$1.to_i].name }
    buf.gsub!(/\\EN\[(\d+)\]/i) { $data_enemies[$1.to_i].name }
    buf.gsub!(/\\IN\[(\d+)\]/i) { $data_items[$1.to_i].name }
    buf.gsub!(/\\WN\[(\d+)\]/i) { $data_weapons[$1.to_i].name }
    buf.gsub!(/\\AN\[(\d+)\]/i) { $data_armors[$1.to_i].name }
    return buf
  end
  #
  #
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Game_System
#==============================================================================

class Game_System
  attr_accessor :outline_enable, :outline_complete
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias initialize_KGC_Outline initialize
  def initialize
    initialize_KGC_Outline

    @outline_enable = []
    @outline_complete = []
  end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Window_OutlineList
#------------------------------------------------------------------------------
#  あらすじ一覧を表示するウィンドウです。
#==============================================================================

class Window_OutlineList < Window_Selectable
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 160, 400)
    self.back_opacity = 160 if KGC::OLINE_BACK_TRANSPARENT
    self.index = 0
    self.z = 1000
    refresh
  end
  #--------------------------------------------------------------------------
  # ● 選択あらすじ内容
  #--------------------------------------------------------------------------
  def outline
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    self.contents.dispose if self.contents != nil
    @data = []
    @data_index = []
    # リスト作成
    $game_system.outline_enable = [] if $game_system.outline_enable == nil
    $game_system.outline_complete = [] if $game_system.outline_complete == nil
    KGC::OLINE_CONTENTS.each_with_index { |oline, i|
      if $game_system.outline_enable
        @data << OutlineList_Info.new(oline[0], oline[1], i)
      elsif !KGC::OLINE_HIDE_DISABLED
        @data << OutlineList_Info.new(KGC::OLINE_DISABLED_TITLE, nil, i)
      end
    }
    # リスト描画
    @item_max = [@data.size, 1].max
    self.contents = Bitmap.new(self.width - 32, 32 * @item_max)
    if @data.size == 0
      @data << OutlineList_Info.new
    else
      @data.each_index { |i| draw_item(i) }
    end
    # 根据列表项的数量计算窗口的高度
    window_height = [32 * @item_max+32, 400].min
    # 设置窗口的高度
    self.height = window_height
  end
  #--------------------------------------------------------------------------
  # ● 項目描画
  #--------------------------------------------------------------------------
  def draw_item(index)
    self.contents.fill_rect(0, 32 * index, self.width - 32, 32, Color.new(0, 0, 0, 0))
    # タイトル生成
    text = ($game_system.outline_complete[@data[index].index] ?
      KGC::OLINE_COMPLETION_SYMBOL : KGC::OLINE_INCOMPLETION_SYMBOL) +
      (KGC::OLINE_SERIAL_NUMBER ? sprintf("%0*d : ",
      KGC::OLINE_SERIAL_NUMBER_DIGITS, @data[index].index + 1) : "") +
      KGC::Outline.apply_control_statement(@data[index].title)
    # 描画色設定
    self.contents.font.color = $game_system.outline_enable[@data[index].index] ?
      normal_color : disabled_color
    self.contents.draw_text(0, 32 * index, self.width - 32, 32, text)
  end
end

#==============================================================================
# ■ OutlineList_Info
#------------------------------------------------------------------------------
#   あらすじ一覧の情報を保持するクラスです。
#==============================================================================

class OutlineList_Info
  attr_accessor :title, :contents, :index
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(title = "", contents = nil, index = 0)
    @title = title
    @contents = contents
    @index = index
  end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Window_OutlineTitle
#------------------------------------------------------------------------------
#  あらすじの題名を表示するウィンドウです。
#==============================================================================

class Window_OutlineTitle < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 160 if KGC::OLINE_BACK_TRANSPARENT
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #     text  : 表示する文字列
  #--------------------------------------------------------------------------
  def refresh(text)
    self.contents.clear
    text2 = KGC::Outline.apply_control_statement(text)
    self.contents.draw_text(0, 0, self.width - 32, 32, text2, 1)
  end
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Window_Outline
#------------------------------------------------------------------------------
#  あらすじ(の内容)を表示するウィンドウです。
#==============================================================================

class Window_Outline < Window_Base
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    super(160, 64, 480, 416)
    self.back_opacity = 160 if KGC::OLINE_BACK_TRANSPARENT
    self.active = false
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #     oline : あらすじ
  #--------------------------------------------------------------------------
  def refresh(oline = nil)
    self.oy = 0
    self.contents.dispose if self.contents != nil
    return if oline == nil
    # 本文を描画
    self.contents = Bitmap.new(self.width - 32, 32 * oline.size)
    oline.each_with_index { |l ,i|
      next if l == nil
      text = KGC::Outline.apply_control_statement(l)
     self.contents.draw_text(0, i * 32, self.width - 32, 32, text)
    }
  end
  #--------------------------------------------------------------------------
  # ● 更新
  #--------------------------------------------------------------------------
  def update
    super
    # スクロール
    if self.active
      scroll_max = [self.contents.height - (self.height - 32), 0].max
      if Input.press?(Input::UP)
        self.oy = [self.oy - KGC::OLINE_SCROLL_SPEED, 0].max
      elsif Input.press?(Input::DOWN)
        self.oy = [self.oy + KGC::OLINE_SCROLL_SPEED, scroll_max].min
      elsif Input.repeat?(Input::L)
        self.oy = [self.oy - (self.height - 32), 0].max
      elsif Input.repeat?(Input::R)
        self.oy = [self.oy + (self.height - 32), scroll_max].min
      end
    end
  end
  #
  #
end

#★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★

#==============================================================================
# ■ Scene_Outline
#------------------------------------------------------------------------------
#  あらすじ画面の処理を行うクラスです。
#==============================================================================

class Scene_Outline
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #     map_call : マップからの呼び出しフラグ
  #--------------------------------------------------------------------------
  def initialize(map_call = false)
    @map_call = map_call
  end
  #--------------------------------------------------------------------------
  # ● メイン処理
  #--------------------------------------------------------------------------
  def main
    # スプライトセットを作成
    @spriteset = Spriteset_Map.new if KGC::OLINE_BACK_TRANSPARENT
    # ウィンドウを作成
    @list_window = Window_OutlineList.new
    @title_window = Window_OutlineTitle.new
    @content_window = Window_Outline.new
    # トランジション実行
    Graphics.transition
    # メインループ
    loop {
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    }
    # トランジション準備
    Graphics.freeze
    # ウィンドウを解放
    @list_window.dispose
    @title_window.dispose
    @content_window.dispose
    @spriteset.dispose if KGC::OLINE_BACK_TRANSPARENT
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    # ウィンドウ更新
    @list_window.update
    @title_window.update
    @content_window.update
    # アクティブウィンドウ操作
    if @list_window.active
      update_list
    elsif @content_window.active
      update_content
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新 (リスト)
  #--------------------------------------------------------------------------
  def update_list
    # B ボタンが押された場合
    if Input.trigger?(Input::B)
      # キャンセル SE を演奏
      $game_system.se_play($data_system.cancel_se)
      if @map_call
        # マップ画面に切り替え
        $scene = Scene_Map.new
      else
        # メニュー画面に切り替え
        if $imported["MenuAlter"]
          index = KGC::MA_COMMANDS.index(12)
          if index != nil
            $scene = Scene_Menu.new(index)
          else
            $scene = Scene_Menu.new
          end
        else
          $scene = Scene_Menu.new
        end
      end
      return
    end
    # C ボタンが押された場合
    if Input.trigger?(Input::C)
      outline = @list_window.outline
      # 閲覧できない場合
      if outline.contents == nil
        # ブザー SE を演奏
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 決定 SE を演奏
      $game_system.se_play($data_system.decision_se)
      # あらすじを更新
      @title_window.refresh(outline.title)
      @content_window.refresh(outline.contents)
      # ウィンドウ切り替え
      @list_window.active = false
      @list_window.z = 0
      @content_window.active = true
      @content_window.z = 1000
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新 (本文)
  #--------------------------------------------------------------------------
  def update_content
    # B ボタンが押された場合
    if Input.trigger?(Input::B)
      # キャンセル SE を演奏
      $game_system.se_play($data_system.cancel_se)
      # ウィンドウ切り替え
      @list_window.active = true
      @list_window.z = 1000
      @content_window.active = false
      @content_window.z = 0
      return
    end
  end
end
[/pre]

梦石
0
星屑
2179
在线时间
379 小时
注册时间
2023-6-6
回帖
16
 楼主| 发表于 2023-7-20 01:02:50 | 显示全部楼层
以下是葉子任務系統的控制碼部分
  1. class Game_Task
  2.   attr_accessor   :name                   # 名稱
  3.   attr_accessor   :briefing               # 簡介
  4.   def initialize(name, briefing)
  5.     @name = name
  6.     @briefing = briefing
  7.   end
  8.   def height
  9.     text = @briefing.clone
  10.     x = 0
  11.     y = 64
  12.     min_y = 0
  13.     # 限制文字處理
  14.     begin
  15.       last_text = text.clone
  16.       text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  17.     end until text == last_text
  18.     text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  19.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  20.     end
  21.     # 為了方便、將 "\\\" 變換為 "\000"
  22.     text.gsub!(/\\\\/) { "\000" }
  23.     # "\C" 變為 "\001"
  24.     text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  25.     # "\I" 變為 "\002"
  26.     text.gsub!(/\\[Ii]/) { "\002" }
  27.     # "\P" 變為 "\003"
  28.     text.gsub!(/\\[Pp]/) { "\003" }
  29.     # c 獲取 1 個字 (如果不能取得文字就循環)
  30.     while ((c = text.slice!(/./m)) != nil)
  31.       # \\ 的情況下
  32.       if c == "\000"
  33.         # 還原為本來的文字
  34.         c = "\"
  35.       end
  36.       # \C[n] 的情況下
  37.       if c == "\001"
  38.         # 更改文字色
  39.         text.sub!(/\[([0-9]+)\]/, "")
  40.         # 下面的文字
  41.         next
  42.       end
  43.       # 圖標的情況下
  44.       if c == "\002"
  45.         icon_name = ''
  46.         while ((cha = text.slice!(/./m)) != ']')
  47.           next if cha == '['
  48.           icon_name += cha
  49.         end
  50.         icon = RPG::Cache.icon(icon_name)
  51.         if x + icon.width > 368
  52.           x = 0
  53.           y += [32, min_y].max
  54.           min_y = 0
  55.         end
  56.         x += 28
  57.         next
  58.       end
  59.       # 圖片的情況下
  60.       if c == "\003"
  61.         pic_name = ''
  62.         while ((cha = text.slice!(/./m)) != ']')
  63.           next if cha == '['
  64.           pic_name += cha
  65.         end
  66.         pic = RPG::Cache.picture(pic_name)
  67.         if x + pic.width > 368
  68.           x = 0
  69.           y += [32, min_y].max
  70.           min_y = 0
  71.         end
  72.         x += pic.width
  73.         min_y = [pic.height, 32].max
  74.         next
  75.       end
  76.       # 另起一行文字的情況下
  77.       if c == "\n"
  78.         y += [32, min_y].max
  79.         min_y = 0
  80.         x = 0
  81.         # 下面的文字
  82.         next
  83.       end
  84.       # 自動換行處理
  85.       if x + 22 > 368
  86.         y += [32, min_y].max
  87.         min_y = 0
  88.         x = 0
  89.       end
  90.       # x 為要描繪文字的加法運算
  91.       x += 22
  92.     end
  93.     return (y + [32, min_y].max)
  94.   end
  95.   def id
  96.     return $game_party.tasks_info.index(self)
  97.   end
  98. end
复制代码


如果我沒理解錯 是不是像這樣添加在我上述腳本def self.apply_control_statement(string)裡面???
我自己怎麼弄都 弄不成功
求解


回复

使用道具 举报

梦石
0
星屑
8003
在线时间
1184 小时
注册时间
2007-7-29
回帖
2014
发表于 2023-7-26 02:08:49 | 显示全部楼层
apply_control_statement 只是把格式化的字符串替换成对应的字符串,过程不涉及描绘。\c[n] 这类改变颜色的做法通常是在描绘时处理,我目测应该是在 draw_item 里头。
稍微了解脚本的应该都有办法改到,只是这玩意儿手上没有RM debug很麻烦,目前我手头上就没RM,只能理论提及。
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部