Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # FULL SCRIPT
- #
- # If you don't want to bother copying script entries one by one, this is the
- # full script in a single entry. Don't forget to remove the 'begin' and 'end'
- # tags to uncomment the whole script. Otherwise, just erase this entry.
- #==============================================================================
- FEATURES = [:race, :hair, :eyes, :mustache, :beard, :head, :clothing, :neck,
- :armorf, :armorb, :chest, :arms, :waist, :legs, :feet, :capef,
- :capeb]
- OPTIONS = [:picture, :hue, :brightness, :x_offset, :y_offset]
- DEFAULT_LIBRARY = "Male"
- DEFAULT_PICTURES = {
- "Male" => ["Human.png", nil, nil, nil,
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
- }
- NAME_NO_PICTURE = "None"
- DIR_DATA = "Data/Charsets"
- FILENAME_SAVE = "Selection"
- FILENAME_RENDER = "Render"
- COLOR1 = Color.new(255, 0, 255, 128)
- COLOR2 = Color.new(192, 0, 192, 128)
- HELP_MESSAGE = {
- "Edit" => "Edit the current selection",
- "Load..." => "Load previously saved data to the maker",
- "Save" => "Save current selection for future use",
- "Library..." => "Select a different graphic library to build charset with",
- "Default" => "Revert to default selection",
- "Randomize" => "Randomize each feature for which a selection has been made",
- "Use as hero" => "Replace the player's graphic with the current render",
- "To image file" => "Save current render as a .PNG file",
- "Credits" => "Find out who's behind this great program"
- }
- module RPG
- module Cache
- class << self
- def replace(key, bitmap)
- unless @cache[key].nil?
- @cache[key].dispose
- end
- @cache[key] = bitmap
- end
- def part(type, filename, hue = 0, brightness = 0)
- self.load_bitmap("Graphics/Characters/#{Charset.library}/#{type.display}/", filename, hue, brightness)
- end
- alias mp_charset_load_bitmap load_bitmap
- def load_bitmap(folder_name, filename, hue = 0, brightness = 0)
- if brightness == 0
- return mp_charset_load_bitmap(folder_name, filename, hue)
- else
- path = folder_name + filename
- key = [path, 0, brightness]
- if not @cache.include?(key) or @cache[key].disposed?
- @cache[key] = self.load_bitmap(folder_name, filename).clone
- if brightness > 0
- @cache[key].lighten(brightness.to_f / 10)
- else
- @cache[key].darken(brightness.abs.to_f / 10)
- end
- end
- if hue == 0
- return @cache[key]
- else
- key = [path, hue, brightness]
- if not @cache.include?(key) or @cache[key].disposed?
- @cache[key] = @cache[ [path, 0, brightness] ].clone
- @cache[key].hue_change(hue)
- end
- return @cache[key]
- end
- end
- end
- end
- end
- def self.warn(message)
- $game_system.se_play($data_system.decision_se)
- Graphics.freeze
- window = Window_Base.new(32, 192, 576, 96)
- window.contents = Bitmap.new(window.width - 32, window.height - 32)
- window.contents.draw_text(0, 0, window.width - 32, 32, message, 1)
- window.contents.draw_text(0, 32, 544, 32, "OK", 1)
- window.cursor_rect.set(208, 32, 128, 32)
- window.active = true
- window.z = 5000
- Graphics.transition
- loop do
- Input.update
- Graphics.update
- window.update
- if Input.trigger?(Input::C) or Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- break
- end
- end
- Graphics.freeze
- window.dispose
- Graphics.transition
- return
- end
- def self.confirm(message)
- $game_system.se_play($data_system.buzzer_se)
- Graphics.freeze
- window = Window_Base.new(32, 192, 576, 96)
- window.contents = Bitmap.new(window.width - 32, window.height - 32)
- window.contents.draw_text(0, 0, window.width - 32, 32, message, 1)
- window.contents.draw_text(0, 32, 272, 32, "OK", 1)
- window.contents.draw_text(272, 32, 272, 32, "Cancel", 1)
- window.cursor_rect.set(72, 32, 128, 32)
- window.active = true
- window.z = 5000
- Graphics.transition
- index = 0
- result = nil
- while result.nil?
- Input.update
- Graphics.update
- window.update
- if Input.repeat?(Input::LEFT) or Input.repeat?(Input::RIGHT)
- $game_system.se_play($data_system.cursor_se)
- index += 1
- index %= 2
- window.cursor_rect.set(72 + 272 * index, 32, 128, 32)
- end
- if Input.trigger?(Input::C)
- $game_system.se_play($data_system.decision_se)
- result = index == 0
- end
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- result = false
- end
- end
- Graphics.freeze
- window.dispose
- Graphics.transition
- return result
- end
- end
- class Bitmap
- def darken(factor)
- factor = 1 - factor
- for y in 0...self.height
- for x in 0...self.width
- color = self.get_pixel(x, y)
- next if color.alpha == 0
- self.set_pixel(x, y, Color.new(color.red * factor, color.green * factor,
- color.blue * factor, color.alpha) )
- end
- end
- GC.start
- end
- def lighten(factor)
- p = 255 * factor
- factor = 1 - factor
- for y in 0...self.height
- for x in 0...self.width
- color = self.get_pixel(x, y)
- next if color.alpha == 0
- self.set_pixel(x, y, Color.new(color.red * factor + p, color.green * factor + p,
- color.blue * factor + p, color.alpha) )
- end
- end
- GC.start
- end
- end
- class Bitmask
- def initialize(size = 1)
- @data = [0]
- resize(size)
- end
- def [](i)
- if i >= @size
- raise RangeError, "Bit ##{i} not defined (max = #{@size - 1}) in Bitmask#[]"
- end
- return @data[i >> 5][i & 31] == 1
- end
- def []=(i, b)
- case b
- when TrueClass, FalseClass
- if self[i] == b
- return nil
- else
- @data[i >> 5] ^= 2 ** i
- return b
- end
- else
- raise TypeError, "TrueClass or FalseClass expected as parameters in Bitmask#[]="
- end
- end
- def resize(size)
- while (size >> 5) >= @data.size
- @data << 0
- end
- @size = size
- end
- def to_s
- str = String.new
- for i in 0...@size
- if i & 7 == 0
- str << " "
- end
- str << @data[i >> 5][i & 31].to_s
- end
- return str
- end
- end
- class Dir
- def self.files(directory = self.pwd, *filters)
- ary = []
- for filename in self.entries(directory)
- next if File.directory?(filename) or filename == "." or filename == ".."
- if filters.empty? or filters.include?(File.extname(filename))
- ary << filename
- end
- end
- return ary
- end
- def self.subdirectories(directory = self.pwd)
- ary = []
- for filename in self.entries(directory)
- if File.directory?(filename)
- ary << filename
- end
- end
- return ary
- end
- end
- class File
- def self.directory?(filename)
- return false if filename == "."
- return true if self.extname(filename) == ""
- return false
- end
- end
- module Charset
- VIEWPORT = Viewport.new(0, 0, 640, 480)
- VIEWPORT.z = 1000
- class << self
- attr_reader :data
- attr_accessor :library
- def init(library = DEFAULT_LIBRARY)
- @library = library
- @data = []
- for i in 0...FEATURES.size
- feature = Feature.new(FEATURES[i])
- feature.picture = DEFAULT_PICTURES[@library][i] unless DEFAULT_PICTURES[@library].nil?
- @data << feature
- end
- end
- def render
- bitmap = Bitmap.new(128, 192)
- for feature in @data
- next if feature.picture == NAME_NO_PICTURE
- src_bitmap = RPG::Cache.part(feature.type, feature.picture, feature.hue,
- feature.brightness)
- start_x = feature.x_offset >= 0 ? 0 : feature.x_offset.abs
- start_y = feature.y_offset >= 0 ? 0 : feature.y_offset.abs
- rect = Rect.new(start_x, start_y, 128 - feature.x_offset.abs,
- 192 - feature.y_offset.abs)
- start_x = feature.x_offset >= 0 ? feature.x_offset : 0
- start_y = feature.y_offset >= 0 ? feature.y_offset : 0
- bitmap.blt(start_x, start_y, src_bitmap, rect)
- end
- return bitmap
- end
- def cache(name)
- RPG::Cache.replace("Graphics/Characters/#{name}", self.render)
- end
- end
- class Feature
- attr_reader :type
- attr_accessor :hue
- attr_accessor :brightness
- attr_accessor :x_offset
- attr_accessor :y_offset
- def initialize(type)
- @type = type
- @picture = nil
- @hue = 0
- @brightness = 0
- @x_offset = 0
- @y_offset = 0
- end
- def picture
- if @picture == nil
- return NAME_NO_PICTURE
- else
- return @picture
- end
- end
- def picture=(name)
- if name == NAME_NO_PICTURE
- @picture = nil
- else
- @picture = name
- end
- end
- end
- end
- class Game_Temp
- alias mp_charset_initialize initialize
- def initialize
- mp_charset_initialize
- Charset.init
- end
- end
- class Sprite_Part < RPG::Sprite
- def initialize(id, x, y)
- super(Charset::VIEWPORT)
- @id = id
- @_x = x
- @_y = y
- self.z = id
- end
- def feature
- return Charset.data[@id]
- end
- def refresh
- if self.feature.picture == NAME_NO_PICTURE
- self.bitmap = nil
- return
- end
- self.x = @_x + self.feature.x_offset
- self.y = @_y + self.feature.y_offset
- self.bitmap = RPG::Cache.part(self.feature.type, self.feature.picture,
- self.feature.hue, self.feature.brightness)
- @_whiten_duration = 1
- end
- end
- class Window_Menu < Window_Selectable
- attr_reader :options
- attr_reader :disabled
- def initialize(x, y, width, max_height, options)
- @options = options
- super(x, y, width, [max_height, (@options.size + 1) * 32].min)
- self.contents = Bitmap.new(width - 32, @options.size * 32)
- @item_max = @options.size
- @disabled = Bitmask.new(@item_max)
- self.index = 0
- refresh
- end
- def refresh
- self.contents.clear
- for i in 0...@options.size
- self.contents.font.color = @disabled[i] ? disabled_color : normal_color
- self.contents.draw_text(4, i * 32, width - 32, 32, @options[i])
- end
- end
- def disable_option(i)
- return false if @disabled[i]
- @disabled[i] = true
- refresh
- return true
- end
- def enable_option(i)
- return false unless @disabled[i]
- @disabled[i] = false
- refresh
- return true
- end
- def update_help
- @help_window.set_text(HELP_MESSAGE[@options[self.index]], 1)
- end
- end
- class Window_Charset < Window_Base
- attr_reader :menu_windows
- attr_accessor :index
- def initialize
- super(0,0,640,64)
- self.contents = Bitmap.new(self.width - 32, self.height - 32)
- @item_max = 3
- x = self.contents.width / @item_max
- for i in 0...@item_max
- self.contents.draw_text(x * i + 4, 0, x, 32, case i
- when 0
- "Selection"
- when 1
- "Render"
- when 2
- "?"
- end
- )
- end
- @menu_windows = []
- for i in 0...@item_max
- window = Window_Menu.new(16 + x * i, 64, x, 160, case i
- # Selection Menu
- when 0
- ["Edit", "Load...", "Save", "Library...", "Default", "Randomize"]
- # Export Menu
- when 1
- ["Use as hero", "To image file"]
- # ? Menu
- when 2
- ["Credits"]
- end
- )
- window.visible = false
- window.active = false
- window.z = 4000
- @menu_windows << window
- end
- end
- def help_window=(help_window)
- for window in @menu_windows
- window.help_window = help_window
- end
- end
- def index=(i)
- unless @index.nil?
- menu_window.visible = false
- menu_window.active = false
- end
- if i == -1
- @index = nil
- self.cursor_rect.empty
- return
- end
- @index = i
- x = self.contents.width / @item_max
- self.cursor_rect.set(x * @index, 0, x, 32)
- menu_window.visible = true
- menu_window.active = true
- end
- def update
- return unless self.active
- super
- menu_window.update
- if Input.repeat?(Input::LEFT)
- $game_system.se_play($data_system.cursor_se)
- self.index = (self.index - 1) % @item_max
- end
- if Input.repeat?(Input::RIGHT)
- $game_system.se_play($data_system.cursor_se)
- self.index = (self.index + 1) % @item_max
- end
- end
- def activate
- self.active = true
- self.index = 0
- end
- def deactivate
- self.active = false
- self.index = -1
- end
- def menu_window
- return @menu_windows[self.index]
- end
- def option
- return menu_window.options[menu_window.index]
- end
- def dispose
- for window in @menu_windows
- window.dispose
- end
- super
- end
- end
- class Window_Feature < Window_Selectable
- def initialize
- super(0, 64, 96, 352)
- @item_max = Charset.data.size
- self.index = -1
- self.active = false
- self.contents = Bitmap.new(width - 32, @item_max * 32)
- refresh
- end
- def feature(i = self.index)
- return Charset.data[i].type
- end
- def refresh
- self.contents.clear
- for i in 0...@item_max
- self.contents.draw_text(4, i * 32, 64, 32, self.feature(i).display )
- end
- end
- def update
- return unless self.active
- super
- end
- def activate
- self.active = true
- end
- def deactivate
- self.active = false
- end
- def update_help
- @help_window.set_text("SP: Edit feature ESC: Return to top menu SHIFT: Edit all Q/W: Change order", 1)
- end
- end
- class Window_FeatureOption < Window_Selectable
- attr_accessor :feature_window
- attr_accessor :edit_all
- def initialize
- super(96, 64, 224, 352)
- self.contents = Bitmap.new(self.width - 32, self.height - 32)
- @item_max = OPTIONS.size
- self.index = -1
- self.active = false
- self.visible = true
- @edit_all = false
- @need_refresh = false
- end
- def feature(i = @feature_window.index)
- return Charset.data[i]
- end
- def option
- return OPTIONS[self.index]
- end
- def refresh
- @need_refresh = true
- @pictures = Dir.files("Graphics/Characters/#{Charset.library}/#{feature.type.display}", ".bmp", ".png", ".jpg")
- @pictures.unshift(NAME_NO_PICTURE)
- @picture_index = @pictures.index(self.feature.picture)
- self.contents.clear
- for i in 0...@item_max
- if i == 0 and @edit_all
- self.contents.font.color = disabled_color
- else
- self.contents.font.color = system_color
- end
- self.contents.draw_text(4, i * 32, 64, 32, OPTIONS[i].display)
- end
- for i in 0...@item_max
- if self.feature.send(OPTIONS[i]).is_a?(Numeric)
- text = sprintf("%+d", self.feature.send(OPTIONS[i]))
- else
- text = self.feature.send(OPTIONS[i]).to_s
- end
- if i == 0 and @edit_all
- self.contents.font.color = disabled_color
- self.contents.draw_text(64, i * 32, 124, 32, "---", 2)
- else
- self.contents.font.color = normal_color
- self.contents.draw_text(64, i * 32, 124, 32, text, 2)
- end
- end
- end
- def update
- return unless self.active
- super
- if @edit_all
- return if option == :picture
- for i in 0...Charset.data.size
- update_feature(i)
- end
- else
- update_feature
- end
- if option == :picture and feature.picture != NAME_NO_PICTURE
- if Input.repeat?(Input::Z)
- picture_index = @picture_index
- regexp = Regexp.new(feature.picture[0, feature.picture.size - 6] + "\\d{2}.\\w{3}")
- while @pictures[picture_index] =~ regexp
- picture_index += 1
- if picture_index == @pictures.size
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- end
- $game_system.se_play($data_system.cursor_se)
- @picture_index = picture_index
- self.feature.picture = @pictures[@picture_index]
- self.refresh
- end
- if Input.repeat?(Input::Y)
- picture_index = @picture_index
- regexp = Regexp.new(feature.picture[0, feature.picture.size - 6] + "\\d{2}.\\w{3}")
- while @pictures[picture_index] =~ regexp
- picture_index -= 1
- if picture_index == 0
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- end
- $game_system.se_play($data_system.cursor_se)
- @picture_index = picture_index
- self.feature.picture = @pictures[@picture_index]
- self.refresh
- end
- end
- end
- def update_feature(i = @feature_window.index)
- if Input.repeat?(Input::LEFT)
- $game_system.se_play($data_system.cursor_se)
- case option
- when :picture
- @picture_index -= 1
- @picture_index %= @pictures.size
- self.feature(i).picture = @pictures[@picture_index]
- when :hue
- feature(i).hue -= 10
- feature(i).hue %= 360
- else
- eval("feature(i).#{option} -= 1")
- end
- self.refresh
- return true
- end
- if Input.repeat?(Input::RIGHT)
- $game_system.se_play($data_system.cursor_se)
- case option
- when :picture
- @picture_index += 1
- @picture_index %= @pictures.size
- self.feature(i).picture = @pictures[@picture_index]
- when :hue
- feature(i).hue += 10
- feature(i).hue %= 360
- else
- eval("feature(i).#{option} += 1")
- end
- self.refresh
- return true
- end
- return false
- end
- def activate
- self.active = true
- self.index = 0
- end
- def deactivate
- self.active = false
- self.index = -1
- end
- def update_help
- @help_window.set_text("<-/->: Adjust parameter SP: Apply changes ESC: Cancel changes Q/W: Change order", 1)
- end
- def need_refresh
- if @need_refresh
- @need_refresh = false
- return true
- end
- return false
- end
- end
- class Window_LoadSelection < Window_Selectable
- def initialize
- super(0, 64, 320, 352)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.active = false
- self.visible = false
- self.z = 1000
- @need_refresh = false
- end
- def refresh
- @data = Dir.files(DIR_DATA)#, "*.rxdata")
- return false if @data.empty?
- @item_max = @data.size
- for i in 0...@item_max
- self.contents.draw_text(4, i * 32, self.width - 32, 32, @data[i])
- end
- end
- def filename
- return "#{DIR_DATA}/#{@data[self.index]}"
- end
- def update
- return unless self.active
- super
- if Input.repeat?(Input::DOWN) or Input.repeat?(Input::UP) or
- Input.repeat?(Input::L) or Input.repeat?(Input::R)
- update_selection
- end
- end
- def update_selection
- @need_refresh = true
- file = File.open(self.filename, "r")
- Charset.library = Marshal.load(file)
- Charset.data.replace(Marshal.load(file))
- file.close
- end
- def activate
- self.active = true
- self.visible = true
- self.index = 0
- self.update_selection
- end
- def deactivate
- self.active = false
- self.visible = false
- end
- def update_help
- @help_window.set_text("SP: Load current selection ESC: Cancel selection load", 1)
- end
- def need_refresh
- if @need_refresh
- @need_refresh = false
- return true
- end
- return false
- end
- end
- class Window_LoadSelection < Window_Selectable
- def initialize
- super(0, 64, 320, 352)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.active = false
- self.visible = false
- self.z = 1000
- @need_refresh = false
- end
- def refresh
- @data = Dir.files(DIR_DATA)#, "*.rxdata")
- return false if @data.empty?
- @item_max = @data.size
- for i in 0...@item_max
- self.contents.draw_text(4, i * 32, self.width - 32, 32, @data[i])
- end
- end
- def filename
- return "#{DIR_DATA}/#{@data[self.index]}"
- end
- def update
- return unless self.active
- super
- if Input.repeat?(Input::DOWN) or Input.repeat?(Input::UP) or
- Input.repeat?(Input::L) or Input.repeat?(Input::R)
- update_selection
- end
- end
- def update_selection
- @need_refresh = true
- file = File.open(self.filename, "r")
- Charset.library = Marshal.load(file)
- Charset.data.replace(Marshal.load(file))
- file.close
- end
- def activate
- self.active = true
- self.visible = true
- self.index = 0
- self.update_selection
- end
- def deactivate
- self.active = false
- self.visible = false
- end
- def update_help
- @help_window.set_text("SP: Load current selection ESC: Cancel selection load", 1)
- end
- def need_refresh
- if @need_refresh
- @need_refresh = false
- return true
- end
- return false
- end
- end
- class Window_LibrarySelection < Window_Selectable
- def initialize
- super(0, 64, 320, 352)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.active = false
- self.visible = false
- self.z = 1000
- @need_refresh = false
- end
- def refresh
- @data = Dir.subdirectories("Graphics/Characters")
- return false if @data.empty?
- @item_max = @data.size
- for i in 0...@item_max
- self.contents.draw_text(4, i * 32, self.width - 32, 32, @data[i])
- end
- end
- def library
- return @data[self.index]
- end
- def update
- return unless self.active
- super
- if Input.repeat?(Input::DOWN) or Input.repeat?(Input::UP) or
- Input.repeat?(Input::L) or Input.repeat?(Input::R)
- update_selection
- end
- end
- def update_selection
- @need_refresh = true
- Charset.init(library)
- end
- def activate
- self.active = true
- self.visible = true
- self.index = 0
- self.update_selection
- end
- def deactivate
- self.active = false
- self.visible = false
- end
- def update_help
- @help_window.set_text("SP: Load current library ESC: Cancel library selection", 1)
- end
- def need_refresh
- if @need_refresh
- @need_refresh = false
- return true
- end
- return false
- end
- end
- class Scene_Charset < Scene_Base
- def setup
- super
- @sprites << @charset_window = Window_Charset.new
- @sprites << @feature_window = Window_Feature.new
- @sprites << @option_window = Window_FeatureOption.new
- @option_window.feature_window = @feature_window
- @sprites << @preview_window = Window_Base.new(320, 64, 320, 352)
- @sprites << @load_window = Window_LoadSelection.new
- @sprites << @library_window = Window_LibrarySelection.new
- @sprites << @help_window = Window_Help.new
- @help_window.y = 416
- @charset_window.help_window =
- @feature_window.help_window =
- @option_window.help_window =
- @load_window.help_window =
- @library_window.help_window = @help_window
- @charset_window.activate
- @preview_window.contents = Bitmap.new(@preview_window.width - 32,
- @preview_window.height - 32)
- @preview_window.active = false
- def @preview_window.refresh
- self.contents.clear
- self.contents.draw_text(0, 0, 144, 32, "Selected", 1)
- if self.active
- self.contents.draw_text(160, 0, 144, 32, "Preview", 1)
- end
- end
- def @preview_window.activate
- self.active = true
- self.refresh
- end
- def @preview_window.deactivate
- self.active = false
- self.refresh
- end
- @preview_window.refresh
- @option_windows = []
- @preview_sprites = []
- @selected_sprites = []
- bitmap = Bitmap.new(128, 192)
- for y in 0...4
- for x in 0...4
- bitmap.fill_rect(x * 32, y * 48, 32, 48, (x + y) % 2 == 0 ? COLOR1 : COLOR2)
- end
- end
- sprite = Sprite.new(Charset::VIEWPORT)
- sprite.bitmap = bitmap
- sprite.x = 496
- sprite.y = 128
- sprite.visible = false
- def sprite.refresh; return; end
- @sprites << sprite
- @preview_sprites << sprite
- sprite = Sprite.new(Charset::VIEWPORT)
- sprite.bitmap = bitmap
- sprite.x = 336
- sprite.y = 128
- def sprite.refresh; return; end
- @sprites << sprite
- for i in 0...FEATURES.size
- sprite = Sprite_Part.new(i, 496, 128)
- sprite.visible = false
- @sprites << sprite
- @preview_sprites << sprite
- sprite = Sprite_Part.new(i, 336, 128)
- @sprites << sprite
- @selected_sprites << sprite
- end
- @selected_animated = []
- @preview_animated = []
- for i in 0..3
- rect = Rect.new(0, i * 48, 32, 48)
- sprite = RPG::Sprite.new(Charset::VIEWPORT)
- sprite.x = 336 + i * 32
- sprite.y = 344
- sprite.src_rect = rect
- @selected_animated << sprite
- @sprites << sprite
- sprite = RPG::Sprite.new(Charset::VIEWPORT)
- sprite.x = 496 + i * 32
- sprite.y = 344
- sprite.src_rect = rect
- sprite.visible = false
- @preview_animated << sprite
- @sprites << sprite
- end
- refresh_selected
- refresh_preview
- if Dir.files(DIR_DATA, ".rxdata").empty?
- i = @charset_window.menu_windows[0].options.index("Load...")
- @charset_window.menu_windows[0].disable_option(i)
- end
- @blink_count = 0
- @frame_count = 0
- @frame = 0
- @animation_rect = []
- for i in 0..15
- @animation_rect << Rect.new(i % 4 * 32, i / 4 * 48, 32, 48)
- end
- update_animation
- end
- def terminate
- super
- for sprite in @selected_sprites
- sprite.dispose
- end
- end
- def refresh_selected
- for sprite in @selected_sprites
- sprite.refresh
- end
- bitmap = Charset.cache("Render")
- for sprite in @selected_animated
- sprite.bitmap = bitmap
- end
- end
- def refresh_preview
- for sprite in @preview_sprites
- sprite.refresh
- end
- bitmap = Charset.cache("Preview")
- for sprite in @preview_animated
- sprite.bitmap = bitmap
- end
- end
- def show_preview
- for sprite in @preview_sprites + @preview_animated
- sprite.visible = true
- end
- end
- def hide_preview
- for sprite in @preview_sprites + @preview_animated
- sprite.visible = false
- end
- end
- def enable_save
- enable_export
- i = @charset_window.menu_windows[0].options.index("Save")
- @charset_window.menu_windows[0].enable_option(i)
- end
- def disable_save
- i = @charset_window.menu_windows[0].options.index("Save")
- @charset_window.menu_windows[0].disable_option(i)
- end
- def enable_export
- i = @charset_window.menu_windows[1].options.index("To image file")
- @charset_window.menu_windows[1].enable_option(i)
- end
- def disable_export
- i = @charset_window.menu_windows[1].options.index("To image file")
- @charset_window.menu_windows[1].disable_option(i)
- end
- def export_disabled?
- i = @charset_window.menu_windows[1].options.index("To image file")
- return @charset_window.menu_windows[1].disabled[i]
- end
- def save_disabled?
- i = @charset_window.menu_windows[0].options.index("Save")
- return @charset_window.menu_windows[0].disabled[i]
- end
- def update_animation
- if @frame_count == 0
- @frame_count = 8
- @frame += 1
- @frame %= 4
- end
- @frame_count -= 1
- for i in 0..3
- @selected_animated[i].src_rect =
- @preview_animated[i].src_rect = @animation_rect[i * 4 + @frame]
- end
- end
- def update
- super
- if @option_window.need_refresh or @load_window.need_refresh or
- @library_window.need_refresh
- refresh_preview
- end
- # Confirm Selection
- if Input.trigger?(Input::C)
- # If in command window
- if @charset_window.active
- case @charset_window.option
- # Edit sprite
- when "Edit"
- $game_system.se_play($data_system.decision_se)
- @charset_window.deactivate
- @feature_window.activate
- @blink_count = 0
- @feature_window.index = 0
- @option_window.refresh
- # Default
- when "Default"
- return unless RPG.confirm("Lose all changes and revert to default?")
- Charset.init
- @feature_window.refresh
- for window in @option_windows
- window.refresh
- end
- refresh_selected
- enable_save
- when "Load..."
- unless @load_window.refresh
- return RPG.warn("No saved data found in Data/Charsets!")
- end
- $game_system.se_play($data_system.decision_se)
- @backup_charset = Charset.data.clone
- @charset_window.deactivate
- @preview_window.activate
- @load_window.activate
- show_preview
- refresh_preview
- when "Save"
- if save_disabled?
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- i = 0
- while File.exist?(filename = sprintf("Data/Charsets/#{FILENAME_SAVE}%03d.rxdata", i))
- i += 1
- end
- file = File.open(filename, "wb")
- Marshal.dump(Charset.library, file)
- Marshal.dump(Charset.data, file)
- file.close
- disable_save
- i = @charset_window.menu_windows[0].options.index("Load...")
- @charset_window.menu_windows[0].enable_option(i)
- return RPG.warn("Current selection saved as #{filename}!")
- when "Library..."
- unless @library_window.refresh
- return RPG.warn("No libraries found in Graphics/Characters!")
- end
- $game_system.se_play($data_system.decision_se)
- @backup_charset = Charset.data.clone
- @charset_window.deactivate
- @preview_window.activate
- @library_window.activate
- show_preview
- refresh_preview
- when "Randomize"
- $game_system.se_play($data_system.decision_se)
- @backup_charset = []
- for feature in Charset.data
- @backup_charset << feature.clone
- next if feature.picture == NAME_NO_PICTURE
- # Randomize picture
- feature.picture = Dir.files("Graphics/Characters/#{Charset.library}/#{feature.type.display}").sample
- end
- @preview_window.activate
- show_preview
- refresh_preview
- @help_window.set_text("SP: Apply changes ESC: Cancel changes", 1)
- loop do
- Input.update
- Graphics.update
- update_animation
- if Input.trigger?(Input::C)
- $game_system.se_play($data_system.decision_se)
- enable_save
- refresh_selected
- break
- end
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- Charset.data.replace(@backup_charset)
- break
- end
- end
- @preview_window.deactivate
- hide_preview
- update_animation
- return
- # Use charset
- when "Use as hero"
- Charset.cache($game_actors[1].character_name)
- return RPG.warn("Player's character changed to current selection!")
- when "To image file"
- if export_disabled?
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- i = 0
- while File.exist?(filename = sprintf("Graphics/Characters/#{FILENAME_RENDER}%03d.png", i))
- i += 1
- end
- Charset.render.export(filename)
- disable_export
- return RPG.warn("Current selection rendered as #{filename}!")
- when "Credits"
- RPG.warn("Charset Maker v1.00 written by Moonpearl")
- RPG.warn("Using Bitmap Export written by Zeus81")
- RPG.warn("Graphic library provided by Looseleaf")
- return
- end
- # If selecting feature to edit
- elsif @feature_window.active
- $game_system.se_play($data_system.decision_se)
- @backup_feature = Charset.data[@feature_window.index].clone
- @preview_window.activate
- @feature_window.deactivate
- @option_window.activate
- show_preview
- # If editing selected feature
- elsif @option_window.active
- $game_system.se_play($data_system.decision_se)
- @preview_window.deactivate
- @option_window.deactivate
- @feature_window.activate
- @option_window.edit_all = false
- @blink_count = 0
- refresh_selected
- hide_preview
- enable_save
- # If browsing list of possible selections
- elsif @load_window.active
- $game_system.se_play($data_system.decision_se)
- @load_window.deactivate
- @preview_window.deactivate
- @charset_window.activate
- refresh_selected
- hide_preview
- disable_save
- # If browsing list of libraries
- elsif @library_window.active
- $game_system.se_play($data_system.decision_se)
- @library_window.deactivate
- @preview_window.deactivate
- @charset_window.activate
- refresh_selected
- hide_preview
- disable_save
- end
- end
- # Cancel selection
- if Input.trigger?(Input::B)
- # If in command window
- if @charset_window.active
- $game_system.se_play($data_system.cancel_se)
- $scene = Scene_Map.new
- # If selecting feature to edit
- elsif @feature_window.active
- $game_system.se_play($data_system.cancel_se)
- @feature_window.deactivate
- @feature_window.index = -1
- @charset_window.activate
- @option_window.contents.clear
- # If editing selected feature
- elsif @option_window.active
- $game_system.se_play($data_system.cancel_se)
- @preview_window.deactivate
- @option_window.deactivate
- @feature_window.activate
- # Cancel changes and revert to backup
- if @option_window.edit_all
- Charset.data.replace(@backup_charset)
- else
- Charset.data[@feature_window.index] = @backup_feature
- end
- @option_window.refresh
- @option_window.edit_all = false
- hide_preview
- # If browsing list of possible selections
- elsif @load_window.active
- $game_system.se_play($data_system.cancel_se)
- @load_window.deactivate
- @preview_window.activate
- @charset_window.activate
- Charset.data.replace(@backup_charset)
- hide_preview
- # If browsing list of libraries
- elsif @library_window.active
- $game_system.se_play($data_system.cancel_se)
- @library_window.deactivate
- @preview_window.deactivate
- @charset_window.activate
- Charset.data.replace(@backup_charset)
- hide_preview
- end
- end
- if Input.repeat?(Input::L)
- return if @feature_window.index == - 1
- if @feature_window.index == 0 or @option_window.edit_all
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- $game_system.se_play($data_system.cursor_se)
- Charset.data.insert( @feature_window.index - 1,
- Charset.data.delete_at(@feature_window.index) )
- index = @option_window.index
- @option_window.index = -1
- @option_window.refresh
- @option_window.active = false
- @feature_window.index -= 1
- @feature_window.refresh
- @option_window.refresh
- @option_window.index = index
- if @feature_window.active
- refresh_selected
- else
- feature = Charset.data[@feature_window.index]
- Charset.data[@feature_window.index] = @backup_feature
- refresh_selected
- Charset.data[@feature_window.index] = feature
- @option_window.active = true
- end
- enable_save
- end
- if Input.repeat?(Input::R)
- return if @feature_window.index == - 1
- if @feature_window.index == Charset.data.size - 1 or @option_window.edit_all
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- $game_system.se_play($data_system.cursor_se)
- Charset.data.insert( @feature_window.index + 1,
- Charset.data.delete_at(@feature_window.index) )
- index = @option_window.index
- @option_window.index = -1
- @option_window.refresh
- @option_window.active = false
- @feature_window.index += 1
- @feature_window.refresh
- @option_window.refresh
- @option_window.index = index
- @option_window.active = true unless @feature_window.active
- if @feature_window.active
- refresh_selected
- else
- feature = Charset.data[@feature_window.index]
- Charset.data[@feature_window.index] = @backup_feature
- refresh_selected
- Charset.data[@feature_window.index] = feature
- @option_window.active = true
- end
- enable_save
- end
- update_animation
- if @feature_window.active
- if @blink_count == 0
- @blink_count = 16
- @selected_sprites[@feature_window.index].whiten
- end
- @blink_count -= 1
- if Input.trigger?(Input::A)
- $game_system.se_play($data_system.decision_se)
- @backup_charset = []
- for feature in Charset.data
- @backup_charset << feature.clone
- end
- @option_window.edit_all = true
- @feature_window.deactivate
- @feature_window.cursor_rect.set(0, 0, @feature_window.width - 32,
- Charset.data.size * 32)
- @preview_window.activate
- @option_window.activate
- @option_window.refresh
- show_preview
- end
- if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
- @blink_count = 0
- @option_window.refresh
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement