Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.74 KB | None | 0 0
  1. module MessageConfig
  2. FontName = "Power Green"
  3. # in Graphics/Windowskins/ (specify empty string to use the default windowskin)
  4. TextSkinName = "speech hgss 2"
  5. ChoiceSkinName = "choice"
  6. WindowOpacity = 255
  7. TextSpeed = nil # can be positive to wait frames or negative to
  8. # show multiple characters in a single frame
  9. LIGHTTEXTBASE = Color.new(248,248,248)
  10. LIGHTTEXTSHADOW = Color.new(72,80,88)
  11. DARKTEXTBASE = Color.new(88,88,80)
  12. DARKTEXTSHADOW = Color.new(168,184,184)
  13. # 0 = Pause cursor is displayed at end of text
  14. # 1 = Pause cursor is displayed at bottom right
  15. # 2 = Pause cursor is displayed at lower middle side
  16. CURSORMODE = 1
  17. FontSubstitutes = {
  18. "Power Red and Blue" => "Pokemon RS",
  19. "Power Red and Green" => "Pokemon FireLeaf",
  20. "Power Green" => "Pokemon Emerald",
  21. "Power Green Narrow" => "Pokemon Emerald Narrow",
  22. "Power Green Small" => "Pokemon Emerald Small",
  23. "Power Clear" => "Pokemon DP"
  24. }
  25. @@systemFrame = nil
  26. @@defaultTextSkin = nil
  27. @@systemFont = nil
  28. @@textSpeed = nil
  29.  
  30. def self.pbTryFonts(*args)
  31. for a in args
  32. if a && a.is_a?(String)
  33. return a if Font.exist?(a)
  34. a=MessageConfig::FontSubstitutes[a] || a
  35. return a if Font.exist?(a)
  36. elsif a && a.is_a?(Array)
  37. for aa in a
  38. ret=MessageConfig.pbTryFonts(aa)
  39. return ret if ret!=""
  40. end
  41. end
  42. end
  43. return ""
  44. end
  45.  
  46. def self.pbDefaultSystemFrame
  47. return "" if !MessageConfig::ChoiceSkinName
  48. return pbResolveBitmap("Graphics/Windowskins/"+MessageConfig::ChoiceSkinName) || ""
  49. end
  50.  
  51. def self.pbDefaultSpeechFrame
  52. return "" if !MessageConfig::TextSkinName
  53. return pbResolveBitmap("Graphics/Windowskins/"+MessageConfig::TextSkinName) || ""
  54. end
  55.  
  56. def self.pbDefaultSystemFontName
  57. return MessageConfig.pbTryFonts(MessageConfig::FontName,"Arial Narrow","Arial")
  58. end
  59.  
  60. def self.pbDefaultTextSpeed
  61. return (TextSpeed) ? TextSpeed : (Graphics.width>400) ? -2 : 1
  62. end
  63.  
  64. def self.pbDefaultWindowskin
  65. skin=load_data("Data/System.rxdata").windowskin_name rescue nil
  66. if skin && skin!=""
  67. skin=pbResolveBitmap("Graphics/Windowskins/"+skin) || ""
  68. end
  69. skin=pbResolveBitmap("Graphics/System/Window") if !skin || skin==""
  70. skin=pbResolveBitmap("Graphics/Windowskins/001-Blue01") if !skin || skin==""
  71. return skin || ""
  72. end
  73.  
  74. def self.pbGetSystemFrame
  75. if !@@systemFrame
  76. skin=MessageConfig.pbDefaultSystemFrame
  77. skin=MessageConfig.pbDefaultWindowskin if !skin || skin==""
  78. @@systemFrame=skin || ""
  79. end
  80. return @@systemFrame
  81. end
  82.  
  83. def self.pbGetSpeechFrame
  84. if !@@defaultTextSkin
  85. skin=MessageConfig.pbDefaultSpeechFrame
  86. skin=MessageConfig.pbDefaultWindowskin if !skin || skin==""
  87. @@defaultTextSkin=skin || ""
  88. end
  89. return @@defaultTextSkin
  90. end
  91.  
  92. def self.pbGetSystemFontName
  93. @@systemFont=pbDefaultSystemFontName if !@@systemFont
  94. return @@systemFont
  95. end
  96.  
  97. def self.pbGetTextSpeed
  98. @@textSpeed=pbDefaultTextSpeed if !@@textSpeed
  99. return @@textSpeed
  100. end
  101.  
  102. def self.pbSetSystemFrame(value)
  103. @@systemFrame=pbResolveBitmap(value) || ""
  104. end
  105.  
  106. def self.pbSetSpeechFrame(value)
  107. @@defaultTextSkin=pbResolveBitmap(value) || ""
  108. end
  109.  
  110. def self.pbSetSystemFontName(value)
  111. @@systemFont=MessageConfig.pbTryFonts(value,"Arial Narrow","Arial")
  112. end
  113.  
  114. def self.pbSetTextSpeed(value)
  115. @@textSpeed=value
  116. end
  117. end
  118.  
  119.  
  120.  
  121. #===============================================================================
  122. # Position a window
  123. #===============================================================================
  124. def pbBottomRight(window)
  125. window.x=Graphics.width-window.width
  126. window.y=Graphics.height-window.height
  127. end
  128.  
  129. def pbBottomLeft(window)
  130. window.x=0
  131. window.y=Graphics.height-window.height
  132. end
  133.  
  134. def pbBottomLeftLines(window,lines,width=nil)
  135. window.x=0
  136. window.width=width ? width : Graphics.width
  137. window.height=(window.borderY rescue 32)+lines*32
  138. window.y=Graphics.height-window.height
  139. end
  140.  
  141. def pbPositionFaceWindow(facewindow,msgwindow)
  142. return if !facewindow
  143. if msgwindow
  144. if facewindow.height<=msgwindow.height
  145. facewindow.y=msgwindow.y
  146. else
  147. facewindow.y=msgwindow.y+msgwindow.height-facewindow.height
  148. end
  149. facewindow.x=Graphics.width-facewindow.width
  150. msgwindow.x=0
  151. msgwindow.width=Graphics.width-facewindow.width
  152. else
  153. facewindow.height=Graphics.height if facewindow.height>Graphics.height
  154. facewindow.x=0
  155. facewindow.y=0
  156. end
  157. end
  158.  
  159. def pbPositionNearMsgWindow(cmdwindow,msgwindow,side)
  160. return if !cmdwindow
  161. if msgwindow
  162. height=[cmdwindow.height,Graphics.height-msgwindow.height].min
  163. if cmdwindow.height!=height
  164. cmdwindow.height=height
  165. end
  166. cmdwindow.y=msgwindow.y-cmdwindow.height
  167. if cmdwindow.y<0
  168. cmdwindow.y=msgwindow.y+msgwindow.height
  169. if cmdwindow.y+cmdwindow.height>Graphics.height
  170. cmdwindow.y=msgwindow.y-cmdwindow.height
  171. end
  172. end
  173. case side
  174. when :left
  175. cmdwindow.x=msgwindow.x
  176. when :right
  177. cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width
  178. else
  179. cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width
  180. end
  181. else
  182. cmdwindow.height=Graphics.height if cmdwindow.height>Graphics.height
  183. cmdwindow.x=0
  184. cmdwindow.y=0
  185. end
  186. end
  187.  
  188. # internal function
  189. def pbRepositionMessageWindow(msgwindow, linecount=2)
  190. msgwindow.height=32*linecount+msgwindow.borderY
  191. msgwindow.y=(Graphics.height)-(msgwindow.height)
  192. if $game_system && $game_system.respond_to?("message_position")
  193. case $game_system.message_position
  194. when 0 # up
  195. msgwindow.y=0
  196. when 1 # middle
  197. msgwindow.y=(Graphics.height/2)-(msgwindow.height/2)
  198. when 2
  199. msgwindow.y=(Graphics.height)-(msgwindow.height)
  200. end
  201. end
  202. if $game_system && $game_system.respond_to?("message_frame")
  203. if $game_system.message_frame != 0
  204. msgwindow.opacity = 0
  205. end
  206. end
  207. if $game_message
  208. case $game_message.background
  209. when 1; msgwindow.opacity=0 # dim
  210. when 2; msgwindow.opacity=0 # transparent
  211. end
  212. end
  213. end
  214.  
  215. # internal function
  216. def pbUpdateMsgWindowPos(msgwindow,event,eventChanged=false)
  217. if event
  218. if eventChanged
  219. msgwindow.resizeToFit2(msgwindow.text,Graphics.width*2/3,msgwindow.height)
  220. end
  221. msgwindow.y=event.screen_y-48-msgwindow.height
  222. if msgwindow.y<0
  223. msgwindow.y=event.screen_y+24
  224. end
  225. msgwindow.x=event.screen_x-(msgwindow.width/2)
  226. msgwindow.x=0 if msgwindow.x<0
  227. if msgwindow.x>Graphics.width-msgwindow.width
  228. msgwindow.x=Graphics.width-msgwindow.width
  229. end
  230. else
  231. curwidth=msgwindow.width
  232. if curwidth!=Graphics.width
  233. msgwindow.width=Graphics.width
  234. msgwindow.width=Graphics.width
  235. end
  236. end
  237. end
  238.  
  239.  
  240.  
  241. #===============================================================================
  242. # Determine the colour of a background
  243. #===============================================================================
  244. def isDarkBackground(background,rect=nil)
  245. return true if !background || background.disposed?
  246. rect=background.rect if !rect
  247. return true if rect.width<=0 || rect.height<=0
  248. xSeg=(rect.width/16)
  249. xLoop=(xSeg==0) ? 1 : 16
  250. xStart=(xSeg==0) ? rect.x+(rect.width/2) : rect.x+xSeg/2
  251. ySeg=(rect.height/16)
  252. yLoop=(ySeg==0) ? 1 : 16
  253. yStart=(ySeg==0) ? rect.y+(rect.height/2) : rect.y+ySeg/2
  254. count=0
  255. y=yStart
  256. r=0; g=0; b=0
  257. yLoop.times {
  258. x=xStart
  259. xLoop.times {
  260. clr=background.get_pixel(x,y)
  261. if clr.alpha!=0
  262. r+=clr.red; g+=clr.green; b+=clr.blue
  263. count+=1
  264. end
  265. x+=xSeg
  266. }
  267. y+=ySeg
  268. }
  269. return true if count==0
  270. r/=count
  271. g/=count
  272. b/=count
  273. return (r*0.299+g*0.587+b*0.114)<128
  274. end
  275.  
  276. def isDarkWindowskin(windowskin)
  277. return true if !windowskin || windowskin.disposed?
  278. if windowskin.width==192 && windowskin.height==128
  279. return isDarkBackground(windowskin,Rect.new(0,0,128,128))
  280. elsif windowskin.width==128 && windowskin.height==128
  281. return isDarkBackground(windowskin,Rect.new(0,0,64,64))
  282. elsif windowskin.width==96 && windowskin.height==48
  283. return isDarkBackground(windowskin,Rect.new(32,16,16,16))
  284. else
  285. clr=windowskin.get_pixel(windowskin.width/2, windowskin.height/2)
  286. return (clr.red*0.299+clr.green*0.587+clr.blue*0.114)<128
  287. end
  288. end
  289.  
  290. def getSkinColor(windowskin,color,isDarkSkin)
  291. if !windowskin || windowskin.disposed? ||
  292. windowskin.width!=128 || windowskin.height!=128
  293. textcolors=[
  294. isDarkSkin ? shadowc3tag(MessageConfig::LIGHTTEXTBASE, MessageConfig::LIGHTTEXTSHADOW) :
  295. shadowc3tag(MessageConfig::DARKTEXTBASE, MessageConfig::DARKTEXTSHADOW),
  296. "<c2=7E105D08>", # Blue
  297. "<c2=421F2117>", # Red
  298. "<c2=43F022E8>", # Green
  299. "<c2=7FF05EE8>", # Cyan
  300. "<c2=7E1F5D17>", # Magenta
  301. "<c2=43FF22F7>", # Yellow
  302. "<c2=63184210>", # Grey
  303. "<c2=7FFF5EF7>" # White
  304. ]
  305. color=0 if color>textcolors.length
  306. return textcolors[color]
  307. else # VX windowskin
  308. color=0 if color>=32
  309. x = 64 + (color % 8) * 8
  310. y = 96 + (color / 8) * 8
  311. pixel=windowskin.get_pixel(x, y)
  312. return shadowctagFromColor(pixel)
  313. end
  314. end
  315.  
  316.  
  317.  
  318. #===============================================================================
  319. # Determine which text colours to use based on the darkness of the background
  320. #===============================================================================
  321. def getDefaultTextColors(windowskin)
  322. if !windowskin || windowskin.disposed? ||
  323. windowskin.width!=128 || windowskin.height!=128
  324. if isDarkWindowskin(windowskin)
  325. return [MessageConfig::LIGHTTEXTBASE,MessageConfig::LIGHTTEXTSHADOW] # White
  326. else
  327. return [MessageConfig::DARKTEXTBASE,MessageConfig::DARKTEXTSHADOW] # Dark gray
  328. end
  329. else # VX windowskin
  330. color=windowskin.get_pixel(64, 96)
  331. shadow=nil
  332. isdark=(color.red+color.green+color.blue)/3 < 128
  333. if isdark
  334. shadow=Color.new(color.red+64,color.green+64,color.blue+64)
  335. else
  336. shadow=Color.new(color.red-64,color.green-64,color.blue-64)
  337. end
  338. return [color,shadow]
  339. end
  340. end
  341.  
  342.  
  343.  
  344. #===============================================================================
  345. # Makes sure a bitmap exists
  346. #===============================================================================
  347. def pbDoEnsureBitmap(bitmap,dwidth,dheight)
  348. if !bitmap || bitmap.disposed? || bitmap.width<dwidth || bitmap.height<dheight
  349. oldfont = (bitmap && !bitmap.disposed?) ? bitmap.font : nil
  350. bitmap.dispose if bitmap
  351. bitmap = Bitmap.new([1,dwidth].max,[1,dheight].max)
  352. (oldfont) ? bitmap.font = oldfont : pbSetSystemFont(bitmap)
  353. bitmap.font.shadow = false if bitmap.font && bitmap.font.respond_to?("shadow")
  354. end
  355. return bitmap
  356. end
  357.  
  358.  
  359.  
  360. #===============================================================================
  361. # Set a bitmap's font
  362. #===============================================================================
  363. # Gets the name of the system small font.
  364. def pbSmallFontName
  365. return MessageConfig.pbTryFonts("Power Green Small","Pokemon Emerald Small",
  366. "Arial Narrow","Arial")
  367. end
  368.  
  369. # Gets the name of the system narrow font.
  370. def pbNarrowFontName
  371. return MessageConfig.pbTryFonts("Power Green Narrow","Pokemon Emerald Narrow",
  372. "Arial Narrow","Arial")
  373. end
  374.  
  375. # Sets a bitmap's font to the system font.
  376. def pbSetSystemFont(bitmap)
  377. fontname=MessageConfig.pbGetSystemFontName
  378. bitmap.font.name=fontname
  379. if fontname=="Pokemon FireLeaf" || fontname=="Power Red and Green"
  380. bitmap.font.size=29
  381. elsif fontname=="Pokemon Emerald Small" || fontname=="Power Green Small"
  382. bitmap.font.size=25
  383. else
  384. bitmap.font.size=31
  385. end
  386. end
  387.  
  388. # Sets a bitmap's font to the system small font.
  389. def pbSetSmallFont(bitmap)
  390. bitmap.font.name=pbSmallFontName
  391. bitmap.font.size=25
  392. end
  393.  
  394. # Sets a bitmap's font to the system narrow font.
  395. def pbSetNarrowFont(bitmap)
  396. bitmap.font.name=pbNarrowFontName
  397. bitmap.font.size=31
  398. end
  399.  
  400.  
  401.  
  402. #===============================================================================
  403. # Blend colours, set the colour of all bitmaps in a sprite hash
  404. #===============================================================================
  405. def pbAlphaBlend(dstColor,srcColor)
  406. r=(255*(srcColor.red-dstColor.red)/255)+dstColor.red
  407. g=(255*(srcColor.green-dstColor.green)/255)+dstColor.green
  408. b=(255*(srcColor.blue-dstColor.blue)/255)+dstColor.blue
  409. a=(255*(srcColor.alpha-dstColor.alpha)/255)+dstColor.alpha
  410. return Color.new(r,g,b,a)
  411. end
  412.  
  413. def pbSrcOver(dstColor,srcColor)
  414. er=srcColor.red*srcColor.alpha/255
  415. eg=srcColor.green*srcColor.alpha/255
  416. eb=srcColor.blue*srcColor.alpha/255
  417. iea=255-srcColor.alpha
  418. cr=dstColor.red*dstColor.alpha/255
  419. cg=dstColor.green*dstColor.alpha/255
  420. cb=dstColor.blue*dstColor.alpha/255
  421. ica=255-dstColor.alpha
  422. a=255-(iea*ica)/255
  423. r=(iea*cr)/255+er
  424. g=(iea*cg)/255+eg
  425. b=(iea*cb)/255+eb
  426. r=(a==0) ? 0 : r*255/a
  427. g=(a==0) ? 0 : g*255/a
  428. b=(a==0) ? 0 : b*255/a
  429. return Color.new(r,g,b,a)
  430. end
  431.  
  432. def pbSetSpritesToColor(sprites,color)
  433. return if !sprites || !color
  434. colors={}
  435. for i in sprites
  436. next if !i[1] || pbDisposed?(i[1])
  437. colors[i[0]]=i[1].color.clone
  438. i[1].color=pbSrcOver(i[1].color,color)
  439. end
  440. Graphics.update
  441. Input.update
  442. for i in colors
  443. next if !sprites[i[0]]
  444. sprites[i[0]].color=i[1]
  445. end
  446. end
  447.  
  448.  
  449.  
  450. #===============================================================================
  451. # Update and dispose sprite hashes
  452. #===============================================================================
  453. def using(window)
  454. begin
  455. yield if block_given?
  456. ensure
  457. window.dispose
  458. end
  459. end
  460.  
  461. def pbUpdateSpriteHash(windows)
  462. for i in windows
  463. window=i[1]
  464. if window
  465. if window.is_a?(Sprite) || window.is_a?(Window)
  466. window.update if !pbDisposed?(window)
  467. elsif window.is_a?(Plane)
  468. begin
  469. window.update if !window.disposed?
  470. rescue NoMethodError
  471. end
  472. elsif window.respond_to?("update")
  473. begin
  474. window.update
  475. rescue RGSSError
  476. end
  477. end
  478. end
  479. end
  480. end
  481.  
  482. # Disposes all objects in the specified hash.
  483. def pbDisposeSpriteHash(sprites)
  484. if sprites
  485. for i in sprites.keys
  486. pbDisposeSprite(sprites,i)
  487. end
  488. sprites.clear
  489. end
  490. end
  491.  
  492. # Disposes the specified graphics object within the specified hash. Basically like:
  493. # sprites[id].dispose
  494. def pbDisposeSprite(sprites,id)
  495. sprite=sprites[id]
  496. if sprite && !pbDisposed?(sprite)
  497. sprite.dispose
  498. end
  499. sprites[id]=nil
  500. end
  501.  
  502. def pbDisposed?(x)
  503. return true if !x
  504. if x.is_a?(Viewport)
  505. begin
  506. x.rect=x.rect
  507. rescue
  508. return true
  509. end
  510. return false
  511. else
  512. return x.disposed?
  513. end
  514. end
  515.  
  516.  
  517.  
  518. #===============================================================================
  519. # Fades and window activations for sprite hashes
  520. #===============================================================================
  521. class Game_Temp
  522. attr_accessor :fadestate
  523.  
  524. def fadestate
  525. return (@fadestate) ? @fadestate : 0
  526. end
  527. end
  528.  
  529.  
  530.  
  531. def pbPushFade
  532. $game_temp.fadestate = [$game_temp.fadestate+1,0].max if $game_temp
  533. end
  534.  
  535. def pbPopFade
  536. $game_temp.fadestate = [$game_temp.fadestate-1,0].max if $game_temp
  537. end
  538.  
  539. def pbIsFaded?
  540. return ($game_temp) ? $game_temp.fadestate>0 : false
  541. end
  542.  
  543. # pbFadeOutIn(z) { block }
  544. # Fades out the screen before a block is run and fades it back in after the
  545. # block exits. z indicates the z-coordinate of the viewport used for this effect
  546. def pbFadeOutIn(z,nofadeout=false)
  547. col=Color.new(0,0,0,0)
  548. viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  549. viewport.z=z
  550. for j in 0..17
  551. col.set(0,0,0,j*15)
  552. viewport.color=col
  553. Graphics.update
  554. Input.update
  555. end
  556. pbPushFade
  557. begin
  558. yield if block_given?
  559. ensure
  560. pbPopFade
  561. if !nofadeout
  562. for j in 0..17
  563. col.set(0,0,0,(17-j)*15)
  564. viewport.color=col
  565. Graphics.update
  566. Input.update
  567. end
  568. end
  569. viewport.dispose
  570. end
  571. end
  572.  
  573. def pbFadeOutInWithUpdate(z,sprites,nofadeout=false)
  574. col=Color.new(0,0,0,0)
  575. viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  576. viewport.z=z
  577. for j in 0..17
  578. col.set(0,0,0,j*15)
  579. viewport.color=col
  580. pbUpdateSpriteHash(sprites)
  581. Graphics.update
  582. Input.update
  583. end
  584. pbPushFade
  585. begin
  586. yield if block_given?
  587. ensure
  588. pbPopFade
  589. if !nofadeout
  590. for j in 0..17
  591. col.set(0,0,0,(17-j)*15)
  592. viewport.color=col
  593. pbUpdateSpriteHash(sprites)
  594. Graphics.update
  595. Input.update
  596. end
  597. end
  598. viewport.dispose
  599. end
  600. end
  601.  
  602. def pbFadeOutAndHide(sprites)
  603. visiblesprites={}
  604. pbDeactivateWindows(sprites){
  605. for j in 0..17
  606. pbSetSpritesToColor(sprites,Color.new(0,0,0,j*15))
  607. (block_given?) ? yield : pbUpdateSpriteHash(sprites)
  608. end
  609. }
  610. for i in sprites
  611. next if !i[1]
  612. next if pbDisposed?(i[1])
  613. visiblesprites[i[0]]=true if i[1].visible
  614. i[1].visible=false
  615. end
  616. return visiblesprites
  617. end
  618.  
  619. def pbFadeInAndShow(sprites,visiblesprites=nil)
  620. if visiblesprites
  621. for i in visiblesprites
  622. if i[1] && sprites[i[0]] && !pbDisposed?(sprites[i[0]])
  623. sprites[i[0]].visible=true
  624. end
  625. end
  626. end
  627. pbDeactivateWindows(sprites){
  628. for j in 0..17
  629. pbSetSpritesToColor(sprites,Color.new(0,0,0,((17-j)*15)))
  630. (block_given?) ? yield : pbUpdateSpriteHash(sprites)
  631. end
  632. }
  633. end
  634.  
  635. # Restores which windows are active for the given sprite hash.
  636. # _activeStatuses_ is the result of a previous call to pbActivateWindows
  637. def pbRestoreActivations(sprites,activeStatuses)
  638. return if !sprites || !activeStatuses
  639. for k in activeStatuses.keys
  640. if sprites[k] && sprites[k].is_a?(Window) && !pbDisposed?(sprites[k])
  641. sprites[k].active=activeStatuses[k] ? true : false
  642. end
  643. end
  644. end
  645.  
  646. # Deactivates all windows. If a code block is given, deactivates all windows,
  647. # runs the code in the block, and reactivates them.
  648. def pbDeactivateWindows(sprites)
  649. if block_given?
  650. pbActivateWindow(sprites,nil) { yield }
  651. else
  652. pbActivateWindow(sprites,nil)
  653. end
  654. end
  655.  
  656. # Activates a specific window of a sprite hash. _key_ is the key of the window
  657. # in the sprite hash. If a code block is given, deactivates all windows except
  658. # the specified window, runs the code in the block, and reactivates them.
  659. def pbActivateWindow(sprites,key)
  660. return if !sprites
  661. activeStatuses={}
  662. for i in sprites
  663. if i[1] && i[1].is_a?(Window) && !pbDisposed?(i[1])
  664. activeStatuses[i[0]]=i[1].active
  665. i[1].active=(i[0]==key)
  666. end
  667. end
  668. if block_given?
  669. begin
  670. yield
  671. ensure
  672. pbRestoreActivations(sprites,activeStatuses)
  673. end
  674. return {}
  675. else
  676. return activeStatuses
  677. end
  678. end
  679.  
  680.  
  681.  
  682. #===============================================================================
  683. # Create background planes for a sprite hash
  684. #===============================================================================
  685. # Adds a background to the sprite hash.
  686. # _planename_ is the hash key of the background.
  687. # _background_ is a filename within the Graphics/Pictures/ folder and can be
  688. # an animated image.
  689. # _viewport_ is a viewport to place the background in.
  690. def addBackgroundPlane(sprites,planename,background,viewport=nil)
  691. sprites[planename]=AnimatedPlane.new(viewport)
  692. bitmapName=pbResolveBitmap("Graphics/Pictures/#{background}")
  693. if bitmapName==nil
  694. # Plane should exist in any case
  695. sprites[planename].bitmap=nil
  696. sprites[planename].visible=false
  697. else
  698. sprites[planename].setBitmap(bitmapName)
  699. for spr in sprites.values
  700. if spr.is_a?(Window)
  701. spr.windowskin=nil
  702. end
  703. end
  704. end
  705. end
  706.  
  707. # Adds a background to the sprite hash.
  708. # _planename_ is the hash key of the background.
  709. # _background_ is a filename within the Graphics/Pictures/ folder and can be
  710. # an animated image.
  711. # _color_ is the color to use if the background can't be found.
  712. # _viewport_ is a viewport to place the background in.
  713. def addBackgroundOrColoredPlane(sprites,planename,background,color,viewport=nil)
  714. bitmapName=pbResolveBitmap("Graphics/Pictures/#{background}")
  715. if bitmapName==nil
  716. # Plane should exist in any case
  717. sprites[planename]=ColoredPlane.new(color,@viewport)
  718. else
  719. sprites[planename]=AnimatedPlane.new(viewport)
  720. sprites[planename].setBitmap(bitmapName)
  721. for spr in sprites.values
  722. if spr.is_a?(Window)
  723. spr.windowskin=nil
  724. end
  725. end
  726. end
  727. end
  728.  
  729.  
  730.  
  731. #===============================================================================
  732. # Ensure required method definitions
  733. #===============================================================================
  734. module Graphics
  735. if !self.respond_to?("width")
  736. def self.width; return 640; end
  737. end
  738. if !self.respond_to?("height")
  739. def self.height; return 480; end
  740. end
  741. end
  742.  
  743.  
  744.  
  745. if !defined?(_INTL)
  746. def _INTL(*args)
  747. string=args[0].clone
  748. for i in 1...args.length
  749. string.gsub!(/\{#{i}\}/,"#{args[i]}")
  750. end
  751. return string
  752. end
  753. end
  754.  
  755. if !defined?(_ISPRINTF)
  756. def _ISPRINTF(*args)
  757. string=args[0].clone
  758. for i in 1...args.length
  759. string.gsub!(/\{#{i}\:([^\}]+?)\}/){|m|
  760. next sprintf("%"+$1,args[i])
  761. }
  762. end
  763. return string
  764. end
  765. end
  766.  
  767. if !defined?(_MAPINTL)
  768. def _MAPINTL(*args)
  769. string=args[1].clone
  770. for i in 2...args.length
  771. string.gsub!(/\{#{i}\}/,"#{args[i+1]}")
  772. end
  773. return string
  774. end
  775. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement