查看: 1700|回复: 5

[有事请教] 战斗图标选中切换新的战斗图标

[复制链接]
梦石
0
星屑
1442
在线时间
171 小时
注册时间
2019-10-4
回帖
162
发表于 2023-8-9 00:05:24 | 显示全部楼层 |阅读模式
悬赏1000星屑未解决
本帖最后由 契约师Vi 于 2023-8-9 00:06 编辑

[pre lang="ruby"]#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================

module Momo_IconCommand
  # 图标名称设定
  ATTACK_ICON_NAME = "攻击" # 攻撃
  SKILL_ICON_NAME = "法术"   # 特技
  GUARD_ICON_NAME = "防御"  # 防御
  ITEM_ICON_NAME = "道具"     # 物品
  # X坐标修正
  X_PLUS = -160
  # Y坐标修正
  Y_PLUS = -240
  # 选择时图标的动作
  # 0:静止 1:放大
  SELECT_TYPE = 0
  # 闪烁时光芒的颜色
  FLASH_COLOR = Color.new(255, 255, 255, 128)
  # 闪烁时间
  FLASH_DURATION = 10
  # 闪烁间隔
  FLASH_INTERVAL = 40
  # 是否写出文字的名称
  COM_NAME_DROW = false
  # 文字名称是否移动
  COM_NAME_MOVE = false
  # 文字内容
  ATTACK_NAME = "攻击"    # 攻击
  SKILL_NAME = "特技"   # 特技
  GUARD_NAME = "防御"     # 防御
  ITEM_NAME = "物品"  # 物品
  # 文字颜色
  COM_NAME_COLOR = Color.new(255, 255, 255, 255)
  # 文字坐标修正
  COM_NAME_X_PLUS = 0
  COM_NAME_Y_PLUS = 0
end

class Window_CommandIcon < Window_Selectable
  attr_accessor :last_index
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x, y, commands)
    super(x, y, 32, 32)
    # ウィンドウスキンに空文字列を指定してウィンドウを描画しないようにする
    self.windowskin = RPG::Cache.windowskin("")
   @item_max = commands.size #项目数
   @commands = commands #指令数
   @column_max = 1
    @index = 0
    @last_index = nil
    @name_sprite = nil
    @sprite = []
    refresh
  end
  def dispose
    super
    for sprite in @sprite
      sprite.dispose unless sprite.nil?
    end
    @name_sprite.dispose unless @name_sprite.nil?
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    @name_sprite.dispose unless @name_sprite.nil?
    for sprite in @sprite
      sprite.dispose unless sprite.nil?
    end
    @name_sprite = nil
    draw_com_name if Momo_IconCommand::COM_NAME_DROW
    @sprite = []
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # ● 項目の描画
  #--------------------------------------------------------------------------
  def draw_item(index)
    @sprite[index] = Sprite_Icon.new(nil, @commands[index])
    @sprite[index].z = self.z + 1
  end
  def draw_com_name
    @name_sprite = Sprite_Comm_Name.new(nil, get_com_name)
   
  end
  
  # 更新
  def update
    super
    icon_update
    com_name_update if Momo_IconCommand::COM_NAME_DROW
    if move_index?
      @last_index = self.index
    end
  end
  # アイコンの更新
  def icon_update
    for i in 0...@sprite.size
      @sprite.active = (self.index == i)
      @sprite.x = self.x
      @sprite.y = self.y + i*26
      @sprite.z = (self.index == i) ? self.z + 2 : self.z + 1
      @sprite.visible = self.visible
      @sprite.update
    end
  end
  # コマンドネームの更新
  def com_name_update
    if move_index?
      @name_sprite.name = get_com_name
    end
    @name_sprite.x = self.x - 12 + Momo_IconCommand::COM_NAME_X_PLUS
    @name_sprite.y = self.y - 40 + Momo_IconCommand::COM_NAME_Y_PLUS
    @name_sprite.z = self.z + 1
    @name_sprite.active = self.active
    @name_sprite.visible = self.visible
    @name_sprite.update
  end
  def get_com_name
    make_name_set if @name_set.nil?
    name = @name_set[self.index]
    name = "" if name.nil?
    return name
  end
  def make_name_set
    @name_set = []
    @name_set[0] = Momo_IconCommand::ATTACK_NAME
    @name_set[1] = Momo_IconCommand::SKILL_NAME
    @name_set[2] = Momo_IconCommand::GUARD_NAME
    @name_set[3] = Momo_IconCommand::ITEM_NAME
  end
  def move_index?
    return self.index != @last_index
  end
  def need_reset
    @name_sprite.need_reset = true if Momo_IconCommand::COM_NAME_DROW
  end
end

# アイコン用スプライト
class Sprite_Icon < Sprite
  attr_accessor :active
  attr_accessor :icon_name
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(viewport, icon_name)
    super(viewport)
    @icon_name = icon_name
    @last_icon = @icon_name
    @count = 0
    self.bitmap = RPG::Cache.icon(@icon_name)
    self.ox = self.bitmap.width / 2
    self.oy = self.bitmap.height / 2
    @active = false
  end
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    if @icon_name != @last_icon
      @last_icon = @icon_name
      self.bitmap = RPG::Cache.icon(@icon_name)
    end
    if @active
      @count += 1
      case Momo_IconCommand::SELECT_TYPE
      when 0
        icon_flash
      when 1
        icon_zoom
      end
      @count = 0 if @count == 20
    else
      icon_reset
    end
  end
  def icon_flash
    if @count % Momo_IconCommand::FLASH_INTERVAL == 0 or @count == 1
      self.flash(Momo_IconCommand::FLASH_COLOR, Momo_IconCommand::FLASH_DURATION)
    end
  end
  def icon_zoom
    case @count
    when 1..10
      zoom = 1.0 + @count / 10.0
    when 11..20
      zoom = 2.0 - (@count - 10) / 10.0
    end
    self.zoom_x = zoom
    self.zoom_y = zoom
  end
  def icon_reset
    @count = 0
    self.zoom_x = 1.0
    self.zoom_y = 1.0
  end
end

# コマンドネーム用スプライト
class Sprite_Comm_Name < Sprite
  attr_accessor :active
  attr_accessor :name
  attr_accessor :need_reset
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(viewport, name)
    super(viewport)
    @name = name
    @last_name = nil
    @count = 0
    @x_plus = 0
    @opa_plus = 0
    @need_reset = false
    @active = false
    self.bitmap = Bitmap.new(160, 32)
  end
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    if @active
      if need_reset?
        @need_reset = false
        @last_name = @name
        text_reset
      end
      move_text if Momo_IconCommand::COM_NAME_MOVE
    end
  end
  def move_text
    @count += 1
    @x_plus = [@count * 8, 80].min
    self.x = self.x - 80 + @x_plus
    self.opacity = @count * 25
  end
  def text_reset
    @count = 0
    @x_plus = 0
    self.bitmap.clear
    self.bitmap.font.color = Momo_IconCommand::COM_NAME_COLOR
    self.bitmap.draw_text(0, 0, 160, 32, @name)
  end
  def need_reset?
    return (@name != @last_name or @need_reset)
  end
end

class Scene_Battle
  #--------------------------------------------------------------------------
  # ● プレバトルフェーズ開始
  #--------------------------------------------------------------------------
  alias scene_battle_icon_command_start_phase1 start_phase1
  def start_phase1
    com1 = Momo_IconCommand::ATTACK_ICON_NAME
    com2 = Momo_IconCommand::SKILL_ICON_NAME
    com3 = Momo_IconCommand::GUARD_ICON_NAME
    com4 = Momo_IconCommand::ITEM_ICON_NAME
    @actor_command_window = Window_CommandIcon.new(0, 0, [com1, com2, com3, com4])
    @actor_command_window.y = 160
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
    @actor_command_window.update
    scene_battle_icon_command_start_phase1
  end
  #--------------------------------------------------------------------------
  # ● アクターコマンドウィンドウのセットアップ
  #--------------------------------------------------------------------------
  alias scene_battle_icon_command_phase3_setup_command_window phase3_setup_command_window
  def phase3_setup_command_window
    scene_battle_icon_command_phase3_setup_command_window
    # アクターコマンドウィンドウの位置を設定
    @actor_command_window.x = command_window_actor_x(@actor_index)
    @actor_command_window.y = command_window_actor_y(@actor_index)
    @actor_command_window.need_reset
  end
  def command_window_actor_x(index)
    $game_party.actors[index].screen_x + Momo_IconCommand::X_PLUS
  end
  def command_window_actor_y(index)
    $game_party.actors[index].screen_y + Momo_IconCommand::Y_PLUS
  end
end

#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================

[/pre]
就是有两套图标,选中之后就替换。比较类似标题菜单那种,选中之后就切换另外一个图标。 QQ浏览器截图20230809000438.png QQ浏览器截图20230809000334.png

梦石
0
星屑
4756
在线时间
389 小时
注册时间
2012-11-8
回帖
235
发表于 2023-8-9 08:28:36 | 显示全部楼层
本帖最后由 qq634488405 于 2023-8-9 08:33 编辑
  1.   #--------------------------------------------------------------------------
  2.   # ● 描绘项目
  3.   #     index : 项目编号
  4.   #     color : 文字色
  5.   #--------------------------------------------------------------------------
  6.   def draw_item(index, color)
  7.     self.contents.font.color = color
  8.     # 计算得出当前index所对应的内容所在的行
  9.     row_index = index / @column_max
  10.     # 根据余数得出所在的列
  11.     for y in 0...@column_max
  12.       if index % @column_max == y
  13.         a = y * @width_txt
  14.         b = 32 * row_index
  15.         t_size = self.contents.text_size(@commands[index]).width
  16.         a_off = (@width_txt - t_size) / 2 + a - 24
  17.         rect = Rect.new( a, b, @width_txt, 32)
  18.         self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  19.         case @type
  20.         when 2 # 空白正方形框
  21.           bitmap = RPG::Cache.picture("Rect_Unselected.png")
  22.           self.contents.blt(a,b+4,bitmap,Rect.new(0,0,20,24),255)
  23.         when 3 # 空白圆形
  24.           bitmap = RPG::Cache.picture("Ball_Unselected.png")
  25.           self.contents.blt(a_off,b+4,bitmap,Rect.new(0,0,20,24),255)
  26.         when 4 # 空白正方形框及装备框
  27.           bitmap = [RPG::Cache.picture("Rect_Unselected.png"),
  28.                     RPG::Cache.picture("Rect_Unselected_Equiped.png")]
  29.           self.contents.blt(a_off,b+4,bitmap[0],Rect.new(0,0,20,24),255)
  30.         when 6 # 空白圆形反色
  31.           bitmap = RPG::Cache.picture("GBall_Unselected.png")
  32.           self.contents.blt(a_off,b+4,bitmap,Rect.new(0,0,20,24),255)
  33.         end
  34.         self.contents.draw_text(rect, @commands[index],@align)
  35.         break
  36.       end
  37.     end
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● 更新光标矩形
  41.   #--------------------------------------------------------------------------
  42.   def update_cursor_rect
  43.     # 光标位置不满 0 的情况下
  44.     if @index < 0
  45.       self.cursor_rect.empty
  46.       return
  47.     end
  48.     # 获取当前的行
  49.     row = @index / @column_max
  50.     # 当前行被显示开头行前面的情况下
  51.     if row < self.top_row
  52.       # 从当前行向开头行滚动
  53.       self.top_row = row
  54.     end
  55.     # 当前行被显示末尾行之后的情况下
  56.     if row > self.top_row + (self.page_row_max - 1)
  57.       # 从当前行向末尾滚动
  58.       self.top_row = row - (self.page_row_max - 1)
  59.     end
  60.     # 计算光标的宽
  61.     cursor_width = @width_txt
  62.     # 计算光标坐标
  63.     x = @index % @column_max * cursor_width
  64.     y = @index / @column_max * 32 - self.oy
  65.     y += self.oy if @type != 0
  66.     t_size = self.contents.text_size(@commands[@index]).width
  67.     x_off = (@width_txt - t_size) / 2 + x - 24
  68.     case @type
  69.     when 0 # 光标矩形
  70.       self.cursor_rect.set(x, y, @width_txt, 32)
  71.     when 1 # 三角光标
  72.       bitmap = RPG::Cache.picture("Cursor.png")
  73.       self.contents.blt(x_off, y+4,bitmap,Rect.new(0, 0, 20, 24),255)
  74.     when 2 # 正方形选择框
  75.       bitmap = RPG::Cache.picture("Rect_Selected.png")
  76.       self.contents.blt(x, y+4,bitmap,Rect.new(0, 0, 20, 24),255)
  77.     when 3 # 圆形选择框
  78.       bitmap = RPG::Cache.picture("Ball_Selected.png")
  79.       self.contents.blt(x_off, y+4,bitmap,Rect.new(0, 0, 20, 24),255)
  80.     when 4 # 空白正方形框及装备框
  81.       bitmap = [RPG::Cache.picture("Rect_Selected.png"),
  82.                 RPG::Cache.picture("Rect_Selected_Equiped.png")]
  83.       self.contents.blt(x,y+4,bitmap[0],Rect.new(0,0,20,24),255)
  84.     when 5 # 反色显示
  85.       @new_command.set_size(@width_txt,32)
  86.       @new_command.set_up(16+x+self.x,16+y+self.y,@commands[@index])
  87.       @new_command.update
  88.     when 6 # 圆形选择框反色
  89.       bitmap = RPG::Cache.picture("GBall_Selected.png")
  90.       self.contents.blt(x_off, y+4,bitmap,Rect.new(0, 0, 20, 24),255)
  91.     when 7 # 手指选择
  92.       bitmap = RPG::Cache.picture("Hand.png")
  93.       self.contents.blt(x, y+3,bitmap,Rect.new(0, 0, 28, 26),255)
  94.     end
  95.   end
复制代码


这是我改的Window_Selectable里的两个方法,实现了用图片替换原本菜单中的方框选择框。
大致思路就是draw_item描绘未选中时的图形,update_cursor_rect描绘选中后的图形
类似的,你只要把draw_item改成显示未选择的图片,update_cursor_rect里显示选中的图片
如果你怕影响其他菜单,那就单独在你需要改变的那个菜单类里重载这两个方法
我这个图片尺寸一样的所以可以直接覆盖掉。如果无法覆盖掉的话那就draw_item的时候跳过光标位置的选项

效果如下图
屏幕截图 2023-08-09 082954.png

点评

自己写肯定是可行的,不过脑子转不过来,哈哈有时显示了 让其消失才是麻烦 更新 战败死亡游戏结束 还出现这就挺无语 这个方法我懂还是表示感谢  发表于 2025-2-19 22:38
我早自己試過写了十几次不过都以失败告终 出现各种毛病 不过还是表示感谢  发表于 2023-10-21 15:10
可以自己写一个,设置好选中和未选中的图片,在draw_item里循环到index的时候就显示选中的图片,否则显示未选中的,update就是根据按键改变index或其他  发表于 2023-9-19 08:15
你说的我大致理解光标替换成黑底 不过我那个更加类似标题菜单图片替换 我想有没有更简单易懂的方法  发表于 2023-9-17 10:59
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部