Advertisement
Archeia

Image Pop Up Add-On

Apr 3rd, 2017
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.98 KB | None | 0 0
  1. #==============================================================================
  2. # ■ BattleLuna: Damage Popup Image Add-On
  3. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  4. # This is an extension for Damage Popup. This uses Image sheets rather than
  5. # using the game's font. The sheets are arranged horizontally.
  6. #==============================================================================
  7.  
  8. module BattleLuna
  9.   module Addon
  10.    
  11.     BATTLE_POPUP[:image_setup] = {
  12.       # For numbers, there are some options below.
  13.       :enable_numbers =>  false,
  14.      
  15.       # For words, this script will search for image in Graphics/Systems
  16.       # with name is the word display in default. Config in :word_setting.
  17.       # This will create default text if it cannot find an image.
  18.       # For example:
  19.       # "MISS" will search for image MISS in Graphics/System
  20.       # If :add_state  => "%s", it will search for image STATENAME
  21.       :enable_words   =>  false,
  22.      
  23.       # Setup for numbers
  24.       :numbers_setup  =>  {
  25.         # Setup images.
  26.         :hp_number_dmg    =>  "Number+",
  27.         :hp_number_heal   =>  "Number-",
  28.         :mp_number_dmg    =>  "MP_Number+",
  29.         :mp_number_heal   =>  "MP_Number-",
  30.         :tp_number_dmg    =>  "MP_Number+",
  31.         :tp_number_heal   =>  "MP_Number-",
  32.        
  33.         # Setup style.
  34.         :spacing          =>  -4,
  35.       },
  36.     } # Basic setting for image
  37.    
  38.   end # Addon
  39. end # BattleLuna
  40.  
  41. #==============================================================================
  42. # Editing anything past the engine's configuration script may potentially  
  43. # result in causing computer damage, incontinence, explosion of user's head,
  44. # coma, death, and/or halitosis so edit at your own risk.
  45. # We're not liable for the risks you take should you pass this sacred grounds.
  46. #==============================================================================
  47.  
  48. #==============================================================================
  49. # ■ Sprite_PopupLuna
  50. #==============================================================================
  51. class Sprite_PopupLuna < Sprite
  52.  
  53.   #--------------------------------------------------------------------------
  54.   # new method: setting_image
  55.   #--------------------------------------------------------------------------
  56.   def setting_image
  57.     BattleLuna::Addon::BATTLE_POPUP[:image_setup]
  58.   end
  59.  
  60.   #--------------------------------------------------------------------------
  61.   # alias method: create_bitmap
  62.   #--------------------------------------------------------------------------
  63.   alias battle_luna_dpip_create_bitmap create_bitmap
  64.   def create_bitmap
  65.     case @rule
  66.     when :hp_dmg, :hp_heal, :mp_dmg, :mp_heal, :tp_dmg, :tp_heal
  67.       if setting_image[:enable_numbers]
  68.         create_image_bitmap
  69.       else
  70.         battle_luna_dpip_create_bitmap
  71.       end
  72.     else
  73.       if setting_image[:enable_words]
  74.         create_word_bitmap
  75.       else
  76.         battle_luna_dpip_create_bitmap
  77.       end
  78.     end
  79.   end
  80.  
  81.   #--------------------------------------------------------------------------
  82.   # new method: create_image_bitmap
  83.   #--------------------------------------------------------------------------
  84.   def create_image_bitmap
  85.     case @rule
  86.     when :hp_dmg; num_bitmap = setting_image[:numbers_setup][:hp_number_dmg]
  87.     when :mp_dmg; num_bitmap = setting_image[:numbers_setup][:mp_number_dmg]
  88.     when :tp_dmg; num_bitmap = setting_image[:numbers_setup][:tp_number_dmg]
  89.     when :hp_heal; num_bitmap = setting_image[:numbers_setup][:hp_number_heal]
  90.     when :mp_heal; num_bitmap = setting_image[:numbers_setup][:mp_number_heal]
  91.     when :tp_heal; num_bitmap = setting_image[:numbers_setup][:tp_number_heal]
  92.     end
  93.     num_bitmap = Cache.system(num_bitmap)
  94.     #---
  95.     bw = Graphics.width
  96.     bh = num_bitmap.height * 2
  97.     bitmap = Bitmap.new(bw, bh)
  98.     #---
  99.     spacing  = setting_image[:numbers_setup][:spacing]
  100.     nwidth   = num_bitmap.width / 10
  101.     nheight  = num_bitmap.height
  102.     ncount   = @data[0].size
  103.     twidth   = ncount * (nwidth + spacing) - spacing
  104.     offset_x = [(bw - twidth) / 2, 0].max
  105.     #---
  106.     (0...ncount).each { |index|
  107.       x = offset_x + index * (nwidth + spacing)
  108.       number = @data[0][index].to_i
  109.       rect   = Rect.new(nwidth * number, 0, nwidth, nheight)
  110.       bitmap.blt(x, 0, num_bitmap, rect)
  111.     }
  112.     bitmap
  113.   end
  114.  
  115.   #--------------------------------------------------------------------------
  116.   # new method: create_word_bitmap
  117.   #--------------------------------------------------------------------------
  118.   def create_word_bitmap
  119.     begin
  120.       word_bitmap = Cache.system(@data[0])
  121.     rescue
  122.       return battle_luna_dpip_create_bitmap
  123.     end
  124.     #---
  125.     bw = Graphics.width
  126.     bh = word_bitmap.height
  127.     bitmap = Bitmap.new(bw, bh)    
  128.     offset_x = [(bw - word_bitmap.width) / 2, 0].max
  129.     bitmap.blt(offset_x, 0, word_bitmap, word_bitmap.rect)
  130.     bitmap
  131.   end
  132.  
  133. end # Sprite_PopupLuna
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement