Advertisement
roninator2

Yanfly System Options Addon - List Options

Nov 3rd, 2020 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.98 KB | Source Code | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: List Options                 ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║ Yanfly System Options -             ╠════════════════════╣
  7. # ║ Allows you to create lists          ║    21 Jun 2019     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Normally you can use switches or variables for the       ║
  11. # ║ various custom options.                                  ║
  12. # ║ But what if you wanted to write text instead of numbers  ║
  13. # ║ for the variables?                                       ║
  14. # ║                                                          ║
  15. # ║ Create a list as detailed below and add it to Yanfly's   ║
  16. # ║ script to have it show up.                               ║
  17. # ║                                                          ║
  18. # ║ Supports up to 4 words on screen                         ║
  19. # ║ And they need to be short                                ║
  20. # ╚══════════════════════════════════════════════════════════╝
  21. # ╔═════════════════════════════════════╗
  22. # ║ Terms of use:                       ║
  23. # ║ Follow the Original Authors terms   ║
  24. # ╚═════════════════════════════════════╝
  25.  
  26. module YEA
  27.   module SYSTEM
  28.     CUSTOM_LISTS ={
  29.     # -------------------------------------------------------------------------
  30.     # :list    => [Variable, Name, Color1, Color2, minimum, maximum,
  31.     #               Help Window Description, Value1, Value2, Value3, etc
  32.     #               ], # Do not remove this.
  33.     # -------------------------------------------------------------------------
  34.       :list_1  => [ 67, "Difficulty", 0, 7, 0, 3, "Change Difficulty?",
  35.                       "Easy", "Normal", "Heroic", "Legendary"
  36.                     ],
  37.     # -------------------------------------------------------------------------
  38.       :list_2  => [ 127, "Cursor", 0, 7, 0, 3, "Change the cursor for the menu.\n"+
  39.                       "Exit screen for change to take effect.",
  40.                       "Magic", "Crystal", "Hand", "None"
  41.                     ],
  42.     # -------------------------------------------------------------------------
  43.       :list_3  => [ 150, "Font", 0, 7, 0, 3, "Change the font for the game messages.\n"+
  44.                       "Not the menu",
  45.                       "Philosopher", "Duel", "Immortal", "Almendra",
  46.                     ],
  47.     # -------------------------------------------------------------------------
  48.       :list_4  => [ 151, "Font Size", 0, 7, 0, 3, "Change the font size for the game messages.\n"+
  49.                       "Not the menu",
  50.                       "18", "20", "22", "24",
  51.                     ],
  52.     # -------------------------------------------------------------------------
  53.     } # Do not remove this.
  54.   end
  55. end
  56.  
  57. class Window_SystemOptions < Window_Command
  58.   #--------------------------------------------------------------------------
  59.   # Overwrite * update_help
  60.   #--------------------------------------------------------------------------
  61.   def update_help
  62.     if current_symbol == :custom_switch || current_symbol == :custom_variable ||
  63.       current_symbol == :custom_list
  64.       text = @help_descriptions[current_ext]
  65.     else
  66.       text = @help_descriptions[current_symbol]
  67.     end
  68.     text = "" if text.nil?
  69.     @help_window.set_text(text)
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # new * process_custom_list
  73.   #--------------------------------------------------------------------------
  74.   def process_custom_list(command)
  75.     return unless YEA::SYSTEM::CUSTOM_LISTS.include?(command)
  76.     name = YEA::SYSTEM::CUSTOM_LISTS[command][1]
  77.     add_command(name, :custom_list, true, command)
  78.     @help_descriptions[command] = YEA::SYSTEM::CUSTOM_LISTS[command][6]
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # draw_item
  82.   #--------------------------------------------------------------------------
  83.   alias r2_draw_item_823gf  draw_item
  84.   def draw_item(index)
  85.     reset_font_settings
  86.     rect = item_rect(index)
  87.     contents.clear_rect(rect)
  88.     r2_draw_item_823gf(index)
  89.     case @list[index][:symbol]
  90.     when :custom_list
  91.       draw_custom_list(rect, index, @list[index][:ext])
  92.     end
  93.   end
  94.  
  95.   def item_height
  96.     line_height
  97.   end
  98.  
  99.   def line_height
  100.     return 21
  101.   end
  102.  
  103.   #--------------------------------------------------------------------------
  104.   # Overwrite * make_command_list
  105.   #--------------------------------------------------------------------------
  106.   def make_command_list
  107.     @help_descriptions = {}
  108.     for command in YEA::SYSTEM::COMMANDS
  109.       case command
  110.       when :blank
  111.         add_command(YEA::SYSTEM::COMMAND_VOCAB[command][0], command)
  112.         @help_descriptions[command] = YEA::SYSTEM::COMMAND_VOCAB[command][3]
  113.       when :window_red, :window_grn, :window_blu
  114.         add_command(YEA::SYSTEM::COMMAND_VOCAB[command][0], command)
  115.         @help_descriptions[command] = YEA::SYSTEM::COMMAND_VOCAB[command][3]
  116.       when :volume_bgm, :volume_bgs, :volume_sfx
  117.         add_command(YEA::SYSTEM::COMMAND_VOCAB[command][0], command)
  118.         @help_descriptions[command] = YEA::SYSTEM::COMMAND_VOCAB[command][3]
  119.       when :autodash, :instantmsg, :animations
  120.         add_command(YEA::SYSTEM::COMMAND_VOCAB[command][0], command)
  121.         @help_descriptions[command] = YEA::SYSTEM::COMMAND_VOCAB[command][3]
  122.       when :encyclopedia, :achievement, :cancel, :to_title, :shutdown, :stats, :varmenu
  123.         add_command(YEA::SYSTEM::COMMAND_VOCAB[command][0], command)
  124.         @help_descriptions[command] = YEA::SYSTEM::COMMAND_VOCAB[command][3]
  125.       when :fullscreen, :ratio
  126.         add_command(YEA::SYSTEM::COMMAND_VOCAB[command][0], command)
  127.         @help_descriptions[command] = YEA::SYSTEM::COMMAND_VOCAB[command][3]
  128.       else
  129.         process_custom_list(command)
  130.         process_custom_switch(command)
  131.         process_custom_variable(command)
  132.       end
  133.     end
  134.   end
  135.    
  136.   #--------------------------------------------------------------------------
  137.   # New * draw_custom_list
  138.   #--------------------------------------------------------------------------
  139.   def draw_custom_list(rect, index, ext)
  140.     name = @list[index][:name]
  141.     change_color(normal_color)
  142.     draw_text(-40, rect.y, contents.width/2, line_height, name, 1)
  143.     #---
  144.     value = $game_variables[YEA::SYSTEM::CUSTOM_LISTS[ext][0]].to_i
  145.     minimum = YEA::SYSTEM::CUSTOM_LISTS[ext][4].to_i
  146.     maximum = YEA::SYSTEM::CUSTOM_LISTS[ext][5].to_i
  147.     if minimum > value
  148.       value = minimum
  149.       $game_variables[YEA::SYSTEM::CUSTOM_LISTS[ext][0]] = value
  150.     end
  151.     if maximum < value
  152.       value = maximum
  153.       $game_variables[YEA::SYSTEM::CUSTOM_LISTS[ext][0]] = value
  154.     end
  155.     pos = 0
  156.     for i in 0..maximum
  157.       dx = maximum <= 2 ? -40 : maximum >= 4 ? 100 : 40
  158.       entry = YEA::SYSTEM::CUSTOM_LISTS[ext][pos + 7]
  159.       color1 = text_color(YEA::SYSTEM::CUSTOM_LISTS[ext][3].to_i)
  160.       change_color(color1)
  161.       d = i + 1
  162.       draw_text(dx + contents.width*d/maximum/2, rect.y, contents.width/maximum, line_height, entry, 1)
  163.       if value == i
  164.         color2 = text_color(YEA::SYSTEM::CUSTOM_LISTS[ext][2].to_i)
  165.         change_color(color2)
  166.         entry = YEA::SYSTEM::CUSTOM_LISTS[ext][pos + 7]
  167.         draw_text(dx + contents.width*d/maximum/2, rect.y, contents.width/maximum, line_height, entry, 1)
  168.       end
  169.       pos += 1
  170.     end
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # cursor_change
  174.   #--------------------------------------------------------------------------
  175.   alias r2_cursor_change_92fkw  cursor_change
  176.   def cursor_change(direction)
  177.     r2_cursor_change_92fkw(direction)
  178.     case current_symbol
  179.     when :custom_list
  180.       change_custom_lists(direction)
  181.     end
  182.   end
  183.  
  184.   #--------------------------------------------------------------------------
  185.   # Overwrite * draw_item
  186.   #--------------------------------------------------------------------------
  187.   alias r2_draw_item_9713g  draw_item
  188.   def draw_item(index)
  189.     reset_font_settings
  190.     contents.font.size = 20
  191.     rect = item_rect(index)
  192.     contents.clear_rect(rect)
  193.     r2_draw_item_9713g(index)
  194.     case @list[index][:symbol]
  195.     when :custom_list
  196.       draw_custom_list(rect, index, @list[index][:ext])
  197.     end
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # new * change_custom_lists
  201.   #--------------------------------------------------------------------------
  202.   def change_custom_lists(direction)
  203.     Sound.play_cursor
  204.     value = direction == :left ? -1 : 1
  205.     ext = current_ext
  206.     var = YEA::SYSTEM::CUSTOM_LISTS[ext][0]
  207.     minimum = YEA::SYSTEM::CUSTOM_LISTS[ext][2]
  208.     maximum = YEA::SYSTEM::CUSTOM_LISTS[ext][3]
  209.     $game_variables[var] += value
  210.     $game_variables[var] = [[$game_variables[var], minimum].max, maximum].min
  211.     draw_item(index)
  212.   end
  213.  
  214. end # Window_SystemOptions
  215.  
  216.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement