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

Project1

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

[有事请教] 战斗图标脚本添加光标矩形

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1368
在线时间
176 小时
注册时间
2019-10-4
帖子
247
跳转到指定楼层
1
发表于 2024-8-21 23:30:44 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

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

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

x
本帖最后由 契约师Vi 于 2024-8-21 23:32 编辑

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. #==============================================================================

战斗图标脚本,添加矩形光标Window_Selectable,光标在用了这个战斗图标脚本就没了,想在此脚本基础上,加入光标的选择框,但是没有入手点。希望大佬帮忙

Lv3.寻梦者

梦石
0
星屑
2801
在线时间
174 小时
注册时间
2020-8-9
帖子
116
3
发表于 2024-9-7 22:34:02 | 只看该作者
又研究了一下,发现这个脚本是通过①取消了窗口皮肤②把窗口设置的很小来把原选择窗口给隐藏了,如果你还需要光标的话可以学这个脚本一样,用额外的精灵来实现你要的效果

点评

有偏差大概率是因为这个脚本的图标是使用独立的sprite实现的,你可以尝试调整一下这些sprite的坐标  发表于 2024-9-9 18:42
super(x, y, 192, 192) @actor_command_window.opacity = 0 总的来说是对的 在设置的大小和透明度这里,虽然是可以显示了不过图标和光标有所偏差  发表于 2024-9-8 21:04
self.windowskin = RPG::Cache.windowskin("") 这行注释掉你就可以看到窗口了,因为没有皮肤,所以所有相关的东西估计都是用透明图替代,就看不到  发表于 2024-9-7 22:36

评分

参与人数 1+1 收起 理由
契约师Vi + 1 塞糖

查看全部评分

回复 支持 1 反对 0

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2801
在线时间
174 小时
注册时间
2020-8-9
帖子
116
2
发表于 2024-9-7 21:54:34 | 只看该作者

回帖奖励 +100

看了一下,我初步认为大概率是因为重新绘制的时候覆盖了,一个比较简单粗暴的方法是在现在的脚本绘制的方法里头加上光标框的绘制,并且再update里同步更新光标,这样你就又有光标框了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-20 10:57

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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