Advertisement
Archeia

Skill Display v1.2

Nov 11th, 2014
876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.58 KB | None | 0 0
  1. ###-----------------------------------------------------------------------------
  2. #  Skill Display v1.2
  3. #  Created by Neon Black
  4. #  V1.2 - 2.11.2014 - More small updates
  5. #  V1.1 - 1.28.2013 - Small updates
  6. #  V1.0 - 1.9.2013 - Version created for release
  7. #  For both commercial and non-commercial use as long as credit is given to
  8. #  Neon Black and any additional authors.  Licensed under Creative Commons
  9. #  CC BY 4.0 - http://creativecommons.org/licenses/by/4.0/
  10. ###-----------------------------------------------------------------------------
  11. $imported = {} if $imported.nil?
  12. $imported["CP-SkillDisplay"] = true
  13.  
  14. class Window_BattleLog < Window_Selectable
  15.   ##------
  16.   #  These three constants can be changed from nil to a string value ("Counter"
  17.   #  with the quotes for example) to display a message when counter, reflection,
  18.   #  or substitution occurs.
  19.   ##------
  20.   COUNTER = nil
  21.   REFLECT = nil
  22.   SUB = nil
  23.  
  24.   ##------
  25.   #  These twho constants are used to determined the X and Y offsets of the
  26.   #  window.  Increase these values to move them down or right and decrease
  27.   #  them to move the window up and left.
  28.   ##------
  29.  
  30.   X_OFFSET = 0
  31.   Y_OFFSET = 48
  32.  
  33.   ##------
  34.   #  Allows a picture to be used instead of the default black background.  If
  35.   #  you do not want to use a picture, just set this to nil.  The picture goes
  36.   #  in the Graphics/Pictures folder.
  37.   ##------
  38.  
  39.   BACK_COLOR = Color.new(0, 0, 0, 64)
  40.   BACK_PIC = nil
  41.  
  42.   ##------
  43.   #  The time taken for each turn measured in frames.
  44.   ##------
  45.   ACTION_SPEED = 20
  46.    
  47. ##-----------------------------------------------------------------------------
  48. #  The following lines are the actual core code of the script.  While you are
  49. #  certainly invited to look, modifying it may result in undesirable results.
  50. #  Modify at your own risk!
  51. ##-----------------------------------------------------------------------------
  52.  
  53.  
  54.   ## Adds a new array to store skill names.
  55.   alias cp_init initialize
  56.   def initialize
  57.     @pop_wind = []
  58.     cp_init
  59.     @back_sprite.x = self.x = X_OFFSET
  60.     @back_sprite.y = self.y = Y_OFFSET
  61.     create_background_picture
  62.   end
  63.  
  64.   def create_background_picture
  65.     @back_pic_sprite = Sprite.new
  66.     return unless BACK_PIC
  67.     @back_pic_sprite.bitmap = Cache.picture(BACK_PIC)
  68.     @back_pic_sprite.ox = @back_pic_sprite.width / 2
  69.     @back_pic_sprite.oy = @back_pic_sprite.height / 2
  70.     @back_pic_sprite.x = width / 2 + x
  71.     @back_pic_sprite.y = height / 2 + y
  72.     @back_pic_sprite.visible = false
  73.   end
  74.  
  75.   ## Change the log window to 1 line max.
  76.   def max_line_number
  77.     return 1
  78.   end
  79.  
  80.   alias cp_window_clear clear
  81.   def clear
  82.     @pop_wind.clear
  83.     cp_window_clear
  84.   end
  85.  
  86.   ## Overwrites the refresh to change what is drawn.
  87.   def refresh
  88.     draw_background unless BACK_PIC
  89.     contents.clear
  90.     @back_pic_sprite.visible = false if @back_pic_sprite
  91.     return if @pop_wind.empty?
  92.     self.openness = 255
  93.     @back_pic_sprite.visible = true
  94.     if @pop_wind[-1].is_a?(String)
  95.       draw_text(0, 0, contents.width, line_height, @pop_wind[-1], 1)
  96.     elsif @pop_wind[-1].is_a?(Array)
  97.       xpos = contents.width - (contents.text_size(@pop_wind[-1][1]).width + 24)
  98.       xpos /= 2
  99.       draw_icon(@pop_wind[-1][0], xpos, 0)
  100.       change_color(normal_color)
  101.       draw_text(xpos + 24, 0, contents.width, line_height, @pop_wind[-1][1])
  102.     else
  103.       xpos = contents.width - (contents.text_size(@pop_wind[-1].name).width + 24)
  104.       xpos /= 2
  105.       draw_item_name(@pop_wind[-1], xpos, 0)
  106.     end
  107.   end
  108.  
  109.   ## Draws the display box in a different size.
  110.   def draw_background
  111.     @back_bitmap.clear
  112.     @back_bitmap.fill_rect(back_rect, back_color)
  113.     rect1 = Rect.new(back_rect.x - 64, back_rect.y, 64, back_rect.height)
  114.     rect2 = Rect.new(back_rect.x + back_rect.width, back_rect.y, 64,
  115.                      back_rect.height)
  116.     @back_bitmap.gradient_fill_rect(rect1, no_colour, back_color)
  117.     @back_bitmap.gradient_fill_rect(rect2, back_color, no_colour)
  118.   end
  119.  
  120.   def back_rect
  121.     if @pop_wind.empty?
  122.       i = width
  123.     elsif @pop_wind[-1].is_a?(Array)
  124.       n = @pop_wind[-1][1]
  125.       i = contents.text_size(n).width
  126.       i += 24
  127.     else
  128.       n = @pop_wind[-1].is_a?(String) ? @pop_wind[-1] : @pop_wind[-1].name
  129.       i = contents.text_size(n).width
  130.       i += 24 unless @pop_wind[-1].is_a?(String)
  131.     end
  132.     Rect.new((width - i) / 2, padding, i, (@pop_wind.empty? ? 0 : 1) * line_height)
  133.   end
  134.  
  135.   def back_color
  136.     BACK_COLOR
  137.   end
  138.  
  139.   def no_colour
  140.     color = back_color.clone
  141.     color.alpha = 0
  142.     color
  143.   end
  144.    
  145.   def add_pop_line(item = nil)
  146.     @pop_wind.push(item) unless item.nil? || item == ""
  147.     @pop_wind.pop if !item.is_a?(String) && item.name == ""
  148.     refresh
  149.   end
  150.    
  151.   def add_pop_array(icon = 0, text = "")
  152.     @pop_wind.push([icon, text]) unless text.empty?
  153.     refresh
  154.   end
  155.  
  156.   ## Grabs the names of skills rather than the usage lines.  
  157.   def display_use_item(subject, item)
  158.     add_pop_line(item)
  159.   end
  160.  
  161.   def display_counter(target, item)
  162.     return unless COUNTER
  163.     add_pop_line(COUNTER)
  164.     wait
  165.   end
  166.  
  167.   def display_reflection(target, item)
  168.     return unless REFLECT
  169.     add_pop_line(REFLECT)
  170.     wait
  171.   end
  172.  
  173.   def display_substitute(substitute, target)
  174.     return unless SUB
  175.     add_pop_line(SUB)
  176.     wait
  177.   end
  178.  
  179.   def message_speed
  180.     return ACTION_SPEED
  181.   end
  182. end
  183.  
  184.  
  185. ##-----------------------------------------------------------------------------
  186. #  End of script.
  187. ##-----------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement