blucalm

Hotkeys bugfix dec 5

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