| 赞 | 0 |
| VIP | 0 |
| 好人卡 | 1 |
| 积分 | 1 |
| 经验 | 4922 |
| 最后登录 | 2026-6-3 |
| 在线时间 | 77 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 141
- 在线时间
- 77 小时
- 注册时间
- 2012-4-5
- 帖子
- 33
|
- class Window_MapStatus < Window_Base
- # 假设 Hide_Window_Mapshow 是一个开关 ID,这里定义为常量以便管理
- HIDE_SWITCH_ID = 1 # 请根据实际项目修改此 ID
- def initialize
- # 假设窗口大小为 640x48 或类似,需根据实际布局调整
- super(0, 0, 640, 48)
- self.opacity = 0 # 如果需要透明背景
- @old_hp = nil
- @old_maxhp = nil
- @old_sp = nil
- @old_maxsp = nil
- @old_gold = nil
- refresh
- end
- def actor
- # 安全获取第一个演员,避免空数组错误
- return $game_party.actors if $game_party.actors.size > 0
- return nil
- end
- #--------------------------------------------------------------------------
- # ● 描绘HP槽
- #--------------------------------------------------------------------------
- def draw_actor_hp_bar(actor, x, y, width = 200)
- return unless actor
-
- # 背景框 (白色边框)
- self.contents.fill_rect(x, y, width + 4, 24, Color.new(255, 255, 255, 255))
- # 内部黑底
- self.contents.fill_rect(x + 2, y + 2, width, 20, Color.new(0, 0, 0, 255))
-
- # 计算 HP 比例,防止除以零
- rate = actor.maxhp == 0 ? 0 : 1.0 * actor.hp / actor.maxhp
- w1 = (rate * width).to_i
-
- # 红色血条
- self.contents.fill_rect(x + 2, y + 2, w1, 20, Color.new(200, 0, 0, 255))
- end
- #--------------------------------------------------------------------------
- # ● 描绘SP槽
- #--------------------------------------------------------------------------
- def draw_actor_sp_bar(actor, x, y, width = 200)
- return unless actor
- # 背景框 (白色边框) - 注意:这里假设 x 是起始位置,不再硬编码 +240
- self.contents.fill_rect(x, y, width + 4, 24, Color.new(255, 255, 255, 255))
- # 内部黑底
- self.contents.fill_rect(x + 2, y + 2, width, 20, Color.new(0, 0, 0, 255))
-
- # 计算 SP 比例
- rate = actor.maxsp == 0 ? 0 : 1.0 * actor.sp / actor.maxsp
- w2 = (rate * width).to_i
-
- # 橙色魔条
- self.contents.fill_rect(x + 2, y + 2, w2, 20, Color.new(248, 112, 0, 255))
- end
- #--------------------------------------------------------------------------
- # ● 描绘金钱数目
- #--------------------------------------------------------------------------
- def draw_actor_gold(x, y)
- gold_text = $game_party.gold.to_s
- gold_unit = $data_system.words.gold
-
- cx = contents.text_size(gold_unit).width
-
- # 绘制数字 (右对齐或左对齐需根据需求调整,这里保持原意:数字在左,单位在右)
- self.contents.font.color = normal_color
- # 原代码逻辑:数字在 538,单位在 600-cx。这里改为相对 x,y 的布局
- # 假设总宽度预留 100 像素给金钱显示
- money_area_width = 100
- self.contents.draw_text(x + money_area_width - cx - 64, y, 64 - cx - 2, 32, gold_text, 2)
-
- self.contents.font.color = system_color
- self.contents.draw_text(x + money_area_width - cx, y, cx, 32, gold_unit, 2)
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
-
- act = actor
- return unless act # 如果没有演员,则不绘制
- # 定义布局常量,方便调整
- hp_x = 40
- sp_x = 280 # 原代码是 36+240=276 左右,这里取整
- text_y = 0
- bar_y = 20
-
- # 绘制标签
- self.contents.font.color = Color.new(255, 255, 255, 255)
- self.contents.draw_text(hp_x - 40, text_y, 40, 32, "血量:")
- self.contents.draw_text(sp_x - 40, text_y, 40, 32, "魔法:")
-
- # 绘制数值文本
- self.contents.font.color = normal_color
- hp_text = "#{act.hp}/#{act.maxhp}"
- sp_text = "#{act.sp}/#{act.maxsp}"
-
- self.contents.draw_text(hp_x, text_y, 100, 32, hp_text, 0)
- self.contents.draw_text(sp_x, text_y, 100, 32, sp_text, 0)
-
- # 绘制进度条
- draw_actor_hp_bar(act, hp_x, bar_y, 200)
- draw_actor_sp_bar(act, sp_x, bar_y, 200)
-
- # 绘制金钱 (放在右侧)
- draw_actor_gold(self.width - 120, text_y)
- end
- #--------------------------------------------------------------------------
- # ● 更新
- #--------------------------------------------------------------------------
- def update
- super
-
- # 控制可见性
- self.visible = !$game_switches[HIDE_SWITCH_ID]
- return unless self.visible
-
- act = actor
- return unless act # 如果没有演员,无需更新状态检查
- rest_hp = act.hp
- max_hp = act.maxhp
- rest_sp = act.sp
- max_sp = act.maxsp
- gold = $game_party.gold
-
- # 检查是否有变化
- if @old_hp != rest_hp || @old_maxhp != max_hp ||
- @old_sp != rest_sp || @old_maxsp != max_sp ||
- @old_gold != gold
-
- @old_hp = rest_hp
- @old_maxhp = max_hp
- @old_sp = rest_sp
- @old_maxsp = max_sp
- @old_gold = gold
-
- refresh
- end
- end
- end
复制代码 |
|