neonblack

Skill Box v1.0

Jan 10th, 2013
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###-----------------------------------------------------------------------------
  2. #  Skill Display script v1.0
  3. #  Created by Neon Black
  4. #  V1.0 - 1.9.2013 - Version created for release
  5. #  Created for both commercial and non-commercial use as long as credit is
  6. #  given to Neon Black.
  7. ###-----------------------------------------------------------------------------
  8.  
  9. class Window_BattleLog < Window_Selectable
  10.   ##------
  11.   ## These three constants can be changed from nil to a string value ("Counter"
  12.   ## with the quotes for example) to display a message when counter, reflection,
  13.   ## or substitution occurs.
  14.   ##------
  15.   COUNTER = nil
  16.   REFLECT = nil
  17.   SUB = nil
  18.  
  19.   ##------
  20.   ## These twho constants are used to determined the X and Y offsets of the
  21.   ## window.  Increase these values to move them down or right and decrease
  22.   ## them to move the window up and left.
  23.   ##------
  24.  
  25.   X_OFFSET = 0
  26.   Y_OFFSET = 48
  27.  
  28.   ##------
  29.   ## Allows a picture to be used instead of the default black background.  If
  30.   ## you do not want to use a picture, just set this to nil.  The picture goes
  31.   ## in the Graphics/Pictures folder.
  32.   ##------
  33.  
  34.   BACK_PIC = nil
  35.  
  36.   ## Adds a new array to store skill names.
  37.   alias cp_init initialize
  38.   def initialize
  39.     @pop_wind = []
  40.     cp_init
  41.     @back_sprite.x = self.x = X_OFFSET
  42.     @back_sprite.y = self.y = Y_OFFSET
  43.     create_background_picture
  44.   end
  45.  
  46.   def create_background_picture
  47.     @back_pic_sprite = Sprite.new
  48.     return unless BACK_PIC
  49.     @back_pic_sprite.bitmap = Cache.picture(BACK_PIC)
  50.     @back_pic_sprite.ox = @back_pic_sprite.width / 2
  51.     @back_pic_sprite.oy = @back_pic_sprite.height / 2
  52.     @back_pic_sprite.x = width / 2 + x
  53.     @back_pic_sprite.y = height / 2 + y
  54.     @back_pic_sprite.visible = false
  55.   end
  56.  
  57.   ## Change the log window to 1 line max.
  58.   def max_line_number
  59.     return 1
  60.   end
  61.  
  62.   alias cp_window_clear clear
  63.   def clear
  64.     @pop_wind.clear
  65.     cp_window_clear
  66.   end
  67.  
  68.   ## Overwrites the refresh to change what is drawn.
  69.   def refresh
  70.     draw_background unless BACK_PIC
  71.     contents.clear
  72.     @back_pic_sprite.visible = false if @back_pic_sprite
  73.     return if @pop_wind.empty?
  74.     @back_pic_sprite.visible = true
  75.     if @pop_wind[-1].is_a?(String)
  76.       draw_text(0, 0, contents.width, line_height, @pop_wind[-1], 1)
  77.     else
  78.       xpos = contents.width - (contents.text_size(@pop_wind[-1].name).width + 24)
  79.       xpos /= 2
  80.       draw_item_name(@pop_wind[-1], xpos, 0)
  81.     end
  82.   end
  83.  
  84.   ## Draws the display box in a different size.
  85.   def draw_background
  86.     @back_bitmap.clear
  87.     @back_bitmap.fill_rect(back_rect, back_color)
  88.     rect1 = Rect.new(back_rect.x - 64, back_rect.y, 64, back_rect.height)
  89.     rect2 = Rect.new(back_rect.x + back_rect.width, back_rect.y, 64,
  90.                      back_rect.height)
  91.     @back_bitmap.gradient_fill_rect(rect1, no_colour, back_color)
  92.     @back_bitmap.gradient_fill_rect(rect2, back_color, no_colour)
  93.   end
  94.  
  95.   def back_rect
  96.     if @pop_wind.empty?
  97.       i = width
  98.     else
  99.       n = @pop_wind[-1].is_a?(String) ? @pop_wind[-1] : @pop_wind[-1].name
  100.       i = contents.text_size(n).width
  101.       i += 24 unless @pop_wind[-1].is_a?(String)
  102.     end
  103.     Rect.new((width - i) / 2, padding, i, (@pop_wind.empty? ? 0 : 1) * line_height)
  104.   end
  105.  
  106.   def no_colour
  107.     Color.new(0, 0, 0, 0)
  108.   end
  109.    
  110.   def add_pop_line(item = nil)
  111.     @pop_wind.push(item) unless item.nil? || item == ""
  112.     @pop_wind.pop if !item.is_a?(String) && item.name == ""
  113.     refresh
  114.   end
  115.  
  116.   ## Grabs the names of skills rather than the usage lines.  
  117.   def display_use_item(subject, item)
  118.     add_pop_line(item)
  119.   end
  120.  
  121.   def display_counter(target, item)
  122.     return unless COUNTER
  123.     add_pop_line(COUNTER)
  124.     wait
  125.   end
  126.  
  127.   def display_reflection(target, item)
  128.     return unless REFLECT
  129.     add_pop_line(REFLECT)
  130.     wait
  131.   end
  132.  
  133.   def display_substitute(substitute, target)
  134.     return unless SUB
  135.     add_pop_line(SUB)
  136.     wait
  137.   end
  138. end
RAW Paste Data