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

Project1

 找回密码
 注册会员
搜索
查看: 594|回复: 4

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1237
在线时间
163 小时
注册时间
2019-10-4
帖子
217
发表于 2023-8-9 00:05:24 | 显示全部楼层 |阅读模式
1000星屑
本帖最后由 契约师Vi 于 2023-8-9 00:06 编辑

RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4.  
  5. module Momo_IconCommand
  6.   # 图标名称设定
  7.   ATTACK_ICON_NAME = "攻击" # 攻撃
  8.   SKILL_ICON_NAME = "法术"   # 特技
  9.   GUARD_ICON_NAME = "防御"  # 防御
  10.   ITEM_ICON_NAME = "道具"     # 物品
  11.   # X坐标修正
  12.   X_PLUS = -160
  13.   # Y坐标修正
  14.   Y_PLUS = -240
  15.   # 选择时图标的动作
  16.   # 0:静止 1:放大
  17.   SELECT_TYPE = 0
  18.   # 闪烁时光芒的颜色
  19.   FLASH_COLOR = Color.new(255, 255, 255, 128)
  20.   # 闪烁时间
  21.   FLASH_DURATION = 10
  22.   # 闪烁间隔
  23.   FLASH_INTERVAL = 40
  24.   # 是否写出文字的名称
  25.   COM_NAME_DROW = false
  26.   # 文字名称是否移动
  27.   COM_NAME_MOVE = false
  28.   # 文字内容
  29.   ATTACK_NAME = "攻击"    # 攻击
  30.   SKILL_NAME = "特技"   # 特技
  31.   GUARD_NAME = "防御"     # 防御
  32.   ITEM_NAME = "物品"  # 物品
  33.   # 文字颜色
  34.   COM_NAME_COLOR = Color.new(255, 255, 255, 255)
  35.   # 文字坐标修正
  36.   COM_NAME_X_PLUS = 0
  37.   COM_NAME_Y_PLUS = 0
  38. end
  39.  
  40. class Window_CommandIcon < Window_Selectable
  41.   attr_accessor :last_index
  42.   #--------------------------------------------------------------------------
  43.   # ● オブジェクト初期化
  44.   #--------------------------------------------------------------------------
  45.   def initialize(x, y, commands)
  46.     super(x, y, 32, 32)
  47.     # ウィンドウスキンに空文字列を指定してウィンドウを描画しないようにする
  48.     self.windowskin = RPG::Cache.windowskin("")
  49.    @item_max = commands.size #项目数
  50.    @commands = commands #指令数
  51.    @column_max = 1
  52.     @index = 0
  53.     @last_index = nil
  54.     @name_sprite = nil
  55.     @sprite = []
  56.     refresh
  57.   end
  58.   def dispose
  59.     super
  60.     for sprite in @sprite
  61.       sprite.dispose unless sprite.nil?
  62.     end
  63.     @name_sprite.dispose unless @name_sprite.nil?
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● リフレッシュ
  67.   #--------------------------------------------------------------------------
  68.   def refresh
  69.     @name_sprite.dispose unless @name_sprite.nil?
  70.     for sprite in @sprite
  71.       sprite.dispose unless sprite.nil?
  72.     end
  73.     @name_sprite = nil
  74.     draw_com_name if Momo_IconCommand::COM_NAME_DROW
  75.     @sprite = []
  76.     for i in 0...@item_max
  77.       draw_item(i)
  78.     end
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # ● 項目の描画
  82.   #--------------------------------------------------------------------------
  83.   def draw_item(index)
  84.     @sprite[index] = Sprite_Icon.new(nil, @commands[index])
  85.     @sprite[index].z = self.z + 1
  86.   end
  87.   def draw_com_name
  88.     @name_sprite = Sprite_Comm_Name.new(nil, get_com_name)
  89.  
  90.   end
  91.  
  92.   # 更新
  93.   def update
  94.     super
  95.     icon_update
  96.     com_name_update if Momo_IconCommand::COM_NAME_DROW
  97.     if move_index?
  98.       @last_index = self.index
  99.     end
  100.   end
  101.   # アイコンの更新
  102.   def icon_update
  103.     for i in 0...@sprite.size
  104.       @sprite[i].active = (self.index == i)
  105.       @sprite[i].x = self.x
  106.       @sprite[i].y = self.y + i*26
  107.       @sprite[i].z = (self.index == i) ? self.z + 2 : self.z + 1
  108.       @sprite[i].visible = self.visible
  109.       @sprite[i].update
  110.     end
  111.   end
  112.   # コマンドネームの更新
  113.   def com_name_update
  114.     if move_index?
  115.       @name_sprite.name = get_com_name
  116.     end
  117.     @name_sprite.x = self.x - 12 + Momo_IconCommand::COM_NAME_X_PLUS
  118.     @name_sprite.y = self.y - 40 + Momo_IconCommand::COM_NAME_Y_PLUS
  119.     @name_sprite.z = self.z + 1
  120.     @name_sprite.active = self.active
  121.     @name_sprite.visible = self.visible
  122.     @name_sprite.update
  123.   end
  124.   def get_com_name
  125.     make_name_set if @name_set.nil?
  126.     name = @name_set[self.index]
  127.     name = "" if name.nil?
  128.     return name
  129.   end
  130.   def make_name_set
  131.     @name_set = []
  132.     @name_set[0] = Momo_IconCommand::ATTACK_NAME
  133.     @name_set[1] = Momo_IconCommand::SKILL_NAME
  134.     @name_set[2] = Momo_IconCommand::GUARD_NAME
  135.     @name_set[3] = Momo_IconCommand::ITEM_NAME
  136.   end
  137.   def move_index?
  138.     return self.index != @last_index
  139.   end
  140.   def need_reset
  141.     @name_sprite.need_reset = true if Momo_IconCommand::COM_NAME_DROW
  142.   end
  143. end
  144.  
  145. # アイコン用スプライト
  146. class Sprite_Icon < Sprite
  147.   attr_accessor :active
  148.   attr_accessor :icon_name
  149.   #--------------------------------------------------------------------------
  150.   # ● オブジェクト初期化
  151.   #--------------------------------------------------------------------------
  152.   def initialize(viewport, icon_name)
  153.     super(viewport)
  154.     @icon_name = icon_name
  155.     @last_icon = @icon_name
  156.     @count = 0
  157.     self.bitmap = RPG::Cache.icon(@icon_name)
  158.     self.ox = self.bitmap.width / 2
  159.     self.oy = self.bitmap.height / 2
  160.     @active = false
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 解放
  164.   #--------------------------------------------------------------------------
  165.   def dispose
  166.     if self.bitmap != nil
  167.       self.bitmap.dispose
  168.     end
  169.     super
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ● フレーム更新
  173.   #--------------------------------------------------------------------------
  174.   def update
  175.     super
  176.     if @icon_name != @last_icon
  177.       @last_icon = @icon_name
  178.       self.bitmap = RPG::Cache.icon(@icon_name)
  179.     end
  180.     if @active
  181.       @count += 1
  182.       case Momo_IconCommand::SELECT_TYPE
  183.       when 0
  184.         icon_flash
  185.       when 1
  186.         icon_zoom
  187.       end
  188.       @count = 0 if @count == 20
  189.     else
  190.       icon_reset
  191.     end
  192.   end
  193.   def icon_flash
  194.     if @count % Momo_IconCommand::FLASH_INTERVAL == 0 or @count == 1
  195.       self.flash(Momo_IconCommand::FLASH_COLOR, Momo_IconCommand::FLASH_DURATION)
  196.     end
  197.   end
  198.   def icon_zoom
  199.     case @count
  200.     when 1..10
  201.       zoom = 1.0 + @count / 10.0
  202.     when 11..20
  203.       zoom = 2.0 - (@count - 10) / 10.0
  204.     end
  205.     self.zoom_x = zoom
  206.     self.zoom_y = zoom
  207.   end
  208.   def icon_reset
  209.     @count = 0
  210.     self.zoom_x = 1.0
  211.     self.zoom_y = 1.0
  212.   end
  213. end
  214.  
  215. # コマンドネーム用スプライト
  216. class Sprite_Comm_Name < Sprite
  217.   attr_accessor :active
  218.   attr_accessor :name
  219.   attr_accessor :need_reset
  220.   #--------------------------------------------------------------------------
  221.   # ● オブジェクト初期化
  222.   #--------------------------------------------------------------------------
  223.   def initialize(viewport, name)
  224.     super(viewport)
  225.     @name = name
  226.     @last_name = nil
  227.     @count = 0
  228.     @x_plus = 0
  229.     @opa_plus = 0
  230.     @need_reset = false
  231.     @active = false
  232.     self.bitmap = Bitmap.new(160, 32)
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # ● 解放
  236.   #--------------------------------------------------------------------------
  237.   def dispose
  238.     if self.bitmap != nil
  239.       self.bitmap.dispose
  240.     end
  241.     super
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● フレーム更新
  245.   #--------------------------------------------------------------------------
  246.   def update
  247.     super
  248.     if @active
  249.       if need_reset?
  250.         @need_reset = false
  251.         @last_name = @name
  252.         text_reset
  253.       end
  254.       move_text if Momo_IconCommand::COM_NAME_MOVE
  255.     end
  256.   end
  257.   def move_text
  258.     @count += 1
  259.     @x_plus = [@count * 8, 80].min
  260.     self.x = self.x - 80 + @x_plus
  261.     self.opacity = @count * 25
  262.   end
  263.   def text_reset
  264.     @count = 0
  265.     @x_plus = 0
  266.     self.bitmap.clear
  267.     self.bitmap.font.color = Momo_IconCommand::COM_NAME_COLOR
  268.     self.bitmap.draw_text(0, 0, 160, 32, @name)
  269.   end
  270.   def need_reset?
  271.     return (@name != @last_name or @need_reset)
  272.   end
  273. end
  274.  
  275. class Scene_Battle
  276.   #--------------------------------------------------------------------------
  277.   # ● プレバトルフェーズ開始
  278.   #--------------------------------------------------------------------------
  279.   alias scene_battle_icon_command_start_phase1 start_phase1
  280.   def start_phase1
  281.     com1 = Momo_IconCommand::ATTACK_ICON_NAME
  282.     com2 = Momo_IconCommand::SKILL_ICON_NAME
  283.     com3 = Momo_IconCommand::GUARD_ICON_NAME
  284.     com4 = Momo_IconCommand::ITEM_ICON_NAME
  285.     @actor_command_window = Window_CommandIcon.new(0, 0, [com1, com2, com3, com4])
  286.     @actor_command_window.y = 160
  287.     @actor_command_window.back_opacity = 160
  288.     @actor_command_window.active = false
  289.     @actor_command_window.visible = false
  290.     @actor_command_window.update
  291.     scene_battle_icon_command_start_phase1
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ● アクターコマンドウィンドウのセットアップ
  295.   #--------------------------------------------------------------------------
  296.   alias scene_battle_icon_command_phase3_setup_command_window phase3_setup_command_window
  297.   def phase3_setup_command_window
  298.     scene_battle_icon_command_phase3_setup_command_window
  299.     # アクターコマンドウィンドウの位置を設定
  300.     @actor_command_window.x = command_window_actor_x(@actor_index)
  301.     @actor_command_window.y = command_window_actor_y(@actor_index)
  302.     @actor_command_window.need_reset
  303.   end
  304.   def command_window_actor_x(index)
  305.     $game_party.actors[index].screen_x + Momo_IconCommand::X_PLUS
  306.   end
  307.   def command_window_actor_y(index)
  308.     $game_party.actors[index].screen_y + Momo_IconCommand::Y_PLUS
  309.   end
  310. end
  311.  
  312. #==============================================================================
  313. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  314. #==============================================================================

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

Lv3.寻梦者

梦石
0
星屑
4481
在线时间
380 小时
注册时间
2012-11-8
帖子
272
发表于 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

点评

我早自己試過写了十几次不过都以失败告终 出现各种毛病 不过还是表示感谢  发表于 2023-10-21 15:10
可以自己写一个,设置好选中和未选中的图片,在draw_item里循环到index的时候就显示选中的图片,否则显示未选中的,update就是根据按键改变index或其他  发表于 2023-9-19 08:15
你说的我大致理解光标替换成黑底 不过我那个更加类似标题菜单图片替换 我想有没有更简单易懂的方法  发表于 2023-9-17 10:59
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 18:39

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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