Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################### Yankas' Radial Menu Script ##############################
- ########## VERSION 1.0
- #####################################################################################
- class MenuEntry
- attr_accessor :angle
- attr_reader :name
- attr_reader :icon
- end
- class MenuEntryPokemon < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item267"
- @name = "Pokémon"
- end
- def selected(menu)
- hiddenmove = nil
- pbFadeOutIn(99999){
- sscene = PokemonParty_Scene.new
- sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
- hiddenmove = sscreen.pbPokemonScreen
- return (hiddenmove)
- }
- if hiddenmove
- $game_temp.in_menu = false
- Kernel.pbUseHiddenMove(hiddenmove[0],hiddenmove[1])
- return
- end
- end
- end
- class MenuEntryPokedex < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item509"
- @name = "Pokédex"
- end
- def selected(menu)
- if $PokemonGlobal.pokedexViable.length==1
- $PokemonGlobal.pokedexDex = $PokemonGlobal.pokedexViable[0]
- $PokemonGlobal.pokedexDex = -1 if $PokemonGlobal.pokedexDex==$PokemonGlobal.pokedexUnlocked.length-1
- pbFadeOutIn(99999){
- scene = PokemonPokedex_Scene.new
- screen = PokemonPokedexScreen.new(scene)
- screen.pbStartScreen
- }
- else
- pbFadeOutIn(99999){
- scene = PokemonPokedexMenu_Scene.new
- screen = PokemonPokedexMenuScreen.new(scene)
- screen.pbStartScreen
- }
- end
- return false
- end
- end
- class MenuEntryBag < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item513"
- @name = "Bag"
- end
- def selected(menu)
- item = 0
- pbFadeOutIn(99999){
- scene = PokemonBag_Scene.new
- screen = PokemonBagScreen.new(scene,$PokemonBag)
- item = screen.pbStartScreen
- return (item>0)
- }
- if item>0
- Kernel.pbUseKeyItemInField(item)
- return true
- end
- end
- end
- class MenuEntryTrainer < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item520"
- @name = $Trainer.name
- end
- def selected(menu)
- pbFadeOutIn(99999){
- scene = PokemonTrainerCard_Scene.new
- screen = PokemonTrainerCardScreen.new(scene)
- screen.pbStartScreen
- return false
- }
- end
- end
- class MenuEntrySave < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item204"
- @name = "Save"
- end
- def selected(menu)
- menu.pbHideMenu(true)
- scene = PokemonSave_Scene.new
- screen = PokemonSaveScreen.new(scene)
- if screen.pbSaveScreen
- return true
- end
- menu.pbHideMenu(false)
- end
- end
- class MenuEntryQuit < MenuEntry
- def initialize
- @icon = "Graphics/Icons/itemBack"
- @name = "Exit Game"
- end
- def selected(menu)
- menu.pbHideMenu(true)
- if Kernel.pbConfirmMessage(_INTL("Are you sure you want to quit the game?"))
- scene = PokemonSave_Scene.new
- screen = PokemonSaveScreen.new(scene)
- if screen.pbSaveScreen
- return true
- end
- $scene = nil
- return true
- end
- menu.pbHideMenu(false)
- end
- end
- class MenuEntryPokegear < MenuEntry
- def initialize
- @icon = "Graphics/Icons/itemPokegear"
- @name = "Pokégear"
- end
- def selected(menu)
- pbFadeOutIn(99999){
- scene = PokemonPokegear_Scene.new
- screen = PokemonPokegearScreen.new(scene)
- screen.pbStartScreen
- return false
- }
- end
- end
- class MenuEntryOption < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item207"
- @name = "Options"
- end
- def selected(menu)
- pbFadeOutIn(99999){
- scene = PokemonOption_Scene.new
- screen = PokemonOptionScreen.new(scene)
- screen.pbStartScreen
- return false
- }
- end
- end
- class MenuEntryDebug < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item000"
- @name = "Debug"
- end
- def selected(menu)
- pbFadeOutIn(99999){
- pbDebugMenu
- return false
- }
- end
- end
- class MenuEntryExitSafari < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item009"
- @name = "Quit Safari"
- end
- def selected(menu)
- if pbInSafari?
- if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
- menu.pbEndScene
- pbSafariState.decision = 1
- pbSafariState.pbGoToStart
- return false
- end
- return false # Since we already exited the scene, we shouldn't return an exit command.
- end
- end
- end
- class MenuEntryExitBugContest < MenuEntry
- def initialize
- @icon = "Graphics/Icons/item009"
- @name = "Quit Contest"
- end
- def selected(menu)
- if pbInBugContest?
- if Kernel.pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
- menu.pbEndScene
- pbBugContestState.pbStartJudging
- end
- return false # Since we already exited the scene, we shouldn't return an exit command.
- end
- end
- end
- class Component
- attr_accessor :viewport
- attr_accessor :sprites
- def initialize(viewport, spritehash)
- @viewport = viewport
- @sprites = spritehash
- end
- def dispose
- @sprites = nil
- end
- end
- class Clock < Component
- def initialize(viewport, spritehash, format)
- super(viewport, spritehash)
- ############# CLOCK CONFIGURATION SECTION ################
- @timeFormat = "%I:%M %p"
- #### FORMAT => EXAMPLE ######
- # "%I:%M %p" => 07:08 pm
- # "%I:%M:%S %p" => 07:08:20 pm
- # "%H:%M:%S" => 19:08:20
- # "%H:%M => 19:08
- ############# END CONFIG#################
- @time = pbGetTimeNow
- @sprites["clock"] = BitmapSprite.new(256,64,viewport)
- @sprites["clock"].x = 380
- @sprites["clock"].y = (pbInBugContest?) ? (Graphics.height - 64) : 10
- @textColor = Color.new(244,244,244)
- @highlightColor = Color.new(30,30,30)
- end
- def update
- @time = pbGetTimeNow
- text = @time.strftime(@timeFormat)
- textDay = @time.strftime("%A")
- @sprites["clock"].bitmap.clear
- pbSetSystemFont(@sprites["clock"].bitmap)
- pbDrawTextPositions(@sprites["clock"].bitmap,[[text,0,0,0,@textColor,@highlightColor],[textDay,0,32,0,@textColor,@highlightColor]])
- end
- end
- class SafariHud < Component
- def initialize(viewport, spritehash)
- super
- @sprites["safari"] = BitmapSprite.new(256,64,viewport)
- @sprites["safari"].x = 10
- @sprites["safari"].y = 10
- @textColor = Color.new(244,244,244)
- @highlightColor = Color.new(30,30,30)
- @oldText
- @oldText2
- end
- def update
- text = _INTL("Balls: {1}",pbSafariState.ballcount)
- text2 = (SAFARISTEPS>0) ? _INTL("Steps: {1}/{2}", pbSafariState.steps,SAFARISTEPS) : ""
- if(@oldText != text || @oldText2 != text2)
- @oldText = text
- @oldText2 = text2
- @sprites["safari"].bitmap.clear
- pbSetSystemFont(@sprites["safari"].bitmap)
- pbDrawTextPositions(@sprites["safari"].bitmap,[[text,0,0,0,@textColor,@highlightColor],[text2,0,32,0,@textColor,@highlightColor]])
- end
- end
- end
- class BugContestHud < Component
- def initialize(viewport, spritehash)
- super
- @sprites["safari"] = BitmapSprite.new(256,96,viewport)
- @sprites["safari"].x = 10
- @sprites["safari"].y = 10
- @textColor = Color.new(244,244,244)
- @highlightColor = Color.new(30,30,30)
- @oldText = ""
- @oldText2 = ""
- @oldText3 = ""
- end
- def update
- if(pbBugContestState.lastPokemon)
- text = _INTL("Caught: {1}", PBSpecies.getName(pbBugContestState.lastPokemon.species))
- text2 = _INTL("Level: {1}", pbBugContestState.lastPokemon.level)
- text3 = _INTL("Balls: {1}", pbBugContestState.ballcount)
- else
- text = "Caught: None"
- text2 = _INTL("Balls: {1}",pbBugContestState.ballcount)
- text3 = ""
- end
- if(@oldText != text || @oldText2 != text2 || @oldText3 != text3)
- @oldText = text
- @oldText2 = text2
- @oldText3 = text3
- @sprites["safari"].bitmap.clear
- pbSetSystemFont(@sprites["safari"].bitmap)
- pbDrawTextPositions(@sprites["safari"].bitmap,[[text,0,0,0,@textColor,@highlightColor],[text2,0,32,0,@textColor,@highlightColor],[text3,0,64,0,@textColor,@highlightColor]])
- end
- end
- end
- class RadialMenu < Component
- def initialize(viewport, spritehash, menu)
- super(viewport, spritehash)
- @menu = menu
- ############################ RADIAL CONFIGURATION SECTION ############################
- ####
- @distance = 110 # Distance of menu icons from the center in pixel.
- @iconWidth = 48 # The width of menu icons
- @iconHeight = 48 # The height of menu icons
- @activeIconScale = 1.5 # The active icon is scaled by this factor (1 = no resize, 2 = 200% etc.)
- @activeIconOpacity = 255 # Transparency of active icon; 0=fully transparent, 255=fully solid
- @inactiveIconOpacity = 155 # Transparency of inactive icons; 0=fully, 255=fully solid
- @activeIconTone = Tone.new(0,0,0,0) # Tone (Red, Green, Blue, Grey) shift applied to active icon.
- @inactiveIconTone = Tone.new(0,0,0,0) # Tone (Red, Green, Blue, Grey) shift applied to inactive icon.
- @textColor=Color.new(244,244,244) # The text color of the menu icon's name/description.
- @textHighlight=Color.new(30,30,30) # The highlight (outline) color of the text.
- @movementDuration = 12 # How long the ring menu left/right animation takes in frames.
- @startUpAnimation = 12 # Duration of the menu start-up animation in frames, set to 0 to disable.
- @soundTurning = "GUI sel cursor" # Sound that plays when selection is changed.
- # Determines the position of the "active/selected" item. You can set
- # any angle you like (in Radians), or use one of the 4 presets here.
- # TOP (default) = -(Math::PI/2)
- # RIGHT = 0
- # LEFT = Math::PI
- # BOTTOM = Math::PI/2
- @startingAngle = -(Math::PI/2)
- @buttonTurnCounterClockwise = Input::LEFT # Button used to turn the menu clockwise, default=INPUT::LEFT
- @buttonTurnClockwise = Input::RIGHT
- ####
- ############################ END OF CONFIGURATION ##############################
- @entries = []
- @originX = Graphics.width / 2 - @iconWidth / 2
- @originY = Graphics.height / 2 - @iconHeight / 2 - 8
- @animationCounter = @startUpAnimation
- @currentSelection = 0 # The current selection, used as index for @entries
- @angleSize = 0
- @finalDistance = @distance
- @frameAngleShift = 0 # How many frames it takes to turn one time.
- # SAFARI = Bag Trainer PokeGear Quit Options Debug Exit Game
- # BCONTEST = Pokemon Trainer PokeGear Quit Options Debug Exit Game
- addMenuEntry(MenuEntryPokemon.new) if $Trainer.party.length>0
- addMenuEntry(MenuEntryPokedex.new) if $Trainer.pokedex && $PokemonGlobal.pokedexViable.length>0
- addMenuEntry(MenuEntryBag.new) if !pbInBugContest?
- addMenuEntry(MenuEntryExitBugContest.new) if pbInBugContest?
- addMenuEntry(MenuEntryExitSafari.new) if pbInSafari?
- addMenuEntry(MenuEntryOption.new)
- addMenuEntry(MenuEntrySave.new) if !pbInBugContest? && $game_system && !$game_system.save_disabled && !pbInSafari?
- addMenuEntry(MenuEntryQuit.new)
- addMenuEntry(MenuEntryDebug.new)if $DEBUG
- addMenuEntry(MenuEntryTrainer.new)
- addMenuEntry(MenuEntryPokegear.new) if $Trainer.pokegear
- @sprites["entrytext"] = BitmapSprite.new(256,32,@viewport)
- @sprites["entrytext"].y = @originY + 48
- refreshMenuText
- if(@animationCounter == 0)
- positionMenuEntries
- transformIcon(@sprites[@entries[0].name], @activeIconScale, @activeIconTone, @activeIconOpacity)
- @menu.pbHideMenu(false)
- end
- end
- def addMenuEntry(entry)
- @entries << entry
- @sprites[entry.name] = IconSprite.new(0,0,@viewport)
- @sprites[entry.name].visible = false
- @sprites[entry.name].setBitmap(entry.icon)
- @sprites[entry.name].tone = @inactiveIconTone
- @sprites[entry.name].opacity = @inactiveIconOpacity
- end
- def update
- exit = false # should the menu-loop continue
- if(Input.trigger?(Input::B))
- @menu.shouldExit = true
- return
- end
- if(@animationCounter > 0)
- if(@startUpAnimation > 0)
- @distance = 24 + (@startUpAnimation - @animationCounter) * ((@finalDistance - 24) / @startUpAnimation)
- positionMenuEntries
- @menu.pbHideMenu(false) if(@startUpAnimation == @animationCounter) # If it's the first frame
- transformIcon(@sprites[@entries[0].name], @activeIconScale, @activeIconTone, @activeIconOpacity)
- @animationCounter -= 1
- @startUpAnimation = 0 if @animationCounter == 0
- else
- updateAnimation
- refreshMenuText
- end
- else
- if Input.trigger?(@buttonTurnCounterClockwise)
- startAnimation(1)
- elsif Input.trigger?(@buttonTurnClockwise)
- startAnimation(-1)
- elsif Input.trigger?(Input::C)
- exit = @entries[@currentSelection].selected(@menu) # trigger selected entry.
- end
- end
- @menu.shouldExit = exit
- end
- # direction is either 1 (clockwise) or -1 (counterclockwise)
- def startAnimation(direction)
- @currentSelection = (@currentSelection - direction) % @entries.length # keep selection within array bounds
- @currentAngle = @startingAngle
- @frameAngleShift = direction * @angleSize / @movementDuration # in radians
- @frameScaleShift = ((@activeIconScale-1) / @movementDuration)
- @animationCounter = @movementDuration
- pbSEPlay(@soundTurning)
- end
- def updateAnimation
- @animationCounter -= 1
- @entries.each do |entry|
- entry.angle += @frameAngleShift
- repositionSprite(@sprites[entry.name], entry.angle)
- end
- # Transition properties of selected/deselected entries
- newActive = @sprites[@entries[@currentSelection].name]
- if(@frameAngleShift > 0)
- oldActive = @sprites[@entries[(@currentSelection + 1) % @entries.length].name]
- else
- oldActive = @sprites[@entries[(@currentSelection - 1) % @entries.length].name]
- end
- scaleNew = 1 + @frameScaleShift * (@movementDuration - @animationCounter)
- scaleOld = 1 + @frameScaleShift * @animationCounter
- transformIcon(newActive, scaleNew, @activeIconTone, @activeIconOpacity)
- transformIcon(oldActive, scaleOld, @inactiveIconTone, @inactiveIconOpacity)
- end
- def refreshMenuText
- @sprites["entrytext"].bitmap.clear
- text = @entries[@currentSelection].name
- @sprites["entrytext"].x = @originX + 24 - text.length * 5.5 # rough guesstimate for centering
- pbSetSystemFont(@sprites["entrytext"].bitmap)
- pbDrawTextPositions(@sprites["entrytext"].bitmap,[[text,0,0,0,@textColor,@textHighlight]])
- end
- def positionMenuEntries
- @currentAngle = @startingAngle
- @angleSize = (2*Math::PI) / @entries.length
- @entries.each do |entry|
- entry.angle = @currentAngle
- repositionSprite(@sprites[entry.name], entry.angle)
- @currentAngle += @angleSize
- end
- end
- def repositionSprite(sprite, theta)
- sprite.y = (@distance * Math.sin(theta)) + @originY
- sprite.x = (@distance * Math.cos(theta)) + @originX
- end
- def transformIcon(sprite, scale, tone, opacity)
- width = sprite.bitmap.width
- height = sprite.bitmap.height
- sprite.zoom_x = scale
- sprite.zoom_y = scale
- sprite.x = sprite.x - (width*scale-width)/2
- sprite.y = sprite.y - (height*scale-height)/2
- sprite.tone = tone
- sprite.opacity = opacity
- end
- end
- class PokemonPauseMenu_Scene
- attr_accessor :shouldExit
- def initialize
- #################### MISC CONFIGURATION SECTION
- @soundOpenMenu = "GUI menu open" # When menu opens, play the following sound.
- @backgroundTint = Tone.new(0,0,0,150) # Tone (shade) applied to the background/map.
- @enableClock = true # enable the clock, for clock configuration, CTRL+F: "class Clock"
- #################### END CONFIGURATION
- #### INTERNAL STUFF - changing values carelessly may break stuff
- @background = Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @entries = []
- @sprites = {}
- @shouldExit = false
- end
- def pbStartScene
- @viewport.z = 99999
- @background.z = 99998
- @background.tone = @backgroundTint
- @clock = (@enableClock) ? Clock.new(@viewport, @sprites, @timeFormat) : nil
- @safari = SafariHud.new(@viewport, @sprites) if (pbInSafari?)
- @safari = BugContestHud.new(@viewport, @sprites) if (pbInBugContest?)
- @radialMenu = RadialMenu.new(@viewport, @sprites, self)
- end
- def pbHideMenu(hide)
- @sprites.each do |_,sprite|
- sprite.visible = !hide
- end
- end
- def update
- @hasTerminated = false
- pbSEPlay(@soundOpenMenu)
- loop do
- Graphics.update
- Input.update
- @clock.update if @enableClock
- @safari.update if defined?(@safari)
- @radialMenu.update
- if(@hasTerminated)
- return # If pbEndScene was already called, don't call it again.
- end
- pbUpdateSceneMap
- if(shouldExit)
- pbEndScene
- break
- end
- end
- pbUpdateSpriteHash(@sprites)
- end
- def pbRefresh ; end
- def pbShowMenu ; end
- def pbEndScene
- @hasTerminated = true
- @background.dispose
- @radialMenu.dispose
- @safari.dispose if defined?(@safari)
- @clock.dispose if @clockEnabled
- pbDisposeSpriteHash(@sprites)
- @viewport.dispose
- end
- end
- class PokemonPauseMenu
- def initialize(scene)
- @scene = scene
- end
- def pbShowMenu
- @scene.pbRefresh
- @scene.pbShowMenu
- end
- def pbStartPokemonMenu
- pbSetViableDexes # ?? called in original script
- @scene.pbStartScene
- @scene.update
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement