Advertisement
roninator2

Kid Friendly Basic Quest - Spell Menu

Dec 14th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.48 KB | None | 0 0
  1. # ╔═════════════════════════════════════╦════════════════════╗
  2. # ║ Title: KFBQ Spell Menu Functions    ║  Version: 1.00     ║
  3. # ║ Author: Roninator2                  ║                    ║
  4. # ╠═════════════════════════════════════╬════════════════════╣
  5. # ║ Function:                           ║   Date Created     ║
  6. # ║                                     ╠════════════════════╣
  7. # ║   FFMQ Style Spell Screens          ║    09 Mar 2023     ║
  8. # ╚═════════════════════════════════════╩════════════════════╝
  9. # ╔══════════════════════════════════════════════════════════╗
  10. # ║ Instructions:                                            ║
  11. # ║                                                          ║
  12. # ║  Set the Windows to look like FFMQ.                      ║
  13. # ║                                                          ║
  14. # ╚══════════════════════════════════════════════════════════╝
  15. # ╔══════════════════════════════════════════════════════════╗
  16. # ║ Terms of use:                                            ║
  17. # ║ Free for all uses in RPG Maker - Except nudity           ║
  18. # ╚══════════════════════════════════════════════════════════╝
  19.  
  20. #==============================================================================
  21. # ** Window_Help
  22. #==============================================================================
  23. class Window_SpellHelp < Window_Base
  24.   #--------------------------------------------------------------------------
  25.   # * Object Initialization
  26.   #--------------------------------------------------------------------------
  27.   def initialize(line_number = 1)
  28.     super(0, 0, Graphics.width / 2, fitting_height(line_number))
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Set Text
  32.   #--------------------------------------------------------------------------
  33.   def set_text(text)
  34.     if text != @text
  35.       @text = text
  36.       refresh
  37.     end
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # * Clear
  41.   #--------------------------------------------------------------------------
  42.   def clear
  43.     set_text("")
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # * Set Item
  47.   #     item : Skills and items etc.
  48.   #--------------------------------------------------------------------------
  49.   def set_item(item)
  50.     set_text(item ? item.name : "")
  51.   end
  52.   #--------------------------------------------------------------------------
  53.   # * Refresh
  54.   #--------------------------------------------------------------------------
  55.   def refresh
  56.     contents.clear
  57.     draw_text_ex(4, 0, @text)
  58.   end
  59. end
  60.  
  61. #==============================================================================
  62. # ** Window_Item_Command
  63. #==============================================================================
  64. class Window_Spell_Command < Window_Base
  65.   #--------------------------------------------------------------------------
  66.   # * Iniatilize
  67.   #--------------------------------------------------------------------------
  68.   def initialize
  69.     super(Graphics.width / 2, 0, Graphics.width / 2, fitting_height(1))
  70.     refresh
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Dispose
  74.   #--------------------------------------------------------------------------
  75.   def dispose
  76.     contents.dispose unless disposed?
  77.     super unless disposed?
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Refresh
  81.   #--------------------------------------------------------------------------
  82.   def refresh
  83.     contents.clear
  84.     change_color(crisis_color)
  85.     name = "Spells"
  86.     draw_text(4, 0, 200, line_height, name, 1)
  87.   end
  88. end
  89.  
  90. #==============================================================================
  91. # ** Window_SkillList
  92. #==============================================================================
  93. class Window_SpellList < Window_Selectable
  94.   #--------------------------------------------------------------------------
  95.   # * Object Initialization
  96.   #--------------------------------------------------------------------------
  97.   def initialize(x, y, width, height)
  98.     super
  99.     self.back_opacity = 0
  100.     @actor = nil
  101.     @data = []
  102.     self.unselect
  103.     self.deactivate
  104.     @active_window = 0
  105.     @move_pos = 0
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # * Set Actor
  109.   #--------------------------------------------------------------------------
  110.   def actor=(actor)
  111.     return if @actor == actor
  112.     @actor = actor
  113.     refresh
  114.     self.oy = 0
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Get Digit Count
  118.   #--------------------------------------------------------------------------
  119.   def col_max
  120.     return 3
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Get Data
  124.   #--------------------------------------------------------------------------
  125.   def check_data
  126.     return @data
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # * Get Item Height
  130.   #--------------------------------------------------------------------------
  131.   def item_height
  132.     return 60
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * Get Skill
  136.   #--------------------------------------------------------------------------
  137.   def item
  138.     @data && index >= 0 ? @data[index] : nil
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Get Number of Items
  142.   #--------------------------------------------------------------------------
  143.   def item_max
  144.     @data ? @data.size : 1
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # * Get Activation State of Selection Item
  148.   #--------------------------------------------------------------------------
  149.   def current_item_enabled?
  150.     return true
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # * Include in Skill List?
  154.   #--------------------------------------------------------------------------
  155.   def include?(item)
  156.     return true
  157.   end
  158.   #--------------------------------------------------------------------------
  159.   # * Display Skill in Active State?
  160.   #--------------------------------------------------------------------------
  161.   def enable?(item)
  162.     return true
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Create Skill List
  166.   #--------------------------------------------------------------------------
  167.   def make_item_list
  168.     @data = []
  169.     subtract = 0
  170.     for i in 3..$data_skills.size - 1
  171.       spell = $data_skills[i]
  172.       @data[i-3] = nil
  173.       if !spell.kfbq_exclude?
  174.         @data[i-3] = nil unless !@data[i-1].nil?
  175.       else
  176.         subtract += 1
  177.         next
  178.       end
  179.       if @actor.skills.include?(spell)
  180.         spell.note.split(/[\r\n]+/).each { |line|
  181.           case line
  182.           when /<position:[-_ ](\d+)>/i
  183.             pos = $1.to_i
  184.             @data[pos-1-subtract] = spell
  185.           end
  186.         }
  187.       end
  188.     end
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * Restore Previous Selection Position
  192.   #--------------------------------------------------------------------------
  193.   def select_last
  194.     select(0)
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # * Draw Item
  198.   #--------------------------------------------------------------------------
  199.   def draw_item(index)
  200.     skill = @data[index]
  201.     if skill
  202.       rect = item_rect(index)
  203.       rect.width -= 4
  204.       pos = index % 3
  205.       case pos
  206.       when 0
  207.         ox = 15
  208.       when 1
  209.         ox = 25
  210.       when 2
  211.         ox = 35
  212.       end
  213.       draw_icon(skill.icon_index, rect.x + ox, rect.y, enable?(skill))
  214.     end
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # * Update Help Text
  218.   #--------------------------------------------------------------------------
  219.   def update_help
  220.     @help_window.set_item(item)
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # * Refresh
  224.   #--------------------------------------------------------------------------
  225.   def refresh
  226.     make_item_list
  227.     create_contents
  228.     draw_all_items
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   # * Item Rect
  232.   #--------------------------------------------------------------------------
  233.   def item_rect(index)
  234.     rect = Rect.new
  235.     rect.width = 60
  236.     rect.height = 60
  237.     rect.x = index % col_max * (60)
  238.     rect.y = index / col_max * (60)
  239.     rect
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # * Update Cursor
  243.   #--------------------------------------------------------------------------
  244.   def update_cursor
  245.     ensure_cursor_visible
  246.     cursor_rect.set(item_rect(@index))
  247.     cursor_rect.height -= 10
  248.     pos = @index % 3
  249.     case pos
  250.     when 0
  251.       cursor_rect.x += 10
  252.     when 1
  253.       cursor_rect.x += 20
  254.     when 2
  255.       cursor_rect.x += 30
  256.     end
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # * Set Cursor Position
  260.   #--------------------------------------------------------------------------
  261.   def index=(index)
  262.     @index = index
  263.     update_cursor
  264.     call_update_help
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # * Move Cursor Right
  268.   #--------------------------------------------------------------------------
  269.   def cursor_right(wrap = false)
  270.     pos = @index % 3
  271.     case pos
  272.     when 2
  273.       if @active_window == 0
  274.         SceneManager.scene.swap_window_right(@index)
  275.       end
  276.     else
  277.       if col_max >= 2 && (index < item_max - 1 || (wrap && horizontal?))
  278.         select((index + 1) % item_max)
  279.       end
  280.     end
  281.     if @move_index
  282.       @index -= 1
  283.       update_cursor
  284.       @move_index = false
  285.     end
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # * Check if windows Changed
  289.   #--------------------------------------------------------------------------
  290.   def check_move=(move = false)
  291.     @move_index = move
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # * Move Cursor Left
  295.   #--------------------------------------------------------------------------
  296.   def cursor_left(wrap = false)
  297.     pos = @index % 3
  298.     case pos
  299.     when 0
  300.       if @active_window == 1
  301.         SceneManager.scene.swap_window_left(@index)
  302.       end
  303.     else
  304.       if col_max >= 2 && (index > 0 || (wrap && horizontal?))
  305.         select((index - 1 + item_max) % item_max)
  306.       end
  307.     end
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Window Active
  311.   #--------------------------------------------------------------------------
  312.   def active_window=(win = 0)
  313.     @active_window = win
  314.   end
  315. end
  316.  
  317. #==============================================================================
  318. # ■ Window Spell Count
  319. #==============================================================================
  320. class Window_KFBQSpellCount < Window_Base
  321.   #--------------------------------------------------------------------------
  322.   # * Object Initialization
  323.   #--------------------------------------------------------------------------
  324.   def initialize(x, y, w, h)
  325.     super(x, y, w, h)
  326.     self.back_opacity = 255
  327.     @actor1 = $game_party.members[0]
  328.     @actor2 = $game_party.members[1]
  329.     draw_data
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * Get Line Height
  333.   #--------------------------------------------------------------------------
  334.   def line_height
  335.     return 24
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # * Get Line Height
  339.   #--------------------------------------------------------------------------
  340.   def refresh
  341.     contents.clear
  342.     draw_data
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Dispose
  346.   #--------------------------------------------------------------------------
  347.   def dispose
  348.     return if @spell_image.nil?
  349.     @spell_image.bitmap.dispose
  350.     @spell_image.dispose
  351.     super
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # * Draw Data
  355.   #--------------------------------------------------------------------------
  356.   def draw_data
  357.     draw_base_image
  358.     draw_spell_count
  359.   end
  360.   #--------------------------------------------------------------------------
  361.   # * Draw Base Image
  362.   #--------------------------------------------------------------------------
  363.   def draw_base_image
  364.     @spell_image = Sprite.new
  365.     @spell_image.bitmap = Cache.system("Magic_Left")
  366.     @spell_image.x = 0
  367.     @spell_image.y = 332
  368.     @spell_image.z = 70
  369.   end
  370.   #--------------------------------------------------------------------------
  371.   # * Draw Spell Count
  372.   #--------------------------------------------------------------------------
  373.   def draw_spell_count
  374.     draw_text(20, -5, 30, 24, @actor1.whitespells, 1)
  375.     draw_text(100, -5, 30, 24, @actor1.blackspells, 1)
  376.     draw_text(180, -5, 30, 24, @actor1.wizardspells, 1)
  377.     if @actor2
  378.       draw_text(325, -5, 30, 24, @actor2.whitespells, 1)
  379.       draw_text(400, -5, 30, 24, @actor2.blackspells, 1)
  380.       draw_text(480, -5, 30, 24, @actor2.wizardspells, 1)
  381.     end
  382.   end
  383. end
  384.  
  385. #==============================================================================
  386. # ** Scene_Spell
  387. #==============================================================================
  388. class Scene_Spell < Scene_ItemBase
  389.   #--------------------------------------------------------------------------
  390.   # * Start Processing
  391.   #--------------------------------------------------------------------------
  392.   def start
  393.     super
  394.     create_help_window
  395.     create_spell_window
  396.     create_spell_window2
  397.     create_spell_command
  398.     create_spell_count_window
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # * Create Help Window
  402.   #--------------------------------------------------------------------------
  403.   def create_help_window
  404.     @help_window = Window_SpellHelp.new
  405.     @help_window.viewport = @viewport
  406.   end
  407.   #--------------------------------------------------------------------------
  408.   # * Create Item Command Text Window
  409.   #--------------------------------------------------------------------------
  410.   def create_spell_command
  411.     @command_window = Window_Spell_Command.new
  412.     @command_window.viewport = @viewport
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # * Create Item Window
  416.   #--------------------------------------------------------------------------
  417.   def create_spell_window
  418.     ww = Graphics.width / 2
  419.     wh = Graphics.height - 208
  420.     @spell_window = Window_SpellList.new(0, 48, ww, wh)
  421.     @spell_window.actor = $game_party.members[0]
  422.     @spell_window.viewport = @viewport
  423.     @spell_window.help_window = @help_window
  424.     @spell_window.actor = $game_party.members[0]
  425.     @spell_window.activate
  426.     @spell_window.select(0)
  427.     @spell_window.set_handler(:ok,     method(:on_item_ok))
  428.     @spell_window.set_handler(:cancel, method(:return_scene))
  429.     @left = true
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # * Create Item Window2
  433.   #--------------------------------------------------------------------------
  434.   def create_spell_window2
  435.     ww = Graphics.width / 2
  436.     wh = Graphics.height - 208
  437.     @spell_window2 = Window_SpellList.new(ww, 48, ww, wh)
  438.     @spell_window2.actor = $game_party.members[1]
  439.     @spell_window2.viewport = @viewport
  440.     @spell_window2.help_window = @help_window
  441.     @spell_window2.actor = $game_party.members[1]
  442.     @spell_window2.set_handler(:ok,     method(:on_item_ok))
  443.     @spell_window2.set_handler(:cancel, method(:return_scene))
  444.     @spell_window2.deactivate
  445.   end
  446.   #--------------------------------------------------------------------------
  447.   # * Swap Window from right to left
  448.   #--------------------------------------------------------------------------
  449.   def swap_window_left(index)
  450.     @left = true
  451.     @spell_window.active_window = 0
  452.     @spell_window2.active_window = 0
  453.     @spell_window2.unselect
  454.     @spell_window2.deactivate
  455.     @spell_window.activate
  456.     @spell_window.select(index+2)
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * Swap Window from left to roght
  460.   #--------------------------------------------------------------------------
  461.   def swap_window_right(index)
  462.     if @spell_window2.check_data == []
  463.       Sound.play_buzzer
  464.       return
  465.     end
  466.     @spell_window.active_window = 1
  467.     @spell_window2.active_window = 1
  468.     @spell_window.unselect
  469.     @spell_window.deactivate
  470.     @spell_window2.activate
  471.     @left = false
  472.     @spell_window2.select(index-2)
  473.     @spell_window2.check_move=(true)
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # * Specify Item
  477.   #--------------------------------------------------------------------------
  478.   def item
  479.     if @left == true
  480.       return @spell_window.item
  481.     else
  482.       return @spell_window2.item
  483.     end
  484.   end
  485.   #--------------------------------------------------------------------------
  486.   # * Show Actor Select Window
  487.   #--------------------------------------------------------------------------
  488.   def show_sub_window(window)
  489.     window.show.activate
  490.   end
  491.   #--------------------------------------------------------------------------
  492.   # * Activate Item Window
  493.   #--------------------------------------------------------------------------
  494.   def activate_item_window
  495.     if @left == true
  496.       @spell_window.activate
  497.       @spell_window.select_last
  498.     else
  499.       @spell_window2.activate
  500.       @spell_window2.select_last
  501.     end
  502.   end
  503.   #--------------------------------------------------------------------------
  504.   # * Confirm Item
  505.   #--------------------------------------------------------------------------
  506.   def determine_item
  507.     if item.for_friend?
  508.       show_sub_window(@actor_window)
  509.       @actor_window.select_for_item(item)
  510.     else
  511.       use_item if SceneManager.scene_is?(Scene_Battle)
  512.       activate_item_window
  513.     end
  514.   end
  515.   #--------------------------------------------------------------------------
  516.   # * Item [OK]
  517.   #--------------------------------------------------------------------------
  518.   def on_item_ok
  519.     @spell_window2.deactivate
  520.     @spell_window.deactivate
  521.     @actor.last_skill.object = item
  522.     determine_item if !item.nil?
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   # * Item [Cancel]
  526.   #--------------------------------------------------------------------------
  527.   def on_item_cancel
  528.     activate_item_window
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # * Play SE When Using Item
  532.   #--------------------------------------------------------------------------
  533.   def play_se_for_item
  534.     Sound.play_use_skill
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # * Create Spell Count Window
  538.   #--------------------------------------------------------------------------
  539.   def create_spell_count_window
  540.     @spell_count_window = Window_KFBQSpellCount.new(0, Graphics.height - 160, Graphics.width, 60)
  541.     @spell_count_window.z = 60
  542.     @actor_window.spell_count = @spell_count_window
  543.   end
  544. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement