blucalm

Updated Hotkey script, now has option for cooldowns

Aug 22nd, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.46 KB | None | 0 0
  1. #===============================================================
  2. # - Eshra HOT KEYS -
  3. #===============================================================
  4.  
  5. # To use this script, insert it as new script in the script editor under
  6. # the materials section.
  7.  
  8. # This script allows skills and items to be linked to hotkeys from a new menu
  9. # inside of the main menu. It also creates an actionbar that can be turned on or
  10. # off.
  11.  
  12. # The hotkeys can be used while the current Scene is Scene_Map. The update method
  13. # of Scene_Map is now listens for key presses.
  14.  
  15. # Aliased Methods:
  16. # Scene_Map:
  17. # update
  18. # Scene_Map
  19. # update
  20.  
  21. # Window_MenuCommand
  22. # add_original_commands
  23.  
  24. # Scene_Menu
  25. # create_command_window
  26. # on_personal_ok
  27.  
  28.  
  29. # Below are the settings that can be adjusted when using this script
  30. module HOTKEY
  31. module ACTIONBAR
  32. HEIGHT = 47 # Height of the action bar
  33.  
  34. FONTSIZE = 13.5 # Size of the font in the action bar
  35.  
  36. MAX = 12 # This value should be greater than 0 and less than or equal to 12
  37. # it is the number of hotkeys the player can use
  38. LOCATION = [183, 205] # Numerator mod, Denominator
  39. VISIBLE = true # Switch this to false to hide the action bar.
  40.  
  41. WIDTH_OFFSET = 100
  42.  
  43. CD_VISIBLE = true
  44. ORDER = { # The hotkey associated with 1 is the leftmost, 12 is rightmost.
  45. 1 => :F5, # The symbols associatated with each number can be mixed and
  46. 2 => :F6, # matched around. For example to display hotkey A as the
  47. 3 => :F7, # leftmost hotkey instead of F5. Swamp :A with :F5 in the hash
  48. 4 => :F8, # such that 1 => :A and 5 => :F5.
  49. 5 => :A,
  50. 6 => :B,
  51. 7 => :C,
  52. 8 => :X,
  53. 9 => :Y,
  54. 10 => :Z,
  55. 11 => :L,
  56. 12 => :R
  57. }
  58. end
  59.  
  60. module COOLDOWN_GAUGE
  61. COLOR1 = Color.new(120, 80, 0, 250)
  62. COLOR2 = Color.new(200, 250, 0, 250)
  63. end
  64. end
  65.  
  66.  
  67. # Skill/Item cooldowns. While thae cooldown timer is greater than 0 they cannot
  68. # be used.
  69.  
  70. $imported = {} if $imported.nil?
  71. $imported["Eshra-SCENE_MAP_COOLDOWNS"] = true
  72.  
  73. module COOLDOWNS
  74. module USE_FAILED
  75. SOUND = 3 # Default Buzzer
  76. end
  77. module REGEXP
  78. TAG = /<!cooldown (\d+)>/i
  79. GLOBAL = /<!global cool (\d+)>/i
  80. end
  81. end
  82.  
  83. module DURATION
  84. module REGEXP
  85. TAG = /<!duration (\d+)>/i
  86. end
  87. module NAME
  88. TAG = /<!ts-name = (\w+)(?:\s|)\[T(\d+)\]>/i
  89. end
  90. end
  91.  
  92. module DataManager
  93.  
  94. #--------------------------------------------------------------------------
  95. # alias method: load_database
  96. #--------------------------------------------------------------------------
  97. class <<self; alias load_dtbase_mp_cd_ntags load_database; end
  98. def self.load_database
  99. load_dtbase_mp_cd_ntags
  100. load_map_cd_notetags
  101. end
  102.  
  103. #--------------------------------------------------------------------------
  104. # new method: load_notetags_abe
  105. #--------------------------------------------------------------------------
  106. def self.load_map_cd_notetags
  107. groups = [$data_armors, $data_weapons, $data_items, $data_skills]
  108. for group in groups
  109. for obj in group
  110. next if obj.nil?
  111. obj.load_sc_map_cd_notetags
  112. end
  113. end
  114. end
  115. end # DataManager
  116.  
  117. class RPG::UsableItem < RPG::BaseItem
  118. attr_accessor :cooldown_timer
  119. attr_accessor :base_cooldown
  120. attr_accessor :duration_timer
  121. attr_accessor :base_duration
  122. attr_accessor :global_cooldown
  123.  
  124. def load_sc_map_cd_notetags
  125. @cooldown_timer = 0
  126. @base_cooldown = 0
  127. @duration_timer = 0
  128. @base_duration = 0
  129. @global_cooldown = 0
  130.  
  131. self.note.split(/[\r\n]+/).each { |line|
  132. next unless line != nil
  133. case line
  134. when COOLDOWNS::REGEXP::TAG
  135. @base_cooldown = $1.to_i
  136. when DURATION::REGEXP::TAG
  137. @base_duration = $1.to_i
  138. when COOLDOWNS::REGEXP::GLOBAL
  139. @global_cooldown = $1.to_i
  140. print "loaded global cool = #{@global_cooldown}\n"
  141. end # End - case line
  142. } # End - self.note.split
  143. end # End - load_sc_map_cd_notetagss
  144.  
  145. end # End - RPG::UsableItem
  146.  
  147. #
  148. # RPG::BaseItem - Add an accessor for name
  149. #
  150. class RPG::BaseItem
  151. attr_accessor :name
  152. end
  153.  
  154. class RPG::EquipItem < RPG::BaseItem
  155. attr_accessor :cooldown_timer
  156. attr_accessor :base_cooldown
  157. attr_accessor :duration_timer
  158. attr_accessor :base_duration
  159. attr_accessor :global_cooldown
  160.  
  161. def load_sc_map_cd_notetags
  162. @cooldown_timer = 0
  163. @base_cooldown = 0
  164. @duration_timer = 0
  165. @base_duration = 0
  166. @global_cooldown = 0
  167.  
  168. self.note.split(/[\r\n]+/).each { |line|
  169. next unless line != nil
  170. case line
  171. when COOLDOWNS::REGEXP::TAG
  172. @base_cooldown = $1.to_i
  173. when DURATION::REGEXP::TAG
  174. @base_duration = $1.to_i
  175. when COOLDOWNS::REGEXP::GLOBAL
  176. @global_cooldown = $1.to_i
  177. end # End - case line
  178. } # End - self.note.split
  179. end # End - load_sc_map_cd_notetagss
  180. end # End - RPG::EquipItem
  181.  
  182. class Game_Map
  183.  
  184. attr_accessor :cooldown_queue # Items on cd are placed here
  185. attr_accessor :duration_queue # Items that last over time are place here
  186. attr_accessor :global_cooldown
  187. attr_accessor :global_cooldown_base
  188.  
  189. #
  190. # ** Alias method initialize
  191. #
  192. alias gme_map_cool_down_ch_initialize initialize
  193. def initialize
  194. gme_map_cool_down_ch_initialize
  195. @cooldown_queue = []
  196. @duration_queue = []
  197. @global_cooldown = 0
  198.  
  199. end # End - initialize
  200.  
  201. #
  202. # ** Alias method update
  203. #
  204. alias gme_map_cool_down_ch_update_9817 update
  205. def update(*arg)
  206.  
  207. gme_map_cool_down_ch_update_9817(*arg)
  208.  
  209. @global_cooldown -= 1 if @global_cooldown > 0
  210. print "global_cooldown remaining: #{global_cooldown}\n"
  211.  
  212.  
  213. print "cooldown_queue = #{@cooldown_queue.inspect}\n"
  214. @cooldown_queue.each{ |item|
  215. item.cooldown_timer-=1
  216. print "cooldown left on #{item}: #{item.cooldown_timer}\n"
  217. if(item.cooldown_timer <= 0)
  218. @cooldown_queue.delete(item)
  219. end
  220. } # End - @cooldown_queue.each
  221.  
  222. @duration_queue.each{ |item|
  223. item.duration_timer-=1
  224. print "duration left on #{item}: #{item.duration_timer}\n"
  225. if(item.duration_timer <= 0)
  226. @duration_queue.delete(item)
  227. end
  228.  
  229. } # End - @duration_queue.each
  230. end # End - update
  231.  
  232. # Store all the cooldown data for the item.
  233.  
  234. def init_cooldown_timers(item)
  235. item.cooldown_timer = item.base_cooldown
  236. item.duration_timer = item.base_duration
  237.  
  238. print "init cooldown_timer, item gcd = #{item.global_cooldown}\n"
  239.  
  240. if @global_cooldown < item.global_cooldown
  241. @global_cooldown = item.global_cooldown
  242. @global_cooldown_base = item.global_cooldown
  243. end
  244. @cooldown_queue.push(item) unless @cooldown_queue.include?(item)
  245. @duration_queue.push(item) unless @duration_queue.include?(item)
  246. end
  247.  
  248. def game_timer_skills
  249. @@game_timer_skills
  250. end
  251.  
  252. # Check if there is a global cooldown
  253. def all_cd?
  254. print "on gcd = ", @global_cooldown > 0, "\n"
  255. return @global_cooldown > 0
  256. end
  257.  
  258. def gcd_val(mod = 0)
  259. @global_cooldown + mod
  260. end
  261.  
  262. def gcd_base(mod = 0)
  263. @global_cooldown_base + mod
  264. end
  265.  
  266. end # End - Scene_Map
  267.  
  268. #
  269. # ** Aliased use_item methods in various classes: **
  270. #
  271.  
  272. class Scene_ItemBase < Scene_MenuBase
  273. alias item_usable_check_for_cd_4289_use_item use_item
  274. def use_item
  275. if item.cooldown_timer > 0 || $game_map.all_cd?
  276. Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  277. return
  278. end
  279. print "on global cooldown? #{$game_map.all_cd?}\n"
  280. item_usable_check_for_cd_4289_use_item
  281. $game_map.init_cooldown_timers(item)
  282. end # End - use_item
  283. end # End - Scene_ItemBase
  284.  
  285. #class Scene_Battle < Scene_Base
  286. # alias item_usable_check_for_cd_4288_use_item use_item
  287. # def use_item
  288. # if item.cooldown_timer != 0 && item.cooldown_timer != nil && $game_map.all_cd?
  289. # Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  290. # return
  291. # item_usable_check_for_cd_4288_use_item
  292. # $game_map.init_cooldown_timers(item)
  293. # end # End - use_item
  294. #end # End - Scene_Battle
  295.  
  296. #class Scene_Item < Scene_ItemBase
  297. # alias item_usable_check_for_cd_4287_use_item use_item
  298. # def use_item
  299. # if item.cooldown_timer != 0 && item.cooldown_timer != nil && $game_map.all_cd?
  300. # Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  301. # return
  302. # end
  303. # item_usable_check_for_cd_4287_use_item
  304. # $game_map.init_cooldown_timers(item)
  305. # end # End - use_item
  306. #end # End - Scene_Item
  307.  
  308. #class Scene_Skill < Scene_ItemBase
  309. # alias item_usable_check_for_cd_4286_use_item use_item
  310. # def use_item
  311. # if item.cooldown_timer != 0 && item.cooldown_timer != nil && $game_map.all_cd?
  312. # Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  313. # return
  314. # end
  315. # item_usable_check_for_cd_4286_use_item
  316. # $game_map.init_cooldown_timers(item)
  317. # end # End - use_item
  318. #end # End - Scene_Skill
  319.  
  320. class Game_Battler < Game_BattlerBase
  321. alias item_usable_check_for_cd_4285_use_item use_item
  322. def use_item(item)
  323. print "cooldown_timer: #{item.cooldown_timer}"
  324. if item.cooldown_timer > 0 || $game_map.all_cd?
  325. Sound.play_system_sound(COOLDOWNS::USE_FAILED::SOUND)
  326. return
  327. end
  328. item_usable_check_for_cd_4285_use_item(item)
  329. $game_map.init_cooldown_timers(item)
  330. end # End - use_item
  331. end # End - Game_Battler
  332.  
  333.  
  334. #===============================================================
  335. # Game_Map:
  336.  
  337. # New variables are added to hold hotkey information
  338. #
  339. #===============================================================
  340.  
  341. class Game_Map
  342. $hotkey_data ||= {} #maps symbols to item icons
  343. @@game_hotkeys ||= {}
  344.  
  345. def self.game_hotkeys
  346. @@game_hotkeys
  347. end
  348. end
  349. #===============================================================
  350. # Window_Base:
  351.  
  352. # Change the update so it handles the case where the window
  353. # has been disposed of.
  354. #===============================================================
  355. class Window_Base < Window
  356. alias hotkey_update_alias_meth_9092 update
  357. def update
  358. return if disposed?
  359. hotkey_update_alias_meth_9092
  360. end # - End update
  361. end # - End Window_Base
  362.  
  363. #===============================================================
  364. # Scene_Map:
  365.  
  366. # The update method listens for keyboard input.
  367. #===============================================================
  368. class Scene_Map < Scene_Base
  369.  
  370. $hkey_user = nil
  371. $hkey_target = nil
  372.  
  373.  
  374. alias hotkey_update_alias_9090 update
  375. def update
  376. hotkey_update_alias_9090
  377. if Input.trigger?(:F5)
  378. evalute_hotkey(:F5)
  379. elsif Input.trigger?(:F6)
  380. evalute_hotkey(:F6)
  381. elsif Input.trigger?(:F7)
  382. evalute_hotkey(:F7)
  383. elsif Input.trigger?(:F8)
  384. evalute_hotkey(:F8)
  385. elsif Input.trigger?(:A)
  386. evalute_hotkey(:A)
  387. elsif Input.trigger?(:B)
  388. evalute_hotkey(:B)
  389. elsif Input.trigger?(:C)
  390. evalute_hotkey(:C)
  391. elsif Input.trigger?(:X)
  392. evalute_hotkey(:X)
  393. elsif Input.trigger?(:Y)
  394. evalute_hotkey(:Y)
  395. elsif Input.trigger?(:Z)
  396. evalute_hotkey(:Z)
  397. elsif Input.trigger?(:R)
  398. evalute_hotkey(:R)
  399. elsif Input.trigger?(:L)
  400. evalute_hotkey(:L)
  401. end # - End trigger cases
  402.  
  403. update_actionbar
  404. update_cool_downs
  405.  
  406. end # - End update
  407.  
  408. def update_actionbar
  409. if HOTKEY::ACTIONBAR::VISIBLE
  410. if @actionbar == nil || @actionbar.disposed?
  411. create_actionbar
  412. end # - End actionbar check
  413. @actionbar.update unless @actionbar.disposed?
  414. end
  415. end
  416.  
  417. def update_cool_downs
  418. return unless $imported["Eshra-SCENE_MAP_COOLDOWNS"]
  419.  
  420. if HOTKEY::ACTIONBAR::VISIBLE && HOTKEY::ACTIONBAR::CD_VISIBLE
  421. if @cooldown_imgs == nil || @cooldown_imgs.disposed?
  422. create_cooldown_images
  423. end # - End actionbar check
  424. @cooldown_imgs.contents.clear
  425. draw_cooldown_imgs_contents(@cooldown_imgs)
  426. @cooldown_imgs.update unless @cooldown_imgs.disposed?
  427. end
  428.  
  429. end
  430.  
  431. def create_cooldown_images
  432. wy = HOTKEY::ACTIONBAR::LOCATION[0]*Graphics.height/HOTKEY::ACTIONBAR::LOCATION[1]
  433. wh = HOTKEY::ACTIONBAR::HEIGHT
  434. ww = Graphics.width - HOTKEY::ACTIONBAR::WIDTH_OFFSET
  435. @cooldown_imgs = Window_Base.new(HOTKEY::ACTIONBAR::WIDTH_OFFSET/2, wy, ww, wh)
  436. @cooldown_imgs.viewport = @viewport
  437. @cooldown_imgs.opacity = 0
  438. draw_cooldown_imgs_contents(@cooldown_imgs)
  439. end
  440.  
  441. def draw_cooldown_imgs_contents(window)
  442. width = Graphics.width-HOTKEY::ACTIONBAR::WIDTH_OFFSET
  443. font_size = HOTKEY::ACTIONBAR::FONTSIZE
  444. max = HOTKEY::ACTIONBAR::MAX
  445.  
  446. #(1..max).each{ |key|
  447. # sym = HOTKEY::ACTIONBAR::ORDER[key]
  448. # ind = $hotkey_data[sym]
  449. # window.draw_icon(ind, (key-1)*width/max, 0) unless ind == nil
  450. # window.contents.font.size = font_size
  451. # window.contents.draw_text((key-1)*width/max,0,width,22,sym.to_s)
  452. #}
  453. #window.draw_text(0,0,width,22,"Cool Downs")
  454.  
  455. (1..max).each{ |key|
  456. used_cd = 0
  457. used_cd_base = 0
  458. bar_length = 0
  459. item_cd = 0
  460. item_cd_base = 0
  461.  
  462. sym = HOTKEY::ACTIONBAR::ORDER[key]
  463. item = Game_Map.game_hotkeys[sym]
  464. item = item[1] unless item == nil
  465. if item == nil
  466. #print "item was nil\n"
  467. end
  468. next if item == nil
  469. #print "~~~~~~~~~~~~~~~~~~~~~item wasn't nil\n~~~~~~~~~~~~~~~~~~~~~~~\n"
  470. gcd = $game_map.gcd_val #global cooldown amt
  471. item_cd = item.cooldown_timer
  472. used_cd = 0#(gcd > item_cd) gcd : item_cd
  473. used_cd_base = -1
  474. if gcd > item_cd
  475. used_cd = $game_map.gcd_val
  476. used_cd_base = $game_map.gcd_base
  477. else
  478. used_cd = item_cd
  479. used_cd_base = item.base_cooldown
  480. end
  481.  
  482. print "item.cooldown_timer = #{item.cooldown_timer}\n"
  483. print "item.base_cooldown = #{item.base_cooldown}\n"
  484.  
  485. if used_cd_base <= 0
  486. used_cd_base = 1
  487. end
  488. bar_length = used_cd * (width/max) / used_cd_base
  489.  
  490. print "used_cd_base = #{used_cd_base}\n"
  491. print "used_cd= #{used_cd}\n"
  492. print "((key)*width/max) = #{(width/max)}\n"
  493. print "bar_length = #{bar_length}\n"
  494.  
  495. if bar_length > 0
  496. window.draw_gauge((key-1)*width/max,0,bar_length,1.01,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
  497. end
  498. #window.draw_gauge(0,0,500,165,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
  499. }
  500.  
  501. #window.draw_gauge(0,0,500,165,HOTKEY::COOLDOWN_GAUGE::COLOR1,HOTKEY::COOLDOWN_GAUGE::COLOR2)
  502. #window.draw_gauge(0,0,500,165,Color.new(120, 80, 0, 100),Color.new(200, 150, 0, 100))
  503. end # - End draw_actionbar_contents
  504.  
  505. def create_cd_bar
  506. @cd_bar = Bitmap.new(50,50)
  507. @cd_bar.fill_rect(0,0,50,50, Color.new(0, 0, 0, 160))
  508. end
  509.  
  510. def create_actionbar
  511. wy = HOTKEY::ACTIONBAR::LOCATION[0]*Graphics.height/HOTKEY::ACTIONBAR::LOCATION[1]
  512. wh = HOTKEY::ACTIONBAR::HEIGHT
  513. ww = Graphics.width - HOTKEY::ACTIONBAR::WIDTH_OFFSET
  514. @actionbar = Window_Base.new(HOTKEY::ACTIONBAR::WIDTH_OFFSET/2, wy, ww, wh)
  515. @actionbar.viewport = @viewport
  516. draw_actionbar_contents(@actionbar)
  517. end # - End create_actionbar
  518.  
  519. def draw_actionbar_contents(window)
  520. width = Graphics.width-HOTKEY::ACTIONBAR::WIDTH_OFFSET
  521. font_size = HOTKEY::ACTIONBAR::FONTSIZE
  522. max = HOTKEY::ACTIONBAR::MAX
  523.  
  524. (1..max).each{ |key|
  525. sym = HOTKEY::ACTIONBAR::ORDER[key]
  526. ind = $hotkey_data[sym]
  527. window.draw_icon(ind, (key-1)*width/max, 0) unless ind == nil
  528. window.contents.font.size = font_size
  529. window.contents.draw_text((key-1)*width/max,0,width,22,sym.to_s)
  530. }
  531. end # - End draw_actionbar_contents
  532.  
  533. def evalute_hotkey(symbol)
  534. return if !(hkey = Game_Map.game_hotkeys[symbol])
  535. $hkey_item = item = hkey[1]
  536. $hkey_user = actor = hkey[0]
  537. return if item == nil || actor == nil
  538. actor.use_item(item)
  539. use_item_to_actors if item.for_friend?
  540. check_gameover
  541. Sound.play_use_item
  542. end # - End evalute_hotkey
  543.  
  544. def check_gameover
  545. SceneManager.goto(Scene_Gameover) if $game_party.all_dead?
  546. end # - End check_gameover
  547.  
  548. def use_item_to_actors
  549. item, user = $hkey_item, $hkey_user
  550. array = item_target_actors
  551. return if array == nil
  552. array.each do |target|
  553. item.repeats.times {
  554. target.item_apply(user, item)
  555. }
  556. end
  557. end # - End use_item_to_actors
  558.  
  559. def item_target_actors
  560. item = $hkey_item
  561. if !item.for_friend?
  562. []
  563. elsif item.for_all?
  564. $game_party.members
  565. else
  566. SceneManager.call(Scene_HotkeyActorSelection)
  567. []
  568. end
  569. end # - End item_target_actors
  570.  
  571. end # - End Scene_Map
  572.  
  573. #===============================================================
  574. # Scene_HotkeyActorSelection:
  575.  
  576. # This class handles party member selection for hotkeys linked
  577. # to items/skills with a single target.
  578. #===============================================================
  579.  
  580. class Scene_HotkeyActorSelection < Scene_ItemBase
  581. def start
  582. super
  583. create_actor_window
  584. show_sub_window(@actor_window)
  585. @user = $hkey_user
  586. @item = $hkey_item
  587. @actor_window.select(0)
  588. end # - End start
  589.  
  590. #--------------------------------------------------------------------------
  591. # * Window to select the target of a skill or item
  592. #--------------------------------------------------------------------------
  593. def create_actor_window
  594. @actor_window = Window_MenuActor.new
  595. @actor_window.set_handler(:ok, method(:on_actor_ok))
  596. @actor_window.set_handler(:cancel, method(:on_actor_cancel))
  597. end # - End create_actor_window
  598.  
  599. #--------------------------------------------------------------------------
  600. # * Use Item on Actor
  601. #--------------------------------------------------------------------------
  602. def use_item_to_actors
  603. item_target_actors.each do |target|
  604. item.repeats.times { target.item_apply(user, item) }
  605. end
  606. end # - End use_item_to_actors
  607.  
  608. def user
  609. @user
  610. end
  611.  
  612. def item
  613. @item
  614. end
  615.  
  616. def play_se_for_item
  617. Sound.play_use_item
  618. end
  619.  
  620. #--------------------------------------------------------------------------
  621. # * Actor [Cancel]
  622. #--------------------------------------------------------------------------
  623. def on_actor_cancel
  624. hide_sub_window(@actor_window)
  625. end
  626.  
  627. #--------------------------------------------------------------------------
  628. # * Show Subwindow
  629. #--------------------------------------------------------------------------
  630. def show_sub_window(window)
  631. width_remain = Graphics.width - window.width
  632. window.x = 0
  633. @viewport.rect.x = @viewport.ox = window.width
  634. @viewport.rect.width = width_remain
  635. window.show.activate
  636. end # - End show_sub_window
  637.  
  638. #--------------------------------------------------------------------------
  639. # * Hide Subwindow
  640. #--------------------------------------------------------------------------
  641. def hide_sub_window(window)
  642. @viewport.rect.x = @viewport.ox = 0
  643. @viewport.rect.width = Graphics.width
  644. window.hide.deactivate
  645. return_scene
  646. end # - End hide_sub_window
  647.  
  648. #--------------------------------------------------------------------------
  649. # * Determine if Item Is usable
  650. #--------------------------------------------------------------------------
  651. #def item_usable?
  652. # $hkey_user.usable?($hkey_item) && item_effects_valid?
  653. #end # - End item_usable?
  654.  
  655. #--------------------------------------------------------------------------
  656. # * Determine if Item Is Effective
  657. #--------------------------------------------------------------------------
  658. def item_effects_valid?
  659. item_target_actors.any? do |target|
  660. target.item_test($hkey_user, $hkey_item)
  661. end
  662. end # - End item_effects_valid?
  663.  
  664. #--------------------------------------------------------------------------
  665. # * Determine item targets
  666. #--------------------------------------------------------------------------
  667. def item_target_actors
  668. if !$hkey_item.for_friend?
  669. []
  670. elsif $hkey_item.for_all?
  671. $game_party.members
  672. else
  673. [$game_party.members[@actor_window.index]]
  674. end
  675. end # - End item_target_actors
  676.  
  677. end # - End Scene_HotkeyActorSelection
  678.  
  679. #===============================================================
  680. # Window_MenuCommand:
  681.  
  682. # Adds a new command option called "Hot Keys" to the main menu
  683. #===============================================================
  684. class Window_MenuCommand < Window_Command
  685.  
  686. alias al_alias_method_m_make_com_l_ch_98384 make_command_list
  687. def make_command_list
  688. add_command("Hot Keys", :hotkey, true)
  689. al_alias_method_m_make_com_l_ch_98384
  690.  
  691.  
  692. #add_game_end_command #I commented out this line (I added this code)
  693.  
  694. end
  695.  
  696. alias hotkey_add_orig_com_alias_9089 add_original_commands
  697. def add_original_commands
  698. hotkey_add_orig_com_alias_9089
  699. add_command("Hot Keys", :hotkey, true)
  700. end # - End add_original_commands
  701.  
  702. end # - End Window_MenuCommand
  703.  
  704. #Scene_Menu class
  705. class Scene_Menu < Scene_MenuBase
  706. #--------------------------------------------------------------------------
  707. # * Create Command Window
  708. #--------------------------------------------------------------------------
  709. alias hotkey_create_com_win_alias_9088 create_command_window
  710. def create_command_window
  711. hotkey_create_com_win_alias_9088
  712. @command_window.set_handler(:hotkey, method(:command_personal))
  713. end # - End create_command_window
  714.  
  715. # * Alias on_personal_ok
  716. alias hotkey_on_pers_ok_alias_meth on_personal_ok
  717. def on_personal_ok
  718. hotkey_on_pers_ok_alias_meth
  719. case @command_window.current_symbol
  720. when :hotkey
  721. SceneManager.call(Scene_Hotkey)
  722. end # - End case block
  723. end # - End on_personal_ok
  724. end # - End Scene_Menu
  725.  
  726. #==============================================================================
  727. # ** Window_HotkeyCommand
  728. #------------------------------------------------------------------------------
  729. # This command window appears on the menu screen.
  730. #==============================================================================
  731.  
  732. class Window_HotkeyCommand < Window_Command
  733.  
  734. attr_accessor :list
  735.  
  736. #--------------------------------------------------------------------------
  737. # * Initialize Command Selection Position (Class Method)
  738. #--------------------------------------------------------------------------
  739. @@last_command_symbol = nil
  740.  
  741. @@command_names ||= {
  742. :F5 => "F5",
  743. :F6 => "F6",
  744. :F7 => "F7",
  745. :F8 => "F8",
  746. :A => ":A",
  747. :B => ":B",
  748. :C => ":C",
  749. :X => ":X",
  750. :Y => ":Y",
  751. :Z => ":Z",
  752. :L => ":L",
  753. :R => ":R"
  754. }
  755.  
  756. #--------------------------------------------------------------------------
  757. # * Object Initialization
  758. #--------------------------------------------------------------------------
  759. def initialize(x,y)
  760. super(x, y)
  761. select_last
  762. @actor = nil
  763. end
  764.  
  765. #--------------------------------------------------------------------------
  766. # * Get Window Width
  767. #--------------------------------------------------------------------------
  768. def window_width
  769. return 160
  770. end
  771. #--------------------------------------------------------------------------
  772. # * Get Number of Lines to Show
  773. #--------------------------------------------------------------------------
  774. def visible_line_number
  775. item_max
  776. end
  777. #--------------------------------------------------------------------------
  778. # * Create Command List
  779. #--------------------------------------------------------------------------
  780. def make_command_list
  781. add_main_commands
  782. end
  783. #--------------------------------------------------------------------------
  784. # * Add Main Commands to List
  785. #--------------------------------------------------------------------------
  786. def add_main_commands
  787. pos_hash = HOTKEY::ACTIONBAR::ORDER
  788. (1..HOTKEY::ACTIONBAR::MAX).each{ |key|
  789. sym = pos_hash[key]
  790. add_command(@@command_names[sym], sym)
  791. }
  792. end
  793. #--------------------------------------------------------------------------
  794. # * Processing When OK Button Is Pressed
  795. #--------------------------------------------------------------------------
  796. def process_ok
  797. @@last_command_symbol = current_symbol
  798. super
  799. end
  800. #--------------------------------------------------------------------------
  801. # * Restore Previous Selection Position
  802. #--------------------------------------------------------------------------
  803. def select_last
  804. select_symbol(@@last_command_symbol)
  805. end
  806.  
  807. def self.last_command_symbol
  808. @@last_command_symbol
  809. end
  810.  
  811. def actor=(actor)
  812. return if @actor == actor
  813. @actor = actor
  814. refresh
  815. select_last
  816. end
  817.  
  818. #--------------------------------------------------------------------------
  819. # * Changes the name of the command on the menu
  820. #--------------------------------------------------------------------------
  821. def change_command_name(index, symbol, name)
  822. @list[index][:name] = name
  823. @@command_names[symbol] = name
  824. end
  825.  
  826. end # - End Window_HotKeyCommand
  827.  
  828. #==============================================================================
  829. # ** Window_HotkeyCategory
  830. #------------------------------------------------------------------------------
  831. # This window displays the categories Item and Skill when choosing which
  832. # hotkeys to associate with what.
  833. #==============================================================================
  834. class Window_HotkeyCategory < Window_HorzCommand
  835. attr_reader :item_window
  836.  
  837. def initialize(x,y,width)
  838. @widow_width = width
  839. super(x,y)
  840.  
  841. end # - End initialize
  842. #--------------------------------------------------------------------------
  843. # * Get Window Width
  844. #--------------------------------------------------------------------------
  845. def window_width
  846. @widow_width
  847. end # - End window_width
  848. #--------------------------------------------------------------------------
  849. # * Get Digit Count
  850. #--------------------------------------------------------------------------
  851. def col_max
  852. return 3
  853. end # - End col_max
  854. #--------------------------------------------------------------------------
  855. # * Frame Update
  856. #--------------------------------------------------------------------------
  857. def update
  858. super
  859. @item_window.category = current_symbol if @item_window
  860. end # - End update
  861. #--------------------------------------------------------------------------
  862. # * Create Command List
  863. #--------------------------------------------------------------------------
  864. def make_command_list
  865. add_command(Vocab::item, :item)
  866. add_command(Vocab::skill, :skill)
  867. add_command("Clear", :clear)
  868. end # - End make_command_list
  869. #--------------------------------------------------------------------------
  870. # * Set Item Window
  871. #--------------------------------------------------------------------------
  872. def item_window=(item_window)
  873. @item_window = item_window
  874. update
  875. end # - End item_window
  876.  
  877. end # - End Window_HotkeyCategory
  878.  
  879. #==============================================================================
  880. # ** Window_HotkeyItem
  881. #------------------------------------------------------------------------------
  882. # This window displays a list of items that can be associated with hotkeys.
  883. #==============================================================================
  884.  
  885. class Window_HotkeyItem < Window_Selectable
  886. #--------------------------------------------------------------------------
  887. # * Object Initialization
  888. #--------------------------------------------------------------------------
  889. def initialize(x, y, width, height)
  890. super
  891. @category = :none
  892. @data = []
  893. end
  894. #--------------------------------------------------------------------------
  895. # * Set Category
  896. #--------------------------------------------------------------------------
  897. def category=(category)
  898. return if @category == category
  899. @category = category
  900. refresh
  901. self.oy = 0
  902. end
  903. #--------------------------------------------------------------------------
  904. # * Get Digit Count
  905. #--------------------------------------------------------------------------
  906. def col_max
  907. return 2
  908. end
  909. #--------------------------------------------------------------------------
  910. # * Get Number of Items
  911. #--------------------------------------------------------------------------
  912. def item_max
  913. @data ? @data.size : 1
  914. end
  915. #--------------------------------------------------------------------------
  916. # * Get Item
  917. #--------------------------------------------------------------------------
  918. def item
  919. @data && index >= 0 ? @data[index] : nil
  920. end
  921. #--------------------------------------------------------------------------
  922. # * Get Activation State of Selection Item
  923. #--------------------------------------------------------------------------
  924. def current_item_enabled?
  925. enable?(@data[index])
  926. end
  927. #--------------------------------------------------------------------------
  928. # * Include in Item List?
  929. #--------------------------------------------------------------------------
  930. def include?(item)
  931. return item.is_a?(RPG::Item)# && !item.key_item?
  932. end
  933. #--------------------------------------------------------------------------
  934. # * Display in Enabled State?
  935. #--------------------------------------------------------------------------
  936. def enable?(item)
  937. $game_party.usable?(item)
  938. end
  939. #--------------------------------------------------------------------------
  940. # * Create Item List
  941. #--------------------------------------------------------------------------
  942. def make_item_list
  943. @data = $game_party.all_items.select {|item| include?(item) }
  944. @data.push(nil) if include?(nil)
  945. end
  946. #--------------------------------------------------------------------------
  947. # * Restore Previous Selection Position
  948. #--------------------------------------------------------------------------
  949. def select_last
  950. select(@data.index($game_party.last_item.object) || 0)
  951. end
  952. #--------------------------------------------------------------------------
  953. # * Draw Item
  954. #--------------------------------------------------------------------------
  955. def draw_item(index)
  956. item = @data[index]
  957. if item
  958. rect = item_rect(index)
  959. rect.width -= 4
  960. draw_item_name(item, rect.x, rect.y, enable?(item))
  961. draw_item_number(rect, item)
  962. end
  963. end
  964. #--------------------------------------------------------------------------
  965. # * Draw Number of Items
  966. #--------------------------------------------------------------------------
  967. def draw_item_number(rect, item)
  968. draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  969. end
  970. #--------------------------------------------------------------------------
  971. # * Update Help Text
  972. #--------------------------------------------------------------------------
  973. def update_help
  974. @help_window.set_item(item)
  975. end
  976. #--------------------------------------------------------------------------
  977. # * Refresh
  978. #--------------------------------------------------------------------------
  979. def refresh
  980. make_item_list
  981. create_contents
  982. draw_all_items
  983. end
  984.  
  985. end # - End Window_HotkeyItem
  986.  
  987.  
  988. #==============================================================================
  989. # ** Window_HotkeySkillList
  990. #------------------------------------------------------------------------------
  991. # This window is for displaying skills which can be associated with a hotkey
  992. #==============================================================================
  993.  
  994. class Window_HotkeySkillList < Window_Selectable
  995. #--------------------------------------------------------------------------
  996. # * Object Initialization
  997. #--------------------------------------------------------------------------
  998. def initialize(x, y, width, height)
  999. super
  1000. @actor = nil
  1001. @stype_id = 0
  1002. @data = []
  1003. #self.visible = false
  1004. end
  1005. #--------------------------------------------------------------------------
  1006. # * Set Actor
  1007. #--------------------------------------------------------------------------
  1008. def actor=(actor)
  1009. return if @actor == actor
  1010. @actor = actor
  1011. refresh
  1012. self.oy = 0
  1013. end
  1014. #--------------------------------------------------------------------------
  1015. # * Set Skill Type ID
  1016. #--------------------------------------------------------------------------
  1017. def stype_id=(stype_id)
  1018. return if @stype_id == stype_id
  1019. @stype_id = stype_id
  1020. refresh
  1021. self.oy = 0
  1022. end
  1023. #--------------------------------------------------------------------------
  1024. # * Get Digit Count
  1025. #--------------------------------------------------------------------------
  1026. def col_max
  1027. return 2
  1028. end
  1029. #--------------------------------------------------------------------------
  1030. # * Get Number of Items
  1031. #--------------------------------------------------------------------------
  1032. def item_max
  1033. @data ? @data.size : 1
  1034. end
  1035. #--------------------------------------------------------------------------
  1036. # * Get Skill
  1037. #--------------------------------------------------------------------------
  1038. def item
  1039. @data && index >= 0 ? @data[index] : nil
  1040. end
  1041. #--------------------------------------------------------------------------
  1042. # * Get Activation State of Selection Item
  1043. #--------------------------------------------------------------------------
  1044. def current_item_enabled?
  1045. enable?(@data[index])
  1046. end
  1047. #--------------------------------------------------------------------------
  1048. # * Include in Skill List?
  1049. #--------------------------------------------------------------------------
  1050. def include?(item)
  1051. item
  1052. end
  1053. #--------------------------------------------------------------------------
  1054. # * Display Skill in Active State?
  1055. #--------------------------------------------------------------------------
  1056. def enable?(item)
  1057. true#@actor && @actor.usable?(item)
  1058. end
  1059. #--------------------------------------------------------------------------
  1060. # * Create Skill List
  1061. #--------------------------------------------------------------------------
  1062. def make_item_list
  1063. @data = @actor ? @actor.skills.select {|skill| include?(skill) } : []
  1064. end
  1065. #--------------------------------------------------------------------------
  1066. # * Restore Previous Selection Position
  1067. #--------------------------------------------------------------------------
  1068. def select_last
  1069. select(@data.index(@actor.last_skill.object) || 0)
  1070. end
  1071. #--------------------------------------------------------------------------
  1072. # * Draw Item
  1073. #--------------------------------------------------------------------------
  1074. def draw_item(index)
  1075. skill = @data[index]
  1076. if skill
  1077. rect = item_rect(index)
  1078. rect.width -= 4
  1079. draw_item_name(skill, rect.x, rect.y, enable?(skill))
  1080. draw_skill_cost(rect, skill)
  1081. end
  1082. end
  1083. #--------------------------------------------------------------------------
  1084. # * Draw Skill Use Cost
  1085. #--------------------------------------------------------------------------
  1086. def draw_skill_cost(rect, skill)
  1087. if @actor.skill_tp_cost(skill) > 0
  1088. change_color(tp_cost_color, enable?(skill))
  1089. draw_text(rect, @actor.skill_tp_cost(skill), 2)
  1090. elsif @actor.skill_mp_cost(skill) > 0
  1091. change_color(mp_cost_color, enable?(skill))
  1092. draw_text(rect, @actor.skill_mp_cost(skill), 2)
  1093. end
  1094. end
  1095. #--------------------------------------------------------------------------
  1096. # * Update Help Text
  1097. #--------------------------------------------------------------------------
  1098. def update_help
  1099. @help_window.set_item(item)
  1100. end
  1101. #--------------------------------------------------------------------------
  1102. # * Refresh
  1103. #--------------------------------------------------------------------------
  1104. def refresh
  1105. make_item_list
  1106. create_contents
  1107. draw_all_items
  1108. end
  1109.  
  1110. end # - End Window_HotkeySkillList
  1111.  
  1112.  
  1113.  
  1114. #==============================================================================
  1115. # ** Scene_Hotkey
  1116. #------------------------------------------------------------------------------
  1117. # This class performs the hotkey screen processing.
  1118. #==============================================================================
  1119. class Scene_Hotkey < Scene_ItemBase
  1120. #--------------------------------------------------------------------------
  1121. # * Start Processing
  1122. #--------------------------------------------------------------------------
  1123. def start
  1124. super
  1125. create_help_window
  1126. create_command_window
  1127. create_category_window
  1128. create_dummy_window
  1129. create_skill_window
  1130. create_item_window
  1131.  
  1132. @skill_window.hide
  1133. @item_window.hide
  1134. @category_window.unselect
  1135. @category_window.deactivate
  1136. end # - End start
  1137.  
  1138. #--------------------------------------------------------------------------
  1139. # * Create Command Window
  1140. # * This windows has commands representing keys to use as hotkeys
  1141. #--------------------------------------------------------------------------
  1142. def create_command_window
  1143. wx = 0
  1144. wy = @help_window.height
  1145. @command_window = Window_HotkeyCommand.new(wx, wy)
  1146. @command_window.viewport = @viewport
  1147. @command_window.help_window = @help_window
  1148. @command_window.actor = @actor
  1149. @command_window.set_handler(:ok, method(:on_hotkey_select))
  1150. @command_window.set_handler(:cancel, method(:return_scene))
  1151. end # - End create_command_window
  1152.  
  1153. #--------------------------------------------------------------------------
  1154. # * Create Skill Window
  1155. #--------------------------------------------------------------------------
  1156. def create_skill_window
  1157. wx = @command_window.width
  1158. wy = @category_window.y + @category_window.height
  1159. ww = Graphics.width - @command_window.width
  1160. wh = Graphics.height - wy
  1161. @skill_window = Window_HotkeySkillList.new(wx, wy, ww, wh)
  1162. @skill_window.actor = @actor
  1163. @skill_window.viewport = @viewport
  1164. @skill_window.help_window = @help_window
  1165. @skill_window.set_handler(:ok, method(:on_skill_ok))
  1166. @skill_window.set_handler(:cancel, method(:on_item_cancel))
  1167. end # - End create_skill_window
  1168.  
  1169. #--------------------------------------------------------------------------
  1170. # * Create Item Window
  1171. #--------------------------------------------------------------------------
  1172. def create_item_window
  1173. wy = @category_window.y + @category_window.height
  1174. wh = Graphics.height - wy
  1175. ww = Graphics.width-@command_window.width
  1176. @item_window = Window_ItemList.new(@command_window.width, wy, ww, wh)
  1177. @item_window.viewport = @viewport
  1178. @item_window.help_window = @help_window
  1179. @item_window.set_handler(:ok, method(:on_item_ok))
  1180. @item_window.set_handler(:cancel, method(:on_item_cancel))
  1181. @category_window.item_window = @item_window
  1182. end # - End create_item_window
  1183.  
  1184. #def item_usable?
  1185. # $hkey_user.usable?($hkey_item) && item_effects_valid?
  1186. #end
  1187.  
  1188. #--------------------------------------------------------------------------
  1189. # * Create Category Window
  1190. #--------------------------------------------------------------------------
  1191. def create_category_window
  1192. x = @command_window.width
  1193. y = @help_window.height
  1194. width = Graphics.width - @command_window.width
  1195. @category_window = Window_HotkeyCategory.new(x,y, width)
  1196. @category_window.viewport = @viewport
  1197. @category_window.help_window = @help_window
  1198. @category_window.y = @help_window.height
  1199. @category_window.set_handler(:ok, method(:on_category_ok))
  1200. @category_window.set_handler(:cancel, method(:on_hotkey_cancel))
  1201. end # - End create_category_window
  1202.  
  1203. #--------------------------------------------------------------------------
  1204. # * Create Dummy Window
  1205. # * This window is used just for looks, it sits in the background
  1206. #--------------------------------------------------------------------------
  1207. def create_dummy_window
  1208. wy = @category_window.y + @category_window.height
  1209. wh = Graphics.height - wy
  1210. ww = Graphics.width - @command_window.width
  1211. @dummy_window = Window_Base.new(@command_window.width, wy, ww, wh)
  1212. @dummy_window.viewport = @viewport
  1213. end # - End create_dummy_window
  1214.  
  1215. #--------------------------------------------------------------------------
  1216. # * Get the user this hotkey is associated with
  1217. #--------------------------------------------------------------------------
  1218. #def user
  1219. # @actor
  1220. #end
  1221.  
  1222. #--------------------------------------------------------------------------
  1223. # * Category [OK]
  1224. #--------------------------------------------------------------------------
  1225. def on_category_ok
  1226. @dummy_window.hide
  1227. if @category_window.index == 0 #category item
  1228. @item_window.activate
  1229. @item_window.select_last
  1230. @skill_window.hide
  1231. @item_window.show
  1232. @skill_window.refresh
  1233. @item_window.refresh
  1234. elsif @category_window.index == 1 #category skill
  1235. @skill_window.activate
  1236. @skill_window.select_last
  1237. @skill_window.show
  1238. @item_window.hide
  1239. @skill_window.refresh
  1240. @item_window.refresh
  1241. else #category clear
  1242. @dummy_window.show
  1243. Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = nil
  1244. sym = @command_window.current_symbol
  1245. $hotkey_data[sym] = nil
  1246. update_command_window_text(sym, nil)
  1247. @category_window.refresh
  1248. @category_window.activate
  1249. end
  1250. end # - End on_category_ok
  1251.  
  1252. #--------------------------------------------------------------------------
  1253. # * Item [OK]
  1254. #--------------------------------------------------------------------------
  1255. def on_item_ok
  1256. update_hotkey(@item_window)
  1257. end # - End on_item_ok
  1258.  
  1259. #--------------------------------------------------------------------------
  1260. # * Skill [OK]
  1261. #--------------------------------------------------------------------------
  1262. def on_skill_ok
  1263. update_hotkey(@skill_window)
  1264. end # - End on_skill_ok
  1265.  
  1266. #--------------------------------------------------------------------------
  1267. # * Update $hotkey_data with the new hotkey.
  1268. #--------------------------------------------------------------------------
  1269. def update_hotkey(window)
  1270. $game_party.last_item.object = item
  1271. Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = [@actor, (item = window.item)]
  1272. sym = @command_window.current_symbol
  1273. $hotkey_data[sym] = item.icon_index
  1274. update_command_window_text(sym, item)
  1275. @command_window.activate
  1276. end # - End update_hotkey
  1277.  
  1278. def update_command_window_text(sym, item)
  1279. colon = get_colon(sym)
  1280. name = (!item) ? "" : ("->" + item.name)
  1281. @command_window.change_command_name(@command_window.index, sym, colon+sym.to_s + name)
  1282. @command_window.refresh
  1283. end
  1284.  
  1285. def get_colon(sym)
  1286. colon = ":"
  1287. case sym.to_s
  1288. when "F5"
  1289. colon = ""
  1290. when "F6"
  1291. colon = ""
  1292. when "F7"
  1293. colon = ""
  1294. when "F8"
  1295. colon = ""
  1296. end
  1297. return colon
  1298. end
  1299. #--------------------------------------------------------------------------
  1300. # * Item [Cancel]
  1301. #--------------------------------------------------------------------------
  1302. def on_item_cancel
  1303. @item_window.hide
  1304. @skill_window.hide
  1305. @dummy_window.show
  1306. @category_window.activate
  1307. end # - End on_item_cancel
  1308.  
  1309. #--------------------------------------------------------------------------
  1310. # * Play SE When Using Item
  1311. #--------------------------------------------------------------------------
  1312. def play_se_for_item
  1313. Sound.play_use_item
  1314. end
  1315.  
  1316. #--------------------------------------------------------------------------
  1317. # * Cancels selection on the category window and moves back to the command
  1318. # window.
  1319. #--------------------------------------------------------------------------
  1320. def on_hotkey_cancel
  1321. @command_window.activate
  1322. @category_window.unselect
  1323. end # - End on_hotkey_cancel
  1324.  
  1325. #--------------------------------------------------------------------------
  1326. # * Handles processing after a hotkey has been selected from the command
  1327. # window.
  1328. #--------------------------------------------------------------------------
  1329. def on_hotkey_select
  1330. @category_window.activate
  1331. @category_window.select(0)
  1332. end
  1333.  
  1334. end # - End Scene_Hotkey
  1335. #=================================END OF FILE===================================
Advertisement
Add Comment
Please, Sign In to add comment