Guest User

Untitled

a guest
Oct 11th, 2022
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.52 KB | None | 0 0
  1. #This is an adaptation of Mr.Gela's Portrait and Namebox Scripts combined
  2. # for 20.1
  3. #Please give credit to Mr.Gela, Golisopod User, mej71 and battlelegendblue if used!
  4. #=========================================
  5. #The script supports full portrait functionality
  6. #but basic Namebox functionality.
  7. #This script is meant to replace the MESSAGES script, so if you
  8. #have already made any changes of your own, please make sure
  9. #you copy them over.
  10. #Portait Y position seemed to be off by a couple of pixels,
  11. #I have adjusted the lines responsible, but you may edit as you see fit.
  12. #Sections with Gela's additions have been marked, as well as
  13. #anything that has been manually changed.
  14. #===========GELANAME0===========
  15. # SHIFT NAMEWINDOW IN X AXIS (except when specifying a particular X location)
  16. OFFSET_NAMEWINDOW_X=0
  17. # SHIFT NAMEWINDOW IN Y AXIS (except when specifying a particular Y location)
  18. OFFSET_NAMEWINDOW_Y=0
  19. # WHETHER THE TEXT SHOULD BE CENTERED (0=right, 1=center, 2=right)
  20. DEFAULT_ALIGNMENT=1
  21. # ENSURES A MIN. WIDTH OF THE WINDOW
  22. MIN_WIDTH=200
  23. # DEFAULT FONT
  24. DEFAULT_FONT="Power Green Narrow" # "Power Clear", etc.
  25. # DEFAULT FONT SIZE
  26. DEFAULT_FONT_SIZE=24
  27. # DEFAULT WINDOWSKIN (nil = based on the currently displayed message windowskin)
  28. # (File inside Graphics/Windowskins/)
  29. DEFAULT_WINDOWSKIN="nmbx"
  30. # Name of namebox file is nmbx. Simply add Gela's Namebox Graphic from his original resource into your #windowskins folder, and name it "nmbx".
  31. #===========GELANAME0===========
  32. #===============================================================================
  33. #
  34. #===============================================================================
  35. def pbMapInterpreter
  36. return $game_system&.map_interpreter
  37. end
  38.  
  39. def pbMapInterpreterRunning?
  40. interp = pbMapInterpreter
  41. return interp&.running?
  42. end
  43.  
  44. # Unused
  45. def pbRefreshSceneMap
  46. $scene.miniupdate if $scene.is_a?(Scene_Map)
  47. end
  48.  
  49. def pbUpdateSceneMap
  50. $scene.miniupdate if $scene.is_a?(Scene_Map) && !pbIsFaded?
  51. end
  52.  
  53. #===============================================================================
  54. #
  55. #===============================================================================
  56. def pbEventCommentInput(*args)
  57. parameters = []
  58. list = args[0].list # List of commands for event or event page
  59. elements = args[1] # Number of elements
  60. trigger = args[2] # Trigger
  61. return nil if list.nil?
  62. return nil unless list.is_a?(Array)
  63. list.each do |item|
  64. next if ![108, 108].include?(item.code)
  65. next if item.parameters[0] != trigger
  66. start = list.index(item) + 1
  67. finish = start + elements
  68. (start...finish).each do |id|
  69. parameters.push(list[id].parameters[0]) if list[id]
  70. end
  71. return parameters
  72. end
  73. return nil
  74. end
  75.  
  76. def pbCurrentEventCommentInput(elements, trigger)
  77. return nil if !pbMapInterpreterRunning?
  78. event = pbMapInterpreter.get_self
  79. return nil if !event
  80. return pbEventCommentInput(event, elements, trigger)
  81. end
  82.  
  83. #===============================================================================
  84. #
  85. #===============================================================================
  86. class ChooseNumberParams
  87. attr_reader :messageSkin # Set the full path for the message's window skin
  88. attr_reader :skin
  89.  
  90. def initialize
  91. @maxDigits = 0
  92. @minNumber = 0
  93. @maxNumber = 0
  94. @skin = nil
  95. @messageSkin = nil
  96. @negativesAllowed = false
  97. @initialNumber = 0
  98. @cancelNumber = nil
  99. end
  100.  
  101. def setMessageSkin(value)
  102. @messageSkin = value
  103. end
  104.  
  105. def setSkin(value)
  106. @skin = value
  107. end
  108.  
  109. def setNegativesAllowed(value)
  110. @negativeAllowed = value
  111. end
  112.  
  113. def negativesAllowed
  114. @negativeAllowed ? true : false
  115. end
  116.  
  117. def setRange(minNumber, maxNumber)
  118. maxNumber = minNumber if minNumber > maxNumber
  119. @maxDigits = 0
  120. @minNumber = minNumber
  121. @maxNumber = maxNumber
  122. end
  123.  
  124. def setDefaultValue(number)
  125. @initialNumber = number
  126. @cancelNumber = nil
  127. end
  128.  
  129. def setInitialValue(number)
  130. @initialNumber = number
  131. end
  132.  
  133. def setCancelValue(number)
  134. @cancelNumber = number
  135. end
  136.  
  137. def initialNumber
  138. return clamp(@initialNumber, self.minNumber, self.maxNumber)
  139. end
  140.  
  141. def cancelNumber
  142. return @cancelNumber || self.initialNumber
  143. end
  144.  
  145. def minNumber
  146. ret = 0
  147. if @maxDigits > 0
  148. ret = -((10**@maxDigits) - 1)
  149. else
  150. ret = @minNumber
  151. end
  152. ret = 0 if !@negativeAllowed && ret < 0
  153. return ret
  154. end
  155.  
  156. def maxNumber
  157. ret = 0
  158. if @maxDigits > 0
  159. ret = ((10**@maxDigits) - 1)
  160. else
  161. ret = @maxNumber
  162. end
  163. ret = 0 if !@negativeAllowed && ret < 0
  164. return ret
  165. end
  166.  
  167. def setMaxDigits(value)
  168. @maxDigits = [1, value].max
  169. end
  170.  
  171. def maxDigits
  172. if @maxDigits > 0
  173. return @maxDigits
  174. else
  175. return [numDigits(self.minNumber), numDigits(self.maxNumber)].max
  176. end
  177. end
  178.  
  179. private
  180.  
  181. def clamp(v, mn, mx)
  182. return v < mn ? mn : (v > mx ? mx : v)
  183. end
  184.  
  185. def numDigits(number)
  186. ans = 1
  187. number = number.abs
  188. while number >= 10
  189. ans += 1
  190. number /= 10
  191. end
  192. return ans
  193. end
  194. end
  195.  
  196.  
  197.  
  198. def pbChooseNumber(msgwindow, params)
  199. return 0 if !params
  200. ret = 0
  201. maximum = params.maxNumber
  202. minimum = params.minNumber
  203. defaultNumber = params.initialNumber
  204. cancelNumber = params.cancelNumber
  205. cmdwindow = Window_InputNumberPokemon.new(params.maxDigits)
  206. cmdwindow.z = 99999
  207. cmdwindow.visible = true
  208. cmdwindow.setSkin(params.skin) if params.skin
  209. cmdwindow.sign = params.negativesAllowed # must be set before number
  210. cmdwindow.number = defaultNumber
  211. pbPositionNearMsgWindow(cmdwindow, msgwindow, :right)
  212. loop do
  213. Graphics.update
  214. Input.update
  215. pbUpdateSceneMap
  216. cmdwindow.update
  217. msgwindow&.update
  218. yield if block_given?
  219. if Input.trigger?(Input::USE)
  220. ret = cmdwindow.number
  221. if ret > maximum
  222. pbPlayBuzzerSE
  223. elsif ret < minimum
  224. pbPlayBuzzerSE
  225. else
  226. pbPlayDecisionSE
  227. break
  228. end
  229. elsif Input.trigger?(Input::BACK)
  230. pbPlayCancelSE
  231. ret = cancelNumber
  232. break
  233. end
  234. end
  235. cmdwindow.dispose
  236. Input.update
  237. return ret
  238. end
  239.  
  240.  
  241.  
  242.  
  243. #===============================================================================
  244. #
  245. #===============================================================================
  246. class FaceWindowVX < SpriteWindow_Base
  247. def initialize(face)
  248. super(0, 0, 128, 128)
  249. faceinfo = face.split(",")
  250. facefile = pbResolveBitmap("Graphics/Faces/" + faceinfo[0])
  251. facefile = pbResolveBitmap("Graphics/Pictures/" + faceinfo[0]) if !facefile
  252. self.contents&.dispose
  253. @faceIndex = faceinfo[1].to_i
  254. @facebitmaptmp = AnimatedBitmap.new(facefile)
  255. @facebitmap = BitmapWrapper.new(96, 96)
  256. @facebitmap.blt(0, 0, @facebitmaptmp.bitmap,
  257. Rect.new((@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96))
  258. self.contents = @facebitmap
  259. end
  260.  
  261. def update
  262. super
  263. if @facebitmaptmp.totalFrames > 1
  264. @facebitmaptmp.update
  265. @facebitmap.blt(0, 0, @facebitmaptmp.bitmap,
  266. Rect.new((@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96))
  267. end
  268. end
  269.  
  270. def dispose
  271. @facebitmaptmp.dispose
  272. @facebitmap&.dispose
  273. super
  274. end
  275. end
  276.  
  277.  
  278. #===============================================================================
  279. #
  280. #===============================================================================
  281. def pbGetBasicMapNameFromId(id)
  282. begin
  283. map = pbLoadMapInfos
  284. return "" if !map
  285. return map[id].name
  286. rescue
  287. return ""
  288. end
  289. end
  290.  
  291. def pbGetMapNameFromId(id)
  292. name = pbGetMessage(MessageTypes::MapNames, id)
  293. name = pbGetBasicMapNameFromId(id) if nil_or_empty?(name)
  294. name.gsub!(/\\PN/, $player.name) if $player
  295. return name
  296. end
  297.  
  298. def pbCsvField!(str)
  299. ret = ""
  300. str.sub!(/\A\s*/, "")
  301. if str[0, 1] == "\""
  302. str[0, 1] = ""
  303. escaped = false
  304. fieldbytes = 0
  305. str.scan(/./) do |s|
  306. fieldbytes += s.length
  307. break if s == "\"" && !escaped
  308. if s == "\\" && !escaped
  309. escaped = true
  310. else
  311. ret += s
  312. escaped = false
  313. end
  314. end
  315. str[0, fieldbytes] = ""
  316. if !str[/\A\s*,/] && !str[/\A\s*$/]
  317. raise _INTL("Invalid quoted field (in: {1})", ret)
  318. end
  319. str[0, str.length] = $~.post_match
  320. else
  321. if str[/,/]
  322. str[0, str.length] = $~.post_match
  323. ret = $~.pre_match
  324. else
  325. ret = str.clone
  326. str[0, str.length] = ""
  327. end
  328. ret.gsub!(/\s+$/, "")
  329. end
  330. return ret
  331. end
  332.  
  333. def pbCsvPosInt!(str)
  334. ret = pbCsvField!(str)
  335. if !ret[/\A\d+$/]
  336. raise _INTL("Field {1} is not a positive integer", ret)
  337. end
  338. return ret.to_i
  339. end
  340.  
  341. #===================GELA FACE1=======================================
  342. class FaceWindowVXNew < SpriteWindow_Base
  343. def initialize(face)
  344. super(0,0,270,270)
  345. self.windowskin=nil
  346. faceinfo=face.split(",")
  347. facefile=pbResolveBitmap("Graphics/Faces/"+faceinfo[0])
  348. facefile=pbResolveBitmap("Graphics/Pictures/"+faceinfo[0]) if !facefile
  349. self.contents.dispose if self.contents
  350. @faceIndex=faceinfo[1].to_i
  351. @facebitmaptmp=AnimatedBitmap.new(facefile)
  352. @facebitmap=BitmapWrapper.new(240,260)
  353. @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  354. (@faceIndex % 4) * 260,
  355. (@faceIndex / 4) * 260, 260, 260
  356. ))
  357. self.contents=@facebitmap
  358. end
  359.  
  360. def update
  361. super
  362. if @facebitmaptmp.totalFrames>77 #This should be 1. Adjust accordingly
  363. @facebitmaptmp.update
  364. @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new(
  365. (@faceIndex % 4) * 260,
  366. (@faceIndex / 4) * 260, 260, 260
  367. ))
  368. end
  369. end
  370.  
  371. def dispose
  372. @facebitmaptmp.dispose
  373. @facebitmap.dispose if @facebitmap
  374. super
  375.  
  376. end
  377. end
  378. #==========================GELA FACE1==============================
  379.  
  380.  
  381.  
  382. #===============================================================================
  383. #
  384. #===============================================================================
  385. def pbGetBasicMapNameFromId(id)
  386. begin
  387. map = pbLoadMapInfos
  388. return "" if !map
  389. return map[id].name
  390. rescue
  391. return ""
  392. end
  393. end
  394.  
  395. def pbGetMapNameFromId(id)
  396. name = pbGetMessage(MessageTypes::MapNames, id)
  397. name = pbGetBasicMapNameFromId(id) if nil_or_empty?(name)
  398. name.gsub!(/\\PN/, $player.name) if $player
  399. return name
  400. end
  401.  
  402. def pbCsvField!(str)
  403. ret = ""
  404. str.sub!(/\A\s*/, "")
  405. if str[0, 1] == "\""
  406. str[0, 1] = ""
  407. escaped = false
  408. fieldbytes = 0
  409. str.scan(/./) do |s|
  410. fieldbytes += s.length
  411. break if s == "\"" && !escaped
  412. if s == "\\" && !escaped
  413. escaped = true
  414. else
  415. ret += s
  416. escaped = false
  417. end
  418. end
  419. str[0, fieldbytes] = ""
  420. if !str[/\A\s*,/] && !str[/\A\s*$/]
  421. raise _INTL("Invalid quoted field (in: {1})", ret)
  422. end
  423. str[0, str.length] = $~.post_match
  424. else
  425. if str[/,/]
  426. str[0, str.length] = $~.post_match
  427. ret = $~.pre_match
  428. else
  429. ret = str.clone
  430. str[0, str.length] = ""
  431. end
  432. ret.gsub!(/\s+$/, "")
  433. end
  434. return ret
  435. end
  436.  
  437. def pbCsvPosInt!(str)
  438. ret = pbCsvField!(str)
  439. if !ret[/\A\d+$/]
  440. raise _INTL("Field {1} is not a positive integer", ret)
  441. end
  442. return ret.to_i
  443. end
  444.  
  445.  
  446. #===============================================================================
  447. # Money and coins windows
  448. #===============================================================================
  449. def pbGetGoldString
  450. return _INTL("${1}", $player.money.to_s_formatted)
  451. end
  452.  
  453. def pbDisplayGoldWindow(msgwindow)
  454. moneyString = pbGetGoldString
  455. goldwindow = Window_AdvancedTextPokemon.new(_INTL("Money:\n<ar>{1}</ar>", moneyString))
  456. goldwindow.setSkin("Graphics/Windowskins/goldskin")
  457. goldwindow.resizeToFit(goldwindow.text, Graphics.width)
  458. goldwindow.width = 160 if goldwindow.width <= 160
  459. if msgwindow.y == 0
  460. goldwindow.y = Graphics.height - goldwindow.height
  461. else
  462. goldwindow.y = 0
  463. end
  464. goldwindow.viewport = msgwindow.viewport
  465. goldwindow.z = msgwindow.z
  466. return goldwindow
  467. end
  468.  
  469. def pbDisplayCoinsWindow(msgwindow, goldwindow)
  470. coinString = ($player) ? $player.coins.to_s_formatted : "0"
  471. coinwindow = Window_AdvancedTextPokemon.new(_INTL("Coins:\n<ar>{1}</ar>", coinString))
  472. coinwindow.setSkin("Graphics/Windowskins/goldskin")
  473. coinwindow.resizeToFit(coinwindow.text, Graphics.width)
  474. coinwindow.width = 160 if coinwindow.width <= 160
  475. if msgwindow.y == 0
  476. coinwindow.y = (goldwindow) ? goldwindow.y - coinwindow.height : Graphics.height - coinwindow.height
  477. else
  478. coinwindow.y = (goldwindow) ? goldwindow.height : 0
  479. end
  480. coinwindow.viewport = msgwindow.viewport
  481. coinwindow.z = msgwindow.z
  482. return coinwindow
  483. end
  484.  
  485. def pbDisplayBattlePointsWindow(msgwindow)
  486. pointsString = ($player) ? $player.battle_points.to_s_formatted : "0"
  487. pointswindow = Window_AdvancedTextPokemon.new(_INTL("Battle Points:\n<ar>{1}</ar>", pointsString))
  488. pointswindow.setSkin("Graphics/Windowskins/goldskin")
  489. pointswindow.resizeToFit(pointswindow.text, Graphics.width)
  490. pointswindow.width = 160 if pointswindow.width <= 160
  491. if msgwindow.y == 0
  492. pointswindow.y = Graphics.height - pointswindow.height
  493. else
  494. pointswindow.y = 0
  495. end
  496. pointswindow.viewport = msgwindow.viewport
  497. pointswindow.z = msgwindow.z
  498. return pointswindow
  499. end
  500.  
  501.  
  502. #=======GELANAME1==============
  503.  
  504. # NEW
  505. def pbDisplayNameWindow(msgwindow,dark,param)
  506. namewindow=Window_AdvancedTextPokemon.new(_INTL("<ac>{1}</ac>",param))
  507. if dark==true
  508. namewindow.setSkin("Graphics/Windowskins/"+MessageConfig::TextSkinName+"xndark")
  509. colortag=getSkinColor(msgwindow.windowskin,0,true)
  510. namewindow.text=colortag+namewindow.text
  511. else
  512. namewindow.setSkin("Graphics/Windowskins/nmbx")
  513. end
  514.  
  515. namewindow.resizeToFit(namewindow.text,Graphics.width)
  516. namewindow.width=180 if namewindow.width<=180
  517. namewindow.width = namewindow.width
  518. namewindow.y=msgwindow.y-namewindow.height
  519. namewindow.y+=OFFSET_NAMEWINDOW_Y
  520. namewindow.x+=OFFSET_NAMEWINDOW_X
  521. namewindow.viewport=msgwindow.viewport
  522. namewindow.z=msgwindow.z
  523. return namewindow
  524. end
  525. #=======GELANAME1==============
  526.  
  527.  
  528. #===============================================================================
  529. #
  530. #===============================================================================
  531. def pbCreateStatusWindow(viewport = nil)
  532. msgwindow = Window_AdvancedTextPokemon.new("")
  533. if viewport
  534. msgwindow.viewport = viewport
  535. else
  536. msgwindow.z = 99999
  537. end
  538. msgwindow.visible = false
  539. msgwindow.letterbyletter = false
  540. pbBottomLeftLines(msgwindow, 2)
  541. skinfile = MessageConfig.pbGetSpeechFrame
  542. msgwindow.setSkin(skinfile)
  543. return msgwindow
  544. end
  545.  
  546. def pbCreateMessageWindow(viewport = nil, skin = nil)
  547. msgwindow = Window_AdvancedTextPokemon.new("")
  548. if viewport
  549. msgwindow.viewport = viewport
  550. else
  551. msgwindow.z = 99999
  552. end
  553. msgwindow.visible = true
  554. msgwindow.letterbyletter = true
  555. msgwindow.back_opacity = MessageConfig::WINDOW_OPACITY
  556. pbBottomLeftLines(msgwindow, 2)
  557. $game_temp.message_window_showing = true if $game_temp
  558. skin = MessageConfig.pbGetSpeechFrame if !skin
  559. msgwindow.setSkin(skin)
  560. return msgwindow
  561. end
  562.  
  563. def pbDisposeMessageWindow(msgwindow)
  564. $game_temp.message_window_showing = false if $game_temp
  565. msgwindow.dispose
  566. end
  567.  
  568.  
  569. #===============================================================================
  570. # Main message-displaying function
  571. #===============================================================================
  572. def pbMessageDisplay(msgwindow,message,letterbyletter=true,commandProc=nil)
  573. return if !msgwindow
  574. oldletterbyletter=msgwindow.letterbyletter
  575. msgwindow.letterbyletter=(letterbyletter) ? true : false
  576. ret=nil
  577.  
  578. #=======GELANAME2=======
  579. count=0
  580. #=======GELANAME2=======
  581.  
  582. commands=nil
  583. facewindow=nil
  584.  
  585. #======GELA FACE2=================
  586. facewindowL=nil
  587. facewindowR=nil
  588. #=====GELA FACE2==================
  589.  
  590. goldwindow=nil
  591. coinwindow=nil
  592.  
  593. #=======GELANAME3=======
  594. namewindow=nil
  595. #=======GELANAME3=======
  596.  
  597. cmdvariable=0
  598. cmdIfCancel=0
  599. msgwindow.waitcount=0
  600. autoresume=false
  601. text=message.clone
  602. msgback=nil
  603. linecount=(Graphics.height>400) ? 3 : 2
  604. ### Text replacement
  605. text.gsub!(/\\sign\[([^\]]*)\]/i) { # \sign[something] gets turned into
  606. next "\\op\\cl\\ts[]\\w["+$1+"]" # \op\cl\ts[]\w[something]
  607. }
  608. text.gsub!(/\\\\/,"\5")
  609. text.gsub!(/\\1/,"\1")
  610. if $game_actors
  611. text.gsub!(/\\n\[([1-8])\]/i) {
  612. m = $1.to_i
  613. next $game_actors[m].name
  614. }
  615. end
  616. text.gsub!(/\\pn/i,$Trainer.name) if $Trainer
  617. text.gsub!(/\\pm/i,_INTL("${1}",$Trainer.money.to_s_formatted)) if $Trainer
  618. text.gsub!(/\\n/i,"\n")
  619. text.gsub!(/\\\[([0-9a-f]{8,8})\]/i) { "<c2="+$1+">" }
  620. text.gsub!(/\\pg/i,"\\b") if $Trainer && $Trainer.male?
  621. text.gsub!(/\\pg/i,"\\r") if $Trainer && $Trainer.female?
  622. text.gsub!(/\\pog/i,"\\r") if $Trainer && $Trainer.male?
  623. text.gsub!(/\\pog/i,"\\b") if $Trainer && $Trainer.female?
  624. text.gsub!(/\\pg/i,"")
  625. text.gsub!(/\\pog/i,"")
  626. text.gsub!(/\\b/i,"<c3=3050C8,D0D0C8>")
  627. text.gsub!(/\\r/i,"<c3=E00808,D0D0C8>")
  628. isDarkSkin = isDarkWindowskin(msgwindow.windowskin)
  629. text.gsub!(/\\[Cc]\[([0-9]+)\]/) {
  630. m = $1.to_i
  631. next getSkinColor(msgwindow.windowskin,m,isDarkSkin)
  632. }
  633. loop do
  634. last_text = text.clone
  635. text.gsub!(/\\v\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  636. break if text == last_text
  637. end
  638. loop do
  639. last_text = text.clone
  640. text.gsub!(/\\l\[([0-9]+)\]/i) {
  641. linecount = [1,$1.to_i].max
  642. next ""
  643. }
  644. break if text == last_text
  645. end
  646. colortag = ""
  647. if ($game_message && $game_message.background>0) ||
  648. ($game_system && $game_system.respond_to?("message_frame") &&
  649. $game_system.message_frame != 0)
  650. colortag = getSkinColor(msgwindow.windowskin,0,true)
  651. else
  652. colortag = getSkinColor(msgwindow.windowskin,0,isDarkSkin)
  653. end
  654. text = colortag+text
  655. ### Controls
  656. textchunks=[]
  657. controls=[]
  658. #==========GELA FACE, ADDING PORTRAIT CATCH, BASICALLY MR, ML ETC===========
  659. while text[/(?:\\(w|f|ff|ts|xn|cl|me|ml|mr|se|wt|wtnp|ch)\[([^\]]*)\]|\\(g|cn|wd|wm|op|cl|wu|\.|\||\!|\^))/i]
  660. textchunks.push($~.pre_match)
  661. #==========GELA FACE, ADDING PORTRAIT CODES===========
  662. if $~[1]
  663. controls.push([$~[1].downcase,$~[2],-1])
  664. else
  665. controls.push([$~[3].downcase,"",-1])
  666. end
  667. text=$~.post_match
  668. end
  669. textchunks.push(text)
  670. for chunk in textchunks
  671. chunk.gsub!(/\005/,"\\")
  672. end
  673. textlen = 0
  674. for i in 0...controls.length
  675. control = controls[i][0]
  676. case control
  677. when "wt", "wtnp", ".", "|"
  678. textchunks[i] += "\2"
  679. when "!"
  680. textchunks[i] += "\1"
  681. end
  682. textlen += toUnformattedText(textchunks[i]).scan(/./m).length
  683. controls[i][2] = textlen
  684. end
  685. text = textchunks.join("")
  686. unformattedText = toUnformattedText(text)
  687. signWaitCount = 0
  688. signWaitTime = Graphics.frame_rate/2
  689. haveSpecialClose = false
  690. specialCloseSE = ""
  691. for i in 0...controls.length
  692. control = controls[i][0]
  693. param = controls[i][1]
  694. case control
  695. when "op"
  696. signWaitCount = signWaitTime+1
  697. when "cl"
  698. text = text.sub(/\001\z/,"") # fix: '$' can match end of line as well
  699. haveSpecialClose = true
  700. specialCloseSE = param
  701. # when "f"
  702. # facewindow.dispose if facewindow
  703. # facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
  704. when "ch"
  705. cmds = param.clone
  706. cmdvariable = pbCsvPosInt!(cmds)
  707. cmdIfCancel = pbCsvField!(cmds).to_i
  708. commands = []
  709. while cmds.length>0
  710. commands.push(pbCsvField!(cmds))
  711. end
  712. when "wtnp", "^"
  713. text = text.sub(/\001\z/,"") # fix: '$' can match end of line as well
  714. when "se"
  715. if controls[i][2]==0
  716. startSE = param
  717. controls[i] = nil
  718. end
  719. end
  720. end
  721. if startSE!=nil
  722. pbSEPlay(pbStringToAudioFile(startSE))
  723. elsif signWaitCount==0 && letterbyletter
  724. pbPlayDecisionSE()
  725. end
  726. ########## Position message window ##############
  727. pbRepositionMessageWindow(msgwindow,linecount)
  728. if $game_message && $game_message.background==1
  729. msgback = IconSprite.new(0,msgwindow.y,msgwindow.viewport)
  730. msgback.z = msgwindow.z-1
  731. msgback.setBitmap("Graphics/System/MessageBack")
  732. end
  733.  
  734.  
  735. #==============GELA FACE3=========================================================
  736. if facewindowL
  737. facewindowL.viewport=msgwindow.viewport
  738. facewindowL.z=msgwindow.z
  739. end
  740. if facewindowR
  741. facewindowR.viewport=msgwindow.viewport
  742. facewindowR.z=msgwindow.z
  743. end
  744. #===============GELA FACE3========================================================
  745.  
  746.  
  747. #if facewindow
  748. # pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  749. # facewindow.viewport = msgwindow.viewport
  750. # facewindow.z = msgwindow.z
  751. #end
  752. atTop = (msgwindow.y==0)
  753. ########## Show text #############################
  754. msgwindow.text = text
  755. # ===============change this to the framerate your game is using ??
  756. Graphics.frame_reset if Graphics.frame_rate>60
  757. # ===============change this to the framerate your game is using ??
  758. loop do
  759. if signWaitCount>0
  760. signWaitCount -= 1
  761. if atTop
  762. msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
  763. else
  764. msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
  765. end
  766. end
  767. for i in 0...controls.length
  768. next if !controls[i]
  769. next if controls[i][2]>msgwindow.position || msgwindow.waitcount!=0
  770. control = controls[i][0]
  771. param = controls[i][1]
  772. case control
  773. #===========GELANAME4=========
  774. # NEW
  775. when "xn"
  776. # Show name box, based on #{param}
  777. namewindow.dispose if namewindow
  778. namewindow=pbDisplayNameWindow(msgwindow,dark=false,param)
  779. when "dxn"
  780. # Show name box, based on #{param}
  781. namewindow.dispose if namewindow
  782. namewindow=pbDisplayNameWindow(msgwindow,dark=true,param)
  783. #===========GELANAME4=========
  784. when "f"
  785. facewindow.dispose if facewindow
  786. facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
  787. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  788. facewindow.viewport = msgwindow.viewport
  789. facewindow.z = msgwindow.z
  790.  
  791.  
  792. #====================GELA FACE4==================================
  793. when "ml" # Mug Shot (Left)
  794. facewindowL.dispose if facewindowL
  795. facewindowL=FaceWindowVXNew.new(param)
  796. facewindowL.windowskin=nil
  797. facewindowL.x=0
  798. facewindowL.y=36 #changes in Y position. Adjust accordingly
  799. facewindowL.viewport=msgwindow.viewport
  800. facewindowL.z=msgwindow.z
  801. when "mr" # Mug Shot (Right)
  802. facewindowR.dispose if facewindowR
  803. facewindowR=FaceWindowVXNew.new(param)
  804. facewindowR.windowskin=nil
  805. facewindowR.x=280
  806. facewindowR.y=36 #changes in Y position. Adjust accordingly
  807. facewindowR.viewport=msgwindow.viewport
  808. facewindowR.z=msgwindow.z
  809. when "ff"
  810. facewindow.dispose if facewindow
  811. facewindow = FaceWindowVX.new(param)
  812. facewindow.x=320
  813. facewindow.y=114-32 #changes in Y position. Adjust accordingly
  814. #==================GELA FACE4=======================
  815.  
  816.  
  817. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  818. facewindow.viewport = msgwindow.viewport
  819. facewindow.z = msgwindow.z
  820.  
  821. when "g" # Display gold window
  822. goldwindow.dispose if goldwindow
  823. goldwindow = pbDisplayGoldWindow(msgwindow)
  824. when "cn" # Display coins window
  825. coinwindow.dispose if coinwindow
  826. coinwindow = pbDisplayCoinsWindow(msgwindow,goldwindow)
  827. when "wu"
  828. msgwindow.y = 0
  829. atTop = true
  830. msgback.y = msgwindow.y if msgback
  831. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  832. msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
  833. when "wm"
  834. atTop = false
  835. msgwindow.y = (Graphics.height-msgwindow.height)/2
  836. msgback.y = msgwindow.y if msgback
  837. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  838. when "wd"
  839. atTop = false
  840. msgwindow.y = Graphics.height-msgwindow.height
  841. msgback.y = msgwindow.y if msgback
  842. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  843. msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
  844. when "w" # Change windowskin
  845. if param==""
  846. msgwindow.windowskin = nil
  847. else
  848. msgwindow.setSkin("Graphics/Windowskins/#{param}",false)
  849. end
  850. when "ts" # Change text speed
  851. msgwindow.textspeed = (param=="") ? -999 : param.to_i
  852. when "." # Wait 0.25 seconds
  853. msgwindow.waitcount += Graphics.frame_rate/4
  854. when "|" # Wait 1 second
  855. msgwindow.waitcount += Graphics.frame_rate
  856. when "wt" # Wait X/20 seconds
  857. param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  858. msgwindow.waitcount += param.to_i*Graphics.frame_rate/20
  859. when "wtnp" # Wait X/20 seconds, no pause
  860. param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  861. msgwindow.waitcount = param.to_i*Graphics.frame_rate/20
  862. autoresume = true
  863. when "^" # Wait, no pause
  864. autoresume = true
  865. when "se" # Play SE
  866. pbSEPlay(pbStringToAudioFile(param))
  867. when "me" # Play ME
  868. pbMEPlay(pbStringToAudioFile(param))
  869. end
  870. controls[i] = nil
  871. end
  872. break if !letterbyletter
  873. Graphics.update
  874. Input.update
  875. facewindow.update if facewindow
  876. #===================GELA FACE5===============================
  877. facewindowL.update if facewindowL
  878. facewindowR.update if facewindowR
  879. #===================GELA FACE5===============================
  880. if $DEBUG && Input.trigger?(Input::F6)
  881. pbRecord(unformattedText)
  882. end
  883. if autoresume && msgwindow.waitcount==0
  884. msgwindow.resume if msgwindow.busy?
  885. break if !msgwindow.busy?
  886. end
  887. #======================HOLD B TO SKIP=============
  888. if Input.press?(Input::B)
  889. msgwindow.textspeed=-999
  890. msgwindow.update
  891. if msgwindow.busy?
  892. pbPlayDecisionSE() if msgwindow.pausing?
  893. msgwindow.resume
  894. else
  895. break if signWaitCount==0
  896. end
  897. end
  898. #======================HOLD B TO SKIP=============
  899. if Input.trigger?(Input::C) || Input.trigger?(Input::B)
  900. if msgwindow.busy?
  901. pbPlayDecisionSE if msgwindow.pausing?
  902. msgwindow.resume
  903. else
  904. break if signWaitCount==0
  905. end
  906. end
  907. pbUpdateSceneMap
  908. msgwindow.update
  909. yield if block_given?
  910. break if (!letterbyletter || commandProc || commands) && !msgwindow.busy?
  911. end
  912. Input.update # Must call Input.update again to avoid extra triggers
  913. msgwindow.letterbyletter=oldletterbyletter
  914. if commands
  915. $game_variables[cmdvariable]=pbShowCommands(msgwindow,commands,cmdIfCancel)
  916. $game_map.need_refresh = true if $game_map
  917. end
  918. if commandProc
  919. ret=commandProc.call(msgwindow)
  920. end
  921. msgback.dispose if msgback
  922. #======GELANAME5==========
  923. # NEW
  924. namewindow.dispose if namewindow
  925. #======GELANAME5==========
  926.  
  927. goldwindow.dispose if goldwindow
  928. #==========GELA FACE6===================================
  929. facewindowL.dispose if facewindowL
  930. facewindowR.dispose if facewindowR
  931. #============GELA FACE6=================================
  932. coinwindow.dispose if coinwindow
  933. facewindow.dispose if facewindow
  934. if haveSpecialClose
  935. pbSEPlay(pbStringToAudioFile(specialCloseSE))
  936. atTop = (msgwindow.y==0)
  937. for i in 0..signWaitTime
  938. if atTop
  939. msgwindow.y = -msgwindow.height*i/signWaitTime
  940. else
  941. msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-i)/signWaitTime
  942. end
  943. Graphics.update
  944. Input.update
  945. pbUpdateSceneMap
  946. msgwindow.update
  947. end
  948. end
  949. return ret
  950. end
  951.  
  952.  
  953.  
  954. #===============================================================================
  955. # Message-displaying functions
  956. #===============================================================================
  957. def pbMessage(message, commands = nil, cmdIfCancel = 0, skin = nil, defaultCmd = 0, &block)
  958. ret = 0
  959. msgwindow = pbCreateMessageWindow(nil, skin)
  960. if commands
  961. ret = pbMessageDisplay(msgwindow, message, true,
  962. proc { |msgwindow|
  963. next Kernel.pbShowCommands(msgwindow, commands, cmdIfCancel, defaultCmd, &block)
  964. }, &block)
  965. else
  966. pbMessageDisplay(msgwindow, message, &block)
  967. end
  968. pbDisposeMessageWindow(msgwindow)
  969. Input.update
  970. return ret
  971. end
  972.  
  973. def pbConfirmMessage(message, &block)
  974. return (pbMessage(message, [_INTL("Yes"), _INTL("No")], 2, &block) == 0)
  975. end
  976.  
  977. def pbConfirmMessageSerious(message, &block)
  978. return (pbMessage(message, [_INTL("No"), _INTL("Yes")], 1, &block) == 1)
  979. end
  980.  
  981. def pbMessageChooseNumber(message, params, &block)
  982. msgwindow = pbCreateMessageWindow(nil, params.messageSkin)
  983. ret = pbMessageDisplay(msgwindow, message, true,
  984. proc { |msgwindow|
  985. next pbChooseNumber(msgwindow, params, &block)
  986. }, &block)
  987. pbDisposeMessageWindow(msgwindow)
  988. return ret
  989. end
  990.  
  991. def pbShowCommands(msgwindow, commands = nil, cmdIfCancel = 0, defaultCmd = 0)
  992. return 0 if !commands
  993. cmdwindow = Window_CommandPokemonEx.new(commands)
  994. cmdwindow.z = 99999
  995. cmdwindow.visible = true
  996. cmdwindow.resizeToFit(cmdwindow.commands)
  997. pbPositionNearMsgWindow(cmdwindow, msgwindow, :right)
  998. cmdwindow.index = defaultCmd
  999. command = 0
  1000. loop do
  1001. Graphics.update
  1002. Input.update
  1003. cmdwindow.update
  1004. msgwindow&.update
  1005. yield if block_given?
  1006. if Input.trigger?(Input::BACK)
  1007. if cmdIfCancel > 0
  1008. command = cmdIfCancel - 1
  1009. break
  1010. elsif cmdIfCancel < 0
  1011. command = cmdIfCancel
  1012. break
  1013. end
  1014. end
  1015. if Input.trigger?(Input::USE)
  1016. command = cmdwindow.index
  1017. break
  1018. end
  1019. pbUpdateSceneMap
  1020. end
  1021. ret = command
  1022. cmdwindow.dispose
  1023. Input.update
  1024. return ret
  1025. end
  1026.  
  1027. def pbShowCommandsWithHelp(msgwindow, commands, help, cmdIfCancel = 0, defaultCmd = 0)
  1028. msgwin = msgwindow
  1029. msgwin = pbCreateMessageWindow(nil) if !msgwindow
  1030. oldlbl = msgwin.letterbyletter
  1031. msgwin.letterbyletter = false
  1032. if commands
  1033. cmdwindow = Window_CommandPokemonEx.new(commands)
  1034. cmdwindow.z = 99999
  1035. cmdwindow.visible = true
  1036. cmdwindow.resizeToFit(cmdwindow.commands)
  1037. cmdwindow.height = msgwin.y if cmdwindow.height > msgwin.y
  1038. cmdwindow.index = defaultCmd
  1039. command = 0
  1040. msgwin.text = help[cmdwindow.index]
  1041. msgwin.width = msgwin.width # Necessary evil to make it use the proper margins
  1042. loop do
  1043. Graphics.update
  1044. Input.update
  1045. oldindex = cmdwindow.index
  1046. cmdwindow.update
  1047. if oldindex != cmdwindow.index
  1048. msgwin.text = help[cmdwindow.index]
  1049. end
  1050. msgwin.update
  1051. yield if block_given?
  1052. if Input.trigger?(Input::BACK)
  1053. if cmdIfCancel > 0
  1054. command = cmdIfCancel - 1
  1055. break
  1056. elsif cmdIfCancel < 0
  1057. command = cmdIfCancel
  1058. break
  1059. end
  1060. end
  1061. if Input.trigger?(Input::USE)
  1062. command = cmdwindow.index
  1063. break
  1064. end
  1065. pbUpdateSceneMap
  1066. end
  1067. ret = command
  1068. cmdwindow.dispose
  1069. Input.update
  1070. end
  1071. msgwin.letterbyletter = oldlbl
  1072. msgwin.dispose if !msgwindow
  1073. return ret
  1074. end
  1075.  
  1076. # frames is the number of 1/20 seconds to wait for
  1077. def pbMessageWaitForInput(msgwindow, frames, showPause = false)
  1078. return if !frames || frames <= 0
  1079. msgwindow.startPause if msgwindow && showPause
  1080. frames = frames * Graphics.frame_rate / 20
  1081. frames.times do
  1082. Graphics.update
  1083. Input.update
  1084. msgwindow&.update
  1085. pbUpdateSceneMap
  1086. if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
  1087. break
  1088. end
  1089. yield if block_given?
  1090. end
  1091. msgwindow.stopPause if msgwindow && showPause
  1092. end
  1093.  
  1094. def pbFreeText(msgwindow, currenttext, passwordbox, maxlength, width = 240)
  1095. window = Window_TextEntry_Keyboard.new(currenttext, 0, 0, width, 64)
  1096. ret = ""
  1097. window.maxlength = maxlength
  1098. window.visible = true
  1099. window.z = 99999
  1100. pbPositionNearMsgWindow(window, msgwindow, :right)
  1101. window.text = currenttext
  1102. window.passwordChar = "*" if passwordbox
  1103. Input.text_input = true
  1104. loop do
  1105. Graphics.update
  1106. Input.update
  1107. if Input.triggerex?(:ESCAPE)
  1108. ret = currenttext
  1109. break
  1110. elsif Input.triggerex?(:RETURN)
  1111. ret = window.text
  1112. break
  1113. end
  1114. window.update
  1115. msgwindow&.update
  1116. yield if block_given?
  1117. end
  1118. Input.text_input = false
  1119. window.dispose
  1120. Input.update
  1121. return ret
  1122. end
  1123.  
  1124. def pbMessageFreeText(message, currenttext, passwordbox, maxlength, width = 240, &block)
  1125. msgwindow = pbCreateMessageWindow
  1126. retval = pbMessageDisplay(msgwindow, message, true,
  1127. proc { |msgwindow|
  1128. next pbFreeText(msgwindow, currenttext, passwordbox, maxlength, width, &block)
  1129. }, &block)
  1130. pbDisposeMessageWindow(msgwindow)
  1131. return retval
  1132. end
  1133.  
Advertisement
Add Comment
Please, Sign In to add comment