IceDragon200

IRS-Core (WIP)

Jun 2nd, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.42 KB | None | 0 0
  1. # // Last Modified :06/08/2011
  2. #==============================================================================#
  3. $imported = {} if $imported == nil
  4. $imported["IRS-Core"] = true
  5.  
  6. #==============================================================================#
  7. # IRS
  8. #==============================================================================#
  9. module IRS ; end
  10. unless $imported["ICY_Bitmap_Xtended"]
  11.   raise %Q(
  12. IRS-Core Error
  13.   ICY - BitmapExtended (ICY_Bitmap_Xtended)
  14.   Was not found, or has not been installed above the IRS-Core script
  15.   Please ensure that the script is installed correctly before proceeding.
  16.   Your game will now close.
  17.   )
  18.   exit()
  19. end  
  20.  
  21. #==============================================================================#
  22. # Vocab
  23. #==============================================================================#
  24. module Vocab  
  25.   def self.location() ; return "Location" end
  26. end  
  27.  
  28. #==============================================================================#
  29. # Game_System
  30. #==============================================================================#
  31. class Game_System
  32.  
  33.   #--------------------------------------------------------------------------#
  34.   # * Public Instance Variables
  35.   #--------------------------------------------------------------------------#  
  36.   attr_accessor :last_location_name
  37.  
  38.   #--------------------------------------------------------------------------#
  39.   # * alias method :initialize
  40.   #--------------------------------------------------------------------------#
  41.   alias :irs000_gsys_initialize :initialize unless $@
  42.   def initialize()
  43.     irs000_gsys_initialize()
  44.     @last_location_name = ""
  45.   end
  46.  
  47. end  
  48.  
  49. #==============================================================================#
  50. # Game_Map
  51. #==============================================================================#
  52. class Game_Map
  53.  
  54.   #--------------------------------------------------------------------------#
  55.   # * new method :name
  56.   #--------------------------------------------------------------------------#  
  57.   def name( map_id=@map_id )
  58.     load_map_infos() if @map_infos.nil?()
  59.     return @map_infos[map_id].name
  60.   end
  61.  
  62.   #--------------------------------------------------------------------------#
  63.   # * new method :load_map_infos
  64.   #--------------------------------------------------------------------------#  
  65.   def load_map_infos()
  66.     @map_infos = load_data( "Data/MapInfos.rvdata" )
  67.   end
  68.  
  69.   #--------------------------------------------------------------------------#
  70.   # * alias method :initialize
  71.   #--------------------------------------------------------------------------#
  72.   alias :irs000_gmap_setup :setup unless $@
  73.   def setup( map_id )
  74.     irs000_gmap_setup( map_id )
  75.     $game_system.last_location_name = name()
  76.   end
  77.  
  78. end
  79.  
  80. #==============================================================================#
  81. # IRS::Sprite_Core
  82. #==============================================================================#  
  83. class IRS::Sprite_Core < ::Sprite  
  84.  
  85.   #--------------------------------------------------------------------------#
  86.   # * Constants
  87.   #--------------------------------------------------------------------------#
  88.   WLH = 24
  89.   BACKGROUND_COLOR = Color.new( 0, 0, 0 )
  90.  
  91.   #--------------------------------------------------------------------------#
  92.   # * super method :initialize
  93.   #--------------------------------------------------------------------------#  
  94.   def initialize( x, y, width, height, viewport=nil )
  95.     super( viewport )
  96.     self.x = x ; self.y = y
  97.     self.bitmap = Bitmap.new( width, height )
  98.     draw_background()
  99.     refresh()
  100.   end
  101.  
  102.   #--------------------------------------------------------------------------#
  103.   # * new method :bwidth
  104.   #--------------------------------------------------------------------------#  
  105.   def bwidth()
  106.     return self.bitmap.width
  107.   end
  108.  
  109.   #--------------------------------------------------------------------------#
  110.   # * new method :bheight
  111.   #--------------------------------------------------------------------------#  
  112.   def bheight()
  113.     return self.bitmap.height
  114.   end
  115.  
  116.   #--------------------------------------------------------------------------#
  117.   # * new method :refresh
  118.   #--------------------------------------------------------------------------#  
  119.   def refresh()
  120.   end
  121.  
  122.   #--------------------------------------------------------------------------#
  123.   # * new method :draw_background
  124.   #--------------------------------------------------------------------------#  
  125.   def draw_background()
  126.     width, height = self.bitmap.width, self.bitmap.height
  127.     self.bitmap.fill_rect( 0, 0, width, height, BACKGROUND_COLOR )
  128.   end  
  129.  
  130.   #--------------------------------------------------------------------------#
  131.   # * new method :resize
  132.   #--------------------------------------------------------------------------#  
  133.   def resize( new_width, new_height )
  134.     old_bitmap = self.bitmap
  135.     self.bitmap = Bitmap.new( new_width, new_height )
  136.     unless old_bitmap.nil?()
  137.       self.bitmap.blt( 0, 0, old_bitmap, self.bitmap.rect )
  138.       old_bitmap.dispose()
  139.     end  
  140.   end
  141.      
  142.   #--------------------------------------------------------------------------#
  143.   # * new method :draw_currency_value
  144.   #--------------------------------------------------------------------------#
  145.   def draw_currency_value( value, x, y, width )
  146.     cx = bitmap.text_size( ::Vocab::gold ).width
  147.     self.bitmap.font.color = normal_color
  148.     self.bitmap.font.size  = Font.default_size - 2
  149.     self.bitmap.draw_text( x, y, width-cx-2, WLH, value, 2 )
  150.     self.bitmap.font.size  = Font.default_size
  151.     self.bitmap.font.color = system_color
  152.     self.bitmap.draw_text( x, y, width, WLH, ::Vocab::gold, 2 )
  153.   end
  154.  
  155.   #--------------------------------------------------------------------------#
  156.   # * new method :draw_face
  157.   #--------------------------------------------------------------------------#
  158.   def draw_face( face_name, face_index, x, y, wsize = 96, hsize = 96 )
  159.     bitmap = Cache.face(face_name)
  160.     rect = Rect.new( 0, 0, 0, 0 )
  161.     rect.x = face_index % 4 * 96 + (96 - wsize) / 2
  162.     rect.y = face_index / 4 * 96 + (96 - hsize) / 2
  163.     rect.width = wsize
  164.     rect.height = hsize
  165.     self.bitmap.blt(x, y, bitmap, rect)
  166.     bitmap.dispose
  167.   end
  168.  
  169.   #--------------------------------------------------------------------------#
  170.   # * new method :draw_actor_face
  171.   #--------------------------------------------------------------------------#  
  172.   def draw_actor_face( actor, x, y, wsize = 96, hsize = 96 )
  173.     draw_face( actor.face_name, actor.face_index, x, y, wsize, hsize )
  174.   end
  175.  
  176. end  
  177. #==============================================================================#
  178. # IRS::Sprite_Help
  179. #==============================================================================#
  180. class IRS::Sprite_Help < ::IRS::Sprite_Core
  181.    
  182.   #--------------------------------------------------------------------------#
  183.   # * Public Instance Variables
  184.   #--------------------------------------------------------------------------#
  185.   attr_accessor :text
  186.   attr_accessor :align
  187.  
  188.   #--------------------------------------------------------------------------#
  189.   # * super method :initialize
  190.   #--------------------------------------------------------------------------#  
  191.   def initialize( *args )
  192.     @text  = -1
  193.     @align = 0
  194.     super( *args )
  195.   end
  196.  
  197.   #--------------------------------------------------------------------------#
  198.   # * new method :set_obj
  199.   #--------------------------------------------------------------------------#  
  200.   def set_obj( text, enabled=true )
  201.     return 0 if @text == text
  202.     self.bitmap.clear()
  203.     rect = Rect.new( 4, 4, self.bitmap.width-16, ::Window_Base::WLH )
  204.     draw_background()
  205.     self.bitmap.draw_text( rect, text, @align )
  206.     @text = text
  207.   end
  208.  
  209.   #--------------------------------------------------------------------------#
  210.   # * new method :set_text
  211.   #--------------------------------------------------------------------------#  
  212.   def set_text( text, enabled=true ) ; set_obj( text, enabled ) end
  213.  
  214. end
  215.  
  216. #==============================================================================#
  217. # IRS::Sprite_Gold
  218. #==============================================================================#
  219. class IRS::Sprite_Gold < ::IRS::Sprite_Help
  220.  
  221.   #--------------------------------------------------------------------------#
  222.   # * new method :refresh
  223.   #--------------------------------------------------------------------------#  
  224.   def refresh()
  225.     draw_currency_value( $game_party.gold, 4, 0, 120 )
  226.   end
  227.  
  228. end  
  229.  
  230. #==============================================================================#
  231. # IRS::Sprite_Location
  232. #==============================================================================#
  233. class IRS::Sprite_Location < ::IRS::Sprite_Help
  234.  
  235.   #--------------------------------------------------------------------------#
  236.   # * new method :refresh
  237.   #--------------------------------------------------------------------------#  
  238.   def refresh()
  239.     self.bitmap.font.size = Font.default_size - 2
  240.     self.bitmap.font.color = system_color
  241.     rect = Rect.new( 64,  12, self.bitmap.width, WLH )
  242.     self.bitmap.draw_text( rect, $game_map.name )
  243.     self.bitmap.font.size = Font.default_size - 4
  244.     self.bitmap.font.color = normal_color
  245.     rect = Rect.new(  4,  0, self.bitmap.width, WLH )
  246.     self.bitmap.draw_text( rect, Vocab.location )
  247.   end
  248.  
  249. end
  250.  
  251. #==============================================================================#
  252. # IRS::Sprite_FaceTab
  253. #==============================================================================#
  254. class IRS::Sprite_FaceTab < ::IRS::Sprite_Core
  255.  
  256.   #--------------------------------------------------------------------------#
  257.   # * super method :initialize
  258.   #--------------------------------------------------------------------------#  
  259.   def initialize( actor, *args )
  260.     @actor = actor
  261.     super( *args )
  262.   end
  263.  
  264.   #--------------------------------------------------------------------------#
  265.   # * new method :refresh
  266.   #--------------------------------------------------------------------------#  
  267.   def refresh()
  268.     draw_actor_face( @actor, 2, 2, [self.width-4, 96].min, [self.height, 96].min )
  269.   end
  270.  
  271. end
  272. #=*==========================================================================*=#
  273. # ** END OF FILE
  274. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment