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

Project1

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

[已经解决] 战斗中查看状态

[复制链接]

Lv4.逐梦者

梦石
0
星屑
6483
在线时间
119 小时
注册时间
2020-1-8
帖子
234
1
发表于 2021-6-20 21:22:48 | 显示全部楼层
看了下楼主发的工程的效果,大概写了下。

说明:Scene_Battle的phase3阶段皆可以查看状态(敌我)
         G键开启,G键结束
         不包含图标状态,状态介绍文字直接使用的楼主工程中的

RUBY 代码复制
  1. class Window_State < Window_Selectable
  2.   def initialize(battler)
  3.     super(240, 240, 200, 160)
  4.     @column_max = 1
  5.     self.z = 1000
  6.     @help_window_active = false
  7.     @name = Window_Base.new(self.x, self.y - 64, self.width, 64)
  8.     @name.z = 1000
  9.     @name.contents = Bitmap.new(@name.width - 32, @name.height - 32)
  10.     self.refresh(battler)
  11.     @last_state_id = 0
  12.   end
  13.  
  14.   def refresh(battler)
  15.     @battler = battler
  16.     if self.contents != nil
  17.       self.contents.dispose
  18.       self.contents = nil
  19.     end
  20.     @name.contents.clear
  21.     return if @battler == nil
  22.     @name.contents.font.color.set(0, 250, 0)
  23.     @name.contents.draw_text(0, 0, @name.width - 32, 32, @battler.name, 1)
  24.     @item_max = @battler.states.size
  25.     w = self.width - 32
  26.     self.contents = Bitmap.new(w, self.row_max * 32 + 32)
  27.     self.oy = 0
  28.     if @item_max == 0
  29.       self.contents.draw_text(0, 0, w, 32, "没有状态", 1)
  30.       @index = -1
  31.       @help_window.set_text("") if @help_window != nil
  32.       @help_window_active = false
  33.       return
  34.     end
  35.     @battler.states.each_with_index do |state_id, i|
  36.       state = $data_states[state_id]
  37.       if state != nil
  38.         turn = @battler.states_turn[state_id]
  39.         turn_text = (turn == -1 ? "∞" : turn.to_s) + "回合"
  40.         self.contents.draw_text(0, 32 * i, w, 32, state.name, 0)
  41.         self.contents.draw_text(0, 32 * i, w, 32, turn_text, 2)
  42.       end
  43.     end
  44.     @index = 0
  45.     @help_window_active = true
  46.   end
  47.  
  48.   def dispose
  49.     super
  50.     @name.dispose
  51.   end
  52.  
  53.   def set_help
  54.     state_id = @battler.states[@index]  
  55.     state = $data_states[state_id]
  56.     info = $状态介绍[state_id] == nil ? "" :
  57.       ("【#{state.name}】:" + $状态介绍[state_id])
  58.     @help_window.set_text(state == nil ? "" : info)
  59.   end
  60.  
  61.   def update_help
  62.     return unless @help_window_active == true
  63.     if @last_state_id != @battler.states[@index]
  64.       self.set_help
  65.       @last_state_id = @battler.states[@index]
  66.     end
  67.   end
  68.  
  69.   def update
  70.     super
  71.     @name.visible = self.visible
  72.   end
  73. end
  74.  
  75. class Window_StateHelp < Window_Base
  76.   def initialize
  77.     super(0, 0, 640, 64)
  78.     self.z = 1000
  79.   end
  80.  
  81.   def set_text(text)
  82.     temp = Bitmap.new(1, 1)
  83.     rect = temp.text_size(text)
  84.     max = (rect.width * 1.0 / (self.width - 32)).ceil
  85.     max = 1 if max < 1
  86.     temp.dispose
  87.     temp = nil
  88.     text2 = text.clone
  89.     if self.contents != nil
  90.       self.contents.dispose
  91.       self.contents = nil
  92.     end
  93.     self.height = max * 32 + 32
  94.     self.contents = Bitmap.new(self.width - 32, max * 32)
  95.     self.contents.font.color = normal_color
  96.     if max == 1
  97.       align = rect.width < (self.width - 32) / 2 ? 1 : 0
  98.       self.contents.draw_text(0, 0, self.width - 32, 32, text2, align)
  99.       return
  100.     end
  101.     sx, sy = 0, 0
  102.     while ((c = text2.slice!(/./m)) != nil)
  103.       if c == "\n"
  104.         sy += 1
  105.         sx = 0
  106.         next
  107.       end
  108.       rect = self.contents.text_size(c)
  109.       if sx + rect.width > self.width - 32
  110.         sx = 0
  111.         sy += 1
  112.       end
  113.       self.contents.draw_text(sx, sy * 32, rect.width, 32, c, 0)
  114.       sx += rect.width        
  115.     end
  116.     self.visible = true
  117.   end
  118. end
  119.  
  120. class Key
  121.   GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I')
  122.   G = 71
  123.   def self.trigger?(nVK)
  124.     value = GetAsyncKeyState.call(nVK)
  125.     return (value & 0x8000 != 0) && (value & 1 == 1)
  126.   end
  127. end
  128.  
  129. class Game_Battler
  130.   def states_turn
  131.     return @states_turn
  132.   end
  133. end
  134.  
  135. class Scene_Battle
  136. =begin
  137.   def main
  138.     …………
  139.     # 准备过渡
  140.     Graphics.freeze
  141.     # 释放窗口
  142.     self.end_state    #自行添加
  143.     …………
  144.   end
  145. =end
  146.   def update_state
  147.     @state_window.update
  148.     if Input.trigger?(Input::R)
  149.       @state_index = (@state_index + 1) % @all_battlers.size
  150.       @state_window.refresh(@all_battlers[@state_index])
  151.       return
  152.     end
  153.     if Input.trigger?(Input::L)
  154.       @state_index = (@state_index - 1) % @all_battlers.size
  155.       @state_window.refresh(@all_battlers[@state_index])
  156.       return
  157.     end
  158.   end
  159.  
  160.   def start_state
  161.     @state_window = Window_State.new(@active_battler)
  162.     @state_help_window = Window_StateHelp.new
  163.     @state_window.help_window = @state_help_window
  164.     # 根据需要,自行修改查看的目标范围。比如battler.exist?
  165.     @all_battlers = $game_party.actors + $game_troop.enemies
  166.     @state_index = @all_battlers.index(@active_battler) || 0
  167.   end
  168.  
  169.   def end_state
  170.     if @state_window != nil
  171.       @state_window.dispose
  172.       @state_window = nil
  173.     end
  174.     if @state_help_window != nil
  175.       @state_help_window.dispose
  176.       @state_help_window = nil
  177.     end
  178.     @all_battlers = nil
  179.     @state_index = nil
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ● 刷新画面 (角色命令回合)
  183.   #--------------------------------------------------------------------------
  184.   alias ori_update_phase3 update_phase3
  185.   def update_phase3
  186.     if Key.trigger?(Key::G)
  187.       if @state_window == nil
  188.         self.start_state
  189.         bool = false
  190.       else
  191.         self.end_state
  192.         bool = true        
  193.       end
  194.       if @enemy_arrow != nil
  195.         @enemy_arrow.visible = bool
  196.       elsif @actor_arrow != nil
  197.         @actor_arrow.visible = bool
  198.       elsif @skill_window != nil
  199.         @skill_window.visible = bool
  200.       elsif @item_window != nil
  201.         @item_window.visible = bool
  202.       elsif @actor_command_window.active
  203.         @actor_command_window.visible = bool
  204.       end
  205.     end
  206.     if @state_window != nil
  207.       self.update_state
  208.       return
  209.     end
  210.  
  211.     ori_update_phase3
  212.   end
  213. end


回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-6-11 06:18

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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