Guest User

Name windows v18

a guest
Jan 31st, 2022
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.71 KB | None | 0 0
  1. # Name-box by By Theo/MrGela @ theo#7722
  2. # Expected behaviour and use:
  3. # Use in a text command, with an added keyword like "\xn[Test]" in order to
  4. # display a small box to the top-left of the message window, displaying "Test".
  5. # This window will rely on the user's choice of text frame unless there's one
  6. # specified in DEFAULT_WINDOWSKIN below.
  7. #===============================================================================
  8. # HOW TO USE THIS?
  9. # \xn[Text,baseColor,shadowColor,fontName,fontSize,textAlignment,windowX,windowY,windowSkin]
  10. # EXAMPLES:
  11. # \xn[Prof. Oak,0073ff,7bbdef,Power Clear,,2]Test.
  12. # \wu\xn[Prof. Oak,,,,,2,18,162]Test.
  13. #===============================================================================
  14. # CONFIGURATION
  15. #===============================================================================
  16. # SHIFT NAMEWINDOW IN X AXIS (except when specifying a particular X location)
  17. OFFSET_NAMEWINDOW_X=0
  18. # SHIFT NAMEWINDOW IN Y AXIS (except when specifying a particular Y location)
  19. OFFSET_NAMEWINDOW_Y=0
  20. # WHETHER THE TEXT SHOULD BE CENTERED (0=right, 1=center, 2=right)
  21. DEFAULT_ALIGNMENT=1
  22. # ENSURES A MIN. WIDTH OF THE WINDOW
  23. MIN_WIDTH=200
  24. # DEFAULT FONT
  25. DEFAULT_FONT="Power Green Narrow" # "Power Clear", etc.
  26. # DEFAULT FONT SIZE
  27. DEFAULT_FONT_SIZE=nil
  28. # DEFAULT WINDOWSKIN (nil = based on the currently displayed message windowskin)
  29. # (File inside Graphics/Windowskins/)
  30. DEFAULT_WINDOWSKIN="speech em"
  31. #===============================================================================
  32. # END CONFIGURATION / Don't touch anything below this point or you'll get a bonk
  33. #===============================================================================
  34. # Params:
  35. # 0 = msgwindow (required)
  36. # 1 = string (required)
  37. # 2 = use dark windowskin? (boolean) (defaults to false)
  38. # 3 = color override
  39. # 4 = shadow override
  40. # 4 = font override
  41. # 5 = font size override
  42. # 6 = alignment (defaults to 0, left)
  43. # 7 and 8 = forced X and Y of the namewindow
  44. def pbDisplayNameWindow(params)
  45. name = params[1]
  46. isDark = params[2] if params[2]
  47. colorBase = colorToRgb32(MessageConfig::DARKTEXTBASE)
  48. colorBase = colorToRgb32(MessageConfig::LIGHT_TEXT_MAIN_COLOR) if isDark==true
  49. colorBase = params[3] if !params[3].nil?
  50. colowShadow = colorToRgb32(MessageConfig::DARKTEXTSHADOW)
  51. colorShadow = colorToRgb32(MessageConfig::LIGHT_TEXT_SHADOW_COLOR) if isDark==true
  52. colorShadow = params[4] if !params[4].nil?
  53. font = params[5] if !params[5].nil?
  54. font = DEFAULT_FONT if font.nil? || font=="0"
  55. fontSize = DEFAULT_FONT_SIZE
  56. fontSize = params[6] if !params[6].nil?
  57. position = params[7] if !params[7].nil?
  58. newX = 0
  59. newY = 0
  60. newX = params[8] if !params[8].nil?
  61. newY = params[9] if !params[9].nil?
  62. newSkin = params[10] if params[10] != (nil || "0")
  63. newSkin = DEFAULT_WINDOWSKIN if newSkin=="nil" || (newSkin==nil || newSkin=="0")
  64. msgwindow=params[0]
  65. fullName=(params[1].split(","))[0]
  66. # Handle text alignment
  67. align=""
  68. alignEnd=""
  69. case DEFAULT_ALIGNMENT
  70. when 0
  71. align="<al>"
  72. alignEnd="</al>"
  73. when 1
  74. align="<ac>"
  75. alignEnd="</ac>"
  76. when 2
  77. align="<ar>"
  78. alignEnd="</ar>"
  79. end
  80. # If position is defined, use that instead
  81. if !position.nil? || position!="nil"
  82. case position
  83. when "0"
  84. align="<al>"
  85. alignEnd="</al>"
  86. when "1", "", nil
  87. align="<ac>"
  88. alignEnd="</ac>"
  89. when "2"
  90. align="<ar>"
  91. alignEnd="</ar>"
  92. end
  93. end
  94. fullName.insert(0,align)
  95. fullName+=alignEnd
  96. # Handle text color
  97. # If base or shadow are empty somehow, load windowskin-sensitive colors
  98. if colorBase.nil? || colorBase.empty?
  99. colorBase=colorToRgb32(MessageConfig::DARKTEXTBASE)
  100. colorBase=colorToRgb32(MessageConfig::LIGHT_TEXT_MAIN_COLOR) if isDark==true
  101. end
  102. if colorShadow.nil? || colorShadow.empty?
  103. colorShadow=colorToRgb32(MessageConfig::DARKTEXTSHADOW)
  104. colorShadow=colorToRgb32(MessageConfig::LIGHT_TEXT_SHADOW_COLOR) if isDark==true
  105. end
  106. fullColor="<c3="+colorBase+","+colorShadow+">"
  107. fullName.insert(0,fullColor) unless fullColor=="<c3=0,0>"
  108. # Handle text font
  109. if font.nil? || font.empty?
  110. elsif font.is_a?(String)
  111. fullFont="<fn="+font+">"
  112. fullName.insert(0,fullFont)
  113. fullName+="</fn>"
  114. end
  115. # Handle text font size
  116. if fontSize.nil?
  117. elsif (fontSize.is_a?(Numeric) && fontSize!=0) || (fontSize.is_a?(String) && !fontSize.empty? && fontSize!="0")
  118. fullFontSize="<fs="+fontSize.to_s+">"
  119. fullName.insert(0,fullFontSize)
  120. fullName+="</fs>"
  121. end
  122. namewindow=Window_AdvancedTextPokemon.new(_INTL(fullName.to_s))
  123. if isDark==true
  124. namewindow.setSkin("Graphics/Windowskins/speech black")
  125. end
  126. if newSkin!=nil
  127. if newSkin==DEFAULT_WINDOWSKIN
  128. if isDark==true
  129. else
  130. namewindow.setSkin("Graphics/Windowskins/"+newSkin)
  131. end
  132. else
  133. namewindow.setSkin("Graphics/Windowskins/"+newSkin)
  134. end
  135. end
  136. namewindow.resizeToFit(namewindow.text,Graphics.width)
  137. namewindow.width=MIN_WIDTH if namewindow.width<=MIN_WIDTH
  138. namewindow.width = namewindow.width
  139. namewindow.y=msgwindow.y-namewindow.height
  140. if newX != (nil || "0") && !newX.empty?
  141. namewindow.x=newX.to_i
  142. else
  143. namewindow.x+=OFFSET_NAMEWINDOW_X
  144. end
  145. if newY != (nil || "0") && !newY.empty?
  146. namewindow.y=newY.to_i
  147. else
  148. namewindow.y+=OFFSET_NAMEWINDOW_Y
  149. end
  150.  
  151. namewindow.viewport=msgwindow.viewport
  152. namewindow.z=msgwindow.z
  153. return namewindow
  154. end
  155.  
  156. def pbMessageDisplay(msgwindow,message,letterbyletter=true,commandProc=nil)
  157. return if !msgwindow
  158. oldletterbyletter=msgwindow.letterbyletter
  159. msgwindow.letterbyletter=(letterbyletter) ? true : false
  160. ret=nil
  161. commands=nil
  162. facewindow=nil
  163. goldwindow=nil
  164. coinwindow=nil
  165. namewindow=nil
  166. battlepointswindow=nil
  167. cmdvariable=0
  168. cmdIfCancel=0
  169. msgwindow.waitcount=0
  170. autoresume=false
  171. text=message.clone
  172. msgback=nil
  173. linecount=(Graphics.height>400) ? 3 : 2
  174. ### Text replacement
  175. text.gsub!(/\\sign\[([^\]]*)\]/i) { # \sign[something] gets turned into
  176. next "\\op\\cl\\ts[]\\w["+$1+"]" # \op\cl\ts[]\w[something]
  177. }
  178. text.gsub!(/\\\\/,"\5")
  179. text.gsub!(/\\1/,"\1")
  180. if $game_actors
  181. text.gsub!(/\\n\[([1-8])\]/i) {
  182. m = $1.to_i
  183. next $game_actors[m].name
  184. }
  185. end
  186. text.gsub!(/\\pn/i,$Trainer.name) if $Trainer
  187. text.gsub!(/\\pm/i,_INTL("${1}",$Trainer.money.to_s_formatted)) if $Trainer
  188. text.gsub!(/\\n/i,"\n")
  189. text.gsub!(/\\\[([0-9a-f]{8,8})\]/i) { "<c2="+$1+">" }
  190. text.gsub!(/\\pg/i,"\\b") if $Trainer && $Trainer.male?
  191. text.gsub!(/\\pg/i,"\\r") if $Trainer && $Trainer.female?
  192. text.gsub!(/\\pog/i,"\\r") if $Trainer && $Trainer.male?
  193. text.gsub!(/\\pog/i,"\\b") if $Trainer && $Trainer.female?
  194. text.gsub!(/\\pg/i,"")
  195. text.gsub!(/\\pog/i,"")
  196. text.gsub!(/\\b/i,"<c3=3050C8,D0D0C8>")
  197. text.gsub!(/\\r/i,"<c3=E00808,D0D0C8>")
  198. text.gsub!(/\\[Ww]\[([^\]]*)\]/) {
  199. w = $1.to_s
  200. if w==""
  201. msgwindow.windowskin = nil
  202. else
  203. msgwindow.setSkin("Graphics/Windowskins/#{w}",false)
  204. end
  205. next ""
  206. }
  207. isDarkSkin = isDarkWindowskin(msgwindow.windowskin)
  208. text.gsub!(/\\[Cc]\[([0-9]+)\]/) {
  209. m = $1.to_i
  210. next getSkinColor(msgwindow.windowskin,m,isDarkSkin)
  211. }
  212. loop do
  213. last_text = text.clone
  214. text.gsub!(/\\v\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  215. break if text == last_text
  216. end
  217. loop do
  218. last_text = text.clone
  219. text.gsub!(/\\l\[([0-9]+)\]/i) {
  220. linecount = [1,$1.to_i].max
  221. next ""
  222. }
  223. break if text == last_text
  224. end
  225. colortag = ""
  226. if $game_system && $game_system.respond_to?("message_frame") &&
  227. $game_system.message_frame != 0
  228. colortag = getSkinColor(msgwindow.windowskin,0,true)
  229. else
  230. colortag = getSkinColor(msgwindow.windowskin,0,isDarkSkin)
  231. end
  232. text = colortag+text
  233. ### Controls
  234. textchunks=[]
  235. controls=[]
  236. while text[/(?:\\([Xn][Nn]|[Dd][Xx][Nn]|[Xn][Nn][Aa]|[Xn][Nn][Bb]|[Xn][Nn][Cc]|f|ff|ts|cl|me|se|wt|wtnp|ch)\[([^\]]*)\]|\\(g|cn|pt|wd|wm|op|cl|wu|\.|\||\!|\^))/i]
  237. textchunks.push($~.pre_match)
  238. if $~[1]
  239. controls.push([$~[1].downcase,$~[2],-1])
  240. else
  241. controls.push([$~[3].downcase,"",-1])
  242. end
  243. text=$~.post_match
  244. end
  245. textchunks.push(text)
  246. for chunk in textchunks
  247. chunk.gsub!(/\005/,"\\")
  248. end
  249. textlen = 0
  250. for i in 0...controls.length
  251. control = controls[i][0]
  252. case control
  253. when "wt", "wtnp", ".", "|"
  254. textchunks[i] += "\2"
  255. when "!"
  256. textchunks[i] += "\1"
  257. end
  258. textlen += toUnformattedText(textchunks[i]).scan(/./m).length
  259. controls[i][2] = textlen
  260. end
  261. text = textchunks.join("")
  262. signWaitCount = 0
  263. signWaitTime = Graphics.frame_rate/2
  264. haveSpecialClose = false
  265. specialCloseSE = ""
  266. for i in 0...controls.length
  267. control = controls[i][0]
  268. param = controls[i][1]
  269. case control
  270. when "op"
  271. signWaitCount = signWaitTime+1
  272. when "cl"
  273. text = text.sub(/\001\z/,"") # fix: '$' can match end of line as well
  274. haveSpecialClose = true
  275. specialCloseSE = param
  276. when "f"
  277. facewindow.dispose if facewindow
  278. facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
  279. when "ff"
  280. facewindow.dispose if facewindow
  281. facewindow = FaceWindowVX.new(param)
  282. when "ch"
  283. cmds = param.clone
  284. cmdvariable = pbCsvPosInt!(cmds)
  285. cmdIfCancel = pbCsvField!(cmds).to_i
  286. commands = []
  287. while cmds.length>0
  288. commands.push(pbCsvField!(cmds))
  289. end
  290. when "wtnp", "^"
  291. text = text.sub(/\001\z/,"") # fix: '$' can match end of line as well
  292. when "se"
  293. if controls[i][2]==0
  294. startSE = param
  295. controls[i] = nil
  296. end
  297. end
  298. end
  299. if startSE!=nil
  300. pbSEPlay(pbStringToAudioFile(startSE))
  301. elsif signWaitCount==0 && letterbyletter
  302. pbPlayDecisionSE()
  303. end
  304. ########## Position message window ##############
  305. pbRepositionMessageWindow(msgwindow,linecount)
  306. if facewindow
  307. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  308. facewindow.viewport = msgwindow.viewport
  309. facewindow.z = msgwindow.z
  310. end
  311. atTop = (msgwindow.y==0)
  312. ########## Show text #############################
  313. msgwindow.text = text
  314. Graphics.frame_reset if Graphics.frame_rate>40
  315. loop do
  316. if signWaitCount>0
  317. signWaitCount -= 1
  318. if atTop
  319. msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
  320. else
  321. msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
  322. end
  323. end
  324. for i in 0...controls.length
  325. next if !controls[i]
  326. next if controls[i][2]>msgwindow.position || msgwindow.waitcount!=0
  327. control = controls[i][0]
  328. param = controls[i][1]
  329. case control
  330. # NEW
  331. when "xn"
  332. # Show name box, displaying string
  333. string=controls[i][1]
  334. extra=string.split(",")
  335. # Feed them 0/nil to pass down and later ignore
  336. extra[1]="" if extra[1]=="" || !extra[1]
  337. extra[2]="" if extra[2]=="" || !extra[2]
  338. extra[3]="0" if extra[3]=="" || !extra[3]
  339. extra[4]="0" if extra[4]=="" || !extra[4]
  340. extra[5]="nil" if extra[5]=="" || !extra[5]
  341. extra[6]="0" if extra[6]=="" || !extra[6]
  342. extra[7]="0" if extra[7]=="" || !extra[7]
  343. extra[8]="0" if extra[8]=="" || !extra[8]
  344. colorBase=extra[1]
  345. colorShadow=extra[2]
  346. font=extra[3]
  347. fontSize=extra[4]
  348. alignment=extra[5]
  349. forcedX=extra[6]
  350. forcedY=extra[7]
  351. newSkin=extra[8]
  352. namewindow.dispose if namewindow
  353. namewindow=pbDisplayNameWindow([msgwindow,string,false,colorBase,colorShadow,font,fontSize,alignment,forcedX,forcedY,newSkin])
  354. when "dxn"
  355. # Show dark name box, displaying string
  356. string=controls[i][1]
  357. extra=string.split(",")
  358. # Feed them 0/nil to pass down and later ignore
  359. extra[1]="" if extra[1]=="" || !extra[1]
  360. extra[2]="" if extra[2]=="" || !extra[2]
  361. extra[3]="0" if extra[3]=="" || !extra[3]
  362. extra[4]="0" if extra[4]=="" || !extra[4]
  363. extra[5]="nil" if extra[5]=="" || !extra[5]
  364. extra[6]="0" if extra[6]=="" || !extra[6]
  365. extra[7]="0" if extra[7]=="" || !extra[7]
  366. extra[8]="0" if extra[8]=="" || !extra[8]
  367. colorBase=extra[1]
  368. colorShadow=extra[2]
  369. font=extra[3]
  370. fontSize=extra[4]
  371. alignment=extra[5]
  372. forcedX=extra[6]
  373. forcedY=extra[7]
  374. newSkin=extra[8]
  375. namewindow.dispose if namewindow
  376. namewindow=pbDisplayNameWindow([msgwindow,string,true,colorBase,colorShadow,font,fontSize,alignment,forcedX,forcedY,newSkin])
  377. # START SAMPLES / PRESETS
  378. # Three samples, use xna, xnb or xnc instead of xn or dxn in the text command
  379. # These do not take any additional parameters except for name
  380. # I created these samples so if, for example, you use a couple of commands
  381. # all the time (like to make the text blue/red for some NPCs) you don't
  382. # have to manually type them all the time, and can use these as shortcuts
  383. # instead!
  384. # Customize at your own peril but feel free to contact me on the
  385. # resource's thread for some directions.
  386. # namewindow=pbDisplayNameWindow([msgwindow,string,true,colorBase,colorShadow,font,fontSize,alignment,forcedX,forcedY,newSkin])
  387. # Only keep msgwindow, string and the true/false, and set the others (as "0"/nil)
  388. when "xna"
  389. # Sample, sets a particular color (red)
  390. string=controls[i][1]
  391. namewindow.dispose if namewindow
  392. namewindow=pbDisplayNameWindow([msgwindow,string,false,"ef2110","ffadbd","0","0",nil,"0","0","0"])
  393. when "xnb"
  394. # Sample, sets a particular color (blue)
  395. string=controls[i][1]
  396. namewindow.dispose if namewindow
  397. namewindow=pbDisplayNameWindow([msgwindow,string,false,"0073ff","7bbdef","0","0",nil,"0","0","0"])
  398. when "xnc"
  399. # Sample, window is placed at 96, 96, uses a different font and windowskin
  400. string=controls[i][1]
  401. namewindow.dispose if namewindow
  402. namewindow=pbDisplayNameWindow([msgwindow,string,false,"0","0","Power Clear","0",nil,"96","96","speech frlg"])
  403. # END SAMPLES / PRESETS
  404. when "f"
  405. facewindow.dispose if facewindow
  406. facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
  407. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  408. facewindow.viewport = msgwindow.viewport
  409. facewindow.z = msgwindow.z
  410. when "ff"
  411. facewindow.dispose if facewindow
  412. facewindow = FaceWindowVX.new(param)
  413. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  414. facewindow.viewport = msgwindow.viewport
  415. facewindow.z = msgwindow.z
  416. when "g" # Display gold window
  417. goldwindow.dispose if goldwindow
  418. goldwindow = pbDisplayGoldWindow(msgwindow)
  419. when "cn" # Display coins window
  420. coinwindow.dispose if coinwindow
  421. coinwindow = pbDisplayCoinsWindow(msgwindow,goldwindow)
  422. when "pt" # Display battle points window
  423. battlepointswindow.dispose if battlepointswindow
  424. battlepointswindow = pbDisplayBattlePointsWindow(msgwindow)
  425. when "wu"
  426. msgwindow.y = 0
  427. atTop = true
  428. msgback.y = msgwindow.y if msgback
  429. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  430. msgwindow.y = -msgwindow.height*signWaitCount/signWaitTime
  431. when "wm"
  432. atTop = false
  433. msgwindow.y = (Graphics.height-msgwindow.height)/2
  434. msgback.y = msgwindow.y if msgback
  435. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  436. when "wd"
  437. atTop = false
  438. msgwindow.y = Graphics.height-msgwindow.height
  439. msgback.y = msgwindow.y if msgback
  440. pbPositionNearMsgWindow(facewindow,msgwindow,:left)
  441. msgwindow.y = Graphics.height-msgwindow.height*(signWaitTime-signWaitCount)/signWaitTime
  442. when "ts" # Change text speed
  443. msgwindow.textspeed = (param=="") ? -999 : param.to_i
  444. when "." # Wait 0.25 seconds
  445. msgwindow.waitcount += Graphics.frame_rate/4
  446. when "|" # Wait 1 second
  447. msgwindow.waitcount += Graphics.frame_rate
  448. when "wt" # Wait X/20 seconds
  449. param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  450. msgwindow.waitcount += param.to_i*Graphics.frame_rate/20
  451. when "wtnp" # Wait X/20 seconds, no pause
  452. param = param.sub(/\A\s+/,"").sub(/\s+\z/,"")
  453. msgwindow.waitcount = param.to_i*Graphics.frame_rate/20
  454. autoresume = true
  455. when "^" # Wait, no pause
  456. autoresume = true
  457. when "se" # Play SE
  458. pbSEPlay(pbStringToAudioFile(param))
  459. when "me" # Play ME
  460. pbMEPlay(pbStringToAudioFile(param))
  461. end
  462. controls[i] = nil
  463. end
  464. break if !letterbyletter
  465. Graphics.update
  466. Input.update
  467. facewindow.update if facewindow
  468. if autoresume && msgwindow.waitcount==0
  469. msgwindow.resume if msgwindow.busy?
  470. break if !msgwindow.busy?
  471. end
  472. if Input.trigger?(Input::C) || Input.trigger?(Input::X)
  473. if msgwindow.busy?
  474. pbPlayDecisionSE if msgwindow.pausing?
  475. msgwindow.resume
  476. else
  477. break if signWaitCount==0
  478. end
  479. end
  480. pbUpdateSceneMap
  481. msgwindow.update
  482. yield if block_given?
  483. break if (!letterbyletter || commandProc || commands) && !msgwindow.busy?
  484. end
  485. Input.update # Must call Input.update again to avoid extra triggers
  486. msgwindow.letterbyletter=oldletterbyletter
  487. if commands
  488. $game_variables[cmdvariable]=pbShowCommands(msgwindow,commands,cmdIfCancel)
  489. $game_map.need_refresh = true if $game_map
  490. end
  491. if commandProc
  492. ret=commandProc.call(msgwindow)
  493. end
  494. msgback.dispose if msgback
  495. goldwindow.dispose if goldwindow
  496. coinwindow.dispose if coinwindow
  497. battlepointswindow.dispose if battlepointswindow
  498. facewindow.dispose if facewindow
  499. namewindow.dispose if namewindow
  500. if haveSpecialClose
  501. pbSEPlay(pbStringToAudioFile(specialCloseSE))
  502. atTop = (msgwindow.y==0)
  503. for i in 0..signWaitTime
  504. if atTop
  505. msgwindow_y = -msgwindow.height*i/signWaitTime
  506. else
  507. msgwindow_y = Graphics.height-msgwindow.height*(signWaitTime-i)/signWaitTime
  508. end
  509. Graphics.update
  510. Input.update
  511. pbUpdateSceneMap
  512. msgwindow.update
  513. end
  514. end
  515. return ret
  516. end
  517.  
Advertisement
Add Comment
Please, Sign In to add comment