blucalm

Untitled

Dec 3rd, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. elsif !item.for_friend?
  357. actor.use_item(item)
  358. end
  359. check_gameover
  360. Sound.play_use_item
  361. else
  362. Sound.play_buzzer
  363. end
  364. refresh_actionbar
  365. end # - End evalute_hotkey
  366.  
  367. def check_gameover
  368. SceneManager.goto(Scene_Gameover) if $game_party.all_dead?
  369. end # - End check_gameover
  370.  
  371. def use_item_to_actors
  372. item, user = $hkey_item, $hkey_user
  373. array = item_target_actors
  374. return if !array
  375. array.each do |target|
  376. @hkey_use_itm_ok = true
  377. item.repeats.times {
  378. target.item_apply(user, item)
  379. }
  380. end
  381. end # - End use_item_to_actors
  382.  
  383. def item_target_actors
  384. item = $hkey_item
  385. if !item.for_friend?
  386. []
  387. elsif item.for_all?
  388. $game_party.members
  389. else
  390. SceneManager.call(Scene_HotkeyActorSelection)
  391. []
  392. end
  393. end # - End item_target_actors
  394.  
  395. end # - End Scene_Map
  396.  
  397. #===============================================================
  398. # Scene_HotkeyActorSelection:
  399. # This class handles party member selection for hotkeys linked
  400. # to items/skills with a single target.
  401. #===============================================================
  402.  
  403. class Scene_HotkeyActorSelection < Scene_ItemBase
  404. def start
  405. super
  406. create_actor_window
  407. show_sub_window(@actor_window)
  408. @user = $hkey_user
  409. @item = $hkey_item
  410. @actor_window.select(0)
  411. end # - End start
  412.  
  413. #--------------------------------------------------------------------------
  414. # * Window to select the target of a skill or item
  415. #--------------------------------------------------------------------------
  416. def create_actor_window
  417. @actor_window = Window_MenuActor.new
  418. @actor_window.set_handler(:ok, method(:on_actor_ok))
  419. @actor_window.set_handler(:cancel, method(:on_actor_cancel))
  420. end # - End create_actor_window
  421.  
  422. #--------------------------------------------------------------------------
  423. # * Use Item on Actor
  424. #--------------------------------------------------------------------------
  425. def use_item_to_actors
  426. item_target_actors.each do |target|
  427. item.repeats.times { target.item_apply(user, item) }
  428. end
  429. end # - End use_item_to_actors
  430.  
  431. def user
  432. @user
  433. end
  434.  
  435. def item
  436. @item
  437. end
  438.  
  439. def play_se_for_item
  440. Sound.play_use_item
  441. end
  442.  
  443. #--------------------------------------------------------------------------
  444. # * Actor [Cancel]
  445. #--------------------------------------------------------------------------
  446. def on_actor_cancel
  447. hide_sub_window(@actor_window)
  448. end
  449.  
  450. #--------------------------------------------------------------------------
  451. # * Show Subwindow
  452. #--------------------------------------------------------------------------
  453. def show_sub_window(window)
  454. width_remain = Graphics.width - window.width
  455. window.x = 0
  456. @viewport.rect.x = @viewport.ox = window.width
  457. @viewport.rect.width = width_remain
  458. window.show.activate
  459. end # - End show_sub_window
  460.  
  461. #--------------------------------------------------------------------------
  462. # * Hide Subwindow
  463. #--------------------------------------------------------------------------
  464. def hide_sub_window(window)
  465. @viewport.rect.x = @viewport.ox = 0
  466. @viewport.rect.width = Graphics.width
  467. window.hide.deactivate
  468. return_scene
  469. end # - End hide_sub_window
  470.  
  471. #--------------------------------------------------------------------------
  472. # * Determine if Item Is Effective
  473. #--------------------------------------------------------------------------
  474. def item_effects_valid?
  475. item_target_actors.any? do |target|
  476. target.item_test($hkey_user, $hkey_item)
  477. end
  478. end # - End item_effects_valid?
  479.  
  480. #--------------------------------------------------------------------------
  481. # * Determine item targets
  482. #--------------------------------------------------------------------------
  483. def item_target_actors
  484. if !$hkey_item.for_friend?
  485. []
  486. elsif $hkey_item.for_all?
  487. $game_party.members
  488. else
  489. [$game_party.members[@actor_window.index]]
  490. end
  491. end # - End item_target_actors
  492.  
  493. end # - End Scene_HotkeyActorSelection
  494.  
  495. #===============================================================
  496. # Window_MenuCommand:
  497. # Adds a new command option called "Hot Keys" to the main menu
  498. #===============================================================
  499. class Window_MenuCommand < Window_Command
  500.  
  501. alias al_alias_method_m_make_com_l_ch_98384 make_command_list
  502. def make_command_list
  503. add_command("Hot Keys", :hotkey, true)
  504. al_alias_method_m_make_com_l_ch_98384
  505. end
  506.  
  507. alias hotkey_add_orig_com_alias_9089 add_original_commands
  508. def add_original_commands
  509. hotkey_add_orig_com_alias_9089
  510. end # - End add_original_commands
  511.  
  512. end # - End Window_MenuCommand
  513.  
  514. #Scene_Menu class
  515. class Scene_Menu < Scene_MenuBase
  516. #--------------------------------------------------------------------------
  517. # * Create Command Window
  518. #--------------------------------------------------------------------------
  519. alias hotkey_create_com_win_alias_9088 create_command_window
  520. def create_command_window
  521. hotkey_create_com_win_alias_9088
  522. @command_window.set_handler(:hotkey, method(:command_personal))
  523. end # - End create_command_window
  524.  
  525. # * Alias on_personal_ok
  526. alias hotkey_on_pers_ok_alias_meth on_personal_ok
  527. def on_personal_ok
  528. hotkey_on_pers_ok_alias_meth
  529. case @command_window.current_symbol
  530. when :hotkey
  531. SceneManager.call(Scene_Hotkey)
  532. end # - End case block
  533. end # - End on_personal_ok
  534. end # - End Scene_Menu
  535.  
  536. #==============================================================================
  537. # ** Window_HotkeyCommand
  538. #------------------------------------------------------------------------------
  539. # This command window appears on the menu screen.
  540. #==============================================================================
  541.  
  542. class Window_HotkeyCommand < Window_Command
  543.  
  544. attr_accessor :list
  545.  
  546. #--------------------------------------------------------------------------
  547. # * Initialize Command Selection Position (Class Method)
  548. #--------------------------------------------------------------------------
  549. @@last_command_symbol = nil
  550.  
  551. @@command_names ||= {
  552. :F5 => "F5",
  553. :F6 => "F6",
  554. :F7 => "F7",
  555. :F8 => "F8",
  556. :A => ":A",
  557. :B => ":B",
  558. :C => ":C",
  559. :X => ":X",
  560. :Y => ":Y",
  561. :Z => ":Z",
  562. :L => ":L",
  563. :R => ":R"
  564. }
  565.  
  566. #--------------------------------------------------------------------------
  567. # * Object Initialization
  568. #--------------------------------------------------------------------------
  569. def initialize(x,y)
  570. super(x, y)
  571. select_last
  572. @actor = nil
  573. end
  574.  
  575. #--------------------------------------------------------------------------
  576. # * Get Window Width
  577. #--------------------------------------------------------------------------
  578. def window_width
  579. return 160
  580. end
  581. #--------------------------------------------------------------------------
  582. # * Get Number of Lines to Show
  583. #--------------------------------------------------------------------------
  584. def visible_line_number
  585. item_max
  586. end
  587. #--------------------------------------------------------------------------
  588. # * Create Command List
  589. #--------------------------------------------------------------------------
  590. def make_command_list
  591. add_main_commands
  592. end
  593. #--------------------------------------------------------------------------
  594. # * Add Main Commands to List
  595. #--------------------------------------------------------------------------
  596. def add_main_commands
  597. pos_hash = HOTKEY::ACTIONBAR::ORDER
  598. (1..HOTKEY::ACTIONBAR::MAX).each{ |key|
  599. sym = pos_hash[key]
  600. add_command(@@command_names[sym], sym)
  601. }
  602. end
  603. #--------------------------------------------------------------------------
  604. # * Processing When OK Button Is Pressed
  605. #--------------------------------------------------------------------------
  606. def process_ok
  607. @@last_command_symbol = current_symbol
  608. super
  609. end
  610. #--------------------------------------------------------------------------
  611. # * Restore Previous Selection Position
  612. #--------------------------------------------------------------------------
  613. def select_last
  614. select_symbol(@@last_command_symbol)
  615. end
  616.  
  617. def self.last_command_symbol
  618. @@last_command_symbol
  619. end
  620.  
  621. def actor=(actor)
  622. return if @actor == actor
  623. @actor = actor
  624. refresh
  625. select_last
  626. end
  627.  
  628. #--------------------------------------------------------------------------
  629. # * Changes the name of the command on the menu
  630. #--------------------------------------------------------------------------
  631. def change_command_name(index, symbol, name)
  632. @list[index][:name] = name
  633. @@command_names[symbol] = name
  634. end
  635.  
  636. end # - End Window_HotKeyCommand
  637.  
  638. #==============================================================================
  639. # ** Window_HotkeyCategory
  640. #------------------------------------------------------------------------------
  641. # This window displays the categories Item and Skill when choosing which
  642. # hotkeys to associate with what.
  643. #==============================================================================
  644. class Window_HotkeyCategory < Window_HorzCommand
  645. attr_reader :item_window
  646.  
  647. def initialize(x,y,width)
  648. @widow_width = width
  649. super(x,y)
  650.  
  651. end # - End initialize
  652. #--------------------------------------------------------------------------
  653. # * Get Window Width
  654. #--------------------------------------------------------------------------
  655. def window_width
  656. @widow_width
  657. end # - End window_width
  658. #--------------------------------------------------------------------------
  659. # * Get Digit Count
  660. #--------------------------------------------------------------------------
  661. def col_max
  662. return 4
  663. end # - End col_max
  664. #--------------------------------------------------------------------------
  665. # * Frame Update
  666. #--------------------------------------------------------------------------
  667. def update
  668. super
  669. @item_window.category = current_symbol if @item_window
  670. end # - End update
  671. #--------------------------------------------------------------------------
  672. # * Create Command List
  673. #--------------------------------------------------------------------------
  674. def make_command_list
  675. add_command(Vocab::item, :item)
  676. add_command(Vocab::skill, :skill)
  677. add_command("On/Off", :on_off)
  678. add_command("Clear", :clear)
  679. end # - End make_command_list
  680. #--------------------------------------------------------------------------
  681. # * Set Item Window
  682. #--------------------------------------------------------------------------
  683. def item_window=(item_window)
  684. @item_window = item_window
  685. update
  686. end # - End item_window
  687.  
  688. end # - End Window_HotkeyCategory
  689.  
  690. #==============================================================================
  691. # ** Window_HotkeyItem
  692. #------------------------------------------------------------------------------
  693. # This window displays a list of items that can be associated with hotkeys.
  694. #==============================================================================
  695.  
  696. class Window_HotkeyItem < Window_Selectable
  697. #--------------------------------------------------------------------------
  698. # * Object Initialization
  699. #--------------------------------------------------------------------------
  700. def initialize(x, y, width, height)
  701. super
  702. @category = :none
  703. @data = []
  704. end
  705. #--------------------------------------------------------------------------
  706. # * Set Category
  707. #--------------------------------------------------------------------------
  708. def category=(category)
  709. return if @category == category
  710. @category = category
  711. refresh
  712. self.oy = 0
  713. end
  714. #--------------------------------------------------------------------------
  715. # * Get Digit Count
  716. #--------------------------------------------------------------------------
  717. def col_max
  718. return 2
  719. end
  720. #--------------------------------------------------------------------------
  721. # * Get Number of Items
  722. #--------------------------------------------------------------------------
  723. def item_max
  724. @data ? @data.size : 1
  725. end
  726. #--------------------------------------------------------------------------
  727. # * Get Item
  728. #--------------------------------------------------------------------------
  729. def item
  730. @data && index >= 0 ? @data[index] : nil
  731. end
  732. #--------------------------------------------------------------------------
  733. # * Get Activation State of Selection Item
  734. #--------------------------------------------------------------------------
  735. def current_item_enabled?
  736. enable?(@data[index])
  737. end
  738. #--------------------------------------------------------------------------
  739. # * Include in Item List?
  740. #--------------------------------------------------------------------------
  741. def include?(item)
  742. return item.is_a?(RPG::Item)# && !item.key_item?
  743. end
  744. #--------------------------------------------------------------------------
  745. # * Display in Enabled State?
  746. #--------------------------------------------------------------------------
  747. def enable?(item)
  748. $game_party.usable?(item)
  749. end
  750. #--------------------------------------------------------------------------
  751. # * Create Item List
  752. #--------------------------------------------------------------------------
  753. def make_item_list
  754. @data = $game_party.all_items.select { |item|
  755. include?(item) && enable?(item)
  756. }
  757. @data.push(nil) if include?(nil)
  758. end
  759. #--------------------------------------------------------------------------
  760. # * Restore Previous Selection Position
  761. #--------------------------------------------------------------------------
  762. def select_last
  763. select(@data.index($game_party.last_item.object) || 0)
  764. end
  765. #--------------------------------------------------------------------------
  766. # * Draw Item
  767. #--------------------------------------------------------------------------
  768. def draw_item(index)
  769. item = @data[index]
  770. if item
  771. rect = item_rect(index)
  772. rect.width -= 4
  773. draw_item_name(item, rect.x, rect.y, enable?(item))
  774. draw_item_number(rect, item)
  775. end
  776. end
  777. #--------------------------------------------------------------------------
  778. # * Draw Number of Items
  779. #--------------------------------------------------------------------------
  780. def draw_item_number(rect, item)
  781. draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  782. end
  783. #--------------------------------------------------------------------------
  784. # * Update Help Text
  785. #--------------------------------------------------------------------------
  786. def update_help
  787. @help_window.set_item(item)
  788. end
  789. #--------------------------------------------------------------------------
  790. # * Refresh
  791. #--------------------------------------------------------------------------
  792. def refresh
  793. make_item_list
  794. create_contents
  795. draw_all_items
  796. end
  797.  
  798. end # - End Window_HotkeyItem
  799.  
  800.  
  801. #==============================================================================
  802. # ** Window_HotkeySkillList
  803. #------------------------------------------------------------------------------
  804. # This window is for displaying skills which can be associated with a hotkey
  805. #==============================================================================
  806.  
  807. class Window_HotkeySkillList < Window_Selectable
  808. #--------------------------------------------------------------------------
  809. # * Object Initialization
  810. #--------------------------------------------------------------------------
  811. def initialize(x, y, width, height)
  812. super
  813. @actor = nil
  814. @stype_id = 0
  815. @data = []
  816. #self.visible = false
  817. end
  818. #--------------------------------------------------------------------------
  819. # * Set Actor
  820. #--------------------------------------------------------------------------
  821. def actor=(actor)
  822. return if @actor == actor
  823. @actor = actor
  824. refresh
  825. self.oy = 0
  826. end
  827. #--------------------------------------------------------------------------
  828. # * Set Skill Type ID
  829. #--------------------------------------------------------------------------
  830. def stype_id=(stype_id)
  831. return if @stype_id == stype_id
  832. @stype_id = stype_id
  833. refresh
  834. self.oy = 0
  835. end
  836. #--------------------------------------------------------------------------
  837. # * Get Digit Count
  838. #--------------------------------------------------------------------------
  839. def col_max
  840. return 2
  841. end
  842. #--------------------------------------------------------------------------
  843. # * Get Number of Items
  844. #--------------------------------------------------------------------------
  845. def item_max
  846. @data ? @data.size : 1
  847. end
  848. #--------------------------------------------------------------------------
  849. # * Get Skill
  850. #--------------------------------------------------------------------------
  851. def item
  852. @data && index >= 0 ? @data[index] : nil
  853. end
  854. #--------------------------------------------------------------------------
  855. # * Get Activation State of Selection Item
  856. #--------------------------------------------------------------------------
  857. def current_item_enabled?
  858. enable?(@data[index])
  859. end
  860. #--------------------------------------------------------------------------
  861. # * Include in Skill List?
  862. #--------------------------------------------------------------------------
  863. def include?(item)
  864. item
  865. end
  866. #--------------------------------------------------------------------------
  867. # * Display Skill in Active State?
  868. #--------------------------------------------------------------------------
  869. def enable?(item)
  870. true#@actor && @actor.usable?(item)
  871. end
  872. #--------------------------------------------------------------------------
  873. # * Create Skill List
  874. #--------------------------------------------------------------------------
  875. def make_item_list
  876. @data = @actor ? @actor.skills.select {|skill| include?(skill) } : []
  877. end
  878. #--------------------------------------------------------------------------
  879. # * Restore Previous Selection Position
  880. #--------------------------------------------------------------------------
  881. def select_last
  882. select(@data.index(@actor.last_skill.object) || 0)
  883. end
  884. #--------------------------------------------------------------------------
  885. # * Draw Item
  886. #--------------------------------------------------------------------------
  887. def draw_item(index)
  888. skill = @data[index]
  889. if skill
  890. rect = item_rect(index)
  891. rect.width -= 4
  892. draw_item_name(skill, rect.x, rect.y, enable?(skill))
  893. draw_skill_cost(rect, skill)
  894. end
  895. end
  896. #--------------------------------------------------------------------------
  897. # * Draw Skill Use Cost
  898. #--------------------------------------------------------------------------
  899. def draw_skill_cost(rect, skill)
  900. if @actor.skill_tp_cost(skill) > 0
  901. change_color(tp_cost_color, enable?(skill))
  902. draw_text(rect, @actor.skill_tp_cost(skill), 2)
  903. elsif @actor.skill_mp_cost(skill) > 0
  904. change_color(mp_cost_color, enable?(skill))
  905. draw_text(rect, @actor.skill_mp_cost(skill), 2)
  906. end
  907. end
  908. #--------------------------------------------------------------------------
  909. # * Update Help Text
  910. #--------------------------------------------------------------------------
  911. def update_help
  912. @help_window.set_item(item)
  913. end
  914. #--------------------------------------------------------------------------
  915. # * Refresh
  916. #--------------------------------------------------------------------------
  917. def refresh
  918. make_item_list
  919. create_contents
  920. draw_all_items
  921. end
  922.  
  923. end # - End Window_HotkeySkillList
  924.  
  925. #==============================================================================
  926. # * Easy Option for turning hotkey on/off
  927. #==============================================================================
  928. class Window_HkeyOnOff < Window_Selectable
  929. #--------------------------------------------------------------------------
  930. # * Draw Item
  931. #--------------------------------------------------------------------------
  932. def draw_item(index)
  933. draw_text(5,0,180,22, "Action Bar On/Off")
  934. end
  935.  
  936. def item_max
  937. return 1
  938. end
  939. end # Window_HkeyOnOFf
  940.  
  941. #==============================================================================
  942. # ** Scene_Hotkey
  943. #------------------------------------------------------------------------------
  944. # This class performs the hotkey screen processing.
  945. #==============================================================================
  946. class Scene_Hotkey < Scene_ItemBase
  947. #--------------------------------------------------------------------------
  948. # * Start Processing
  949. #--------------------------------------------------------------------------
  950. def start
  951. super
  952. create_help_window
  953. create_command_window
  954. create_category_window
  955. create_dummy_window
  956. create_skill_window
  957. create_item_window
  958. create_hkey_on_off_window
  959.  
  960. @skill_window.hide
  961. @item_window.hide
  962. @category_window.unselect
  963. @category_window.deactivate
  964. @hkey_on_off_window.hide
  965. end # - End start
  966.  
  967. #--------------------------------------------------------------------------
  968. # * Create Command Window
  969. # * This windows has commands representing keys to use as hotkeys
  970. #--------------------------------------------------------------------------
  971. def create_command_window
  972. wx = 0
  973. wy = @help_window.height
  974. @command_window = Window_HotkeyCommand.new(wx, wy)
  975. @command_window.viewport = @viewport
  976. @command_window.help_window = @help_window
  977. @command_window.actor = @actor
  978. @command_window.set_handler(:ok, method(:on_hotkey_select))
  979. @command_window.set_handler(:cancel, method(:return_scene))
  980. end # - End create_command_window
  981.  
  982. #--------------------------------------------------------------------------
  983. # * Create Skill Window
  984. #--------------------------------------------------------------------------
  985. def create_skill_window
  986. wx = @command_window.width
  987. wy = @category_window.y + @category_window.height
  988. ww = Graphics.width - @command_window.width
  989. wh = Graphics.height - wy
  990. @skill_window = Window_HotkeySkillList.new(wx, wy, ww, wh)
  991. @skill_window.actor = @actor
  992. @skill_window.viewport = @viewport
  993. @skill_window.help_window = @help_window
  994. @skill_window.set_handler(:ok, method(:on_skill_ok))
  995. @skill_window.set_handler(:cancel, method(:on_item_cancel))
  996. end # - End create_skill_window
  997.  
  998. #--------------------------------------------------------------------------
  999. # * Create Item Window
  1000. #--------------------------------------------------------------------------
  1001. def create_item_window
  1002. wy = @category_window.y + @category_window.height
  1003. wh = Graphics.height - wy
  1004. ww = Graphics.width-@command_window.width
  1005. @item_window = Window_HotkeyItem.new(@command_window.width, wy, ww, wh)
  1006. @item_window.viewport = @viewport
  1007. @item_window.help_window = @help_window
  1008. @item_window.set_handler(:ok, method(:on_item_ok))
  1009. @item_window.set_handler(:cancel, method(:on_item_cancel))
  1010. @category_window.item_window = @item_window
  1011. end # - End create_item_window
  1012.  
  1013. def create_hkey_on_off_window
  1014. wy = @category_window.y + @category_window.height
  1015. wh = Graphics.height - wy
  1016. ww = Graphics.width-@command_window.width
  1017. @hkey_on_off_window = Window_HkeyOnOff.new(@command_window.width, wy,ww,wh)
  1018. @hkey_on_off_window.viewport = @viewport
  1019. @hkey_on_off_window.set_handler(:ok, method(:on_off_ok))
  1020. @hkey_on_off_window.set_handler(:cancel, method(:on_item_cancel))
  1021. end
  1022.  
  1023. #def item_usable?
  1024. # $hkey_user.usable?($hkey_item) && item_effects_valid?
  1025. #end
  1026.  
  1027. #--------------------------------------------------------------------------
  1028. # * Create Category Window
  1029. #--------------------------------------------------------------------------
  1030. def create_category_window
  1031. x = @command_window.width
  1032. y = @help_window.height
  1033. width = Graphics.width - @command_window.width
  1034. @category_window = Window_HotkeyCategory.new(x,y, width)
  1035. @category_window.viewport = @viewport
  1036. @category_window.help_window = @help_window
  1037. @category_window.y = @help_window.height
  1038. @category_window.set_handler(:ok, method(:on_category_ok))
  1039. @category_window.set_handler(:cancel, method(:on_hotkey_cancel))
  1040. end # - End create_category_window
  1041.  
  1042. #--------------------------------------------------------------------------
  1043. # * Create Dummy Window
  1044. # * This window is used just for looks, it sits in the background
  1045. #--------------------------------------------------------------------------
  1046. def create_dummy_window
  1047. wy = @category_window.y + @category_window.height
  1048. wh = Graphics.height - wy
  1049. ww = Graphics.width - @command_window.width
  1050. @dummy_window = Window_Base.new(@command_window.width, wy, ww, wh)
  1051. @dummy_window.viewport = @viewport
  1052. end # - End create_dummy_window
  1053.  
  1054. #--------------------------------------------------------------------------
  1055. # * Get the user this hotkey is associated with
  1056. #--------------------------------------------------------------------------
  1057. #def user
  1058. # @actor
  1059. #end
  1060.  
  1061. #--------------------------------------------------------------------------
  1062. # * Category [OK]
  1063. #--------------------------------------------------------------------------
  1064. def on_category_ok
  1065. @dummy_window.hide
  1066. if @category_window.index == 0 #category item
  1067. @item_window.activate
  1068. @item_window.select_last
  1069. @skill_window.hide
  1070. @hkey_on_off_window.hide
  1071. @item_window.show
  1072. @skill_window.refresh
  1073. @item_window.refresh
  1074. elsif @category_window.index == 1 #category skill
  1075. @skill_window.activate
  1076. @skill_window.select_last
  1077. @skill_window.show
  1078. @item_window.hide
  1079. @hkey_on_off_window.hide
  1080. @skill_window.refresh
  1081. @item_window.refresh
  1082. elsif @category_window.index == 2 # action bar on/off
  1083. @hkey_on_off_window.activate
  1084. @hkey_on_off_window.select(0)
  1085. @hkey_on_off_window.show
  1086. @hkey_on_off_window.refresh
  1087. @item_window.hide
  1088. @skill_window.hide
  1089. else #category clear
  1090. @dummy_window.show
  1091. Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = nil
  1092. sym = @command_window.current_symbol
  1093. $hotkey_data[sym] = nil
  1094. update_command_window_text(sym, nil)
  1095. @category_window.refresh
  1096. @category_window.activate
  1097. end
  1098. end # - End on_category_ok
  1099.  
  1100. #--------------------------------------------------------------------------
  1101. # * Item [OK]
  1102. #--------------------------------------------------------------------------
  1103. def on_item_ok
  1104. new_hotkey(@item_window)
  1105. end # - End on_item_ok
  1106.  
  1107. #--------------------------------------------------------------------------
  1108. # * Skill [OK]
  1109. #--------------------------------------------------------------------------
  1110. def on_skill_ok
  1111. new_hotkey(@skill_window)
  1112. end # - End on_skill_ok
  1113.  
  1114. #--------------------------------------------------------------------------
  1115. # * Action bar on/off category
  1116. #--------------------------------------------------------------------------
  1117. def on_off_ok
  1118. add_on_off_hkey
  1119. @command_window.activate
  1120. end
  1121.  
  1122. def add_on_off_hkey
  1123. sym = @command_window.current_symbol
  1124. $hotkey_data[sym] = :action_bar_on_off
  1125. update_command_window_text(sym, :action_bar_on_off)
  1126. end
  1127. #--------------------------------------------------------------------------
  1128. # * Update $hotkey_data with the new hotkey.
  1129. #--------------------------------------------------------------------------
  1130. def new_hotkey(window)
  1131. $game_party.last_item.object = item
  1132. Game_Map.game_hotkeys[Window_HotkeyCommand.last_command_symbol] = [@actor, (item = window.item), window.item.is_a?(RPG::Skill) ? :skill : :item]
  1133. sym = @command_window.current_symbol
  1134. $hotkey_data[sym] = item.icon_index
  1135. update_command_window_text(sym, item)
  1136. @command_window.activate
  1137. end # - End new_hotkey
  1138.  
  1139. def update_command_window_text(sym, item)
  1140. colon = get_colon(sym)
  1141. name = !item ? "" : nil
  1142. name = (item &&!item.is_a?(RPG::UsableItem)) ? "->On/Off" : ("->" + item.name) if name.nil?
  1143.  
  1144.  
  1145. @command_window.change_command_name(@command_window.index, sym, colon+sym.to_s + name)
  1146. @command_window.refresh
  1147. end
  1148.  
  1149. def get_colon(sym)
  1150. colon = ":"
  1151. case sym.to_s
  1152. when "F5"
  1153. colon = ""
  1154. when "F6"
  1155. colon = ""
  1156. when "F7"
  1157. colon = ""
  1158. when "F8"
  1159. colon = ""
  1160. end
  1161. return colon
  1162. end
  1163. #--------------------------------------------------------------------------
  1164. # * Item [Cancel]
  1165. #--------------------------------------------------------------------------
  1166. def on_item_cancel
  1167. @item_window.hide
  1168. @skill_window.hide
  1169. @hkey_on_off_window.hide
  1170. @dummy_window.show
  1171. @category_window.activate
  1172. end # - End on_item_cancel
  1173.  
  1174. #--------------------------------------------------------------------------
  1175. # * Play SE When Using Item
  1176. #--------------------------------------------------------------------------
  1177. def play_se_for_item
  1178. Sound.play_use_item
  1179. end
  1180.  
  1181. #--------------------------------------------------------------------------
  1182. # * Cancels selection on the category window and moves back to the command
  1183. # window.
  1184. #--------------------------------------------------------------------------
  1185. def on_hotkey_cancel
  1186. @command_window.activate
  1187. @category_window.unselect
  1188. end # - End on_hotkey_cancel
  1189.  
  1190. #--------------------------------------------------------------------------
  1191. # * Handles processing after a hotkey has been selected from the command
  1192. # window.
  1193. #--------------------------------------------------------------------------
  1194. def on_hotkey_select
  1195. @category_window.activate
  1196. @category_window.select(0)
  1197. end
  1198. end # - End Scene_Hotkey
  1199. #=================================END OF FILE===================================
Advertisement
Add Comment
Please, Sign In to add comment