[RMVX] Dialog System

0 Members and 1 Guest are viewing this topic.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
I just found out that this system works amazingly well on RMVX. All that is needed is to change the fixed widths 640 and 480 to Graphics.width and Graphics.height.
So here is an update with a RMVX version:

The dialog framework:
Code: [Select]
#==============================================================================
# ** Dialog system - RMVX
#------------------------------------------------------------------------------
# Zeriab
# Version 1.0
# 2008-02-16 (Year-Month-Day)
#------------------------------------------------------------------------------
# * Description :
#
#   A small framework like script for dialogs
#------------------------------------------------------------------------------
# * License :
#
#   Copyright (C) 2008  Zeriab
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Lesser Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Lesser Public License for more details.
#
#   For the full license see <http://www.gnu.org/licenses/>
#   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
#   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
#------------------------------------------------------------------------------
# * Instructions :
#
#   You can place this script pretty much anyway you like.
#   Place it above any other Dialogs you might be using.
#   Increase the STARTING_Z_VALUE if you have trouble with the dialog not
#   on top.
#==============================================================================
class Dialog
  STARTING_Z_VALUE = 1500 # Default value is 1500
  attr_accessor :value
  attr_writer :marked_to_close
  #--------------------------------------------------------------------------
  # * Getter with 'false' as default value
  #--------------------------------------------------------------------------
  def marked_to_close
@marked_to_close = false  if @marked_to_close.nil?
return @marked_to_close
  end
  #--------------------------------------------------------------------------
  # * Mark the dialog to close
  #--------------------------------------------------------------------------
  def mark_to_close
self.marked_to_close = true
  end
  #--------------------------------------------------------------------------
  # * Show the dialog
  #   Returns the value from the dialog
  #--------------------------------------------------------------------------
  def self.show(*args, &block)
dialog = self.new(*args, &block)
dialog.marked_to_close = false
return dialog.main
  end
  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  def initialize(*args, &block)
# For subclasses to overwrite
  end
  #--------------------------------------------------------------------------
  # * Main processing
  #--------------------------------------------------------------------------
  def main
# Create the dimmed background
create_background
# Create Windows
main_window
# Main loop
loop do
  # Update game screen
  Graphics.update
  # Update input information
  Input.update
  # Frame update
  update
  # Abort loop if the dialog should close
  if marked_to_close
break
  end
end
# Dispose of windows
main_dispose
# Dispose of background
dispose_background
# Update input information
Input.update
# Returns the acquired value
return self.value
  end
  #--------------------------------------------------------------------------
  # * Create the dimmed background
  #--------------------------------------------------------------------------
  def create_background
bitmap = Bitmap.new(Graphics.width,Graphics.height)
bitmap.fill_rect(0,0,Graphics.width,Graphics.height,Color.new(0,0,0,128))
@background_sprite = Sprite.new
@background_sprite.z = STARTING_Z_VALUE
@background_sprite.bitmap = bitmap
  end
  #--------------------------------------------------------------------------
  # * Create the windows
  #--------------------------------------------------------------------------
  def main_window
# For the subclasses to override
# Remember to set their z.value to at least STARTING_Z_VALUE + 1
  end
  #--------------------------------------------------------------------------
  # * Dispose the background
  #--------------------------------------------------------------------------
  def dispose_background
@background_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose the windows
  #--------------------------------------------------------------------------
  def main_dispose
# For the subclasses to override
# Dispose your windows here
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
# For the subclasses to override
if Input.trigger?(Input::B)
  mark_to_close
end
  end
end

A simple Yes/No Dialog: (as an example, REQUIRES the framework)
Code: [Select]
#============================================================================
# * A Simple Yes/No dialog (RMVX)
#============================================================================
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 = (Graphics.width - @command_window.width) / 2
@command_window.y = (Graphics.height - @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
  self.value = false
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

An as an actual use here is a code if you want a confirmation dialog when attempting to overwrite an existing save: (REQUIRES Dialog_YesNo)
Code: [Select]
class Scene_File < Scene_Base
  alias scene_file_dialog_determine_savefile determine_savefile
  #--------------------------------------------------------------------------
  # * Determine savefile
  #--------------------------------------------------------------------------
  def determine_savefile
if @saving && @savefile_windows[@index].file_exist
  var = Dialog_YesNo.show(false, 'Do you want to overwrite' +
' the old savegame?')
  unless var
Sound.play_buzzer
return
  end
end
scene_file_dialog_determine_savefile
  end
end
It is used in the very same way as the RMXP version, so refer to my RMXP Dialog System for instructions.

Note: Only have 1 copy of the scripts here or you might get errors.

*hugs*
 - Zeriab
« Last Edit: February 20, 2008, 05:55:47 PM by Zeriab »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Best RPG Maker User (Scripting)2010 Most Mature Member
Neat. It's nice when scripts convert as easily as that  ^-^

**
Rep: +0/-0Level 86
What's with these people?!?
I inserted the script for the overwriting files thing into the INSERT SCRIPTS area, but when I try to overwrite it, an error message appears! It says "????? '( Insert scripts here )' ? 8 ??? NameError ???????? uninitialized constant Scene_File::Dialog_YesNo" If you could help with this, please tell, I'm new at scripts. BTW I'm using the RMVX Starter Kit that has the Database and Script names translated. I also looked at the XP version, it says you have to put it under the original Scene_Save, but there is no Scene_Save in VX! Well, not that name anyway. Is it under Scene_File?
« Last Edit: February 19, 2008, 12:42:26 AM by GasparXR »

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
Whoops. I pasted the wrong code for the confirmation dialog >_>
Please try again ^^

Notice that the confirmation dialog for overwriting save files REQUIRES the the Dialog_YesNo script, which in turn requires the Dialog framework.
Basically, you need to paste the Dialog system in the script editor, paste Dialog_YesNo somewhere below the frame work and finally the save confimation script below Dialog_YesNo and below Scene_File.

From your error you have most likely not copied the Dialog_YesNo. Since you do not have this script, the game complains about Dialog_YesNo not existing.

**
Rep: +0/-0Level 86
What's with these people?!?
Okay, thanks a lot! I'm new at scripts hehe.

Though when I put the save script under Save_File, it says "stack level too deep" so I deleted from Scene_File(another copy of it is in my empty space) and it works perfectly!
« Last Edit: February 19, 2008, 08:56:10 PM by GasparXR »

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
You should only have one copy of the script, if you have more then you should get errors.
I assumed people knew that, something I shouldn't ^_^

*changes*