Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # ♥ IEI - Gallery
- #==============================================================================#
- # // • Created By : IceDragon
- # // • Data Created : 05/17/2012
- # // • Data Modified : 05/17/2012
- # // • Version : 1.0
- #==============================================================================#
- ($imported||={})["IEI::Gallery"] = 0x10000
- # // IEI Core Header
- ($imported||={})["IEI::Core"]||=0x01001
- unless $imported["IEI::Core"] >= 0x10000
- module IEI
- module Core
- end
- module Sprite
- end
- module Window
- end
- module Scene
- end
- end
- unless $imported["EDOS::Data"]
- module Scene
- Base = Scene_Base
- end
- class Sprite
- Base = Sprite_Base
- end
- class Window
- Base = Window_Base
- Selectable = Window_Selectable
- Command = Window_Command
- end
- end
- end
- #==============================================================================#
- # ■ IEI::Gallery
- #==============================================================================#
- module IEI
- module Gallery
- # // Do not modify
- class CG
- class << self
- alias :[] new
- end
- FUNC_TRUE = proc { true }
- FUNC_SWITCH = proc { switch?(@switch_id) }
- attr_accessor :id, :name, :filenames, :switch_id
- def initialize(id,name,filenames,switch_id=nil,&block)
- @id,@name,@filenames,@switch_id = id,name,Array(filenames),switch_id
- init_condition(&block)
- end
- def size
- @filenames.size
- end
- def init_condition(&block)
- @condition = block_given? ? block : (@switch_id ? FUNC_SWITCH : FUNC_TRUE)
- end
- def switch?(id)
- $game_switches[id]
- end
- def condition_met?
- instance_exec(&@condition) #rescue true
- end
- end
- # // Edit Here
- @sets = {}
- def self.sets ; @sets ; end
- # // CG[id,"CG-Name","filename"]
- # // CG[id,"CG-Name","filename",switch_id]
- # // CG[id,"CG-Name",["filename","filename","filename"],switch_id]
- end
- end
- #==============================================================================#
- # ♥ IEI::Sprite::CG
- #==============================================================================#
- class IEI::Sprite::CG < Sprite
- def initialize(viewport=nil,cg=nil)
- super(viewport)
- self.cg = cg
- end
- attr_reader :cg
- def cg=(new_cg)
- @cg = new_cg
- @index = 0
- update_bitmap
- end
- def update_bitmap
- self.bitmap = @cg ? Cache.picture(@cg.filenames[@index]) : nil
- end
- def update
- last_index = index
- super
- update_handler
- Sound.play_cursor if last_index != index
- end
- def update_handler
- return unless active?
- return call_handler(:next) if Input.trigger?(:DOWN) or Input.trigger?(:RIGHT)
- return call_handler(:prev) if Input.trigger?(:UP) or Input.trigger?(:LEFT)
- return call_handler(:ok) if Input.trigger?(:C)
- return call_handler(:cancel) if Input.trigger?(:B)
- end
- # // Edits
- def index= n
- @index = n.to_i
- @index %= [item_max,1].max
- update_bitmap
- end
- def item_max
- @cg ? @cg.filenames.size : 0
- end
- # // indexing
- def index
- @index ||= 0
- end unless method_defined? :index
- def index= n
- @index = n.to_i
- end unless method_defined? :index=
- def item_max
- 0
- end unless method_defined? :item_max
- def wrap_index wrap=item_max
- self.index %= wrap > 0 ? wrap : 1
- self
- end
- def select n
- self.index = n
- self
- end
- def deselect
- self.index = -1
- self
- end
- def next
- self.index += 1
- self
- end
- def prev
- self.index -= 1
- self
- end
- # // passive_state
- def active
- !!@active
- end unless method_defined? :active
- def active= state
- @active = !!state
- end unless method_defined? :active=
- alias :active? :active
- def activate
- self.active = true
- self
- end
- def deactivate
- self.active = false
- self
- end
- def toggle_active
- self.active = !self.active
- self
- end
- # // Visibility
- def visible
- !!@visible
- end unless method_defined? :visible
- def visible= n
- @visible = !!n
- end unless method_defined? :visible=
- def toggle_visible
- self.visible = !self.visible
- self
- end
- def show
- self.visible = true
- self
- end
- def hide
- self.visible = false
- self
- end
- # // basic_handler
- def handler
- @handler ||= {}
- end
- attr_writer :handler
- private :handler, :handler=
- def set_handler symbol,function
- handler[symbol] = function
- self
- end
- def rem_handler symbol
- handler.delete(symbol)
- self
- end
- def call_handler symbol
- handler[symbol].call if handler.has_key? symbol
- end
- end
- #==============================================================================#
- # ♥ IEI::Window::Gallery_Set
- #==============================================================================#
- class IEI::Window::Gallery_Set < Window::Selectable
- def initialize(x,y,w,h)
- make_item_list
- super
- activate.select 0
- refresh
- end
- attr_reader :cg_window
- def cg_window=(window)
- @cg_window = window
- update_cg_window
- end
- def index=(n)
- super(n)
- update_cg_window
- end
- def update_cg_window
- @cg_window.set = IEI::Gallery.sets[self.item] if @cg_window
- end
- def item(i=self.index)
- @items[i]
- end
- def make_item_list
- @items = IEI::Gallery.sets.keys.sort
- end
- def item_max
- @items.size
- end
- def draw_item(index)
- #rect = item_rect(index)
- trect = item_rect_for_text(index)
- str = @items[index]
- draw_text(trect,str)
- end
- end
- #==============================================================================#
- # ♥ IEI::Window::Gallery_CGs
- #==============================================================================#
- class IEI::Window::Gallery_CGs < Window::Selectable
- def initialize(x,y,w,h)
- @set = []
- make_item_list
- super
- select(0)
- refresh
- end
- attr_reader :set
- def set=(set)
- @set = set
- make_item_list
- refresh
- end
- def cg(i=index)
- @set[i]
- end
- def make_item_list
- @items = @set.sort_by{|cg|cg.id}.collect{|cg|
- [cg.filenames,cg.condition_met?]
- }
- end
- def item_max
- @items.size
- end
- def item_width
- self.width / col_max - spacing
- end
- def item_height
- (item_width * 0.75).to_i
- end
- def spacing
- 2
- end
- def col_max
- 4
- end
- BLANK_BMP = Bitmap.new(128,96)
- def draw_item(index)
- rect = item_rect(index)
- item_a = @items[index]
- bmp_fn,valid = item_a[0].first, item_a[1]
- bmp = Cache.picture(bmp_fn) rescue BLANK_BMP
- unless valid
- contents.fill_rect rect, Color.new(48,48,48,128)
- else
- srect = Rect.fit_in bmp.rect, rect
- contents.stretch_blt srect, bmp, bmp.rect
- end
- end
- def current_item_enabled?
- return false unless @items[self.index]
- @items[self.index][1]
- end
- end
- #==============================================================================#
- # ♥ IEI::Scene::Gallery
- #==============================================================================#
- class IEI::Scene::Gallery < Scene::Base
- # // Scene::Base
- def start
- super
- #create_background if respond_to? :create_background
- create_all_windows
- create_sprites
- auto_add_windows if $imported["EDOS::Data"]
- end
- def terminate
- super
- #dispose_background if respond_to? :dispose_background
- @cg_sprite.dispose unless @cg_sprite
- end
- def update
- super
- #update_background if respond_to? :update_background
- @cg_sprite.update
- end
- # // Create
- def create_all_windows
- create_set_window
- create_cg_window
- end
- def create_sprites
- @cg_sprite = IEI::Sprite::CG.new @viewport
- @cg_sprite.set_handler :next , method(:next_cg_image)
- @cg_sprite.set_handler :prev , method(:prev_cg_image)
- @cg_sprite.set_handler :ok , method(:end_cg_view)
- @cg_sprite.set_handler :cancel, method(:end_cg_view)
- @cg_sprite.hide
- @cg_sprite.z = 201
- end
- # // Windows
- def create_set_window
- @set_window = IEI::Window::Gallery_Set.new(0,0,(Graphics.width*0.25).to_i,Graphics.height)
- @set_window.set_handler :cancel, method(:return_scene)
- @set_window.set_handler :ok , method(:start_cg_selection)
- #add_window @set_window
- end
- def create_cg_window
- x = @set_window.x + @set_window.width
- w = Graphics.width - x
- h = @set_window.height
- @cg_window = IEI::Window::Gallery_CGs.new(x,0,w,h)
- @cg_window.set_handler :ok , method(:start_cg_view)
- @cg_window.set_handler :cancel, method(:start_set_selection)
- @set_window.cg_window = @cg_window
- #add_window @cg_window
- end
- # // Sprites
- # // Nothing here but us whitespace
- # // Commands
- def start_set_selection
- @set_window.activate
- end
- def start_cg_selection
- @cg_window.activate
- end
- def end_cg_selection
- @set_window.activate
- end
- def start_cg_view
- @cg_sprite.activate.show
- @cg_sprite.cg = @cg_window.cg
- @cg_sprite.x = (Graphics.width - @cg_sprite.width) / 2
- @cg_sprite.y = (Graphics.height - @cg_sprite.height) / 2
- @cg_window.deactivate.close
- @set_window.deactivate.close
- end
- def end_cg_view
- @cg_sprite.deactivate.hide
- @cg_window.activate.open
- @set_window.deactivate.open
- end
- def next_cg_image
- if @cg_sprite.index < @cg_sprite.item_max
- @cg_sprite.next
- else
- Sound.play_buzzer
- end
- end
- def prev_cg_image
- if @cg_sprite.index > 0
- @cg_sprite.prev
- else
- Sound.play_buzzer
- end
- end
- end
- Scene_Gallery = IEI::Scene::Gallery
- #==============================================================================#
- # EOF
- #==============================================================================#
Advertisement
Add Comment
Please, Sign In to add comment