IceDragon200

[IEI]Gallery RAW

May 24th, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.11 KB | None | 0 0
  1. #-define HDR_TYP#=:type=>"class"
  2. #-define HDR_GNM#=:name=>"IEI - Gallery"
  3. #-define HDR_GDC#=:dc=>"05/17/2012"
  4. #-define HDR_GDM#=:dm=>"05/17/2012"
  5. #-define HDR_GAUT#=:author=>"IceDragon"
  6. #-define HDR_VER#=:version=>"1.0"
  7. #-inject gen_script_header HDR_TYP,HDR_GNM,HDR_GAUT,HDR_GDC,HDR_GDM,HDR_VER
  8. ($imported||={})["IEI::Gallery"] = 0x10000
  9. #-include C:/Lib/IEI/header/standalone_header.rb
  10. #-inject gen_module_header "IEI::Gallery"
  11. module IEI
  12.   module Gallery
  13.     # // Do not modify
  14.     class CG
  15.       class << self
  16.         alias :[] new
  17.       end
  18.       FUNC_TRUE   = proc { true }
  19.       FUNC_SWITCH = proc { switch?(@switch_id) }
  20.       attr_accessor :id, :name, :filenames, :switch_id
  21.       def initialize(id,name,filenames,switch_id=nil,&block)
  22.         @id,@name,@filenames,@switch_id = id,name,Array(filenames),switch_id
  23.         init_condition(&block)
  24.       end
  25.       def size
  26.         @filenames.size
  27.       end
  28.       def init_condition(&block)
  29.         @condition = block_given? ? block : (@switch_id ? FUNC_SWITCH : FUNC_TRUE)
  30.       end
  31.       def switch?(id)
  32.         $game_switches[id]
  33.       end
  34.       def condition_met?
  35.         instance_exec(&@condition) #rescue true
  36.       end
  37.     end
  38.     # // Edit Here
  39.     @sets = {}
  40.     def self.sets ; @sets ; end
  41.     # // CG[id,"CG-Name","filename"]
  42.     # // CG[id,"CG-Name","filename",switch_id]
  43.     # // CG[id,"CG-Name",["filename","filename","filename"],switch_id]
  44.   end
  45. end
  46. #-inject gen_class_header "IEI::Sprite::CG"
  47. class IEI::Sprite::CG < Sprite
  48.   def initialize(viewport=nil,cg=nil)
  49.     super(viewport)
  50.     self.cg = cg
  51.   end
  52.   attr_reader :cg
  53.   def cg=(new_cg)
  54.     @cg = new_cg
  55.     @index = 0
  56.     update_bitmap
  57.   end
  58.   def update_bitmap
  59.     self.bitmap = @cg ? Cache.picture(@cg.filenames[@index]) : nil
  60.   end
  61.   def update
  62.     last_index = index
  63.     super
  64.     update_handler
  65.     Sound.play_cursor if last_index != index
  66.   end
  67.   def update_handler
  68.     return unless active?
  69.     return call_handler(:next) if Input.trigger?(:DOWN) or Input.trigger?(:RIGHT)
  70.     return call_handler(:prev) if Input.trigger?(:UP) or Input.trigger?(:LEFT)
  71.     return call_handler(:ok) if Input.trigger?(:C)
  72.     return call_handler(:cancel) if Input.trigger?(:B)
  73.   end
  74.   # // Edits
  75.   def index= n
  76.     @index = n.to_i
  77.     @index %= [item_max,1].max
  78.     update_bitmap
  79.   end
  80.   def item_max
  81.     @cg ? @cg.filenames.size : 0
  82.   end
  83. #-2include C:/Lib/IEI/inc/indexing.rb
  84. #-2include C:/Lib/IEI/inc/passive_state.rb
  85. #-2include C:/Lib/IEI/inc/visibility.rb  
  86. #-2include C:/Lib/IEI/inc/basic_handler.rb
  87. end
  88. #-inject gen_class_header "IEI::Window::Gallery_Set"
  89. class IEI::Window::Gallery_Set < Window::Selectable
  90.   def initialize(x,y,w,h)
  91.     make_item_list
  92.     super
  93.     activate.select 0
  94.     refresh
  95.   end
  96.   attr_reader :cg_window
  97.   def cg_window=(window)
  98.     @cg_window = window
  99.     update_cg_window
  100.   end
  101.   def index=(n)
  102.     super(n)
  103.     update_cg_window
  104.   end
  105.   def update_cg_window
  106.     @cg_window.set = IEI::Gallery.sets[self.item] if @cg_window
  107.   end
  108.   def item(i=self.index)
  109.     @items[i]
  110.   end
  111.   def make_item_list
  112.     @items = IEI::Gallery.sets.keys.sort
  113.   end
  114.   def item_max
  115.     @items.size
  116.   end
  117.   def draw_item(index)
  118.     #rect  = item_rect(index)
  119.     trect = item_rect_for_text(index)
  120.     str   = @items[index]
  121.     draw_text(trect,str)
  122.   end
  123. end
  124. #-inject gen_class_header "IEI::Window::Gallery_CGs"
  125. class IEI::Window::Gallery_CGs < Window::Selectable
  126.   def initialize(x,y,w,h)
  127.     @set = []
  128.     make_item_list
  129.     super
  130.     select(0)
  131.     refresh
  132.   end
  133.   attr_reader :set
  134.   def set=(set)
  135.     @set = set
  136.     make_item_list
  137.     refresh
  138.   end
  139.   def cg(i=index)
  140.     @set[i]
  141.   end
  142.   def make_item_list
  143.     @items = @set.sort_by{|cg|cg.id}.collect{|cg|
  144.       [cg.filenames,cg.condition_met?]
  145.     }
  146.   end
  147.   def item_max
  148.     @items.size
  149.   end
  150.   def item_width
  151.     self.width / col_max - spacing
  152.   end
  153.   def item_height
  154.     (item_width * 0.75).to_i
  155.   end
  156.   def spacing
  157.     2
  158.   end
  159.   def col_max
  160.     4
  161.   end
  162.   BLANK_BMP = Bitmap.new(128,96)
  163.   def draw_item(index)
  164.     rect   = item_rect(index)
  165.     item_a = @items[index]
  166.     bmp_fn,valid = item_a[0].first, item_a[1]
  167.     bmp    = Cache.picture(bmp_fn) rescue BLANK_BMP
  168.     unless valid
  169.       contents.fill_rect rect, Color.new(48,48,48,128)
  170.     else
  171.       srect = Rect.fit_in bmp.rect, rect
  172.       contents.stretch_blt srect, bmp, bmp.rect
  173.     end
  174.   end
  175.   def current_item_enabled?
  176.     return false unless @items[self.index]
  177.     @items[self.index][1]
  178.   end
  179. end
  180. #-inject gen_class_header "IEI::Scene::Gallery"
  181. class IEI::Scene::Gallery < Scene::Base
  182.   # // Scene::Base
  183.   def start
  184.     super
  185.     #create_background if respond_to? :create_background
  186.     create_all_windows
  187.     create_sprites
  188.     auto_add_windows if $imported["EDOS::Data"]
  189.   end
  190.   def terminate
  191.     super
  192.     #dispose_background if respond_to? :dispose_background
  193.     @cg_sprite.dispose unless @cg_sprite
  194.   end
  195.   def update
  196.     super
  197.     #update_background if respond_to? :update_background
  198.     @cg_sprite.update
  199.   end
  200.   # // Create
  201.   def create_all_windows
  202.     create_set_window
  203.     create_cg_window
  204.   end
  205.   def create_sprites
  206.     @cg_sprite = IEI::Sprite::CG.new @viewport
  207.     @cg_sprite.set_handler :next  , method(:next_cg_image)
  208.     @cg_sprite.set_handler :prev  , method(:prev_cg_image)
  209.     @cg_sprite.set_handler :ok    , method(:end_cg_view)
  210.     @cg_sprite.set_handler :cancel, method(:end_cg_view)
  211.     @cg_sprite.hide
  212.     @cg_sprite.z = 201
  213.   end
  214.   # // Windows
  215.   def create_set_window
  216.     @set_window = IEI::Window::Gallery_Set.new(0,0,(Graphics.width*0.25).to_i,Graphics.height)
  217.     @set_window.set_handler :cancel, method(:return_scene)
  218.     @set_window.set_handler :ok    , method(:start_cg_selection)
  219.     #add_window @set_window
  220.   end
  221.   def create_cg_window
  222.     x = @set_window.x + @set_window.width
  223.     w = Graphics.width - x
  224.     h = @set_window.height
  225.     @cg_window = IEI::Window::Gallery_CGs.new(x,0,w,h)
  226.     @cg_window.set_handler :ok    , method(:start_cg_view)
  227.     @cg_window.set_handler :cancel, method(:start_set_selection)
  228.     @set_window.cg_window = @cg_window
  229.     #add_window @cg_window
  230.   end
  231.   # // Sprites
  232.   # // Nothing here but us whitespace
  233.   # // Commands
  234.   def start_set_selection
  235.     @set_window.activate
  236.   end
  237.   def start_cg_selection
  238.     @cg_window.activate
  239.   end
  240.   def end_cg_selection
  241.     @set_window.activate
  242.   end
  243.   def start_cg_view
  244.     @cg_sprite.activate.show
  245.     @cg_sprite.cg = @cg_window.cg
  246.     @cg_sprite.x = (Graphics.width - @cg_sprite.width) / 2
  247.     @cg_sprite.y = (Graphics.height - @cg_sprite.height) / 2
  248.     @cg_window.deactivate.close
  249.     @set_window.deactivate.close
  250.   end
  251.   def end_cg_view
  252.     @cg_sprite.deactivate.hide
  253.     @cg_window.activate.open
  254.     @set_window.deactivate.open
  255.   end
  256.   def next_cg_image
  257.     if @cg_sprite.index < @cg_sprite.item_max
  258.       @cg_sprite.next
  259.     else
  260.       Sound.play_buzzer  
  261.     end  
  262.   end
  263.   def prev_cg_image
  264.     if @cg_sprite.index > 0
  265.       @cg_sprite.prev
  266.     else
  267.       Sound.play_buzzer  
  268.     end  
  269.   end
  270. end
  271. Scene_Gallery = IEI::Scene::Gallery
  272. #-inject gen_script_footer
Advertisement
Add Comment
Please, Sign In to add comment