Advertisement
roninator2

Chapter Selection

Nov 19th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 31.63 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════╦════════════════════╗
  2. # ║ Title: Chapter Selection                      ║  Version: 1.03     ║
  3. # ║ Author: Roninator2                            ║                    ║
  4. # ╠═══════════════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                                     ║   Date Created     ║
  6. # ║   Allows to perform a chapter                 ╠════════════════════╣
  7. # ║   selection                                   ║    15 Feb 2022     ║
  8. # ╚═══════════════════════════════════════════════╩════════════════════╝
  9. # ╔════════════════════════════════════════════════════════════════════╗
  10. # ║ Requires: nil                                                      ║
  11. # ║                                                                    ║
  12. # ╚════════════════════════════════════════════════════════════════════╝
  13. # ╔════════════════════════════════════════════════════════════════════╗
  14. # ║ Brief Description:                                                 ║
  15. # ║       Provide a Chapter Selection scene                            ║
  16. # ╚════════════════════════════════════════════════════════════════════╝
  17. # ╔════════════════════════════════════════════════════════════════════╗
  18. # ║ Instructions:                                                      ║
  19. # ║   Script calls:                                                    ║
  20. # ║     chapter_unlock(id)                                             ║
  21. # ║       id = the chapter to unlock. Chapter 1 = 0                    ║
  22. # ║          it is presumed that you will call this                    ║
  23. # ║          command when the previous chapter is finished             ║
  24. # ║     load_chapter(id)                                               ║
  25. # ║       just simply load a chapter.                                  ║
  26. # ║       doesn't have to be unlocked                                  ║
  27. # ║     start_new_chapter                                              ║
  28. # ║       calls the chapter select menu                                ║
  29. # ║                                                                    ║
  30. # ║   Pu in your desired words and image names below                   ║
  31. # ║                                                                    ║
  32. # ╚════════════════════════════════════════════════════════════════════╝
  33. # ╔════════════════════════════════════════════════════════════════════╗
  34. # ║ Updates:                                                           ║
  35. # ║ 1.03 - 20 Feb 2022 - Added fadeout - returning to title            ║
  36. # ║ 1.02 - 18 Feb 2022 - Configured for 640 x 480 screen               ║
  37. # ║                                        Added more control options.                   ║
  38. # ║ 1.01 - 16 Feb 2022 - minor additions                               ║
  39. # ║ 1.00 - 16 Feb 2022 - Script finished                               ║
  40. # ╚════════════════════════════════════════════════════════════════════╝
  41. # ╔════════════════════════════════════════════════════════════════════╗
  42. # ║ Credits and Thanks:                                                ║
  43. # ║   Roninator2                                                       ║
  44. # ║   Whotfisjojo                                                      ║
  45. # ╚════════════════════════════════════════════════════════════════════╝
  46. # ╔════════════════════════════════════════════════════════════════════╗
  47. # ║ Terms of use:                                                      ║
  48. # ║  Follow the original Authors terms of use where applicable         ║
  49. # ║    - When not made by me (Roninator2)                              ║
  50. # ║  Free for all uses in RPG Maker except nudity                      ║
  51. # ║  Anyone using this script in their project before these terms      ║
  52. # ║  were changed are allowed to use this script even if it conflicts  ║
  53. # ║  with these new terms. New terms effective 03 Apr 2024             ║
  54. # ║  No part of this code can be used with AI programs or tools        ║
  55. # ║  Credit must be given                                              ║
  56. # ╚════════════════════════════════════════════════════════════════════╝
  57.  
  58. module R2_Chapter_Select
  59.  
  60.   # background image for the scene
  61.   Background = ""
  62.  
  63.    
  64.   # Switch used temporarily to control exiting the menu
  65.   # * required - but used internally. do not change in game.
  66.   Control_Switch = 3
  67.    
  68.  
  69.   # file where chapter data writened below is saved
  70.   Chapter_Save_File = "Chapters.rvdata2"
  71.  
  72.   # name of image to use for locked chapters
  73.   Locked = "Locked"
  74.   # Text to display in description when chapter locked
  75.   Locked_Text = "Locked"
  76.  
  77.  
  78.   # text to be displayed on the chapter select screen
  79.   Title_Text = "Select an Episode"
  80.   # Set font size for title text
  81.   Title_Font = 48
  82.   # position adjustment for centering
  83.   Title_X = 160
  84.  
  85.  
  86.     # Arrows
  87.   # set to false to not use arrows
  88.   Arrows = false
  89.   # Right Arrow for moving right
  90.   Right_Arrow = "Right_Arrow"
  91.   # Left arrow for moving left
  92.   Left_Arrow = "Left_Arrow"
  93.   # set to false to not use text for the left and right direction
  94.   Arrows_Text = true
  95.   # Right text for moving right
  96.   Right_Text = "->"
  97.   # Left text for moving left
  98.   Left_Text = "<-"
  99.   # variable used to pass index position to the other window for draing text
  100.   Arrow_Var = 2
  101.   # Set font size for text. When using the <- -> for the arrows
  102.   Arrow_Font = 24
  103.   # Right text position for moving right
  104.   Right_Arrow_X = 580 # 485 for 544 screen
  105.   Right_Arrow_Y = 170
  106.   # Left text for position moving left
  107.   Left_Arrow_X = 10
  108.   Left_Arrow_Y = 170
  109.  
  110.  
  111.   # Chapter image window
  112.   # set how many rows to show on the screen
  113.   Column_Max = 5
  114.   # adjusts based on other numbers
  115.   Chapter_Window_Height = 100  # Graphics.height - value # 50 for 416 height
  116.   # adjusts based on other numbers
  117.   Chapter_Window_X = 45
  118.   Chapter_Window_Y = 90
  119.   # Window padding. push everthing more inside
  120.   Window_Padding = 16
  121.   # Position of chapter images. hard coded formula will need
  122.   # to be changed if using different sized images
  123.   Image_Base_X = 18
  124.   Image_Base_Y = 100
  125.   Image_Base_Adjust = 3
  126.   # Determine the Y position of the text under the chapter image
  127.   Chapter_Text_X = 90
  128.   Chapter_Text_Y = 180
  129.   # Window width to show chapter images
  130.   Chapter_Width = 90  # Graphics.width - 100
  131.   Chapter_Height = 220 # Graphics.height - 220
  132.  
  133.  
  134.   # turn line drawn off
  135.   Lines_Off = false
  136.   # Move line drawn on the bottom
  137.   Line_Y = 140  # Graphics.height - 140 # 90 for 416 height
  138.  
  139.  
  140.     # Help window
  141.   # set to false to not use marker
  142.   Help_Window_Height = 100  # 2 rows in 416 height, 4 rows in 480 height
  143.   # number of description lines to use
  144.   Help_Lines = 4 # 2 for 416 height, 4 for 480 height
  145.  
  146.  
  147.     # last mark image
  148.   # set to false to not use marker
  149.   Last_Marker = true
  150.   # Determine y position of last mark image
  151.   Last_Mark_Y = 120
  152.   # Determine the OFFSET of the X position
  153.   Last_Mark_X = 0
  154.   # image used to indicate what chapter was played last
  155.   Last_Image = "Battle_Cursor"
  156.     # adjust value to position mark
  157.   Last_Mark_Adjust = 140
  158.  
  159.    
  160.     # cursor
  161.   # Width of selection cursor
  162.   Select_Width = 95
  163.   # Height of selection cursor
  164.   Select_Height = 220
  165.   # Space between cursor selections
  166.   Spacing = 10
  167.  
  168.    
  169.   # Chapter data
  170.   Chapters = {
  171.               0 => {
  172.                     :title => "Part 1",
  173.                     :image => "Chapter_1",
  174.                     :location => [1,5,5], # [ map id, x, y ]
  175.                     :locked => false,     # show chapter image or - blank (true)
  176.                     :last => true,        # last chapter accessed
  177.                     :description =>
  178.       "The first chapter in your journey. Welcome adventurer" + "\n" +
  179.       "Your quest is to find the crown and finish the race" + "\n" +
  180.       "Larger screen means larger description text" + "\n" +
  181.       "What can you fill in here to give the player info?",
  182.                     },
  183.               1 => {
  184.                     :title => "Part 2",
  185.                     :image => "Chapter_2",
  186.                     :location => [2,5,5],
  187.                     :locked => true,
  188.                     :last => false,
  189.                     :description =>
  190.       "The second chapter in your journey. Welcome to the adventure" + "\n" +
  191.       "Your quest is to find the item and proceed to the next chapter",
  192.                     },
  193.               2 => {
  194.                     :title => "Part 3",
  195.                     :image => "Chapter_3",
  196.                     :location => [1,5,5],
  197.                     :locked => true,
  198.                     :last => false,
  199.                     :description =>
  200.       "The third chapter in your journey. Welcome to the adventure" + "\n" +
  201.       "Your quest is to find the thing and proceed to the next chapter",
  202.                     },
  203.               3 => {
  204.                     :title => "Part 4",
  205.                     :image => "Chapter_4",
  206.                     :location => [1,5,5],
  207.                     :locked => true,
  208.                     :last => false,
  209.                     :description =>
  210.       "The fourth chapter in your journey. Welcome to the adventure" + "\n" +
  211.       "Your quest is to find the herb and proceed to the next chapter",
  212.                     },
  213.               4 => {
  214.                     :title => "Part 5",
  215.                     :image => "Chapter_5",
  216.                     :location => [1,5,5],
  217.                     :locked => true,
  218.                     :last => false,
  219.                     :description =>
  220.       "The fifth chapter in your journey. Welcome to the adventure" + "\n" +
  221.       "Your quest is to find the mouse and proceed to the next chapter",
  222.                     },
  223.               5 => {
  224.                     :title => "Part 6",
  225.                     :image => "Chapter_6",
  226.                     :location => [1,5,5],
  227.                     :locked => true,
  228.                     :last => false,
  229.                     :description =>
  230.       "The first chapter in your journey. Welcome to the adventure" + "\n" +
  231.       "Your quest is to find the crown and proceed to the next chapter",
  232.                     },
  233.               6 => {
  234.                     :title => "Part 7",
  235.                     :image => "Chapter_7",
  236.                     :location => [1,5,5],
  237.                     :locked => true,
  238.                     :last => false,
  239.                     :description =>
  240.       "The first chapter in your journey. Welcome to the adventure" + "\n" +
  241.       "Your quest is to find the crown and proceed to the next chapter",
  242.                     },
  243.               7 => {
  244.                     :title => "Part 8",
  245.                     :image => "Chapter_8",
  246.                     :location => [1,5,5],
  247.                     :locked => true,
  248.                     :last => false,
  249.                     :description =>
  250.       "The first chapter in your journey. Welcome to the adventure" + "\n" +
  251.       "Your quest is to find the crown and proceed to the next chapter",
  252.                     },
  253.               8 => {
  254.                     :title => "Part 9",
  255.                     :image => "Chapter_9",
  256.                     :location => [1,5,5],
  257.                     :locked => true,
  258.                     :last => false,
  259.                     :description =>
  260.       "The first chapter in your journey. Welcome to the adventure" + "\n" +
  261.       "Your quest is to find the crown and proceed to the next chapter",
  262.                     },
  263.               9 => {
  264.                     :title => "Part 10",
  265.                     :image => "Chapter_10",
  266.                     :location => [1,5,5],
  267.                     :locked => true,
  268.                     :last => false,
  269.                     :description =>
  270.       "The first chapter in your journey. Welcome to the adventure" + "\n" +
  271.       "Your quest is to find the crown and proceed to the next chapter",
  272.                     }
  273.               }
  274. end
  275. # ╔════════════════════════════════════════════════════════════════════╗
  276. # ║                      End of editable region                        ║
  277. # ╚════════════════════════════════════════════════════════════════════╝
  278.  
  279.  
  280. module DataManager
  281.  
  282.   class << self  
  283.     alias r2_chapter create_game_objects
  284.     alias r2_load_chapter extract_save_contents
  285.     alias r2_save_chapter make_save_contents
  286.   end
  287.  
  288.   def self.make_save_contents
  289.     r2chapterdata = r2_save_chapter
  290.     r2chapterdata[:chapters] = $chapter_data
  291.     r2chapterdata
  292.   end
  293.  
  294.   def self.extract_save_contents(contents)
  295.     r2_load_chapter(contents)
  296.     $chapter_data = contents[:chapters]
  297.   end
  298.  
  299.   def self.save_chapter
  300.     filename = R2_Chapter_Select::Chapter_Save_File
  301.     File.open(filename, "wb") do |file|
  302.       Marshal.dump(make_save_contents, file)
  303.     end
  304.     return true
  305.   end
  306.  
  307.   def self.load_chapter
  308.     filename = R2_Chapter_Select::Chapter_Save_File
  309.     File.open(filename, "rb") do |file|
  310.       extract_save_contents(Marshal.load(file))
  311.     end
  312.     return true
  313.   end
  314.  
  315.   def self.create_game_objects
  316.     r2_chapter
  317.     $chapter_data = Game_Chapters.new
  318.     load_chapter if File.exist?(R2_Chapter_Select::Chapter_Save_File)
  319.   end
  320.  
  321.   def self.setup_chapter(id)
  322.     load_chapter if File.exist?(R2_Chapter_Select::Chapter_Save_File)
  323.     for i in 0..$chapter_data.chapter_info.size-1
  324.       if i == id
  325.         $chapter_data.chapter_info[i][:last] = true
  326.       else
  327.         $chapter_data.chapter_info[i][:last] = false
  328.       end
  329.     end
  330.     map = $chapter_data.chapter_info[id][:location][0]
  331.     x   = $chapter_data.chapter_info[id][:location][1]
  332.     y   = $chapter_data.chapter_info[id][:location][2]
  333.     $game_player.reserve_transfer(map, x, y)
  334.     $game_player.perform_transfer
  335.     $game_player.refresh
  336.     Graphics.frame_count = 0
  337.     save_chapter
  338.   end
  339.  
  340. end
  341.  
  342. class Game_Interpreter
  343.   def chapter_unlock(id)
  344.     $chapter_data.chapter_info[id][:locked] = false
  345.     DataManager.save_chapter
  346.   end
  347.   def load_chapter(id)
  348.     command_221
  349.     DataManager.setup_chapter(id)
  350.     command_222
  351.   end
  352.   def start_new_chapter
  353.     SceneManager.call(Scene_Chapter)
  354.   end
  355. end
  356.  
  357. class Game_Chapters
  358.   attr_accessor :id
  359.   attr_accessor :chapter_info
  360.   def initialize
  361.     @id = 0
  362.     @chapter_info = R2_Chapter_Select::Chapters
  363.   end
  364. end
  365.  
  366. class Window_Chapter_Back < Window_Base
  367.   def initialize
  368.     super(0, 0, Graphics.width, Graphics.height)
  369.     if (R2_Chapter_Select::Arrows == false) && (R2_Chapter_Select::Arrow_Var == 0)
  370.       draw_lines
  371.       draw_title
  372.     end
  373.   end
  374.   def draw_horz_line(y)
  375.     line_y = y + line_height / 2 - 1
  376.     contents.fill_rect(0, line_y, contents_width, 2, line_color)
  377.   end
  378.   def line_color
  379.     color = normal_color
  380.     color.alpha = 100
  381.     color
  382.   end
  383.   def draw_title
  384.     contents.font.size = R2_Chapter_Select::Title_Font
  385.     contents.font.bold = true
  386.     @text = R2_Chapter_Select::Title_Text
  387.     draw_text(0, 10, Graphics.width, 68, @text, 1)
  388.     contents.font.size = Font.default_size
  389.     contents.font.bold = false
  390.   end
  391.   def draw_lines
  392.     return if R2_Chapter_Select::Lines_Off == true
  393.     draw_horz_line(Graphics.height - R2_Chapter_Select::Line_Y)
  394.     draw_horz_line(Graphics.height - R2_Chapter_Select::Line_Y + 1)
  395.     draw_horz_line(58);    draw_horz_line(59)
  396.     draw_horz_line(5);    draw_horz_line(4)
  397.   end
  398.   def draw_direction
  399.     contents.font.size = R2_Chapter_Select::Arrow_Font
  400.     contents.font.bold = true
  401.     l_x = R2_Chapter_Select::Left_Arrow_X
  402.     l_y = R2_Chapter_Select::Left_Arrow_Y
  403.     r_x = R2_Chapter_Select::Right_Arrow_X
  404.     r_y = R2_Chapter_Select::Right_Arrow_Y
  405.     @text = ""
  406.     if @index > 0
  407.       @text = R2_Chapter_Select::Left_Text
  408.     end
  409.     draw_text(l_x, l_y, 40, 100, @text, 1)
  410.     @text = ""
  411.     if @index < $chapter_data.chapter_info.size - 1
  412.       @text = R2_Chapter_Select::Right_Text
  413.     end
  414.     draw_text(r_x, r_y, 40, 100, @text, 1)
  415.     contents.font.size = Font.default_size
  416.     contents.font.bold = false
  417.   end
  418.   alias r2_chapter_update update
  419.   def update
  420.     r2_chapter_update
  421.     return if R2_Chapter_Select::Arrow_Var == 0
  422.     if $game_variables[R2_Chapter_Select::Arrow_Var] != @index
  423.       @index = $game_variables[R2_Chapter_Select::Arrow_Var]
  424.       contents.clear if R2_Chapter_Select::Arrow_Var > 0
  425.       draw_title
  426.       draw_lines
  427.       draw_direction if R2_Chapter_Select::Arrows_Text == true
  428.     end
  429.   end
  430. end
  431.  
  432. class Window_ChapterHelp < Window_Base
  433.   def initialize(line_number = R2_Chapter_Select::Help_Lines)
  434.     super(0, 0, Graphics.width, fitting_height(line_number))
  435.   end
  436.   def set_text(text)
  437.     if text != @text
  438.       @text = text
  439.       refresh
  440.     end
  441.   end
  442.   def clear
  443.     set_text("")
  444.   end
  445.   def set_item(item)
  446.     set_text(item ? item.description : "")
  447.   end
  448.   def refresh
  449.     contents.clear
  450.     draw_text_ex(4, 0, @text)
  451.   end
  452. end
  453.  
  454. class Window_Chapter_Choose < Window_Selectable
  455.   def initialize
  456.     super(window_x,window_y, window_width, window_height)
  457.     if R2_Chapter_Select::Column_Max == 4
  458.       @ch_sh = [0, 1, 2, 3] # chapter shown
  459.     else
  460.       @ch_sh = [0, 1, 2, 3, 4] # chapter shown
  461.     end
  462.     @chap_image = []
  463.     @text = []
  464.     @place = 0
  465.     @index_pos = 0
  466.     @index = 0
  467.     create_help_window
  468.     update_pictures
  469.     self.z = 101
  470.     select(0)
  471.     activate
  472.   end
  473.   def window_x
  474.     return R2_Chapter_Select::Chapter_Window_X
  475.   end
  476.   def window_y
  477.     return R2_Chapter_Select::Chapter_Window_Y
  478.   end
  479.   def window_width
  480.     return Graphics.width - R2_Chapter_Select::Chapter_Width
  481.   end
  482.   def window_height
  483.     return Graphics.height - R2_Chapter_Select::Chapter_Height
  484.   end
  485.   def col_max
  486.     return R2_Chapter_Select::Column_Max
  487.   end
  488.   def spacing
  489.     return R2_Chapter_Select::Spacing
  490.   end
  491.   def item_max
  492.     return $chapter_data.chapter_info.size
  493.   end
  494.   def item_width
  495.     return R2_Chapter_Select::Select_Width
  496.   end
  497.   def item_height
  498.     return R2_Chapter_Select::Select_Height
  499.   end
  500.   def row_max
  501.     return 1
  502.   end
  503.   def standard_padding
  504.     return R2_Chapter_Select::Window_Padding
  505.   end
  506.   def create_help_window
  507.     @help_window = Window_ChapterHelp.new
  508.     @help_window.y = Graphics.height - @help_window.height + 4
  509.     @help_window.opacity = 0
  510.   end
  511.   def show_chapters
  512.     @ch_sh.each_with_index do |i, j|
  513.       if $chapter_data.chapter_info[i][:locked] == true
  514.         image = R2_Chapter_Select::Locked
  515.       else
  516.         image = $chapter_data.chapter_info[i][:image]
  517.       end
  518.       draw_image(image, i, j)
  519.       @text = $chapter_data.chapter_info[i][:title]
  520.       draw_chapter_title(j, @text)
  521.     end
  522.   end
  523.   def draw_chapter_title(j, text)
  524.     rect = Rect.new
  525.     r_x = R2_Chapter_Select::Chapter_Text_X
  526.     r_y = R2_Chapter_Select::Chapter_Text_Y
  527.     rect.width = r_x
  528.     rect.height = 40
  529.     rect.x = (r_x * j) + (j * standard_padding / 2) + j * 8
  530.     rect.y = r_y
  531.     draw_text(rect.x, rect.y, rect.width, rect.height, text, 1)
  532.   end
  533.   def update_pictures
  534.     contents.clear
  535.     clear_image
  536.     if @index == 0
  537.       if R2_Chapter_Select::Column_Max == 5
  538.         @ch_sh = [0, 1, 2, 3, 4]
  539.       else
  540.         @ch_sh = [0, 1, 2, 3]
  541.       end
  542.     elsif @index == $chapter_data.chapter_info.size - 1
  543.       max = $chapter_data.chapter_info.size.to_i - 1
  544.       last = max
  545.       sndlast = max - 1
  546.       thrlast = max - 2
  547.       frthlast = max - 3
  548.       ffthlast = max - 4
  549.       if R2_Chapter_Select::Column_Max == 5
  550.         @ch_sh = [ffthlast, frthlast, thrlast, sndlast, last]
  551.       else
  552.         @ch_sh = [frthlast, thrlast, sndlast, last]
  553.       end
  554.     elsif (@index > 0) && (@index < $chapter_data.chapter_info.size) && (@index < @ch_sh[0])
  555.       if R2_Chapter_Select::Column_Max == 5
  556.         max = @ch_sh[4].to_i
  557.       else
  558.         max = @ch_sh[3].to_i
  559.       end
  560.       last = max - 1
  561.       sndlast = max - 2
  562.       thrlast = max - 3
  563.       frthlast = max - 4
  564.       ffthlast = max - 5
  565.       if R2_Chapter_Select::Column_Max == 5
  566.         @ch_sh = [ffthlast, frthlast, thrlast, sndlast, last]
  567.       else
  568.         @ch_sh = [frthlast, thrlast, sndlast, last]
  569.       end
  570.     else
  571.       if R2_Chapter_Select::Column_Max == 5
  572.         if (@index > 4) && (@index < $chapter_data.chapter_info.size - 1) && (@index > @ch_sh[4])
  573.           max = @ch_sh[4].to_i
  574.           last = max + 1
  575.           sndlast = max
  576.           thrlast = max - 1
  577.           frthlast = max - 2
  578.           ffthlast = max - 3
  579.           @ch_sh = [ffthlast, frthlast, thrlast, sndlast, last]
  580.         end
  581.       else
  582.         if (@index > 3) && (@index < $chapter_data.chapter_info.size - 1) && (@index > @ch_sh[3])
  583.           max = @ch_sh[3].to_i
  584.           last = max + 1
  585.           sndlast = max
  586.           thrlast = max - 1
  587.           frthlast = max - 2
  588.           @ch_sh = [frthlast, thrlast, sndlast, last]
  589.         end
  590.       end
  591.     end
  592.     show_arrows
  593.     show_chapters
  594.     show_last
  595.   end
  596.   def draw_image(file, i, j)
  597.     @chap_image[i] = Sprite.new
  598.     @chap_image[i].bitmap = Cache.system(file)
  599.     i_x = R2_Chapter_Select::Image_Base_X
  600.     i_y = R2_Chapter_Select::Image_Base_Y
  601.     i_a = R2_Chapter_Select::Image_Base_Adjust
  602.     i_w = R2_Chapter_Select::Chapter_Window_X
  603.     case j
  604.     when 0
  605.       @chap_image[i].x = i_x + i_w + j * 106 + i_a * j - j * 4 # 68
  606.       @chap_image[i].y = i_y + standard_padding / 2
  607.     when 1
  608.       @chap_image[i].x = i_x + i_w + j * 106 + i_a * j - j * 4 # 172
  609.       @chap_image[i].y = i_y + standard_padding / 2
  610.     when 2
  611.       @chap_image[i].x = i_x + i_w + j * 106 + i_a * j - j * 4 # 278
  612.       @chap_image[i].y = i_y + standard_padding / 2
  613.     when 3
  614.       @chap_image[i].x = i_x + i_w + j * 106 + i_a * j - j * 4 # 384
  615.       @chap_image[i].y = i_y + standard_padding / 2
  616.     when 4
  617.       @chap_image[i].x = i_x + i_w + j * 106 + i_a * j - j * 4 # 490
  618.       @chap_image[i].y = i_y + standard_padding / 2
  619.     end
  620.     @chap_image[i].z = 102
  621.   end
  622.   def show_arrows
  623.     $game_variables[R2_Chapter_Select::Arrow_Var] = @index
  624.     if @index > 0
  625.       draw_left
  626.     else
  627.       clear_left
  628.     end
  629.     if @index < $chapter_data.chapter_info.size - 1
  630.       draw_right
  631.     else
  632.       clear_right
  633.     end
  634.   end
  635.   def show_last
  636.     return if R2_Chapter_Select::Last_Marker == false
  637.     @last_mark = Sprite.new
  638.     @last_mark.bitmap = Cache.system(R2_Chapter_Select::Last_Image)
  639.     m_x = R2_Chapter_Select::Chapter_Text_X
  640.         m_a = R2_Chapter_Select::Last_Mark_Adjust
  641.     @last_mark.x = -200
  642.     @ch_sh.each_with_index do |d, m|
  643.       @last_mark.x = m * m_x + m_a if $chapter_data.chapter_info[d][:last] == true
  644.     end
  645.     @last_mark.y = R2_Chapter_Select::Last_Mark_Y
  646.     @last_mark.z = 111
  647.   end
  648.   def draw_left
  649.     return if R2_Chapter_Select::Arrows == false
  650.     @l_arrow = Sprite.new
  651.     @l_arrow.bitmap = Cache.system(R2_Chapter_Select::Left_Arrow)
  652.     @l_arrow.x = R2_Chapter_Select::Left_X
  653.     @l_arrow.y = R2_Chapter_Select::Left_Y
  654.     @l_arrow.z = 110
  655.   end
  656.   def draw_right
  657.     return if R2_Chapter_Select::Arrows == false
  658.     @r_arrow = Sprite.new
  659.     @r_arrow.bitmap = Cache.system(R2_Chapter_Select::Right_Arrow)
  660.     @r_arrow.x = R2_Chapter_Select::Right_X
  661.     @r_arrow.y = R2_Chapter_Select::Right_Y
  662.     @r_arrow.z = 110
  663.   end
  664.   def clear_left
  665.     return if @l_arrow.nil?
  666.     @l_arrow.bitmap.dispose
  667.     @l_arrow.dispose
  668.   end
  669.   def clear_right
  670.     return if @r_arrow.nil?
  671.     @r_arrow.bitmap.dispose
  672.     @r_arrow.dispose
  673.   end
  674.   def clear_image
  675.     for i in 0..@chap_image.size - 1
  676.       next if @chap_image[i].nil?
  677.       @chap_image[i].bitmap.dispose
  678.       @chap_image[i].dispose
  679.     end
  680.     @help_window.set_text("")
  681.     @r_arrow.bitmap.dispose if @r_arrow
  682.     @r_arrow.dispose if @r_arrow
  683.     @l_arrow.bitmap.dispose if @l_arrow
  684.     @l_arrow.dispose if @l_arrow
  685.     @last_mark.bitmap.dispose if @last_mark
  686.     @last_mark.dispose if @last_mark
  687.   end
  688.   def terminate
  689.     super
  690.     for i in 0..@chap_image.size - 1
  691.       next if @chap_image[i].nil?
  692.       @chap_image[i].bitmap.dispose
  693.       @chap_image[i].dispose
  694.       @text[i].dispose if @text[i]
  695.     end
  696.     @r_arrow.bitmap.dispose if @r_arrow
  697.     @r_arrow.dispose if @r_arrow
  698.     @l_arrow.bitmap.dispose if @l_arrow
  699.     @l_arrow.dispose if @l_arrow
  700.     @last_mark.bitmap.dispose
  701.     @last_mark.dispose
  702.   end
  703.   def cursor_down(wrap = false)
  704.   end
  705.   def cursor_up(wrap = false)
  706.   end
  707.   def cursor_pagedown
  708.   end
  709.   def cursor_pageup
  710.   end
  711.   def cursor_right(wrap = false)
  712.     if col_max >= 2 && (index < item_max - 1 || (wrap && horizontal?))
  713.       @index_pos = ((index + 1) % item_max)
  714.       if R2_Chapter_Select::Column_Max == 5
  715.         if (@index_pos > 4) && (@index_pos < ($chapter_data.chapter_info.size)) && (@place == 4)
  716.           select(4)
  717.           @place = 4
  718.         elsif (@index_pos > 0) && (@index_pos < ($chapter_data.chapter_info.size - 1)) && (@place < 4)
  719.           @place += 1
  720.           select(@place)
  721.         elsif (@index_pos > 0) && (@index_pos == ($chapter_data.chapter_info.size - 1)) && (@place == 4)
  722.           @place = 0
  723.           select(@place)
  724.         elsif (@index_pos == ($chapter_data.chapter_info.size - 1)) && (@place < 4)
  725.           select(4)
  726.           @place = 4
  727.         elsif (@index_pos == 0) && (@place == 4)
  728.           @place = 0
  729.           select(@place)
  730.         else
  731.           select(@place)
  732.         end
  733.       else
  734.         if (@index_pos > 3) && (@index_pos < ($chapter_data.chapter_info.size)) && (@place == 3)
  735.           select(3)
  736.           @place = 3
  737.         elsif (@index_pos > 0) && (@index_pos < ($chapter_data.chapter_info.size - 1)) && (@place < 3)
  738.           @place += 1
  739.           select(@place)
  740.         elsif (@index_pos > 0) && (@index_pos == ($chapter_data.chapter_info.size - 1)) && (@place == 3)
  741.           @place = 0
  742.           select(@place)
  743.         elsif (@index_pos == ($chapter_data.chapter_info.size - 1)) && (@place < 3)
  744.           select(3)
  745.           @place = 3
  746.         elsif (@index_pos == 0) && (@place == 3)
  747.           @place = 0
  748.           select(@place)
  749.         else
  750.           select(@place)
  751.         end
  752.       end
  753.       @index = @index_pos
  754.     end
  755.     update_pictures
  756.   end
  757.   def cursor_left(wrap = false)
  758.     if col_max >= 2 && (index > 0 || (wrap && horizontal?))
  759.       @index_pos = (index - 1 + item_max) % item_max
  760.       if (@index_pos > 0) && (@index_pos < ($chapter_data.chapter_info.size - 1)) && (@place == 0)
  761.         select(0)
  762.         @place = 0
  763.       elsif (@index_pos > 0) && (@index_pos < ($chapter_data.chapter_info.size - 1)) && (@place > 0)
  764.         @place -= 1
  765.         select(@place)
  766.       elsif (@index_pos == 0) && (@place == 0)
  767.         @place = 0
  768.         select(@place)
  769.       elsif (@index_pos == 0) && (@place > 0)
  770.         @place = 0
  771.         select(@place)
  772.       elsif (@index_pos == ($chapter_data.chapter_info.size - 1)) && (@place == 0) && R2_Chapter_Select::Column_Max == 5
  773.         @place = 4
  774.         select(@place)
  775.       elsif (@index_pos == ($chapter_data.chapter_info.size - 1)) && (@place == 0)
  776.         @place = 3
  777.         select(@place)
  778.       else
  779.         @place -= 1 unless @index_pos == 0 || @place == 0
  780.         select(@place)
  781.       end
  782.       @index = @index_pos
  783.     end
  784.     update_pictures
  785.   end
  786.   def process_cursor_move
  787.     return unless cursor_movable?
  788.     last_index = @index
  789.     cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:RIGHT)
  790.     cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:LEFT)
  791.     cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  792.     cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  793.     Sound.play_cursor if @index != last_index
  794.     if @index <= 0
  795.       @index = 0
  796.     elsif @index >= $chapter_data.chapter_info.size
  797.       @index = $chapter_data.chapter_info.size
  798.     end
  799.     if $chapter_data.chapter_info[@index][:locked] == true
  800.       @help_window.set_text(R2_Chapter_Select::Locked_Text)
  801.     else
  802.       @help_window.set_text($chapter_data.chapter_info[@index][:description])
  803.     end
  804.   end
  805. end
  806.  
  807. class Scene_Title < Scene_Base
  808.   def command_new_game
  809.       DataManager.setup_new_game
  810.       close_command_window
  811.       fadeout_all
  812.       $game_switches[R2_Chapter_Select::Control_Switch] = true
  813.       SceneManager.call(Scene_Chapter)
  814.   end
  815. end
  816.  
  817. class Scene_Chapter < Scene_Base
  818.   def start
  819.     super
  820.     create_chapter_back
  821.     create_back_window
  822.     create_command_window
  823.   end
  824.   def create_chapter_back
  825.     @chapterback = Sprite.new
  826.     @chapterback.bitmap = Cache.system(R2_Chapter_Select::Background)
  827.     @chapterback.tone.set(0, 0, 0, 180)
  828.   end
  829.   def terminate
  830.     super
  831.     @chapterback.bitmap.dispose if @spritech
  832.     @chapterback.dispose if @spritech
  833.     @back_window.dispose
  834.     @chapter_window.clear_image
  835.   end
  836.   def create_back_window
  837.     @back_window = Window_Chapter_Back.new
  838.   end
  839.   def create_command_window
  840.     @chapter_window = Window_Chapter_Choose.new
  841.     @chapter_window.set_handler(:ok, method(:chapter))
  842.     @chapter_window.set_handler(:cancel, method(:on_chapter_cancel))
  843.   end
  844.   def chapter
  845.     id = @chapter_window.index
  846.     if $chapter_data.chapter_info[id][:locked] == true
  847.       Sound.play_buzzer
  848.       @chapter_window.activate
  849.       return
  850.     else
  851.       fadeout_all
  852.       DataManager.setup_chapter(id)
  853.       $game_map.autoplay
  854.     end
  855.     SceneManager.goto(Scene_Map)
  856.   end
  857.   def on_chapter_cancel
  858.     Sound.play_cancel
  859.     fadeout_all
  860.     terminate
  861.     if $game_switches[R2_Chapter_Select::Control_Switch] == true
  862.       SceneManager.goto(Scene_Title)
  863.     else
  864.       return_scene
  865.     end
  866.   end
  867. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement