molegato

Variable Quests menu

Apr 4th, 2012
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.62 KB | None | 0 0
  1. #==============================================================================
  2. # VARIABLE_QUESTS
  3. # Author Molegato
  4. # Version 1.1
  5. #------------------------------------------------------------------------------
  6. # Just a simple menu where some variable-based quests are shown
  7. #------------------------------------------------------------------------------
  8. # INSTRUCTIONS
  9. #
  10. # You map each quest to a variable
  11. # If the variable value is 0, the quest doesn't appear in the menu
  12. # If the variable value is 1, it appears as 'unsolved'
  13. # If the variable value is 2, it appears as 'active'
  14. # If the variable value is 3 or greater, it appears as 'solved'
  15. #
  16. # Any quest on 'unsolved' state can turn into 'active' by selecting it
  17. # on the quest menu, and only a single quest can be active at any time.
  18. #
  19. # To call the menu, use SceneManager.call(Scene_Quests) on a script call,
  20. # you can directly program it on your custom menu, or put it on a common
  21. # event attached to an item or skill, for making it easier to access.
  22. #==============================================================================
  23.  
  24. $imported = {} if $imported.nil?
  25. $imported['Molegato-VarQuests'] = true
  26.  
  27. #==============================================================================
  28. # CONFIGURATION, YOU CAN TOUCH THIS
  29. #==============================================================================
  30. module MOLEGATO_QUESTS
  31.   # Enable quest activation?
  32.   QUEST_ACTIVATION=true
  33.   # text shown to indicate a quest is not cleared
  34.   TEXT_UNSOLVED="-Aviable-"
  35.   # text sown to indicate a quest is cleared
  36.   TEXT_SOLVED="-Solved-"
  37.   # text sown to indicate a quest is activated
  38.   TEXT_ACTIVE="-Active-"
  39.   # color of the text in both cases
  40.   COLOR_SOLVED=1
  41.   COLOR_UNSOLVED=2
  42.   COLOR_ACTIVE=3
  43.  
  44.   #list of quests. Please follow the pattern shown on the commentary.
  45.   QUEST_DATA=[
  46.   #name               #var. #icon #image        #description
  47.   #block for long text
  48.   ["first quest"      ,1    ,1    ,""           ,"this is a first quest set up for testing.",
  49.   "yadda yadda yadda yadda
  50. more yadda yadda
  51. and a bit of bla bla blah"],
  52.  
  53.   ["second quest"     ,2    ,2    ,"window"     ,"just another quest",
  54.   "yadda yadda yadda yadda
  55. more yadda yadda
  56. and a bit of bla bla blah"],
  57.  
  58.   ["super quest"      ,3    ,3    ,"window"     ,"whatever. just keep going",
  59.   "yadda yadda yadda yadda
  60. more yadda yadda
  61. and a bit of bla bla blah"],
  62.   ]
  63. end
  64. #==============================================================================
  65. # END OF CONFIGURATION. EVERYTHING UNDER HERE IS A HELLISH MESS OF DEFICIENT
  66. # AMATEUR SCRIPTING. BE AWARE THAT MESSING WITH IT CAN RESULT IN DISASTER
  67. #==============================================================================
  68. #==============================================================================
  69. # ■ Scene_quests
  70. #==============================================================================
  71.  
  72. class Scene_Quests < Scene_MenuBase
  73.   def start
  74.     super
  75.     create_help_window
  76.     create_info_window
  77.     create_item_window
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● create windows
  81.   #--------------------------------------------------------------------------
  82.   def create_item_window
  83.     @item_window = Window_QuestList.new(0, @help_window.height,Graphics.width/2,Graphics.height-@help_window.height)
  84.     @item_window.viewport = @viewport
  85.     @item_window.help_window = @help_window
  86.     @item_window.set_handler(:cancel,   method(:return_scene))
  87.     @item_window.set_handler(:pagedown, method(:next_actor))
  88.     @item_window.set_handler(:pageup,   method(:prev_actor))
  89.     @item_window.set_handler(:ok,       method(:activate_quest))
  90.     @item_window.active=true
  91.     @info_window.window=@item_window
  92.     @info_window.refresh
  93.   end
  94.   def create_info_window
  95.     @info_window = Window_Quest_Status.new(Graphics.width/2,@help_window.height,Graphics.width/2,Graphics.height-@help_window.height)
  96.     @info_window.viewport = @viewport
  97.   end
  98.  
  99.   def update
  100.     super
  101.     @info_window.update
  102.   end
  103.  
  104.   def activate_quest
  105.    
  106.     return if MOLEGATO_QUESTS::QUEST_ACTIVATION==false
  107.     if $game_variables[@item_window.item[1]]==1
  108.       $game_variables[@item_window.item[1]]=2
  109.     elsif $game_variables[@item_window.item[1]]==2
  110.       $game_variables[@item_window.item[1]]=1
  111.     end    
  112.     MOLEGATO_QUESTS::QUEST_DATA.each do |each|
  113.       $game_variables[each[1]]=1 if $game_variables[each[1]]==2 and each[1]!=@item_window.item[1]
  114.       @item_window.activate
  115.       @item_window.refresh
  116.       @info_window.refresh
  117.     end
  118.   end
  119.  
  120. end
  121.  
  122. #==============================================================================
  123. # ■ Window_QuestList
  124. #==============================================================================
  125.  
  126. class Window_QuestList < Window_Selectable
  127.  
  128.   def initialize(x, y, width, height)
  129.     super
  130.     refresh
  131.     @index=0 if item_max>0
  132.   end
  133.  
  134.   def col_max
  135.     return 1
  136.   end
  137.  
  138.   def item_max
  139.     @data ? @data.size : 1
  140.   end
  141.  
  142.   def item
  143.     @data && index >= 0 ? @data[index] : nil
  144.   end
  145.  
  146.   def make_item_list
  147.     @data = []
  148.     for i in 0..MOLEGATO_QUESTS::QUEST_DATA.size-1
  149.       if $game_variables[MOLEGATO_QUESTS::QUEST_DATA[i][1]]!=0
  150.         quest = MOLEGATO_QUESTS::QUEST_DATA[i]
  151.         @data.push(quest)
  152.       end
  153.     end
  154.   end
  155.  
  156.   def draw_item(index)
  157.     current_item = @data[index]
  158.     if current_item
  159.       rect = item_rect(index)
  160.       rect.width -= 4
  161.       rect.x+=24
  162.       enableicon=false
  163.       enableicon=true if $game_variables[current_item[1]]>1
  164.       draw_icon(current_item[2],0,rect.y,enableicon)
  165.       change_color(text_color(MOLEGATO_QUESTS::COLOR_ACTIVE)) if $game_variables[current_item[1]]==2
  166.       draw_text(rect, current_item[0])
  167.       change_color(normal_color)
  168.     end
  169.   end
  170.  
  171.   def update_help
  172.     @help_window.set_text(item[4]) if item
  173.   end
  174.  
  175.   def refresh
  176.     make_item_list
  177.     create_contents
  178.     draw_all_items
  179.   end
  180.  
  181. end
  182.  
  183. #==============================================================================
  184. # ■ Window_Quest_Status
  185. #==============================================================================
  186.  
  187. class Window_Quest_Status < Window_Selectable
  188.   attr_accessor :index
  189.   attr_accessor :window
  190.  
  191.   def initialize(x, y, width, height)
  192.     super
  193.     @index=0
  194.   end
  195.  
  196.   def refresh
  197.     contents.clear
  198.     #draw quest name
  199.     return if !window.item
  200.     change_color(system_color)
  201.     draw_text(0, 0, contents.width, line_height, window.item[0],1)
  202.     #draw if solved
  203.     if $game_variables[window.item[1]]>2
  204.       change_color(text_color(MOLEGATO_QUESTS::COLOR_SOLVED))
  205.       draw_text(0, line_height, contents.width, line_height, MOLEGATO_QUESTS::TEXT_SOLVED,0)
  206.     elsif $game_variables[window.item[1]]>1
  207.       change_color(text_color(MOLEGATO_QUESTS::COLOR_ACTIVE))
  208.       draw_text(0, line_height, contents.width, line_height, MOLEGATO_QUESTS::TEXT_ACTIVE,0)
  209.     else
  210.       change_color(text_color(MOLEGATO_QUESTS::COLOR_UNSOLVED))
  211.       draw_text(0, line_height, contents.width, line_height, MOLEGATO_QUESTS::TEXT_UNSOLVED,0)
  212.     end
  213.     #draw image, if must
  214.     if not window.item[3].empty?
  215.       height_gap=draw_system(window.item[3],contents.width/2,48,0.5,0)[3]
  216.     else
  217.       height_gap=48
  218.     end
  219.    
  220.     #draw big text block
  221.     change_color(normal_color)
  222.     textarray=window.item[5].split("\n")
  223.     for i in 0..textarray.size-1
  224.       draw_text(0,height_gap+(line_height*i),contents.width,line_height,textarray[i])
  225.     end
  226.    
  227.   end
  228.  
  229.  
  230.   def update
  231.     super
  232.     if @index and @window and @index!=@window.index
  233.       @index=@window.index
  234.       refresh
  235.     end
  236.   end
  237.  
  238. end
Advertisement
Add Comment
Please, Sign In to add comment