Advertisement
AngryPacman

[VXA] YanPac Battle HUD

Feb 23rd, 2012
4,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.50 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # YanPac Battle HUD (1.0)
  4. # 22/06/2014
  5. # By Yanfly and Pacman (originally by Yanfly, extracted and worked on by Pacman)
  6. # This script adds the Actor HUD from Yanfly Engine Ace's Battle System to the
  7. # default battle system. It draws the actor's name, face, HP, MP, TP, action
  8. # and states. The script automatically detects whether to draw the actor's TP
  9. # or MP depending on which skills they have. You can change some simple
  10. # aesthetic options below.
  11. # You can use simple notetags to make sure the actor's gauges are drawn:
  12. # \def_draw_hp  - Definitely draw HP
  13. # \def_draw_mp  - Definitely draw MP
  14. # \def_draw_tp  - Definitely draw TP
  15. # \def_not_hp   - Definitely don't draw HP
  16. # \def_not_mp   - Definitely don't draw MP
  17. # \def_not_tp   - Definitely don't draw TP
  18. # The main point of this standalone script is to optimize compatibility with
  19. # other scripts and increase efficiency (currently pending :P).
  20. #
  21. # Version list:
  22. # 1.0: Compatible with Enemy HUD
  23. #   http://pacmanvx.wordpress.com/2012/02/12/enemy-hud/
  24. # 0.3: Compatible with Change Gauge Display
  25. #   http://pacmanvx.wordpress.com/2012/02/11/change-gauge-display/
  26. # 0.2: Compatible with Neo Gauge Ultimate
  27. #   http://pacmanvx.wordpress.com/2012/02/05/neo-gauge-ultimate/
  28. # 0.l: Script extracted / created.
  29. #
  30. #===============================================================================
  31.  
  32. module PAC_HUD
  33. #===============================================================================
  34. # BEGIN CONFIGURATION
  35. #===============================================================================
  36.   BATTLESTATUS_NAME_FONT_SIZE = 20    # Font size used for name.
  37.   BATTLESTATUS_TEXT_FONT_SIZE = 16    # Font size used for HP, MP, TP.
  38.   BATTLESTATUS_NO_ACTION_ICON = 185   # No action icon.
  39.   BATTLESTATUS_HPGAUGE_Y_PLUS = 11    # Y Location buffer used for HP gauge.
  40.   BATTLESTATUS_CENTER_FACES   = false # Center faces for the Battle Status.
  41.   MP_OVER_TP = true                   # If TP is not drawn, draw MP? (still
  42.                                       # applies notetag effects)
  43. #===============================================================================
  44. # END CONFIGURATION
  45. #===============================================================================
  46. end
  47.  
  48. $imported ||= {}
  49.  
  50. #==============================================================================
  51. # ■ Numeric
  52. #------------------------------------------------------------------------------
  53. #  Numeric は数値の抽象クラスです。Ruby では異なる数値クラス間で演算を行うことができます。
  54. # 演算や比較を行うメソッド (+, -, *, /, <=>) などはサブクラスで定義されます。また、効率のため Numeric
  55. # のメソッドと同じメソッドがサブクラスで再定義されている場合があります。 私のひどい日本語を言い訳。
  56. #==============================================================================
  57.  
  58. class Numeric
  59.   #--------------------------------------------------------------------------
  60.   # * Group Digits
  61.   #--------------------------------------------------------------------------
  62.   unless defined?(group); def group; return self.to_s; end; end
  63. end
  64.  
  65. #==============================================================================
  66. # ■ Game_Battler
  67. #------------------------------------------------------------------------------
  68. #  スプライトや行動に関するメソッドを追加したバトラーのクラスです。このクラス
  69. # は Game_Actor クラスと Game_Enemy クラスのスーパークラスとして使用されます。
  70. #==============================================================================
  71.  
  72. class Game_Battler < Game_BattlerBase
  73.   #--------------------------------------------------------------------------
  74.   # * Draw Battler's HP?
  75.   #--------------------------------------------------------------------------
  76.   def draw_hp?; return true; end
  77.   #--------------------------------------------------------------------------
  78.   # * Draw Battler's MP?
  79.   #--------------------------------------------------------------------------
  80.   def draw_mp?; return true; end
  81.   #--------------------------------------------------------------------------
  82.   # * Draw Battler's TP?
  83.   #--------------------------------------------------------------------------
  84.   def draw_tp?
  85.     return $imported[:pac_change_gauge] ? $game_system.opt_display_tp :
  86.      $data_system.opt_display_tp
  87.   end
  88. end
  89.  
  90. #==============================================================================
  91. # ■ Game_Actor
  92. #------------------------------------------------------------------------------
  93. #  アクターを扱うクラスです。このクラスは Game_Actors クラス($game_actors)
  94. # の内部で使用され、Game_Party クラス($game_party)からも参照されます。
  95. #==============================================================================
  96.  
  97. class Game_Actor < Game_Battler
  98.   #--------------------------------------------------------------------------
  99.   # * Draw Actor's HP?
  100.   #--------------------------------------------------------------------------
  101.   def draw_hp?
  102.     return true if !self.actor.note[/\\def[_ ]?draw[_ ]?hp/i].nil?
  103.     return false if !self.actor.note[/\\def[_ ]?not[_ ]?hp/i].nil?
  104.     if $imported[:pac_gauge_change]
  105.       return false if self.actor.no_hp_display?
  106.     end
  107.     return true
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # * Draw Actor's MP?
  111.   #--------------------------------------------------------------------------
  112.   def draw_mp?
  113.     return true if !self.actor.note[/\\def[_ ]?draw[_ ]?mp/i].nil?
  114.     return false if !self.actor.note[/\\def[_ ]?not[_ ]?mp/i].nil?
  115.     if $imported[:pac_gauge_change]
  116.       return false if self.actor.no_mp_display?
  117.     end
  118.     return true if !draw_tp? && PAC_HUD::MP_OVER_TP
  119.     for skill in skills
  120.       next unless added_skill_types.include?(skill.stype_id)
  121.       return true if skill.mp_cost > 0
  122.     end
  123.     return false
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # * Draw Actor's TP?
  127.   #--------------------------------------------------------------------------
  128.   def draw_tp?
  129.     return true if !self.actor.note[/\\def[_ ]?draw[_ ]?tp/i].nil?
  130.     return false if !self.actor.note[/\\def[_ ]?not[_ ]?tp/i].nil?
  131.     if $imported[:pac_gauge_change]
  132.       return false if self.actor.no_tp_display?
  133.     end
  134.     return false unless $imported[:pac_change_gauge] ?
  135.      $game_system.opt_display_tp : $data_system.opt_display_tp
  136.     for skill in skills
  137.       next unless added_skill_types.include?(skill.stype_id)
  138.       return true if skill.tp_cost > 0
  139.     end
  140.     return false
  141.   end
  142. end
  143.  
  144. #==============================================================================
  145. # ■ Window_BattleStatus
  146. #------------------------------------------------------------------------------
  147. #  バトル画面で、パーティメンバーのステータスを表示するウィンドウです。
  148. #==============================================================================
  149.  
  150. class Window_YanPac_BattleStatus < Window_BattleStatus
  151.   #--------------------------------------------------------------------------
  152.   # * Object Initialization
  153.   #--------------------------------------------------------------------------
  154.   def initialize
  155.     super
  156.     self.openness = 0
  157.     @party = $game_party.battle_members.clone
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # * Column Max
  161.   #--------------------------------------------------------------------------
  162.   def col_max; return $game_party.max_battle_members; end
  163.   #--------------------------------------------------------------------------
  164.   # * Get Battle Members
  165.   #--------------------------------------------------------------------------
  166.   def battle_members; return $game_party.battle_members; end
  167.   #--------------------------------------------------------------------------
  168.   # * Get Current Actor
  169.   #--------------------------------------------------------------------------
  170.   def actor; return battle_members[@index]; end
  171.   #--------------------------------------------------------------------------
  172.   # * Frame Update
  173.   #--------------------------------------------------------------------------
  174.   def update
  175.     super
  176.     return if @party == $game_party.battle_members
  177.     @party = $game_party.battle_members.clone
  178.     refresh
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # * Draw Item
  182.   #     index : index of item to be drawn
  183.   #--------------------------------------------------------------------------
  184.   def draw_item(index)
  185.     return if index.nil?
  186.     clear_item(index)
  187.     actor = battle_members[index]
  188.     rect = item_rect(index)
  189.     return if actor.nil?
  190.     draw_actor_face(actor, rect.x+2, rect.y+2, actor.alive?)
  191.     draw_actor_name(actor, rect.x, rect.y, rect.width-8)
  192.     draw_actor_action(actor, rect.x, rect.y)
  193.     draw_actor_icons(actor, rect.x, line_height*1, rect.width)
  194.     gx = PAC_HUD::BATTLESTATUS_HPGAUGE_Y_PLUS
  195.     contents.font.size = PAC_HUD::BATTLESTATUS_TEXT_FONT_SIZE
  196.     if draw_hp?(actor)
  197.       draw_actor_hp(actor, rect.x+2, line_height*2+gx, rect.width-4)
  198.     end
  199.     if draw_tp?(actor) && draw_mp?(actor)
  200.       dw = rect.width/2-2
  201.       dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE
  202.       draw_actor_tp(actor, rect.x+2, line_height*3, dw)
  203.       dw = rect.width - rect.width/2 - 2
  204.       draw_actor_mp(actor, rect.x+rect.width/2, line_height*3, dw)
  205.     elsif draw_tp?(actor) && !draw_mp?(actor)
  206.       draw_actor_tp(actor, rect.x+2, line_height*3, rect.width-4)
  207.     elsif !draw_tp?(actor) && draw_mp?(actor)
  208.       draw_actor_mp(actor, rect.x+2, line_height*3, rect.width-4)
  209.     else
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Get Item Rect
  214.   #     index : index of item to get rect for
  215.   #--------------------------------------------------------------------------
  216.   def item_rect(index)
  217.     rect = Rect.new
  218.     rect.width = contents.width / $game_party.max_battle_members
  219.     rect.height = contents.height
  220.     rect.x = index * rect.width
  221.     if PAC_HUD::BATTLESTATUS_CENTER_FACES
  222.       rect.x += (contents.width - $game_party.members.size * rect.width) / 2
  223.     end
  224.     rect.y = 0
  225.     return rect
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Draw Face (specifically for this HUD)
  229.   #--------------------------------------------------------------------------
  230.   def draw_face(face_name, face_index, dx, dy, enabled = true)
  231.     bitmap = Cache.face(face_name)
  232.     fx = [(96 - item_rect(0).width + 1) / 2, 0].max
  233.     fy = face_index / 4 * 96 + 2
  234.     fw = [item_rect(0).width - 4, 92].min
  235.     rect = Rect.new(fx, fy, fw, 92)
  236.     rect = Rect.new(face_index % 4 * 96 + fx, fy, fw, 92)
  237.     contents.blt(dx, dy, bitmap, rect, enabled ? 255 : translucent_alpha)
  238.     bitmap.dispose
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * Draw Actor Name
  242.   #--------------------------------------------------------------------------
  243.   def draw_actor_name(actor, dx, dy, dw = 112)
  244.     reset_font_settings
  245.     contents.font.size = PAC_HUD::BATTLESTATUS_NAME_FONT_SIZE
  246.     change_color(hp_color(actor))
  247.     draw_text(dx+24, dy, dw-24, line_height, actor.name)
  248.   end
  249.   #--------------------------------------------------------------------------
  250.   # * Draw Actor's Action Icon
  251.   #--------------------------------------------------------------------------
  252.   def draw_actor_action(actor, dx, dy)
  253.     draw_icon(action_icon(actor), dx, dy)
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Get Actor's Action Icon
  257.   #--------------------------------------------------------------------------
  258.   def action_icon(actor)
  259.     return PAC_HUD::BATTLESTATUS_NO_ACTION_ICON if actor.current_action.nil?
  260.     return PAC_HUD::BATTLESTATUS_NO_ACTION_ICON if actor.current_action.item.nil?
  261.     return actor.current_action.item.icon_index
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # * Draw Actor's TP?
  265.   #--------------------------------------------------------------------------
  266.   def draw_tp?(actor)
  267.     return actor.draw_tp?
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # * Draw Actor's MP?
  271.   #--------------------------------------------------------------------------
  272.   def draw_mp?(actor)
  273.     return actor.draw_mp?
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # * Draw Actor's HP?
  277.   #--------------------------------------------------------------------------
  278.   def draw_hp?(actor)
  279.     return actor.draw_hp?
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * Draw Current & Max Values
  283.   #--------------------------------------------------------------------------
  284.   def draw_current_and_max_values(dx, dy, dw, current, max, color1, color2)
  285.     change_color(color1)
  286.     draw_text(dx, dy, dw, line_height, current.group, 2)
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # * Draw Actor's HP Gauge
  290.   #--------------------------------------------------------------------------
  291.   def draw_actor_hp(actor, dx, dy, width = 124, h = 6, *args)
  292.     if defined?(draw_neo_gauge) # NGU Support
  293.       gwidth = width * actor.hp / actor.mhp
  294.       cg = neo_gauge_back_color
  295.       c1, c2, c3 = cg[0], cg[1], cg[2]
  296.       draw_neo_gauge(dx, dy + line_height - 8, width, h, c1, c2, c3)
  297.       (1..3).each { |i| eval("c#{i} = HP_GCOLOR_#{i}")}
  298.       draw_neo_gauge(dx, dy + line_height - 8, gwidth, h, c1, c2, c3, false,
  299.        false, width, 40)
  300.     else
  301.       draw_gauge(dx, dy, width, actor.hp_rate, hp_gauge_color1, hp_gauge_color2)
  302.     end
  303.     change_color(system_color)
  304.     cy = (Font.default_size - contents.font.size) / 2 + 1
  305.     draw_text(dx+2, dy+cy, 30, line_height, Vocab::hp_a)
  306.     draw_current_and_max_values(dx, dy+cy, width, actor.hp, actor.mhp,
  307.       hp_color(actor), normal_color)
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Draw Actor's MP Gauge
  311.   #--------------------------------------------------------------------------
  312.   def draw_actor_mp(actor, dx, dy, width = 124)
  313.     if defined?(draw_neo_gauge) # NGU Support
  314.       gwidth = width * actor.mp / [actor.mmp, 1].max
  315.       cg = neo_gauge_back_color
  316.       c1, c2, c3 = cg[0], cg[1], cg[2]
  317.       draw_neo_gauge(dx, dy + line_height - 8, width, 6, c1, c2, c3)
  318.       (1..3).each { |i| eval("c#{i} = MP_GCOLOR_#{i}")}
  319.       draw_neo_gauge(dx, dy + line_height - 8, gwidth, 6, c1, c2, c3, false,
  320.        false, width, 40)
  321.     else
  322.       draw_gauge(dx, dy, width, actor.mp_rate, mp_gauge_color1, mp_gauge_color2)
  323.     end
  324.     change_color(system_color)
  325.     cy = (Font.default_size - contents.font.size) / 2 + 1
  326.     draw_text(dx+2, dy+cy, 30, line_height, Vocab::mp_a)
  327.     draw_current_and_max_values(dx, dy+cy, width, actor.mp, actor.mmp,
  328.       mp_color(actor), normal_color)
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # * Draw Actor's TP Gauge
  332.   #--------------------------------------------------------------------------
  333.   def draw_actor_tp(actor, dx, dy, width = 124)
  334.     if defined?(draw_neo_gauge) # NGU Support
  335.       gwidth = width * actor.tp / 100
  336.       cg = neo_gauge_back_color
  337.       c1, c2, c3 = cg[0], cg[1], cg[2]
  338.       draw_neo_gauge(dx, dy + line_height - 8, width, 6, c1, c2, c3)
  339.       (1..3).each { |i| eval("c#{i} = TP_GCOLOR_#{i}")}
  340.       draw_neo_gauge(dx, dy + line_height - 8, gwidth, 6, c1, c2, c3, false,
  341.        false, width, 40)
  342.     else
  343.       draw_gauge(dx, dy, width, actor.tp_rate, tp_gauge_color1, tp_gauge_color2)
  344.     end
  345.     change_color(system_color)
  346.     cy = (Font.default_size - contents.font.size) / 2 + 1
  347.     draw_text(dx+2, dy+cy, 30, line_height, Vocab::tp_a)
  348.     change_color(tp_color(actor))
  349.     draw_text(dx + width - 42, dy+cy, 42, line_height, actor.tp.to_i, 2)
  350.   end
  351. end
  352.  
  353. class Scene_Battle < Scene_Base
  354.   def create_status_window
  355.     @status_window = Window_YanPac_BattleStatus.new
  356.     @status_window.x = 128
  357.   end
  358. end
  359.  
  360. ($pac ||= {})[:yan_battle_hud] = [1.0]
  361.  
  362. #===============================================================================
  363. #
  364. # END OF SCRIPT
  365. #
  366. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement