Advertisement
Guest User

FF9 Help 1.11

a guest
Oct 30th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 29.38 KB | None | 0 0
  1. #==============================================================================
  2. # ** FF9 Help
  3. #------------------------------------------------------------------------------
  4. # Author: BuddySievers/Griver03
  5. #
  6. # Version History:
  7. #   v1.00 - 2015.10.15 > First release
  8. #   v1.01 - 2015.10.23 > First public release
  9. #   v1.02 - 2015.10.24 > Fixed a bug with toggle on/off when there is no help available
  10. #   v1.03 - 2015.10.24 > Forgot to call a method in Window_Selectable from the last update.
  11. #   v1.04 - 2015.10.25 > Optimized window positioning.
  12. #   v1.10 - 2015.10.28 > Optimized code and fixed the update proccess which caused lag.
  13. #   v1.11 - 2015.10.28 > Added window shadows.
  14. #
  15. # Credits:
  16. #   TheoAllen for his 'Command Help Popup' script which was the base for this.
  17. #   Vlue for parts of his 'Popup Window' script.
  18. #   vFoggy from rpgmakervxace.net forums for the 'index_of_visible_row' method.
  19. #   RedShard from rpgmakervxace.net forums for asking me to release it.
  20. #
  21. #------------------------------------------------------------------------------
  22. # Description:
  23. #   This is a clone from the help system of SquareSoft's masterpiece
  24. #   'Final Fantasy IX' which i actually made for my own project.
  25. #   The rpgmakervxace.net forums user RedShard asked me if i plan to release
  26. #   it but it was a mess, not plug and play and not user friendly at all so
  27. #   i cleaned up the code and added a simple configuration module.
  28. #
  29. #------------------------------------------------------------------------------
  30. # Compatibility:
  31. #   Requires the script 'Victor Engine - Arrow Cursor' v 1.01 or higher
  32. #   which in turn rquires 'Victor Engine - Basic Module' v 1.09 or higher.
  33. #
  34. #------------------------------------------------------------------------------
  35. # Instructions:
  36. #   To instal the script, open you script editor and paste this script on
  37. #   a new section on bellow the Materials section. This script must also
  38. #   be bellow the scripts 'Victor Engine - Basic Module' and
  39. #   'Victor Engine - Arrow Cursor'.
  40. #   Place all of the scripts above the most other custom scripts best compatibility!
  41. #
  42. #------------------------------------------------------------------------------
  43. # Additional Info:
  44. #   The all graphics must be in the folder Graphics/System/FF9_Help.
  45. #
  46. #   If you want to use custom graphics you have to edit the script yourself.
  47. #   It was hard enough for me to get this done and its far away from beeing
  48. #   perfect so dont ask me for help when you want to use custom graphics.
  49. #   If you need help with anything else or a have bug to report feel free
  50. #   to contact me at http://www.rpgmakervxace.net/ forums!
  51. #
  52. #   I hope you enjoy this script and i would like to see it when you
  53. #   give TheoAllen, Vlue, vFoggy and maybe me credits in your game! :)
  54. #
  55. #==============================================================================
  56.  
  57. #==============================================================================
  58. # ■ Config
  59. #==============================================================================
  60.  
  61. module Config
  62.   module FF9_Help
  63.   #--------------------------------------------------------------------------
  64.   # Set the key to be pressed to toggle the help on and off.
  65.   # Can be A, B, C, X, Y, Z, L, R, SHIFT, CTRL or ALT.
  66.   #--------------------------------------------------------------------------
  67.     Toggle_Key = :ALT
  68.   #--------------------------------------------------------------------------
  69.   # Auto toggle the help off when change to these scenes.
  70.   #--------------------------------------------------------------------------
  71.     Force_Deactivate = ["Scene_Map", "Scene_Title"]
  72.   #--------------------------------------------------------------------------
  73.   # Format is RPG::SE.new(Filename, Volume, Pitch)
  74.   # to set a sound effect which gets played when toggle the help on.
  75.   # Otherwise set to nil if you dont want to use a sound effect.
  76.   #--------------------------------------------------------------------------
  77.     Activate_SE = RPG::SE.new("FF9_Help_Moogle.wav", 80, 100)
  78.   #--------------------------------------------------------------------------
  79.   # Format is RPG::SE.new(Filename, Volume, Pitch)
  80.   # to set a sound effect which gets played when toggle the help off.
  81.   # Otherwise set to nil if you dont want to use a sound effect.
  82.   #--------------------------------------------------------------------------
  83.     Deactivate_SE = nil
  84.   #--------------------------------------------------------------------------
  85.   # Adjust the Z position of help window.
  86.   #--------------------------------------------------------------------------
  87.     Window_Z = 8000
  88.   #--------------------------------------------------------------------------
  89.   # Use the help window header sprite.
  90.   #--------------------------------------------------------------------------
  91.     Window_Header = true
  92.   #--------------------------------------------------------------------------
  93.   # Adjust the X position of the help window header sprite.
  94.   # Can be negative, like -2.
  95.   #--------------------------------------------------------------------------
  96.     Header_X = 8
  97.   #--------------------------------------------------------------------------
  98.   # Adjust the Y position of the help window header sprite.
  99.   # Can be negative, like -2.
  100.   #--------------------------------------------------------------------------
  101.     Header_Y = 0
  102.   #--------------------------------------------------------------------------
  103.   # Change the font settings for the help window text.
  104.   #--------------------------------------------------------------------------
  105.     Font_Name = Font.default_name
  106.     Font_Size = Font.default_size
  107.     Font_Bold = false
  108.     Font_Italic = false
  109.     Font_Outline = false
  110.     Font_Shadow = false
  111.     Font_Color = Color.new(0, 0, 0, 255)
  112.     Font_Outline_Color = Color.new(0,0,0,128)
  113.   #--------------------------------------------------------------------------
  114.   # Use window shadow.
  115.   #--------------------------------------------------------------------------
  116.     Window_Shadow = true
  117.   #--------------------------------------------------------------------------
  118.   # Adjust the X position of the window shadow.
  119.   # Can be negative, like -2.
  120.   #--------------------------------------------------------------------------
  121.     Window_Shadow_X = 3
  122.   #--------------------------------------------------------------------------
  123.   # Adjust the Y position of the window shadow.
  124.   # Can be negative, like -2.
  125.   #--------------------------------------------------------------------------
  126.     Window_Shadow_Y = 3
  127.   #--------------------------------------------------------------------------
  128.   # Adjust the opacity of the window shadow. (0-255)
  129.   #--------------------------------------------------------------------------
  130.     Window_Shadow_Opacity = 120
  131.   #--------------------------------------------------------------------------
  132.   # Set here your help text's you want to show for the
  133.   # corresponding items in selectable windows.
  134.   # Works for everything with a .name variable.
  135.   # The format is "Name" => ['Text'],
  136.   # Make sure to use single quotes ('') not double quotes ("")
  137.   # Dont use \n for a new line, instead use this format ['Line 1', 'Line 2']
  138.   # If you have a ' in your string like character's use \' like character\'s
  139.   # You can use controll codes like \i[icon_id] to draw an icon or
  140.   # \c[color_id] to change the text color.
  141.   #--------------------------------------------------------------------------
  142.     Window_Selectable = {
  143.     # Items
  144.       "Potion" => ['Recovers \c[17]500 \c[15]HP.'],
  145.       "Hi-Potion" => ['Recovers \c[17]2,500 \c[15]HP.', 'Just a test line...'],
  146.       "Full Potion" => ['Recovers all HP.', 'Just a test line...', 'And another one...'],
  147.       "Magic Water" => ['Recovers \c[17]200 \c[15]MP.', 'Just a test line...', 'And another one...', 'Dude, seriously?!'],
  148.       "Stimulant" => ['Recovers ally from \c[18]death\c[15].'],
  149.       "Antidote" => ['Treats \c[18]poison\c[15].'],
  150.       "Dispel Herb" => ['Treats many status ailments.'],
  151.       "Elixir" => ['Restores all HP and MP.'],
  152.       "Life Up" => ['Increases MaxHP by \c[17]50\c[15].'],
  153.       "Mana Up" => ['Increases MaxMP by \c[17]10\c[15].'],
  154.       "Power Up" => ['Increases ATK by \c[17]3\c[15].'],
  155.       "Guard Up" => ['Increases DEF by \c[17]3\c[15].'],
  156.       "Magic Up" => ['Increases MAT by \c[17]3\c[15].'],
  157.       "Resist Up" => ['Increases MDF by \c[17]3\c[15].'],
  158.       "Speed Up" => ['Increases AGI by \c[17]3\c[15].'],
  159.       "Luck Up" => ['Increases LUK by \c[17]3\c[15].'],
  160.     # Weapons
  161.       "Hand Ax" => ['Small ax used for harvesting wood.'],
  162.       "Battle Axe" => ['Double-sided axe made for combat.'],
  163.       "Bardiche" => ['Three crescent blades on this axe.'],
  164.       "Mithril Axe" => ['Mithril axe made of the magic mineral.'],
  165.       "Crimson Axe" => ['Crimson soaked battle axe.'],
  166.       "Gigantes Axe" => ['Heavy axe used by giants.'],
  167.     # Armors
  168.       "Casual Clothes" => ['Very lightweight clothes.'],
  169.       "Leather Top" => ['Made with the best leather.'],
  170.       "Adventurer's Garb" => ['Worn clothing that can withstand a harsh journey.'],
  171.       "Hard Leather" => ['Hardened leather vest.'],
  172.       "Brigandine" => ['Clothing made with reinforced steel.'],
  173.       "Bandana" => ['Headband cloth that protects the head.'],
  174.       "Leather Bandana" => ['Headband made of leather to protect the head.'],
  175.       "Fur Hat" => ['Hat made of fur.'],
  176.       "Turban" => ['Thick cloth wrapped repeatedly around one\'s head.'],
  177.       "Feather Cap" => ['Stylish hat with feathers from many beautiful birds.'],
  178.       "Wood Shield" => ['A shield made with hard wood.'],
  179.       "Iron Shield" => ['Shield made of steel.'],
  180.       "Knight Shield" => ['Knights use this shield.'],
  181.       "Mithril Shield" => ['Mithril shield made of the magic mineral.'],
  182.       "Dragon Shield" => ['Shield made of dragon scales.'],
  183.       "War God's Belt" => ['Metal belt engraved with the War God\'s name.'],
  184.       "Defense Piece" => ['Hung at the magic forest for defense.'],
  185.       "Winged Boots" => ['The holy spirit of the wind dwell in these boots.'],
  186.       "Earth's Embrace" => ['The power of the earth protects the wearer.'],
  187.       "Lucky Charm" => ['A charm engraved with the name of the goddess of luck.'],
  188.       "Holy Symbol" => ['A symbol worn by those who serve God.'],
  189.       "Solomon's Ring" => ['A ring with the hidden power of a genie.'],
  190.       "Odin's Necklace" => ['A magic necklace that empowers those who fight.'],
  191.       "Eyepatch of Fury" => ['An eyepatch worn by powerful berserkers.'],
  192.       "Talisman of Light" => ['The king of gods dwell in this talisman.'],
  193.     # Skills
  194.       "Strong Attack" => ['A strong attack against one enemy.'],
  195.       "Cleave" => ['An attack against all enemies.'],
  196.       "Berserker's Roar" => ['For 5 turns, increase ATK of party.'],
  197.       "Berserker's Dance" => ['Axe skill.', 'Powerful attack against 3 random enemies.'],
  198.       "Giant's Rampage" => ['Axe Skill.', 'A strong attack against all enemies.'],
  199.     }
  200.   #--------------------------------------------------------------------------
  201.   # Set here your help text's you want to show for the
  202.   # corresponding commands in command windows.
  203.   # The format is "Name" => ['Text'],
  204.   # Make sure to use single quotes ('') not double quotes ("")
  205.   # Dont use \n for a new line, instead use this format ['Line 1', 'Line 2']
  206.   # If you have a ' in your string like character's use \' like character\'s
  207.   # You can use controll codes like \i[icon_id] to draw an icon or
  208.   # \c[color_id] to change the text color.
  209.   #--------------------------------------------------------------------------
  210.     Window_Command = {
  211.     # Title Scene
  212.       "New Game" => ['Start a new game.'],
  213.       "Continue" => ['Load a saved game.'],
  214.       "Shutdown" => ['Close the game.'],
  215.     # Menu Scene
  216.       "Items" => ['View items and equip you have.', 'View key items you have', 'recieved in the game.'],
  217.       "Skills" => ['View and use the character\'s skills.'],
  218.       "Equipment" => ['Change the character\'s equipment.'],
  219.       "Status" => ['View character\'s parameters', 'and learned skills.'],
  220.       "Formation" => ['Rearrange the party order.'],
  221.       "Save" => ['Save the game.'],
  222.       "Game End" => ['End the current game.'],
  223.       "System" => ['Open the game configuration.'],
  224.     # Skill Scene
  225.       "Special" => ['View learned specials.'],
  226.       "Magic" => ['View learned magic.'],
  227.     # Equipment Scene
  228.       "Change" => ['Change your current equipment.'],
  229.       "Optimize" => ['Optimize your equipment.'],
  230.       "Clear" => ['Clear your equipment.'],
  231.     # End Scene
  232.       "To Title" => ['End your current game and', 'go back to the title screen.'],
  233.       "Cancel" => ['Cancel and go back to the main menu.'],
  234.     # System Scene
  235.       "Window Red" => ['\c[18]Red \c[15]color adjustment.'],
  236.       "Window Green" => ['\c[11]Green \c[15]color adjustment.'],
  237.       "Window Blue" => ['\c[9]Blue \c[15]color adjustment.'],
  238.       "BGM Volume" => ['Background music adjustment.'],
  239.       "BGS Volume" => ['Background sound adjustment.'],
  240.       "SFX Volume" => ['Soundeffect adjustment.'],
  241.       "Auto-Dash" => ['Change default movement.'],
  242.       "Instant Text" => ['Change how dialouge text', 'is displayed.'],
  243.       "Battle Animations" => ['Disable animations in battle.'],
  244.       "Return to Title Screen" => ['End the game and return', 'to the title screen.'],
  245.       "Shutdown Game" => ['End the current game.'],
  246.     }
  247.   end
  248. end
  249.  
  250. #==============================================================================
  251. # ■ Require
  252. #==============================================================================
  253.  
  254. $imported = {} if $imported.nil?
  255. $imported[:BS_FF9_Help] = true
  256. if !$imported[:ve_arrow_cursor]
  257.   string = "The script 'Final Fantasy IX Help System' requires\n"
  258.   string += "Victor's 'Arrow Cursor' script to work.\n"
  259.   string += "Go to https://victorscripts.wordpress.com/ to download this script.\n"
  260.   string += "Remember that the script 'Arrow Cursor' in turn requires Victor's\n"
  261.   string += "'Base Module' script to work.\n"
  262.   string += "Place the 'FF9 Help' script below the 'Arrow Cursor' script."
  263.   msgbox(string)
  264.   exit
  265. end
  266.  
  267. #==============================================================================
  268. # ■ Cache
  269. #==============================================================================
  270.  
  271. module Cache
  272.  
  273.   def self.ff9_help(filename)
  274.     load_bitmap("Graphics/System/FF9_Help/", filename)
  275.   end
  276. end
  277.  
  278. #==============================================================================
  279. # ■ SceneManager
  280. #==============================================================================
  281.  
  282. module SceneManager
  283.  
  284.   class << self
  285.     alias :griver_ff9_help_scenemanager_goto :goto
  286.     alias :griver_ff9_help_scenemanager_call :call
  287.     alias :griver_ff9_help_scenemanager_return :return
  288.   end
  289.  
  290.   def self.goto(scene_class)
  291.     $ff9_help_active = false if Config::FF9_Help::Force_Deactivate.include?(scene_class.to_s)
  292.     griver_ff9_help_scenemanager_goto(scene_class)
  293.   end
  294.  
  295.   def self.call(scene_class)
  296.     $ff9_help_active = false if Config::FF9_Help::Force_Deactivate.include?(scene_class.to_s)
  297.     griver_ff9_help_scenemanager_call(scene_class)
  298.   end
  299.  
  300.   def self.return
  301.     scene_stack = @stack.dup
  302.     scene_class = scene_stack.pop
  303.     scene_name = scene_class.class.name.to_s
  304.     $ff9_help_active = false if Config::FF9_Help::Force_Deactivate.include?(scene_name)
  305.     griver_ff9_help_scenemanager_return
  306.   end
  307. end
  308.  
  309. #==============================================================================
  310. # ■ Window_Shadow
  311. #==============================================================================
  312.  
  313. class Window_Shadow < Window_Base
  314.  
  315.   def initialize
  316.     super(0, 0, 1, 1)
  317.     self.windowskin = Cache.ff9_help("FF9_Window_Shadow")
  318.     self.tone.set(Tone.new(0, 0, 0, 0))
  319.     self.opacity = Config::FF9_Help::Window_Shadow_Opacity
  320.     self.back_opacity = 255
  321.     self.visible = false
  322.   end
  323.  
  324.   def refresh(x, y, z, width, height)
  325.     self.x = x + Config::FF9_Help::Window_Shadow_X
  326.     self.y = y + Config::FF9_Help::Window_Shadow_Y
  327.     self.z = z
  328.     self.width = width
  329.     self.height = height
  330.   end
  331.  
  332.   def update_tone
  333.   end
  334. end
  335.  
  336. #==============================================================================
  337. # ■ Window_Selectable
  338. #==============================================================================
  339.  
  340. class Window_Selectable < Window_Base
  341.  
  342.   alias :griver_ff9_help_window_selectable_initialize :initialize
  343.   def initialize(*args)
  344.     griver_ff9_help_window_selectable_initialize(*args)
  345.     @ff9_help_window = Window_FF9_Help.new(viewport)
  346.   end
  347.  
  348.   alias :griver_ff9_help_window_selectable_update :update
  349.   def update
  350.     griver_ff9_help_window_selectable_update
  351.     @ff9_help_window.update
  352.     ff9_help_show if $ff9_help_active && $ff9_help_refresh && ff9_help_avalaible?
  353.   end
  354.  
  355.   alias :griver_ff9_help_window_selectable_dispose :dispose
  356.   def dispose
  357.     griver_ff9_help_window_selectable_dispose
  358.     @ff9_help_window.dispose
  359.   end
  360.  
  361.   alias :griver_ff9_help_window_selectable_process_handling :process_handling
  362.   def process_handling
  363.     griver_ff9_help_window_selectable_process_handling
  364.     return unless open? && active
  365.     if @data
  366.       if $ff9_help_active
  367.         Config::FF9_Help::Deactivate_SE.play if ff9_help_open? && Input.trigger?(Config::FF9_Help::Toggle_Key) && Config::FF9_Help::Deactivate_SE != nil
  368.         return ff9_help_toggle if Input.trigger?(Config::FF9_Help::Toggle_Key)
  369.       else
  370.         Config::FF9_Help::Activate_SE.play if ff9_help_avalaible? && Input.trigger?(Config::FF9_Help::Toggle_Key) && Config::FF9_Help::Activate_SE != nil
  371.         return ff9_help_toggle if ff9_help_avalaible? && Input.trigger?(Config::FF9_Help::Toggle_Key)
  372.       end
  373.     end
  374.   end
  375.  
  376.   alias :griver_ff9_help_window_selectable_process_ok :process_ok
  377.   def process_ok
  378.     griver_ff9_help_window_selectable_process_ok
  379.     ff9_help_hide if !self.active
  380.     $ff9_help_refresh = true
  381.   end
  382.  
  383.   alias :griver_ff9_help_window_selectable_process_cancel :process_cancel
  384.   def process_cancel
  385.     griver_ff9_help_window_selectable_process_cancel
  386.     ff9_help_hide if !self.active
  387.     $ff9_help_refresh = true
  388.   end
  389.  
  390.   alias :griver_ff9_help_window_selectable_cursor_down :cursor_down
  391.   def cursor_down(wrap = false)
  392.     griver_ff9_help_window_selectable_cursor_down(wrap)
  393.     if $ff9_help_active && ff9_help_avalaible? && cursor_movable?
  394.       ff9_help_show
  395.     else
  396.       ff9_help_hide
  397.     end
  398.   end
  399.  
  400.   alias :griver_ff9_help_window_selectable_cursor_up :cursor_up
  401.   def cursor_up(wrap = false)
  402.     griver_ff9_help_window_selectable_cursor_up(wrap)
  403.     if $ff9_help_active && ff9_help_avalaible? && cursor_movable?
  404.       ff9_help_show
  405.     else
  406.       ff9_help_hide
  407.     end
  408.   end
  409.  
  410.   alias :griver_ff9_help_window_selectable_cursor_right :cursor_right
  411.   def cursor_right(wrap = false)
  412.     griver_ff9_help_window_selectable_cursor_right(wrap)
  413.     if $ff9_help_active && ff9_help_avalaible? && cursor_movable?
  414.       ff9_help_show
  415.     else
  416.       ff9_help_hide
  417.     end
  418.   end
  419.  
  420.   alias :griver_ff9_help_window_selectable_cursor_left :cursor_left
  421.   def cursor_left(wrap = false)
  422.     griver_ff9_help_window_selectable_cursor_left(wrap)
  423.     if $ff9_help_active && ff9_help_avalaible? && cursor_movable?
  424.       ff9_help_show
  425.     else
  426.       ff9_help_hide
  427.     end
  428.   end
  429.  
  430.   alias :griver_ff9_help_window_selectable_cursor_pagedown :cursor_pagedown
  431.   def cursor_pagedown
  432.     griver_ff9_help_window_selectable_cursor_pagedown
  433.     if $ff9_help_active && ff9_help_avalaible? && cursor_movable?
  434.       ff9_help_show
  435.     else
  436.       ff9_help_hide
  437.     end
  438.   end
  439.  
  440.   alias :griver_ff9_help_window_selectable_cursor_pageup :cursor_pageup
  441.   def cursor_pageup
  442.     griver_ff9_help_window_selectable_cursor_pageup
  443.     if $ff9_help_active && ff9_help_avalaible? && cursor_movable?
  444.       ff9_help_show
  445.     else
  446.       ff9_help_hide
  447.     end
  448.   end
  449.  
  450.   def ff9_help_toggle
  451.     if $ff9_help_active
  452.       $ff9_help_active = false
  453.       ff9_help_hide
  454.     else
  455.       $ff9_help_active = true
  456.       ff9_help_show if $ff9_help_active && ff9_help_avalaible?
  457.     end
  458.   end
  459.  
  460.   def ff9_help_show
  461.     return unless open? && active
  462.     cursor_x = (@cursor[0].x - (@cursor[0].bitmap.width / 2)) - 2
  463.     cursor_y = (@cursor[0].y - (@cursor[0].bitmap.height / 2)) - 26
  464.     window_rows = [page_row_max / 2, 1].max
  465.     window_rows += 1 if !window_rows.even?
  466.     window_index = index_of_visible_row + 1
  467.     @ff9_help_window.show(ff9_help_text, cursor_x, cursor_y, window_rows, window_index)
  468.   end
  469.  
  470.   def ff9_help_hide
  471.     Config::FF9_Help::Deactivate_SE.play if ff9_help_open? && Config::FF9_Help::Deactivate_SE != nil
  472.     @ff9_help_window.hide
  473.   end
  474.  
  475.   def ff9_help_text
  476.     Config::FF9_Help::Window_Selectable[@data[index].name]
  477.   end
  478.  
  479.   def ff9_help_avalaible?
  480.     Config::FF9_Help::Window_Selectable.include?(@data[index].name) rescue false
  481.   end
  482.  
  483.   def ff9_help_open?
  484.     @ff9_help_window.open?
  485.   end
  486.  
  487.   def index_of_visible_row
  488.     row - top_row
  489.   end
  490. end
  491.  
  492. #==============================================================================
  493. # ■ Window_Command
  494. #==============================================================================
  495.  
  496. class Window_Command < Window_Selectable
  497.  
  498.   alias :griver_ff9_help_window_command_update :update
  499.   def update
  500.     griver_ff9_help_window_command_update
  501.     ff9_help_hide if @closing
  502.   end
  503.  
  504.   alias :griver_ff9_help_window_command_process_handling :process_handling
  505.   def process_handling
  506.     griver_ff9_help_window_command_process_handling
  507.     return unless open? && active
  508.     if $ff9_help_active
  509.       Config::FF9_Help::Deactivate_SE.play if ff9_help_open? && Input.trigger?(Config::FF9_Help::Toggle_Key) && Config::FF9_Help::Deactivate_SE != nil
  510.       return ff9_help_toggle if Input.trigger?(Config::FF9_Help::Toggle_Key)
  511.     else
  512.       Config::FF9_Help::Activate_SE.play if ff9_help_avalaible? && Input.trigger?(Config::FF9_Help::Toggle_Key) && Config::FF9_Help::Activate_SE != nil
  513.       return ff9_help_toggle if ff9_help_avalaible? && Input.trigger?(Config::FF9_Help::Toggle_Key)
  514.     end
  515.   end
  516.  
  517.   def ff9_help_show
  518.     return unless open? && active
  519.     cursor_x = (@cursor[0].x - (@cursor[0].bitmap.width / 2)) - 2
  520.     cursor_y = (@cursor[0].y - (@cursor[0].bitmap.height / 2)) - 26
  521.     window_rows = [page_row_max / 2, 1].max
  522.     window_rows += 1 if !window_rows.even?
  523.     window_index = index_of_visible_row + 1
  524.     @ff9_help_window.show(ff9_help_text, cursor_x, cursor_y, window_rows, window_index)
  525.   end
  526.  
  527.   def ff9_help_text
  528.     Config::FF9_Help::Window_Command[command_name(index)]
  529.   end
  530.  
  531.   def ff9_help_avalaible?
  532.     Config::FF9_Help::Window_Command.include?(command_name(index)) rescue false
  533.   end
  534. end
  535.  
  536. #==============================================================================
  537. # ■ Window_FF9_Help
  538. #==============================================================================
  539.  
  540. class Window_FF9_Help < Window_Base
  541.  
  542.   def initialize(viewport)
  543.     super(0,0,1,1)
  544.     self.viewport = viewport
  545.     self.openness = 255
  546.     self.windowskin = Cache.ff9_help("FF9_Help_Window.png")
  547.     self.tone.set(Tone.new(0, 0, 0, 0))
  548.     self.opacity = 255
  549.     self.back_opacity = 255
  550.     self.visible = false
  551.     self.z = Config::FF9_Help::Window_Z
  552.     @text = [""]
  553.     @toggle = false
  554.     @moogle_x = 0
  555.     @moogle_y = 0
  556.     @help_arrow_pos = :TOP
  557.     @help_arrow_x = 0
  558.     @help_arrow_y = 0
  559.     if Config::FF9_Help::Window_Header
  560.       @header_sprite = Sprite.new
  561.       @header_sprite.bitmap = Cache.ff9_help("FF9_Help_Header.png")
  562.       @header_sprite.x = 0
  563.       @header_sprite.y = 0
  564.       @header_sprite.z = self.z + 1000
  565.       @header_sprite.visible = false
  566.     end
  567.     @arrow_sprite = Sprite.new
  568.     @arrow_sprite.bitmap = Cache.ff9_help("FF9_Help_Arrow_Top.png")
  569.     @arrow_sprite.x = 0
  570.     @arrow_sprite.y = 0
  571.     @arrow_sprite.z = self.z + 1000
  572.     @arrow_sprite.visible = false
  573.     @moogle_sprite = Sprite.new
  574.     @moogle_sprite.bitmap = Cache.ff9_help("FF9_Help_Moogle.png")
  575.     @moogle_sprite.x = 0
  576.     @moogle_sprite.y = 0
  577.     @moogle_sprite.z = self.z + 1000
  578.     @moogle_sprite.visible = false
  579.     @init_shadow = false
  580.     create_window_shadow
  581.   end
  582.  
  583.   def create_window_shadow
  584.     @window_shadow = Window_Shadow.new
  585.     @init_shadow = true
  586.   end
  587.  
  588.   def window_height
  589.     (line_height * @text.size) + standard_padding * 2
  590.   end
  591.  
  592.   def icon_width
  593.     size = text_size(' ').width
  594.     ' ' * (24 / size)
  595.   end
  596.  
  597.   def open?
  598.     self.visible
  599.   end
  600.  
  601.   def update
  602.     super
  603.     if @toggle
  604.       self.visible = true
  605.       @moogle_sprite.visible = true
  606.       @arrow_sprite.visible = true
  607.       @header_sprite.visible = true if Config::FF9_Help::Window_Header
  608.     else
  609.       self.visible = false
  610.       @arrow_sprite.visible = false
  611.       @moogle_sprite.visible = false
  612.       @header_sprite.visible = false if Config::FF9_Help::Window_Header
  613.     end
  614.     if @init_shadow && Config::FF9_Help::Window_Shadow
  615.       @window_shadow.refresh(self.x, self.y, self.z - 1, self.width, self.height)
  616.       @init_shadow = false
  617.     end
  618.     @window_shadow.visible = self.visible if Config::FF9_Help::Window_Shadow
  619.   end
  620.  
  621.   def dispose
  622.     super
  623.     @window_shadow.dispose
  624.     @arrow_sprite.dispose
  625.     @moogle_sprite.dispose
  626.     @header_sprite.dispose if Config::FF9_Help::Window_Header
  627.   end
  628.  
  629.   def show(help, cursor_x, cursor_y, window_rows, window_index)
  630.     $ff9_help_refresh = false
  631.     @text = help
  632.     @moogle_x = cursor_x
  633.     @moogle_y = cursor_y
  634.     text = @text
  635.     text_sizes = []
  636.     text.each do |string|
  637.       temp_string = string.gsub(/\\[^invpgINVPG]\[\d{0,3}\]/) { "" }
  638.       temp_string = temp_string.gsub(/\\i\[\d{0,3}\]/) { icon_width }
  639.       temp_string = convert_escape_characters(temp_string)
  640.       text_sizes.push(text_size(temp_string).width)
  641.     end
  642.     text_sizes.sort!
  643.     size = text_sizes[text_sizes.size - 1]
  644.     self.width = (size + (standard_padding * 2) + 2)
  645.     self.height = window_height
  646.     create_contents
  647.     @moogle_sprite.x = @moogle_x
  648.     @moogle_sprite.y = @moogle_y
  649.     if window_index < window_rows
  650.       @help_arrow_pos = :TOP
  651.     elsif window_index == window_rows
  652.       @help_arrow_pos = :TOP
  653.     else
  654.       @help_arrow_pos = :BOTTOM
  655.     end
  656.     case @help_arrow_pos
  657.     when :BOTTOM
  658.       left_height = @moogle_y + 4
  659.       if self.height >= left_height
  660.         @help_arrow_pos = :TOP
  661.         @help_arrow_x = @moogle_x + 34
  662.         @help_arrow_y = @moogle_y + 34
  663.       else
  664.         @help_arrow_x = @moogle_x + 34
  665.         @help_arrow_y = @moogle_y + 4
  666.       end
  667.       rest_width = Graphics.width - (@help_arrow_x - 22)
  668.       result = 0
  669.       if rest_width < self.width
  670.         window_rest = self.width - rest_width
  671.         result = window_rest + 6
  672.         self.x = @help_arrow_x - 24 - result
  673.       else
  674.         self.x = (@help_arrow_x + 16) - (self.width/2)
  675.       end
  676.       self.x = 8 if self.x < 8
  677.       case @help_arrow_pos
  678.       when :BOTTOM
  679.         self.y = @help_arrow_y - self.height + 10
  680.         @arrow_sprite.bitmap = Cache.ff9_help("FF9_Help_Arrow_Bottom.png")
  681.       when :TOP
  682.         self.y = @help_arrow_y + 22
  683.         @arrow_sprite.bitmap = Cache.ff9_help("FF9_Help_Arrow_Top.png")
  684.       end
  685.     when :TOP
  686.       left_height = Graphics.height - @moogle_y + 34
  687.       if self.height >= left_height
  688.         @help_arrow_pos = :BOTTOM
  689.         @help_arrow_x = @moogle_x + 34
  690.         @help_arrow_y = @moogle_y + 4
  691.       else
  692.         @help_arrow_x = @moogle_x + 34
  693.         @help_arrow_y = @moogle_y + 34
  694.       end
  695.       rest_width = Graphics.width - (@help_arrow_x - 22)
  696.       result = 0
  697.       if rest_width < self.width
  698.         window_rest = self.width - rest_width
  699.         result = window_rest + 6
  700.         self.x = @help_arrow_x - 24 - result
  701.       else
  702.         self.x = (@help_arrow_x + 16) - (self.width/2)
  703.       end
  704.       self.x = 8 if self.x < 8
  705.       case @help_arrow_pos
  706.       when :BOTTOM
  707.         self.y = @help_arrow_y - self.height + 10
  708.         @arrow_sprite.bitmap = Cache.ff9_help("FF9_Help_Arrow_Bottom.png")
  709.       when :TOP
  710.         self.y = @help_arrow_y + 22
  711.         @arrow_sprite.bitmap = Cache.ff9_help("FF9_Help_Arrow_Top.png")
  712.       end
  713.     end
  714.     @arrow_sprite.x = @help_arrow_x
  715.     @arrow_sprite.y = @help_arrow_y
  716.     @header_sprite.x = self.x + Config::FF9_Help::Header_X if Config::FF9_Help::Window_Header
  717.     @header_sprite.y = self.y + Config::FF9_Help::Header_Y if Config::FF9_Help::Window_Header
  718.     @text.each_with_index {|text, i| draw_help_text(0, i * line_height, @text[i]) }
  719.     @window_shadow.refresh(self.x, self.y, self.z - 1, self.width, self.height) if Config::FF9_Help::Window_Shadow
  720.     @toggle = true
  721.   end
  722.  
  723.   def hide
  724.     @toggle = false
  725.   end
  726.  
  727.   def draw_help_text(x, y, text)
  728.     reset_font_settings
  729.     contents.font.name = Config::FF9_Help::Font_Name
  730.     contents.font.size = Config::FF9_Help::Font_Size
  731.     contents.font.bold = Config::FF9_Help::Font_Bold
  732.     contents.font.italic = Config::FF9_Help::Font_Italic
  733.     contents.font.outline = Config::FF9_Help::Font_Outline
  734.     contents.font.shadow = Config::FF9_Help::Font_Shadow
  735.     contents.font.color = Config::FF9_Help::Font_Color
  736.     contents.font.out_color = Config::FF9_Help::Font_Outline_Color
  737.     text = convert_escape_characters(text)
  738.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  739.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  740.   end
  741.  
  742.   def update_tone
  743.   end
  744. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement