| 赞 | 68 |
| VIP | |
| 好人卡 | |
| 积分 | 65 |
| 经验 | |
| 最后登录 | 2023-7-2 |
| 在线时间 | 119 小时 |
- 梦石
- 0
- 星屑
- 6483
- 在线时间
- 119 小时
- 注册时间
- 2020-1-8
- 回帖
- 205
|
发表于 2021-6-20 21:22:48
|
显示全部楼层
看了下楼主发的工程的效果,大概写了下。
说明:Scene_Battle的phase3阶段皆可以查看状态(敌我)
G键开启,G键结束
不包含图标状态,状态介绍文字直接使用的楼主工程中的
- class Window_State < Window_Selectable
- def initialize(battler)
- super(240, 240, 200, 160)
- @column_max = 1
- self.z = 1000
- @help_window_active = false
- @name = Window_Base.new(self.x, self.y - 64, self.width, 64)
- @name.z = 1000
- @name.contents = Bitmap.new(@name.width - 32, @name.height - 32)
- self.refresh(battler)
- @last_state_id = 0
- end
-
- def refresh(battler)
- @battler = battler
- if self.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- @name.contents.clear
- return if @battler == nil
- @name.contents.font.color.set(0, 250, 0)
- @name.contents.draw_text(0, 0, @name.width - 32, 32, @battler.name, 1)
- @item_max = @battler.states.size
- w = self.width - 32
- self.contents = Bitmap.new(w, self.row_max * 32 + 32)
- self.oy = 0
- if @item_max == 0
- self.contents.draw_text(0, 0, w, 32, "没有状态", 1)
- @index = -1
- @help_window.set_text("") if @help_window != nil
- @help_window_active = false
- return
- end
- @battler.states.each_with_index do |state_id, i|
- state = $data_states[state_id]
- if state != nil
- turn = @battler.states_turn[state_id]
- turn_text = (turn == -1 ? "∞" : turn.to_s) + "回合"
- self.contents.draw_text(0, 32 * i, w, 32, state.name, 0)
- self.contents.draw_text(0, 32 * i, w, 32, turn_text, 2)
- end
- end
- @index = 0
- @help_window_active = true
- end
-
- def dispose
- super
- @name.dispose
- end
-
- def set_help
- state_id = @battler.states[@index]
- state = $data_states[state_id]
- info = $状态介绍[state_id] == nil ? "" :
- ("【#{state.name}】:" + $状态介绍[state_id])
- @help_window.set_text(state == nil ? "" : info)
- end
-
- def update_help
- return unless @help_window_active == true
- if @last_state_id != @battler.states[@index]
- self.set_help
- @last_state_id = @battler.states[@index]
- end
- end
-
- def update
- super
- @name.visible = self.visible
- end
- end
- class Window_StateHelp < Window_Base
- def initialize
- super(0, 0, 640, 64)
- self.z = 1000
- end
-
- def set_text(text)
- temp = Bitmap.new(1, 1)
- rect = temp.text_size(text)
- max = (rect.width * 1.0 / (self.width - 32)).ceil
- max = 1 if max < 1
- temp.dispose
- temp = nil
- text2 = text.clone
- if self.contents != nil
- self.contents.dispose
- self.contents = nil
- end
- self.height = max * 32 + 32
- self.contents = Bitmap.new(self.width - 32, max * 32)
- self.contents.font.color = normal_color
- if max == 1
- align = rect.width < (self.width - 32) / 2 ? 1 : 0
- self.contents.draw_text(0, 0, self.width - 32, 32, text2, align)
- return
- end
- sx, sy = 0, 0
- while ((c = text2.slice!(/./m)) != nil)
- if c == "\n"
- sy += 1
- sx = 0
- next
- end
- rect = self.contents.text_size(c)
- if sx + rect.width > self.width - 32
- sx = 0
- sy += 1
- end
- self.contents.draw_text(sx, sy * 32, rect.width, 32, c, 0)
- sx += rect.width
- end
- self.visible = true
- end
- end
- class Key
- GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I')
- G = 71
- def self.trigger?(nVK)
- value = GetAsyncKeyState.call(nVK)
- return (value & 0x8000 != 0) && (value & 1 == 1)
- end
- end
- class Game_Battler
- def states_turn
- return @states_turn
- end
- end
-
- class Scene_Battle
- =begin
- def main
- …………
- # 准备过渡
- Graphics.freeze
- # 释放窗口
- self.end_state #自行添加
- …………
- end
- =end
- def update_state
- @state_window.update
- if Input.trigger?(Input::R)
- @state_index = (@state_index + 1) % @all_battlers.size
- @state_window.refresh(@all_battlers[@state_index])
- return
- end
- if Input.trigger?(Input::L)
- @state_index = (@state_index - 1) % @all_battlers.size
- @state_window.refresh(@all_battlers[@state_index])
- return
- end
- end
-
- def start_state
- @state_window = Window_State.new(@active_battler)
- @state_help_window = Window_StateHelp.new
- @state_window.help_window = @state_help_window
- # 根据需要,自行修改查看的目标范围。比如battler.exist?
- @all_battlers = $game_party.actors + $game_troop.enemies
- @state_index = @all_battlers.index(@active_battler) || 0
- end
-
- def end_state
- if @state_window != nil
- @state_window.dispose
- @state_window = nil
- end
- if @state_help_window != nil
- @state_help_window.dispose
- @state_help_window = nil
- end
- @all_battlers = nil
- @state_index = nil
- end
- #--------------------------------------------------------------------------
- # ● 刷新画面 (角色命令回合)
- #--------------------------------------------------------------------------
- alias ori_update_phase3 update_phase3
- def update_phase3
- if Key.trigger?(Key::G)
- if @state_window == nil
- self.start_state
- bool = false
- else
- self.end_state
- bool = true
- end
- if @enemy_arrow != nil
- @enemy_arrow.visible = bool
- elsif @actor_arrow != nil
- @actor_arrow.visible = bool
- elsif @skill_window != nil
- @skill_window.visible = bool
- elsif @item_window != nil
- @item_window.visible = bool
- elsif @actor_command_window.active
- @actor_command_window.visible = bool
- end
- end
- if @state_window != nil
- self.update_state
- return
- end
-
- ori_update_phase3
- end
- end
复制代码
|
|