#============================================================================
# * A Simple Yes/No dialog
#============================================================================
class Dialog_YesNo < Dialog
# self.value: false = No, true = Yes
#--------------------------------------------------------------------------
# * A show method
#--------------------------------------------------------------------------
def initialize(default_value = false, text = nil)
# Sets the default value
self.value = default_value
@text = text
# Sets the menu index
if default_value
@menu_index = 0
else
@menu_index = 1
end
end
#--------------------------------------------------------------------------
# * Create the windows
#--------------------------------------------------------------------------
def main_window
@disposables = []
# The command window
@command_window = Window_Command.new(80, ['Yes', 'No'])
@command_window.index = @menu_index
@command_window.x = (640 - @command_window.width) / 2
@command_window.y = (480 - @command_window.height) / 2
@command_window.z = STARTING_Z_VALUE + 1
@disposables << @command_window
# The text window
if @text.is_a?(String)
@text_window = Window_Help.new
@text_window.set_text(@text, 1)
@text_window.z = STARTING_Z_VALUE + 1
@disposables << @text_window
end
end
#--------------------------------------------------------------------------
# * Dispose the windows
#--------------------------------------------------------------------------
def main_dispose
@disposables.each {|element| element.dispose}
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@command_window.update
if Input.trigger?(Input::B)
mark_to_close
end
if Input.trigger?(Input::C)
if @command_window.index == 0
self.value = true
else
self.value = false
end
mark_to_close
end
end
end
The idea is that you can all this dialog anywhere with the code:
# Code before
var = Dialog_YesNo.show(default_value, text) # Calls the dialog
# Code after
The dialog should then be shown and the code after will only be executed after the player chooses yes or no. It will return
false if
No is selected and
true if
Yes is selected.
Then the code placed after the call will be executed. You can say it will
freeze execution until the dialog is closed.
The principle is that you can call this code anyway. In script calls as well as in normal scripts.
Here is an example of a script call:
s = 'Do you want to open the chest?'
v = Dialog_YesNo.show(true, s)
$game_switches[5] = v
Here is an event using this:
Here is a screenie of it in action:
I assume you know how to make page 2 and page 3 yourself.
I know. This can easily be done with the normal choice system in events. So what about an example where its use is more clear?
Did you know that if you try to save on a slot where there already is a savegame it does not ask if you want to overwrite? It simply just overwrites the savegame. Let us say we don't want that. The remedy?
class Scene_Save < Scene_File
alias scene_save_overwrite_dialog_on_decision on_decision
#--------------------------------------------------------------------------
# * Decision Processing
#--------------------------------------------------------------------------
def on_decision(filename)
if File.exist?(filename)
var = Dialog_YesNo.show(false, 'Do you want to overwrite' +
' the old savegame?')
unless var
$game_system.se_play($data_system.buzzer_se)
return
end
end
scene_save_overwrite_dialog_on_decision(filename)
end
end
Just paste this anywhere below the original Scene_Save.