Zetu

Terminal Script Menu v1.03

Jul 10th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.11 KB | None | 0 0
  1. #===============================================================================
  2. # Dynamic Script Menu v1.03 by Zetu
  3. #===============================================================================
  4.  
  5. module Z
  6.   module Menu
  7.     SCRIPTS = [
  8.       #/regex/, script call.
  9.       [/item/i,   %Q{$scene = Scene_Item.new}],
  10.       [/skill/i,  %Q{$next = "Scene_Skill.new(@status_window.index)"
  11.                      start_actor_selection}],
  12.       [/equip/i,  %Q{$next = "Scene_Equip.new(@status_window.index)"
  13.                      start_actor_selection}],
  14.       [/status/i, %Q{$next = "Scene_Status.new(@status_window.index)"
  15.                      start_actor_selection}],
  16.       [/save/i,   %Q{$scene = Scene_File.new(true, false, false)}],
  17.       [/end/i,    %Q{$scene = Scene_End.new}],
  18.       [/clear/i,  %Q{@command_window.output.clear}],
  19.       [/exit/i,   %Q{$scene = Scene_Map.new}],
  20.       [/quicksave\((.*)\)/i, %Q{i = $1.to_i
  21.                                 Scene_File.new(true, false, false).force_save(i)
  22.                                 @command_window.output.print(
  23.                                 "game saved to slot \#{i}")}]
  24.     ]
  25.   end
  26.   module Item
  27.     SCRIPTS = [
  28.       [/item/i, %Q{@command_window.output.print(
  29.                     "start_selection $game_party.item")
  30.                     activate_item_selection}],
  31.       [/exit/i,  %Q{return_scene}],
  32.       [/next/i,  %Q{next_actor}],
  33.       [/prev/i,  %Q{prev_actor}]
  34.     ]
  35.   end
  36.   module Skill
  37.     SCRIPTS = [
  38.       [/skill/i, %Q{@command_window.output.print(
  39.                     "start_selection @actor.skill")
  40.                     activate_skill_selection}],
  41.       [/exit/i,  %Q{return_scene}],
  42.       [/next/i,  %Q{next_actor}],
  43.       [/prev/i,  %Q{prev_actor}]
  44.     ]
  45.   end
  46.   module Equip
  47.     SCRIPTS = [
  48.       [/equip/i, %Q{@command_window.output.print(
  49.                     "start_selection @actor.equips")
  50.                     activate_equip_selection}],
  51.       [/exit/i,  %Q{return_scene}],
  52.       [/next/i,  %Q{next_actor}],
  53.       [/prev/i,  %Q{prev_actor}]
  54.     ]
  55.   end
  56.   module Status
  57.     SCRIPTS = [
  58.       [/next/i,  %Q{next_actor}],
  59.       [/prev/i,  %Q{prev_actor}],
  60.       [/exit/i,  %Q{return_scene}]
  61.     ]
  62.   end
  63.   module General
  64.     SCRIPTS = [
  65.       [/[\$game_party\.]gold/i,   %Q{@command_window.output.print(
  66.           "$game_party.gold == \#{$game_party.gold}")}],
  67.       [/(?:\$game_party|PARTY)[\.members](?: |\.)size/, %Q{@command_window.output.print(
  68.           "$game_party.members.size == \#{$game_party.members.size}")}],
  69.       [/calc (.*)/i, %Q{value = eval($1)
  70.                                 @command_window.output.print("Result \#{value}")}]
  71.     ]
  72.   end
  73. end
  74.  
  75. class Scene_Menu < Scene_Base
  76.  
  77.   alias zmenu_start start
  78.   def start
  79.     zmenu_start
  80.     @status_window.x = 35
  81.     @status_window.y = 0
  82.     @gold_window.x = 640
  83.     @status_window.opacity = 0
  84.   end
  85.  
  86.   def create_command_window
  87.     @command_window = Scriptletter.new(0, 424, 640)
  88.     @command_window.create_output(6)
  89.   end
  90.  
  91.   def update_command_selection
  92.     if JetInput.trigger?(JetInput::ESCAPE)
  93.       Sound.play_cancel
  94.       $scene = Scene_Map.new
  95.     elsif JetInput.trigger?(JetInput::RETURN)
  96.       run_regexp(@command_window.text)
  97.     end
  98.   end
  99.  
  100.   def update
  101.     super
  102.     update_menu_background
  103.     @gold_window.update
  104.     @status_window.update
  105.     @command_window.update
  106.     if @status_window.active
  107.       update_actor_selection
  108.     else
  109.       update_command_selection
  110.     end
  111.    
  112.   end
  113.  
  114.   def update_actor_selection
  115.     if JetInput.trigger?(JetInput::ESCAPE)
  116.       Sound.play_cancel
  117.       end_actor_selection
  118.     elsif JetInput.trigger?(JetInput::RETURN)
  119.       $game_party.last_actor_index = @status_window.index
  120.       Sound.play_decision
  121.       $scene = eval($next)
  122.     end
  123.   end
  124.  
  125.   def run_regexp(string)
  126.     for param in Z::Menu::SCRIPTS + Z::General::SCRIPTS
  127.       if string =~ param[0]
  128.         eval(param[1])
  129.         @command_window.clear
  130.         return
  131.       end
  132.     end
  133.     @command_window.output.print("No Command '#{@command_window.text}' found!")
  134.     @command_window.clear
  135.   end
  136.  
  137.   def start_actor_selection
  138.     @command_window.active = false
  139.     @status_window.active = true
  140.     if $game_party.last_actor_index < @status_window.item_max
  141.       @status_window.index = $game_party.last_actor_index
  142.     else
  143.       @status_window.index = 0
  144.     end
  145.   end
  146.  
  147. end
  148.  
  149. class Window_MenuStatus < Window_Selectable
  150.  
  151.   def initialize(x, y)
  152.     super(x, y, 570, 304)
  153.     refresh
  154.     self.active = false
  155.     self.index = -1
  156.     @column_max = 2
  157.     @spacing = 4
  158.     refresh
  159.   end
  160.  
  161.   def refresh
  162.     self.contents.clear
  163.     @item_max = $game_party.members.size
  164.     for actor in $game_party.members
  165.       rect = item_rect(actor.index)
  166.       x = rect.x + 6; y = rect.y + 19
  167.       draw_actor_face(actor, x+2, y-10, 92)
  168.       draw_actor_name(actor, x + 100, y)
  169.       draw_actor_class(actor, x + 100, y+WLH)
  170.       draw_actor_level(actor, x+ 192, y + WLH*1)
  171.       draw_actor_hp(actor,    x+100, y + WLH * 2, 148)
  172.       draw_actor_mp(actor,    x+100, y + WLH * 3, 148)
  173.       draw_actor_state(actor, x, y + WLH * 4 - 12)
  174.     end
  175.   end
  176.  
  177.   def update_cursor
  178.     if @index < 0
  179.       self.cursor_rect.empty
  180.     elsif @index < @item_max or @index >= 100
  181.       rect = item_rect(@index)
  182.       self.cursor_rect.set(rect.x, rect.y, rect.width, rect.height)
  183.     else
  184.       self.cursor_rect.set(0, 0, contents.width, contents.height)
  185.     end
  186.   end
  187.  
  188.   def item_rect(index)
  189.     rect = Rect.new(0, 0, 0, 0)
  190.     rect.width  = self.contents.width  / @column_max - @spacing
  191.     rect.height = self.contents.height / (Game_Party::MAX_MEMBERS / @column_max) - @spacing
  192.     rect.x = index % @column_max * (rect.width  + 4) + @spacing/2
  193.     rect.y = index / @column_max * (rect.height + 4) + @spacing/2
  194.     return rect
  195.   end
  196.  
  197. end
  198.  
  199. class Scene_Base
  200.  
  201.   def create_menu_background
  202.     @menuback_sprite = Sprite.new
  203.     @menuback_sprite.bitmap = $game_temp.background_bitmap
  204.     @menuback_sprite.color.set(16, 16, 16, 255)
  205.     update_menu_background
  206.   end
  207.  
  208. end
  209.  
  210. class Scene_File < Scene_Base
  211.  
  212.   def force_save(index)
  213.     Sound.play_decision
  214.     file = File.open(@savefile_windows[index].filename, "wb")
  215.     write_save_data(file)
  216.     file.close
  217.   end
  218.  
  219. end
  220.  
  221.  
  222.  
  223.  
  224. class Scene_Status < Scene_Base
  225.  
  226.   alias zstatus_start start unless $@
  227.   def start
  228.     zstatus_start
  229.     @status_window.opacity = 0
  230.     create_output
  231.   end
  232.  
  233.   alias zstatus_terminate terminate unless $@
  234.   def terminate
  235.     zstatus_terminate
  236.     @command_window.dispose
  237.   end
  238.  
  239.   def update
  240.     update_menu_background
  241.     @status_window.update
  242.     @command_window.update
  243.     if JetInput.trigger?(JetInput::ESCAPE)
  244.       Sound.play_cancel
  245.       return_scene
  246.     end
  247.     update_command_selection
  248.     super
  249.   end
  250.  
  251.   def create_output
  252.     @command_window = Scriptletter.new(0, 424, 640)
  253.     @command_window.create_output(6)
  254.   end
  255.  
  256.   def run_regexp(string)
  257.     for param in Z::Status::SCRIPTS + Z::General::SCRIPTS
  258.       if string =~ param[0]
  259.         eval(param[1])
  260.         @command_window.clear
  261.         return
  262.       end
  263.     end
  264.     @command_window.output.print("No Command '#{@command_window.text}' found!")
  265.     @command_window.clear
  266.   end
  267.  
  268.   def update_command_selection
  269.     if JetInput.trigger?(JetInput::ESCAPE)
  270.       Sound.play_cancel
  271.       return_scene
  272.     elsif JetInput.trigger?(JetInput::RETURN) and @command_window.text != ""
  273.       run_regexp(@command_window.text)
  274.     end
  275.   end
  276.  
  277. end
  278.  
  279.  
  280.  
  281.  
  282. class Scene_Skill < Scene_Base
  283.  
  284.   alias zskill_start start unless $@
  285.   def start
  286.     zskill_start
  287.     @skill_window.height  -= 96
  288.     @skill_window.active   = false
  289.     @skill_window.opacity  = 0
  290.     @help_window.opacity   = 0
  291.     @status_window.opacity = 0
  292.     create_output
  293.   end
  294.  
  295.   alias zskill_terminate terminate unless $@
  296.   def terminate
  297.     zskill_terminate
  298.     @command_window.dispose
  299.   end
  300.  
  301.   alias zskill_update update unless $@
  302.   def update
  303.     @command_window.update
  304.     zskill_update
  305.     update_command_selection if @command_window.active
  306.   end
  307.  
  308.   def update_skill_selection
  309.     if JetInput.trigger?(JetInput::ESCAPE)
  310.       Sound.play_cancel
  311.       return_command_selection
  312.     elsif JetInput.trigger?(JetInput::RETURN)
  313.       @skill = @skill_window.skill
  314.       if @skill != nil
  315.         @actor.last_skill_id = @skill.id
  316.       end
  317.       if @actor.skill_can_use?(@skill)
  318.         Sound.play_decision
  319.         determine_skill
  320.       else
  321.         Sound.play_buzzer
  322.       end
  323.     end
  324.   end
  325.  
  326.   def activate_skill_selection
  327.     @command_window.active = false
  328.     @skill_window.active   = true
  329.   end
  330.  
  331.   def return_command_selection
  332.     @command_window.active = true
  333.     @skill_window.active   = false
  334.   end
  335.  
  336.   def create_output
  337.     @command_window = Scriptletter.new(0, 424, 640)
  338.     @command_window.create_output(3)
  339.   end
  340.  
  341.   def run_regexp(string)
  342.     for param in Z::Skill::SCRIPTS + Z::General::SCRIPTS
  343.       if string =~ param[0]
  344.         eval(param[1])
  345.         @command_window.clear
  346.         return
  347.       end
  348.     end
  349.     @command_window.output.print("No Command '#{@command_window.text}' found!")
  350.     @command_window.clear
  351.   end
  352.  
  353.   def update_command_selection
  354.     if JetInput.trigger?(JetInput::ESCAPE)
  355.       Sound.play_cancel
  356.       return_scene
  357.     elsif JetInput.trigger?(JetInput::RETURN) and @command_window.text != ""
  358.       run_regexp(@command_window.text)
  359.     end
  360.   end
  361.  
  362. end
  363.  
  364.  
  365.  
  366.  
  367. #==============================================================================
  368. # ** Scene_Item
  369. #------------------------------------------------------------------------------
  370. #  This class performs the item screen processing.
  371. #==============================================================================
  372.  
  373. class Scene_Item < Scene_Base
  374.  
  375.   alias zitem_start start unless $@
  376.   def start
  377.     zitem_start
  378.     @item_window.height -= 96
  379.     @item_window.opacity = 0
  380.     @help_window.opacity = 0
  381.     @item_window.active  = false
  382.     create_output(3)
  383.   end
  384.  
  385.   alias zitem_terminate terminate unless $@
  386.   def terminate
  387.     zitem_terminate
  388.     @command_window.dispose
  389.   end
  390.  
  391.   alias zitem_update update unless $@
  392.   def update
  393.     @command_window.update
  394.     zitem_update
  395.     update_command_selection if @command_window.active
  396.   end
  397.  
  398.   def update_item_selection
  399.     if JetInput.trigger?(JetInput::ESCAPE)
  400.       Sound.play_cancel
  401.       return_command_selection
  402.     elsif JetInput.trigger?(JetInput::RETURN)
  403.       @item = @item_window.item
  404.       if @item != nil
  405.         $game_party.last_item_id = @item.id
  406.       end
  407.       if $game_party.item_can_use?(@item)
  408.         Sound.play_decision
  409.         determine_item
  410.       else
  411.         Sound.play_buzzer
  412.       end
  413.     end
  414.   end
  415.  
  416.   def return_command_selection
  417.     @item_window.active = false
  418.     @command_window.active = true
  419.   end
  420.  
  421.   def activate_item_selection
  422.     @item_window.active = true
  423.     @command_window.active = false
  424.   end
  425.  
  426.   def create_output(lines)
  427.     @command_window = Scriptletter.new(0, 424, 640)
  428.     @command_window.create_output(lines)
  429.   end
  430.  
  431.   def run_regexp(string)
  432.     for param in Z::Item::SCRIPTS + Z::General::SCRIPTS
  433.       if string =~ param[0]
  434.         eval(param[1])
  435.         @command_window.clear
  436.         return
  437.       end
  438.     end
  439.     @command_window.output.print("No Command '#{@command_window.text}' found!")
  440.     @command_window.clear
  441.   end
  442.  
  443.   def update_command_selection
  444.     if JetInput.trigger?(JetInput::ESCAPE)
  445.       Sound.play_cancel
  446.       return_scene
  447.     elsif JetInput.trigger?(JetInput::RETURN) and @command_window.text != ""
  448.       run_regexp(@command_window.text)
  449.     end
  450.   end
  451.  
  452. end
  453.  
  454.  
  455.  
  456.  
  457. class Scene_Equip < Scene_Base
  458.  
  459.   alias zequip_start start unless $@
  460.   def start
  461.     zequip_start
  462.     @equip_window.height  -= 24
  463.     @equip_window.opacity = 0
  464.     @status_window.height -= 24
  465.     @status_window.opacity = 0
  466.     create_output(3)
  467.     @equip_window.active = false
  468.   end
  469.  
  470.   alias zequip_terminate terminate unless $@
  471.   def terminate
  472.     zequip_terminate
  473.   end
  474.  
  475.   alias zequip_create_item_windows create_item_windows unless $@
  476.   def create_item_windows
  477.     zequip_create_item_windows
  478.     for i in 0...EQUIP_TYPE_MAX
  479.       @item_windows[i].opacity = 0
  480.       @item_windows[i].y -= 24
  481.       @item_windows[i].height -= 72
  482.     end
  483.   end
  484.  
  485.   alias zequip_update_status_window update_status_window unless $@
  486.   def update_status_window
  487.     return if @item_window.nil?
  488.     zequip_update_status_window
  489.   end
  490.  
  491.   def update_equip_selection
  492.     if Input.trigger?(Input::B)
  493.       Sound.play_cancel
  494.       return_command_selection
  495.     elsif Input.trigger?(Input::R)
  496.       Sound.play_cursor
  497.       next_actor
  498.     elsif Input.trigger?(Input::L)
  499.       Sound.play_cursor
  500.       prev_actor
  501.     elsif Input.trigger?(Input::C)
  502.       if @actor.fix_equipment
  503.         Sound.play_buzzer
  504.       else
  505.         Sound.play_decision
  506.         @equip_window.active = false
  507.         @item_window.active = true
  508.         @item_window.index = 0
  509.       end
  510.     end
  511.   end
  512.  
  513.   alias zequip_update update unless $@
  514.   def update
  515.     @command_window.update
  516.     zequip_update
  517.     update_command_selection if @command_window.active
  518.   end
  519.  
  520.   def return_command_selection
  521.     @equip_window.active = false
  522.     @command_window.active = true
  523.   end
  524.  
  525.   def activate_equip_selection
  526.     @equip_window.active = true
  527.     @command_window.active = false
  528.   end
  529.  
  530.   def create_output(lines)
  531.     @command_window = Scriptletter.new(0, 424, 640)
  532.     @command_window.create_output(lines)
  533.   end
  534.  
  535.   def run_regexp(string)
  536.     for param in Z::Equip::SCRIPTS + Z::General::SCRIPTS
  537.       if string =~ param[0]
  538.         eval(param[1])
  539.         @command_window.clear
  540.         return
  541.       end
  542.     end
  543.     @command_window.output.print("No Command '#{@command_window.text}' found!")
  544.     @command_window.clear
  545.   end
  546.  
  547.   def update_command_selection
  548.     if JetInput.trigger?(JetInput::ESCAPE)
  549.       Sound.play_cancel
  550.       return_scene
  551.     elsif JetInput.trigger?(JetInput::RETURN) and @command_window.text != ""
  552.       run_regexp(@command_window.text)
  553.     end
  554.   end
  555.  
  556. end
Advertisement
Add Comment
Please, Sign In to add comment