Nyaruko69

Untitled

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