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

Project1

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

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
4531
在线时间
382 小时
注册时间
2012-11-8
帖子
275
1
发表于 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-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-5-15 09:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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