Advertisement
blucalm

Hotkey, skills work see item amount turn bar on/off easily

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