____
La
couche de représentation graphique
Il reste maintenant à coder une Scene qui permet de savoir quelles quêtes sont
en cours, lesquelles sont terminées, et de pouvoir voir combien d'argent et
d'expérience elles rapportent.
Voici un exemple de Scene basique. Le code n'est pas détaillé et compréhensible
pour les personnes capables d'écrire leurs propres Scenes. Si vous n'en êtes
pas capable, allez jeter un oeil sur le tutorial de création de Scenes.
Code Rubyclass Scene_Quest
def main
@command_window = Window_QuestCommand.new
@status_window = Window_QuestStatus.new
@quest_window1 = Window_Quest.new ( 0 )
@quest_window2 = Window_Quest.new ( 1 )
@quest_window1 .status_window = @status_window
@quest_window2 .status_window = @status_window
refresh
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@command_window .dispose
@status_window .dispose
@quest_window1 .dispose
@quest_window2 .dispose
end
def refresh
@quest_window1 .visible = ( @command_window.index == 0 )
@quest_window2 .visible = ( @command_window.index == 1 )
case @command_window .index
when 0
@quest_window = @quest_window1
when 1
@quest_window = @quest_window2
end
end
def update
@command_window .update
@status_window .update
@quest_window .update
refresh
if @command_window .active
update_command
return
end
if @quest_window .active
update_quest
return
end
end
def update_command
if Input.trigger ?( Input::B )
$game_system .se_play ( $data_system.cancel_se )
$scene = Scene_Map.new
return
end
if Input.trigger ?( Input::C )
$game_system .se_play ( $data_system.decision_se )
@command_window .active = false
@quest_window .index = 0
@quest_window .active = true
return
end
end
def update_quest
if Input.trigger ?( Input::B )
$game_system .se_play ( $data_system.cancel_se )
@quest_window .active = false
@quest_window .index = -1
@command_window .active = true
return
end
end
end
class Window_QuestCommand < Window_Selectable
def initialize
super ( 0 , 0 , 640 , 64 )
self .contents = Bitmap.new ( width - 32 , height - 32 )
self .contents .font .name = $fontface
self .contents .font .size = 24
self .back_opacity = 160
@commands = [ "En cours" , "Terminées" ]
@item_max = 2
@column_max = 2
draw_item( 0 )
draw_item( 1 )
self .index = 0
end
def draw_item( index)
rect = Rect.new ( 160 + index * 160 + 4 , 0 , 128 - 10 , 32 )
self .contents .fill_rect ( rect, Color.new ( 0 , 0 , 0 , 0 ) )
self .contents .draw_text ( rect, @commands [ index] , 1 )
end
def update_cursor_rect
self .cursor_rect .set ( 160 + index * 160 , 0 , 128 , 32 )
end
end
class Window_Quest < Window_Selectable
attr_writer :status_window
def initialize( quest_status)
super ( 0 , 256 , 640 , 224 )
@quest_status = quest_status
@column_max = 2
refresh
self .active = false
self .index = -1
end
def quest
return self .index == -1 ? nil : @data [ self .index ]
end
def update
@status_window .quest = self .quest
end
def refresh
if self .contents != nil
self .contents .dispose
self .contents = nil
end
if @quest_status == 0
@data = $game_party .quests .find_all { |quest|
not quest.finished ?
}
end
if @quest_status != 0
@data = $game_party .quests .find_all { |quest|
quest.finished ?
}
end
@item_max = @data .size
self .contents = Bitmap.new ( width - 32 , height - 32 )
self .contents .font .name = $fontface
self .contents .font .size = $fontsize
for i in 0 ...@item_max
draw_quest( i)
end
end
def draw_quest( index)
quest = @data [ index]
x = 4 + index % 2 * ( 288 + 32 )
y = index / 2 * 32
self .contents .draw_text ( x , y, 280 , 32 , quest.name , 0 )
end
end
class Window_QuestStatus < Window_Base
def initialize
super ( 0 , 64 , 640 , 192 )
self .contents = Bitmap.new ( width - 32 , height - 32 )
self .contents .font .name = $fontface
self .contents .font .size = $fontsize
@old_quest = nil
end
def quest=( quest)
@quest = quest
refresh
end
def refresh
if @quest != @old_quest
self .contents .clear
@old_quest = @quest
if @old_quest != nil
self .contents .draw_text ( 0 , 0 , 600 , 32 , @old_quest .description )
self .contents .draw_text ( 0 , 60 , 600 , 32 , "Argent : #{@old_quest.gold}" )
self .contents .draw_text ( 0 , 120 , 600 , 32 , "Exp : #{@old_quest.exp}" )
end
end
end
end
Pour appeler la Scene, un simple
Code Ruby$scene = Scene_Quest.new
fera l'affaire.