Hi all...
In the process of learning RGSS2, I am working on my first script. It is the begining for a Dialog system. Here it is
But wher I activate an event doing the 'start_dialog("Barnaby")' script and the scene appears, the Window_Command containing the active topics doesn't respond to to my keyboard commands. What did I miss ??
And... by the way... How do you change the default title of the spoiler thing ?
Thanks
In the process of learning RGSS2, I am working on my first script. It is the begining for a Dialog system. Here it is
Code:
class BDR_Dlg_Topic
attr_reader :owner
attr_reader :id
attr_reader :caption
attr_reader :answer
def initialize(owner, id)
@owner = owner # owning dialog
@id = id # id, displayed in the topic list
@caption = "" # the topic the PC wnats to discuss
@answers = "" # the answer the NPC will guive
@enabled = false # active state of the topic
@lnk_tpc = [] # list of topics to enable/disable
end
# writer fot @caption : set it to String class
def caption=(txt)
@caption = txt.to_s
end
# writer for @answer : set it to String class
def answer=(txt)
@answer = txt.to_s
end
# sets @enabled to true
def enable
@enabled = true
end
# sets @enabled to false
def disable
@enabled = false
end
# reader for @enabled
def enabled?
@enabled
end
# writer for @lnk_tpc : add the 3 1st element of the argument as an array the list
def linked_topics=(keys)
k = keys.to_a
@lnk_tpc += [[k[0].to_s, k[1].to_s, keys[2]]]
end
# process the topics of the owning dialog list identified by a key (array) in the @lnk_tpc list
# for each key, sets the @enabled flag of dialog(key[0]).topic(key[1]) to key[2]
def update_linked_topics!
@lnk_tpc.each do |dkey, tkey, ok|
if ok
owner.owner.dialog(dkey).topic(tkey).enable
else
owner.owner.dialog(dkey).topic(tkey).disable
end
end
end
end
#--------------------------------------------------------------------------------------------------------------------------
# BDR_Dlg_Dialog
# Encapsulatad all that is needed to handle a dialog
# - id : unique identifer of the dialog in teh dialogs list, case sensitive
# - caption : displayed at the top of teh dialog scene
# - list of topics : each topic can be accessed via self.topic(<ID>) , <ID> beeing case sensitive
# - greeting message : one of the topics is the greeting message, displayed as soon as the dialog beins
# by default, it is the self.topic(""); but its id can be set via self.greeting_id=<ID>
#--------------------------------------------------------------------------------------------------------------------------
class BDR_Dlg_Dialog
attr_reader :owner
attr_reader :id
attr_reader :caption
def initialize(owner, id)
@owner = owner # owning dialog list
@id = id # id
@caption = "" # text displayed at the top of the dialog scene
@greeting_id ="" # identifier of the greeting topic
@topics = {} # list of topics
greeting.answer = "Hello"
end
# writer for @caption
def caption=(txt)
@caption = txt.to_s
end
# reader for @topics : returns the topic identified by a key
# create a topic if non existent
def topic(key)
k = key.to_s
if @topics[k].nil?
@topics[k] = BDR_Dlg_Topic.new(self, k)
end
@topics[k]
end
# reader the @greeting_id
def greeting_id=(key)
@greeting_id = key.to_s
end
# returns the topic identified by @greeting_id, i.e. the greeting topic of a dialog
def greeting
topic(@greeting_id)
end
# returns the list of active topics
def active_topics
r = []
@topics.each do |k, t|
if t.enabled?
r += [k]
end
end
r
end
end
#--------------------------------------------------------------------------------------------------------------------------
# BDR_Dlg_Dialogs
# The maisn class : list of dialogs
# You can set and get its various dialogs via
# self.dialog(<ID>) whete <ID> being case sensitive
#
# It's instance is $BDR_Dlg_Dialogs
#--------------------------------------------------------------------------------------------------------------------------
class BDR_Dlg_Dialogs
def initialize
@dialogs = {} # list of dialogs
end
# reader for @dialogs : returns the dialog identified by a key
# create a topic if non existent
def dialog(key)
k = key.to_s
if @dialogs[k].nil?
@dialogs[k] = BDR_Dlg_Dialog.new(self, k)
end
@dialogs[k]
end
end
$BDR_Dialogs = BDR_Dlg_Dialogs.new
class Scene_BDR_Dlg < Scene_Base
def initialize(dlg)
@dialog = dlg
@active_topics = get_active_topics
end
# remember a screen is 544*416
def start
super
create_menu_background
@win_title = Window_Base.new(0,0,544,57)
@win_title.contents.draw_text(0,0,512,30,$BDR_Dialogs.dialog(@dialog).caption,1)
@win_topics = Window_Command.new(136,@active_topics)
@win_topics.y = 64
@win_topics.height = 352
@win_topics.index = 0
@win_topics.active = true
end
def terminate
super
dispose_menu_background
@win_title.dispose
@win_topics.dispose
end
def update
super
#win_topics.update
if Input.repeat?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
end
end
def get_active_topics
$BDR_Dialogs.dialog(@dialog).active_topics
end
end
def start_dialog(id)
$scene = Scene_BDR_Dlg.new(id)
end
$BDR_Dialogs.dialog("Barnaby").caption = "Brother Barnaby"
$BDR_Dialogs.dialog("Barnaby").topic("Name").caption = "Name"
$BDR_Dialogs.dialog("Barnaby").topic("Name").answer = "I am Brother Barnaby"
$BDR_Dialogs.dialog("Barnaby").topic("Name").enable
$BDR_Dialogs.dialog("Barnaby").topic("Job").caption = "Job"
$BDR_Dialogs.dialog("Barnaby").topic("Job").answer = "I am a healer"
$BDR_Dialogs.dialog("Barnaby").topic("Job").enable
$BDR_Dialogs.dialog("Barnaby").topic("Job").linked_topics = ["Barnaby", "Heal", true]
$BDR_Dialogs.dialog("Barnaby").topic("Heal").caption = "Heal"
$BDR_Dialogs.dialog("Barnaby").topic("Heal").answer = "'tis done"
But wher I activate an event doing the 'start_dialog("Barnaby")' script and the scene appears, the Window_Command containing the active topics doesn't respond to to my keyboard commands. What did I miss ??
And... by the way... How do you change the default title of the spoiler thing ?
Thanks