Guest User

FF9 Help 1.10

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