Advertisement
Guest User

nada

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