Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # [XP] Drago Save Layout
- # Version: 1.05
- # Author : LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- ($imported ||= {})[:drg_save_layout] = 1.05
- #==============================================================================
- # ** Drago_DataModule
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- core = "This script needs Drago - Core Engine ver 1.58 or above"
- ($imported[:drg_core_engine] || 0) >= 1.58 || raise(core)
- module Drago_DataModule
- #--------------------------------------------------------------------------
- # * Constant
- #--------------------------------------------------------------------------
- FOLDERSAVE = "Saves/" # Folder which save data is saved.
- SAVENAME = "Save%d.rxdata" # Filename of the save data.
- MAXSAVES = 20 # Max save data that can be saved and load.
- FASTCURSOR = false # Toggle the button to fast cursor selection.
- # Edit if want to use background, else the script will use moving image.
- # Example: "Graphics/Pictures/Background.png"
- # Type "MAP" if you want to use map screenshot as background.
- BACKGROUND = nil
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_sec_accessor :scene_update, 'Array.new'
- #--------------------------------------------------------------------------
- # * Main Processing
- #--------------------------------------------------------------------------
- def main
- start
- post_start
- Graphics.transition
- scene_update.update while $scene == self
- Graphics.freeze
- all_variable_dispose
- end
- #--------------------------------------------------------------------------
- # * Start
- #--------------------------------------------------------------------------
- def start
- create_background
- create_plane
- create_font_sprite
- create_screenshot_sprite
- create_window_save
- end
- #--------------------------------------------------------------------------
- # * Create Background
- #--------------------------------------------------------------------------
- def create_background
- preview_scene = $game_temp.instance_variable_get(:@preview_bitmap)
- @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @background_sprite = Sprite.new(@viewport)
- @background_sprite.bitmap =
- if preview_scene.is_a?(Bitmap) && preview_scene.not.disposed?
- preview_scene
- else
- Graphics.snap_to_bitmap
- end
- @background_sprite.color.set(16, 16, 16, 128)
- end
- #--------------------------------------------------------------------------
- # * Create Plane
- #--------------------------------------------------------------------------
- def create_plane
- @plane_sprite = Plane.new(@viewport)
- if BACKGROUND
- bitmap = Bitmap.new(BACKGROUND) rescue LiTTleDRAgo.cache.empty_bitmap
- @plane_sprite.bitmap = bitmap.clone
- @plane_sprite.opacity = 255
- else
- bitmap = LiTTleDRAgo.cache.transitions('015-Diamond01') rescue
- LiTTleDRAgo.cache.empty_bitmap
- @plane_sprite.bitmap = Bitmap.new(bitmap.width,bitmap.height*2)
- @plane_sprite.bitmap.blt(0,0,bitmap,bitmap.rect)
- bitmap.flip_vertical!
- @plane_sprite.bitmap.blt(0,bitmap.height,bitmap,bitmap.rect)
- @plane_sprite.opacity = not_scene_title? ? 50 : 255
- end
- bitmap.dispose
- end
- #--------------------------------------------------------------------------
- # * Create Font Sprite
- #--------------------------------------------------------------------------
- def create_font_sprite
- font = ['Georgia','Arial']
- font += [Font.default_name]
- @font_sprite = Sprite.new
- @font_sprite.z = @plane_sprite.z + 1
- @font_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
- @font_sprite.bitmap.font.name = font.flatten
- @font_sprite.bitmap.font.size = 42
- @font_sprite.bitmap.font.italic = true
- @font_sprite.bitmap.draw_edging_text(0,32,Graphics.width,36,"SaveData",2)
- end
- #--------------------------------------------------------------------------
- # * Create Screenshot Sprite
- #--------------------------------------------------------------------------
- def create_screenshot_sprite
- @current_bitmap = @background_sprite.bitmap.stretch(
- Graphics.width / 2, Graphics.height / 2)
- font = ['Monotype Corsiva','Arial','Times New Roman']
- font += [Font.default_name]
- @screenshot_sprite = Sprite.new
- @screenshot_sprite.bitmap = Bitmap.new(Graphics.width/2, Graphics.height/2)
- @screenshot_sprite.bitmap.font.name = font.flatten
- @screenshot_sprite.bitmap.font.size = 16
- @screenshot_sprite.bitmap.font.italic = true
- @screenshot_sprite.bitmap.full_fill(Color.black)
- @screenshot_sprite.x = (Graphics.width - @screenshot_sprite.width) - 32
- @screenshot_sprite.y = (Graphics.height - @screenshot_sprite.height) - 32
- @screenshot_sprite.z = @font_sprite.z
- end
- #--------------------------------------------------------------------------
- # * Create Window Save
- #--------------------------------------------------------------------------
- def create_window_save
- @window_save = Window_CStream.new(create_command(MAXSAVES),20,0)
- @window_save.set_handler(:ok, method(:command_ok) )
- @window_save.set_handler(:cancel, method(:command_cancel) )
- end
- #--------------------------------------------------------------------------
- # * Post Start
- #--------------------------------------------------------------------------
- def post_start
- rect = Rect.new(0,26, Graphics.width, 5)
- scene_update.replace([Graphics,Input,self])
- @font_sprite.bitmap.fill_rect(rect,Color.white)
- Dir.make_dir(FOLDERSAVE) unless FileTest.directory?(FOLDERSAVE)
- @notesavedata = NoteSaveData.new
- end
- #--------------------------------------------------------------------------
- # * Create Command
- #--------------------------------------------------------------------------
- def create_command(size)
- command = []
- size.times do |i|
- if (exist = FileTest.exist?(filename = make_filename(i)))
- content = read_content(filename)
- text = content[:game_system].instance_variable_get(:@notesavedata)
- else
- text = "---------------No Data---------------"
- end
- savedata = {}
- savedata[:name] = "\\}File #{i+1}: #{text}"
- savedata[:condition] = exist if self.is_a?(Scene_Load)
- command.push(savedata)
- end
- command
- end
- #--------------------------------------------------------------------------
- # * Make File Name
- # file_index : save file index (0-3)
- #--------------------------------------------------------------------------
- def make_filename(file_index)
- name = FOLDERSAVE + '/' + sprintf(SAVENAME,file_index)
- name = name.gsub("\\","/").gsub("//","/")
- return name
- end
- #--------------------------------------------------------------------------
- # * Make Preview Bitmap Name
- # file_index : save file index (0-3)
- #--------------------------------------------------------------------------
- def preview_bitmap_name(file_index)
- #filename = LiTTleDRAgo::APPPATHDRAGO + make_filename(file_index)
- filename = make_filename(file_index)
- dirname = File.dirname(filename)
- Dir.make_dir(dirname) unless FileTest.directory?(dirname)
- name = dirname + '/' + File.basename(filename) + '.png'
- name = name.gsub("\\","/").gsub("//","/").sub('.rxdata','')
- return name
- end
- #--------------------------------------------------------------------------
- # * Read Save Data
- # file : file object for reading (opened)
- #--------------------------------------------------------------------------
- def read_content(filename)
- content = (c = {})
- file = File.open(filename, "r")
- begin
- content[:time_stamp] = file.mtime
- content[:characters] = Marshal.load(file)
- content[:frame_count] = Marshal.load(file)
- content[:game_system] = Marshal.load(file)
- content[:game_switches] = Marshal.load(file)
- content[:game_variables] = Marshal.load(file)
- content[:game_self_switches] = Marshal.load(file)
- content[:game_screen] = Marshal.load(file)
- content[:game_actors] = Marshal.load(file)
- content[:game_party] = Marshal.load(file)
- content[:game_troop] = Marshal.load(file)
- content[:game_map] = Marshal.load(file)
- content[:game_player] = Marshal.load(file)
- c[:total_sec] = c[:frame_count] / Graphics.frame_rate
- c[:hour] = c[:total_sec] / 60 / 60
- c[:min] = c[:total_sec] / 60 % 60
- c[:sec] = c[:total_sec] % 60
- c[:time_string] = sprintf("%02d:%02d:%02d", c[:hour], c[:min], c[:sec])
- c[:date_string] = c[:time_stamp].strftime("%Y/%m/%d %H:%M")
- file.close
- rescue
- file.close
- Graphics.transition
- dprint("File #{File.basename(filename)} is corrupt!")
- FileTest.exist?(filename) && File.delete(filename)
- content[:game_system].instance_variable_set(:@notesavedata,"File Deleted")
- end
- return content
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- update_window_save
- update_screenshot_sprite
- update_plane
- end
- #--------------------------------------------------------------------------
- # * Update Plane
- #--------------------------------------------------------------------------
- def update_plane
- unless BACKGROUND
- @plane_sprite.ox += 1
- @plane_sprite.oy += 1
- end
- end
- #--------------------------------------------------------------------------
- # * Update Window Save
- #--------------------------------------------------------------------------
- def update_window_save
- @window_save.update
- end
- #--------------------------------------------------------------------------
- # * Update Screenshot Sprite
- #--------------------------------------------------------------------------
- def update_screenshot_sprite
- return if @old_index == @window_save.index
- @old_index = @window_save.index
- filename = make_filename(@old_index)
- if FileTest.exist?(filename)
- content = read_content(filename)
- system = content[:game_system]
- if FileTest.exist?(bitmap = preview_bitmap_name(@old_index))
- temp = (s = @screenshot_sprite.bitmap) && Bitmap.new(bitmap)
- rect = Rect.new(4,4,s.width-8,s.height-8)
- s.stretch_blt(rect,temp,temp.rect)
- temp.dispose
- else
- s = @screenshot_sprite.bitmap
- fontsize = s.font.size
- if (preview = system.instance_variable_get(:@preview_save))
- s.font.size = ((s.full_fill(Color.black) || 0) && 32)
- s.draw_edging_text(0,s.height/2-16,s.width,32,'Loading...',1)
- Graphics.wait(5)
- temp = BitmapDump.read_bitmap_data(*preview)
- temp.export(preview_bitmap_name(@old_index))
- rect = Rect.new(4,4,s.width-8,s.height-8)
- s.stretch_blt(rect,temp,temp.rect)
- temp.dispose
- else
- s.font.size = ((s.full_fill(Color.black) || 0) && 32)
- s.draw_edging_text(0,s.height/2-16,s.width,32,'No Preview',1)
- end
- s.font.size = fontsize
- end
- time = "#{content[:time_string]} #{content[:date_string]}"
- if system.respond_to?(:chapter_name)
- text = system.chapter_name
- s.draw_edging_text(0-4,s.height-32,s.width,32,"#{text}",2)
- s.draw_edging_text(0-4,s.height-64,s.width,32,"#{time}",2)
- else
- s.draw_edging_text(0-4,s.height-32,s.width,32,"#{time}",2)
- end
- else
- delete_savedata(@old_index)
- @screenshot_sprite.bitmap.full_fill(Color.black)
- end
- end
- #--------------------------------------------------------------------------
- # * Not in Scene_Title?
- #--------------------------------------------------------------------------
- def not_scene_title?
- $game_system.is_a?(Game_System) && $game_system.magic_number != 0
- end
- #--------------------------------------------------------------------------
- # * Decision Processing
- #--------------------------------------------------------------------------
- def command_ok
- command = confirm_saveload(0)
- execute_choice(command)
- end
- #--------------------------------------------------------------------------
- # * Execute Choice
- #--------------------------------------------------------------------------
- def execute_choice(command)
- index = @window_save.index
- filename = make_filename(index)
- if [:save,:overwrite].include?(command.result[:symbol])
- if command.result[:symbol] == :overwrite
- proceed = confirm_saveload(2)
- if proceed.result[:symbol] == :cancel
- Sound.play_cancel
- return @window_save.activate
- end
- end
- @notesavedata.show_window
- @current_bitmap.export(preview_bitmap_name(index))
- preview_data = BitmapDump.bitmap_data(@current_bitmap)
- $game_system.instance_variable_set(:@preview_save,preview_data)
- Audio.se_stop
- on_decision(filename)
- elsif command.result[:symbol] == :load
- Audio.se_stop
- on_decision(filename) rescue Sound.play_buzzer
- @window_save.activate unless $scene.is_a?(Scene_Map)
- elsif command.result[:symbol] == :delete
- proceed = confirm_saveload(2)
- if proceed.result[:symbol] == :proceed
- delete_savedata((@old_index = index + 100) - 100)
- @window_save.dispose
- create_window_save
- elsif proceed.result[:symbol] == :cancel
- Sound.play_cancel
- @window_save.activate
- end
- elsif command.result[:symbol] == :cancel
- Sound.play_cancel
- @window_save.activate
- end
- end
- #--------------------------------------------------------------------------
- # * Confirm SaveLoad
- #--------------------------------------------------------------------------
- def confirm_saveload(type=0)
- index = @window_save.index
- exist = FileTest.exist?(filename = make_filename(index))
- if type == 0
- choice = exist ? '\\}Overwrite' : '\\}Save Game'
- delete = '\\}Delete Save'
- cancel = '\\}Cancel Save'
- symbol = exist ? :overwrite : :save
- elsif type == 1
- choice = '\\}Load Game'
- delete = '\\}Delete Save'
- cancel = '\\}Cancel Load'
- symbol = :load
- else
- choice = '\\}Proceed'
- cancel = '\\}Cancel'
- symbol = :proceed
- end
- command = [{:name => choice, :symbol => symbol}]
- if exist && [0,1].include?(type)
- command << {:name => delete, :symbol => :delete}
- end
- command << {:name => cancel, :symbol => :cancel}
- command = Window_CStream.new(command,
- Graphics.width/2-30, Graphics.height/2-30)
- command.set_handler(:ok, carrot {})
- command.set_handler(:cancel, carrot { command.result[:symbol] = :cancel })
- command.x_off = 0
- command.x = Graphics.width/2 - command.width / 2
- command.y = Graphics.height/2 - command.height * command.item_max
- while command.active
- [command,Graphics,Input].update
- @window_save.process_cursor_rect
- update_plane
- end
- command.dispose
- command
- end
- #--------------------------------------------------------------------------
- # * Delete SaveData
- #--------------------------------------------------------------------------
- def delete_savedata(index)
- filename = make_filename(index)
- preview = preview_bitmap_name(index)
- FileTest.exist?(filename) && File.delete(filename) rescue nil
- FileTest.exist?(preview) && File.delete(preview) rescue nil
- end
- #--------------------------------------------------------------------------
- # * Cancel Processing
- #--------------------------------------------------------------------------
- def command_cancel
- on_cancel
- end
- end
- Scene_Save.send(:include, Drago_DataModule)
- Scene_Load.send(:include, Drago_DataModule)
- #==============================================================================
- # ** Scene_Load
- #------------------------------------------------------------------------------
- # This class performs load screen processing.
- #==============================================================================
- class Scene_Load
- #--------------------------------------------------------------------------
- # * Create Font Sprite
- #--------------------------------------------------------------------------
- define_post_alias(:create_font_sprite) do
- @font_sprite.bitmap.clear
- @font_sprite.bitmap.draw_edging_text(0,32,Graphics.width,36,"LoadData",2)
- end
- #--------------------------------------------------------------------------
- # * Decision Processing
- #--------------------------------------------------------------------------
- def command_ok
- command = confirm_saveload(1)
- execute_choice(command)
- end
- #--------------------------------------------------------------------------
- # * Cancel Processing
- #--------------------------------------------------------------------------
- def command_cancel
- if not_scene_title?
- $scene = Scene_Map.new
- else
- $scene = Scene_Title.new
- end
- end
- end
- #==============================================================================
- # ** Scene_Title
- #------------------------------------------------------------------------------
- # This class performs title screen processing.
- #==============================================================================
- class Scene_Title
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- define_pre_alias(:update) do
- if @command_window.not.nil? && !@drg_save_checker
- @drg_save_checker = true
- @continue_enabled = false
- load = Scene_Load.new
- Drago_DataModule::MAXSAVES.times do |i|
- @continue_enabled = true if FileTest.exist?(load.make_filename(i))
- end
- if @continue_enabled
- @command_window.index = 1
- @command_window.draw_item(1, @command_window.normal_color)
- else
- @command_window.index = 0
- @command_window.disable_item(1)
- end
- end
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # This class performs map screen processing.
- #==============================================================================
- class Scene_Map
- #--------------------------------------------------------------------------
- # * Main Processing
- #--------------------------------------------------------------------------
- define_pre_alias(:main) { dispose_preview_bitmap }
- define_post_alias(:main) do
- unless $scene.is_a?(Scene_Title)
- dispose_preview_bitmap
- $game_temp.instance_variable_set(:@preview_bitmap,
- LiTTleDRAgo.snap_to_bitmap)
- end
- end
- #--------------------------------------------------------------------------
- # * Dispose Preview Bitmap
- #--------------------------------------------------------------------------
- def dispose_preview_bitmap
- bitmap = $game_temp.instance_variable_get(:@preview_bitmap)
- bitmap.dispose if bitmap.is_a?(Bitmap) && bitmap.not.disposed?
- end
- end
- #==============================================================================
- # ** NoteSaveData
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- class NoteSaveData
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- @main = LiTTleDRAgo.hwnd
- @create_window = Win32API.new('user32','CreateWindowEx','lpplllllllll','l')
- @show_window = Win32API.new('user32','ShowWindow',%w(l l),'l')
- @destroy_window = Win32API.new('user32','DestroyWindow','p','l')
- @metrics = LiTTleDRAgo.systemmetrix
- @window_text = Win32API.new('user32','GetWindowText',%w(n p n ),'l')
- @setwindowpos = Win32API.new('user32','SetWindowPos', 'LLIIIII', 'I')
- @window_rect = Win32API.new('user32','GetWindowRect',%w(l p),'i')
- @update_window = Win32API.new('user32','UpdateWindow','p','i')
- @input = Win32API.new('user32','GetAsyncKeyState','i','i')
- end
- #--------------------------------------------------------------------------
- # * Destroy Window
- #--------------------------------------------------------------------------
- def destroy_window
- @destroy_window.call(@note_window)
- @note_window = nil
- end
- #--------------------------------------------------------------------------
- # * Show Window
- #--------------------------------------------------------------------------
- def show_window
- return if @note_window != nil
- @sprite_help = s = Sprite.new
- s.bitmap = Bitmap.new((g = Graphics).width,g.height)
- s.bitmap.font.name = ['Georgia',Font.default_name].flatten
- s.opacity = (s.z += 9999) * 0
- s.bitmap.draw_edging_text(0,0-32,g.width,g.height,"Enter notes here.",1)
- (s.opacity += 10) && Graphics.update until s.opacity >= 255
- calculate_window_pos
- @note_window = @create_window.call(768, 'Edit', '',
- 0x86000000, @x, @y, Graphics.width / 2, 22, @main, 0, 0, 0)
- @show_window.call(@note_window, 1)
- start_script_update
- end
- #--------------------------------------------------------------------------
- # * Calculate Window Pos
- #--------------------------------------------------------------------------
- def calculate_window_pos
- @window_rect.call(@main, (rect = '0'*16))
- left, top, right, bottom = rect.unpack("LLLL")
- @x = left + (me5 = @metrics.call(5)) + (me45 = @metrics.call(45))
- @y = top + (me6 = @metrics.call(6)) + (me46 = @metrics.call(46))
- @x = (@x + (Graphics.width / 4))
- @y = (@y + (Graphics.height / 2))
- end
- #--------------------------------------------------------------------------
- # * Start Script Update
- #--------------------------------------------------------------------------
- def start_script_update
- @count = 0
- until @input.call(0x0D) & 0x01 == 1 && @count > 10 do
- Graphics.update
- @update_window.call(@note_window)
- @count += 1
- if @count % 5 == 0
- calculate_window_pos
- @setwindowpos.call(@note_window, 0, @x, @y, Graphics.width / 2, 22,0)
- end
- end
- @window_text.call(@note_window, (text = "\0" * 256), 0x3E80)
- $game_system.instance_variable_set(:@notesavedata, text.gsub("\0", ""))
- until @sprite_help.opacity <= 0
- Graphics.update
- @sprite_help.opacity -= 10
- end
- @sprite_help.bitmap.dispose
- @sprite_help.dispose
- destroy_window
- end
- end
- #==============================================================================
- # ** Window_CStream
- #------------------------------------------------------------------------------
- #
- #==============================================================================
- class Window_CStream
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_sec_reader :commands, :window_commands, 'Array.new'
- attr_sec_reader :handler, 'Hash.new'
- attr_sec_reader :index, :width, :height, 0
- attr_sec_reader :disabled_item, 'Array.new'
- attr_sec_accessor :scroll_index, 0
- attr_sec_accessor :x, :y, 0
- attr_sec_accessor :x_off, 30
- attr_accessor :active, :visible
- #--------------------------------------------------------------------------
- # *
- #--------------------------------------------------------------------------
- define_method(:item_max) { commands.size }
- define_method(:result) { commands[index] }
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(commands, x = 0,y = 0)
- @x, @y = x, y
- change_commands(commands)
- activate
- show
- end
- #--------------------------------------------------------------------------
- # * Add Command
- #--------------------------------------------------------------------------
- def add_command(command)
- commands.push(command)
- change_commands(commands)
- end
- #--------------------------------------------------------------------------
- # * Change Existing Commands
- #--------------------------------------------------------------------------
- def change_commands(commands)
- @commands = commands
- refresh(true)
- end
- #--------------------------------------------------------------------------
- # * Activate Window
- #--------------------------------------------------------------------------
- def activate
- window_commands.activate
- self.active = true
- self
- end
- #--------------------------------------------------------------------------
- # * Deactivate Window
- #--------------------------------------------------------------------------
- def deactivate
- window_commands.deactivate
- self.active = false
- self
- end
- #--------------------------------------------------------------------------
- # * Show Window
- #--------------------------------------------------------------------------
- def show
- window_commands.show
- self.visible = true
- self
- end
- #--------------------------------------------------------------------------
- # * Hide Window
- #--------------------------------------------------------------------------
- def hide
- window_commands.hide
- self.visible = false
- self
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh(create = false)
- clear_window
- @width = 0
- @height = 0
- @drawed = []
- create && (@index = 0)
- commands.each_with_index do |c,i|
- @window_commands[i] = s = Window_Help.new
- s.draw_text_ex(4,0,c[:name])
- @width = @width.clamp(s.text_size(c[:name]).width+32, Graphics.width)
- @height = s.contents.height
- end
- window_commands.each_with_index do |s,i|
- if create
- s.x, s.y = @x, @y
- else
- process_position_x(s,i,true)
- process_position_y(s,i,true)
- end
- s.width = @width
- s.contents.dispose
- s.contents = Bitmap.new(s.width - 32, @height)
- s.opacity = i == 0 ? 255 : 0
- if i == 0
- s.draw_text_ex(4,0,commands[i][:name])
- s.z += 10
- else
- s.z = window_commands[i-1].z - 1
- end
- condition = commands[i][:condition]
- unless condition.nil?
- condition_met = condition.is_a?(String) ? eval(condition) : condition
- unless condition_met
- disabled_item.push(i)
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Dispose
- #--------------------------------------------------------------------------
- def dispose
- clear_window
- end
- #--------------------------------------------------------------------------
- # * Clear All Window
- #--------------------------------------------------------------------------
- def clear_window
- window_commands.dispose
- window_commands.clear
- disabled_item.clear
- end
- #--------------------------------------------------------------------------
- # * Get Number of Rows Displayable on 1 Page
- #--------------------------------------------------------------------------
- def page_row_max
- # Subtract a frame height of 32 from the window height, and divide it by
- # 1 row height of 32
- return 0 if item_max == 0
- Graphics.height / window_commands[0].height
- end
- #--------------------------------------------------------------------------
- # * Select Item
- #--------------------------------------------------------------------------
- def select(index)
- return unless index
- if (@index = index) < page_row_max
- @scroll_index = 0
- else
- limit = [page_row_max/2,0].max
- @scroll_index = [@scroll_index.clamp(index,index-limit),
- item_max-page_row_max].min
- end
- end
- #--------------------------------------------------------------------------
- # * Move Cursor Down
- #--------------------------------------------------------------------------
- def cursor_down(wrap = false)
- if index < (item_max - 1) || (wrap)
- select((index + 1) % item_max)
- end
- end
- #--------------------------------------------------------------------------
- # * Move Cursor Up
- #--------------------------------------------------------------------------
- def cursor_up(wrap = false)
- if index >= 1 || (wrap)
- select((index - 1) % item_max)
- end
- end
- #--------------------------------------------------------------------------
- # * Scroll Cursor Down
- #--------------------------------------------------------------------------
- def scroll_down
- @scroll_index = ((scroll_index + 1) % item_max)
- end
- #--------------------------------------------------------------------------
- # * Scroll Cursor Up
- #--------------------------------------------------------------------------
- def scroll_up
- @scroll_index = ((scroll_index - 1) % item_max)
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- if mouse_in_position?
- process_mouse_move
- process_mouse_scroll
- process_mouse_handling
- else
- process_cursor_move
- process_cursor_rect
- process_handling
- end
- end
- #--------------------------------------------------------------------------
- # * Cursor Movement Processing
- #--------------------------------------------------------------------------
- def process_cursor_move
- return unless cursor_movable?
- last_index = @index
- if Drago_DataModule::FASTCURSOR
- cursor_down( Input.trigger?(:DOWN)) if Input.repeat?(:DOWN)
- cursor_up( Input.trigger?(:UP )) if Input.repeat?(:UP )
- else
- cursor_down( Input.trigger?(:DOWN)) if Input.trigger?(:DOWN)
- cursor_up( Input.trigger?(:UP )) if Input.trigger?(:UP )
- end
- Sound.play_cursor if @index != last_index
- end
- #--------------------------------------------------------------------------
- # * Mouse Movement Processing
- #--------------------------------------------------------------------------
- def process_mouse_move
- return unless cursor_visible?
- window_commands.each_with_index do |window,index|
- process_position_mouse(window,index)
- end
- end
- #--------------------------------------------------------------------------
- # * Mouse Scroll Processing
- #--------------------------------------------------------------------------
- def process_mouse_scroll
- cursor_down if Mouse.scroll_down?
- cursor_up if Mouse.scroll_up?
- end
- #--------------------------------------------------------------------------
- # * Cursor Position Processing
- #--------------------------------------------------------------------------
- def process_cursor_rect
- return unless cursor_visible?
- window_commands.each_with_index do |window,index|
- process_position_x(window,index)
- process_position_y(window,index)
- process_opacity(window,index)
- end
- end
- #--------------------------------------------------------------------------
- # * Cursor Position X Processing
- #--------------------------------------------------------------------------
- def process_position_x(s,i,fixed = false)
- pos = index == i
- return s.x = @x + (pos ? x_off : 0) if fixed
- s.x = pos ? [s.x + 1, @x + x_off].min : [s.x - 1, @x].max
- end
- #--------------------------------------------------------------------------
- # * Cursor Position Y Processing
- #--------------------------------------------------------------------------
- def process_position_y(s,i,fixed = false)
- pos = @y + (s.height * (i - scroll_index))
- return s.y = pos if fixed
- if s.y < pos
- s.y = [s.y + 5, pos].min
- elsif s.y > pos
- s.y = [s.y - 5, pos].max
- end
- end
- #--------------------------------------------------------------------------
- # * Cursor Position X and Y (Mouse) Processing
- #--------------------------------------------------------------------------
- def process_position_mouse(s,i)
- if Mouse.in_area?(@x,s.y,s.width+x_off,s.height)
- s.x = [s.x + 1, @x + x_off].min
- unless Mouse.scroll?
- last_index = @index
- @index = i
- Sound.play_cursor if last_index != index
- end
- else
- s.x = [s.x - 1, @x].max
- end
- pos = @y + (s.height * (i - scroll_index))
- if s.y < pos
- s.y = [s.y + 5, pos].min
- elsif s.y > pos
- s.y = [s.y - 5, pos].max
- end
- process_opacity(s,i)
- end
- #--------------------------------------------------------------------------
- # * Process Opacity
- #--------------------------------------------------------------------------
- def process_opacity(s,i)
- return if s.y > Graphics.height
- if i == 0 || s.y >= window_commands[i-1].y + (s.height / 4)
- s.opacity = [s.opacity + 20, disabled_item.include?(i) ?
- index == i ? 120 : 60 :
- index == i ? 255 : 180].min
- if s.opacity >= 100 && !(@drawed||=[]).include?(i)
- s.draw_text_ex(4,0,commands[i][:name])
- @drawed.push(i)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Handling Processing for Mouse Clicking Etc.
- #--------------------------------------------------------------------------
- def process_mouse_handling
- return unless active
- return process_ok if ok_enabled? &&
- (Mouse.trigger?(Mouse::PRIMARY) or Input.trigger?(:C))
- return process_cancel if cancel_enabled? &&
- (Mouse.trigger?(Mouse::SECONDARY)or Input.trigger?(:B))
- end
- #--------------------------------------------------------------------------
- # * Handling Processing for OK and Cancel Etc.
- #--------------------------------------------------------------------------
- def process_handling
- return unless active
- return process_ok if ok_enabled? && Input.trigger?(:C)
- return process_cancel if cancel_enabled? && Input.trigger?(:B)
- end
- #--------------------------------------------------------------------------
- # * Determine if Mouse is in range
- #--------------------------------------------------------------------------
- def mouse_in_position?
- return false unless ($imported[:drg_custom_input] || 0) >= 2.00
- return false unless cursor_movable?
- x = [window_commands[0].x,0].max
- y = [window_commands[0].y,0].max
- w = [window_commands[0].width + x_off, Graphics.width].min
- h = [window_commands[0].height * item_max, Graphics.height].min
- return true if Mouse.in_area?(x,y,w,h)
- return false
- end
- #--------------------------------------------------------------------------
- # * Determine if Cursor is Moveable
- #--------------------------------------------------------------------------
- def cursor_movable?
- return false unless item_max > 0
- return false unless active
- return true
- end
- #--------------------------------------------------------------------------
- # * Determine if Cursor is Visible
- #--------------------------------------------------------------------------
- def cursor_visible?
- return false unless item_max > 0
- return false unless visible
- return true
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of OK Processing
- #--------------------------------------------------------------------------
- def ok_enabled?
- return false unless item_max > 0
- return false unless (handle?(:ok) || result[:handle])
- return true
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Cancel Processing
- #--------------------------------------------------------------------------
- def cancel_enabled?
- return false unless handle?(:cancel)
- return true
- end
- #--------------------------------------------------------------------------
- # * Get Activation State of Selection Item
- #--------------------------------------------------------------------------
- def current_item_enabled?
- return false unless index > -1 && result != nil
- return false if disabled_item.include?(index)
- return true
- end
- #--------------------------------------------------------------------------
- # * Set Handler Corresponding to Operation
- # method : Method set as a handler (Method object)
- #--------------------------------------------------------------------------
- def set_handler(symbol, method)
- handler[symbol] = method
- end
- #--------------------------------------------------------------------------
- # * Check for Handler Existence
- #--------------------------------------------------------------------------
- def handle?(symbol)
- handler.include?(symbol)
- end
- #--------------------------------------------------------------------------
- # * Call Handler
- #--------------------------------------------------------------------------
- def call_handler(symbol)
- handler[symbol].call if handle?(symbol)
- end
- #--------------------------------------------------------------------------
- # * Processing When OK Button Is Pressed
- #--------------------------------------------------------------------------
- def process_ok
- if current_item_enabled?
- Sound.play_ok
- Input.update
- deactivate
- call_ok_handler
- else
- Sound.play_buzzer
- end
- end
- #--------------------------------------------------------------------------
- # * Processing When Cancel Button Is Pressed
- #--------------------------------------------------------------------------
- def process_cancel
- Sound.play_cancel
- Input.update
- deactivate
- call_cancel_handler
- end
- #--------------------------------------------------------------------------
- # * Call OK Handler
- #--------------------------------------------------------------------------
- def call_ok_handler
- if result[:handle]
- result[:handle].call
- else
- call_handler(:ok)
- end
- end
- #--------------------------------------------------------------------------
- # * Call Cancel Handler
- #--------------------------------------------------------------------------
- def call_cancel_handler
- call_handler(:cancel)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement