Advertisement
Nyaruko69

Untitled

Apr 20th, 2020
92
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. 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,"Arial Narrow","Arial")
  348. else
  349. return MessageConfig.pbTryFonts($VersionStyles[$PokemonSystem.font][0],"Arial Narrow","Arial")
  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. attr_accessor :calidad
  378.  
  379. def language
  380. return (!@language) ? 0 : @language
  381. end
  382.  
  383. def textskin
  384. return (!@textskin) ? 0 : @textskin
  385. end
  386.  
  387. def border
  388. return (!@border) ? 0 : @border
  389. end
  390.  
  391. def runstyle
  392. return (!@runstyle) ? 0 : @runstyle
  393. end
  394.  
  395. def bgmvolume
  396. return (!@bgmvolume) ? 100 : @bgmvolume
  397. end
  398.  
  399. def sevolume
  400. return (!@sevolume) ? 100 : @sevolume
  401. end
  402.  
  403. def tilemap; return MAPVIEWMODE; end
  404.  
  405. def initialize
  406. @textspeed = 1 # Text speed (0=slow, 1=normal, 2=fast)
  407. @battlescene = 0 # Battle effects (animations) (0=on, 1=off)
  408. @battlestyle = 0 # Battle style (0=switch, 1=set)
  409. @frame = 0 # Default window frame (see also $TextFrames)
  410. @textskin = 0 # Speech frame
  411. @font = 0 # Font (see also $VersionStyles)
  412. @screensize = (DEFAULTSCREENZOOM.floor).to_i # 0=half size, 1=full size, 2=double size
  413. @border = 0 # Screen border (0=off, 1=on)
  414. @language = 0 # Language (see also LANGUAGES in script PokemonSystem)
  415. @runstyle = 0 # Run key functionality (0=hold to run, 1=toggle auto-run)
  416. @bgmvolume = 100 # Volume of background music and ME
  417. @sevolume = 100 # Volume of sound effects
  418. @calidad = 0 # 0 es alta, la predeterminada
  419. end
  420. end
  421.  
  422.  
  423.  
  424. class PokemonOptionScene
  425. def pbUpdate
  426. pbUpdateSpriteHash(@sprites)
  427. end
  428.  
  429. def pbStartScene(inloadscreen=false)
  430. @sprites={}
  431. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  432. @viewport.z=99999
  433. @sprites["title"]=Window_UnformattedTextPokemon.newWithSize(
  434. _INTL("Opciones"),0,0,Graphics.width,64,@viewport)
  435. @sprites["textbox"]=Kernel.pbCreateMessageWindow
  436. @sprites["textbox"].letterbyletter=false
  437. @sprites["textbox"].text=_INTL("Marco de diálogo {1}.",1+$PokemonSystem.textskin)
  438. # Éstas son las distintas opciones del juego. Para agregar una opción, se debe definir un
  439. # setter y un getter para esa opción. Para borrar una opción, comentarla
  440. # o borrarla. Las opciones del juego se pueden ubicar en cualquier orden.
  441. @PokemonOptions=[
  442. SliderOption.new(_INTL("Volumen Música"),0,100,5,
  443. proc { $PokemonSystem.bgmvolume },
  444. proc {|value|
  445. if $PokemonSystem.bgmvolume!=value
  446. $PokemonSystem.bgmvolume=value
  447. if $game_system.playing_bgm != nil && !inloadscreen
  448. $game_system.playing_bgm.volume=value
  449. playingBGM=$game_system.getPlayingBGM
  450. $game_system.bgm_pause
  451. $game_system.bgm_resume(playingBGM)
  452. end
  453. end
  454. }
  455. ),
  456. SliderOption.new(_INTL("Volumen Efec. Esp."),0,100,5,
  457. proc { $PokemonSystem.sevolume },
  458. proc {|value|
  459. if $PokemonSystem.sevolume!=value
  460. $PokemonSystem.sevolume=value
  461. if $game_system.playing_bgs != nil
  462. $game_system.playing_bgs.volume=value
  463. playingBGS=$game_system.getPlayingBGS
  464. $game_system.bgs_pause
  465. $game_system.bgs_resume(playingBGS)
  466. end
  467. pbPlayCursorSE()
  468. end
  469. }
  470. ),
  471. EnumOption.new(_INTL("Velocidad del texto"),[_INTL("Lenta"),_INTL("Normal"),_INTL("Rápida")],
  472. proc { $PokemonSystem.textspeed },
  473. proc {|value|
  474. $PokemonSystem.textspeed=value
  475. MessageConfig.pbSetTextSpeed(pbSettingToTextSpeed(value))
  476. }
  477. ),
  478. EnumOption.new(_INTL("Animación de batalla"),[_INTL("Sí"),_INTL("No")],
  479. proc { $PokemonSystem.battlescene },
  480. proc {|value| $PokemonSystem.battlescene=value }
  481. ),
  482. EnumOption.new(_INTL("Estilo de batalla"),[_INTL("Cambio"),_INTL("Mantener")],
  483. proc { $PokemonSystem.battlestyle },
  484. proc {|value| $PokemonSystem.battlestyle=value }
  485. ),
  486. EnumOption.new(_INTL("Tecla Correr"),[_INTL("Sostener"),_INTL("Pulsar")],
  487. proc { $PokemonSystem.runstyle },
  488. proc {|value|
  489. if $PokemonSystem.runstyle!=value
  490. $PokemonSystem.runstyle=value
  491. $PokemonGlobal.runtoggle=false if $PokemonGlobal
  492. end
  493. }
  494. ),
  495. EnumOption.new(_INTL("Detalles gráficos"),[_INTL("Si"),_INTL("No")],
  496. proc { $PokemonSystem.calidad },
  497. proc {|value|
  498. if $PokemonSystem.calidad!=value
  499. $PokemonSystem.calidad=value
  500. $game_variables[50] = value
  501. end
  502. }
  503. ),
  504. EnumOption.new(_INTL("Estilo de fuente"),[_INTL("Em"),_INTL("R/S"),_INTL("FRLG"),_INTL("DP")],
  505. proc { $PokemonSystem.font },
  506. proc {|value|
  507. $PokemonSystem.font=value
  508. MessageConfig.pbSetSystemFontName($VersionStyles[value])
  509. }
  510. ),
  511. # ------------------------------------------------------------------------------
  512. # Quote this section out if you don't want to allow players to change the screen
  513. # size.
  514.  
  515. # ------------------------------------------------------------------------------
  516. EnumOption.new(_INTL("Borde de pantalla"),[_INTL("No"),_INTL("Si")],
  517. proc { $PokemonSystem.border },
  518. proc {|value|
  519. oldvalue=$PokemonSystem.border
  520. $PokemonSystem.border=value
  521. if value!=oldvalue
  522. pbSetResizeFactor($PokemonSystem.screensize)
  523. ObjectSpace.each_object(TilemapLoader){|o| next if o.disposed?; o.updateClass }
  524. end
  525. }
  526. )
  527. ]
  528. @PokemonOptions=pbAddOnOptions(@PokemonOptions)
  529. @sprites["option"]=Window_PokemonOption.new(@PokemonOptions,0,
  530. @sprites["title"].height,Graphics.width,
  531. Graphics.height-@sprites["title"].height-@sprites["textbox"].height)
  532. @sprites["option"].viewport=@viewport
  533. @sprites["option"].visible=true
  534. # Get the values of each option
  535. for i in 0...@PokemonOptions.length
  536. @sprites["option"][i]=(@PokemonOptions[i].get || 0)
  537. end
  538. pbDeactivateWindows(@sprites)
  539. pbFadeInAndShow(@sprites) { pbUpdate }
  540. end
  541.  
  542. def pbAddOnOptions(options)
  543. return options
  544. end
  545.  
  546. def pbOptions
  547. pbActivateWindow(@sprites,"option"){
  548. loop do
  549. Graphics.update
  550. Input.update
  551. pbUpdate
  552. if @sprites["option"].mustUpdateOptions
  553. # Set the values of each option
  554. for i in 0...@PokemonOptions.length
  555. @PokemonOptions[i].set(@sprites["option"][i])
  556. end
  557. @sprites["textbox"].setSkin(MessageConfig.pbGetSpeechFrame())
  558. @sprites["textbox"].width=@sprites["textbox"].width # Necessary evil
  559. pbSetSystemFont(@sprites["textbox"].contents)
  560. @sprites["textbox"].text=_INTL("Cuadro diálogo {1}.",1+$PokemonSystem.textskin)
  561. end
  562. if Input.trigger?(Input::B)
  563. break
  564. end
  565. if Input.trigger?(Input::C) && @sprites["option"].index==@PokemonOptions.length
  566. break
  567. end
  568. end
  569. }
  570. end
  571.  
  572. def pbEndScene
  573. pbFadeOutAndHide(@sprites) { pbUpdate }
  574. # Set the values of each option
  575. for i in 0...@PokemonOptions.length
  576. @PokemonOptions[i].set(@sprites["option"][i])
  577. end
  578. Kernel.pbDisposeMessageWindow(@sprites["textbox"])
  579. pbDisposeSpriteHash(@sprites)
  580. pbRefreshSceneMap
  581. @viewport.dispose
  582. end
  583. end
  584.  
  585.  
  586.  
  587. class PokemonOption
  588. def initialize(scene)
  589. @scene=scene
  590. end
  591.  
  592. def pbStartScreen(inloadscreen=false)
  593. @scene.pbStartScene(inloadscreen)
  594. @scene.pbOptions
  595. @scene.pbEndScene
  596. end
  597. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement