khanhdu

One-player Menu Script

May 20th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 25.05 KB | None | 0 0
  1. #==============================================================================#
  2. # Script by: Tigurus Fay                                                       #
  3. #==============================================================================#
  4. # Script: One-Player Menu Script                                               #
  5. # Version: v1.1.2 (ACE)                                                        #
  6. # Install: Press F11 and place the Script directly above [Main].               #
  7. # Description: This script allows a menu optimized for 1 player only.          #
  8. #==============================================================================#
  9. #==============================================================================#
  10. # ** Support                                                                   #
  11. #------------------------------------------------------------------------------#
  12. # If you require support because there is an error with this script or would   #
  13. # be incompatible with another script, please contact the creator at the       #
  14. # following websites:                                                          #
  15. # - RPGMaker.org    - http://www.rpgmaker.org/resources/view.asp?id=57         #
  16. #                                                                              #
  17. #==============================================================================#
  18. # ** Compatibility                                                             #
  19. #------------------------------------------------------------------------------#
  20. # This script may be incompatible with the following scripts:                  #
  21. # - HUD Scripts                                                                #
  22. # - Untested with other scripts                                                #                
  23. #==============================================================================#
  24. # ** Terms & Conditions                                                        #
  25. #------------------------------------------------------------------------------#
  26. #   - You may use this script for your game
  27. #   - You may modify this script
  28. #   - You may distribute this script
  29. #     (Though I would like you to redirect to one of the links located in the script)
  30. #   - You may not use this script for commercial games unless discussed with the creator
  31. #   - Credit is always necessary!
  32. #==============================================================================#
  33. # ** Config                                                                    #
  34. #------------------------------------------------------------------------------#
  35. #  Here you can configurate several external options.                          #
  36. #==============================================================================#
  37.  
  38. module TOPSVOCAB
  39.  
  40.   # Here you can change the names of certain items in the Menu.
  41.      
  42.   # Change Icon:
  43.   # !!! NOTE !!! Don't forget to create a folder named "Icons" for the images below!
  44.   # Location Icon
  45.   LOCATION        = "Location" # Best result: 24x24 max
  46.  
  47.  
  48.   # Change Names of:
  49.   # Party Menu
  50.     EXP           =    "EXP"
  51.     Equipped      =    "Equipped Gear"
  52.     Wequipped     =    "No Weapon Equipped"
  53.     Hequipped     =    "No Helmet Equipped"
  54.     ARequipped    =    "No Armor Equipped"
  55.     Sequipped     =    "No Shield Equipped"
  56.     ACequipped    =    "No Accessory Equipped"
  57.    
  58.   # End Game
  59.     TOTITLE       =     "To Title"
  60.     EXIT          =     "Exit Game"
  61.     CANCEL        =     "Cancel"
  62.      
  63. end
  64.  
  65. #==============================================================================
  66. # ** Window_Base
  67. #------------------------------------------------------------------------------
  68. #  This is a super class of all windows within the game.
  69. #==============================================================================
  70.  class Window_Base
  71.  
  72.   def exp_gauge_color1;      text_color(7);   end;  # EXP gauge added lower half
  73.   def exp_gauge_color2;      text_color(8);   end;  # EXP gauge added upper half
  74.   def exp_gauge_back_color;  text_color(19);  end;  # EXP Gauge background
  75.  
  76.   # draws the EXP bar on the Menu
  77.   def draw_expgauge(x, y, width, rate, color1, color2)
  78.     fill_w = (width * rate).to_i
  79.     gauge_y = y + line_height - 8
  80.     contents.fill_rect(x, gauge_y, width, 6, exp_gauge_back_color)
  81.     contents.gradient_fill_rect(x, gauge_y, fill_w, 6, color1, color2)
  82.   end
  83.    
  84.     def draw_exp(actor, x, y, width = 124)
  85.         s1 = actor.max_level? ? "---------" : actor.exp
  86.         s2 = actor.max_level? ? "0" : actor.next_level_exp - actor.exp
  87.         if actor.max_level? ?
  88.           draw_expgauge(x, y, width, 1, exp_gauge_color1, exp_gauge_color2) :
  89.           draw_gauge(x, y,width,((((actor.exp - actor.current_level_exp).to_f/100) / ((actor.next_level_exp.to_f - actor.current_level_exp.to_f)/100))),  
  90.           exp_gauge_color1, exp_gauge_color2)
  91.         end
  92.         change_color(system_color)
  93.         draw_text(x, y, 30, line_height, TOPSVOCAB::EXP)
  94.         change_color(normal_color)
  95.         if actor.max_level? ?
  96.           draw_text(x + width - 72, y, 72, line_height, "------------", 2) :
  97.           draw_text(x + width - 72, y, 72, line_height, actor.next_level_exp.to_i - actor.exp.to_i, 2)
  98.         end
  99.       end    
  100.      
  101.   #--------------------------------------------------------------------------
  102.   # * Draw Class
  103.   #--------------------------------------------------------------------------
  104.   def draw_actor_class_opm(actor, x, y, width = 200)
  105.     change_color(normal_color)
  106.     draw_text(x, y, width, line_height, actor.class.name)
  107.   end
  108. end
  109.  
  110. #==============================================================================
  111. # ** Window_Location
  112. #------------------------------------------------------------------------------
  113. #  This window displays the party's location
  114. #==============================================================================
  115.  
  116. class Window_Location < Window_Base
  117.   #--------------------------------------------------------------------------
  118.   # * Object Initialization
  119.   #--------------------------------------------------------------------------
  120.   def initialize
  121.     super(0, 0, Graphics.width - 340, window_height)
  122.     refresh
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Get Window Height
  126.   #--------------------------------------------------------------------------
  127.   def window_height
  128.     return 80
  129.   end
  130.  
  131.   #--------------------------------------------------------------------------
  132.   # * Refresh
  133.   #--------------------------------------------------------------------------
  134.   def refresh
  135.     contents.clear
  136.     draw_location_opm
  137.   end
  138.  
  139.   def draw_location_opm
  140.     bitmap = Bitmap.new("Graphics/Icons/" + TOPSVOCAB::LOCATION + ".png")
  141.     src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
  142.     ret_rect = Rect.new(contents.width - 25, 28, bitmap.width, bitmap.height)
  143.     contents.stretch_blt(ret_rect, bitmap, src_rect)
  144.     draw_text(contents.width - 232, 25, 204, line_height, $game_map.display_name, 2)
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # * Open Window
  148.   #--------------------------------------------------------------------------
  149.   def open
  150.     refresh
  151.     super
  152.   end
  153. end
  154.  
  155. #==============================================================================
  156. # ** Window_Gold
  157. #------------------------------------------------------------------------------
  158. #  This window displays the party's gold.
  159. #==============================================================================
  160.  
  161. class Window_Gold < Window_Base
  162.   #--------------------------------------------------------------------------
  163.   # * Object Initialization
  164.   #--------------------------------------------------------------------------
  165.   def initialize
  166.     super(0, 0, Graphics.width - 340, fitting_height(1))
  167.     refresh
  168.   end
  169.  
  170.   #--------------------------------------------------------------------------
  171.   # * Refresh
  172.   #--------------------------------------------------------------------------
  173.   def refresh
  174.     contents.clear
  175.     draw_currency_value(value, currency_unit, 4, 0, contents.width - 8)
  176.   end
  177.   #--------------------------------------------------------------------------
  178.   # * Get Party Gold
  179.   #--------------------------------------------------------------------------
  180.   def value
  181.     $game_party.gold
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # Get Currency Unit
  185.   #--------------------------------------------------------------------------
  186.   def currency_unit
  187.     Vocab::currency_unit
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Open Window
  191.   #--------------------------------------------------------------------------
  192.   def open
  193.     refresh
  194.     super
  195.   end
  196. end
  197.  
  198. #==============================================================================
  199. # ** Window_MenuCommand
  200. #------------------------------------------------------------------------------
  201. #  This command window appears on the menu screen.
  202. #==============================================================================
  203.  
  204. class Window_MenuCommand < Window_Command
  205.   #--------------------------------------------------------------------------
  206.   # * Initialize Command Selection Position (Class Method)
  207.   #--------------------------------------------------------------------------
  208.   def self.init_command_position
  209.     @@last_command_symbol = nil
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # * Object Initialization
  213.   #--------------------------------------------------------------------------
  214.   def initialize
  215.     super(0, 0)
  216.     select_last
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # * Get Window Width
  220.   #--------------------------------------------------------------------------
  221.   def window_width
  222.     return 340
  223.   end
  224.  
  225.   def window_height
  226.     return 128
  227.   end
  228.  
  229.   def col_max
  230.     return 2
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # * Get Number of Lines to Show
  234.   #--------------------------------------------------------------------------
  235.   def visible_line_number
  236.     item_max
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # * Create Command List
  240.   #--------------------------------------------------------------------------
  241.   def make_command_list
  242.     add_main_commands
  243.     add_original_commands
  244.     add_save_command
  245.     add_game_end_command
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # * Add Main Commands to List
  249.   #--------------------------------------------------------------------------
  250.   def add_main_commands
  251.     add_command(Vocab::item,   :item,   main_commands_enabled)
  252.     add_command(Vocab::skill,  :skill,  main_commands_enabled)
  253.     add_command(Vocab::equip,  :equip,  main_commands_enabled)
  254.     add_command(Vocab::status, :status, main_commands_enabled)
  255.   end
  256.  
  257.   #--------------------------------------------------------------------------
  258.   # * For Adding Original Commands
  259.   #--------------------------------------------------------------------------
  260.   def add_original_commands
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * Add Save to Command List
  264.   #--------------------------------------------------------------------------
  265.   def add_save_command
  266.     add_command(Vocab::save, :save, save_enabled)
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Add Exit Game to Command List
  270.   #--------------------------------------------------------------------------
  271.   def add_game_end_command
  272.     add_command(TOPSVOCAB::TOTITLE, :to_title)
  273.     add_command(TOPSVOCAB::EXIT, :shutdown)
  274.     add_command(TOPSVOCAB::CANCEL, :cancel)
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # * Get Activation State of Main Commands
  278.   #--------------------------------------------------------------------------
  279.   def main_commands_enabled
  280.     $game_party.exists
  281.   end
  282.   #--------------------------------------------------------------------------
  283.   # * Get Activation State of Formation
  284.   #--------------------------------------------------------------------------
  285.   def formation_enabled
  286.     $game_party.members.size >= 2 && !$game_system.formation_disabled
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # * Get Activation State of Save
  290.   #--------------------------------------------------------------------------
  291.   def save_enabled
  292.     !$game_system.save_disabled
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # * Processing When OK Button Is Pressed
  296.   #--------------------------------------------------------------------------
  297.   def process_ok
  298.     @@last_command_symbol = current_symbol
  299.     super
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # * Restore Previous Selection Position
  303.   #--------------------------------------------------------------------------
  304.   def select_last
  305.     select_symbol(@@last_command_symbol)
  306.   end
  307. end
  308.  
  309. #==============================================================================
  310. # ** Window_MenuStatus_Opm
  311. #------------------------------------------------------------------------------
  312. #  This window displays full status specs on the menu screen.
  313. #==============================================================================
  314.  
  315. class Window_MenuStatus_Opm < Window_Selectable
  316.   #--------------------------------------------------------------------------
  317.   # * Object Initialization
  318.   #--------------------------------------------------------------------------
  319.   def initialize(x, y, actor)
  320.     super(0, 128, Graphics.width, Graphics.height - 128)
  321.     @actor = $game_party.members[0]
  322.     refresh
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # * Set Actor
  326.   #--------------------------------------------------------------------------
  327.   def actor=(actor)
  328.     return if @actor == actor
  329.     @actor = actor
  330.     refresh
  331.   end
  332.   #--------------------------------------------------------------------------
  333.   # * Refresh
  334.   #--------------------------------------------------------------------------
  335.   def refresh
  336.     contents.clear
  337.     draw_geninfo   (line_height * 0)
  338.     draw_basicinfo   (line_height * 2)
  339.     draw_parablock   (line_height * 1)
  340.     draw_horz_line(line_height * 7)
  341.     draw_equipblock (line_height * 8)
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # * Draw general info
  345.   #--------------------------------------------------------------------------
  346.   def draw_geninfo(y)
  347.     draw_actor_face(@actor, 8, y)
  348.     draw_actor_fullname(120, y)
  349.     draw_actor_level(@actor, 120, y + line_height * 1)
  350.     draw_actor_class_opm(@actor, 120, y + line_height * 2)
  351.     draw_actor_icons(@actor, 120, y + line_height * 3)
  352.   end
  353.  
  354.   #--------------------------------------------------------------------------
  355.   # * Draw basic info
  356.   #--------------------------------------------------------------------------
  357.   def draw_basicinfo(y)
  358.     draw_basic_info(8, y)
  359.   end
  360.  
  361.   #--------------------------------------------------------------------------
  362.   # * Draw parablock
  363.   #--------------------------------------------------------------------------
  364.   def draw_parablock(y)
  365.     draw_parameters(330, y)
  366.   end
  367.  
  368.   #--------------------------------------------------------------------------
  369.   # * Draw equipblock
  370.   #--------------------------------------------------------------------------
  371.   def draw_equipblock(y)
  372.     draw_equipments(8, y)
  373.   end
  374.  
  375.   #--------------------------------------------------------------------------
  376.   # * Draw Horizontal Line
  377.   #--------------------------------------------------------------------------
  378.   def draw_horz_line(y)
  379.     line_y = y + line_height / 2 - 1
  380.     contents.fill_rect(0, line_y, contents_width, 2, line_color)
  381.   end
  382.   #--------------------------------------------------------------------------
  383.   # * Get Color of Horizontal Line
  384.   #--------------------------------------------------------------------------
  385.   def line_color
  386.     color = normal_color
  387.     color.alpha = 48
  388.     color
  389.   end
  390.   #--------------------------------------------------------------------------
  391.   # * Draw Basic Information
  392.   #--------------------------------------------------------------------------
  393.   def draw_basic_info(x, y)
  394.     draw_actor_hp(@actor, x, y + line_height * 2)
  395.     draw_actor_mp(@actor, x, y + line_height * 3)
  396.     draw_exp(@actor, x, y + line_height * 4)
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # * Draw Parameters
  400.   #--------------------------------------------------------------------------
  401.   def draw_parameters(x, y)
  402.     6.times {|i| draw_actor_param(@actor, x, y + line_height * i, i + 2) }
  403.   end
  404.   #--------------------------------------------------------------------------
  405.   # * Draw Experience Information
  406.   #--------------------------------------------------------------------------
  407.   def draw_exp_info(x, y)
  408.     s1 = @actor.max_level? ? "-------" : @actor.exp
  409.     s2 = @actor.max_level? ? "-------" : @actor.next_level_exp - @actor.exp
  410.     s_next = sprintf(Vocab::ExpNext, Vocab::level)
  411.     change_color(system_color)
  412.     draw_text(x, y + line_height * 0, 180, line_height, Vocab::ExpTotal)
  413.     draw_text(x, y + line_height * 2, 180, line_height, s_next)
  414.     change_color(normal_color)
  415.     draw_text(x, y + line_height * 1, 180, line_height, s1, 2)
  416.     draw_text(x, y + line_height * 3, 180, line_height, s2, 2)
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # * Draw Equipment
  420.   #--------------------------------------------------------------------------
  421.   def draw_equipments(x, y)
  422.     change_color(system_color)
  423.     draw_text(x, y, 180, line_height, TOPSVOCAB::Equipped, 0)
  424.     change_color(normal_color)
  425.       weapon = @actor.equips[0]
  426.       shield = @actor.equips[1]
  427.       helmet = @actor.equips[2]
  428.       armor  = @actor.equips[3]
  429.       acces  = @actor.equips[4]
  430.     if weapon == nil
  431.       change_color(knockout_color)
  432.       draw_text(x, y + line_height + 10, 170, line_height, TOPSVOCAB::Wequipped)
  433.       change_color(normal_color)
  434.     else      
  435.       draw_item_name(weapon, x, y + line_height + 10)
  436.     end
  437.     if shield == nil
  438.       draw_text(x + 350, y + line_height + 10, 170, line_height, TOPSVOCAB::Sequipped)
  439.     else      
  440.       draw_item_name(shield, x + 350, y + line_height + 10)
  441.     end
  442.     if helmet == nil
  443.       draw_text(x + 170, y, 170, line_height, TOPSVOCAB::Hequipped)
  444.     else      
  445.       draw_item_name(helmet, x + 170, y)
  446.     end
  447.     if armor == nil
  448.       draw_text(x + 170, y + line_height + 10, 180, line_height, TOPSVOCAB::ARequipped)
  449.     else      
  450.       draw_item_name(armor, x + 170, y + line_height + 10, 0)
  451.     end  
  452.     if acces == nil
  453.       draw_text(x + 350, y, 180, line_height, TOPSVOCAB::ACequipped)
  454.     else      
  455.       draw_item_name(acces, x + 350, y)
  456.     end
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * Draw Description
  460.   #--------------------------------------------------------------------------
  461.   def draw_description(x, y)
  462.     draw_text_ex(x, y, @actor.description)
  463.   end
  464.  
  465.   #--------------------------------------------------------------------------
  466.   # * Draw name + nickname
  467.   #--------------------------------------------------------------------------
  468.   def draw_actor_fullname(x, y)
  469.     draw_text(x, y + line_height * 0, 180, line_height, @actor.name + " " + @actor.nickname)
  470.   end
  471. end
  472.  
  473. #==============================================================================
  474. # ** Scene_Skill
  475. #------------------------------------------------------------------------------
  476. #  This class performs skill screen processing. Skills are handled as items for
  477. # the sake of process sharing.
  478. #==============================================================================
  479.  
  480. class Scene_Skill
  481.  
  482.   def on_item_ok
  483.     if $game_party.members.size == 1
  484.       use_item
  485.       activate_item_window
  486.     else
  487.       @actor.last_skill.object = item
  488.       determine_item
  489.     end
  490.   end
  491. end
  492.  
  493. #==============================================================================
  494. # ** Scene_Menu
  495. #------------------------------------------------------------------------------
  496. #  This class performs the menu screen processing.
  497. #==============================================================================
  498.  
  499. class Scene_Menu < Scene_MenuBase
  500.   #--------------------------------------------------------------------------
  501.   # * Start Processing
  502.   #--------------------------------------------------------------------------
  503.   def start
  504.     super
  505.     create_command_window
  506.     create_status_window
  507.     create_location_window
  508.     create_gold_window
  509.   end
  510.   #--------------------------------------------------------------------------
  511.   # * Create Command Window
  512.   #--------------------------------------------------------------------------
  513.   def create_command_window
  514.     @command_window = Window_MenuCommand.new
  515.     @command_window.set_handler(:status,      method(:command_op_status))
  516.     @command_window.set_handler(:item,        method(:command_item))
  517.     @command_window.set_handler(:equip,      method(:command_op_equip))
  518.     @command_window.set_handler(:skill,      method(:command_op_skill))
  519.     @command_window.set_handler(:save,       method(:command_save))
  520.     @command_window.set_handler(:to_title,  method(:command_game_to_titleTOPS))
  521.     @command_window.set_handler(:shutdown,  method(:command_game_to_exitTOPS))
  522.     @command_window.set_handler(:cancel,    method(:return_scene))
  523.     # Makes it possible to change actors in the menu.
  524.     @command_window.set_handler(:pagedown, method(:next_actor))
  525.     @command_window.set_handler(:pageup,   method(:prev_actor))
  526.   end
  527.  
  528.   #--------------------------------------------------------------------------
  529.   # * Create Location Window
  530.   #--------------------------------------------------------------------------
  531.   def create_location_window
  532.     @location_window = Window_Location.new
  533.     @location_window.x = 340
  534.     @location_window.y = 0
  535.   end
  536.  
  537.   #--------------------------------------------------------------------------
  538.   # * Create Gold Window
  539.   #--------------------------------------------------------------------------
  540.   def create_gold_window
  541.     @gold_window = Window_Gold.new
  542.     @gold_window.x = 340
  543.     @gold_window.y = 80
  544.   end
  545.    
  546.   #--------------------------------------------------------------------------
  547.   # * Create Status Window
  548.   #--------------------------------------------------------------------------
  549.   def create_status_window
  550.     @status_window = Window_MenuStatus_Opm.new(0, 128, @actor)
  551.   end
  552.  
  553.   #--------------------------------------------------------------------------
  554.   # * [Item] Command
  555.   #--------------------------------------------------------------------------
  556.   def command_item
  557.     SceneManager.call(Scene_Item)
  558.   end
  559.   #--------------------------------------------------------------------------
  560.   # * [Skill] Commands
  561.   #--------------------------------------------------------------------------
  562.  
  563.   def command_op_skill
  564.     @status_window.activate
  565.     SceneManager.call(Scene_Skill)
  566.   end
  567.  
  568.   #--------------------------------------------------------------------------
  569.   # * [Equipment] Commands
  570.   #--------------------------------------------------------------------------
  571.  
  572.   def command_op_equip
  573.     @status_window.activate
  574.     SceneManager.call(Scene_Equip)
  575.   end
  576.  
  577.   #--------------------------------------------------------------------------
  578.   # * [Status] Commands
  579.   #--------------------------------------------------------------------------
  580.  
  581.   def command_op_status
  582.     @status_window.activate
  583.     SceneManager.call(Scene_Status)
  584.   end
  585.  
  586.   #--------------------------------------------------------------------------
  587.   # * [Save] Command
  588.   #--------------------------------------------------------------------------
  589.   def command_save
  590.     SceneManager.call(Scene_Save)
  591.   end
  592.  
  593.   #--------------------------------------------------------------------------
  594.   # * [To Title] Command
  595.   #--------------------------------------------------------------------------
  596.   def command_game_to_titleTOPS
  597.       fadeout_all
  598.       SceneManager.goto(Scene_Title)
  599.   end
  600.  
  601.   #--------------------------------------------------------------------------
  602.   # * [Exit Command
  603.   #--------------------------------------------------------------------------
  604.   def command_game_to_exitTOPS
  605.       fadeout_all
  606.       SceneManager.exit
  607.   end
  608.    
  609.   #--------------------------------------------------------------------------
  610.   # * [Cancel] Personal Command
  611.   #--------------------------------------------------------------------------
  612.   def on_personal_cancel
  613.     @status_window.unselect
  614.     @command_window.activate
  615.   end
  616.  
  617.   def on_actor_change
  618.     @status_window.actor = @actor
  619.     @command_window.activate
  620.   end
  621. end
Advertisement
Add Comment
Please, Sign In to add comment