polectron

Untitled

Dec 28th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.41 KB | None | 0 0
  1. class Game_Temp
  2. attr_writer :message_window_showing
  3. attr_writer :player_transferring
  4. attr_writer :transition_processing
  5.  
  6. def message_window_showing
  7. @message_window_showing=false if !@message_window_showing
  8. return @message_window_showing
  9. end
  10.  
  11. def player_transferring
  12. @player_transferring=false if !@player_transferring
  13. return @player_transferring
  14. end
  15.  
  16. def transition_processing
  17. @transition_processing=false if !@transition_processing
  18. return @transition_processing
  19. end
  20. end
  21.  
  22.  
  23.  
  24. class Game_Message
  25. attr_writer :background, :visible
  26. def visible; return @visible ? @visible : false; end
  27. def background; return @background ? @background : 0; end
  28. end
  29.  
  30.  
  31.  
  32. class Game_System
  33. attr_writer :message_position
  34.  
  35. def message_position
  36. @message_position=2 if !@message_position
  37. return @message_position
  38. end
  39. end
  40.  
  41.  
  42.  
  43. #########
  44.  
  45. class Scene_Map
  46. def updatemini
  47. oldmws=$game_temp.message_window_showing
  48. oldvis=$game_message ? $game_message.visible : false
  49. $game_temp.message_window_showing=true
  50. $game_message.visible=true if $game_message
  51. loop do
  52. $game_map.update
  53. $game_player.update
  54. $game_system.update
  55. if $game_screen
  56. $game_screen.update
  57. else
  58. $game_map.screen.update
  59. end
  60. unless $game_temp.player_transferring
  61. break
  62. end
  63. transfer_player
  64. if $game_temp.transition_processing
  65. break
  66. end
  67. end
  68. $game_temp.message_window_showing=oldmws
  69. $game_message.visible=oldvis if $game_message
  70. @spriteset.update if @spriteset
  71. @message_window.update if @message_window
  72. end
  73. end
  74.  
  75.  
  76.  
  77. class Scene_Battle
  78. def updatemini
  79. if self.respond_to?("update_basic")
  80. update_basic(true)
  81. update_info_viewport # Update information viewport
  82. if $game_message && $game_message.visible
  83. @info_viewport.visible = false
  84. @message_window.visible = true
  85. end
  86. else
  87. oldmws=$game_temp.message_window_showing
  88. $game_temp.message_window_showing=true
  89. # Update system (timer) and screen
  90. $game_system.update
  91. if $game_screen
  92. $game_screen.update
  93. else
  94. $game_map.screen.update
  95. end
  96. # If timer has reached 0
  97. if $game_system.timer_working and $game_system.timer == 0
  98. # Abort battle
  99. $game_temp.battle_abort = true
  100. end
  101. # Update windows
  102. @help_window.update if @help_window
  103. @party_command_window.update if @party_command_window
  104. @actor_command_window.update if @actor_command_window
  105. @status_window.update if @status_window
  106. $game_temp.message_window_showing=oldmws
  107. @message_window.update if @message_window
  108. # Update sprite set
  109. @spriteset.update if @spriteset
  110. end
  111. end
  112. end
  113.  
  114.  
  115.  
  116. def pbMapInterpreterRunning?
  117. interp=pbMapInterpreter
  118. return interp && interp.running?
  119. end
  120.  
  121. def pbMapInterpreter
  122. if $game_map && $game_map.respond_to?("interpreter")
  123. return $game_map.interpreter
  124. elsif $game_system
  125. return $game_system.map_interpreter
  126. end
  127. return nil
  128. end
  129.  
  130. def pbRefreshSceneMap
  131. if $scene && $scene.is_a?(Scene_Map)
  132. if $scene.respond_to?("miniupdate")
  133. $scene.miniupdate
  134. else
  135. $scene.updatemini
  136. end
  137. elsif $scene && $scene.is_a?(Scene_Battle)
  138. $scene.updatemini
  139. end
  140. end
  141.  
  142. def pbUpdateSceneMap
  143. if $scene && $scene.is_a?(Scene_Map) && !pbIsFaded?
  144. if $scene.respond_to?("miniupdate")
  145. $scene.miniupdate
  146. else
  147. $scene.updatemini
  148. end
  149. elsif $scene && $scene.is_a?(Scene_Battle)
  150. $scene.updatemini
  151. end
  152. end
  153. #########
  154.  
  155. def pbCsvField!(str)
  156. ret=""
  157. str.sub!(/\A\s*/,"")
  158. if str[0,1]=="\""
  159. str[0,1]=""
  160. escaped=false
  161. fieldbytes=0
  162. str.scan(/./) do |s|
  163. fieldbytes+=s.length
  164. break if s=="\"" && !escaped
  165. if s=="\\" && !escaped
  166. escaped=true
  167. else
  168. ret+=s
  169. escaped=false
  170. end
  171. end
  172. str[0,fieldbytes]=""
  173. if !str[/\A\s*,/] && !str[/\A\s*$/]
  174. raise _INTL("Invalid quoted field (in: {1})",ret)
  175. end
  176. str[0,str.length]=$~.post_match
  177. else
  178. if str[/,/]
  179. str[0,str.length]=$~.post_match
  180. ret=$~.pre_match
  181. else
  182. ret=str.clone
  183. str[0,str.length]=""
  184. end
  185. ret.gsub!(/\s+$/,"")
  186. end
  187. return ret
  188. end
  189.  
  190. def pbCsvPosInt!(str)
  191. ret=pbCsvField!(str)
  192. if !ret[/\A\d+$/]
  193. raise _INTL("Field {1} is not a positive integer",ret)
  194. end
  195. return ret.to_i
  196. end
  197.  
  198. def pbEventCommentInput(*args)
  199. parameters = []
  200. list = *args[0].list # Event or event page
  201. elements = *args[1] # Number of elements
  202. trigger = *args[2] # Trigger
  203. return nil if list == nil
  204. return nil unless list.is_a?(Array)
  205. for item in list
  206. next unless item.code == 108 || item.code == 408
  207. if item.parameters[0] == trigger
  208. start = list.index(item) + 1
  209. finish = start + elements
  210. for id in start...finish
  211. next if !list[id]
  212. parameters.push(list[id].parameters[0])
  213. end
  214. return parameters
  215. end
  216. end
  217. return nil
  218. end
  219.  
  220. def pbCurrentEventCommentInput(elements,trigger)
  221. return nil if !pbMapInterpreterRunning?
  222. event=pbMapInterpreter.get_character(0)
  223. return nil if !event
  224. return pbEventCommentInput(event,elements,trigger)
  225. end
  226.  
  227.  
  228.  
  229. module InterpreterMixin
  230. def pbGlobalLock # Freezes all events on the map (for use at the beginning of common events)
  231. for event in $game_map.events.values
  232. event.minilock
  233. end
  234. end
  235.  
  236. def pbGlobalUnlock # Unfreezes all events on the map (for use at the end of common events)
  237. for event in $game_map.events.values
  238. event.unlock
  239. end
  240. end
  241.  
  242. def pbRepeatAbove(index)
  243. index=@list[index].indent
  244. loop do
  245. index-=1
  246. if @list[index].indent==indent
  247. return index+1
  248. end
  249. end
  250. end
  251.  
  252. def pbBreakLoop(index)
  253. indent = @list[index].indent
  254. temp_index=index
  255. # Copy index to temporary variables
  256. loop do
  257. # Advance index
  258. temp_index += 1
  259. # If a fitting loop was not found
  260. if temp_index >= @list.size-1
  261. return index+1
  262. end
  263. if @list[temp_index].code == 413 and @list[temp_index].indent < indent
  264. return temp_index+1
  265. end
  266. end
  267. end
  268.  
  269. def pbJumpToLabel(index,label_name)
  270. temp_index = 0
  271. loop do
  272. if temp_index >= @list.size-1
  273. return index+1
  274. end
  275. if @list[temp_index].code == 118 and
  276. @list[temp_index].parameters[0] == label_name
  277. return temp_index+1
  278. end
  279. temp_index += 1
  280. end
  281. end
  282.  
  283. # Gets the next index in the interpreter, ignoring
  284. # certain events between messages
  285. def pbNextIndex(index)
  286. return -1 if !@list || @list.length==0
  287. i=index+1
  288. loop do
  289. return i
  290. end
  291. code=@list[i].code
  292. case code
  293. when 118, 108, 408 # Label, Comment
  294. i+=1
  295. when 413 # Repeat Above
  296. i=pbRepeatAbove(i)
  297. when 113 # Break Loop
  298. i=pbBreakLoop(i)
  299. when 119 # Jump to Label
  300. newI=pbJumpToLabel(i,@list[i].parameters[0])
  301. if newI>i
  302. i=newI
  303. else
  304. i+=1
  305. end
  306. else
  307. return i
  308. end
  309. end
  310. end
  311.  
  312. # Helper function that shows a picture in a script. To be used in
  313. # a script event command.
  314. def pbShowPicture(number,name,origin,x,y,zoomX=100,zoomY=100,opacity=255,blendType=0)
  315. number = number + ($game_temp.in_battle ? 50 : 0)
  316. $game_screen.pictures[number].show(name,origin,
  317. x, y, zoomX,zoomY,opacity,blendType)
  318. end
  319.  
  320. # Erases an event and adds it to the list of erased events so that
  321. # it can stay erased when the game is saved then loaded again. To be used in
  322. # a script event command.
  323. def pbEraseThisEvent
  324. if $game_map.events[@event_id]
  325. $game_map.events[@event_id].erase
  326. $PokemonMap.addErasedEvent(@event_id) if $PokemonMap
  327. end
  328. @index+=1
  329. return true
  330. end
  331.  
  332. # Runs a common event. To be used in a script event command.
  333. def pbCommonEvent(id)
  334. if $game_temp.in_battle
  335. $game_temp.common_event_id = id
  336. else
  337. commonEvent = $data_common_events[id]
  338. $game_system.battle_interpreter.setup(commonEvent.list, 0)
  339. end
  340. end
  341.  
  342. # Sets another event's self switch (eg. pbSetSelfSwitch(20,"A",true) ).
  343. # To be used in a script event command.
  344. def pbSetSelfSwitch(event,swtch,value)
  345. $game_self_switches[[@map_id,event,swtch]]=value
  346. $game_map.need_refresh = true
  347. end
  348.  
  349. # Must use this approach to share the methods because the methods already
  350. # defined in a class override those defined in an included module
  351. CustomEventCommands=<<_END_
  352.  
  353. def command_242
  354. pbBGMFade(pbParams[0])
  355. return true
  356. end
  357.  
  358. def command_246
  359. pbBGSFade(pbParams[0])
  360. return true
  361. end
  362.  
  363. def command_251
  364. pbSEStop()
  365. return true
  366. end
  367.  
  368. def command_241
  369. pbBGMPlay(pbParams[0])
  370. return true
  371. end
  372.  
  373. def command_245
  374. pbBGSPlay(pbParams[0])
  375. return true
  376. end
  377.  
  378. def command_249
  379. pbMEPlay(pbParams[0])
  380. return true
  381. end
  382.  
  383. def command_250
  384. pbSEPlay(pbParams[0])
  385. return true
  386. end
  387. _END_
  388. end
  389.  
  390.  
  391.  
  392. def pbButtonInputProcessing(variableNumber=0,timeoutFrames=0)
  393. ret=0
  394. loop do
  395. Graphics.update
  396. Input.update
  397. pbUpdateSceneMap
  398. for i in 1..18
  399. if Input.trigger?(i)
  400. ret=i
  401. end
  402. end
  403. break if ret!=0
  404. if timeoutFrames && timeoutFrames>0
  405. i+=1
  406. break if i>=timeoutFrames
  407. end
  408. end
  409. Input.update
  410. if variableNumber && variableNumber>0
  411. $game_variables[variableNumber]=ret
  412. $game_map.need_refresh = true if $game_map
  413. end
  414. return ret
  415. end
  416.  
  417.  
  418.  
  419. class Game_Temp
  420. attr_accessor :background
  421. end
  422.  
  423.  
  424.  
  425. class Game_Interpreter # Used by RMVX
  426. include InterpreterMixin
  427. eval(InterpreterMixin::CustomEventCommands)
  428. @@immediateDisplayAfterWait=false
  429. @buttonInput=false
  430.  
  431. def pbParams
  432. return @params
  433. end
  434.  
  435. def command_105
  436. return false if @buttonInput
  437. @buttonInput=true
  438. pbButtonInputProcessing(@list[@index].parameters[0])
  439. @buttonInput=false
  440. @index+=1
  441. return true
  442. end
  443.  
  444. def command_101
  445. if $game_temp.message_window_showing
  446. return false
  447. end
  448. $game_message=Game_Message.new if !$game_message
  449. message=""
  450. commands=nil
  451. numInputVar=nil
  452. numInputDigitsMax=nil
  453. text=""
  454. facename=@list[@index].parameters[0]
  455. faceindex=@list[@index].parameters[1]
  456. if facename && facename!=""
  457. text+="\\ff[#{facename},#{faceindex}]"
  458. end
  459. if $game_message
  460. $game_message.background=@list[@index].parameters[2]
  461. end
  462. $game_system.message_position=@list[@index].parameters[3]
  463. message+=text
  464. messageend=""
  465. loop do
  466. nextIndex=pbNextIndex(@index)
  467. code=@list[nextIndex].code
  468. if code == 401
  469. text=@list[nextIndex].parameters[0]
  470. text+=" " if text!="" && text[text.length-1,1]!=" "
  471. message+=text
  472. @index=nextIndex
  473. else
  474. if code == 102
  475. commands=@list[nextIndex].parameters
  476. @index=nextIndex
  477. elsif code == 106 && @@immediateDisplayAfterWait
  478. params=@list[nextIndex].parameters
  479. if params[0]<=10
  480. nextcode=@list[nextIndex+1].code
  481. if nextcode==101||nextcode==102||nextcode==103
  482. @index=nextIndex
  483. else
  484. break
  485. end
  486. else
  487. break
  488. end
  489. elsif code == 103
  490. numInputVar=@list[nextIndex].parameters[0]
  491. numInputDigitsMax=@list[nextIndex].parameters[1]
  492. @index=nextIndex
  493. elsif code == 101
  494. messageend="\1"
  495. end
  496. break
  497. end
  498. end
  499. message=_MAPINTL($game_map.map_id,message)
  500. @message_waiting=true
  501. if commands
  502. cmdlist=[]
  503. for cmd in commands[0]
  504. cmdlist.push(_MAPINTL($game_map.map_id,cmd))
  505. end
  506. command=Kernel.pbMessage(message+messageend,cmdlist,commands[1])
  507. @branch[@list[@index].indent] = command
  508. elsif numInputVar
  509. params=ChooseNumberParams.new
  510. params.setMaxDigits(numInputDigitsMax)
  511. params.setDefaultValue($game_variables[numInputVar])
  512. $game_variables[numInputVar]=Kernel.pbMessageChooseNumber(message+messageend,params)
  513. $game_map.need_refresh = true if $game_map
  514. else
  515. Kernel.pbMessage(message+messageend)
  516. end
  517. @message_waiting=false
  518. return true
  519. end
  520.  
  521. def command_102
  522. @message_waiting=true
  523. command=Kernel.pbShowCommands(nil,@list[@index].parameters[0],@list[@index].parameters[1])
  524. @message_waiting=false
  525. @branch[@list[@index].indent] = command
  526. Input.update # Must call Input.update again to avoid extra triggers
  527. return true
  528. end
  529.  
  530. def command_103
  531. varnumber=@list[@index].parameters[0]
  532. @message_waiting=true
  533. params=ChooseNumberParams.new
  534. params.setMaxDigits(@list[@index].parameters[1])
  535. params.setDefaultValue($game_variables[varnumber])
  536. $game_variables[varnumber]=Kernel.pbChooseNumber(nil,params)
  537. $game_map.need_refresh = true if $game_map
  538. @message_waiting=false
  539. return true
  540. end
  541. end
  542.  
  543.  
  544.  
  545. class Interpreter # Used by RMXP
  546. include InterpreterMixin
  547. eval(InterpreterMixin::CustomEventCommands)
  548. @@immediateDisplayAfterWait=false
  549. @buttonInput=false
  550.  
  551. def pbParams
  552. return @parameters
  553. end
  554.  
  555. def command_105
  556. return false if @buttonInput
  557. @buttonInput=true
  558. pbButtonInputProcessing(@list[@index].parameters[0])
  559. @buttonInput=false
  560. @index+=1
  561. return true
  562. end
  563.  
  564. def command_101
  565. if $game_temp.message_window_showing
  566. return false
  567. end
  568. message=""
  569. commands=nil
  570. numInputVar=nil
  571. numInputDigitsMax=nil
  572. text=""
  573. firstText=nil
  574. if @list[@index].parameters.length==1
  575. text+=@list[@index].parameters[0]
  576. firstText=@list[@index].parameters[0]
  577. text+=" " if text[text.length-1,1]!=" "
  578. message+=text
  579. else
  580. facename=@list[@index].parameters[0]
  581. faceindex=@list[@index].parameters[1]
  582. if facename && facename!=""
  583. text+="\\ff[#{facename},#{faceindex}]"
  584. message+=text
  585. end
  586. end
  587. messageend=""
  588. loop do
  589. nextIndex=pbNextIndex(@index)
  590. code=@list[nextIndex].code
  591. if code == 401
  592. text=@list[nextIndex].parameters[0]
  593. text+=" " if text[text.length-1,1]!=" "
  594. message+=text
  595. @index=nextIndex
  596. else
  597. if code == 102
  598. commands=@list[nextIndex].parameters
  599. @index=nextIndex
  600. elsif code == 106 && @@immediateDisplayAfterWait
  601. params=@list[nextIndex].parameters
  602. if params[0]<=10
  603. nextcode=@list[nextIndex+1].code
  604. if nextcode==101||nextcode==102||nextcode==103
  605. @index=nextIndex
  606. else
  607. break
  608. end
  609. else
  610. break
  611. end
  612. elsif code == 103
  613. numInputVar=@list[nextIndex].parameters[0]
  614. numInputDigitsMax=@list[nextIndex].parameters[1]
  615. @index=nextIndex
  616. elsif code == 101
  617. if @list[@index].parameters.length==1
  618. text=@list[@index].parameters[0]
  619. if text[/\A\\ignr/] && text==firstText
  620. text+=" " if text[text.length-1,1]!=" "
  621. message+=text
  622. @index=nextIndex
  623. continue
  624. end
  625. end
  626. messageend="\1"
  627. end
  628. break
  629. end
  630. end
  631. @message_waiting=true # needed to allow parallel process events to work while
  632. # a message is displayed
  633. message=_MAPINTL($game_map.map_id,message)
  634. if commands
  635. cmdlist=[]
  636. for cmd in commands[0]
  637. cmdlist.push(_MAPINTL($game_map.map_id,cmd))
  638. end
  639. command=Kernel.pbMessage(message+messageend,cmdlist,commands[1])
  640. @branch[@list[@index].indent] = command
  641. elsif numInputVar
  642. params=ChooseNumberParams.new
  643. params.setMaxDigits(numInputDigitsMax)
  644. params.setDefaultValue($game_variables[numInputVar])
  645. $game_variables[numInputVar]=Kernel.pbMessageChooseNumber(message+messageend,params)
  646. $game_map.need_refresh = true if $game_map
  647. else
  648. Kernel.pbMessage(message+messageend,nil)
  649. end
  650. @message_waiting=false
  651. return true
  652. end
  653.  
  654. def command_102
  655. @message_waiting=true
  656. command=Kernel.pbShowCommands(nil,@list[@index].parameters[0],@list[@index].parameters[1])
  657. @message_waiting=false
  658. @branch[@list[@index].indent] = command
  659. Input.update # Must call Input.update again to avoid extra triggers
  660. return true
  661. end
  662.  
  663. def command_103
  664. varnumber=@list[@index].parameters[0]
  665. @message_waiting=true
  666. params=ChooseNumberParams.new
  667. params.setMaxDigits(@list[@index].parameters[1])
  668. params.setDefaultValue($game_variables[varnumber])
  669. $game_variables[varnumber]=Kernel.pbChooseNumber(nil,params)
  670. $game_map.need_refresh = true if $game_map
  671. @message_waiting=false
  672. return true
  673. end
  674. end
  675.  
  676.  
  677.  
  678. class ChooseNumberParams
  679. def initialize
  680. @maxDigits=0
  681. @minNumber=0
  682. @maxNumber=0
  683. @skin=nil
  684. @messageSkin=nil
  685. @negativesAllowed=false
  686. @initialNumber=0
  687. @cancelNumber=nil
  688. end
  689.  
  690. def setMessageSkin(value)
  691. @messageSkin=value
  692. end
  693.  
  694. def messageSkin # Set the full path for the message's window skin
  695. @messageSkin
  696. end
  697.  
  698. def setSkin(value)
  699. @skin=value
  700. end
  701.  
  702. def skin
  703. @skin
  704. end
  705.  
  706. def setNegativesAllowed(value)
  707. @negativeAllowed=value
  708. end
  709.  
  710. def negativesAllowed
  711. @negativeAllowed ? true : false
  712. end
  713.  
  714. def setRange(minNumber,maxNumber)
  715. maxNumber=minNumber if minNumber>maxNumber
  716. @maxDigits=0
  717. @minNumber=minNumber
  718. @maxNumber=maxNumber
  719. end
  720.  
  721. def setDefaultValue(number)
  722. @initialNumber=number
  723. @cancelNumber=nil
  724. end
  725.  
  726. def setInitialValue(number)
  727. @initialNumber=number
  728. end
  729.  
  730. def setCancelValue(number)
  731. @cancelNumber=number
  732. end
  733.  
  734. def initialNumber
  735. return clamp(@initialNumber,self.minNumber,self.maxNumber)
  736. end
  737.  
  738. def cancelNumber
  739. return @cancelNumber ? @cancelNumber : self.initialNumber
  740. end
  741.  
  742. def minNumber
  743. ret=0
  744. if @maxDigits>0
  745. ret=-((10**@maxDigits)-1)
  746. elsif
  747. ret=@minNumber
  748. end
  749. ret=0 if !@negativeAllowed && ret<0
  750. return ret
  751. end
  752.  
  753. def maxNumber
  754. ret=0
  755. if @maxDigits>0
  756. ret=((10**@maxDigits)-1)
  757. elsif
  758. ret=@maxNumber
  759. end
  760. ret=0 if !@negativeAllowed && ret<0
  761. return ret
  762. end
  763.  
  764. def setMaxDigits(value)
  765. @maxDigits=[1,value].max
  766. end
  767.  
  768. def maxDigits
  769. if @maxDigits>0
  770. return @maxDigits
  771. else
  772. return [numDigits(self.minNumber),numDigits(self.maxNumber)].max
  773. end
  774. end
  775.  
  776. private
  777.  
  778. def clamp(v,mn,mx)
  779. return v<mn ? mn : (v>mx ? mx : v)
  780. end
  781.  
  782. def numDigits(number)
  783. ans = 1
  784. number=number.abs
  785. while number >= 10
  786. ans+=1
  787. number/=10
  788. end
  789. return ans
  790. end
  791. end
  792.  
  793.  
  794.  
  795. def pbChooseNumber(msgwindow,params)
  796. return 0 if !params
  797. ret=0
  798. maximum=params.maxNumber
  799. minimum=params.minNumber
  800. defaultNumber=params.initialNumber
  801. cancelNumber=params.cancelNumber
  802. cmdwindow=Window_InputNumberPokemon.new(params.maxDigits)
  803. cmdwindow.z=99999
  804. cmdwindow.visible=true
  805. cmdwindow.setSkin(params.skin) if params.skin
  806. cmdwindow.sign=params.negativesAllowed # must be set before number
  807. cmdwindow.number=defaultNumber
  808. curnumber=defaultNumber
  809. pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  810. command=0
  811. loop do
  812. Graphics.update
  813. Input.update
  814. pbUpdateSceneMap
  815. cmdwindow.update
  816. msgwindow.update if msgwindow
  817. yield if block_given?
  818. if Input.trigger?(Input::C)
  819. ret=cmdwindow.number
  820. if ret>maximum
  821. pbPlayBuzzerSE()
  822. elsif ret<minimum
  823. pbPlayBuzzerSE()
  824. else
  825. pbPlayDecisionSE()
  826. break
  827. end
  828. elsif Input.trigger?(Input::B)
  829. pbPlayCancelSE()
  830. ret=cancelNumber
  831. break
  832. end
  833. end
  834. cmdwindow.dispose
  835. Input.update
  836. return ret
  837. end
  838.  
  839. def Kernel.pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0)
  840. msgwin=msgwindow
  841. if !msgwindow
  842. msgwin=Kernel.pbCreateMessageWindow(nil)
  843. end
  844. oldlbl=msgwin.letterbyletter
  845. msgwin.letterbyletter=false
  846. if commands
  847. cmdwindow=Window_CommandPokemonEx.new(commands)
  848. cmdwindow.z=99999
  849. cmdwindow.visible=true
  850. cmdwindow.resizeToFit(cmdwindow.commands)
  851. cmdwindow.height=msgwin.y if cmdwindow.height>msgwin.y
  852. cmdwindow.index=defaultCmd
  853. command=0
  854. msgwin.text=help[cmdwindow.index]
  855. msgwin.width=msgwin.width # Necessary evil to make it use the proper margins.
  856. loop do
  857. Graphics.update
  858. Input.update
  859. oldindex=cmdwindow.index
  860. cmdwindow.update
  861. if oldindex!=cmdwindow.index
  862. msgwin.text=help[cmdwindow.index]
  863. end
  864. msgwin.update
  865. yield if block_given?
  866. if Input.trigger?(Input::B)
  867. if cmdIfCancel>0
  868. command=cmdIfCancel-1
  869. break
  870. elsif cmdIfCancel<0
  871. command=cmdIfCancel
  872. break
  873. end
  874. end
  875. if Input.trigger?(Input::C)
  876. command=cmdwindow.index
  877. break
  878. end
  879. pbUpdateSceneMap
  880. end
  881. ret=command
  882. cmdwindow.dispose
  883. Input.update
  884. end
  885. msgwin.letterbyletter=oldlbl
  886. if !msgwindow
  887. msgwin.dispose
  888. end
  889. return ret
  890. end
  891.  
  892. def Kernel.pbShowCommands(msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
  893. ret=0
  894. if commands
  895. cmdwindow=Window_CommandPokemonEx.new(commands)
  896. cmdwindow.z=99999
  897. cmdwindow.visible=true
  898. cmdwindow.resizeToFit(cmdwindow.commands)
  899. pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  900. cmdwindow.index=defaultCmd
  901. command=0
  902. loop do
  903. Graphics.update
  904. Input.update
  905. cmdwindow.update
  906. msgwindow.update if msgwindow
  907. yield if block_given?
  908. if Input.trigger?(Input::B)
  909. if cmdIfCancel>0
  910. command=cmdIfCancel-1
  911. break
  912. elsif cmdIfCancel<0
  913. command=cmdIfCancel
  914. break
  915. end
  916. end
  917. if Input.trigger?(Input::C)
  918. command=cmdwindow.index
  919. break
  920. end
  921. pbUpdateSceneMap
  922. end
  923. ret=command
  924. cmdwindow.dispose
  925. Input.update
  926. end
  927. return ret
  928. end
  929.  
  930. def pbPositionFaceWindow(facewindow,msgwindow)
  931. return if !facewindow
  932. if msgwindow
  933. if facewindow.height<=msgwindow.height
  934. facewindow.y=msgwindow.y
  935. else
  936. facewindow.y=msgwindow.y+msgwindow.height-facewindow.height
  937. end
  938. facewindow.x=Graphics.width-facewindow.width
  939. msgwindow.x=0
  940. msgwindow.width=Graphics.width-facewindow.width
  941. else
  942. facewindow.height=Graphics.height if facewindow.height>Graphics.height
  943. facewindow.x=0
  944. facewindow.y=0
  945. end
  946. end
  947.  
  948. def pbPositionNearMsgWindow(cmdwindow,msgwindow,side)
  949. return if !cmdwindow
  950. if msgwindow
  951. height=[cmdwindow.height,Graphics.height-msgwindow.height].min
  952. if cmdwindow.height!=height
  953. cmdwindow.height=height
  954. end
  955. cmdwindow.y=msgwindow.y-cmdwindow.height
  956. if cmdwindow.y<0
  957. cmdwindow.y=msgwindow.y+msgwindow.height
  958. if cmdwindow.y+cmdwindow.height>Graphics.height
  959. cmdwindow.y=msgwindow.y-cmdwindow.height
  960. end
  961. end
  962. case side
  963. when :left
  964. cmdwindow.x=msgwindow.x
  965. when :right
  966. cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width
  967. else
  968. cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width
  969. end
  970. else
  971. cmdwindow.height=Graphics.height if cmdwindow.height>Graphics.height
  972. cmdwindow.x=0
  973. cmdwindow.y=0
  974. end
  975. end
  976.  
  977. def pbGetBasicMapNameFromId(id)
  978. begin
  979. map = pbLoadRxData("Data/MapInfos")
  980. return "" if !map
  981. return map[id].name
  982. rescue
  983. return ""
  984. end
  985. end
  986.  
  987. def pbGetMapNameFromId(id)
  988. map=pbGetBasicMapNameFromId(id)
  989. if $Trainer
  990. map.gsub!(/\\PN/,$Trainer.name)
  991. end
  992. return map
  993. end
  994.  
  995. def Kernel.pbMessage(message,commands=nil,cmdIfCancel=0,skin=nil,defaultCmd=0,&block)
  996. ret=0
  997. msgwindow=Kernel.pbCreateMessageWindow(nil,skin)
  998. if commands
  999. ret=Kernel.pbMessageDisplay(msgwindow,message,true,
  1000. proc {|msgwindow|
  1001. next Kernel.pbShowCommands(msgwindow,commands,cmdIfCancel,defaultCmd,&block)
  1002. },&block)
  1003. else
  1004. Kernel.pbMessageDisplay(msgwindow,message,&block)
  1005. end
  1006. Kernel.pbDisposeMessageWindow(msgwindow)
  1007. Input.update
  1008. return ret
  1009. end
  1010.  
  1011. def Kernel.pbMessageChooseNumber(message,params,&block)
  1012. msgwindow=Kernel.pbCreateMessageWindow(nil,params.messageSkin)
  1013. ret=Kernel.pbMessageDisplay(msgwindow,message,true,
  1014. proc {|msgwindow|
  1015. next Kernel.pbChooseNumber(msgwindow,params,&block)
  1016. },&block)
  1017. Kernel.pbDisposeMessageWindow(msgwindow)
  1018. return ret
  1019. end
  1020.  
  1021. def Kernel.pbConfirmMessage(message,&block)
  1022. return (Kernel.pbMessage(message,[_INTL("Yes"),_INTL("No")],2,&block)==0)
  1023. end
  1024.  
  1025. def Kernel.pbConfirmMessageSerious(message,&block)
  1026. return (Kernel.pbMessage(message,[_INTL("No"),_INTL("Yes")],1,&block)==1)
  1027. end
  1028.  
  1029. def Kernel.pbCreateStatusWindow(viewport=nil)
  1030. msgwindow=Window_AdvancedTextPokemon.new("")
  1031. if !viewport
  1032. msgwindow.z=99999
  1033. else
  1034. msgwindow.viewport=viewport
  1035. end
  1036. msgwindow.visible=false
  1037. msgwindow.letterbyletter=false
  1038. pbBottomLeftLines(msgwindow,2)
  1039. skinfile=MessageConfig.pbGetSpeechFrame()
  1040. msgwindow.setSkin(skinfile)
  1041. return msgwindow
  1042. end
  1043.  
  1044. def Kernel.pbCreateMessageWindow(viewport=nil,skin=nil)
  1045. msgwindow=Window_AdvancedTextPokemon.new("")
  1046. if !viewport
  1047. msgwindow.z=99999
  1048. else
  1049. msgwindow.viewport=viewport
  1050. end
  1051. msgwindow.visible=true
  1052. msgwindow.letterbyletter=true
  1053. msgwindow.back_opacity=MessageConfig::WindowOpacity
  1054. pbBottomLeftLines(msgwindow,2)
  1055. $game_temp.message_window_showing=true if $game_temp
  1056. $game_message.visible=true if $game_message
  1057. skin=MessageConfig.pbGetSpeechFrame() if !skin
  1058. msgwindow.setSkin(skin)
  1059. return msgwindow
  1060. end
  1061.  
  1062. def Kernel.pbDisposeMessageWindow(msgwindow)
  1063. $game_temp.message_window_showing=false if $game_temp
  1064. $game_message.visible=false if $game_message
  1065. msgwindow.dispose
  1066. end
  1067.  
  1068.  
  1069.  
  1070. class FaceWindowVX < SpriteWindow_Base
  1071. def initialize(face)
  1072. super(0,0,128,128)
  1073. faceinfo=face.split(",")
  1074. facefile=pbResolveBitmap("Graphics/Faces/"+faceinfo[0])
  1075. facefile=pbResolveBitmap("Graphics/Pictures/"+faceinfo[0]) if !facefile
  1076. self.contents.dispose if self.contents
  1077. @faceIndex=faceinfo[1].to_i
  1078. @facebitmaptmp=AnimatedBitmap.new(facefile)
  1079. @facebitmap=BitmapWrapper.new(96,96)
  1080. @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  1081. (@faceIndex % 4) * 96,
  1082. (@faceIndex / 4) * 96, 96, 96
  1083. ))
  1084. self.contents=@facebitmap
  1085. end
  1086.  
  1087. def update
  1088. super
  1089. if @facebitmaptmp.totalFrames>1
  1090. @facebitmaptmp.update
  1091. @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  1092. (@faceIndex % 4) * 96,
  1093. (@faceIndex / 4) * 96, 96, 96
  1094. ))
  1095. end
  1096. end
  1097.  
  1098. def dispose
  1099. @facebitmaptmp.dispose
  1100. @facebitmap.dispose if @facebitmap
  1101. super
  1102. end
  1103. end
  1104.  
  1105.  
  1106.  
  1107. def itemIconTag(item)
  1108. return "" if !item
  1109. if item.respond_to?("icon_name")
  1110. return sprintf("<icon=%s>",item.icon_name)
  1111. else
  1112. ix=item.icon_index % 16 * 24
  1113. iy=item.icon_index / 16 * 24
  1114. return sprintf("<img=Graphics/System/Iconset|%d|%d|24|24>",ix,iy)
  1115. end
  1116. end
  1117.  
  1118. def getSkinColor(windowskin,color,isDarkSkin)
  1119. if !windowskin || windowskin.disposed? ||
  1120. windowskin.width!=128 || windowskin.height!=128
  1121. textcolors=[
  1122. isDarkSkin ? shadowc3tag(MessageConfig::LIGHTTEXTBASE, MessageConfig::LIGHTTEXTSHADOW) :
  1123. shadowc3tag(MessageConfig::DARKTEXTBASE, MessageConfig::DARKTEXTSHADOW),
  1124. "<c2=7E105D08>", # Red
  1125. "<c2=421F2117>", # Blue
  1126. "<c2=43F022E8>", # Green
  1127. "<c2=7FF05EE8>", # Yellow
  1128. "<c2=7E1F5D17>", # Magenta
  1129. "<c2=43FF22F7>", # Cyan
  1130. "<c2=63184210>", # Grey
  1131. "<c2=7FFF5EF7>" # White
  1132. ]
  1133. color=0 if color>textcolors.length
  1134. return textcolors[color]
  1135. else # VX windowskin
  1136. color=0 if color>=32
  1137. x = 64 + (color % 8) * 8
  1138. y = 96 + (color / 8) * 8
  1139. pixel=windowskin.get_pixel(x, y)
  1140. return shadowctagFromColor(pixel)
  1141. end
  1142. end
  1143.  
  1144. # internal function
  1145. def pbRepositionMessageWindow(msgwindow, linecount=2)
  1146. msgwindow.height=32*linecount+msgwindow.borderY
  1147. msgwindow.y=(Graphics.height)-(msgwindow.height)
  1148. if $game_temp && $game_temp.in_battle && !$scene.respond_to?("update_basic")
  1149. msgwindow.y=0
  1150. elsif $game_system && $game_system.respond_to?("message_position")
  1151. case $game_system.message_position
  1152. when 0 # up
  1153. msgwindow.y=0
  1154. when 1 # middle
  1155. msgwindow.y=(Graphics.height/2)-(msgwindow.height/2)
  1156. when 2
  1157. msgwindow.y=(Graphics.height)-(msgwindow.height)
  1158. end
  1159. end
  1160. if $game_system && $game_system.respond_to?("message_frame")
  1161. if $game_system.message_frame != 0
  1162. msgwindow.opacity = 0
  1163. end
  1164. end
  1165. if $game_message
  1166. case $game_message.background
  1167. when 1 # dim
  1168. msgwindow.opacity=0
  1169. when 2 # transparent
  1170. msgwindow.opacity=0
  1171. end
  1172. end
  1173. end
  1174.  
  1175. # internal function
  1176. def pbUpdateMsgWindowPos(msgwindow,event,eventChanged=false)
  1177. if event
  1178. if eventChanged
  1179. msgwindow.resizeToFit2(msgwindow.text,Graphics.width*2/3,msgwindow.height)
  1180. end
  1181. msgwindow.y=event.screen_y-48-msgwindow.height
  1182. if msgwindow.y<0
  1183. msgwindow.y=event.screen_y+24
  1184. end
  1185. msgwindow.x=event.screen_x-(msgwindow.width/2)
  1186. msgwindow.x=0 if msgwindow.x<0
  1187. if msgwindow.x>Graphics.width-msgwindow.width
  1188. msgwindow.x=Graphics.width-msgwindow.width
  1189. end
  1190. else
  1191. curwidth=msgwindow.width
  1192. if curwidth!=Graphics.width
  1193. msgwindow.width=Graphics.width
  1194. msgwindow.width=Graphics.width
  1195. end
  1196. end
  1197. end
  1198.  
  1199. # internal function
  1200.  
  1201. def pbGetGoldString
  1202. moneyString=""
  1203. if $Trainer
  1204. moneyString=_INTL("${1}",$Trainer.money)
  1205. else
  1206. if $data_system.respond_to?("words")
  1207. moneyString=_INTL("{1} {2}",$game_party.gold,$data_system.words.gold)
  1208. else
  1209. moneyString=_INTL("{1} {2}",$game_party.gold,Vocab.gold)
  1210. end
  1211. end
  1212. return moneyString
  1213. end
  1214.  
  1215. def pbDisplayGoldWindow(msgwindow)
  1216. moneyString=pbGetGoldString()
  1217. goldwindow=Window_AdvancedTextPokemon.new(_INTL("Money:\n<ar>{1}</ar>",moneyString))
  1218. goldwindow.setSkin("Graphics/Windowskins/goldskin")
  1219. goldwindow.resizeToFit(goldwindow.text,Graphics.width)
  1220. goldwindow.width=160 if goldwindow.width<=160
  1221. if msgwindow.y==0
  1222. goldwindow.y=Graphics.height-goldwindow.height
  1223. else
  1224. goldwindow.y=0
  1225. end
  1226. goldwindow.viewport=msgwindow.viewport
  1227. goldwindow.z=msgwindow.z
  1228. return goldwindow
  1229. end
  1230.  
  1231. #polectron
  1232. def pbDisplayNametagWindow(msgwindow, facewindow, name)
  1233. namewindow=Window_AdvancedTextPokemon.new(_INTL("{1}",name))
  1234. namewindow.setSkin("Graphics/Windowskins/nameskin")
  1235. namewindow.resizeToFit(namewindow.text,Graphics.width)
  1236. namewindow.width=160 if namewindow.width<=160
  1237. if msgwindow.y==0
  1238. namewindow.y=Graphics.height-namewindow.height
  1239. else
  1240. namewindow.y=0
  1241. end
  1242.  
  1243. namewindow.y=msgwindow.y-namewindow.height
  1244. namewindow.x=msgwindow.x+6
  1245. if facewindow
  1246. namewindow.x=facewindow.x+facewindow.width+6
  1247. end
  1248.  
  1249. namewindow.viewport=msgwindow.viewport
  1250. namewindow.z=msgwindow.z
  1251. return namewindow
  1252. end
  1253. def pbDisplayCoinsWindow(msgwindow,goldwindow)
  1254. coinString=($PokemonGlobal) ? $PokemonGlobal.coins : "0"
  1255. coinwindow=Window_AdvancedTextPokemon.new(_INTL("Coins:\n<ar>{1}</ar>",coinString))
  1256. coinwindow.setSkin("Graphics/Windowskins/goldskin")
  1257. coinwindow.resizeToFit(coinwindow.text,Graphics.width)
  1258. coinwindow.width=160 if coinwindow.width<=160
  1259. if msgwindow.y==0
  1260. coinwindow.y=(goldwindow) ? goldwindow.y-coinwindow.height : Graphics.height-coinwindow.height
  1261. else
  1262. coinwindow.y=(goldwindow) ? goldwindow.height : 0
  1263. end
  1264. coinwindow.viewport=msgwindow.viewport
  1265. coinwindow.z=msgwindow.z
  1266. return coinwindow
  1267. end
  1268.  
  1269. def pbMessageWaitForInput(msgwindow,frames,showPause=false)
  1270. return if !frames || frames<=0
  1271. if msgwindow && showPause
  1272. msgwindow.startPause
  1273. end
  1274. frames.times do
  1275. Graphics.update
  1276. Input.update
  1277. msgwindow.update if msgwindow
  1278. pbUpdateSceneMap
  1279. if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  1280. break
  1281. end
  1282. yield if block_given?
  1283. end
  1284. if msgwindow && showPause
  1285. msgwindow.stopPause
  1286. end
  1287. end
  1288.  
  1289. def Kernel.pbMessageDisplay(msgwindow,message,letterbyletter=true,commandProc=nil)
  1290. return if !msgwindow
  1291. oldletterbyletter=msgwindow.letterbyletter
  1292. msgwindow.letterbyletter=(letterbyletter ? true : false)
  1293. ret=nil
  1294. count=0
  1295. commands=nil
  1296. facewindow=nil
  1297. goldwindow=nil
  1298. coinwindow=nil
  1299. namewindow=nil
  1300. cmdvariable=0
  1301. cmdIfCancel=0
  1302. msgwindow.waitcount=0
  1303. autoresume=false
  1304. text=message.clone
  1305. msgback=nil
  1306. linecount=(Graphics.height>400) ? 3 : 2
  1307. ### Text replacement
  1308. text.gsub!(/\\\\/,"\5")
  1309. if $game_actors
  1310. text.gsub!(/\\[Nn]\[([1-8])\]/){
  1311. m=$1.to_i
  1312. next $game_actors[m].name
  1313. }
  1314. end
  1315. text.gsub!(/\\[Ss][Ii][Gg][Nn]\[([^\]]*)\]/){
  1316. next "\\op\\cl\\ts[]\\w["+$1+"]"
  1317. }
  1318. text.gsub!(/\\[Pp][Nn]/,$Trainer.name) if $Trainer
  1319. text.gsub!(/\\[Pp][Mm]/,_INTL("${1}",$Trainer.money)) if $Trainer
  1320. text.gsub!(/\\[Nn]/,"\n")
  1321. text.gsub!(/\\\[([0-9A-Fa-f]{8,8})\]/){ "<c2="+$1+">" }
  1322. text.gsub!(/\\[Pp][Gg]/,"\\b") if $Trainer && $Trainer.isMale?
  1323. text.gsub!(/\\[Pp][Gg]/,"\\r") if $Trainer && $Trainer.isFemale?
  1324. text.gsub!(/\\[Pp][Oo][Gg]/,"\\r") if $Trainer && $Trainer.isMale?
  1325. text.gsub!(/\\[Pp][Oo][Gg]/,"\\b") if $Trainer && $Trainer.isFemale?
  1326. text.gsub!(/\\[Pp][Gg]/,"")
  1327. text.gsub!(/\\[Pp][Oo][Gg]/,"")
  1328. text.gsub!(/\\[Bb]/,"<c2=6546675A>")
  1329. text.gsub!(/\\[Rr]/,"<c2=043C675A>")
  1330. text.gsub!(/\\1/,"\1")
  1331. colortag=""
  1332. isDarkSkin=isDarkWindowskin(msgwindow.windowskin)
  1333. if ($game_message && $game_message.background>0) ||
  1334. ($game_system && $game_system.respond_to?("message_frame") &&
  1335. $game_system.message_frame != 0)
  1336. colortag=getSkinColor(msgwindow.windowskin,0,true)
  1337. else
  1338. colortag=getSkinColor(msgwindow.windowskin,0,isDarkSkin)
  1339. end
  1340. text.gsub!(/\\[Cc]\[([0-9]+)\]/){
  1341. m=$1.to_i
  1342. next getSkinColor(msgwindow.windowskin,m,isDarkSkin)
  1343. }
  1344. begin
  1345. last_text = text.clone
  1346. text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  1347. end until text == last_text
  1348. begin
  1349. last_text = text.clone
  1350. text.gsub!(/\\[Ll]\[([0-9]+)\]/) {
  1351. linecount=[1,$1.to_i].max;
  1352. next ""
  1353. }
  1354. end until text == last_text
  1355. text=colortag+text
  1356. ### Controls
  1357. textchunks=[]
  1358. controls=[]
  1359. while text[/(?:\\([WwFf]|[Ff][Ff]|[Tt][Ss]|[Cc][Ll]|[Mm][Ee]|[Tt][Gg]|[Ss][Ee]|[Ww][Tt]|[Ww][Tt][Nn][Pp]|[Cc][Hh])\[([^\]]*)\]|\\([Gg]|[Cc][Nn]|[Ww][Dd]|[Ww][Mm]|[Oo][Pp]|[Cc][Ll]|[Ww][Uu]|[\.]|[\|]|[\!]|[\x5E])())/i]
  1360. textchunks.push($~.pre_match)
  1361. if $~[1]
  1362. controls.push([$~[1].downcase,$~[2],-1])
  1363. else
  1364. controls.push([$~[3].downcase,"",-1])
  1365. end
  1366. text=$~.post_match
  1367. end
  1368. textchunks.push(text)
  1369. for chunk in textchunks
  1370. chunk.gsub!(/\005/,"\\")
  1371. end
  1372. textlen=0
  1373. for i in 0...controls.length
  1374. control=controls[i][0]
  1375. if control=="wt" || control=="wtnp" || control=="." || control=="|"
  1376. textchunks[i]+="\2"
  1377. elsif control=="!"
  1378. textchunks[i]+="\1"
  1379. end
  1380. textlen+=toUnformattedText(textchunks[i]).scan(/./m).length
  1381. controls[i][2]=textlen
  1382. end
  1383. text=textchunks.join("")
  1384. unformattedText=toUnformattedText(text)
  1385. signWaitCount=0
  1386. haveSpecialClose=false
  1387. specialCloseSE=""
  1388. for i in 0...controls.length
  1389. control=controls[i][0]
  1390. param=controls[i][1]
  1391. if control=="f"
  1392. facewindow.dispose if facewindow
  1393. facewindow=PictureWindow.new("Graphics/Pictures/#{param}")
  1394. elsif control=="tg" #display nametag by polectron
  1395. namewindow.dispose if namewindow
  1396. namewindow=pbDisplayNametagWindow(msgwindow, facewindow, param)
  1397. elsif control=="op"
  1398. signWaitCount=21
  1399. elsif control=="cl"
  1400. text=text.sub(/\001\z/,"") # fix: '$' can match end of line as well
  1401. haveSpecialClose=true
  1402. specialCloseSE=param
  1403. elsif control=="se" && controls[i][2]==0
  1404. startSE=param
  1405. controls[i]=nil
  1406. elsif control=="ff"
  1407. facewindow.dispose if facewindow
  1408. facewindow=FaceWindowVX.new(param)
  1409. elsif control=="ch"
  1410. cmds=param.clone
  1411. cmdvariable=pbCsvPosInt!(cmds)
  1412. cmdIfCancel=pbCsvField!(cmds).to_i
  1413. commands=[]
  1414. while cmds.length>0
  1415. commands.push(pbCsvField!(cmds))
  1416. end
  1417. elsif control=="wtnp" || control=="^"
  1418. text=text.sub(/\001\z/,"") # fix: '$' can match end of line as well
  1419. end
  1420. end
  1421. if startSE!=nil
  1422. pbSEPlay(pbStringToAudioFile(startSE))
  1423. elsif signWaitCount==0 && letterbyletter
  1424. pbPlayDecisionSE()
  1425. end
  1426. ########## Position message window ##############
  1427. pbRepositionMessageWindow(msgwindow,linecount)
  1428. if $game_message && $game_message.background==1
  1429. msgback=IconSprite.new(0,msgwindow.y,msgwindow.viewport)
  1430. msgback.z=msgwindow.z-1
  1431. msgback.setBitmap("Graphics/System/MessageBack")
  1432. end
  1433. if facewindow
  1434. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  1435. facewindow.viewport=msgwindow.viewport
  1436. facewindow.z=msgwindow.z
  1437. end
  1438. atTop=(msgwindow.y==0)
  1439. ########## Show text #############################
  1440. msgwindow.text=text
  1441. Graphics.frame_reset if Graphics.frame_rate>40
  1442. begin
  1443. if signWaitCount>0
  1444. signWaitCount-=1
  1445. if atTop
  1446. msgwindow.y=-(msgwindow.height*(signWaitCount)/20)
  1447. else
  1448. msgwindow.y=Graphics.height-(msgwindow.height*(20-signWaitCount)/20)
  1449. end
  1450. end
  1451. for i in 0...controls.length
  1452. if controls[i] && controls[i][2]<=msgwindow.position && msgwindow.waitcount==0
  1453. control=controls[i][0]
  1454. param=controls[i][1]
  1455. case control
  1456. when "f"
  1457. facewindow.dispose if facewindow
  1458. facewindow=PictureWindow.new("Graphics/Pictures/#{param}")
  1459. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  1460. facewindow.viewport=msgwindow.viewport
  1461. facewindow.z=msgwindow.z
  1462. when "ts"
  1463. if param==""
  1464. msgwindow.textspeed=-999
  1465. else
  1466. msgwindow.textspeed=param.to_i
  1467. end
  1468. when "ff"
  1469. facewindow.dispose if facewindow
  1470. facewindow=FaceWindowVX.new(param)
  1471. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  1472. facewindow.viewport=msgwindow.viewport
  1473. facewindow.z=msgwindow.z
  1474. when "g" # Display gold window
  1475. goldwindow.dispose if goldwindow
  1476. goldwindow=pbDisplayGoldWindow(msgwindow)
  1477. when "tg" #display nametag by polectron
  1478. namewindow.dispose if namewindow
  1479. namewindow=pbDisplayNametagWindow(msgwindow, facewindow, param)
  1480. when "cn" # Display coins window
  1481. coinwindow.dispose if coinwindow
  1482. coinwindow=pbDisplayCoinsWindow(msgwindow,goldwindow)
  1483. when "wu"
  1484. msgwindow.y=0
  1485. atTop=true
  1486. msgback.y=msgwindow.y if msgback
  1487. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  1488. msgwindow.y=-(msgwindow.height*(signWaitCount)/20)
  1489. when "wm"
  1490. atTop=false
  1491. msgwindow.y=(Graphics.height/2)-(msgwindow.height/2)
  1492. msgback.y=msgwindow.y if msgback
  1493. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  1494. when "wd"
  1495. atTop=false
  1496. msgwindow.y=(Graphics.height)-(msgwindow.height)
  1497. msgback.y=msgwindow.y if msgback
  1498. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  1499. msgwindow.y=Graphics.height-(msgwindow.height*(20-signWaitCount)/20)
  1500. when "."
  1501. msgwindow.waitcount+=Graphics.frame_rate/4
  1502. when "|"
  1503. msgwindow.waitcount+=Graphics.frame_rate
  1504. when "wt" # Wait
  1505. param=param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  1506. msgwindow.waitcount+=param.to_i*2
  1507. when "w" # Windowskin
  1508. if param==""
  1509. msgwindow.windowskin=nil
  1510. else
  1511. msgwindow.setSkin("Graphics/Windowskins/#{param}")
  1512. end
  1513. msgwindow.width=msgwindow.width # Necessary evil
  1514. when "^" # Wait, no pause
  1515. autoresume=true
  1516. when "wtnp" # Wait, no pause
  1517. param=param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  1518. msgwindow.waitcount=param.to_i*2
  1519. autoresume=true
  1520. when "se" # Play SE
  1521. pbSEPlay(pbStringToAudioFile(param))
  1522. when "me" # Play ME
  1523. pbMEPlay(pbStringToAudioFile(param))
  1524. end
  1525. controls[i]=nil
  1526. end
  1527. end
  1528. break if !letterbyletter
  1529. Graphics.update
  1530. Input.update
  1531. facewindow.update if facewindow
  1532. if $DEBUG && Input.trigger?(Input::F6)
  1533. pbRecord(unformattedText)
  1534. end
  1535. if autoresume && msgwindow.waitcount==0
  1536. msgwindow.resume if msgwindow.busy?
  1537. break if !msgwindow.busy?
  1538. end
  1539. if (Input.trigger?(Input::C) || Input.trigger?(Input::B))
  1540. if msgwindow.busy?
  1541. pbPlayDecisionSE() if msgwindow.pausing?
  1542. msgwindow.resume
  1543. else
  1544. break if signWaitCount==0
  1545. end
  1546. end
  1547. pbUpdateSceneMap
  1548. msgwindow.update
  1549. yield if block_given?
  1550. end until (!letterbyletter || commandProc || commands) && !msgwindow.busy?
  1551. Input.update # Must call Input.update again to avoid extra triggers
  1552. msgwindow.letterbyletter=oldletterbyletter
  1553. if commands
  1554. $game_variables[cmdvariable]=Kernel.pbShowCommands(
  1555. msgwindow,commands,cmdIfCancel)
  1556. $game_map.need_refresh = true if $game_map
  1557. end
  1558. if commandProc
  1559. ret=commandProc.call(msgwindow)
  1560. end
  1561. msgback.dispose if msgback
  1562. goldwindow.dispose if goldwindow
  1563. coinwindow.dispose if coinwindow
  1564. facewindow.dispose if facewindow
  1565. namewindow.dispose if namewindow
  1566. if haveSpecialClose
  1567. pbSEPlay(pbStringToAudioFile(specialCloseSE))
  1568. atTop=(msgwindow.y==0)
  1569. for i in 0..20
  1570. if atTop
  1571. msgwindow.y=-(msgwindow.height*(i)/20)
  1572. else
  1573. msgwindow.y=Graphics.height-(msgwindow.height*(20-i)/20)
  1574. end
  1575. Graphics.update
  1576. Input.update
  1577. pbUpdateSceneMap
  1578. msgwindow.update
  1579. end
  1580. end
  1581. return ret
  1582. end
Add Comment
Please, Sign In to add comment