Advertisement
modern_algebra

[VXA] Hover Alerts 1.0.3

Oct 16th, 2012
2,849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 35.51 KB | None | 0 0
  1. #==============================================================================
  2. #    Hover Alerts
  3. #    Version: 1.0.3
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: 4 November 2012
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #    
  9. #    This script lets you display a graphic which hovers above any given event,
  10. #   player or follower. The primary virtue of the script is that it allows for
  11. #   a feature like in Diablo, where characters that have something important to
  12. #   say have an exclamation point or something above their heads. However, it
  13. #   is not limited to that: this script can show any picture, icon, text, or
  14. #   combination of icon & text above any character.
  15. #
  16. #    A secondary (and completely optional) feature is that you can set it up so
  17. #   that whenever gold, items, weapons, or armours are received through their
  18. #   respective event commands, a hover alert will float above the player's head
  19. #   with the icon, name, and amount of the item received before fading out.
  20. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  21. #  Instructions:
  22. #    
  23. #    Paste this script into its own slot in the Script Editor, above Main but
  24. #   below Materials.
  25. #
  26. #    I decided to try something new with this script, so this script operates
  27. #   through event comment commands. When the comment is the very first comment
  28. #   on an event's page, then the hover graphic set through that comment will
  29. #   automatically be generated as soon as that event page's conditions are met.
  30. #   If it is not, then it will only be run when that event is active and the
  31. #   Interpreter reaches it.
  32. #
  33. #    The basic format for setting a hover graphic above the event in which the
  34. #   comment occurs is as follows, with any of the options between the curly
  35. #   brackets omitted if you are satisfied with the default setting:
  36. #
  37. #      \hover_alert { name = ""; icon = 0; icon_hue = 0; time = -1;
  38. #        fontname = "Default"; fontsize = 20; colour = 0; bold = false;
  39. #        italic = false; effect = :none; effect_param = nil; se = nil;
  40. #        proximity = 0 }
  41. #
  42. #   When setting any of the options, make sure it is concluded with either a
  43. #   semicolon or simply a new line. Each of the options is explained below, but
  44. #   I reiterate that you can exclude almost any of them if you are satisfied
  45. #   with the default value listed above:
  46. #
  47. #      name - This is a string, and if there is a graphic in Pictures with the
  48. #          filename set here, then that picture will be shown. Otherwise, the
  49. #          text of name itself will be drawn in the hover graphic.
  50. #      icon - The index of an icon to show to the left of any text in the hover
  51. #          graphic. It will do nothing if name corresponds to a picture, but it
  52. #          will show up if name is just text or if it is left empty.
  53. #      icon_hue - If icon is not 0, then this will be the hue of the icon drawn
  54. #      time - If this is set to something other than -1, then the hover graphic
  55. #          will expire once the number of frames specified pass. There are 60
  56. #          frames in a second, so if you set time to 180, for instance, the
  57. #          hover graphic will disappear after 3 seconds.
  58. #      fontname - If drawing text, this is the font used. It can be either a
  59. #          string or an array of strings.
  60. #      fontsize - If drawing text, this is the size of it.
  61. #      colour - If drawing text, this is the colour of it. It can be either an
  62. #          integer ID for the colour palette on the windowskin, or it can be
  63. #          an array of integers corresponding to [red, green, blue, alpha]
  64. #      bold - If drawing text, this determines whether it is bolded. It must be
  65. #          true or false.
  66. #      italic - If drawing text, this determines whether it is italicized. It
  67. #          must be true or false.
  68. #      effect - This is a symbol, and it can play some effects on the hover
  69. #          graphic. There are three repeated effects that you can set, and
  70. #          these are:
  71. #            :bounce - the hover graphic will move up and down slightly;
  72. #            :fade_bounce - the hover graphic will fade in and out; and
  73. #            :flash - the hover graphic will flash. You can set to which colour
  74. #              by setting effect_param to a palette ID or an [r,g,b,a] array
  75. #          there are also two closing effects which will dispose of the hover
  76. #          graphic once they are completed. These are:
  77. #            :fade - This will show up for about half a second before smoothly
  78. #              fading out of existence;
  79. #            :rise_and_fade - This will do the same as :fade, but it will also
  80. #              rise up a little bit before fading;
  81. #            :disintegrate - This shows up for about a half second before
  82. #              clearing itself by disposing of random pixels each frame for
  83. #              another half a second;
  84. #            :rise_and_disintegrate - This will do the same as :disintegrate,
  85. #              but it will also rise up a little bit before disintegrating.
  86. #          
  87. #      effect_param - This is only pertinent if you are using the flash effect,
  88. #          and you set the colour for that effect here with a a palette ID or
  89. #          an [r,g,b,a] array
  90. #      se - If you wish, you can set an SE to play when the hover alert first
  91. #          appears. It must be an array in the form ["filename", volume, pitch]
  92. #      proximity - Set this to any integer, and the hover graphic will only
  93. #          be visible if the player is within that many squares of the
  94. #          character over which the hover graphic is intended to appear.
  95. #
  96. #   For any given hover alert, you only need to have either name or icon set
  97. #   directly. If you don't set those, then it will simply remove any existing
  98. #   hover graphic. If you exclude any other value, then I reiterate that it
  99. #   will just be set to the default value identified in the sample itself.
  100. #   You can set the default values for fontname, fontsize, colour, bold, italic
  101. #   and effect in the editable region starting at line 158.
  102. #
  103. #    Now, the above code will only set a hover graphic on the event in which
  104. #   the comment appears. For auto-hover alerts in comments at the top of the
  105. #   page, you can only set it to that event, but for the interpreted comments
  106. #   that appear anywhere else you can set the hover graphic above a different
  107. #   event by adding the ID of the event in square brackets after \hover_alert,
  108. #   like so:
  109. #
  110. #      \hover_alert[0] { ... }
  111. #
  112. #   Now, if you set it to -1, then it will show above the player. If you set it
  113. #   to 0, it will show above the event in which the comment is. If you set it
  114. #   to any integer > 0, it will show above the event with that ID. If you want
  115. #   to set it above a follower, then you need to put an f before the ID, like
  116. #   so:
  117. #
  118. #      \hover_alert[f1] { ... }
  119. #
  120. #   where 1 is the first follower after the player, 2 is the second, etc. You
  121. #   can also set a hover alert above a vehicle by placing a v instead of an f:
  122. #
  123. #      \hover_alert[v0] { ... }
  124. #
  125. #   0 is the boat, 1 is the ship, and 2 is the airship.
  126. #
  127. #    Finally, I mention again that you can remove a hover alert graphic simply
  128. #   by not setting the name or icon within the {}. In other words, the
  129. #   following code would delete any hover graphic over Event 4:
  130. #
  131. #      \hover_alert[4] { }
  132. #``````````````````````````````````````````````````````````````````````````````
  133. #  Autogain Hover Alerts
  134. #
  135. #    The autogain feature allows you to make it so that when gold and items are
  136. #   gained, a hover alert is created above the player showing what is received.
  137. #
  138. #    If you want to use this feature, the value of AUTOGAIN_HOVERALERTS_SWITCH
  139. #   at line 182 must be set to a value greater than 0, and then the autogain
  140. #   alerts will only occur when the in-game switch with that ID is ON. You can
  141. #   also set a number of other autogain features starting at line 185. I
  142. #   direct you there for instructions about what each does.
  143. #==============================================================================
  144.  
  145. $imported = {} unless $imported
  146. $imported[:MA_HoverAlerts] = true
  147.  
  148. #==============================================================================
  149. # *** MA_HoverAlert
  150. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  151. #  This module holds configuration and data for the Hover Alerts script
  152. #==============================================================================
  153.  
  154. module MA_HoverAlert
  155.   #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  156.   # * BEGIN  Editable Region
  157.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  158.   #  Text Option Defaults
  159.   #``````````````````````````````````````````````````````````````````````````
  160.   #    These options mostly just change the way text is drawn by default, and
  161.   #   are all subject to be overridden in any hover alert.
  162.   FONTNAME = Font.default_name #  The font used when drawing text
  163.   FONTSIZE = Font.default_size #  The size of text when drawing text
  164.   COLOUR = [255, 255, 255]     #  The default colour of text when drawing text.
  165.                                # It can be either an [r, g, b, a] array or it
  166.                                # can be an integer for the windowskin palette.
  167.   BOLD = Font.default_bold     #  Whether text is bolded. It can be set to
  168.                                # either true or false
  169.   ITALIC = Font.default_italic #  Whether text is italicized. It can be set to
  170.                                # either true or false
  171.   EFFECT = :none               #  Default effect for regular hover alerts. It
  172.                                # can be set to either :none, :bounce, :flash,
  173.                                # :fade_bounce, or :rise_and_fade.
  174.   ANIMATE_FRAMES = 12          #  If using an animated picture named with a
  175.                                # %[x], then the number of frames to wait on
  176.                                # each frame. There are 60 frames in 1 second.
  177.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  178.   #  Autogain Options
  179.   #``````````````````````````````````````````````````````````````````````````
  180.   #    These options affect the autogain feature, and none affect any other
  181.   #   hover alert except those created when gaining items.
  182.   AUTOGAIN_HOVERALERTS_SWITCH = 5 #  The ID of the switch used to turn the
  183.                                   # autogain feature on and off. If you never
  184.                                   # want to use it, set this to 0.
  185.   AUTOGAIN_GOLD_ICON = 262        #  The icon for gold when autogaining
  186.   AUTOGAIN_NAME_FORMAT = "%s"     #  The format for the name of the item. The
  187.                                   # %s will be replaced with the item's name
  188.                                   # when autogaining.
  189.   AUTOGAIN_NUM_FORMAT = " %+d"    #  The format for the amount gained. The %+d
  190.                                   # is replaced by the number of items or gold
  191.                                   # gained.
  192.   AUTOGAIN_GAIN_SE = ["Chime2"]   #  The SE played when gaining items.
  193.   AUTOGAIN_LOSE_SE = ["Chime1"]   #  The SE played when losing items.
  194.   AUTOGAIN_EFFECT = :rise_and_fade# Effect when autogaining. It can be
  195.                                   # either :fade, :rise_and_fade, :disintegrate,
  196.                                   # or :rise_and_disintegrate.
  197.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  198.   # * END    Editable Region
  199.   #//////////////////////////////////////////////////////////////////////////
  200.   AUTOGAIN_GAIN_SE = RPG::SE.new(*AUTOGAIN_GAIN_SE) if AUTOGAIN_GAIN_SE.is_a?(Array)
  201.   AUTOGAIN_LOSE_SE = RPG::SE.new(*AUTOGAIN_LOSE_SE) if AUTOGAIN_LOSE_SE.is_a?(Array)
  202.  
  203.   #==========================================================================
  204.   # ** HoverAlert
  205.   #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  206.   #  This class holds hoveralert data
  207.   #==========================================================================
  208.  
  209.   class HoverAlert < Struct.new(:name, :icon_index, :icon_hue, :effect,
  210.     :effect_param, :se, :proximity, :fontname, :fontsize, :colour, :bold,
  211.     :italic, :time)
  212.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  213.     # * Object Initialization
  214.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  215.     def initialize(*args)
  216.       defaults = MA_HoverAlert.maha_default_values
  217.       defaults[0, args.size] = args unless args.empty?
  218.       super(*defaults)
  219.     end
  220.   end
  221.  
  222.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  223.   # * Default Values
  224.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225.   def self.maha_default_values
  226.     ["", 0, 0, MA_HoverAlert::EFFECT, 0, nil, 0, MA_HoverAlert::FONTNAME,
  227.       MA_HoverAlert::FONTSIZE, MA_HoverAlert::COLOUR, MA_HoverAlert::BOLD,
  228.       MA_HoverAlert::ITALIC, -1]
  229.   end
  230. end
  231.  
  232. #==============================================================================
  233. # ** Game_CharacterBase
  234. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  235. #  Summary of Changes:
  236. #    aliased methods
  237. #    new method - show_hover_alert  
  238. #==============================================================================
  239.  
  240. class Game_CharacterBase
  241.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242.   # * Public Instance Variables
  243.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244.   attr_reader   :hover_alert
  245.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  246.   # * Initialize Private Members
  247.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248.   alias maha_initprivmem_1cr0 init_private_members
  249.   def init_private_members(*args)
  250.     maha_initprivmem_1cr0(*args) # Call original method
  251.     clear_hover_alert
  252.   end
  253.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254.   # * Clear Hover Alert
  255.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  256.   def clear_hover_alert
  257.     @hover_alert_queue = []
  258.     @hover_alert = nil
  259.   end
  260.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  261.   # * Show Hover Alert
  262.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  263.   def show_hover_alert(name = "", icon = 0, *args)
  264.     if (name.nil? || name.empty?) && (icon.nil? || icon == 0)
  265.       @hover_alert = @hover_alert_queue.empty? ? nil : @hover_alert_queue.shift
  266.     else
  267.       alert = MA_HoverAlert::HoverAlert.new(name, icon, *args)
  268.       @hover_alert ? @hover_alert_queue.push(alert) : @hover_alert = alert
  269.     end
  270.   end
  271.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  272.   # * Replace Hover Alert
  273.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  274.   def replace_hover_alert(*args)
  275.     clear_hover_alert
  276.     show_hover_alert(*args)
  277.   end
  278.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279.   # * Setup Hover Alert by Comment
  280.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  281.   def interpret_hover_alert_comment(text)
  282.     if text[/\\HOVER_ALERT\[?.*?\]?\s*\{(.*?)\}/im]
  283.       name, icon, icon_hue, effect, effect_param, se, proximity, fontname,  
  284.         fontsize, colour, bold, italic, time = *MA_HoverAlert.maha_default_values
  285.       color = nil # Initialize alternate spelling of color
  286.       eval($1)
  287.       colour = color if color
  288.       se = RPG::SE.new(*se) if se.is_a?(Array)
  289.       replace_hover_alert(name, icon, icon_hue, effect, effect_param, se,
  290.         proximity, fontname, fontsize, colour, bold, italic, time)
  291.     end
  292.   end
  293. end
  294.  
  295. #==============================================================================
  296. # ** Game_Event
  297. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  298. #  Summary of Changes:
  299. #    aliased methods - setup_page_settings; clear_page_settings
  300. #    new method - ma_collect_first_comment  
  301. #==============================================================================
  302.  
  303. class Game_Event
  304.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  305.   # * Setup Page Settings
  306.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  307.   alias ma_stuppgsets_7sj5 setup_page_settings
  308.   def setup_page_settings(*args)
  309.     ma_stuppgsets_7sj5(*args) # Call original method
  310.     clear_hover_alert
  311.     interpret_hover_alert_comment(ma_collect_init_comment)
  312.   end
  313.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  314.   # * Clear Page Settings
  315.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  316.   alias ma_clrpgsettings_5na5 clear_page_settings
  317.   def clear_page_settings(*args)
  318.     ma_clrpgsettings_5na5(*args) # Call original method
  319.     clear_hover_alert
  320.   end
  321.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  322.   # * Collect First Comment
  323.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  324.   def ma_collect_init_comment
  325.     comment, i = "", 0
  326.     while !@list[i].nil? && (@list[i].code == 108 || @list[i].code == 408)
  327.       comment += @list[i].parameters[0] + "\n"
  328.       i += 1
  329.     end
  330.     comment
  331.   end unless self.method_defined?(:ma_collect_init_comment)
  332. end
  333.  
  334. #==============================================================================
  335. # ** Game_Party
  336. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  337. #  Summary of Changes:
  338. #    new method - maha_item_number_plus_equips
  339. #==============================================================================
  340.  
  341. class Game_Party
  342.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  343.   # * Item Number and Equips
  344.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  345.   def maha_item_number_plus_equips(item)
  346.     equip_num = 0
  347.     members.each { |actor| equip_num += actor.equips.count(item) }
  348.     item_number(item) + equip_num
  349.   end
  350. end
  351.  
  352. #==============================================================================
  353. # ** Game_Interpreter
  354. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  355. #  Summary of Changes:
  356. #    aliased method - command_108
  357. #==============================================================================
  358.  
  359. class Game_Interpreter
  360.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361.   # * Command 108
  362.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  363.   alias maha_cmmndcomment_6cz9 command_108
  364.   def command_108(*args)
  365.     initial = (@index == 0)
  366.     maha_cmmndcomment_6cz9(*args) # Call original method
  367.     maha_interpret_hover_comment(@comments.join("\n")) unless initial
  368.   end
  369.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  370.   # * Setup Hover Alert Comment
  371.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  372.   def maha_interpret_hover_comment(text)
  373.     text2 = text.dup
  374.     loop do # Get evert hover alert code in the comment
  375.       match = text2.slice!(/\\HOVER[ _]ALERT\[?\s*([VF]?)(-?\d*)\s*\]?\s*\{.*?\}/im)
  376.       break if match.nil?
  377.       case $1.upcase
  378.       when ''  # Empty
  379.         character = get_character($2.to_i)
  380.       when 'F' # Follower
  381.         character = $2.to_i == 0 ? $game_player : $game_player.followers[$2.to_i - 1]
  382.         return if !character || !character.visible?
  383.       when 'V' # Vehicle
  384.         character = $game_map.vehicles[$2.to_i]
  385.         return if !character || !character.transparent
  386.       end
  387.       character.interpret_hover_alert_comment(match) if character.is_a?(Game_CharacterBase)
  388.     end
  389.   end
  390.   if MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH >= 0
  391.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  392.     # * Gain Gold
  393.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  394.     alias maha_command125_5fx9 command_125
  395.     def command_125(*args, &block)
  396.       old_value = $game_party.gold
  397.       maha_command125_5fx9(*args, &block) # Call Original Method
  398.       # Add to receipt if the possessed amount of gold has changed
  399.       if $game_party.gold != old_value && (MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH == 0 ||
  400.         $game_switches[MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH])
  401.         text = sprintf(MA_HoverAlert::AUTOGAIN_NUM_FORMAT, $game_party.gold - old_value)
  402.         se = $game_party.gold > old_value ? MA_HoverAlert::AUTOGAIN_GAIN_SE : MA_HoverAlert::AUTOGAIN_LOSE_SE
  403.         $game_player.show_hover_alert(text, MA_HoverAlert::AUTOGAIN_GOLD_ICON,
  404.           0, MA_HoverAlert::AUTOGAIN_EFFECT, 0, se)
  405.       end
  406.     end
  407.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  408.     # * Gain Item
  409.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  410.     alias maha_comnd126_2vv9 command_126
  411.     def command_126(*args)
  412.       item = $data_items[@params[0]]
  413.       old_val = $game_party.maha_item_number_plus_equips(item)
  414.       maha_comnd126_2vv9(*args) # Call original method
  415.       autogain_item_hover_alert(item, $game_party.maha_item_number_plus_equips(item) - old_val)
  416.     end
  417.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  418.     # * Gain Weapon
  419.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  420.     alias maha_commn127_3ar4 command_127
  421.     def command_127(*args)
  422.       item = $data_weapons[@params[0]]
  423.       old_val = $game_party.maha_item_number_plus_equips(item)
  424.       maha_commn127_3ar4(*args) # Call original method
  425.       autogain_item_hover_alert(item, $game_party.maha_item_number_plus_equips(item) - old_val)
  426.     end
  427.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  428.     # * Gain Armor
  429.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  430.     alias maha_cnd128_1sp6 command_128
  431.     def command_128(*args)
  432.       item = $data_armors[@params[0]]
  433.       old_val = $game_party.maha_item_number_plus_equips(item)
  434.       maha_cnd128_1sp6(*args) # Call original method
  435.       autogain_item_hover_alert(item, $game_party.maha_item_number_plus_equips(item) - old_val)
  436.     end
  437.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438.     # * Autogain Hover Alert
  439.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  440.     def autogain_item_hover_alert(item, n)
  441.       return if n == 0 || !(MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH == 0 ||
  442.         $game_switches[MA_HoverAlert::AUTOGAIN_HOVERALERTS_SWITCH])
  443.       text = sprintf(MA_HoverAlert::AUTOGAIN_NAME_FORMAT, item.name) +
  444.         sprintf(MA_HoverAlert::AUTOGAIN_NUM_FORMAT, n)
  445.       se = n > 0 ? MA_HoverAlert::AUTOGAIN_GAIN_SE : MA_HoverAlert::AUTOGAIN_LOSE_SE
  446.       icon_hue = $imported[:MAIcon_Hue] ? item.icon_hue : 0
  447.       $game_player.show_hover_alert(text, item.icon_index, icon_hue,
  448.         MA_HoverAlert::AUTOGAIN_EFFECT, 0, se)
  449.     end
  450.   end
  451. end
  452.  
  453. #==============================================================================
  454. # ** Sprite_HoverAlert
  455. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  456. #  This class handles showing the hover sprite.
  457. #==============================================================================
  458.  
  459. class Sprite_HoverAlert < Sprite_Base
  460.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  461.   # * Object Initialization
  462.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  463.   def initialize(viewport, character)
  464.     # Initialize variables
  465.     @char_x, @char_y = 0, 0
  466.     @effect_x, @effect_y = 0, 0
  467.     @effect, @effect_param, @effect_time = :none, 0, -1
  468.     @ap_time, @ap_max_time, @ap_width, @ap_frame_index, @ap_frame_num = -1, 0, 0, 0, 0
  469.     @time = 0
  470.     @disintegrate_array = []
  471.     super(viewport)
  472.     self.z = 200
  473.     @character = character
  474.     refresh
  475.   end
  476.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  477.   # * Free
  478.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  479.   def dispose(*args)
  480.     bitmap.dispose if bitmap && !bitmap.disposed?
  481.     super(*args)
  482.   end
  483.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  484.   # * Update
  485.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  486.   def update
  487.     super
  488.     refresh if @hover_alert != @character.hover_alert # if hover alert changed
  489.     if bitmap
  490.       if @hover_alert.proximity > 0
  491.         x = @character.distance_x_from($game_player.x).abs
  492.         y = @character.distance_y_from($game_player.y).abs
  493.         self.visible = Math.hypot(x, y) <= @hover_alert.proximity
  494.       end
  495.       if self.visible
  496.         maha_update_se              # Update Sound Effect
  497.         maha_update_frame_animation # Update animation
  498.         maha_update_effect          # Update the effect being played
  499.         # Adust position
  500.         self.x = @char_x + @effect_x
  501.         self.y = @char_y + @effect_y
  502.       end
  503.       if @hover_alert && @hover_alert.time > 0
  504.         if @time == @hover_alert.time
  505.           @character.show_hover_alert("", 0) # End Hover Alert
  506.           refresh
  507.         end
  508.         @time += 1
  509.       end
  510.     end
  511.   end
  512.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  513.   # * Update SE
  514.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  515.   def maha_update_se
  516.     if @hover_alert.se && !@se_played
  517.       @hover_alert.se.play
  518.       @se_played = true
  519.     end
  520.   end
  521.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  522.   # * Update Frame Animation
  523.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  524.   def maha_update_frame_animation
  525.     if @ap_time == 0 # If timer finished
  526.       # Switch frames
  527.       @ap_frame_index = (@ap_frame_index + 1) % @ap_frame_num
  528.       @ap_time = @ap_max_time
  529.       self.src_rect.x = @ap_frame_index*@ap_width
  530.     end
  531.     @ap_time -= 1 if @ap_time > 0 # Decrease timer until finished
  532.   end
  533.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  534.   # * Adjust Character Position
  535.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  536.   def adjust_character_position(x, y); @char_x, @char_y = x, y; end
  537.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  538.   # * Refresh
  539.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  540.   def refresh
  541.     @se_played = false
  542.     @hover_alert = @character.hover_alert
  543.     bitmap.dispose if bitmap && !bitmap.disposed?
  544.     return unless @hover_alert
  545.     (!@hover_alert.name.empty? ? maha_draw_picture : maha_draw_text) rescue maha_draw_text
  546.     self.ox = @ap_width / 2
  547.     self.oy = bitmap.height
  548.     self.visible = true
  549.     maha_start_effect
  550.   end
  551.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  552.   # * Reset Font Settings
  553.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  554.   def maha_reset_font_settings
  555.     bitmap.font = Font.new(@hover_alert.fontname, @hover_alert.fontsize)
  556.     bitmap.font.bold = @hover_alert.bold
  557.     bitmap.font.italic = @hover_alert.italic
  558.   end
  559.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  560.   # * Text Colour
  561.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  562.   def text_color(n)
  563.     colour = case n
  564.     when Integer
  565.       # Extended Colour Palette compatibility
  566.       if $imported[:MA_ExtendedColourPalette] && n >= 32
  567.         n -= 32
  568.         Cache.system("Palette").get_pixel((n % 8) * 8, (n / 8) * 8)
  569.       else
  570.         Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
  571.       end
  572.     when Array then Color.new(*n)
  573.     else Color.new(255, 255, 255)
  574.     end
  575.   end
  576.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  577.   # * Draw Picture
  578.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  579.   def maha_draw_picture
  580.     # Use picture if it exists
  581.     self.bitmap = Cache.picture(@hover_alert.name).dup
  582.     @ap_width = bitmap.width
  583.     if @hover_alert.name[/%\[(\d+)[\s,;]*(\d*?)\]/] # If animated graphic
  584.       # Setup animated picture variables
  585.       @ap_frame_num = $1.to_i
  586.       @ap_width /= @ap_frame_num
  587.       @ap_max_time = $2.empty? ? MA_HoverAlert::ANIMATE_FRAMES : $2.to_i
  588.       @ap_frame_index = 0
  589.       @ap_time = @ap_max_time
  590.       self.src_rect = Rect.new(0, 0, @ap_width, bitmap.height)
  591.     else
  592.       @ap_time = -1
  593.     end
  594.   end
  595.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  596.   # * Draw Text
  597.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  598.   def maha_draw_text
  599.     # Else draw the word
  600.     x = 0
  601.     self.bitmap = Bitmap.new(24, 24)
  602.     if @hover_alert.name && !@hover_alert.name.empty?
  603.       maha_reset_font_settings
  604.       # Retrieve actual string
  605.       ts = bitmap.text_size(@hover_alert.name)
  606.       if @hover_alert.icon_index > 0
  607.         x = 28
  608.         ts.width += 28
  609.         ts.height = 24 if ts.height < 24
  610.       end
  611.       # Resize
  612.       bitmap.dispose
  613.       self.bitmap = Bitmap.new(ts.width + 4, ts.height + 4)
  614.       maha_reset_font_settings
  615.       bitmap.font.color = text_color(@hover_alert.colour)
  616.       # Draw text
  617.       bitmap.draw_text(x, 0, bitmap.width - x, bitmap.height, @hover_alert.name, 1)
  618.     end
  619.     # Draw Icon
  620.     @hover_alert.icon_hue == 0 ? maha_draw_icon(@hover_alert.icon_index, 0, (height - 24) / 2) :
  621.       maha_draw_icon_with_hue(@hover_alert.icon_index, @hover_alert.icon_hue, 0, (height - 24) / 2)
  622.     @ap_time = -1
  623.     @ap_width = bitmap.width
  624.   end
  625.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626.   # * Draw Icon
  627.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  628.   def maha_draw_icon(icon_index, x, y)
  629.     bmp = Cache.system("Iconset")
  630.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  631.     bitmap.blt(x, y, bmp, rect, 255)
  632.   end
  633.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  634.   # * Draw Icon With Hue
  635.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  636.   def maha_draw_icon_with_hue(icon_index, icon_hue, x, y)
  637.     bmp = Cache.system("Iconset")
  638.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  639.     # Draw Icon onto small and independent bitmap
  640.     icon_bmp = Bitmap.new(24, 24)
  641.     icon_bmp.blt(0, 0, bmp, rect)
  642.     icon_bmp.hue_change(icon_hue) # Change hue of icon
  643.     rect.x, rect.y = 0, 0
  644.     bitmap.blt(x, y, icon_bmp, rect, 255)
  645.     icon_bmp.dispose # Dispose Icon Bitmap
  646.   end
  647.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  648.   # * Start HoverAlert Effect
  649.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  650.   def maha_start_effect
  651.     @effect = @hover_alert.effect
  652.     @effect_param = @hover_alert.effect_param
  653.     @effect_x, @effect_y = 0, 0
  654.     @disintegrate_array.clear
  655.     self.opacity = 255
  656.     case @effect
  657.     when :bounce, :fade_bounce then @effect_time = 32
  658.     when :flash
  659.       @effect_time = 32
  660.       flash(text_color(@effect_param), @effect_time)
  661.     when :rise_and_fade
  662.       @effect_time = 48
  663.       @effect_y = 18
  664.     when :fade then @effect_time = 48
  665.     when :disintegrate, :rise_and_disintegrate
  666.       @effect_y = 24 if @effect == :rise_and_disintegrate
  667.       @effect_time = 64
  668.       for i in 0...bitmap.width
  669.         for j in 0...bitmap.height
  670.           @disintegrate_array.push(i, j)
  671.         end
  672.       end
  673.     else
  674.       @effect_time = -1
  675.     end
  676.   end
  677.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  678.   # * Update HoverAlert Effect
  679.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  680.   def maha_update_effect
  681.     if @effect_time == 0
  682.       case @effect
  683.       when :bounce, :flash, :fade_bounce then maha_start_effect # Repeat
  684.       else maha_finish_effect # Close
  685.       end
  686.     elsif @effect_time > 0
  687.       case @effect
  688.       when :bounce then @effect_y += (@effect_time > 16 ? -0.5 : 0.5)
  689.       when :fade_bounce then self.opacity += (@effect_time > 16 ? -8 : 8)
  690.       # Temporary Effects
  691.       when :fade then self.opacity = 16*@effect_time if @effect_time < 16
  692.       when :rise_and_fade
  693.         @effect_y -= 0.5
  694.         self.opacity = 16*@effect_time if @effect_time < 16
  695.       when :disintegrate then maha_update_disintegrate_effect if @effect_time < 32
  696.       when :rise_and_disintegrate
  697.         @effect_y -= 0.5 if @effect_time > 32
  698.         maha_update_disintegrate_effect if @effect_time < 32
  699.       end
  700.       @effect_time -= 1
  701.     end
  702.   end
  703.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  704.   # * Update Disintegrate Effect
  705.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  706.   def maha_update_disintegrate_effect
  707.     col = Color.new(0, 0, 0, 0)
  708.     (bitmap.width*bitmap.height / 32).times do
  709.       i = (rand(@disintegrate_array.size / 2)*2)
  710.       x, y = *@disintegrate_array[i, 2]
  711.       bitmap.set_pixel(x, y, col)
  712.       @disintegrate_array.delete_at(i)
  713.       @disintegrate_array.delete_at(i + 1)
  714.     end
  715.   end
  716.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  717.   # * Finish HoverAlert Effect
  718.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  719.   def maha_finish_effect
  720.     @effect_x, @effect_y = 0, 0
  721.     @effect_time = -1
  722.     self.opacity = 255
  723.     @disintegrate_array.clear
  724.     # Set to next hover alert, if any
  725.     @character.show_hover_alert("", 0)
  726.     refresh
  727.   end
  728. end
  729.  
  730. #==============================================================================
  731. # ** Sprite_Character
  732. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  733. #  Summary of Changes:
  734. #    aliased methods - update; dispose
  735. #    new methods - update_maha_sprite; dispose_maha_sprite
  736. #==============================================================================
  737.  
  738. class Sprite_Character
  739.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  740.   # * Frame Update
  741.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  742.   alias maha_update_2hz0 update
  743.   def update(*args)
  744.     maha_update_2hz0(*args) # Call original method
  745.     update_maha_sprite
  746.   end
  747.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  748.   # * Update Hover Alert
  749.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  750.   def update_maha_sprite
  751.     if !@maha_sprite && @character.hover_alert # Create the HoverAlert sprite
  752.       @maha_sprite = Sprite_HoverAlert.new(viewport, @character)
  753.     end
  754.     if @maha_sprite
  755.       if @character.hover_alert.nil?
  756.         dispose_maha_sprite
  757.       else
  758.         # Pass position of sprite to the hover alert's sprite
  759.         @maha_sprite.adjust_character_position(self.x, self.y - self.oy)
  760.         @maha_sprite.update
  761.       end
  762.     end
  763.   end
  764.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  765.   # * Dispose
  766.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  767.   alias maha_dispose_4cm6 dispose
  768.   def dispose(*args)
  769.     dispose_maha_sprite
  770.     maha_dispose_4cm6(*args) # Call original method
  771.   end
  772.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  773.   # * Dispose Hover Alert Sprite
  774.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  775.   def dispose_maha_sprite
  776.     @maha_sprite.dispose if @maha_sprite && !@maha_sprite.disposed?
  777.     @maha_sprite = nil
  778.   end
  779. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement