Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.76 KB | None | 0 0
  1. =begin
  2. ================================================================================
  3. CDR - Guide 1.0
  4. -------------------------------------------------------------------------------
  5. Author: Ceodore
  6. Mail: ceodore@email.com
  7. https://ceodoremaker.wordpress.com
  8.  
  9. ===============================Change log=======================================
  10. 16/03/2013 - 1.0 release.
  11.  
  12. ===============================Description======================================
  13. This implementation is meant to provide a way to guide the user on a scene. It
  14. was made to allow in-game tutorials, like menu or battle tutorials.
  15.  
  16. =================================License========================================
  17. You may freely use and modify this script as long as you do not change the
  18. original author information. If you use this on your game, include the author
  19. on the credits.
  20.  
  21. =========================Instalation & Compatibility============================
  22. Insert this script above main. Currently, only menu scenes, shop scenes and
  23. battle scenes were tested.
  24.  
  25. ===================================Use==========================================
  26. You just need to follow the examples and create your sequences. To enable a
  27. guide on the list, call a script event command and paste this line:
  28.  
  29. GuideManager.enable(x)
  30.  
  31. Where x is the guide id/switch.
  32.  
  33. Alternatively, you can enable the guide by turning it's Switch ON. In this
  34. case, the guide will start automatically once when you enter the scene, but
  35. this feature is still experimental, you may use it at your own risk.
  36.  
  37. You can use wathever tags you would use on a message, just don't forget to
  38. escape code characters, for example, \C[1] must be put as \\C[1]. This
  39. happens because the strings on this script are not treated as your regular
  40. message strings, where the \ character is automatically escaped.
  41.  
  42. =================================Commands=======================================
  43. The guide will follow a list of commands, wich can be a key input or a
  44. message, this is the list of currently supported commands:
  45.  
  46. ## Show Message ##
  47. [:msg, "string", {:face_name => string,
  48. :face_index => int,
  49. :background => int,
  50. :position => int}]
  51. This will display the string on a message window. The values on the
  52. dictionary are all optional, If you are not using any options, you can just
  53. use this format:
  54. [:msg, string]
  55. :face_name stands for the face file name placed on the Graphics/Faces dir
  56. :face_index stands for the face index inside the image, if you define a
  57. face name, you MUST define a face index.
  58.  
  59. The :background and :position have specific values, explained below:
  60.  
  61. :background
  62. 0 -> Normal Window
  63. 1 -> Dim Background
  64. 2 -> Transparent
  65.  
  66. :position
  67. 0 -> Top of the screen
  68. 1 -> Middle of the screen
  69. 2 -> Bottom of the screen
  70.  
  71. ## Show Message (Battle) ##
  72. [:msg, {:wait => int}]
  73. For the sake of compatibility with various battle scripts, the guide messages
  74. are displayed in the battle log on battle scenes, instead of a normal
  75. message window. You can use pretty much all message codes, like display
  76. icons, change colors, an all... but there are obvious limitations:
  77. 1. The battle log works with a line at a time. You can pile then in
  78. sequence, but it will hardly look like a default message window.
  79. 2. The battle log will not accept default message window options, like
  80. face, position or background.
  81. The big advantage is that the battle log window can be displayed at any
  82. moment without closing any window, so the guide flux will not be stopped to
  83. show a message.
  84. The :wait option stands for the time before the message closes automatically.
  85. It's optional, default is 10.
  86.  
  87. ## Change Switch ##
  88. [:sw, number, boolean]
  89. Specifies a switch to be turned on or off.
  90.  
  91. ## Change Variable ##
  92. [:var, number, string]
  93. The string can contain a number or any expression wich could be processed by
  94. the eval() method, like "1 * 2" or "$game_variables[2]", the generated value
  95. will be assigned to the specified variable.
  96.  
  97. ## Input Key ##
  98. [:key, input, times]
  99. This will force a key input. It supports any inputable character the RPG
  100. Maker accepts. Here are the main ones for menus:
  101. :DOWN -> Forces down key
  102. :UP -> Forces up key
  103. :RIGHT -> Forces right key
  104. :LEFT -> Forces left key
  105. :R -> Forces page down key
  106. :L -> Forces page up key
  107. :C -> Forces confirm key
  108. :B -> Forces cancel key
  109. The times parameter is optional and stands for the number of times this
  110. command will repeat. When no times attribute is found, it will execute the
  111. command once.
  112.  
  113. ## Change Rate ##
  114. [:rate, number]
  115. Changes the update rate to this number, the update rate will be restored to
  116. default value at the guide's end.
  117. ================================================================================
  118. =end
  119. $imported = {} if $imported.nil?
  120. $imported['CDR-Rows'] = true
  121. module CDR_GUIDE
  122. # This defines the interval between commands, in frames. Smaller the value,
  123. # higher the speed
  124. DEFAULT_UPDATE_RATE = 40
  125.  
  126. # This defines if the Guide List menu item will be added. This new item
  127. # will be placed below End Game and can access the guide list scene.
  128. ADD_MENU_ITEM = true
  129.  
  130. # This defines the index of the icon wich will be displayed as the file
  131. # icon for each available guide on the Guide_Scene.
  132. GUIDE_FILE_ICON = 286
  133.  
  134. # The menu item name
  135. MENU_ITEM_NAME = "Guide List"
  136.  
  137. # The string for unread guides on guide list
  138. NEW_STRING = "NEW"
  139.  
  140. # The string for the help window on the guide list scene
  141. HELP_WINDOW_TEXT = "Select a Guide"
  142.  
  143. # The color for unread guides on guide list
  144. NEW_COLOR = 6
  145.  
  146. # The bgm to be played when you are on a guide. Set as nil if you do not wish
  147. # a specific BGM.
  148. # [file name, {options}]
  149. GUIDE_BGM = ["Field2",{:volume=>100, :pitch=>100, :pos=>0}]
  150.  
  151. # The bgm to be played when you are on a shop guide. Set as nil if you do not
  152. # wish a specific BGM.
  153. # [file name, {options}]
  154. SHOP_GUIDE_BGM = ["Field2"]
  155.  
  156. # The bgm to be played when you are on a battle guide. Set as nil if you
  157. # do not wish a specific BGM.
  158. # [file name, {options}]
  159. BATTLE_GUIDE_BGM = ["Battle2"]
  160.  
  161. #=============================================================================
  162. # MOCK_PARTY_DATA
  163. #=============================================================================
  164. # Here is the list of fake parties for guide purposes. It can be realy useful
  165. # if your guide depends on the selection of a specific party member, or a
  166. # specific party state, like certain item available on top of the item list,
  167. # a member with depleted HP or high TP. After the guide stops, the original
  168. # party will be automatically restored as it was. The dictionary key is for
  169. # reference only, but must be unique for each mock party.
  170. MOCK_PARTY_DATA = {
  171. 1 => { # Optional, the party member's ids
  172. :members => [11,12],
  173. # Optional, the weapons on the party inventory
  174. :weapon => [# [id, quantity]
  175. [1,1]
  176. ],
  177. # Optional, the armor's id's on the party inventory
  178. :armor => [# [id, quantity]
  179. [1,1],
  180. [2,1]
  181. ],
  182. # Optional, the item's id's on the party inventory
  183. :item => [# [id, quantity]
  184. [1,2]
  185. ],
  186. # Optional, the party gold amount
  187. :gold => 1000,
  188. # Actor setup, here you can define default values for each actor
  189. :setup => [
  190. # [actor_id, {options}]
  191. [11, {:hp => 100, :tp => 20, :mp => 20}],
  192. [12, {:hp => 150}],
  193. ]
  194. }, #end of example mock party
  195. }#end of mock party data
  196.  
  197. #=============================================================================
  198. # GUIDE_DATA
  199. #=============================================================================
  200. # This is the dictionary of guides, please follow the example to create one,
  201. # please read the comments carefully.
  202. # The ID of the guide (the key for the dictionary item) references for a
  203. # game SWITCH, so the guide will be ready to start every time the switch is
  204. # turned on and you are on the guide's scene.
  205. GUIDE_DATA = {
  206.  
  207. # Example of menu guide. This will guide the player to the status scene.
  208. 1 => {# The guide type can be either :menu or :battle, a menu guide will
  209. # aways start from the main menu.
  210. :scene => Scene_Status,
  211. # The mock party id, this is optional, when no :party attribute is
  212. # defined, the current party will be used.
  213. :party => 1,
  214. # The guide name to be displayed on the guide list.
  215. :name => "How to Use the Status Screen",
  216. # An array containing this guide's commands
  217. :commands => [
  218. # Notice how the message is placed on this example. When you
  219. # break a line on the editor, the line break will be considered
  220. # on the message, however, the spaces from the left corner too,
  221. # so unless you intent to leave spaces on the line's left, lean
  222. # the line on the left corner. Another thing to notice are the
  223. # escaped characters, let's say you would put a message
  224. # code \C[1], instead you MUST put the extra \ before it, so it
  225. # becomes \\C[1]. If you don't, it will display an error.
  226. [:msg, "This is the Status screen. Here you can see
  227. the hero details. You can switch between
  228. heroes using \\c[4]Q\\c[0] and \\c[4]W\\c[0] keys on your
  229. keyboard. ", {:background => 1, :position => 1}],
  230. [:key, :R, 3],
  231. [:msg, "Now you know how to use the Status screen!",
  232. {:background => 1, :position => 1}],
  233. ]}, #end of example guide
  234.  
  235. # Example of battle guide
  236. 2 => {
  237. :scene => Scene_Battle,
  238. :troop => 31, # Required, a battle must have a troop id.
  239. :party => 1,
  240. :name => "How to Attack the Enemy",
  241. :commands => [
  242. [:key, :C],
  243. [:msg, "When the actor menu appears, select Attack." ],
  244. [:key, :C],
  245. [:msg, "Now, select an enemy." ],
  246. [:key, :C,3],
  247. [:msg, "Now you know how to attack!" ]
  248. ]
  249. },
  250. # Example of shop guide
  251. 3 => {
  252. :scene => Scene_Shop,
  253. :name => "How to Buy an Item",
  254. :party => 1,
  255. :goods => { # Optional, this will define the goods the shop will sell
  256. :weapon => [1,2,3],
  257. :armor => [1,2,3],
  258. :item => [1,2,3]
  259. },
  260. :commands => [
  261. [:msg, "Select the Buy option."],
  262. [:key, :C],
  263. [:msg, "Now you select an item."],
  264. [:key, :C],
  265. [:msg, "Select the quantity."],
  266. [:key, :RIGHT, 2],
  267. [:msg, "Now, confirm the buy."],
  268. [:key, :C],
  269. [:msg, "Now you know how to buy!"],
  270. ]
  271. },
  272. }#end of guide data
  273.  
  274. end
  275. #==============================================================================
  276. # DO NOT CHANGE beyond this point, unless you know what you're doing.
  277. #==============================================================================
  278.  
  279. # Input module duplicate to use the original methods.
  280. SuperInput = Input.dup
  281.  
  282. #==============================================================================
  283. # ** Input
  284. #==============================================================================
  285. module Input
  286.  
  287. # Flag that defines the currently forced key.
  288. @force_key = :NONE
  289.  
  290. # Flag that defines if player input is halted.
  291. @halt_player_input = false
  292.  
  293. # Flag that indicates if the key to be forced was used
  294. @pending_key = false
  295.  
  296. #--------------------------------------------------------------------------
  297. # * method rewrite: adds key forcing logics
  298. #--------------------------------------------------------------------------
  299. def self.repeat?(input)
  300. return true if @force_key == input
  301. return false if @force_key != :NONE
  302. return SuperInput.repeat?(input) if !@halt_player_input
  303. return false
  304. end
  305.  
  306. #--------------------------------------------------------------------------
  307. # * method rewrite: adds key forcing logics
  308. #--------------------------------------------------------------------------
  309. def self.trigger?(input)
  310. if @force_key == input
  311. @force_key = :NONE
  312. return true
  313. end
  314. return SuperInput.trigger?(input) if !@halt_player_input
  315. return false
  316. end
  317. #--------------------------------------------------------------------------
  318. # * method rewrite: adds key forcing logics
  319. #--------------------------------------------------------------------------
  320. def self.press?(input)
  321. return true if @force_key == input
  322. return false if @force_key != :NONE
  323. return SuperInput.press?(input) if !@halt_player_input
  324. return false
  325. end
  326.  
  327. #--------------------------------------------------------------------------
  328. # * new method: defines the key to be forced
  329. #--------------------------------------------------------------------------
  330. def self.force_key(input)
  331. @force_key = input
  332. end
  333.  
  334. #--------------------------------------------------------------------------
  335. # * new method: returns true if a key is being forced
  336. #--------------------------------------------------------------------------
  337. def self.force_key?
  338. return @force_key != :NONE
  339. end
  340.  
  341. #--------------------------------------------------------------------------
  342. # * new method: halts player input
  343. #--------------------------------------------------------------------------
  344. def self.halt
  345. @halt_player_input = true
  346. end
  347.  
  348. #--------------------------------------------------------------------------
  349. # * new method: releases player input
  350. #--------------------------------------------------------------------------
  351. def self.release
  352. @halt_player_input = false
  353. end
  354. end
  355. #==============================================================================
  356. # ** Sound
  357. #==============================================================================
  358. module Sound
  359. #--------------------------------------------------------------------------
  360. # * new method: plays the guide default bgm
  361. #--------------------------------------------------------------------------
  362. def self.play_guide_bgm
  363. play_bgm(CDR_GUIDE::GUIDE_BGM) if CDR_GUIDE::GUIDE_BGM
  364. end
  365. #--------------------------------------------------------------------------
  366. # * new method: plays the battle guide default bgm
  367. #--------------------------------------------------------------------------
  368. def self.play_battle_guide_bgm
  369. play_bgm(CDR_GUIDE::BATTLE_GUIDE_BGM) if CDR_GUIDE::BATTLE_GUIDE_BGM
  370. end
  371. #--------------------------------------------------------------------------
  372. # * new method: plays the shop guide default bgm
  373. #--------------------------------------------------------------------------
  374. def self.play_shop_guide_bgm
  375. play_bgm(CDR_GUIDE::SHOP_GUIDE_BGM) if CDR_GUIDE::SHOP_GUIDE_BGM
  376. end
  377. #--------------------------------------------------------------------------
  378. # * new method: plays a guide bgm
  379. #--------------------------------------------------------------------------
  380. def self.play_bgm(guide_bgm)
  381. volume = 100
  382. pitch = 100
  383. pos = 0
  384. if guide_bgm[1]
  385. volume = guide_bgm[1][:volume] if guide_bgm[1][:volume]
  386. pitch = guide_bgm[1][:pitch] if guide_bgm[1][:pitch]
  387. pos = guide_bgm[1][:pos] if guide_bgm[1][:pos]
  388. end
  389. Audio.bgm_play(sprintf('Audio/BGM/%s', guide_bgm[0]), volume, pitch, pos)
  390. Audio.bgs_stop
  391. end
  392. end
  393. #==============================================================================
  394. # ** Input
  395. #==============================================================================
  396. module GuideManager
  397. @memory = []
  398. @read = []
  399. @commands = []
  400. @index = 0
  401. @repeat_count = 0
  402. @last_command = false
  403. @current_key = 0
  404. @type = nil
  405. @update_rate = CDR_GUIDE::DEFAULT_UPDATE_RATE
  406. #--------------------------------------------------------------------------
  407. # * new method: defines the guide to be followed
  408. #--------------------------------------------------------------------------
  409. def self.guide(key, guide)
  410. @current_key = key
  411. @memory.push(key)
  412. @memory.compact!
  413. @memory.uniq!
  414. @memory.sort!
  415. @commands = guide[:commands]
  416. @scene = guide[:scene]
  417. return if !guide[:party]
  418. mock_party = CDR_GUIDE::MOCK_PARTY_DATA[guide[:party]]
  419. $party_backup = $game_party unless $game_party.mock_party?
  420. $game_party = Game_MockParty.new
  421. if mock_party[:members]
  422. mock_party[:members].each{|actor_id| $game_party.add_actor(actor_id)}
  423. end
  424. if mock_party[:weapon]
  425. mock_party[:weapon].each{|item|
  426. $game_party.gain_item($data_weapons[item[0]], item[1])
  427. }
  428. end
  429. if mock_party[:armor]
  430. mock_party[:armor].each{|item|
  431. $game_party.gain_item($data_armors[item[0]], item[1])
  432. }
  433. end
  434. if mock_party[:item]
  435. mock_party[:item].each{|item|
  436. $game_party.gain_item($data_items[item[0]], item[1])
  437. }
  438. end
  439. if mock_party[:gold]
  440. $game_party.gain_gold(mock_party[:gold])
  441. end
  442. if mock_party[:setup]
  443. mock_party[:setup].each{|change|
  444. actor = $game_actors[change[0]]
  445. options = change[1]
  446. actor.set_hp(options[:hp]) if options[:hp]
  447. actor.set_tp(options[:tp]) if options[:tp]
  448. actor.set_mp(options[:mp]) if options[:mp]
  449. }
  450. end
  451. end
  452. #--------------------------------------------------------------------------
  453. # * new method: enabled a guide in the Guide_Scene
  454. #--------------------------------------------------------------------------
  455. def self.enable(key)
  456. @memory.push(key)
  457. @memory.compact!
  458. @memory.uniq!
  459. @memory.sort!
  460. end
  461. #--------------------------------------------------------------------------
  462. # * new method: returns true if guide variable is an empty array
  463. #--------------------------------------------------------------------------
  464. def self.disable(key)
  465. @memory.remove(key)
  466. @memory.sort!
  467. end
  468. #--------------------------------------------------------------------------
  469. # * new method: enabled a guide in the Guide_Scene
  470. #--------------------------------------------------------------------------
  471. def self.mark_as_read
  472. return if @current_key == 0
  473. @read.push(@current_key)
  474. @read.compact!
  475. @read.uniq!
  476. @read.sort!
  477. end
  478. #--------------------------------------------------------------------------
  479. # * new method: returns true if guide variable is an empty array
  480. #--------------------------------------------------------------------------
  481. def self.read?(key)
  482. @read.include?(key)
  483. end
  484. #--------------------------------------------------------------------------
  485. # * new method: clears the guide sequence and control variables
  486. #--------------------------------------------------------------------------
  487. def self.clear
  488. mark_as_read
  489. self.replay_bgm_and_bgs
  490. @last_command = false
  491. @current_key = 0
  492. @commands = []
  493. @index = 0
  494. @repeat_count = 0
  495. @scene = nil
  496. @update_rate = CDR_GUIDE::DEFAULT_UPDATE_RATE
  497. $game_party = $party_backup if $game_party.mock_party?
  498. $game_player.refresh
  499. $game_map.need_refresh = true
  500. SceneManager.return
  501. end
  502. #--------------------------------------------------------------------------
  503. # * new method: returns true if guide variable is an empty array
  504. #--------------------------------------------------------------------------
  505. def self.empty?
  506. @commands.empty?
  507. end
  508. #--------------------------------------------------------------------------
  509. # * new method: defines a new list of guide commands
  510. #--------------------------------------------------------------------------
  511. def self.commands=(commands)
  512. @commands = commands
  513. end
  514. #--------------------------------------------------------------------------
  515. # * new method: defines a new update rate
  516. #--------------------------------------------------------------------------
  517. def self.update_rate=(update_rate)
  518. @update_rate = update_rate
  519. end
  520. #--------------------------------------------------------------------------
  521. # * new method: access the current update rate
  522. #--------------------------------------------------------------------------
  523. def self.update_rate
  524. [@update_rate,1].max
  525. end
  526. #--------------------------------------------------------------------------
  527. # * new method: returns true if guide variable is an empty array
  528. #--------------------------------------------------------------------------
  529. def self.guide_list
  530. named = []
  531. @memory.each{|switch|
  532. if !CDR_GUIDE::GUIDE_DATA[switch][:name].nil?
  533. named.push(switch)
  534. end
  535. }
  536. return named
  537. end
  538. #--------------------------------------------------------------------------
  539. # * new method: returns true if guide variable is an empty array
  540. #--------------------------------------------------------------------------
  541. def self.battle_guide?
  542. CDR_GUIDE::GUIDE_DATA[@current_key][:scene] == Scene_Battle
  543. end
  544. #--------------------------------------------------------------------------
  545. # * new method: defines a new value for guide index
  546. #--------------------------------------------------------------------------
  547. def self.index=(index)
  548. @index = index
  549. end
  550. #--------------------------------------------------------------------------
  551. # * new method: defines a new value for repetition counter
  552. #--------------------------------------------------------------------------
  553. def self.repeat_count=(count)
  554. @repeat_count = count-1
  555. end
  556. #--------------------------------------------------------------------------
  557. # * new method: decreases the repetition count
  558. #--------------------------------------------------------------------------
  559. def self.decrease_count
  560. @repeat_count -= 1 if counting?
  561. end
  562. #--------------------------------------------------------------------------
  563. # * new method: returns true if the repeat count is bigger than zero
  564. #--------------------------------------------------------------------------
  565. def self.counting?
  566. @repeat_count > 0
  567. end
  568. #--------------------------------------------------------------------------
  569. # * new method: returns the current guide command being processed
  570. #--------------------------------------------------------------------------
  571. def self.current_command
  572. @last_command = !next_command?
  573. @commands[@index]
  574. end
  575. #--------------------------------------------------------------------------
  576. # * new method: steps to the next command
  577. #--------------------------------------------------------------------------
  578. def self.next_command
  579. @index += 1
  580. end
  581. #--------------------------------------------------------------------------
  582. # * new method: return true if the are any commands left to process
  583. #--------------------------------------------------------------------------
  584. def self.next_command?
  585. return !@commands[@index+1].nil?
  586. end
  587. #--------------------------------------------------------------------------
  588. # * new method: returns true if a guide command is running
  589. #--------------------------------------------------------------------------
  590. def self.running?
  591. return (counting? or next_command?)
  592. end
  593. #--------------------------------------------------------------------------
  594. # * Save BGM and BGS
  595. #--------------------------------------------------------------------------
  596. def self.save_bgm_and_bgs
  597. @map_bgm = RPG::BGM.last
  598. @map_bgs = RPG::BGS.last
  599. end
  600. #--------------------------------------------------------------------------
  601. # * Resume BGM and BGS
  602. #--------------------------------------------------------------------------
  603. def self.replay_bgm_and_bgs
  604. @map_bgm.replay unless @map_bgm.nil?
  605. @map_bgs.replay unless @map_bgs.nil?
  606. end
  607. end
  608.  
  609. #==============================================================================
  610. # ** Game_Party
  611. #==============================================================================
  612. class Game_Party < Game_Unit
  613. #--------------------------------------------------------------------------
  614. # * new method: identifies as a mock party
  615. #--------------------------------------------------------------------------
  616. def mock_party?
  617. false
  618. end
  619. end
  620. #==============================================================================
  621. # ** Game_Actor
  622. #==============================================================================
  623. class Game_Actor < Game_Battler
  624. #--------------------------------------------------------------------------
  625. # * new method: changes the actor's hp value
  626. #--------------------------------------------------------------------------
  627. def set_hp(hp)
  628. self.hp = hp
  629. end
  630. #--------------------------------------------------------------------------
  631. # * new method: changes the actor's mp value
  632. #--------------------------------------------------------------------------
  633. def set_mp(mp)
  634. self.mp = mp
  635. end
  636. #--------------------------------------------------------------------------
  637. # * new method: changes the actor's tp value
  638. #--------------------------------------------------------------------------
  639. def set_tp(tp)
  640. self.tp = tp
  641. end
  642. end
  643. #==============================================================================
  644. # ** Game_MockParty
  645. #==============================================================================
  646. class Game_MockParty < Game_Party
  647. #--------------------------------------------------------------------------
  648. # * new method: identifies as a mock party
  649. #--------------------------------------------------------------------------
  650. def mock_party?
  651. true
  652. end
  653. end
  654. #==============================================================================
  655. # ** Scene_Base
  656. #==============================================================================
  657. class Scene_Base
  658. #--------------------------------------------------------------------------
  659. # * method alias: creates the guide message window
  660. #--------------------------------------------------------------------------
  661. alias cdr_guide_start start
  662. def start
  663. Input.halt
  664. $game_message.visible = false
  665. if (!self.is_a?(Scene_Map))
  666. create_message_window
  667. CDR_GUIDE::GUIDE_DATA.each{ |switch, guide|
  668. if($game_switches[switch] and self.is_a?(guide[:scene]))
  669. $game_switches[switch] = false
  670. GuideManager.guide(switch, guide)
  671. break
  672. end
  673. }
  674. end
  675. cdr_guide_start
  676. Input.release
  677. end
  678.  
  679. #--------------------------------------------------------------------------
  680. # * new method: creates the message window
  681. #--------------------------------------------------------------------------
  682. def create_message_window
  683. @message_window = Window_Message.new
  684. @message_window.z = @message_window.z+100
  685. end
  686.  
  687. #--------------------------------------------------------------------------
  688. # * method alias: fires the guide process
  689. #--------------------------------------------------------------------------
  690. alias cdr_guide_update update
  691. def update
  692. update_guide
  693. cdr_guide_update
  694. end
  695.  
  696. #--------------------------------------------------------------------------
  697. # * new method: process guide logic
  698. #--------------------------------------------------------------------------
  699. def wait_for_message
  700. @message_window.update
  701. update_for_wait while $game_message.visible
  702. end
  703.  
  704. #--------------------------------------------------------------------------
  705. # * new method: process guide logic
  706. #--------------------------------------------------------------------------
  707. def update_guide
  708. return if skip_guide_update?
  709. if GuideManager.current_command.nil?
  710. GuideManager.clear
  711. return
  712. end
  713. Input.halt
  714. return if Graphics.frame_count%GuideManager.update_rate != 0
  715. process_guide_command(GuideManager.current_command)
  716. end
  717. #--------------------------------------------------------------------------
  718. # * new method: returns true if a guide update must be skipped
  719. #--------------------------------------------------------------------------
  720. def skip_guide_update?
  721. return true if GuideManager.empty?
  722. end
  723. #--------------------------------------------------------------------------
  724. # * new method: returns true if a guide update must be skipped
  725. #--------------------------------------------------------------------------
  726. def process_guide_command(command)
  727. case command[0]
  728. when :key
  729. Input.force_key(command[1])
  730. if GuideManager.counting?
  731. GuideManager.decrease_count
  732. else
  733. GuideManager.repeat_count = command[2] if !command[2].nil?
  734. end
  735. GuideManager.next_command if !GuideManager.counting?
  736. when :msg
  737. process_message(command)
  738. GuideManager.next_command
  739. when :sw
  740. $game_switches[command[1]] = command[2]
  741. GuideManager.next_command
  742. when :var
  743. $game_variables[command[1]] = eval(command[2])
  744. GuideManager.next_command
  745. when :rate
  746. GuideManager.update_rate = command[1]
  747. GuideManager.next_command
  748. end
  749. end
  750. #--------------------------------------------------------------------------
  751. # * new method: process the current message command
  752. #--------------------------------------------------------------------------
  753. def process_message(command)
  754. $game_message.add(command[1])
  755. if !command[2].nil?
  756. options = command[2]
  757. $game_message.face_name = options[:face_name] if options[:face_name]
  758. $game_message.face_index = options[:face_index] if options[:face_index]
  759. $game_message.background = options[:background] if options[:background]
  760. $game_message.position = options[:position] if options[:position]
  761. end
  762. Input.release
  763. wait_for_message
  764. Input.halt
  765. end
  766. #--------------------------------------------------------------------------
  767. # * new method: generic method to wait for message proessing
  768. #--------------------------------------------------------------------------
  769. def update_for_wait
  770. update_basic
  771. end
  772.  
  773. #--------------------------------------------------------------------------
  774. # * new method, disposes message window
  775. #--------------------------------------------------------------------------
  776. alias cdr_guide_dispose_all_windows dispose_all_windows
  777. def dispose_all_windows
  778. cdr_guide_dispose_all_windows
  779. @message_window.dispose
  780. end
  781. end
  782.  
  783. class Scene_Battle < Scene_Base
  784. alias cdr_guide_process_message process_message
  785. def process_message(command)
  786. if GuideManager.battle_guide?
  787. wait = 10
  788. wait = command[2][:wait] if command[2] and command[2][:wait]
  789. @log_window.add_text(command[1])
  790. wait.times do @log_window.wait end
  791. @log_window.back_one
  792. else
  793. cdr_guide_process_message(command)
  794. end
  795. end
  796. #--------------------------------------------------------------------------
  797. # * new method: returns true if a guide update must be skipped
  798. #--------------------------------------------------------------------------
  799. alias cdr_guide_battle_skip_guide_update? skip_guide_update?
  800. def skip_guide_update?
  801. return true if cdr_guide_battle_skip_guide_update?
  802. return false if @item_window.active
  803. return false if @skill_window.active
  804. return false if @party_command_window.active
  805. return false if @actor_command_window.active
  806. return false if @status_window.active
  807. return false if @enemy_window.active
  808. return true
  809. end
  810. end
  811.  
  812. class Window_Selectable < Window_Base
  813. #--------------------------------------------------------------------------
  814. # * alias: can only process handlers when not locked
  815. #--------------------------------------------------------------------------
  816. alias cdr_guide_process_handling process_handling
  817. def process_handling
  818. wm = self.is_a?(Window_Message)
  819. return if (!wm and $game_message.busy? and GuideManager.running?)
  820. cdr_guide_process_handling
  821. end
  822. #--------------------------------------------------------------------------
  823. # * alias: can only process cursor moves when not locked
  824. #--------------------------------------------------------------------------
  825. alias cdr_guide_process_cursor_move process_cursor_move
  826. def process_cursor_move
  827. wm = self.is_a?(Window_Message)
  828. return if (!wm and $game_message.busy? and GuideManager.running?)
  829. cdr_guide_process_cursor_move
  830. end
  831. end
  832.  
  833. #==============================================================================
  834. # ** Scene_Guide
  835. #==============================================================================
  836. class Scene_Guide < Scene_Base
  837. #--------------------------------------------------------------------------
  838. # * Start Processing
  839. #--------------------------------------------------------------------------
  840. def start
  841. super
  842. create_help_window
  843. create_guide_window
  844. create_background
  845. @guide_window.set_handler(:ok, method(:on_guide_ok))
  846. @guide_window.set_handler(:cancel, method(:return_scene))
  847. end
  848.  
  849. #--------------------------------------------------------------------------
  850. # * Termination Processing
  851. #--------------------------------------------------------------------------
  852. def terminate
  853. super
  854. dispose_background
  855. end
  856. #--------------------------------------------------------------------------
  857. # * Create Background
  858. #--------------------------------------------------------------------------
  859. def create_background
  860. @background_sprite = Sprite.new
  861. @background_sprite.bitmap = SceneManager.background_bitmap
  862. @background_sprite.color.set(16, 16, 16, 128)
  863. end
  864. #--------------------------------------------------------------------------
  865. # * Free Background
  866. #--------------------------------------------------------------------------
  867. def dispose_background
  868. @background_sprite.dispose
  869. end
  870.  
  871. def update
  872. super
  873. @guide_window.refresh
  874. end
  875. #--------------------------------------------------------------------------
  876. # * Aquisição do texto da janela de ajuda
  877. #--------------------------------------------------------------------------
  878. def help_window_text
  879. return CDR_GUIDE::HELP_WINDOW_TEXT
  880. end
  881.  
  882. #--------------------------------------------------------------------------
  883. # * new method: creates each guide window
  884. #--------------------------------------------------------------------------
  885. def create_guide_window
  886. width = Graphics.width
  887. height = Graphics.height - @help_window.height
  888. @guide_window = Window_GuideList.new(0, @help_window.height, width, height)
  889. @guide_window.viewport = @viewport
  890. end
  891.  
  892. #--------------------------------------------------------------------------
  893. # * new method: call selected guide
  894. #--------------------------------------------------------------------------
  895. def on_guide_ok
  896. $game_switches[@guide_window.item] = true
  897. guide = CDR_GUIDE::GUIDE_DATA[@guide_window.item]
  898. Sound.play_ok
  899. if guide[:scene] == Scene_Battle
  900. call_battle_guide(guide[:troop])
  901. elsif guide[:scene] == Scene_Shop
  902. call_shop_guide(guide[:goods], guide[:sell])
  903. else
  904. GuideManager.save_bgm_and_bgs
  905. Sound.play_guide_bgm
  906. SceneManager.call(guide[:scene])
  907. end
  908. end
  909. #--------------------------------------------------------------------------
  910. # * new method: call a battle guide
  911. #--------------------------------------------------------------------------
  912. def call_battle_guide(troop_id)
  913. if $data_troops[troop_id]
  914. GuideManager.save_bgm_and_bgs
  915. BattleManager.setup(troop_id, false, true)
  916. Sound.play_battle_guide_bgm
  917. Sound.play_battle_start
  918. SceneManager.call(Scene_Battle)
  919. end
  920. end
  921. #--------------------------------------------------------------------------
  922. # * rewrite: call a shop guide
  923. #--------------------------------------------------------------------------
  924. def call_shop_guide(goods_data, sell)
  925. goods = []
  926. types = [:item, :weapon, :armor]
  927. for type in 0..2
  928. if goods_data[types[type]]
  929. goods_data[types[type]].each{|id|
  930. goods.push([type, id, 0])
  931. }
  932. end
  933. end
  934. GuideManager.save_bgm_and_bgs
  935. Sound.play_shop_guide_bgm
  936. SceneManager.call(Scene_Shop)
  937. SceneManager.scene.prepare(goods, !sell)
  938. end
  939. #--------------------------------------------------------------------------
  940. # * Create Help Window
  941. #--------------------------------------------------------------------------
  942. def create_help_window
  943. @help_window = Window_Help.new(1)
  944. @help_window.set_text(help_window_text)
  945. @help_window.viewport = @viewport
  946. end
  947. end
  948.  
  949. #==============================================================================
  950. # ** Window_GuideList
  951. #==============================================================================
  952. class Window_GuideList < Window_Selectable
  953. def initialize(x, y, width, height)
  954. super(x, y, width, height)
  955. make_item_list
  956. refresh
  957. @index = 0
  958. self.activate
  959. end
  960. #--------------------------------------------------------------------------
  961. # * Create Item List
  962. #--------------------------------------------------------------------------
  963. def make_item_list
  964. @data = GuideManager.guide_list
  965. end
  966. #--------------------------------------------------------------------------
  967. # * Draw Item
  968. #--------------------------------------------------------------------------
  969. def draw_item(index)
  970. rect = item_rect(index)
  971. draw_icon(CDR_GUIDE::GUIDE_FILE_ICON, 4, rect.y, enabled = true)
  972. change_color(normal_color)
  973. draw_guide_name(index, rect.x+28, rect.y)
  974. contents.font.bold = true
  975. change_color(text_color(CDR_GUIDE::NEW_COLOR))
  976. draw_new_flag(index, rect.x+text_size(guide(index)[:name]).width+24, rect.y)
  977. contents.font.bold = false
  978. change_color(normal_color)
  979. end
  980. #--------------------------------------------------------------------------
  981. # * new method: draw_guide_name
  982. #--------------------------------------------------------------------------
  983. def draw_guide_name(index, x, y)
  984. name = guide(index)[:name]
  985. draw_text(x, y, Graphics.width - 120, line_height, name)
  986. end
  987. #--------------------------------------------------------------------------
  988. # * new method: draw_new_flag
  989. #--------------------------------------------------------------------------
  990. def draw_new_flag(index, x, y)
  991. return if GuideManager.read?(@data[index])
  992. text = CDR_GUIDE::NEW_STRING
  993. draw_text(x, y, 128, line_height, text)
  994. end
  995. #--------------------------------------------------------------------------
  996. # * method rewrite: returns the max number of guides on the list
  997. #--------------------------------------------------------------------------
  998. def item_max
  999. GuideManager.guide_list.size
  1000. end
  1001. #--------------------------------------------------------------------------
  1002. # * new method: returns the guide corresponding to the key
  1003. #--------------------------------------------------------------------------
  1004. def guide(index)
  1005. CDR_GUIDE::GUIDE_DATA[@data[index]]
  1006. end
  1007. #--------------------------------------------------------------------------
  1008. # * method rewrite: returns the selected guide key
  1009. #--------------------------------------------------------------------------
  1010. def item
  1011. @data[@index]
  1012. end
  1013. end
  1014.  
  1015. #==============================================================================
  1016. # ** Scene_Menu
  1017. #==============================================================================
  1018. class Scene_Menu < Scene_MenuBase
  1019. #--------------------------------------------------------------------------
  1020. # * alias: adds a guide list accessor to the main menu
  1021. #--------------------------------------------------------------------------
  1022. alias cdr_guide_create_command_window create_command_window
  1023. def create_command_window
  1024. cdr_guide_create_command_window
  1025. if CDR_GUIDE::ADD_MENU_ITEM
  1026. @command_window.set_handler(:guide_list, method(:command_guide_list))
  1027. end
  1028. end
  1029.  
  1030. #--------------------------------------------------------------------------
  1031. # * new method: calls the guide list scene
  1032. #--------------------------------------------------------------------------
  1033. def command_guide_list
  1034. SceneManager.call(Scene_Guide)
  1035. end
  1036. end
  1037. #==============================================================================
  1038. # ** Window_MenuCommand
  1039. #==============================================================================
  1040. class Window_MenuCommand < Window_Command
  1041. #--------------------------------------------------------------------------
  1042. # * alias
  1043. #--------------------------------------------------------------------------
  1044. alias cdr_guide_select_last select_last
  1045. def select_last
  1046. if GuideManager.running?
  1047. select_symbol(nil)
  1048. return
  1049. end
  1050. cdr_guide_select_last
  1051. end
  1052.  
  1053. #--------------------------------------------------------------------------
  1054. # * alias: to add guide command menu item
  1055. #--------------------------------------------------------------------------
  1056. alias cdr_guide_add_original_commands add_original_commands
  1057. def add_original_commands
  1058. cdr_guide_add_original_commands
  1059. add_guide_list_command if CDR_GUIDE::ADD_MENU_ITEM
  1060. end
  1061. #--------------------------------------------------------------------------
  1062. # * new method: to add guide command menu item
  1063. #--------------------------------------------------------------------------
  1064. def add_guide_list_command
  1065. add_command(CDR_GUIDE::MENU_ITEM_NAME, :guide_list, has_guides?)
  1066. end
  1067.  
  1068. #--------------------------------------------------------------------------
  1069. # * new method: returns true if there is any guides on the list
  1070. #--------------------------------------------------------------------------
  1071. def has_guides?
  1072. !GuideManager.guide_list.empty?
  1073. end
  1074. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement