neutale

Simple Menu by VitorJ

Nov 18th, 2019
1,318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.66 KB | None | 0 0
  1. #==============================================================================
  2. # Simple Menu by VitorJ (http://vjrgss.blogspot.com/)
  3. #-Funcao-----------------------------------------------------------------------
  4. # Modifica o menu padrao.
  5. #-Nome do mapa-----------------------------------------------------------------
  6. # O nome que aparecera na area de nome do mapa sera o nome escolhido para
  7. # exibicao, caso nao tenha um, ele ira procurar o seguinte comando na nota do
  8. # mapa: <mname>Nome do Mapa</mname>
  9. # Onde o nome do mapa deve ser posto, nao e necessario estar entre aspas.
  10. #==============================================================================
  11. module VJSM
  12.   Icons = []
  13.   #Icones para as opcoes
  14.   Icons[0] = 261                          #Item
  15.   Icons[1] = 116                          #Habilidade
  16.   Icons[2] = 164                          #Equipamento
  17.   Icons[3] = 121                          #Status
  18.   Icons[4] = 12                           #Formaзгo
  19.   Icons[5] = 117                          #Salvar
  20.   Icons[6] = 1                            #Sair
  21.   ##
  22.   Next = "Next"                           #Proximo level
  23.   Gold_Icon = 361                         #Icone do gold
  24.   PlayTime_Icon = 280                     #Icone do tempo de jogo
  25.   Map_Icon = 231                          #Icone do mapa atual
  26.   File = "File"                           #Opзгo de file
  27. end
  28.  
  29. class Window_MenuStatus < Window_Selectable
  30.   attr_reader   :pending_index
  31.   def initialize(x, y)
  32.     super(x, y, window_width, window_height)
  33.     @pending_index = -1
  34.     refresh
  35.   end
  36.   def window_width
  37.     Graphics.width
  38.   end
  39.   def window_height
  40.     Graphics.height - 96
  41.   end
  42.   def item_max
  43.     $game_party.members.size
  44.   end
  45.   def col_max
  46.     return 2
  47.   end
  48.   def item_height
  49.     (height - standard_padding * 2) / 2
  50.   end
  51.   def draw_item(index)
  52.     actor = $game_party.members[index]
  53.     enabled = $game_party.battle_members.include?(actor)
  54.     rect = item_rect(index)
  55.     draw_item_background(index)
  56.     draw_actor_name(actor, rect.x+1, rect.y+1)
  57.     draw_actor_face(actor, rect.x+1, rect.y+1 + line_height, enabled)
  58.     draw_actor_class(actor, rect.x+1, (rect.y+rect.height) - (line_height+1))
  59.     draw_actor_level(actor, rect.x+98+16, rect.y+1)
  60.     draw_exp_info(actor, rect.x+98+16, rect.y + line_height)
  61.     draw_actor_hp(actor, rect.x+98+16, rect.y + line_height * 2)
  62.     draw_actor_mp(actor, rect.x+98+16, rect.y + line_height * 3)
  63.     draw_actor_icons(actor, rect.x+98+16, rect.y + line_height * 4)
  64.   end
  65.   def draw_actor_icons(actor, x, y, width = 128)
  66.     icons = (actor.state_icons + actor.buff_icons)
  67.     i = 0
  68.     icons.each do |icon|
  69.       ix = x+(i*24)
  70.       iy = y+(0)
  71.       if i >= 5
  72.         ix = x+((i-5)*24)
  73.         iy = y+(24)
  74.       end
  75.       draw_icon(icon, ix, iy)
  76.       i+= 1
  77.     end
  78.   end
  79.   def draw_exp_info(actor, x, y)
  80.     s2 = actor.max_level? ? "-------" : actor.next_level_exp - actor.exp
  81.     s_next = VJSM::Next
  82.     change_color(system_color)
  83.     draw_text(x, y, 128, line_height, s_next)
  84.     change_color(normal_color)
  85.     draw_text(x, y, 128, line_height, s2, 2)
  86.   end
  87.   def draw_item_background(index)
  88.     if index == @pending_index
  89.       contents.fill_rect(item_rect(index), pending_color)
  90.     end
  91.   end
  92.   def process_ok
  93.     super
  94.     $game_party.menu_actor = $game_party.members[index]
  95.   end
  96.   def select_last
  97.     select($game_party.menu_actor.index || 0)
  98.   end
  99.   def pending_index=(index)
  100.     last_pending_index = @pending_index
  101.     @pending_index = index
  102.     redraw_item(@pending_index)
  103.     redraw_item(last_pending_index)
  104.   end
  105. end
  106. class Window_NewMenuStatus < Window_Base
  107.   def initialize(actor)
  108.     super(0, 0, Graphics.width - 160, 120)
  109.     @actor = actor
  110.     refresh
  111.   end
  112.   def set_actor(actor)
  113.     return if actor == @actor
  114.     @actor = actor
  115.     refresh
  116.   end
  117.   def refresh
  118.     contents.clear
  119.     actor = @actor
  120.     enabled = $game_party.battle_members.include?(actor)
  121.     draw_actor_face(actor,1, 1, enabled)
  122.     draw_actor_simple_status(actor, 108, line_height / 2)
  123.   end
  124. end
  125. class Window_Time < Window_Base
  126.   def initialize(x,y)
  127.     super(x, y, Graphics.width/3, 48)
  128.     refresh
  129.   end
  130.   def update
  131.     refresh
  132.   end
  133.   def refresh
  134.     contents.clear
  135.     playtime = $game_system.playtime_s
  136.     draw_icon(VJSM::PlayTime_Icon, 0, 0)
  137.     change_color(normal_color)
  138.     draw_text(0, 0, self.contents.width, line_height, playtime, 2)
  139.   end
  140. end
  141. class Window_MenuGold < Window_Base
  142.   def initialize(x,y)
  143.     super(x, y, Graphics.width/3, 48)
  144.     refresh
  145.   end
  146.   def refresh
  147.     contents.clear
  148.     gold = $game_party.gold
  149.     draw_icon(VJSM::Gold_Icon, 0, 0)
  150.     change_color(normal_color)
  151.     draw_text(0, 0, self.contents.width, line_height, gold, 2)
  152.   end
  153. end
  154. class Window_MenuMapName < Window_Base
  155.   def initialize(x,y)
  156.     super(x, y, (Graphics.width/3)*2, 48)
  157.     refresh
  158.   end
  159.   def refresh
  160.     contents.clear
  161.     if $game_map.display_name.empty?
  162.       map_a = load_data(sprintf("Data/Map%03d.rvdata2", $game_map.map_id))
  163.       note = map_a.note.split("\r\n")
  164.       text = "Nome da mapa nгo definido"
  165.       note.each do |thing|
  166.         if thing.include?("<mname>")
  167.           text = thing
  168.           text.slice!("<mname>")
  169.           text.slice!("</mname>")
  170.         end
  171.       end
  172.       map = text
  173.     else
  174.       map = $game_map.display_name
  175.     end
  176.     change_color(normal_color)
  177.     draw_icon(VJSM::Map_Icon, 0, 0)
  178.     draw_text(0, 0, self.contents.width, line_height, map, 2)
  179.   end
  180. end
  181. class Window_Command_Name < Window_Base
  182.   def initialize(text,w=171)
  183.     super(0, 0, w, 48)
  184.     @text = text
  185.     refresh
  186.   end
  187.   def refresh
  188.     contents.clear
  189.     draw_text(0, 0, self.contents.width, self.contents.height, @text, 1)
  190.   end
  191.   def set_text(text)
  192.     return if text == @text
  193.     @text = text
  194.     refresh
  195.   end
  196. end
  197. class Window_MenuFile < Window_Command
  198.   def initialize
  199.     super(0, 0)
  200.     update_placement
  201.   end
  202.   def window_width
  203.     return 160
  204.   end
  205.   def update_placement
  206.     self.x = (Graphics.width - width) / 2
  207.     self.y = (Graphics.height - height) / 2
  208.   end
  209.   def make_command_list
  210.     add_command(Vocab::save, :save, save_enabled)
  211.     add_command(Vocab::continue, :continue)
  212.     add_command(Vocab::cancel,   :cancel)
  213.   end
  214.   def save_enabled
  215.     !$game_system.save_disabled
  216.   end
  217. end
  218. class Window_MenuCommand < Window_Command
  219.   def self.init_command_position
  220.     @@last_command_symbol = nil
  221.   end
  222.   def initialize
  223.     super(0, 0)
  224.     select_last
  225.   end
  226.   def item_rect(index)
  227.     rect = Rect.new
  228.     rect.width = item_width
  229.     rect.height = item_height
  230.     rect.x = index % col_max * item_width
  231.     rect.y = index / col_max * item_height
  232.     rect
  233.   end
  234.   def item_width
  235.     return 24
  236.   end
  237.   def window_width
  238.     return 192
  239.   end
  240.   def window_height
  241.     return 48
  242.   end
  243.   def col_max
  244.     return 8
  245.   end
  246.   def visible_line_number
  247.     item_max
  248.   end
  249.   def make_command_list
  250.     add_main_commands
  251.     add_formation_command
  252.     add_original_commands
  253.     add_save_command
  254.     add_game_end_command
  255.   end
  256.   def draw_item(index)
  257.     x = item_rect(index).x
  258.     y = item_rect(index).y
  259.     draw_icon(VJSM::Icons[index], x, y, command_enabled?(index))
  260.   end
  261.   def add_main_commands
  262.     add_command(Vocab::item,   :item,   main_commands_enabled)
  263.     add_command(Vocab::skill,  :skill,  main_commands_enabled)
  264.     add_command(Vocab::equip,  :equip,  main_commands_enabled)
  265.     add_command(Vocab::status, :status, main_commands_enabled)
  266.   end
  267.   def add_formation_command
  268.     add_command(Vocab::formation, :formation, formation_enabled)
  269.   end
  270.   def get_name(index)
  271.     return command_name(index)
  272.   end
  273.   def add_original_commands
  274.   end
  275.   def add_save_command
  276.     add_command(VJSM::File, :file)
  277.   end
  278.   def add_game_end_command
  279.     add_command(Vocab::game_end, :game_end)
  280.   end
  281.   def main_commands_enabled
  282.     $game_party.exists
  283.   end
  284.   def formation_enabled
  285.     $game_party.members.size >= 2 && !$game_system.formation_disabled
  286.   end
  287.   def save_enabled
  288.     !$game_system.save_disabled
  289.   end
  290.   def process_ok
  291.     @@last_command_symbol = current_symbol
  292.     super
  293.   end
  294.   def select_last
  295.     select_symbol(@@last_command_symbol)
  296.   end
  297. end
  298. class Scene_Menu < Scene_MenuBase
  299.   #--------------------------------------------------------------------------
  300.   # * Inicializaзгo do processo
  301.   #--------------------------------------------------------------------------
  302.   def start
  303.     super
  304.     create_command_window
  305.     create_gold_window
  306.     create_status_window
  307.     create_time_window
  308.     create_map_window
  309.   end
  310.   #--------------------------------------------------------------------------
  311.   # * Criaзгo da janela de comando
  312.   #--------------------------------------------------------------------------
  313.   def create_command_window
  314.     @command_window = Window_MenuCommand.new
  315.     @command_window.set_handler(:item,      method(:command_item))
  316.     @command_window.set_handler(:skill,     method(:command_personal))
  317.     @command_window.set_handler(:equip,     method(:command_personal))
  318.     @command_window.set_handler(:status,    method(:command_personal))
  319.     @command_window.set_handler(:formation, method(:command_formation))
  320.     @command_window.set_handler(:file,      method(:command_file))
  321.     @command_window.set_handler(:game_end,  method(:command_game_end))
  322.     @command_window.set_handler(:cancel,    method(:return_scene))
  323.     @command_window.y = 0
  324.     @command_window.x = 0
  325.     @command_name = Window_Command_Name.new(@command_window.get_name(@command_window.index))
  326.     @command_name.y = @command_window.y
  327.     @command_name.x = @command_window.x + @command_window.width
  328.     @menu_file = Window_MenuFile.new
  329.     @menu_file.set_handler(:save,      method(:command_save))
  330.     @menu_file.set_handler(:continue,     method(:command_continue))
  331.     @menu_file.set_handler(:cancel,     method(:command_cancel))
  332.     @menu_file.visible = false
  333.     @menu_file.active = false
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # * Criaзгo da janela de dinheiro
  337.   #--------------------------------------------------------------------------
  338.   def create_gold_window
  339.     x = @command_name.x + @command_name.width
  340.     y = @command_name.y
  341.     @gold_window = Window_MenuGold.new(x,y)
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # * Criaзгo da janela de atributos
  345.   #--------------------------------------------------------------------------
  346.   def create_status_window
  347.     x = @command_window.x
  348.     y = @command_window.y  + @command_window.height
  349.     @status_window = Window_MenuStatus.new(x, y)
  350.   end
  351.   def create_time_window
  352.     y = @status_window.y + @status_window.height
  353.     x = 0
  354.     @window_time = Window_Time.new(x,y)
  355.   end
  356.   def create_map_window
  357.     y = @window_time.y
  358.     x = @window_time.x + @window_time.width
  359.     @window_map = Window_MenuMapName.new(x,y)
  360.   end
  361.   def update
  362.     update_basic
  363.     @command_name.set_text(@command_window.get_name(@command_window.index))
  364.   end
  365.   #--------------------------------------------------------------------------
  366.   # * Comando [Item]
  367.   #--------------------------------------------------------------------------
  368.   def command_item
  369.     SceneManager.call(Scene_Item)
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # * Comando [Habilidade] [Equipamentos] [Atributos]
  373.   #--------------------------------------------------------------------------
  374.   def command_personal
  375.     @status_window.select_last
  376.     @status_window.activate
  377.     @status_window.set_handler(:ok,     method(:on_personal_ok))
  378.     @status_window.set_handler(:cancel, method(:on_personal_cancel))
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # * Comando [Formaзгo]
  382.   #--------------------------------------------------------------------------
  383.   def command_formation
  384.     @status_window.select_last
  385.     @status_window.activate
  386.     @status_window.set_handler(:ok,     method(:on_formation_ok))
  387.     @status_window.set_handler(:cancel, method(:on_formation_cancel))
  388.   end
  389.   #--------------------------------------------------------------------------
  390.   # * Comando [Salvar]
  391.   #--------------------------------------------------------------------------
  392.   def command_save
  393.     SceneManager.call(Scene_Save)
  394.   end
  395.   def command_file
  396.     @menu_file.visible = true
  397.     @menu_file.index = 0
  398.     @menu_file.activate
  399.     @menu_file.z = @status_window.z + 1
  400.   end
  401.   def command_cancel
  402.     @menu_file.unselect
  403.     @menu_file.visible = false
  404.     @menu_file.active = false
  405.     @menu_file.z = @status_window.z - 1
  406.     @command_window.active = true
  407.   end
  408.   def command_continue
  409.     SceneManager.call(Scene_Load)
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # * Comando [Fim do Jogo]
  413.   #--------------------------------------------------------------------------
  414.   def command_game_end
  415.     SceneManager.call(Scene_End)
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # * Comandos individuais [Confirmaзгo]
  419.   #--------------------------------------------------------------------------
  420.   def on_personal_ok
  421.     case @command_window.current_symbol
  422.     when :skill
  423.       SceneManager.call(Scene_Skill)
  424.     when :equip
  425.       SceneManager.call(Scene_Equip)
  426.     when :status
  427.       SceneManager.call(Scene_Status)
  428.     end
  429.   end
  430.   #--------------------------------------------------------------------------
  431.   # * Comandos individuais [Cancelamento]
  432.   #--------------------------------------------------------------------------
  433.   def on_personal_cancel
  434.     @status_window.unselect
  435.     @command_window.activate
  436.   end
  437.   #--------------------------------------------------------------------------
  438.   # * Mudanзa de Ordem [Confirmaзгo]
  439.   #--------------------------------------------------------------------------
  440.   def on_formation_ok
  441.     if @status_window.pending_index >= 0
  442.       $game_party.swap_order(@status_window.index,
  443.                              @status_window.pending_index)
  444.       @status_window.pending_index = -1
  445.       @status_window.redraw_item(@status_window.index)
  446.     else
  447.       @status_window.pending_index = @status_window.index
  448.     end
  449.     @status_window.activate
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # * Mudanзa de Ordem [Cancelamento]
  453.   #--------------------------------------------------------------------------
  454.   def on_formation_cancel
  455.     if @status_window.pending_index >= 0
  456.       @status_window.pending_index = -1
  457.       @status_window.activate
  458.     else
  459.       @status_window.unselect
  460.       @command_window.activate
  461.     end
  462.   end
  463. end
Advertisement
Add Comment
Please, Sign In to add comment