Advertisement
diamondandplatinum3

DP Core

Dec 25th, 2013
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 77.81 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             DP Core
  3. #             Version: 1.0
  4. #             Author: DiamondandPlatinum3
  5. #             Date: December 23, 2013
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This Core Script adds extra classes and additions to existing classes for
  10. #    use by future DiamondandPlatinum3 scripts and/or any other scripter who
  11. #    finds these additions useful.
  12. #
  13. #    Included is an Improved Input System which allows for Mapping Input to
  14. #    all PC Keyboard Keys and complete Mapping abilities over Xbox360 & PS3
  15. #    Controllers.
  16. #       Additionally you can vibrate an Xbox360 Controller.
  17. #  
  18. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. #  Instructions:
  20. #
  21. #  ~  Check the Editable Region and Modify things to your liking.
  22. #
  23. #  ~  A Video Tutorial for the Improved Input System can be seen here:
  24. #         http://www.youtube.com/watch?v=vp1lB-09K5w
  25. #
  26. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. #  Compatibility:
  28. #
  29. #   ~ Module DPCore:                        (New Module)
  30. #
  31. #       ~ Class ScreenFilledSprite:           (New Class) < Sprite
  32. #           initialize                          (Derived Instance Method)
  33. #           dispose                             (Derived Instance Method)
  34. #
  35. #       ~ Class TimeTracker:                  (New Class)
  36. #           initialize                          (Derived Instance Method)
  37. #           dispose                             (New Instance Method)
  38. #           update                              (New Instance Method)
  39. #           reset                               (New Instance Method)
  40. #           set_current_time                    (New Instance Method)
  41. #           set_finish_time                     (New Instance Method)
  42. #           get_current_time                    (New Instance Method)
  43. #           time_up?                            (New Instance Method)
  44. #           get_completion_percentage           (New Instance Method)
  45. #           get_timetracker_list                (New Class Method)
  46. #           update_timetrackers                 (New Class Method)
  47. #
  48. #       ~ Module GameEvents:                  (New Module)
  49. #           get_event_first_comment             (New Module Method)
  50. #           get_event_all_comments              (New Module Method)
  51. #
  52. #       ~ Module InputHandler:                (New Module)
  53. #           New Editable Constants              (Constant Variables)
  54. #
  55. #
  56. #   ~ Class Scene_Base:                     (Inbuilt Class)
  57. #       update                                (Aliased Method)
  58. #
  59. #
  60. #   ~ Class Window_MenuCommand:             (Inbuilt Class) < Window_Command
  61. #       add_original_commands                 (Aliased Instance Method)
  62. #       activate                              (Aliased Instance Method)
  63. #       dp3_dpcore_get_original_commands      (New Instance Method)
  64. #
  65. #
  66. #
  67. #
  68. #   ~ if InputHandler::UseInputSystem:      (Definition)
  69. #
  70. #       ~ Class Game_Interpreter:             (Inbuilt Class)
  71. #           vibrate_controller                  (New Instance Method)
  72. #
  73. #
  74. #       ~ Module Input:                       (Inbuilt Module)
  75. #           Module InputInfo                    (New Module)
  76. #             Class Repeated                      (New Class)
  77. #             Class VibrationTimer                (New Class)
  78. #           Class InputMapping                  (New Class) < Hash
  79. #           Class Input_Base                    (New Class)
  80. #           Class Controller_Base               (New Class) < Input::Input_Base
  81. #           Class Xbox360Controller             (New Class) < Input::Controller_Base
  82. #           Class PS3Controller                 (New Class) < Input::Controller_Base
  83. #           Class PCKeyboardInput               (New Class) < Input::Input_Base
  84. #
  85. #
  86. #       ~ Module Input:                       (Inbuilt Module)
  87. #           New Constant Variables              (Constant Variables)
  88. #           New Class Variables                 (Class Variables)
  89. #           update                              (Overwritten Module Method)
  90. #           trigger?                            (Overwritten Module Method)
  91. #           press?                              (Overwritten Module Method)
  92. #           repeat?                             (Overwritten Module Method)
  93. #           dir4                                (Overwritten Module Method)
  94. #           dir8                                (Overwritten Module Method)
  95. #           triggered?                          (New Module Method)
  96. #           pressed?                            (New Module Method)
  97. #           repeated?                           (New Module Method)
  98. #           release?                            (New Module Method)
  99. #           released?                           (New Module Method)
  100. #           xbox360_controller_connected?       (New Module Method)
  101. #           ps3_controller_connected?           (New Module Method)
  102. #           xbox360_input                       (New Module Method)
  103. #           ps3_input                           (New Module Method)
  104. #           pc_keyboard_input                   (New Module Method)
  105. #           get_input_instance                  (New Module Method)
  106. #           input_mapping                       (New Module Method)
  107. #           get_currently_triggered_keys        (New Module Method)
  108. #           get_currently_pressed_keys          (New Module Method)
  109. #           get_currently_repeated_keys         (New Module Method)
  110. #           get_currently_released_keys         (New Module Method)
  111. #
  112. #
  113. #       ~ Class Input::InputMapping:        (New Class) < Hash
  114. #           initialize                        (Derived Instance Method)
  115. #           get_input_symbols                 (New Instance Method)
  116. #           create_sym_info                   (New Instance Method)
  117. #           assign_pc_keyboard_input          (New Instance Method)
  118. #           assign_xbox360_controller_input   (New Instance Method)
  119. #           assign_ps3_controller_input       (New Instance Method)
  120. #           assign_additional_input           (New Instance Method)
  121. #        
  122. #
  123. #       ~ Class Input::InputInfo::Repeated: (New Class)
  124. #           initialize                        (Derived Instance Method)
  125. #           reset                             (New Instance Method)
  126. #           update                            (New Instance Method)
  127. #           activate                          (New Instance Method)
  128. #           active?                           (New Instance Method)
  129. #
  130. #
  131. #       ~ Class Input::InputInfo::VibrationTimer: (New Class)
  132. #           initialize                        (Derived Instance Method)
  133. #           reset                             (New Instance Method)
  134. #           update                            (New Instance Method)
  135. #           set_active                        (New Instance Method)
  136. #           set_finish                        (New Instance Method)
  137. #           active?                           (New Instance Method)
  138. #           complete?                         (New Instance Method)
  139. #
  140. #
  141. #       ~ Class Input::Input_Base:          (New Class)
  142. #           initialize                        (Derived Instance Method)
  143. #           reset                             (New Instance Method)
  144. #           new_key_info                      (New Instance Method)
  145. #           set_key_status                    (New Instance Method)
  146. #           update_key                        (New Instance Method)
  147. #           update_key_repeat                 (New Instance Method)
  148. #           reset_key                         (New Instance Method)
  149. #           trigger?                          (New Instance Method)
  150. #           triggered?                        (New Instance Method)
  151. #           press?                            (New Instance Method)
  152. #           pressed?                          (New Instance Method)
  153. #           repeat?                           (New Instance Method)
  154. #           repeated?                         (New Instance Method)
  155. #           release?                          (New Instance Method)
  156. #           released?                         (New Instance Method)
  157. #           currently_triggered_keys          (New Instance Method)
  158. #           currently_pressed_keys            (New Instance Method)
  159. #           currently_repeated_keys           (New Instance Method)
  160. #           currently_released_keys           (New Instance Method)
  161. #           get_rep_symbols                   (New Instance Method)
  162. #
  163. #
  164. #       ~ Class Input::Controller_Base:     (New Class) < Input::Input_Base
  165. #           reset                             (Derived Instance Method)
  166. #           connected?                        (New Instance Method)
  167. #
  168. #
  169. #       ~ if DPCore::InputHandler::UseXbox360ControllerInput  (Definition)
  170. #         ~ Class Input::Xbox360Controller:   (New Class) < Input::Controller_Base
  171. #             New Constant Variables            (Constant Variables)
  172. #             DLL Required Constants            (Constant Variables Referencing DLLs)
  173. #             reset                             (Derived Instance Method)
  174. #             get_rep_symbols                   (Derived Instance Method)
  175. #             update                            (New Instance Method)
  176. #             update_connection                 (New Instance Method)
  177. #             update_buttons                    (New Instance Method)
  178. #             update_axes                       (New Instance Method)
  179. #             update_lstick_movement            (New Instance Method)
  180. #             update_rstick_movement            (New Instance Method)
  181. #             update_vibration                  (New Instance Method)
  182. #             vibrate_controller                (New Instance Method)
  183. #             axis                              (New Instance Method)
  184. #
  185. #
  186. #       ~ if DPCore::InputHandler::UsePS3ControllerInput      (Definition)
  187. #         ~ Class Input::PS3Controller:       (New Class) < Input::Controller_Base
  188. #             New Constant Variables            (Constant Variables)
  189. #             DLL Required Constants            (Constant Variables Referencing DLLs)
  190. #             reset                             (Derived Instance Method)
  191. #             get_rep_symbols                   (Derived Instance Method)
  192. #             update                            (New Instance Method)
  193. #             update_connection                 (New Instance Method)
  194. #             update_buttons                    (New Instance Method)
  195. #
  196. #
  197. #       ~ Class Input::KeyboardInput:       (New Class) < Input::Input_Base
  198. #           New Constant Variables            (Constant Variables)
  199. #           DLL Required Constants            (Constant Variables Referencing DLLs)
  200. #           reset                             (Derived Instance Method)
  201. #           get_rep_symbols                   (Derived Instance Method)
  202. #           update                            (New Instance Method)
  203. #
  204. #
  205. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  206. ($diamondandplatinum3_scripts ||= {})[:DPCore] = true
  207. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  208. module DPCore
  209.   module InputHandler
  210.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  211.     #                                                        -=
  212.     #                 Editable Region        ////            ==
  213.     #                                                        =-
  214.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  215.    
  216.     #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  217.     # Input Scheme |                  What it does!
  218.     #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  219.     #     :A       | Dash When Moving; Warps to OK during Input; Increases Text Speed;
  220.     #     :B       | The Cancel Button; Opens the Main Menu;
  221.     #     :C       | The Confrim Button; Interacts with Events; Increases Text Speed;
  222.     #     :X       | Nothing by Default; Can be used in your events;
  223.     #     :Y       | Nothing by Default; Can be used in your events;
  224.     #     :Z       | Nothing by Default; Can be used in your events;
  225.     #     :L       | The PageUp Button;
  226.     #     :R       | The PageDown Button;
  227.     #     :SHIFT   | Nothing by Default; May be used in a custom script;
  228.     #     :CTRL    | Allows you to walk through walls during debug mode;
  229.     #     :ALT     | Nothing by Default; May be used in a custom script;
  230.     #     :F5      | Nothing by Default; May be used in a custom script;
  231.     #     :F6      | Nothing by Default; May be used in a custom script;
  232.     #     :F7      | Nothing by Default; May be used in a custom script;
  233.     #     :F8      | Nothing by Default; May be used in a custom script;
  234.     #     :F9      | Calls the Debug Menu;
  235.     #     :LEFT    | Moves the Player/Cursor to the Left.
  236.     #     :DOWN    | Moves the Player/Cursor Downwards.
  237.     #     :RIGHT   | Moves the Player/Cursor to the Right.
  238.     #     :UP      | Moves the Player/Cursor Upwards.
  239.     #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  240.    
  241.    
  242.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243.     # *{} System Options
  244.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245.     UseInputSystem = true     # Use the Improved Input System Included With DP Core?
  246.                               # If not using 'Improved Input System', Leave Editable
  247.                               # Region. You are finished here.
  248.    
  249.     RepeatWaitTime = 0.15     # Wait Time (in Seconds) before a Repeat is Initiated.
  250.                               # A Repeat: is when the cursor moves inside of a
  251.                               # command window once again if you're holding
  252.                               # down a corresponding button
  253.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254.     # *{} PC Keyboard Options
  255.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  256.     PCKeyboardKeysMapping =
  257.     {                
  258.     #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  259.     # PC Keyboard Buttons               => Representing Input Scheme(s)
  260.     #
  261.     #   If you don't want a key to represent any Input Scheme, make it an
  262.     #   empty array ( [], ).
  263.     #
  264.     #   One the other hand, if you want a PC Keyboard button to represent
  265.     #   more than one Input Scheme, you can insert multiple Input Schemes:
  266.     #   Example:       [:CTRL, :B, ],
  267.     #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  268.    
  269.       # Letter Keys
  270.       :A                                => [:X, ],
  271.       :B                                => [],
  272.       :C                                => [],
  273.       :D                                => [:Z, ],
  274.       :E                                => [],
  275.       :F                                => [],
  276.       :G                                => [],
  277.       :H                                => [],
  278.       :I                                => [],
  279.       :J                                => [],
  280.       :K                                => [],
  281.       :L                                => [],
  282.       :M                                => [],
  283.       :N                                => [],
  284.       :O                                => [],
  285.       :P                                => [],
  286.       :Q                                => [:L, ],
  287.       :R                                => [],
  288.       :S                                => [:Y, ],
  289.       :T                                => [],
  290.       :U                                => [],
  291.       :V                                => [],
  292.       :W                                => [:R, ],
  293.       :X                                => [:B, ],
  294.       :Y                                => [],
  295.       :Z                                => [:C, ],
  296.  
  297.       # Number/Symbol Keys
  298.       :Num0                             => [],
  299.       :Num1                             => [],
  300.       :Num2                             => [],
  301.       :Num3                             => [],
  302.       :Num4                             => [],
  303.       :Num5                             => [],
  304.       :Num6                             => [],
  305.       :Num7                             => [],
  306.       :Num8                             => [],
  307.       :Num9                             => [],
  308.  
  309.       # Qwerty Symbol Keys
  310.       :Comma                            => [],
  311.       :Period                           => [],
  312.       :ForwardSlash                     => [],
  313.       :SemiColon                        => [],
  314.       :Quote                            => [],
  315.       :LSqrBracket                      => [],
  316.       :RSqrBracket                      => [],
  317.       :BackSlash                        => [],
  318.       :Tilde                            => [],
  319.       :Dash                             => [],
  320.       :Equals                           => [],
  321.  
  322.       # Arrow Keys
  323.       :Left                             => [:LEFT, ],
  324.       :Down                             => [:DOWN, ],
  325.       :Right                            => [:RIGHT, ],
  326.       :Up                               => [:UP, ],  
  327.  
  328.       # NumPad Numbers
  329.       :Numpad0                          => [:B, ],  
  330.       :Numpad1                          => [],  
  331.       :Numpad2                          => [:DOWN, ],  
  332.       :Numpad3                          => [],
  333.       :Numpad4                          => [:LEFT, ],
  334.       :Numpad5                          => [],
  335.       :Numpad6                          => [:RIGHT, ],
  336.       :Numpad7                          => [],
  337.       :Numpad8                          => [:UP, ],
  338.       :Numpad9                          => [],
  339.  
  340.       # NumPad Math Symbols
  341.       :Multiply                         => [],
  342.       :Divide                           => [],
  343.       :Subtract                         => [],
  344.       :Add                              => [],
  345.       :Decimal                          => [],
  346.  
  347.       # Function Keys
  348.       :F1                               => [],
  349.       :F2                               => [],
  350.       :F3                               => [],
  351.       :F4                               => [],
  352.       :F5                               => [:F5, ],
  353.       :F6                               => [:F6, ],
  354.       :F7                               => [:F7, ],
  355.       :F8                               => [:F8, ],
  356.       :F9                               => [:F9, ],
  357.       :F10                              => [],
  358.       :F11                              => [],
  359.       :F12                              => [],
  360.  
  361.       :LCtrl                            => [:CTRL, ],
  362.       :RCtrl                            => [:CTRL, ],
  363.       :LShift                           => [:SHIFT, :A, ],
  364.       :RShift                           => [:SHIFT, :A, ],
  365.       :LAlt                             => [:ALT, ],
  366.       :RAlt                             => [:ALT, ],
  367.       :Enter                            => [:C, ],  
  368.       :Backspace                        => [],
  369.       :Spacebar                         => [:C, ],  
  370.       :Tab                              => [],
  371.       :Escape                           => [:B, ],
  372.  
  373.       :Capslock                         => [],  
  374.       :ScrollLock                       => [],
  375.       :NumLock                          => [],
  376.       :PrintScreen                      => [],  
  377.       :Pause                            => [],
  378.       :Insert                           => [:B, ],
  379.       :Delete                           => [],
  380.       :Home                             => [],
  381.       :End                              => [],
  382.       :PageUp                           => [:L, ],
  383.       :PageDown                         => [:R, ],
  384.     }
  385.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  386.     # *{} Xbox 360 Controller Options
  387.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  388.     UseXbox360ControllerInput     = true   # Allow the Xbox 360 Controller to be used as an Input Device? (Only if Using New Input System)
  389.    
  390.     UseLeftStickAxisForMovement   = true   # Use the Left Stick for Directional Movement? ie. Move Up, Down, Left Right
  391.     UseRightStickAxisForMovement  = true   # Same as above but for the Right Stick
  392.    
  393.     AxisPowerRegister             = 30     # How Far Must an Axis Stick be Moved Before it Registers as Moved?            Default: 30%
  394.     TriggerPowerRegister          = 30     # How Far Must the Triggers be Pulled Before They Register as Being Pressed?;  Default: 30%
  395.    
  396.    
  397.     # Control Mapping for the Xbox360 Controller
  398.     Xbox360ControllerMapping =
  399.     {
  400.       :A                                => [:C, ],    
  401.       :B                                => [:X, ],    
  402.       :X                                => [:B, ],  
  403.       :Y                                => [:Y, ],  
  404.       :Start                            => [:Z, ],  
  405.       :Back                             => [:C, ],              
  406.       :LB                               => [:L, ],  
  407.       :RB                               => [:R, ],                          
  408.       :LStick                           => [:Z, ],            # Left-Stick Click
  409.       :RStick                           => [:Z, ],            # Right-Stick Click
  410.       :DPadUp                           => [:UP, ],  
  411.       :DPadDown                         => [:DOWN, ],  
  412.       :DPadLeft                         => [:LEFT, ],
  413.       :DPadRight                        => [:RIGHT, ],
  414.       :LT                               => [],                # Left Trigger
  415.       :RT                               => [],                # Right Trigger
  416.     }
  417.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  418.     # *{} PS3 Controller Options
  419.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  420.     UsePS3ControllerInput = true      # Allow the PS3 Contoller to be used as an Input Device?       (Only if Using New Input System)
  421.    
  422.     # Control Mapping for the PS3 Controller
  423.     PS3ControllerMapping =
  424.     {
  425.       :Cross                            => [:B, ],  
  426.       :Square                           => [:Y, ],
  427.       :Circle                           => [:X, ],  
  428.       :Triangle                         => [:C, ],  
  429.       :Start                            => [:Z, ],
  430.       :Select                           => [:Z, ],                                      
  431.       :L1                               => [:L, ],  
  432.       :R1                               => [:R, ],                                      
  433.       :L2                               => [:C, ],  
  434.       :R2                               => [:Z, ],                                      
  435.       :DPadUp                           => [:UP, ],
  436.       :DPadDown                         => [:DOWN, ],  
  437.       :DPadLeft                         => [:LEFT, ],  
  438.       :DPadRight                        => [:RIGHT, ],
  439.     }
  440.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  441.     #                                           \/
  442.     #               End of Editable Region      /\
  443.     #                                           \/
  444.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  445.   end
  446. end
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  456. # **  New Class:   Screen Filled Sprite
  457. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  458. # Creates a sprite which automatically fills the screen and can be disposed
  459. # without needing to dispose of the included bitmap.
  460. # Everything beyond initialisation is still accessed the way a normal
  461. # Sprite is accessed.
  462. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  463. module DPCore
  464.   class ScreenFilledSprite < Sprite
  465.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  466.     # * Derived Method:   Object Initialisation
  467.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  468.     # Filename:   Filename of the Sprite Image, includes path if necessary.
  469.     # Visible:    Will be visible? : true by default
  470.     # Z:          The Z Value of this sprite on initialisation : 1 by default
  471.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  472.     def initialize(filename, visible = true, z = 1)
  473.       super()
  474.       self.bitmap   = Bitmap.new(filename)
  475.       self.x        = 0
  476.       self.y        = 0
  477.       self.z        = z
  478.       self.zoom_x   = (Graphics.width.to_f / self.bitmap.width)
  479.       self.zoom_y   = (Graphics.height.to_f / self.bitmap.height)
  480.       self.visible  = visible
  481.     end
  482.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  483.     # * Derived Method:   Dispose
  484.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  485.     def dispose()
  486.       self.bitmap.dispose()     unless self.bitmap.nil? || self.bitmap.disposed?
  487.       super()
  488.     end
  489.   end
  490. end
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  499. # **  New Class:   Time Tracker
  500. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  501. # Once initialised, this class keeps track of time in seconds.
  502. # All instances of the TimeTracker class are updated automatically if you
  503. # have chosen to allow themselves to be added to the list (true by default).
  504. #
  505. # Once initialised, simply call the ' time_up? ' method to see if the time
  506. # is up for this TimeTracker.
  507. # Call ' dispose ' once finished.
  508. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  509. module DPCore
  510.   class TimeTracker
  511.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  512.     # *+ Public Instance Variables
  513.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  514.     attr_reader :current_frame  # Current Frame the Tracker is on: Use to Reset Tracker.
  515.     attr_reader :seconds        # Seconds until TimeUp: Change to Increase/Decrease the Wait Time.
  516.     attr_reader :scenetype      # Scenetype: If not nil, this TimeTracker will only Update if SceneManager is in that Specified Scene.
  517.    
  518.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  519.     # *- Private Static Variables
  520.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521.     @@timetracker_list = []     # Static Variable List/Array containing active instances of TimeTrackers
  522.  
  523.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  524.     # * New Method:   Object Initialisation
  525.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  526.     # Time:             How long (in seconds) until this TimeTracker has been successful
  527.     # Scene Class:      Which Scene Can this TimeTracker be updated in : nil by default, which means it can always be updated no matter what scene it is.
  528.     # Add Self To List: Add Self to the Automatic Update List? : false by default. If not true, you need to update the TimeTracker manually
  529.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  530.     def initialize(time, scene_class = nil, add_self_to_list = false)
  531.       @current_time   = 0.0
  532.       @finish_time    = time.to_f
  533.       @scenetype      = scene_class
  534.       @time_up        = false
  535.      
  536.       @@timetracker_list.push(self) if add_self_to_list
  537.     end
  538.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  539.     # * New Method:   Dispose
  540.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  541.     def dispose()
  542.       @@timetracker_list.reject! { |tracker| tracker == self }
  543.     end
  544.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  545.     # * New Method:   Update
  546.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  547.     def update()
  548.       if !@time_up
  549.         @current_time  += (1.0 / Graphics.frame_rate)
  550.         @time_up        = (@current_time > @finish_time)
  551.         @current_time   =  @finish_time if @time_up
  552.       end
  553.     end
  554.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  555.     # * New Method:   Reset
  556.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557.     def reset()
  558.       @current_time = 0.0
  559.       @time_up      = false
  560.     end
  561.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  562.     # * New Method:   Set Current Time
  563.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  564.     def set_current_time(time)
  565.       @current_time = time
  566.       @time_up      = (@current_time > @finish_time)
  567.       @current_time =  @finish_time if @time_up
  568.     end
  569.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  570.     # * New Method:   Set Finish Time
  571.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  572.     def set_finish_time(time)
  573.       @finish_time  = time
  574.       @time_up      = (@current_time > @finish_time)
  575.       @current_time =  @finish_time if @time_up
  576.     end
  577.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  578.     # * New Method:   Get Current Time (in seconds)
  579.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  580.     def get_current_time()
  581.       return @current_time
  582.     end
  583.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  584.     # * New Method:   Is Time Up?
  585.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  586.     def time_up?()
  587.       return @time_up
  588.     end
  589.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  590.     # * New Method:   Get Total Completion Percentage
  591.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  592.     def get_completion_percentage()
  593.       return (@current_time / @finish_time)
  594.     end
  595.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  596.     # * New Method:   Get TimeTracker List
  597.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  598.     def self.get_timetracker_list()
  599.       return @@timetracker_list
  600.     end
  601.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  602.     # * New Method:   Update TimeTrackers
  603.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  604.     def self.update_timetrackers()
  605.       @@timetracker_list.each do |tracker|
  606.         tracker.update() unless !tracker.scenetype.nil? &&
  607.                                   !SceneManager.scene_is?(tracker.scenetype)
  608.       end
  609.     end
  610.   end
  611. end
  612.  
  613.  
  614. class Scene_Base
  615.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  616.   # *= Alias Listings
  617.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  618.   alias_method(:dp3_dpcore_scenebase_update_axxz,                  :update)
  619.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  620.   # * Aliased Method:   Update
  621.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  622.   def update(*args)
  623.     dp3_dpcore_scenebase_update_axxz(*args)
  624.     DPCore::TimeTracker.update_timetrackers()
  625.   end
  626. end
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  635. # **  Edited Classes:   Scene Menu Quick Option Creation
  636. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  637. # This edit allows for quick Scene Menu Command Creation.
  638. # alias ' dp3_dpcore_get_original_commands ' and follow the instructions
  639. # of that method.
  640. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  641. class Window_MenuCommand < Window_Command
  642.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  643.   # *= Alias Listings
  644.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  645.   alias_method(:dp3_dpcore_addorigcomnd_axxz,       :add_original_commands)
  646.   alias_method(:dp3_dpcore_activate_axxz,           :activate             )
  647.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  648.   # * New Method:   Get Original Commands
  649.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  650.   #   hash = alias
  651.   #   hash[ "label" ] = {
  652.   #     :enabled    => true/false,
  653.   #     :method_ref => method(:method_name),
  654.   #   }
  655.   #   return hash
  656.   #
  657.   #--------------------OR-------------------------------------------------
  658.   #   hash = {
  659.   #             "label" => {
  660.   #                           :enabled    =>  true/false,
  661.   #                           :method_ref =>  method(:method_name),
  662.   #                        }
  663.   #          }
  664.   #   return hash.merge( alias )
  665.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  666.   def dp3_dpcore_get_original_commands()
  667.     return {}
  668.   end
  669.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  670.   # * Aliased Method: For Adding Original Commands
  671.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  672.   def add_original_commands(*args)
  673.     dp3_dpcore_addorigcomnd_axxz(*args) # Call Original Method
  674.    
  675.     original_commands = dp3_dpcore_get_original_commands()
  676.     original_commands.each_key do |key|
  677.       add_command(key, key.to_sym, original_commands[key][:enabled])
  678.     end
  679.   end
  680.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  681.   # * Aliased Method: Activate
  682.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  683.   def activate(*args)
  684.     dp3_dpcore_activate_axxz(*args) # Call Original Command
  685.    
  686.     original_commands = dp3_dpcore_get_original_commands()
  687.     original_commands.each_key do |key|
  688.       set_handler(key.to_sym, original_commands[key][:method_ref])
  689.     end
  690.   end
  691. end
  692.  
  693.  
  694.  
  695.  
  696.  
  697. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  698. # **  New Module:   GameEvents
  699. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  700. # This Module Will interact with GameEvents. For now the only code here is:
  701. #     * Get First Comment in Event Page
  702. #     * Get All Comments in Event Page
  703. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  704. module DPCore
  705.   module GameEvents
  706.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  707.     # * New Method: Get Event First Comment
  708.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  709.     def self.get_event_first_comment( event_id )
  710.       comments = get_event_all_comments( event_id )
  711.       return comments[0]  unless comments.empty?
  712.       return ""
  713.     end
  714.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  715.     # * New Method: Get Event All Comments
  716.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  717.     def self.get_event_all_comments( event_id )
  718.       comments = []
  719.       event = $game_map.events[ event_id ]
  720.       if event.list
  721.         event.list.each do |command|
  722.           case command.code
  723.           when 108
  724.             comments.push( command.parameters[0] )
  725.           when 408
  726.             comments.last += command.parameters[0]
  727.           end
  728.         end
  729.       end
  730.       return comments
  731.     end
  732.   end
  733. end
  734.  
  735.  
  736.  
  737.  
  738.  
  739. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  740. # *****  :L2         Improved                                  :R2   *****
  741. # *****  :LT                  Input                            :RT   *****
  742. # *****  :Q                         System                     :R    *****
  743. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  744. if DPCore::InputHandler::UseInputSystem # Only Define the System if it's going to be used
  745. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  746.  
  747.  
  748.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  749.   # **  New Module:   Input Info
  750.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  751.   # This Module grants information used for the newfound input systems
  752.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  753.   module Input
  754.     module InputInfo
  755.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  756.       # *^ Data Information
  757.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  758.       RepeatWaitTime = DPCore::InputHandler::RepeatWaitTime.to_f
  759.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  760.       # *^ Repeat System ~ All Input Systems
  761.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  762.       class Repeated
  763.         def initialize;   @timer = DPCore::TimeTracker.new(RepeatWaitTime); end
  764.         def reset;        @timer.reset();                                   end
  765.         def update;       @timer.update();                                  end
  766.         def activate;     @timer.set_current_time(RepeatWaitTime + 1.0);    end
  767.         def active?;      return @timer.time_up?();                         end
  768.       end
  769.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  770.       # *^ Vibration Timer ~ Only Xbox360 Controller
  771.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  772.       class VibrationTimer
  773.         def initialize;    @timer,@active = DPCore::TimeTracker.new(0), false; end
  774.         def reset;         @timer.reset();                                     end
  775.         def update;        @timer.update() if active?();                       end
  776.         def set_active(b); @active = b;                                        end
  777.         def set_finish(f); @timer.set_finish_time(f);                          end
  778.         def active?;       return @active;                                     end
  779.         def complete?;     return @timer.time_up?();                           end
  780.       end
  781.     end
  782.   end
  783.  
  784.  
  785.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  786.   # **  New Class:   Input Base
  787.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  788.   # This Class defines the Base Code for the new Input System. This is used
  789.   # for all controller Input and the PC Keyboard
  790.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  791.   module Input
  792.     class Input_Base
  793.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  794.       # * New Method: Object Initialisation
  795.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  796.       def initialize
  797.         reset()
  798.       end
  799.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  800.       # * New Method: Reset
  801.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  802.       def reset
  803.         @input = Hash.new()
  804.       end
  805.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  806.       # * New Method: Get New Key Info Hash
  807.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  808.       def new_key_info
  809.         return { :triggered => false, :pressed => false, :repeated => Input::InputInfo::Repeated.new }
  810.       end
  811.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  812.       # * New Method: Set Key/Button Status
  813.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  814.       def set_key_status(index, active)
  815.         if active        
  816.           update_key(@input[index])
  817.         elsif @input[index][:pressed]
  818.           reset_key(@input[index])
  819.         end
  820.       end
  821.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  822.       # * New Method: Update Key
  823.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  824.       def update_key(input)
  825.         input[:triggered] = !input[:pressed]
  826.         input[:pressed]   = true
  827.         update_key_repeat(input)
  828.       end
  829.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  830.       # * New Method: Update Key Repeat
  831.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  832.       def update_key_repeat(input)
  833.         if input[:triggered]
  834.           input[:repeated].activate()
  835.         else
  836.           input[:repeated].reset()     if input[:repeated].active?()
  837.           input[:repeated].update()
  838.         end
  839.       end
  840.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  841.       # * New Method: Reset Key
  842.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  843.       def reset_key(input)
  844.         input[:triggered] = false
  845.         input[:pressed]   = false
  846.         input[:repeated].reset()
  847.       end
  848.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  849.       # * New Methods: Key Was Triggered?
  850.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  851.       def trigger?(rep)
  852.         return @input[ get_rep_symbols()[rep] ][:triggered] rescue false
  853.       end
  854.      
  855.       def triggered?(rep)
  856.         return trigger?(rep)
  857.       end
  858.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  859.       # * New Methods: Key Is Pressed?
  860.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  861.       def press?(rep)
  862.         return @input[ get_rep_symbols()[rep] ][:pressed] rescue false
  863.       end
  864.      
  865.       def pressed?(rep)
  866.         return press?(rep)
  867.       end
  868.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  869.       # * New Methods: Key Is on Repeat?
  870.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  871.       def repeat?(rep)
  872.         return @input[ get_rep_symbols()[rep] ][:repeated].active?() rescue false
  873.       end
  874.      
  875.       def repeated?(rep)
  876.         return repeat?(rep)
  877.       end
  878.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  879.       # * New Methods: Key Is Released?
  880.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  881.       def release?(rep)
  882.         return !press?(rep)
  883.       end
  884.      
  885.       def released?(rep)
  886.         return release?(rep)
  887.       end
  888.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  889.       # * New Methods: Get Currently Triggered Keys
  890.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  891.       def currently_triggered_keys
  892.         return @input.select { |k, v| v[:triggered] }.collect{ |k| get_rep_symbols().key(k[0]) }
  893.       end
  894.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  895.       # * New Methods: Get Currently Pressed Keys
  896.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  897.       def currently_pressed_keys
  898.         return @input.select { |k, v| v[:pressed] }.collect{ |k| get_rep_symbols().key(k[0]) }
  899.       end
  900.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  901.       # * New Methods: Get Currently Repeated Keys
  902.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  903.       def currently_repeated_keys
  904.         return @input.select { |k, v| v[:repeated].active?() }.collect{ |k| get_rep_symbols().key(k[0]) }
  905.       end
  906.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  907.       # * New Methods: Get Currently Released Keys
  908.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  909.       def currently_released_keys
  910.         return @input.select { |k, v| !v[:pressed] }.collect{ |k| get_rep_symbols().key(k[0]) }
  911.       end
  912.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  913.       # * New Method: Get The Respective Input Devices's Representing Symbols
  914.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  915.       def get_rep_symbols
  916.         return {}
  917.       end
  918.     end
  919.   end
  920.  
  921.  
  922.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  923.   # **  New Class:   Controller Base
  924.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  925.   # This Class defines the Base Code for the Xbox360/PS3/Etc controllers
  926.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  927.   module Input
  928.     class Controller_Base < Input::Input_Base
  929.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  930.       # * New Method: Reset
  931.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  932.       def reset
  933.         super()
  934.         @connected = false
  935.       end
  936.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  937.       # * New Method: Controller Is Connected?
  938.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  939.       def connected?
  940.         return @connected
  941.       end
  942.     end
  943.   end
  944.  
  945.  
  946.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  947.   # **  New Class:   Xbox360 Controller Input
  948.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  949.   # This Class interacts with an Xbox360 Controller connected to the PC,
  950.   # reading and passing information to/from the controller.
  951.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  952.   if DPCore::InputHandler::UseXbox360ControllerInput # Allow Xbox360 Controller Input?
  953.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  954.     module Input
  955.       class Xbox360Controller < Input::Controller_Base
  956.         begin
  957.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  958.           # *^ Controller Representing Symbols
  959.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  960.           Representatives =
  961.           {
  962.             :A      => 0,  :B        => 1,   :X => 2,          :Y => 3,          # Main Buttons
  963.             :Start  => 4,  :Back     => 5,                                       # Operation Buttons
  964.             :LB     => 6,  :RB       => 7,                                       # Shoulder Buttons
  965.             :LStick => 8,  :RStick   => 9,                                       # Thumbstick Clicks
  966.             :DPadUp => 10, :DPadDown => 11,  :DPadLeft => 12,  :DPadRight => 13, # DPad Directions
  967.             :LT     => 14, :RT       => 15,                                      # Triggers
  968.             :LSHorz => 16, :LSVert   => 17,                                      # Left-Stick Axis (Returns between -127 and +127)
  969.             :RSHorz => 18, :RSVert   => 19,                                      # Right-Stick Axis (Returns between -127 and +127)
  970.           }
  971.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  972.           # *^ Data Information
  973.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  974.           MinButtonID           = Representatives.min_by{ |k, v| v }[1]              # Lowest Button ID
  975.           MaxButtonID           = Representatives.max_by{ |k, v| v }[1]              # Highest Button ID
  976.           ButtonIterationRange  = Representatives[:A]..Representatives[:DPadRight]   # Iteration for Buttons
  977.           TriggerIterationRange = Representatives[:LT]..Representatives[:RT]         # Trigger Iteration Range
  978.           HashPressIterRange    = Representatives[:A]..Representatives[:RT]          # Total Press Iteration Range (For Hash Size)
  979.           AxesIterationRange    = Representatives[:LSHorz]..Representatives[:RSVert] # Iteration for Axes
  980.           TriggerPowerRegister  = DPCore::InputHandler::TriggerPowerRegister
  981.           AxisPowerRegister     = (127.0 * (DPCore::InputHandler::AxisPowerRegister.to_f / 100)).to_i
  982.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  983.           # *^ DLL Information
  984.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  985.           IsConnected = Win32API.new('System/Xbox360 Controller Input', 'ControllerConnected', '', 'n')
  986.           GetInput    = Win32API.new('System/Xbox360 Controller Input', 'GetControllerInput', 'n', 'n')
  987.           Vibration   = Win32API.new('System/Xbox360 Controller Input', 'VibrateController', 'nn', '')
  988.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  989.           # * Derived Method: Reset
  990.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  991.           def reset
  992.             super()
  993.             @vib_timer = Input::InputInfo::VibrationTimer.new()
  994.            
  995.             for i in HashPressIterRange
  996.               @input[i] = new_key_info()
  997.             end
  998.             for i in AxesIterationRange
  999.               @input[i] = 0
  1000.             end
  1001.           end
  1002.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1003.           # * New Method: Update Xbox 360 Controller
  1004.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1005.           def update
  1006.             update_connection()
  1007.             if @connected
  1008.               update_buttons()
  1009.               update_axes()
  1010.               update_vibration()
  1011.             end
  1012.           end
  1013.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1014.           # * New Method: Update Xbox 360 Controller Connection Status
  1015.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1016.           def update_connection
  1017.             if @connected    != (IsConnected.call() == 1) # If Connection Status is not equal to Actual Connection Status
  1018.               @connected      = !@connected               # Reverse Connection Status
  1019.               reset()        if !@connected               # If no longer Connected to the Controller, Reset Controller Input
  1020.             end
  1021.           end
  1022.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1023.           # * New Method: Update Xbox 360 Controller Buttons
  1024.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1025.           def update_buttons
  1026.             for i in ButtonIterationRange
  1027.               set_key_status(i, GetInput.call(i) != 0)
  1028.             end
  1029.             for i in TriggerIterationRange
  1030.               set_key_status(i, GetInput.call(i) > TriggerPowerRegister)
  1031.             end
  1032.           end
  1033.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1034.           # * New Method: Update Xbox 360 Controller Axes
  1035.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1036.           def update_axes
  1037.             for i in AxesIterationRange
  1038.               @input[ i ] = GetInput.call(i)
  1039.             end
  1040.            
  1041.             update_lstick_movement() if DPCore::InputHandler::UseLeftStickAxisForMovement
  1042.             update_rstick_movement() if DPCore::InputHandler::UseRightStickAxisForMovement
  1043.           end
  1044.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1045.           # * New Method: Update Xbox 360 LStick Movement
  1046.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1047.           def update_lstick_movement
  1048.             if axis(:LSHorz) > AxisPowerRegister
  1049.               set_key_status(get_rep_symbols()[:DPadRight], true)
  1050.             elsif axis(:LSHorz) < -AxisPowerRegister
  1051.               set_key_status(get_rep_symbols()[:DPadLeft], true)
  1052.             end
  1053.            
  1054.             if axis(:LSVert) > AxisPowerRegister
  1055.               set_key_status(get_rep_symbols()[:DPadUp], true)
  1056.             elsif axis(:LSVert) < -AxisPowerRegister
  1057.               set_key_status(get_rep_symbols()[:DPadDown], true)
  1058.             end
  1059.           end
  1060.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1061.           # * New Method: Update Xbox 360 RStick Movement
  1062.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1063.           def update_rstick_movement
  1064.             if axis(:RSHorz) > AxisPowerRegister
  1065.               set_key_status(get_rep_symbols()[:DPadRight], true)
  1066.             elsif axis(:RSHorz) < -AxisPowerRegister
  1067.               set_key_status(get_rep_symbols()[:DPadLeft], true)
  1068.             end
  1069.            
  1070.             if axis(:RSVert) > AxisPowerRegister
  1071.               set_key_status(get_rep_symbols()[:DPadUp], true)
  1072.             elsif axis(:RSVert) < -AxisPowerRegister
  1073.               set_key_status(get_rep_symbols()[:DPadDown], true)
  1074.             end
  1075.           end
  1076.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1077.           # * New Method: Update Xbox 360 Controller Vibration
  1078.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1079.           def update_vibration
  1080.             @vib_timer.update()                                      # Update Vibration Timer if it Exists
  1081.             vibrate_controller(0, 0, 0.0) if @vib_timer.complete?()  # Turn off Vibration if Timer Finished
  1082.           end
  1083.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1084.           # * New Method: Vibrate Xbox 360 Controller
  1085.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1086.           def vibrate_controller(lpower, rpower, duration)
  1087.             return unless connected?()
  1088.             lpower = [0, [lpower, 100].min].max
  1089.             rpower = [0, [rpower, 100].min].max
  1090.             Vibration.call(lpower, rpower)
  1091.            
  1092.             @vib_timer.set_finish(duration)
  1093.             @vib_timer.set_active(duration > 0.0)
  1094.             @vib_timer.reset()
  1095.           end
  1096.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1097.           # * New Method: Get an Xbox 360 Controller Axis
  1098.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1099.           def axis(rep)
  1100.             return @input[ get_rep_symbols()[rep] ]  rescue 0
  1101.           end
  1102.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1103.           # * Derived Method: Get The Xbox360 Controller's Representing Symbols
  1104.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1105.           def get_rep_symbols
  1106.             return Representatives
  1107.           end
  1108.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1109.           # * New Method: Xbox360 Controller Available
  1110.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1111.           def self.available?
  1112.             return true
  1113.           end
  1114.          
  1115.         rescue
  1116.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1117.           # * New Method: Xbox360 Controller Available
  1118.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1119.           def self.available?
  1120.             return false
  1121.           end
  1122.           error_text = "Warning:\nAn error occurred while attempting to connect with the Xbox360 Controller.\n\n\n" +
  1123.                        "Causes:\n* You may not have the Xbox360 Input dll provided.\n* DirectX may not be installed on this PC. \n* Your Operating System may not be compatible with the software attempting to interact with the controller.\n\n\n" +
  1124.                        "Result:\nThe Xbox360 Controller will not be used in this session."
  1125.           Win32API.new('user32.dll', 'MessageBox', 'pppi', '').call(0, error_text, "Warning", 48)
  1126.         end
  1127.       end
  1128.     end
  1129.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1130.   end # if DPCore::InputHandler::UseXbox360ControllerInput
  1131.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1132.  
  1133.  
  1134.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  1135.   # **  New Class:   PS3 Controller Input
  1136.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1137.   # This Class interacts with a PS3 Controller connected to the PC,
  1138.   # reading and passing information to/from the controller.
  1139.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1140.   if DPCore::InputHandler::UsePS3ControllerInput # Allow PS3 Controller Input?
  1141.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1142.     module Input
  1143.       class PS3Controller < Input::Controller_Base
  1144.         begin
  1145.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1146.           # *^ Controller Representing Symbols
  1147.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1148.           Representatives =
  1149.           {
  1150.             :Cross  => 3,  :Circle   => 2,   :Square => 4,     :Triangle => 1,   # Main Buttons
  1151.             :Start  => 10, :Select   => 9,                                       # Operation Buttons
  1152.             :L1     => 5,  :R1       => 6,                                       # Shoulder Buttons
  1153.             :L2     => 7,  :R2       => 8,                                       # Triggers
  1154.             :DPadUp => 13, :DPadDown => 14,  :DPadLeft => 11,  :DPadRight => 12, # DPad Directions
  1155.           }
  1156.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1157.           # *^ Data Information
  1158.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1159.           MinButtonID           = Representatives.min_by{ |k, v| v }[1]         # Lowest Button ID
  1160.           MaxButtonID           = Representatives.max_by{ |k, v| v }[1]         # Highest Button ID
  1161.           ButtonIterationRange  = MinButtonID..MaxButtonID                      # Iteration for Buttons
  1162.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1163.           # *^ DLL Information
  1164.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1165.           IsConnected = Win32API.new('System/PS3 Controller Input', 'ConnectedController', '', 'n')
  1166.           GetInput    = Win32API.new('System/PS3 Controller Input', 'GetControllerInput', 'n', 'n')
  1167.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1168.           # * Derived Method: Reset
  1169.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1170.           def reset
  1171.             super()
  1172.            
  1173.             for i in ButtonIterationRange
  1174.               @input[i] = new_key_info()
  1175.             end
  1176.           end
  1177.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1178.           # * New Method: Update PS3 Controller
  1179.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1180.           def update
  1181.             update_connection()
  1182.             update_buttons()      if @connected
  1183.           end
  1184.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1185.           # * New Method: Update PS3 Controller Connection Status
  1186.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1187.           def update_connection
  1188.             if @connected    != (IsConnected.call() == 1) # If Connection Status is not equal to Actual Connection Status
  1189.               @connected      = !@connected               # Reverse Connection Status
  1190.               reset()        if !@connected               # If no longer Connected to the Controller, Reset Controller Input
  1191.             end
  1192.           end
  1193.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1194.           # * New Method: Update PS3 Controller Buttons
  1195.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1196.           def update_buttons
  1197.             for i in ButtonIterationRange
  1198.               set_key_status(i, GetInput.call(i) != 0)
  1199.             end
  1200.           end
  1201.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1202.           # * Derived Method: Get The PS3 Controller's Representing Symbols
  1203.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1204.           def get_rep_symbols
  1205.             return Representatives
  1206.           end
  1207.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1208.           # * New Method: PS3 Controller Available
  1209.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1210.           def self.available?
  1211.             return true
  1212.           end
  1213.          
  1214.         rescue
  1215.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1216.           # * New Method: PS3 Controller Available
  1217.           #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1218.           def self.available?
  1219.             return false
  1220.           end
  1221.           error_text = "Warning:\nAn error occurred while attempting to connect with the PS3 Controller.\n\n\n" +
  1222.                        "Causes:\n* You may not have the PS3 Input dll provided. \n* DirectX may not be installed on this PC. \n* Your Operating System may not be compatible with the software attempting to interact with the controller\n\n\n" +
  1223.                        "Result:\nThe PS3 Controller will not be used in this session."
  1224.           Win32API.new('user32.dll', 'MessageBox', 'pppi', '').call(0, error_text, "Warning", 48)
  1225.         end
  1226.       end
  1227.     end
  1228.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1229.   end # if DPCore::InputHandler::UsePS3ControllerInput
  1230.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1231.  
  1232.  
  1233.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  1234.   # **  New Module:   Keyboard Input
  1235.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1236.   # This Module interacts with PC Keyboard, updating which keys have been
  1237.   # pressed and triggering appropriate responses.
  1238.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1239.   module Input
  1240.     class PCKeyboardInput < Input::Input_Base
  1241.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1242.       # *^ Keyboard Representing Symbols
  1243.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1244.       Representatives =
  1245.       {                
  1246.         # Letter Keys
  1247.         :A => 65, :B => 66, :C => 67, :D => 68, :E => 69, :F => 70,
  1248.         :G => 71, :H => 72, :I => 73, :J => 74, :K => 75, :L => 76,
  1249.         :M => 77, :N => 78, :O => 79, :P => 80, :Q => 81, :R => 82,
  1250.         :S => 83, :T => 84, :U => 85, :V => 86, :W => 87, :X => 88,
  1251.         :Y => 89, :Z => 90,
  1252.        
  1253.         # Number/Symbol Keys
  1254.         :Num0 => 48, :Num1 => 49, :Num2 => 50, :Num3 => 51, :Num4 => 52,
  1255.         :Num5 => 53, :Num6 => 54, :Num7 => 55, :Num8 => 56, :Num9 => 57,
  1256.        
  1257.         # Qwerty Symbol Keys
  1258.         :Comma        => 188, :Period       => 190, :ForwardSlash => 191,
  1259.         :SemiColon    => 186, :Quote        => 222,
  1260.         :LSqrBracket  => 219, :RSqrBracket  => 221, :BackSlash    => 220,
  1261.         :Tilde        => 192, :Dash         => 189, :Equals       => 187,
  1262.        
  1263.         # Arrow Keys
  1264.         :Left => 37, :Down => 40, :Right => 39, :Up => 38,  
  1265.        
  1266.         # NumPad Numbers
  1267.         :Numpad0 => 96,  :Numpad1 => 97,  :Numpad2 => 98,  :Numpad3 => 99,
  1268.         :Numpad4 => 100, :Numpad5 => 101, :Numpad6 => 102, :Numpad7 => 103,
  1269.         :Numpad8 => 104, :Numpad9 => 105,
  1270.        
  1271.         # NumPad Math Symbols
  1272.         :Multiply => 106, :Divide => 111,
  1273.         :Subtract => 109, :Add    => 107,
  1274.         :Decimal  => 110,
  1275.        
  1276.         # Function Keys
  1277.         :F1  => 112, :F2  => 113, :F3 => 114, :F4 => 115, :F5  => 116,
  1278.         :F6  => 117, :F7  => 118, :F8 => 119, :F9 => 120, :F10 => 121,
  1279.         :F11 => 122, :F12 => 123,
  1280.        
  1281.         :LCtrl        => 162, :RCtrl        => 163,
  1282.         :LShift       => 160, :RShift       => 161,
  1283.         :LAlt         => 164, :RAlt         => 165,
  1284.         :Enter        => 13,  :Backspace    => 8,
  1285.         :Spacebar     => 32,  :Tab          => 9,
  1286.        
  1287.         :Capslock     => 20,  :ScrollLock   => 145, :NumLock    => 144,
  1288.         :Escape       => 27,  :PrintScreen  => 44,  :Pause      => 19,
  1289.         :Insert       => 45,  :Home         => 36,  :PageUp     => 33,
  1290.         :Delete       => 46,  :End          => 35,  :PageDown   => 34,
  1291.       }
  1292.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1293.       # *^ Data Information
  1294.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1295.       KeysIteration = Representatives.values.sort
  1296.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1297.       # *^ DLL Information
  1298.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1299.       KeyState = Win32API.new('user32', 'GetAsyncKeyState', 'n', 'n')
  1300.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1301.       # * Derived Method: Reset
  1302.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1303.       def reset
  1304.         super()
  1305.         for i in KeysIteration
  1306.           @input[i] = new_key_info()
  1307.         end
  1308.       end
  1309.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1310.       # * New Method: Update PC Keyboard Input
  1311.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1312.       def update
  1313.         for i in KeysIteration
  1314.           set_key_status(i, KeyState.call(i) != 0)
  1315.         end
  1316.       end
  1317.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1318.       # * Derived Method: Get The PC Keyboard's Representing Symbols
  1319.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1320.       def get_rep_symbols
  1321.         return Representatives
  1322.       end
  1323.     end
  1324.   end
  1325.  
  1326.  
  1327.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  1328.   # **  New Class:   InputMapping
  1329.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1330.   # This Class populates itself with information on which buttons/keys for
  1331.   # each input device represents which RPGMaker Input Scheme.
  1332.   # This allows for much faster access when querying if an Input Scheme has
  1333.   # been triggered, pressed, etc
  1334.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1335.   module Input
  1336.     class InputMapping < Hash
  1337.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1338.       # * Derived Method: Object Initialisation
  1339.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1340.       def initialize
  1341.         super()
  1342.        
  1343.         get_input_symbols().each do |sym|
  1344.           create_sym_info(sym)
  1345.           assign_pc_keyboard_input(sym)
  1346.           assign_xbox360_controller_input(sym)
  1347.           assign_ps3_controller_input(sym)
  1348.           assign_additional_input(sym)
  1349.         end
  1350.       end
  1351.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1352.       # * New Method: Get Input Symbols
  1353.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1354.       def get_input_symbols
  1355.         return [:LEFT, :UP, :RIGHT, :DOWN, :A, :B, :C, :X, :Y, :Z, :L, :R,
  1356.                 :SHIFT, :CTRL, :ALT, :F5, :F6, :F7, :F8, :F9 ]
  1357.       end
  1358.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1359.       # * New Method: Create Info for Symbol
  1360.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1361.       def create_sym_info(sym)
  1362.         self[sym] = Hash.new()
  1363.       end
  1364.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1365.       # * New Method: Assign PC Keyboard Input
  1366.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1367.       def assign_pc_keyboard_input(sym)
  1368.         self[sym][:pc_keyboard] = DPCore::InputHandler::PCKeyboardKeysMapping.select{|k,v| v.include?(sym)}.keys
  1369.       end
  1370.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1371.       # * New Method: Assign Xbox 360 Controller Input
  1372.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1373.       def assign_xbox360_controller_input(sym)
  1374.         if DPCore::InputHandler::UseXbox360ControllerInput
  1375.           self[sym][:xbox360] = DPCore::InputHandler::Xbox360ControllerMapping.select{|k,v| v.include?(sym)}.keys
  1376.         end
  1377.       end
  1378.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1379.       # * New Method: Assign PS3 Controller Input
  1380.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1381.       def assign_ps3_controller_input(sym)
  1382.         if DPCore::InputHandler::UsePS3ControllerInput
  1383.           self[sym][:ps3] = DPCore::InputHandler::PS3ControllerMapping.select{|k,v| v.include?(sym)}.keys
  1384.         end
  1385.       end
  1386.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1387.       # * New Method: Assign Additional Input
  1388.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1389.       def assign_additional_input(sym)
  1390.       end
  1391.     end
  1392.   end
  1393.  
  1394.  
  1395.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  1396.   # **  Redefined Module:   Input
  1397.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1398.   # This Module processes the User Input for the Game
  1399.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1400.   module Input
  1401.     class << self
  1402.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1403.       # *^ New Constant Variables
  1404.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1405.       UseXboxCont = DPCore::InputHandler::UseXbox360ControllerInput && Input::Xbox360Controller.available?
  1406.       UsePS3Cont  = DPCore::InputHandler::UsePS3ControllerInput     && Input::PS3Controller.available?
  1407.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1408.       # *^ New Static Variables
  1409.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1410.       @@xbox360_controller  = Input::Xbox360Controller.new()    if UseXboxCont
  1411.       @@ps3_controller      = Input::PS3Controller.new()        if UsePS3Cont
  1412.       @@keyboard_keys       = Input::PCKeyboardInput.new()
  1413.       @@input_mapping       = Input::InputMapping.new()
  1414.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1415.       # * New Method: Xbox 360 Controller Connected?
  1416.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1417.       def xbox360_controller_connected?
  1418.         return UseXboxCont && @@xbox360_controller.connected?()
  1419.       end
  1420.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1421.       # * New Method: PS3 Controller Connected?
  1422.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1423.       def ps3_controller_connected?
  1424.         return UsePS3Cont && !xbox360_controller_connected?() && @@ps3_controller.connected?()
  1425.       end
  1426.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1427.       # * New Method: Get Xbox 360 Controller Instance
  1428.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1429.       def xbox360_input
  1430.         return @@xbox360_controller
  1431.       end
  1432.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1433.       # * New Method: Get PS3 Controller Instance
  1434.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1435.       def ps3_input
  1436.         return @@ps3_controller
  1437.       end
  1438.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1439.       # * New Method: Get PC Keyboard Instance
  1440.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1441.       def pc_keyboard_input
  1442.         return @@keyboard_keys
  1443.       end
  1444.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1445.       # * New Method: Get Input Instance
  1446.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1447.       def get_input_instance(input_type = :pc_keyboard)
  1448.         return xbox360_input()          if input_type == :xbox360
  1449.         return ps3_input()              if input_type == :ps3
  1450.         return pc_keyboard_input()
  1451.       end
  1452.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1453.       # * New Method: Get Input Mapping Hash Value
  1454.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1455.       def input_mapping(sym)
  1456.         return @@input_mapping[sym]
  1457.       end
  1458.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1459.       # * Overwritten Method: Update
  1460.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1461.       def update
  1462.         @@xbox360_controller.update()   if UseXboxCont
  1463.         @@ps3_controller.update()       if UsePS3Cont && !xbox360_controller_connected?()
  1464.         @@keyboard_keys.update()
  1465.       end
  1466.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1467.       # * Overwritten Method: Triggered Key?
  1468.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1469.       def trigger?(sym)
  1470.         return true if xbox360_controller_connected?() && @@input_mapping[sym][:xbox360].any?{|k| @@xbox360_controller.trigger?(k)}
  1471.         return true if ps3_controller_connected?() && @@input_mapping[sym][:ps3].any?{|k| @@ps3_controller.trigger?(k)}
  1472.         return @@input_mapping[sym][:pc_keyboard].any?{|k| @@keyboard_keys.trigger?(k)}
  1473.       end
  1474.      
  1475.       def triggered?(sym)
  1476.         return trigger?(sym)
  1477.       end
  1478.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1479.       # * Overwritten Method: Pressed Key?
  1480.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1481.       def press?(sym)
  1482.         return true if xbox360_controller_connected?() && @@input_mapping[sym][:xbox360].any?{|k| @@xbox360_controller.press?(k)}
  1483.         return true if ps3_controller_connected?() && @@input_mapping[sym][:ps3].any?{|k| @@ps3_controller.press?(k)}
  1484.         return @@input_mapping[sym][:pc_keyboard].any?{|k| @@keyboard_keys.press?(k)}
  1485.       end
  1486.      
  1487.       def pressed?(sym)
  1488.         return press?(sym)
  1489.       end
  1490.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1491.       # * Overwritten Method: Repeated Key?
  1492.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1493.       def repeat?(sym)
  1494.         return true if xbox360_controller_connected?() && @@input_mapping[sym][:xbox360].any?{|k| @@xbox360_controller.repeat?(k)}
  1495.         return true if ps3_controller_connected?() && @@input_mapping[sym][:ps3].any?{|k| @@ps3_controller.repeat?(k)}
  1496.         return @@input_mapping[sym][:pc_keyboard].any?{|k| @@keyboard_keys.repeat?(k)}
  1497.       end
  1498.      
  1499.       def repeated?(sym)
  1500.         return repeat?(sym)
  1501.       end
  1502.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1503.       # * New Method: Released Key?
  1504.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1505.       def release?(sym)
  1506.         return !press?(sym)
  1507.       end
  1508.      
  1509.       def released?(sym)
  1510.         return release?(sym)
  1511.       end
  1512.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1513.       # * New Method: Get Currently Triggered Keys           (Returns Array)
  1514.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1515.       def get_currently_triggered_keys(input_type = :pc_keyboard)
  1516.         return get_input_instance(input_type).currently_triggered_keys()
  1517.       end
  1518.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1519.       # * New Method: Get Currently Pressed Keys             (Returns Array)
  1520.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1521.       def get_currently_pressed_keys(input_type = :pc_keyboard)
  1522.         return get_input_instance(input_type).currently_pressed_keys()
  1523.       end
  1524.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1525.       # * New Method: Get Currently Repeated Keys            (Returns Array)
  1526.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1527.       def get_currently_repeated_keys(input_type = :pc_keyboard)
  1528.         return get_input_instance(input_type).currently_repeated_keys()
  1529.       end
  1530.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1531.       # * New Method: Get Currently Released Keys            (Returns Array)
  1532.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1533.       def get_currently_released_keys(input_type = :pc_keyboard)
  1534.         return get_input_instance(input_type).currently_released_keys()
  1535.       end
  1536.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1537.       # * Overwritten Method: Dir4
  1538.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1539.       def dir4
  1540.         return 2 if press?(:DOWN)
  1541.         return 8 if press?(:UP)
  1542.         return 4 if press?(:LEFT)
  1543.         return 6 if press?(:RIGHT)
  1544.         return 0
  1545.       end
  1546.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1547.       # * Overwritten Method: Dir8
  1548.       #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1549.       def dir8
  1550.         if press?(:DOWN)
  1551.           return 1 if press?(:LEFT)
  1552.           return 3 if press?(:RIGHT)
  1553.           return 2
  1554.         elsif press?(:UP)
  1555.           return 7 if press?(:LEFT)
  1556.           return 9 if press?(:RIGHT)
  1557.           return 8
  1558.         else
  1559.           return 4 if press?(:LEFT)
  1560.           return 6 if press?(:RIGHT)
  1561.           return 0
  1562.         end
  1563.       end
  1564.     end
  1565.   end
  1566.  
  1567.  
  1568.  
  1569.  
  1570.   #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  1571.   # ** Game_Interpreter
  1572.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1573.   #  An interpreter for executing event commands. This class is used within
  1574.   #  the Game_Map, Game_Troop, and Game_Event classes.
  1575.   #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  1576.   class Game_Interpreter
  1577.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1578.     # * New Method: Vibrate Controller
  1579.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1580.     def vibrate_controller(lpower, rpower = nil, duration = nil)
  1581.       return unless Input.xbox360_controller_connected?()
  1582.       if !duration.nil?     # Duration Used?
  1583.         Input.xbox360_input.vibrate_controller(lpower.to_i, rpower.to_i, duration.to_f)
  1584.       elsif !rpower.nil?    # If Duration not Used, perhaps it was defined as the RightPower
  1585.         Input.xbox360_input.vibrate_controller(lpower.to_i, lpower.to_i, rpower.to_f)
  1586.       else                  # Otherwise, Screw it! Forever Vibrate
  1587.         Input.xbox360_input.vibrate_controller(lpower.to_i, lpower.to_i, 0.0)
  1588.       end
  1589.     end
  1590.   end
  1591.  
  1592.  
  1593. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  1594. end # if DPCore::InputHandler::UseInputSystem
  1595. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement