Advertisement
Guest User

Untitled

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