neonblack

Skill Window

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