Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.04 KB | None | 0 0
  1. class Window_PokemonOption < Window_DrawableCommand
  2. attr_reader :mustUpdateOptions
  3.  
  4. def initialize(options,x,y,width,height)
  5. @options=options
  6. @nameBaseColor=Color.new(24*8,15*8,0)
  7. @nameShadowColor=Color.new(31*8,22*8,10*8)
  8. @selBaseColor=Color.new(31*8,6*8,3*8)
  9. @selShadowColor=Color.new(31*8,17*8,16*8)
  10. @optvalues=[]
  11. @mustUpdateOptions=false
  12. for i in 0...@options.length
  13. @optvalues[i]=0
  14. end
  15. super(x,y,width,height)
  16. end
  17.  
  18. def [](i)
  19. return @optvalues[i]
  20. end
  21.  
  22. def []=(i,value)
  23. @optvalues[i]=value
  24. refresh
  25. end
  26.  
  27. def itemCount
  28. return @options.length+1
  29. end
  30.  
  31. def drawItem(index,count,rect)
  32. rect=drawCursor(index,rect)
  33. optionname=(index==@options.length) ? _INTL("Salir") : @options[index].name
  34. optionwidth=(rect.width*9/20)
  35. pbDrawShadowText(self.contents,rect.x,rect.y,optionwidth,rect.height,optionname,
  36. @nameBaseColor,@nameShadowColor)
  37. self.contents.draw_text(rect.x,rect.y,optionwidth,rect.height,optionname)
  38. return if index==@options.length
  39. if @options[index].is_a?(EnumOption)
  40. if @options[index].values.length>1
  41. totalwidth=0
  42. for value in @options[index].values
  43. totalwidth+=self.contents.text_size(value).width
  44. end
  45. spacing=(optionwidth-totalwidth)/(@options[index].values.length-1)
  46. spacing=0 if spacing<0
  47. xpos=optionwidth+rect.x
  48. ivalue=0
  49. for value in @options[index].values
  50. pbDrawShadowText(self.contents,xpos,rect.y,optionwidth,rect.height,value,
  51. (ivalue==self[index]) ? @selBaseColor : self.baseColor,
  52. (ivalue==self[index]) ? @selShadowColor : self.shadowColor
  53. )
  54. self.contents.draw_text(xpos,rect.y,optionwidth,rect.height,value)
  55. xpos+=self.contents.text_size(value).width
  56. xpos+=spacing
  57. ivalue+=1
  58. end
  59. else
  60. pbDrawShadowText(self.contents,rect.x+optionwidth,rect.y,optionwidth,rect.height,
  61. optionname,self.baseColor,self.shadowColor)
  62. end
  63. elsif @options[index].is_a?(NumberOption)
  64. value=sprintf("Tipo %d/%d",@options[index].optstart+self[index],
  65. @options[index].optend-@options[index].optstart+1)
  66. xpos=optionwidth+rect.x
  67. pbDrawShadowText(self.contents,xpos,rect.y,optionwidth,rect.height,value,
  68. @selBaseColor,@selShadowColor)
  69. elsif @options[index].is_a?(SliderOption)
  70. value=sprintf(" %d",@options[index].optend)
  71. sliderlength=optionwidth-self.contents.text_size(value).width
  72. xpos=optionwidth+rect.x
  73. self.contents.fill_rect(xpos,rect.y-2+rect.height/2,
  74. optionwidth-self.contents.text_size(value).width,4,self.baseColor)
  75. self.contents.fill_rect(
  76. xpos+(sliderlength-8)*(@options[index].optstart+self[index])/@options[index].optend,
  77. rect.y-8+rect.height/2,
  78. 8,16,@selBaseColor)
  79.  
  80. value=sprintf("%d",@options[index].optstart+self[index])
  81. xpos+=optionwidth-self.contents.text_size(value).width
  82. pbDrawShadowText(self.contents,xpos,rect.y,optionwidth,rect.height,value,
  83. @selBaseColor,@selShadowColor)
  84. else
  85. value=@options[index].values[self[index]]
  86. xpos=optionwidth+rect.x
  87. pbDrawShadowText(self.contents,xpos,rect.y,optionwidth,rect.height,value,
  88. @selBaseColor,@selShadowColor)
  89. self.contents.draw_text(xpos,rect.y,optionwidth,rect.height,value)
  90. end
  91. end
  92.  
  93. def update
  94. dorefresh=false
  95. oldindex=self.index
  96. @mustUpdateOptions=false
  97. super
  98. dorefresh=self.index!=oldindex
  99. if self.active && self.index<@options.length
  100. if Input.repeat?(Input::LEFT)
  101. self[self.index]=@options[self.index].prev(self[self.index])
  102. dorefresh=true
  103. @mustUpdateOptions=true
  104. elsif Input.repeat?(Input::RIGHT)
  105. self[self.index]=@options[self.index].next(self[self.index])
  106. dorefresh=true
  107. @mustUpdateOptions=true
  108. end
  109. end
  110. refresh if dorefresh
  111. end
  112. end
  113.  
  114.  
  115.  
  116. module PropertyMixin
  117. def get
  118. @getProc ? @getProc.call() : nil
  119. end
  120.  
  121. def set(value)
  122. @setProc.call(value) if @setProc
  123. end
  124. end
  125.  
  126.  
  127.  
  128. class EnumOption
  129. include PropertyMixin
  130. attr_reader :values
  131. attr_reader :name
  132.  
  133. def initialize(name,options,getProc,setProc)
  134. @values=options
  135. @name=name
  136. @getProc=getProc
  137. @setProc=setProc
  138. end
  139.  
  140. def next(current)
  141. index=current+1
  142. index=@values.length-1 if index>@values.length-1
  143. return index
  144. end
  145.  
  146. def prev(current)
  147. index=current-1
  148. index=0 if index<0
  149. return index
  150. end
  151. end
  152.  
  153.  
  154.  
  155. class EnumOption2
  156. include PropertyMixin
  157. attr_reader :values
  158. attr_reader :name
  159.  
  160. def initialize(name,options,getProc,setProc)
  161. @values=options
  162. @name=name
  163. @getProc=getProc
  164. @setProc=setProc
  165. end
  166.  
  167. def next(current)
  168. index=current+1
  169. index=@values.length-1 if index>@values.length-1
  170. return index
  171. end
  172.  
  173. def prev(current)
  174. index=current-1
  175. index=0 if index<0
  176. return index
  177. end
  178. end
  179.  
  180.  
  181.  
  182. class NumberOption
  183. include PropertyMixin
  184. attr_reader :name
  185. attr_reader :optstart
  186. attr_reader :optend
  187.  
  188. def initialize(name,optstart,optend,getProc,setProc)
  189. @name=name
  190. @optstart=optstart
  191. @optend=optend
  192. @getProc=getProc
  193. @setProc=setProc
  194. end
  195.  
  196. def next(current)
  197. index=current+@optstart
  198. index+=1
  199. if index>@optend
  200. index=@optstart
  201. end
  202. return index-@optstart
  203. end
  204.  
  205. def prev(current)
  206. index=current+@optstart
  207. index-=1
  208. if index<@optstart
  209. index=@optend
  210. end
  211. return index-@optstart
  212. end
  213. end
  214.  
  215.  
  216.  
  217. class SliderOption
  218. include PropertyMixin
  219. attr_reader :name
  220. attr_reader :optstart
  221. attr_reader :optend
  222.  
  223. def initialize(name,optstart,optend,optinterval,getProc,setProc)
  224. @name=name
  225. @optstart=optstart
  226. @optend=optend
  227. @optinterval=optinterval
  228. @getProc=getProc
  229. @setProc=setProc
  230. end
  231.  
  232. def next(current)
  233. index=current+@optstart
  234. index+=@optinterval
  235. if index>@optend
  236. index=@optend
  237. end
  238. return index-@optstart
  239. end
  240.  
  241. def prev(current)
  242. index=current+@optstart
  243. index-=@optinterval
  244. if index<@optstart
  245. index=@optstart
  246. end
  247. return index-@optstart
  248. end
  249. end
  250.  
  251. #####################
  252. #
  253. # Stores game options
  254. # Default options are at the top of script section SpriteWindow.
  255.  
  256. $SpeechFrames=[
  257. MessageConfig::TextSkinName, # Default: speech hgss 1
  258. "speech hgss 2",
  259. "speech hgss 3",
  260. "speech hgss 4",
  261. "speech hgss 5",
  262. "speech hgss 6",
  263. "speech hgss 7",
  264. "speech hgss 8",
  265. "speech hgss 9",
  266. "speech hgss 10",
  267. "speech hgss 11",
  268. "speech hgss 12",
  269. "speech hgss 13",
  270. "speech hgss 14",
  271. "speech hgss 15",
  272. "speech hgss 16",
  273. "speech hgss 17",
  274. "speech hgss 18",
  275. "speech hgss 19",
  276. "speech hgss 20",
  277. "speech pl 18"
  278. ]
  279.  
  280. $TextFrames=[
  281. "Graphics/Windowskins/"+MessageConfig::ChoiceSkinName, # Default: choice 1
  282. "Graphics/Windowskins/choice 2",
  283. "Graphics/Windowskins/choice 3",
  284. "Graphics/Windowskins/choice 4",
  285. "Graphics/Windowskins/choice 5",
  286. "Graphics/Windowskins/choice 6",
  287. "Graphics/Windowskins/choice 7",
  288. "Graphics/Windowskins/choice 8",
  289. "Graphics/Windowskins/choice 9",
  290. "Graphics/Windowskins/choice 10",
  291. "Graphics/Windowskins/choice 11",
  292. "Graphics/Windowskins/choice 12",
  293. "Graphics/Windowskins/choice 13",
  294. "Graphics/Windowskins/choice 14",
  295. "Graphics/Windowskins/choice 15",
  296. "Graphics/Windowskins/choice 16",
  297. "Graphics/Windowskins/choice 17",
  298. "Graphics/Windowskins/choice 18",
  299. "Graphics/Windowskins/choice 19",
  300. "Graphics/Windowskins/choice 20",
  301. "Graphics/Windowskins/choice 21",
  302. "Graphics/Windowskins/choice 22",
  303. "Graphics/Windowskins/choice 23",
  304. "Graphics/Windowskins/choice 24",
  305. "Graphics/Windowskins/choice 25",
  306. "Graphics/Windowskins/choice 26",
  307. "Graphics/Windowskins/choice 27",
  308. "Graphics/Windowskins/choice 28"
  309. ]
  310.  
  311. $VersionStyles=[
  312. [MessageConfig::FontName], # Default font style - Power Green/"Pokemon Emerald"
  313. ["Power Red and Blue"],
  314. ["Power Red and Green"],
  315. ["Power Clear"]
  316. ]
  317.  
  318. def pbSettingToTextSpeed(speed)
  319. return 2 if speed==0
  320. return 1 if speed==1
  321. return -2 if speed==2
  322. return MessageConfig::TextSpeed if MessageConfig::TextSpeed
  323. return ((Graphics.frame_rate>40) ? -2 : 1)
  324. end
  325.  
  326.  
  327.  
  328. module MessageConfig
  329. def self.pbDefaultSystemFrame
  330. if !$PokemonSystem
  331. return pbResolveBitmap("Graphics/Windowskins/"+MessageConfig::ChoiceSkinName)||""
  332. else
  333. return pbResolveBitmap($TextFrames[$PokemonSystem.frame])||""
  334. end
  335. end
  336.  
  337. def self.pbDefaultSpeechFrame
  338. if !$PokemonSystem
  339. return pbResolveBitmap("Graphics/Windowskins/"+MessageConfig::TextSkinName)||""
  340. else
  341. return pbResolveBitmap("Graphics/Windowskins/"+$SpeechFrames[$PokemonSystem.textskin])||""
  342. end
  343. end
  344.  
  345. def self.pbDefaultSystemFontName
  346. if !$PokemonSystem
  347. return MessageConfig.pbTryFonts(MessageConfig::FontName,"BerlinSmallCaps")
  348. else
  349. return MessageConfig.pbTryFonts($VersionStyles[$PokemonSystem.font][0],"BerlinSmallCaps")
  350. end
  351. end
  352.  
  353. def self.pbDefaultTextSpeed
  354. return pbSettingToTextSpeed($PokemonSystem ? $PokemonSystem.textspeed : nil)
  355. end
  356.  
  357. def pbGetSystemTextSpeed
  358. return $PokemonSystem ? $PokemonSystem.textspeed : ((Graphics.frame_rate>40) ? 2 : 3)
  359. end
  360. end
  361.  
  362.  
  363.  
  364. class PokemonSystem
  365. attr_accessor :textspeed
  366. attr_accessor :battlescene
  367. attr_accessor :battlestyle
  368. attr_accessor :frame
  369. attr_accessor :textskin
  370. attr_accessor :font
  371. attr_accessor :screensize
  372. attr_accessor :language
  373. attr_accessor :border
  374. attr_accessor :runstyle
  375. attr_accessor :bgmvolume
  376. attr_accessor :sevolume
  377.  
  378. def language
  379. return (!@language) ? 0 : @language
  380. end
  381.  
  382. def textskin
  383. return (!@textskin) ? 0 : @textskin
  384. end
  385.  
  386. def border
  387. return (!@border) ? 0 : @border
  388. end
  389.  
  390. def runstyle
  391. return (!@runstyle) ? 0 : @runstyle
  392. end
  393.  
  394. def bgmvolume
  395. return (!@bgmvolume) ? 100 : @bgmvolume
  396. end
  397.  
  398. def sevolume
  399. return (!@sevolume) ? 100 : @sevolume
  400. end
  401.  
  402. def tilemap; return MAPVIEWMODE; end
  403.  
  404. def initialize
  405. @textspeed = 1 # Text speed (0=slow, 1=normal, 2=fast)
  406. @battlescene = 0 # Battle effects (animations) (0=on, 1=off)
  407. @battlestyle = 0 # Battle style (0=switch, 1=set)
  408. @frame = 2 # Default window frame (see also $TextFrames)
  409. @textskin = 2 # Speech frame
  410. @font = 0 # Font (see also $VersionStyles)
  411. @screensize = (DEFAULTSCREENZOOM.floor).to_i # 0=half size, 1=full size, 2=double size
  412. @border = 0 # Screen border (0=off, 1=on)
  413. @language = 0 # Language (see also LANGUAGES in script PokemonSystem)
  414. @runstyle = 1 # Run key functionality (0=hold to run, 1=toggle auto-run)
  415. @bgmvolume = 100 # Volume of background music and ME
  416. @sevolume = 100 # Volume of sound effects
  417. end
  418. end
  419.  
  420.  
  421.  
  422. class PokemonOptionScene
  423. def pbUpdate
  424. pbUpdateSpriteHash(@sprites)
  425. end
  426.  
  427. def pbStartScene(inloadscreen=false)
  428. @sprites={}
  429. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  430. @viewport.z=99999
  431. @sprites["title"]=Window_UnformattedTextPokemon.newWithSize(
  432. _INTL("Opciones"),0,0,Graphics.width,64,@viewport)
  433. @sprites["textbox"]=Kernel.pbCreateMessageWindow
  434. @sprites["textbox"].letterbyletter=false
  435. @sprites["textbox"].text=_INTL("Marco de diálogo {1}.",1+$PokemonSystem.textskin)
  436. # Éstas son las distintas opciones del juego. Para agregar una opción, se debe definir un
  437. # setter y un getter para esa opción. Para borrar una opción, comentarla
  438. # o borrarla. Las opciones del juego se pueden ubicar en cualquier orden.
  439. @PokemonOptions=[
  440. SliderOption.new(_INTL("Volumen Música"),0,100,5,
  441. proc { $PokemonSystem.bgmvolume },
  442. proc {|value|
  443. if $PokemonSystem.bgmvolume!=value
  444. $PokemonSystem.bgmvolume=value
  445. if $game_system.playing_bgm != nil && !inloadscreen
  446. $game_system.playing_bgm.volume=value
  447. playingBGM=$game_system.getPlayingBGM
  448. $game_system.bgm_pause
  449. $game_system.bgm_resume(playingBGM)
  450. end
  451. end
  452. }
  453. ),
  454. SliderOption.new(_INTL("Volumen Efec. Esp."),0,100,5,
  455. proc { $PokemonSystem.sevolume },
  456. proc {|value|
  457. if $PokemonSystem.sevolume!=value
  458. $PokemonSystem.sevolume=value
  459. if $game_system.playing_bgs != nil
  460. $game_system.playing_bgs.volume=value
  461. playingBGS=$game_system.getPlayingBGS
  462. $game_system.bgs_pause
  463. $game_system.bgs_resume(playingBGS)
  464. end
  465. pbPlayCursorSE()
  466. end
  467. }
  468. ),
  469. EnumOption.new(_INTL("Velocidad del texto"),[_INTL("Lenta"),_INTL("Normal"),_INTL("Rápida")],
  470. proc { $PokemonSystem.textspeed },
  471. proc {|value|
  472. $PokemonSystem.textspeed=value
  473. MessageConfig.pbSetTextSpeed(pbSettingToTextSpeed(value))
  474. }
  475. ),
  476. EnumOption.new(_INTL("Animación de batalla"),[_INTL("Sí"),_INTL("No")],
  477. proc { $PokemonSystem.battlescene },
  478. proc {|value| $PokemonSystem.battlescene=value }
  479. ),
  480. EnumOption.new(_INTL("Estilo de batalla"),[_INTL("Cambio"),_INTL("Mantener")],
  481. proc { $PokemonSystem.battlestyle },
  482. proc {|value| $PokemonSystem.battlestyle=value }
  483. ),
  484. EnumOption.new(_INTL("Tecla Correr"),[_INTL("Sostener"),_INTL("Pulsar")],
  485. proc { $PokemonSystem.runstyle },
  486. proc {|value|
  487. if $PokemonSystem.runstyle!=value
  488. $PokemonSystem.runstyle=value
  489. $PokemonGlobal.runtoggle=false if $PokemonGlobal
  490. end
  491. }
  492. ),
  493. NumberOption.new(_INTL("Marco de diálogo"),1,$SpeechFrames.length,
  494. proc { $PokemonSystem.textskin },
  495. proc {|value|
  496. $PokemonSystem.textskin=value
  497. MessageConfig.pbSetSpeechFrame("Graphics/Windowskins/"+$SpeechFrames[value])
  498. }
  499. ),
  500. NumberOption.new(_INTL("Marco del menú"),1,$TextFrames.length,
  501. proc { $PokemonSystem.frame },
  502. proc {|value|
  503. $PokemonSystem.frame=value
  504. MessageConfig.pbSetSystemFrame($TextFrames[value])
  505. }
  506. ),
  507. EnumOption.new(_INTL("Estilo de fuente"),[_INTL("PRO"),_INTL("R/S"),_INTL("FRLG"),_INTL("DP")],
  508. proc { $PokemonSystem.font },
  509. proc {|value|
  510. $PokemonSystem.font=value
  511. MessageConfig.pbSetSystemFontName($VersionStyles[value])
  512. }
  513. ),
  514. # ------------------------------------------------------------------------------
  515. # Quote this section out if you don't want to allow players to change the screen
  516. # size.
  517. EnumOption.new(_INTL("Tamaño de ventana"),[_INTL("P"),_INTL("M"),_INTL("G"),_INTL("MG"),_INTL("Compl")],
  518. proc { $PokemonSystem.screensize },
  519. proc {|value|
  520. oldvalue=$PokemonSystem.screensize
  521. $PokemonSystem.screensize=value
  522. if value!=oldvalue
  523. pbSetResizeFactor($PokemonSystem.screensize)
  524. ObjectSpace.each_object(TilemapLoader){|o| next if o.disposed?; o.updateClass }
  525. end
  526. }
  527. ),
  528. # ------------------------------------------------------------------------------
  529. EnumOption.new(_INTL("Borde de pantalla"),[_INTL("No"),_INTL("Si")],
  530. proc { $PokemonSystem.border },
  531. proc {|value|
  532. oldvalue=$PokemonSystem.border
  533. $PokemonSystem.border=value
  534. if value!=oldvalue
  535. pbSetResizeFactor($PokemonSystem.screensize)
  536. ObjectSpace.each_object(TilemapLoader){|o| next if o.disposed?; o.updateClass }
  537. end
  538. }
  539. )
  540. ]
  541. @PokemonOptions=pbAddOnOptions(@PokemonOptions)
  542. @sprites["option"]=Window_PokemonOption.new(@PokemonOptions,0,
  543. @sprites["title"].height,Graphics.width,
  544. Graphics.height-@sprites["title"].height-@sprites["textbox"].height)
  545. @sprites["option"].viewport=@viewport
  546. @sprites["option"].visible=true
  547. # Get the values of each option
  548. for i in 0...@PokemonOptions.length
  549. @sprites["option"][i]=(@PokemonOptions[i].get || 0)
  550. end
  551. pbDeactivateWindows(@sprites)
  552. pbFadeInAndShow(@sprites) { pbUpdate }
  553. end
  554.  
  555. def pbAddOnOptions(options)
  556. return options
  557. end
  558.  
  559. def pbOptions
  560. pbActivateWindow(@sprites,"option"){
  561. loop do
  562. Graphics.update
  563. Input.update
  564. pbUpdate
  565. if @sprites["option"].mustUpdateOptions
  566. # Set the values of each option
  567. for i in 0...@PokemonOptions.length
  568. @PokemonOptions[i].set(@sprites["option"][i])
  569. end
  570. @sprites["textbox"].setSkin(MessageConfig.pbGetSpeechFrame())
  571. @sprites["textbox"].width=@sprites["textbox"].width # Necessary evil
  572. pbSetSystemFont(@sprites["textbox"].contents)
  573. @sprites["textbox"].text=_INTL("Cuadro diálogo {1}.",1+$PokemonSystem.textskin)
  574. end
  575. if Input.trigger?(Input::B)
  576. break
  577. end
  578. if Input.trigger?(Input::C) && @sprites["option"].index==@PokemonOptions.length
  579. break
  580. end
  581. end
  582. }
  583. end
  584.  
  585. def pbEndScene
  586. pbFadeOutAndHide(@sprites) { pbUpdate }
  587. # Set the values of each option
  588. for i in 0...@PokemonOptions.length
  589. @PokemonOptions[i].set(@sprites["option"][i])
  590. end
  591. Kernel.pbDisposeMessageWindow(@sprites["textbox"])
  592. pbDisposeSpriteHash(@sprites)
  593. pbRefreshSceneMap
  594. @viewport.dispose
  595. end
  596. end
  597.  
  598.  
  599.  
  600. class PokemonOption
  601. def initialize(scene)
  602. @scene=scene
  603. end
  604.  
  605. def pbStartScreen(inloadscreen=false)
  606. @scene.pbStartScene(inloadscreen)
  607. @scene.pbOptions
  608. @scene.pbEndScene
  609. end
  610. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement