#=======================================================================
# Select Class/Gender by GubiD
# v0.1 Oct 6,2007
#=======================================================================
class Game_Party
#--------------------------------------------------------------------------
# * Initial Party Setup
#--------------------------------------------------------------------------
def setup_starting_members
$new_scene = 1
$scene = Scene_Character_Gen.new
while $new_scene != nil
$scene.main
end
end
# @actors = []
# for i in $data_system.party_members
# @actors.push($game_actors[i])
# end
#end
end
class Spriteset_Gen_Char
attr_reader :character_sprites, :viewport2
def initialize
# Make viewports
@viewport1 = Viewport.new(0, 0, 640, 480)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 200
@viewport3.z = 5000
# Make character sprites
@character_sprites = []
# Make picture sprites
@picture_sprites = []
for i in 1..50
@picture_sprites.push(Sprite_Picture.new(@viewport2,
$game_screen.pictures[i]))
end
# Make timer sprite
@timer_sprite = Sprite_Timer.new
# Frame update
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
# Dispose of character sprites
for sprite in @character_sprites
sprite.dispose
end
# Dispose of picture sprites
for sprite in @picture_sprites
sprite.dispose
end
# Dispose of timer sprite
@timer_sprite.dispose
# Dispose of viewports
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update character sprites
for sprite in @character_sprites
sprite.update
end
# Update picture sprites
for sprite in @picture_sprites
sprite.update
end
# Update timer sprite
@timer_sprite.update
# Set screen color tone and shake position
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
# Set screen flash color
@viewport3.color = $game_screen.flash_color
# Update viewports
@viewport1.update
@viewport3.update
end
end
class Sprite_Character_Gen < RPG::Sprite
attr_accessor :character
def initialize(viewport, character = nil)
super(viewport)
@character = character
update
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
class Char_New
attr_accessor :tile_id,:character_name,:character_hue,:transparent,:pattern
attr_accessor :direction,:opacity,:blend_type,:bush_depth,:animation_id
attr_reader :x,:y
def initialize(name)
@tile_id = 0
@character_name = name
@character_hue = 0
@transparent = false
@pattern = 0
@direction = 2
@real_x = 0
@real_y = 0
@prelock_direction = 0
@opacity = 255
@blend_type = 0
@bush_depth = 0
@animation_id = 0
@anime_count = 0
@move_speed = 3
@step_anime = true
@original_pattern = 0
end
def moveto(x, y)
@x = x % 20 #$game_map.width
@y = y % 15 #$game_map.height
@real_x = @x * 128
@real_y = @y * 128
@prelock_direction = 0
end
def update
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > 18 - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % 4
end
# Clear animation count
@anime_count = 0
end
end
def dispose
@character_name = ""
end
#--------------------------------------------------------------------------
# * Get Screen X-Coordinates
#--------------------------------------------------------------------------
def screen_x
# Get screen coordinates from real coordinates and map display position
return (@real_x - 0 + 3) / 4 + 16
end
#--------------------------------------------------------------------------
# * Get Screen Y-Coordinates
#--------------------------------------------------------------------------
def screen_y
# Get screen coordinates from real coordinates and map display position
y = (@real_y - $game_map.display_y + 3) / 4 + 16#32
# Make y-coordinate smaller via jump count
#if @jump_count >= @jump_peak
# n = @jump_count - @jump_peak
#else
# n = @jump_peak - @jump_count
#end
return y #- (@jump_peak * @jump_peak - n * n) / 2
end
#--------------------------------------------------------------------------
# * Get Screen Z-Coordinates
# height : character height
#--------------------------------------------------------------------------
def screen_z(height = 0)
# If display flag on closest surface is ON
# Get screen coordinates from real coordinates and map display position
z = (@real_y - 0 + 3) / 4 + 32
# If tile
if @tile_id > 0
# Add tile priority * 32
return z #+ $game_map.priorities[@tile_id] * 32
# If character
else
# If height exceeds 32, then add 31
return z + ((height > 32) ? 31 : 0)
end
end
end
class Window_Gender < Window_Selectable
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
$gender = nil
@column_max = 2
@item_max = 2
refresh
end
def refresh
self.contents.clear
x = 240
s1 = "Male"
s2 = "Female"
for i in 0..1
if i == 0 ? text = s1 : text = s2
self.contents.draw_text(x*i,0,320,40,text,1)
end
end
end
def update_cursor_rect
self.cursor_rect.set(@index * 240 + (130-(@index*10)), 0, 80, 32)
if @index == 0
$gender = "Male"
else
$gender = "Female"
end
end
end
class Window_Choose_Class < Window_Selectable
def initialize
super(0, 64, 640, 240)
self.contents = Bitmap.new(width - 32, height - 32)
@column_max = 2
refresh
end
def class_name
return @data[self.index].name
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for i in 1...$data_classes.size
if $data_classes[i].name != ""
@data.push($data_classes[i])
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_class_name(i)
end
end
end
def draw_class_name(index)
profession = @data[index]
#find position to draw
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(x + 28, y, 212, 32, profession.name, 0)
end
end
class Window_Choose_Look < Window_Selectable
def initialize(class_window, sprites, viewport)
super(0, 304, 640, 240)
self.contents = Bitmap.new(width - 32, height - 32)
@class_window = class_window
@sprites = sprites
@viewport = viewport
@pics = []
refresh
end
alias choose_char_dis dispose
def dispose
clear_sprites
choose_char_dis
end
def clear_sprites
for sprite in @sprites
sprite.dispose
end
end
def refresh
graphics = []
case $gender
when "Male"
case @class_window.class_name
when "Lancer"
graphics.push("009-Lancer01")
graphics.push("010-Lancer02")
graphics.push("011-Lancer03")
else
graphics.push("001-Fighter01")
end
when "Female"
case @class_window.class_name
when "Lancer"
graphics.push("012-Lancer04")
else
graphics.push("002-Fighter02")
end
end
@item_max = graphics.size
@pics.clear
for sprite in @sprites
sprite.dispose
end
@sprites.clear
if @item_max > 0
for i in 0...@item_max
draw_character(i, graphics[i])
end
end
end
def draw_character(index, name)
actor = Char_New.new(name)
@pics[index] = actor
@sprites.push(Sprite_Character.new(@viewport, @pics[index]))
x = 4 + (index*5)
y = 13
@pics[index].moveto(x,y)
@sprites.push(@pics[index])
end
def update_cursor_rect
if @index != -1
self.cursor_rect.set(((@pics[@index].x * 128)+ 3) / 4 -19, 80, 40, 40)
else
self.cursor_rect.set(-40, -50, 0,0)
end
end
def selected_hue
return @pics[@index].character_hue
end
def selected_name
return @pics[@index].character_name
end
def change_hue(hue)
@pics[@index].character_hue = hue
end
end
class Game_Actor < Game_Battler
attr_accessor :character_name,:character_hue
end
class Scene_Character_Gen
def main
@spriteset = Spriteset_Gen_Char.new
@gender = Window_Gender.new
@class_name = Window_Choose_Class.new
@choose_look = Window_Choose_Look.new(@class_name, @spriteset.character_sprites, @spriteset.viewport2)
@gender.active = true
@gender.index = 0
current = $game_party.actors.size
actor = $game_actors[$data_system.party_members[current]]
p sprintf("Choose a graphic for %s", actor.name)
if $data_system.battle_transition == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$data_system.battle_transition)
end
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
@gender.dispose
@class_name.dispose
@choose_look.dispose
end
def update
@spriteset.update
if @gender.active
@gender.update
gender_update
return
end
if @class_name.active
@class_name.update
name_update
return
end
if @choose_look.active
@choose_look.update
choose_update
return
end
end
def gender_update
if Input.trigger?(Input::B)
if $game_party.actors.size == 0
$game_system.se_play($data_system.buzzer_se)
else
$scene = Scene_Map.new
$new_scene = nil
end
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@gender.active = false
@class_name.active = true
@class_name.index = 0
end
end
def name_update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@gender.active = true
@class_name.active = false
@class_name.index = -1
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@class_name.active = false
@choose_look.active = true
@choose_look.refresh
@choose_look.index = 0
end
end
def choose_update
if Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
hue = @choose_look.selected_hue - 3
@choose_look.change_hue(hue)
end
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
hue = @choose_look.selected_hue + 3
@choose_look.change_hue(hue)
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@class_name.active = true
@choose_look.active = false
@choose_look.index = -1
end
if Input.trigger?(Input::C)
if $game_party.actors.size != $data_system.party_members.size
$game_system.se_play($data_system.decision_se)
current = $game_party.actors.size
actor = $game_actors[$data_system.party_members[current]]
$game_party.actors.push(actor)
$game_party.actors[current].character_name = @choose_look.selected_name
$game_party.actors[current].character_hue = @choose_look.selected_hue
if $game_party.actors.size != $data_system.party_members.size
current = $game_party.actors.size
actor = $game_actors[$data_system.party_members[current]]
p sprintf("Choose a graphic for %s", actor.name)
@gender.active = true
@choose_look.active = false
@choose_look.index = -1
@choose_look.refresh
@choose_look.update
@class_name.index = -1
@class_name.update
else
$new_scene = nil
$scene = Scene_Map.new
end
else
$new_scene = nil
end
end
end
end