RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Dialog System

0 Members and 1 Guest are viewing this topic.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
I have tried to make a Dialog system which is intended to ease the creation of dialogs.
Spoiler for Dialog system:
Code: [Select]
#==============================================================================
# ** Dialog system
#------------------------------------------------------------------------------
# Zeriab
# Version 1.0
# 2007-11-07 (Year-Month-Day)
#------------------------------------------------------------------------------
# * Description :
#
#   A small framework like script for dialogs
#------------------------------------------------------------------------------
# * License :
#
#   Copyright (C) 2007  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
  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  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(640,480)
    bitmap.fill_rect(0,0,640,480,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

What is a dialog? You can consider it as a scene that runs on top of the current scene.
Here is an example of how the system can be used. It is a yes/no dialog.
Spoiler for An example - A Yes/No Dialog:
Code: [Select]
#============================================================================
# * 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: [Select]
# 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:
Code: [Select]
s = 'Do you want to open the chest?'
v = Dialog_YesNo.show(true, s)
$game_switches[5] = v
Here is an event using this:
Quote from: Angry Chest

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?
Code: [Select]
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.

Spoiler for Screenie:

I have tried to give dialogs the feeling of scenes.
When you create a dialog you will in most cases only have to overwrite 3-4 methods:

main_window
You should create the windows you are going to use in this method.
Please set the .z-values of the windows to at least STARTING_Z_VALUE + 1
This is what you put before the main loop when creating a normal scene.
You can consider it pretty much equivalent to the main_window method in the SDK.
Does nothing by default

main_dispose
Dispose of the windows you have created here and do any other clean up you find necessary.
Does nothing by default

update
The update method is pretty much equivalent to the update method in a normal scene.
Exits the scene when you press the B-button by default.

You end the dialog by calling the mark_to_close method. It will then exit just like if you normally change the scene.
Remember to set the value that will be returned. By default is nil returned.
Use self.value = ... to set the value. This value will not be frozen after you use the mark_to_close method, which means that you can change the value after you use that method if it happens later in the update method.

I am certain that I have messed something up or forgotten to tell something important. Please do tell if you run into any problems

*hugs*
 - Zeriab
« Last Edit: November 19, 2007, 03:14:38 PM by Zeriab »

**
Rep: +0/-0Level 86
I'll totally check this out.

Can I suggest you add some preview pictures? :)
You dropped your pockets.

*
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 Most Mature Member2010 Favourite Staff Member
I like this. I saw it a little while ago, and I can imagine some very nice uses for it.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
It would be a good idea to add a preview of the example ^_^
Expect it coming up in a few days.

I can't add a preview picture of the system because there is not anything to look at. (It is up to the scripter ;))

@modern: Have fun with it ^^

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
I have added the screenies as requested ^_^

********
Shadow Knight
Rep:
Level 91
Ruin that brick wall!
Project of the Month winner for October 2008
Nice script indeed :lol:!
Be kind, everyone you meet is fighting a hard battle.