Advertisement
thiago_d_d

Custom Menu

Jan 15th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.01 KB | None | 0 0
  1. #===============================================================================
  2. #   http://thiagodd.blogspot.com.br/
  3. # [TSDA] Custom Menu
  4. #    --> Versions 1.0
  5. # by thiago_d_d
  6. #
  7. # -----------------------------------------------------------------------------
  8. # * Features
  9. # -----------------------------------------------------------------------------
  10. #  + Just another menu, with an different design.
  11. #
  12. # -----------------------------------------------------------------------------
  13. # * Install
  14. # -----------------------------------------------------------------------------
  15. #  Put this script in the aditional scripts section.
  16. #
  17. # -----------------------------------------------------------------------------
  18. # * Configuration
  19. # -----------------------------------------------------------------------------
  20. #  Change the below lines.
  21. #===============================================================================
  22. #===============================================================================
  23. # TSDA
  24. #===============================================================================
  25. module TSDA
  26.   #Vocabulary
  27.   REAL_TIME_ST = "Tempo"
  28.   NREAL_TIME_ST = "Tempo de Jogo"
  29.   MENU_WORDS = ["Itens",
  30.       "Habil.",
  31.       "Equip.",
  32.       "Estado",
  33.       "Salvar",
  34.       "Sair"]
  35.   SaveSlot = "Arquivo"
  36.   ClearSlot = "Arquivo Vazio"
  37.   NoMenuInfo = "Não há informação disponível"
  38.   NoMenuItem = "Não há itens no seu bolso de itens"
  39.   HaveSTItems = "Mostrando os %d item(s) de seu bolso de itens"
  40.   HaveMoreSTItems = "Mostrando os primeiros 16 itens de seu bolso de itens"
  41.   Nda = "Nada"
  42.   #It will use real life time?
  43.   REAL_TIME = false
  44.   #Icons indexes
  45.   MENU_ICONS = [32,35,3,149,150,117]
  46.   #Background image
  47.   #  "Black" for none
  48.   #  "Map" if you want the map as BG
  49.   #  "MapFocus" if you want focused map as BG
  50.   #  or any image name if you want custom BG
  51.   BACK_MENU_IMG = "MapFocus"
  52.   #Windows opacity
  53.   MENU_WINDOW_OPACITY = 255
  54. end
  55. #===============================================================================
  56. # Window_Base
  57. #===============================================================================
  58. class Window_Base
  59.   attr_reader    :opening
  60.   attr_reader    :closing
  61. end
  62. #===============================================================================
  63. # Game_Map
  64. #===============================================================================
  65. class Game_Map
  66.   alias menu_bat_init initialize
  67.   #---
  68.   #--------------------------------------------------------------------------
  69.   # initialize
  70.   #--------------------------------------------------------------------------
  71.   def initialize
  72.     menu_bat_init
  73.     @map_info = load_data("Data/MapInfos.rvdata")
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # map_name
  77.   #--------------------------------------------------------------------------
  78.   def map_name
  79.     return @map_info[@map_id].name
  80.   end
  81. end
  82. #===============================================================================
  83. # Scene_Menu
  84. #===============================================================================
  85. class Scene_Menu < Scene_Base
  86.   include TSDA
  87.   #--------------------------------------------------------------------------
  88.   # initialize
  89.   #--------------------------------------------------------------------------
  90.   def initialize(menu_index = 0)
  91.     @menu_index = menu_index
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # start
  95.   #--------------------------------------------------------------------------
  96.   def start
  97.     @playtime_window = Window_PlayTime.new
  98.     @gold_window = Window_GoldMap.new
  99.     @status_window = Window_SEH.new(@menu_index)
  100.     @command_window = Window_MenuCommand.new(@status_window)
  101.     @command_window.index = @menu_index
  102.     if BACK_MENU_IMG == "Map"
  103.       create_menu_background
  104.     elsif BACK_MENU_IMG == "MapFocus"
  105.       @menuback_sprite = Sprite.new
  106.       @menuback_sprite.bitmap = $game_temp.background_bitmap
  107.     elsif !(BACK_MENU_IMG == "Black")
  108.       @menuback_sprite = Sprite.new
  109.       @menuback_sprite.bitmap = Cache.picture(BACK_MENU_IMG)
  110.     end
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # terminate
  114.   #--------------------------------------------------------------------------
  115.   def terminate
  116.     if @menuback_sprite != nil
  117.       @menuback_sprite.dispose
  118.     end
  119.     @playtime_window.dispose
  120.     @gold_window.dispose
  121.     @command_window.dispose
  122.     @status_window.dispose
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # update
  126.   #--------------------------------------------------------------------------
  127.   def update
  128.     if @menuback_sprite != nil
  129.       @menuback_sprite.update
  130.     end
  131.     if @status_window.open_flag
  132.       if !@status_window.opening
  133.         @status_window.open_flag = false
  134.         @status_window.refresh
  135.       end
  136.     end
  137.     @playtime_window.update
  138.     @gold_window.update
  139.     @command_window.update
  140.     @status_window.update
  141.     if @command_window.active
  142.       update_command_selection
  143.     elsif @status_window.active
  144.       update_actor_selection
  145.     end
  146.   end
  147.   #--------------------------------------------------------------------------
  148.   # update_command_selection
  149.   #--------------------------------------------------------------------------
  150.   def update_command_selection
  151.     if Input.trigger?(Input::B)
  152.       Sound.play_cancel
  153.       $scene = Scene_Map.new
  154.     elsif Input.trigger?(Input::C)
  155.       if $game_party.members.size == 0 and @command_window.index < 4
  156.         Sound.play_buzzer
  157.         return
  158.       elsif $game_system.save_disabled and @command_window.index == 4
  159.         Sound.play_buzzer
  160.         return
  161.       end
  162.       Sound.play_decision
  163.       case @command_window.index
  164.       when 0
  165.         $scene = Scene_Item.new
  166.       when 1,2,3
  167.         start_actor_selection
  168.       when 4
  169.         $scene = Scene_File.new(true, false, false)
  170.       when 5
  171.         $scene = Scene_End.new
  172.       end
  173.     end
  174.   end
  175. end
  176. #===============================================================================
  177. # Window_GoldMap
  178. #===============================================================================
  179. class Window_GoldMap < Window_Base
  180.   include TSDA
  181.   #--------------------------------------------------------------------------
  182.   # initialize
  183.   #--------------------------------------------------------------------------
  184.   def initialize
  185.     super(0,0, 544,WLH + 32)
  186.     self.back_opacity = MENU_WINDOW_OPACITY
  187.     refresh
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # refresh
  191.   #--------------------------------------------------------------------------
  192.   def refresh
  193.     self.contents.clear
  194.     if $game_party.members.size > 0
  195.       draw_actor_name($game_party.members[0],0,0)
  196.     end
  197.     self.contents.font.color = system_color
  198.     self.contents.draw_text(0, 0, 512, WLH, $game_map.map_name, 1)
  199.     draw_currency_value($game_party.gold, 388, 0, 120)
  200.   end
  201. end
  202. #===============================================================================
  203. # Window_MenuCommand
  204. #===============================================================================
  205. class Window_MenuCommand < Window_Selectable
  206.   include TSDA
  207.   #--------------------------------------------------------------------------
  208.   # initialize
  209.   #--------------------------------------------------------------------------
  210.   def initialize(status_window)
  211.     super(0,WLH + 32,384,WLH * 2 + 32)
  212.     self.back_opacity = MENU_WINDOW_OPACITY
  213.     @column_max = 6
  214.     @row_max = 1
  215.     @item_max = 6
  216.     self.index = 0
  217.     @status_window = status_window
  218.     refresh
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # update
  222.   #--------------------------------------------------------------------------
  223.   def update
  224.     if @status_window.opening or @status_window.closing
  225.       if cursor_movable?
  226.         last_index = @index
  227.         if Input.repeat?(Input::RIGHT)
  228.           cursor_right(Input.trigger?(Input::RIGHT))
  229.         end
  230.         if Input.repeat?(Input::LEFT)
  231.           cursor_left(Input.trigger?(Input::LEFT))
  232.         end
  233.         if @index != last_index
  234.           Sound.play_cursor
  235.           @status_window.openness = 255
  236.         end
  237.       end
  238.       return
  239.     end
  240.     last_index = @index
  241.     super
  242.     if @index != last_index
  243.       @status_window.openness = 0
  244.       @status_window.menu_index = @index
  245.       @status_window.open
  246.       @status_window.contents.clear
  247.     end
  248.   end
  249.   #--------------------------------------------------------------------------
  250.   # cursor_right
  251.   #--------------------------------------------------------------------------
  252.   def cursor_right(wrap = false)
  253.     if (@index < @item_max - 1 or wrap)
  254.       @index = (@index + 1) % @item_max
  255.     end
  256.   end
  257.   #--------------------------------------------------------------------------
  258.   # cursor_left
  259.   #--------------------------------------------------------------------------
  260.   def cursor_left(wrap = false)
  261.     if (@index > 0 or wrap)
  262.       @index = (@index - 1 + @item_max) % @item_max
  263.     end
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   # item_rect
  267.   #--------------------------------------------------------------------------
  268.   def item_rect(index)
  269.     rect = Rect.new(0, 0, 0, 0)
  270.     r = contents.width / @column_max
  271.     rect.width = r
  272.     rect.height = contents.height
  273.     rect.x = index * r
  274.     rect.y = 0
  275.     return rect
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # update_cursor
  279.   #--------------------------------------------------------------------------
  280.   def update_cursor
  281.     if @index < 0
  282.       self.cursor_rect.empty
  283.     else
  284.       self.cursor_rect = item_rect(@index)
  285.     end
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # refresh
  289.   #--------------------------------------------------------------------------
  290.   def refresh
  291.     self.contents.clear
  292.     enable = [true, true, true, true, true, true]
  293.     if $game_party.members.size == 0
  294.       enable[0] = false
  295.       enable[1] = false
  296.       enable[2] = false
  297.       enable[3] = false
  298.     end
  299.     if $game_system.save_disabled
  300.       enable[4] = false
  301.     end
  302.     for i in 0...6
  303.       draw_icon(MENU_ICONS[i], 5 + 58 * i, 5, enable[i])
  304.       self.contents.draw_text(5 + 58 * i,24,58,WLH,MENU_WORDS[i])
  305.     end
  306.   end
  307. end
  308. #===============================================================================
  309. # Window_SEH
  310. #===============================================================================
  311. class Window_SEH < Window_Selectable
  312.   attr_reader       :menu_index
  313.   attr_accessor     :open_flag
  314.   #---
  315.   include TSDA
  316.   #--------------------------------------------------------------------------
  317.   # initialize
  318.   #--------------------------------------------------------------------------
  319.   def initialize(index)
  320.     super(0,WLH * 3 + 64,544,280)
  321.     self.back_opacity = MENU_WINDOW_OPACITY
  322.     @column_max = $game_party.members.size
  323.     @row_max = 1
  324.     @item_max = $game_party.members.size
  325.     self.index = -1
  326.     @menu_index = index
  327.     @open_flag = false
  328.     refresh
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # item_rect
  332.   #--------------------------------------------------------------------------
  333.   def item_rect(index)
  334.     rect = Rect.new(0, 0, 0, 0)
  335.     r = contents.width / 4
  336.     rect.width = r
  337.     rect.height = contents.height
  338.     rect.x = index * r
  339.     rect.y = 0
  340.     return rect
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # update_cursor
  344.   #--------------------------------------------------------------------------
  345.   def update_cursor
  346.     if @index < 0
  347.       self.cursor_rect.empty
  348.     else
  349.       self.cursor_rect = item_rect(@index)
  350.     end
  351.   end
  352.   #--------------------------------------------------------------------------
  353.   # menu_index=
  354.   #--------------------------------------------------------------------------
  355.   def menu_index=(index)
  356.     @menu_index = index
  357.     @open_flag = true
  358.   end
  359.   #--------------------------------------------------------------------------
  360.   # refresh
  361.   #--------------------------------------------------------------------------
  362.   def refresh
  363.     self.contents.clear
  364.     case @menu_index
  365.     when 0
  366.       refresh_item
  367.     when 1
  368.       refresh_skill
  369.     when 2
  370.       refresh_equip
  371.     when 3
  372.       refresh_status
  373.     when 4
  374.       refresh_save
  375.     when 5
  376.       self.contents.font.color = normal_color
  377.       self.contents.draw_text(0,124 - WLH  / 2,512, WLH,
  378.         NoMenuInfo, 1)
  379.     end
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # refresh_status
  383.   #--------------------------------------------------------------------------
  384.   def refresh_status
  385.     for actor in $game_party.members
  386.       x = actor.index * 128 + 4
  387.       draw_actor_face(actor, x, 4, 92)
  388.       draw_actor_name(actor, x, 94)
  389.       draw_actor_class(actor, x, 94 + WLH)
  390.       draw_actor_level(actor, x, 94 + WLH * 2)
  391.       draw_actor_state(actor, x, 94 + WLH * 3)
  392.       draw_actor_hp(actor, x, 94 + WLH * 4)
  393.       draw_actor_mp(actor, x, 94 + WLH * 5)
  394.     end
  395.   end
  396.   #--------------------------------------------------------------------------
  397.   # refresh_item
  398.   #--------------------------------------------------------------------------
  399.   def refresh_item
  400.     if $game_party.items.size > 0
  401.       self.contents.font.color = system_color
  402.       if $game_party.items.size <= 16
  403.         self.contents.draw_text(0,0,512, WLH,
  404.           sprintf(HaveSTItems, $game_party.items.size), 1)
  405.         data = []
  406.         for i in 0...$game_party.items.size
  407.           data.push($game_party.items[i])
  408.         end
  409.         for i in 0...data.size
  410.           draw_item(i, data[i])
  411.         end
  412.       else
  413.         self.contents.draw_text(0,0,512, WLH,
  414.           HaveMoreSTItems, 1)
  415.         data = []
  416.         counter = 0
  417.         for i in 0...16
  418.           data.push($game_party.items[i])
  419.         end
  420.         for i in 0...data.size
  421.           draw_item(i, data[i])
  422.         end
  423.       end
  424.     else
  425.       self.contents.font.color = normal_color
  426.       self.contents.draw_text(0,124 - WLH  / 2,512, WLH,
  427.         NoMenuItem, 1)
  428.     end
  429.   end
  430.   #--------------------------------------------------------------------------
  431.   # draw_item
  432.   #--------------------------------------------------------------------------
  433.   def draw_item(index, item)
  434.     rect = Rect.new((index % 2) * 256 + 4, (index / 2) * WLH + WLH * 2,
  435.       248,WLH)
  436.     if item != nil
  437.       number = $game_party.item_number(item)
  438.       draw_item_name(item, rect.x, rect.y, true)
  439.       self.contents.draw_text(rect, sprintf(":%2d", number), 2)
  440.     end
  441.   end
  442.   #--------------------------------------------------------------------------
  443.   # refresh_skill
  444.   #--------------------------------------------------------------------------
  445.   def refresh_skill
  446.     for actor in $game_party.members
  447.       x = actor.index * 128 + 4
  448.       draw_actor_name(actor, x, 0)
  449.       draw_actor_hp(actor, x, WLH)
  450.       draw_actor_mp(actor, x, WLH * 2)
  451.       draw_actor_level(actor, x, WLH * 3)
  452.       counter = 0
  453.       for skill in actor.skills
  454.         if skill != nil
  455.           draw_width_item_name(skill, x, WLH * counter + WLH * 5)
  456.           counter += 1
  457.         end
  458.         if counter >= 5
  459.           break
  460.         end
  461.       end
  462.       if counter == 0
  463.         self.contents.draw_text(x, WLH * 5, 128, WLH, TSDA::Nda)
  464.       end
  465.     end
  466.   end
  467.   #--------------------------------------------------------------------------
  468.   # refresh_equip
  469.   #--------------------------------------------------------------------------
  470.   def refresh_equip
  471.     for actor in $game_party.members
  472.       x = actor.index * 128 + 4
  473.       draw_actor_name(actor, x, 0)
  474.       draw_actor_class(actor, x, WLH)
  475.       draw_actor_level(actor, x, WLH * 2)
  476.       counter = 0
  477.       for item in actor.equips
  478.         draw_width_item_name(item, x, WLH * counter + WLH * 4)
  479.         if item != nil
  480.           counter += 1
  481.         end
  482.       end
  483.       if counter == 0
  484.         self.contents.draw_text(x, WLH * 4, 128, WLH, TSDA::Nda)
  485.       end
  486.     end
  487.   end
  488.   #--------------------------------------------------------------------------
  489.   # draw_only_item_name
  490.   #--------------------------------------------------------------------------
  491.   def draw_width_item_name(item, x, y, width = 120)
  492.     if item != nil
  493.       draw_icon(item.icon_index, x, y, true)
  494.       self.contents.font.color = normal_color
  495.       self.contents.draw_text(x + 24, y, width - 24, WLH, item.name)
  496.     end
  497.   end
  498.   #--------------------------------------------------------------------------
  499.   # refresh_save
  500.   #--------------------------------------------------------------------------
  501.   def refresh_save
  502.     for i in 0..3
  503.       filename = "Save#{i + 1}.rvdata"
  504.       file_exist = FileTest.exist?(filename)
  505.       self.contents.font.color = system_color
  506.       name = SaveSlot + " #{i + 1}"
  507.       self.contents.draw_text(i * 124 + 4, 4, 200, WLH, name)
  508.       if file_exist
  509.         file = File.open(filename, "r")
  510.         error = false
  511.         begin
  512.           characters          = Marshal.load(file)
  513.           frame_count         = Marshal.load(file)
  514.           last_bgm            = Marshal.load(file)
  515.           last_bgs            = Marshal.load(file)
  516.           game_system         = Marshal.load(file)
  517.           game_message        = Marshal.load(file)
  518.           game_switches       = Marshal.load(file)
  519.           game_variables      = Marshal.load(file)
  520.           game_self_switches  = Marshal.load(file)
  521.           game_actors         = Marshal.load(file)
  522.           game_party          = Marshal.load(file)
  523.           game_troop          = Marshal.load(file)
  524.           game_map            = Marshal.load(file)
  525.           map_name            = game_map.map_name
  526.           total_sec = frame_count / Graphics.frame_rate
  527.         rescue
  528.           error = true
  529.         ensure
  530.           file.close
  531.         end
  532.         self.contents.font.color = normal_color
  533.         if error
  534.           self.contents.draw_text(i * 124 + 4, 4 + WLH * 2, 100, WLH,
  535.             ClearSlot, 0)
  536.         else
  537.           self.contents.draw_text(i * 124 + 4, 4 + WLH, 100, WLH,
  538.             map_name, 1)
  539.           draw_playtime(i * 124 + 4, 4 + WLH * 2, 100, 1,total_sec)
  540.           draw_party_characters(i * 124 + 4, 4 + WLH * 3,characters)
  541.         end
  542.       else
  543.         self.contents.font.color = normal_color
  544.         self.contents.draw_text(i * 124 + 4, 4 + WLH * 2, 120, WLH,
  545.           ClearSlot, 0)
  546.       end
  547.     end
  548.   end
  549.   #--------------------------------------------------------------------------
  550.   # draw_party_characters
  551.   #--------------------------------------------------------------------------
  552.   def draw_party_characters(x, y, characters)
  553.     for i in 0...characters.size
  554.       name = characters[i][0]
  555.       index = characters[i][1]
  556.       draw_character(name, index, x + (i % 2) * 32 + 32, y + (i / 2) * 64 + 64)
  557.     end
  558.   end
  559.   #--------------------------------------------------------------------------
  560.   # draw_playtime
  561.   #--------------------------------------------------------------------------
  562.   def draw_playtime(x, y, width, align, total_sec)
  563.     hour = total_sec / 60 / 60
  564.     min = total_sec / 60 % 60
  565.     sec = total_sec % 60
  566.     time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
  567.     self.contents.font.color = normal_color
  568.     self.contents.draw_text(x, y, width, WLH, time_string, align)
  569.   end
  570. end
  571. #===============================================================================
  572. # Window_PlayTime
  573. #===============================================================================
  574. class Window_PlayTime < Window_Base
  575.   include TSDA
  576.   #--------------------------------------------------------------------------
  577.   # initialize
  578.   #--------------------------------------------------------------------------
  579.   def initialize
  580.     super(384,WLH + 32,160,WLH * 2 + 32)
  581.     self.back_opacity = MENU_WINDOW_OPACITY
  582.     refresh
  583.   end
  584.   #--------------------------------------------------------------------------
  585.   # update
  586.   #--------------------------------------------------------------------------
  587.   def update
  588.     super
  589.     if REAL_TIME
  590.       time = Time.now
  591.       hour = time.hour
  592.       min = time.min
  593.       sec = time.sec
  594.       total_sec = hour * 60 * 60 + min * 60 + sec
  595.       if total_sec != @total_sec
  596.         refresh(total_sec)
  597.       end
  598.     else
  599.       if Graphics.frame_count / Graphics.frame_rate != @total_sec
  600.         refresh
  601.       end
  602.     end
  603.   end
  604.   #--------------------------------------------------------------------------
  605.   # refresh
  606.   #--------------------------------------------------------------------------
  607.   def refresh(total_sec = nil)
  608.     self.contents.clear
  609.     self.contents.font.color = system_color
  610.     if REAL_TIME
  611.       self.contents.draw_text(4, 0, 120, WLH, REAL_TIME_ST)
  612.       if total_sec == nil
  613.         time = Time.now
  614.         hour = time.hour
  615.         min = time.min
  616.         sec = time.sec
  617.         @total_sec = hour * 60 * 60 + min * 60 + sec
  618.       else
  619.         @total_sec = total_sec
  620.         hour = @total_sec / 60 / 60
  621.         min = @total_sec / 60 % 60
  622.         sec = @total_sec % 60
  623.       end
  624.       text = sprintf("%02d:%02d:%02d", hour, min, sec)
  625.       self.contents.font.color = normal_color
  626.       self.contents.draw_text(4, WLH, 120, WLH, text, 2)
  627.     else
  628.       self.contents.draw_text(4, 0, 120, WLH, NREAL_TIME_ST)
  629.       @total_sec = Graphics.frame_count / Graphics.frame_rate
  630.       hour = @total_sec / 60 / 60
  631.       min = @total_sec / 60 % 60
  632.       sec = @total_sec % 60
  633.       text = sprintf("%02d:%02d:%02d", hour, min, sec)
  634.       self.contents.font.color = normal_color
  635.       self.contents.draw_text(4, WLH, 120, WLH, text, 2)
  636.     end
  637.   end
  638. end
  639. #===============================================================================
  640. # FIM DO SCRIPT
  641. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement