Advertisement
mjshi

Enemy HP/MP Icons v1.01

Jan 13th, 2017
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.40 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Enemy HP/MP Icons v1.01
  3. # by mjshi. OK for use in any project.
  4. #-------------------------------------------------------------------------------
  5. # Installation: Put above Main, preferably also above other custom scripts.
  6. #-------------------------------------------------------------------------------
  7. # Update notes:
  8. #- Minor optimizations.
  9. #-------------------------------------------------------------------------------
  10.  
  11. module EnemyHPMPIcons
  12.   #-----------------------------------------------------------------------------
  13.   # **CONFIGURATION**
  14.   #-----------------------------------------------------------------------------
  15.   # Which icons should the script use next to the HP and MP values?
  16.   HP_ICON = 187
  17.   MP_ICON = 188
  18.   #
  19.   # How much should the text be offset?
  20.   X_OFFSET = 0
  21.   Y_OFFSET = 0
  22.   #
  23.   # How much personal space should we have between the icons and text?
  24.   SPACING = 2
  25.   #
  26.   # How much personal longitude should we have between the icons and text?
  27.   Y_SPACING = 2
  28.   #
  29.   # Make this bigger if stuff is getting cut off
  30.   WINDOW_WIDTH = 120
  31.   #
  32.   #-----------------------------------------------------------------------------
  33.   # What color should the text be? [R, G, B] -OR- windowskin color index
  34.   # ex: TEXTCOLOR = 0   on a fresh project would make the text white, and
  35.   #     TEXTCOLOR = 1   would make it blue.
  36.   # also:
  37.   #     TEXTCOLOR = [255, 255, 255]   makes text white
  38.   #     TEXTCOLOR = [0, 0, 0]         makes text black (will look bad unless
  39.   #                                   HIDE_TEXT_SHADOW = true)
  40.   TEXTCOLOR = 0
  41.   #
  42.   # There's this really annoying blurry outline that shows up around stuff...
  43.   # Want me to kill it?
  44.   HIDE_OUTLINE = false
  45.   #
  46.   # How large ought the text be?
  47.   TEXT_SIZE = 24
  48.   #
  49.   # Drop a shadow under it?
  50.   TEXT_DROP_SHADOW = false
  51.   #
  52.   #-----------------------------------------------------------------------------
  53. end
  54.  
  55. class Sprite_Battler
  56.   def create_ehpmpwindow
  57.     height = EnemyHPMPIcons::TEXT_SIZE*3
  58.  
  59.     @ehpmp_window = Window_Base.new(0,0,EnemyHPMPIcons::WINDOW_WIDTH,height)
  60.     @ehpmp_window.x = self.x - @ehpmp_window.width / 2 + EnemyHPMPIcons::X_OFFSET
  61.     @ehpmp_window.y = self.y + EnemyHPMPIcons::Y_OFFSET - self.height - @ehpmp_window.height
  62.     @ehpmp_window.x = 0 if @ehpmp_window.x < 0
  63.     @ehpmp_window.y = 0 if @ehpmp_window.y < 0
  64.    
  65.     @ehpmp_window.contents.font.outline = !EnemyHPMPIcons::HIDE_OUTLINE
  66.     @ehpmp_window.contents.font.size = EnemyHPMPIcons::TEXT_SIZE
  67.     @ehpmp_window.contents.font.shadow = EnemyHPMPIcons::TEXT_DROP_SHADOW
  68.  
  69.     @ehpmp_window.opacity = 0
  70.     @ehpmp_window.z = self.z + 1
  71.     @ehpmp_window.viewport = self.viewport
  72.   end
  73.  
  74.   def update_hpmpinfo
  75.     create_ehpmpwindow if @ehpmp_window.nil?
  76.     @ehpmp_window.visible = @battler.alive? || @battler.hidden?
  77.     return if !@battler.alive? || !@ehpmp_window.visible
  78.  
  79.     @ehpmp_window.update
  80.     @ehpmp_window.contents_opacity = self.opacity if @ehpmp_window.contents_opacity != self.opacity
  81.     @ehpmp_window.y = self.y + EnemyHPMPIcons::Y_OFFSET - self.height - @ehpmp_window.height
  82.     @ehpmp_window.y = 0 if @ehpmp_window.y < 0
  83.     @ehpmp_window.contents.clear
  84.  
  85.     @ehpmp_window.draw_icon(EnemyHPMPIcons::HP_ICON, 0, 0)
  86.     @ehpmp_window.draw_icon(EnemyHPMPIcons::MP_ICON, 0, EnemyHPMPIcons::TEXT_SIZE + EnemyHPMPIcons::Y_SPACING)
  87.  
  88.     width = @ehpmp_window.contents.width - @ehpmp_window.padding
  89.     if EnemyHPMPIcons::TEXTCOLOR.is_a?(Array)
  90.       @ehpmp_window.contents.font.color.set(Color.new(EnemyHPMPIcons::TEXTCOLOR[0], EnemyHPMPIcons::TEXTCOLOR[1], EnemyHPMPIcons::TEXTCOLOR[2]))
  91.     else
  92.       @ehpmp_window.change_color(@ehpmp_window.text_color(EnemyHPMPIcons::TEXTCOLOR))
  93.     end
  94.  
  95.     @ehpmp_window.draw_text(24 + EnemyHPMPIcons::SPACING, 0, width, EnemyHPMPIcons::TEXT_SIZE, @battler.hp.to_s + "/" + @battler.mhp.to_s)
  96.     @ehpmp_window.draw_text(24 + EnemyHPMPIcons::SPACING, EnemyHPMPIcons::TEXT_SIZE + EnemyHPMPIcons::Y_SPACING, width, EnemyHPMPIcons::TEXT_SIZE, @battler.mp.to_s + "/" + @battler.mmp.to_s)
  97.   end
  98.  
  99.   alias _enemyhpmpicons_update update
  100.   def update
  101.     _enemyhpmpicons_update
  102.     return unless @battler.is_a?(Game_Enemy)
  103.     update_hpmpinfo if @battler
  104.   end
  105.  
  106.   alias _enemyhpmpicons_dispose dispose
  107.   def dispose
  108.     @ehpmp_window.dispose if @ehpmp_window
  109.     _enemyhpmpicons_dispose
  110.   end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement