I'm learning Ruby. I started like 2 weeks ago so my code might be 'noobish'. Today I felt brave and attempted to create an addon for your script to make it easier to debug my game.
It actually works
, but there were a few things that I couldn't figure out. (I'm sorry if I ask too many questions)
Problems:
- How do I retrieve a list of all objectives? The problem is that the user may
have his objective id's as follow: 0,1,2,100,1000,434334,etc...
For now I just used a placeholder "@@quests"
- I also need to retrieve them without making them visible.
- How do I retrieve the list of objectives that belong to a specific quest_id
without revealing anything.
#==============================================================================
# Version 1.00
#
# About:
# A quick debug manager for turning on/off quests/objectives and/or revealing/
# concealing them.
#
# Instructions:
# Place below "Modern Algebra's Quest Journal" but above "? Main Process".
# Call like this: SceneManager.call(Scene_QJ_Debug).
# Or Press Q in the quest window to open the debug window
#
# Requires:
# - Modern Algebra's Quest Journal
# - RPG Maker VX Ace
#
# Written by Napoleon (My very first addon!).
#
# Version History:
# 1.00 (16-1-2013)
# - First Release
#==============================================================================
#==============================================================================
# ? Quest Journal - Debug Addon - Singleton instance
#------------------------------------------------------------------------------
# Singleton instance for the QJ debug scene
#==============================================================================
module Quest_Journal
module Utility
################################################################################
# CONFIG START
################################################################################
# When set to true (default) then you can Press [Q] (default) in the quest menu to open the debug menu.
# When set to false this addon can only be manually called.
DEBUG_MENU_ENABLED = true
# Key for opening the debug menu
DEBUG_MENU_KEY = :L
# The first quest id, usually 0
FIRST_QUEST = 0
# The maximum quest id to check. This must be equal or higher than your highest quest id
MAX_QUEST = 1000
# Quest text color when completed (in debug menu only)
QUEST_COMPLETE_COLOR = 3 # 3 = lightgreen
################################################################################
# CONFIG END
################################################################################
# Samples:
# Utility.quest_data(1,:objectives)
# Utility.quest_data(1,:name)
# Possible symbols: :line, :level, :name, :description, :objectives, :rewards
def self.quest_data(q_id, symbol)
return QuestData.setup_quest(q_id)[symbol]
end
# Fills the @@quests variable with all used quest id's.
def self.set_quest_data
result = []
array_idx = 0
for i in FIRST_QUEST..MAX_QUEST
if quest_data(i,:name) != nil
result[array_idx] = i
array_idx +=1
end
end
return result
end
#Utility.quests
@@quests = set_quest_data
# static getter
def self.quests
@@quests
end
#Utility.quest_complete?()
def self.quest_complete?(q_id)
return $game_party.quests.revealed?(q_id) && $game_party.quests[q_id].status?(:complete)
end
#Utility.reset_quest()
def self.reset_quest(q_id)
$game_party.quests.delete_quest(q_id)
$game_party.quests.setup_quest(q_id)
end
#Utility.objective_complete?(,)
def self.objective_complete?(q_id, *obj_id)
$game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:complete, *obj_id)
end
#Utility.objective_revealed?(,)
def self.objective_revealed?(q_id, *obj_id)
$game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:revealed, *obj_id)
end
#Utility.objective_concealed?(,)
def self.objective_concealed?(q_id, *obj_id)
$game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:concealed, *obj_id)
end
#Utility.objective_failed?(,)
def self.objective_failed?(q_id, *obj_id)
$game_party.quests.revealed?(q_id) && $game_party.quests[q_id].objective_status?(:failed, *obj_id)
end
#Utility.complete_objective(,)
def self.complete_objective(q_id, obj_id)
$game_party.quests[q_id].complete_objective(obj_id)
end
#Utility.complete_quest(,)
def self.complete_quest(q_id)
obj_count = QuestData.setup_quest(q_id)[:objectives].length
for i in 0..obj_count-1
complete_objective(q_id,i)
end
end
end # Utility
#==============================================================================
# ? Quest Journal - Debug Addon - Quest window (left window)
#------------------------------------------------------------------------------
# This window contains the list of all quests
#==============================================================================
class Window_Quests < Window_Selectable
include Quest_Journal
#--------------------------------------------------------------------------
# * Class Variable
#--------------------------------------------------------------------------
@@last_top_row = 0 # For saving first line
@@last_index = 0 # For saving cursor position
@@sel_quest_id = 1
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :right_window # Right window
attr_reader :sel_quest_id #
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(x, y)
super(x, y, window_width, window_height)
@sel_quest_id = Utility.quests[0]
refresh
self.top_row = @@last_top_row
select(@@last_index)
activate
end
#--------------------------------------------------------------------------
# * Get Window Width
#--------------------------------------------------------------------------
def window_width
return 164
end
#--------------------------------------------------------------------------
# * Get Window Height
#--------------------------------------------------------------------------
def window_height
Graphics.height
end
#--------------------------------------------------------------------------
# * Get Number of Items
#--------------------------------------------------------------------------
def item_max
Utility.quests.length || 0
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if active && Input.trigger?(:L)
q_id = Utility.quests[index]
if Utility.quest_complete?(q_id)
Utility.reset_quest(q_id)
else
Utility.complete_quest(q_id)
end
Sound.play_ok
redraw_current_item
@right_window.refresh
end
return unless @right_window
@sel_quest_id = Utility.quests[index]
@right_window.refresh_me
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
create_contents
draw_all_items
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
quest_id = Utility.quests[index]
if Utility.quest_complete?(quest_id)
change_color(text_color(Utility::QUEST_COMPLETE_COLOR))
end
text = sprintf("%02d: #{$game_party.quests[quest_id].name} ", quest_id )
text_rect = item_rect_for_text(index)
text_rect.x+=24
draw_text(text_rect, text)
change_color(normal_color)
draw_icon($game_party.quests[quest_id].icon_index, text_rect.x-24, text_rect.y, true)
end
#--------------------------------------------------------------------------
# * Processing When Cancel Button Is Pressed
#--------------------------------------------------------------------------
def process_cancel
super
@@last_top_row = top_row
@@last_index = index
end
#--------------------------------------------------------------------------
# * Set Right Window
#--------------------------------------------------------------------------
def right_window=(right_window)
@right_window = right_window
update
end
end
#==============================================================================
# ? Quest Journal - Debug Addon - Objective window (right window)
#------------------------------------------------------------------------------
# This window contains the list of all objectives for the selected quest
#==============================================================================
#==============================================================================
# ** Objective Window
#------------------------------------------------------------------------------
# Displays the objectives for the currently selected quest (if any)
#==============================================================================
class Window_Objectives < Window_Selectable
include Quest_Journal
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
# None
#--------------------------------------------------------------------------
# * Private Instance Variables
#--------------------------------------------------------------------------
# The previously selected quest id (in the left window)
@previous_quest_id
# The text colors for the objective status
@@OBJ_COLORS = {
'revealed' => 1, # blue
'completed' => 3, # green
'failed' => 18, # red
'concealed' => 0 # white
}
#--------------------------------------------------------------------------
# * Object Initialization
#-------------------------------------------------------------------------
def initialize(x, y, width, left_window)
@left_window = left_window
super(x, y, width, fitting_height(10))
refresh
end
#--------------------------------------------------------------------------
# * Get Number of Items
#--------------------------------------------------------------------------
def item_max
return QuestData.setup_quest(sel_q_id)[:objectives].length
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_all_items
end
#--------------------------------------------------------------------------
# * Selected Quest ID
#--------------------------------------------------------------------------
def sel_q_id
return @left_window.sel_quest_id
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
if sel_q_id == nil then return end
obj_id = index # store currently selected objective_id in a more meaningful variable name
item_text = sprintf("Obj. %0d: #{$game_party.quests[sel_q_id].objectives[obj_id]}",obj_id)
id_width = text_size(item_text).width
status = Utility.objective_complete?(sel_q_id,obj_id) ? "[X]" : "[ ]"
# objective item color
if Utility.objective_failed?(sel_q_id,index)
change_color(text_color(@@OBJ_COLORS['failed']))
elsif Utility.objective_concealed?(sel_q_id,index)
change_color(text_color(@@OBJ_COLORS['concealed']))
elsif Utility.objective_complete?(sel_q_id,index)
change_color(text_color(@@OBJ_COLORS['completed']))
elsif Utility.objective_revealed?(sel_q_id,index)
change_color(text_color(@@OBJ_COLORS['revealed']))
end
# draw text
text_rect = item_rect_for_text(index)
status_rect = item_rect_for_text(index)
text_rect.width -= 30
draw_text(text_rect, item_text)
# draw status
status_rect.x+= 5
draw_text(status_rect, status, 2)
change_color(normal_color) # reset text color
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh_me
if sel_q_id != @previous_quest_id then refresh end
@previous_quest_id = sel_q_id
end
#--------------------------------------------------------------------------
# * redraw_current_items (redraws both windows current items)
#--------------------------------------------------------------------------
def redraw_current_items
redraw_current_item
@left_window.redraw_current_item
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if Input.trigger?(:C)
if Utility.objective_complete?(sel_q_id,index)
$game_party.quests[sel_q_id].uncomplete_objective(index)
else
Utility.complete_objective(sel_q_id,index)
end
redraw_current_items
Sound.play_ok
end
if Input.trigger?(:L)
if Utility.objective_complete?(sel_q_id,index)
$game_party.quests[sel_q_id].fail_objective(index)
#p 'now failed'
elsif Utility.objective_failed?(sel_q_id,index)
$game_party.quests[sel_q_id].unfail_objective(index)
$game_party.quests[sel_q_id].reveal_objective(index)
#p 'now revealed'
elsif Utility.objective_revealed?(sel_q_id,index)
$game_party.quests[sel_q_id].conceal_objective(index)
#p 'now concealed'
else # it's ONLY revealed
$game_party.quests[sel_q_id].complete_objective(index)
#p 'now completed'
end
redraw_current_items
Sound.play_cursor
end
end
end # end of right window class
end # end of module
#==============================================================================
# ? Quest Journal - Debug Addon - Scene
#------------------------------------------------------------------------------
# The scene that contains the debug menu
#==============================================================================
class Scene_QJ_Debug < Scene_MenuBase
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
def start
super
create_left_window
create_right_window
create_help_window
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
end
#--------------------------------------------------------------------------
# * Create Left Window
#--------------------------------------------------------------------------
def create_left_window
@left_window = Quest_Journal::Window_Quests.new(0, 0)
@left_window.set_handler(:ok, method(:on_left_ok))
@left_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# * Create Right Window
#--------------------------------------------------------------------------
def create_right_window
wx = @left_window.width
ww = Graphics.width - wx
@right_window = Quest_Journal::Window_Objectives.new(wx, 0, ww, @left_window)
@right_window.set_handler(:cancel, method(:on_right_cancel))
@left_window.right_window = @right_window
end
#--------------------------------------------------------------------------
# * Create Help Window
#--------------------------------------------------------------------------
def create_help_window
wx = @right_window.x
wy = @right_window.height
ww = @right_window.width
wh = Graphics.height - wy
@help_window = Window_Base.new(wx, wy, ww, wh)
refresh_help_window(:left)
end
#--------------------------------------------------------------------------
# * Left [OK]
#--------------------------------------------------------------------------
def on_left_ok
refresh_help_window(:right)
@right_window.activate
@right_window.select(0)
end
#--------------------------------------------------------------------------
# * Right [Cancel]
#--------------------------------------------------------------------------
def on_right_cancel
@left_window.activate
@right_window.unselect
refresh_help_window(:left)
end
#--------------------------------------------------------------------------
# * Refresh Help Window
#--------------------------------------------------------------------------
def refresh_help_window(window)
if window == :left
help_text = "C (Enter) : Select Quest.\n" +
"L (Q) : Complete / Reset"
else
help_text = "C (Enter) : Complete / Reset\n" +
"L (Q) : Completed [green]\nFailed [red]\nRevealed [blue]\nConcealed [white]"
end
@help_window.contents.clear
@help_window.draw_text_ex(4, 0, help_text)
end
end # Scene
#==============================================================================
# Overwrite Algebra's Window_QuestList update method so it can call this addon's scene
#==============================================================================
class Window_QuestList < Window_Selectable
def update
super
if Quest_Journal::Utility::DEBUG_MENU_ENABLED && Input.trigger?(Quest_Journal::Utility::DEBUG_MENU_KEY)
SceneManager.return
SceneManager.call(Scene_QJ_Debug)
end
end
end
#==============================================================================
#
# ? End of File
#
#==============================================================================