blucalm

Hotkeys update 6 Nov 2012

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