Advertisement
Zetu

Dynamic Menu System v1.02

Jul 8th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.75 KB | None | 0 0
  1. #===============================================================================
  2. # Dynamic Script Menu v1.02 by Zetu
  3. #===============================================================================
  4.  
  5. module Z
  6.   module Menu
  7.    
  8.     SCRIPTS = [
  9.       #/regex/, script call.
  10.       [/item/i,   %Q{$scene = Scene_Item.new}],
  11.       [/skill/i,  %Q{$next = "Scene_Skill.new(@status_window.index)"
  12.                         start_actor_selection}],
  13.       [/equip/i,  %Q{$next = "Scene_Equip.new(@status_window.index)"
  14.                         start_actor_selection}],
  15.       [/status/i,    %Q{$next = "Scene_Status.new(@status_window.index)"
  16.                         start_actor_selection}],
  17.       [/save/i,      %Q{$scene = Scene_File.new(true, false, false)}],
  18.       [/end/i,       %Q{$scene = Scene_End.new}]
  19.     ]
  20.    
  21.   end
  22. end
  23.  
  24. class Scene_Menu < Scene_Base
  25.  
  26.   alias zmenu_start start
  27.   def start
  28.     zmenu_start
  29.     @status_window.x = 35
  30.     @status_window.y = 88
  31.     @gold_window.y = 0
  32.   end
  33.  
  34.   def create_command_window
  35.     @command_window = Scriptletter.new(0, 424, 640)
  36.   end
  37.  
  38.   def update_command_selection
  39.     JetInput.update
  40.     if Input.trigger?(Input::B)
  41.       Sound.play_cancel
  42.       $scene = Scene_Map.new
  43.     elsif JetInput.trigger?(JetInput::RETURN)
  44.       JetInput.update
  45.       run_regexp(@command_window.text)
  46.     end
  47.   end
  48.  
  49.   def update
  50.     super
  51.     update_menu_background
  52.     @command_window.update
  53.     @gold_window.update
  54.     @status_window.update
  55.     if @status_window.active
  56.       update_actor_selection
  57.     else
  58.       update_command_selection
  59.     end
  60.   end
  61.  
  62.   def update_actor_selection
  63.     JetInput.update
  64.     if Input.trigger?(Input::B)
  65.       Sound.play_cancel
  66.       end_actor_selection
  67.     elsif JetInput.trigger?(JetInput::RETURN)
  68.       $game_party.last_actor_index = @status_window.index
  69.       Sound.play_decision
  70.       $scene = eval($next)
  71.     end
  72.   end
  73.  
  74.   def run_regexp(string)
  75.     @command_window.clear
  76.     for param in Z::Menu::SCRIPTS
  77.       if string =~ param[0]
  78.         eval(param[1])
  79.         return
  80.       end
  81.     end
  82.     print "No command found!"
  83.   end
  84.  
  85.   def start_actor_selection
  86.     @command_window.active = false
  87.     @status_window.active = true
  88.     if $game_party.last_actor_index < @status_window.item_max
  89.       @status_window.index = $game_party.last_actor_index
  90.     else
  91.       @status_window.index = 0
  92.     end
  93.   end
  94.  
  95. end
  96.  
  97. class Window_MenuStatus < Window_Selectable
  98.  
  99.   def initialize(x, y)
  100.     super(x, y, 570, 304)
  101.     refresh
  102.     self.active = false
  103.     self.index = -1
  104.     @column_max = 2
  105.     @spacing = 4
  106.     refresh
  107.   end
  108.  
  109.   def refresh
  110.     self.contents.clear
  111.     @item_max = $game_party.members.size
  112.     for actor in $game_party.members
  113.       rect = item_rect(actor.index)
  114.       x = rect.x + 6; y = rect.y + 19
  115.       draw_actor_face(actor, x+2, y-10, 92)
  116.       draw_actor_name(actor, x + 100, y)
  117.       draw_actor_class(actor, x + 100, y+WLH)
  118.       draw_actor_level(actor, x+ 192, y + WLH*1)
  119.       draw_actor_hp(actor,    x+100, y + WLH * 2, 148)
  120.       draw_actor_mp(actor,    x+100, y + WLH * 3, 148)
  121.       draw_actor_state(actor, x, y + WLH * 4 - 12)
  122.     end
  123.   end
  124.  
  125.   def update_cursor
  126.     if @index < 0
  127.       self.cursor_rect.empty
  128.     elsif @index < @item_max or @index >= 100
  129.       rect = item_rect(@index)
  130.       self.cursor_rect.set(rect.x, rect.y, rect.width, rect.height)
  131.     else
  132.       self.cursor_rect.set(0, 0, contents.width, contents.height)
  133.     end
  134.   end
  135.  
  136.   def item_rect(index)
  137.     rect = Rect.new(0, 0, 0, 0)
  138.     rect.width  = self.contents.width  / @column_max - @spacing
  139.     rect.height = self.contents.height / (Game_Party::MAX_MEMBERS / @column_max) - @spacing
  140.     rect.x = index % @column_max * (rect.width  + 4) + @spacing/2
  141.     rect.y = index / @column_max * (rect.height + 4) + @spacing/2
  142.     return rect
  143.   end
  144.  
  145. end
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167. #===============================================================================
  168. # Dynamic Script Menu v1.02 by Zetu
  169. #===============================================================================
  170.  
  171. module Z
  172.   module Menu
  173.    
  174.     SCRIPTS = [
  175.       #/regex/, script call.
  176.       [/item/i,   %Q{$scene = Scene_Item.new}],
  177.       [/skill/i,  %Q{$next = "Scene_Skill.new(@status_window.index)"
  178.                         start_actor_selection}],
  179.       [/equip/i,  %Q{$next = "Scene_Equip.new(@status_window.index)"
  180.                         start_actor_selection}],
  181.       [/status/i,    %Q{$next = "Scene_Status.new(@status_window.index)"
  182.                         start_actor_selection}],
  183.       [/save/i,      %Q{$scene = Scene_File.new(true, false, false)}],
  184.       [/end/i,       %Q{$scene = Scene_End.new}]
  185.     ]
  186.    
  187.   end
  188. end
  189.  
  190. class Scene_Menu < Scene_Base
  191.  
  192.   alias zmenu_start start
  193.   def start
  194.     zmenu_start
  195.     @status_window.x = 35
  196.     @status_window.y = 88
  197.     @gold_window.y = 0
  198.   end
  199.  
  200.   def create_command_window
  201.     @command_window = Scriptletter.new(0, 424, 640)
  202.   end
  203.  
  204.   def update_command_selection
  205.     JetInput.update
  206.     if Input.trigger?(Input::B)
  207.       Sound.play_cancel
  208.       $scene = Scene_Map.new
  209.     elsif JetInput.trigger?(JetInput::RETURN)
  210.       JetInput.update
  211.       run_regexp(@command_window.text)
  212.     end
  213.   end
  214.  
  215.   def update
  216.     super
  217.     update_menu_background
  218.     @command_window.update
  219.     @gold_window.update
  220.     @status_window.update
  221.     if @status_window.active
  222.       update_actor_selection
  223.     else
  224.       update_command_selection
  225.     end
  226.   end
  227.  
  228.   def update_actor_selection
  229.     JetInput.update
  230.     if Input.trigger?(Input::B)
  231.       Sound.play_cancel
  232.       end_actor_selection
  233.     elsif JetInput.trigger?(JetInput::RETURN)
  234.       $game_party.last_actor_index = @status_window.index
  235.       Sound.play_decision
  236.       $scene = eval($next)
  237.     end
  238.   end
  239.  
  240.   def run_regexp(string)
  241.     @command_window.clear
  242.     for param in Z::Menu::SCRIPTS
  243.       if string =~ param[0]
  244.         eval(param[1])
  245.         return
  246.       end
  247.     end
  248.     print "No command found!"
  249.   end
  250.  
  251.   def start_actor_selection
  252.     @command_window.active = false
  253.     @status_window.active = true
  254.     if $game_party.last_actor_index < @status_window.item_max
  255.       @status_window.index = $game_party.last_actor_index
  256.     else
  257.       @status_window.index = 0
  258.     end
  259.   end
  260.  
  261. end
  262.  
  263. class Window_MenuStatus < Window_Selectable
  264.  
  265.   def initialize(x, y)
  266.     super(x, y, 570, 304)
  267.     refresh
  268.     self.active = false
  269.     self.index = -1
  270.     @column_max = 2
  271.     @spacing = 4
  272.     refresh
  273.   end
  274.  
  275.   def refresh
  276.     self.contents.clear
  277.     @item_max = $game_party.members.size
  278.     for actor in $game_party.members
  279.       rect = item_rect(actor.index)
  280.       x = rect.x + 6; y = rect.y + 19
  281.       draw_actor_face(actor, x+2, y-10, 92)
  282.       draw_actor_name(actor, x + 100, y)
  283.       draw_actor_class(actor, x + 100, y+WLH)
  284.       draw_actor_level(actor, x+ 192, y + WLH*1)
  285.       draw_actor_hp(actor,    x+100, y + WLH * 2, 148)
  286.       draw_actor_mp(actor,    x+100, y + WLH * 3, 148)
  287.       draw_actor_state(actor, x, y + WLH * 4 - 12)
  288.     end
  289.   end
  290.  
  291.   def update_cursor
  292.     if @index < 0
  293.       self.cursor_rect.empty
  294.     elsif @index < @item_max or @index >= 100
  295.       rect = item_rect(@index)
  296.       self.cursor_rect.set(rect.x, rect.y, rect.width, rect.height)
  297.     else
  298.       self.cursor_rect.set(0, 0, contents.width, contents.height)
  299.     end
  300.   end
  301.  
  302.   def item_rect(index)
  303.     rect = Rect.new(0, 0, 0, 0)
  304.     rect.width  = self.contents.width  / @column_max - @spacing
  305.     rect.height = self.contents.height / (Game_Party::MAX_MEMBERS / @column_max) - @spacing
  306.     rect.x = index % @column_max * (rect.width  + 4) + @spacing/2
  307.     rect.y = index / @column_max * (rect.height + 4) + @spacing/2
  308.     return rect
  309.   end
  310.  
  311. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement