#===============================================================================
# Hollows Simple GUI Menu v2.1
#===============================================================================
class GUIMenu
#===============================================================================
# Methods for menu items
#===============================================================================
# Bag
@@openBag = Proc.new{
item=0
scene=PokemonBag_Scene.new
screen=PokemonBagScreen.new(scene,$PokemonBag)
pbFadeOutIn(99999) {
item=screen.pbStartScreen
}
if item>0
Kernel.pbUseKeyItemInField(item)
end
}
# Trainer Card
@@showTrainerCard= Proc.new{
pbFadeOutIn(99999) {
scene = PokemonTrainerCard_Scene.new
screen = PokemonTrainerCardScreen.new(scene)
screen.pbStartScreen
}
}
# Save
@@saveGame = Proc.new{ |sgm|
if !$game_system || !$game_system.save_disabled
#sgm.pbHideMenu2
scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene)
if screen.pbSaveScreen
else
sgm.pbShowMenu2
end
else
Kernel.pbMessage("You can't save right now")
end
}
# Settings
@@openSettings = Proc.new{
pbFadeOutIn(99999){
scene = PokemonOption_Scene.new
screen = PokemonOptionScreen.new(scene)
screen.pbStartScreen
pbUpdateSceneMap
}
}
# Pokemon
@@showParty = Proc.new{
if $Trainer.party.length>0
hiddenmove = nil
pbFadeOutIn(99999){
sscene = PokemonParty_Scene.new
sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
hiddenmove = sscreen.pbPokemonScreen
}
if hiddenmove
disposeMenu
Kernel.pbUseHiddenMove(hiddenmove[0],hiddenmove[1])
end
else
Kernel.pbMessage("You don't have Pokemon yet.")
end
}
# Pokedex
@@openPokedex = Proc.new{
if DEXDEPENDSONLOCATION
pbFadeOutIn(99999){
scene = PokemonPokedex_Scene.new
screen = PokemonPokedexScreen.new(scene)
screen.pbStartScreen
}
else
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
end
}
# Phone
@@openPhone = Proc.new{
pbPlayDecisionSE
pbFadeOutIn(99999){
PokemonPhoneScene.new.start
}
}
# Pokémon Amie
@@openAmie = Proc.new{
pbPlayDecisionSE()
setAmiePokemon(pbGet(AMIEPOKEMON))
pbFadeOutIn(99999) {
scene = PokeAmie_Essentials_Scene.new
screen = PokeAmie_EssentialsScreen.new(scene)
screen.pbStartAmie(pbGet(AMIEPOKEMON),pbGet(AMIEINDEX))
}
}
# Exit
#
@@exitMenu = Proc.new{ |sgm|
sgm.pbHideMenu2
if Kernel.pbConfirmMessage(_INTL("Are you sure you want to quit the game?"))
scene = PokemonSave_Scene.new
screen = PokemonSaveScreen.new(scene)
screen.pbSaveScreen
$scene = nil
true
else
sgm.pbShowMenu2
false
end}
# Map
@@showMap = Proc.new{
pbPlayDecisionSE
pbShowMap(-1,false)
}
# Your option
# @@variableName = Proc.new{
# your code goes here
# }
# Fame Checker
@@openFameChecker = Proc.new{
FameChecker.show
}
#===============================================================================
# Settings (change accordingly)
#===============================================================================
# Menu Items
# Format: :key => [position,"name",proc to call action, proc for coditions (optional)
# Name must be the file name and is also used as a display name
# The variables holding the code need to be defined above this part
@@menuItems={
:pokemon => [0,"Pokémon",@@showParty,Proc.new{$Trainer.party.length<=0}],
:bag => [1,"Bag",@@openBag],
:amie => [2,"Amie",@@openAmie],
:map => [3,"Map",@@showMap],
:pokedex => [4,"Pokédex",@@openPokedex,Proc.new{!$Trainer.pokedex || $PokemonGlobal.pokedexViable.length<=0}],
:famechecker => [5,"Fame Checker",@@openFameChecker],
:trainercard => [6,"Trainer",@@showTrainerCard],
:phone => [7,"Phone",@@openPhone],
:save => [8,"Save",@@saveGame],
:settings => [9,"Settings",@@openSettings],
:exit => [10,"Exit",@@exitMenu]
}
# Settings for the viewport of the icons
@@viewportX = 119 # Starting point x-axis of the viewport for the icons
@@viewportY = 108 # Starting point y-axis of the viewport for the icons
@@viewportWidth = 274
@@viewportHeight = 206
# Icon and Icon Text Settings
# Spacing between icons (from middle point to middle point)
@@space = 144
# where the icons should be placed relative to the viewport
# the -36 are an offset to have it all centered includeing the text
# remove or modify that part to reposition the icons and text on the y-axis
@@iconY = @@viewportHeight/2 - 20
# Uses the name specified in @@menuItems (2nd position/index 1)
@@showText = true
# Offset of the menu text. Set to a negative number if you want to move it further up
# Don't forget to adjust the @@iconY if the centering is off
@@textOffset = 30
@@textColor = Color.new(240,240,240)
@@textShadow = Color.new(70,70,70)
# Animation Settings
@@animSpeed = 8
@@style = 3
@@jumpAmt = 3
@@zoomIcons = true
@@zoomFactor = 1.5
# Audio Settings
@@moveSound = true
@@startSound = true
# Clock Settings
@@clock = true # Whether or not to use a clock
@@clockGraphic = false # Wheter or not to use a clock graphics
@@clockX = 196 # Position of glock graphic on x-Axis
@@clockY = 290 # Position of glock graphic on y-Axis
# Color of the time and menu text
# Recommended colors: watch graphic=240,240,240 // clock graphic=18,22,36
# Recommended shadow colors: watch graphic=160,160,160 // clock graphic=nil
@@clockColor = Color.new(240,240,240)
@@clockShadow = Color.new(70,70,70)
# Where the time should appear relative to the bitmap
# Recommend x values: watch graphic=330 // clock graphic=13
# Recommend y values: watch graphic=77 // clock graphic=18
@@timeX = 330
@@timeY = 77
# Enter a Font name here if you want to use a different font (e.g. "Power Clear" )
# If you want to use the default put in nil
# Recommended fonts: watch graphic=nil // clock graphic="QuiverItal"
@@clockFont = nil
# Font size will only be relevant if a different font is used
# Recommended size clock graphic=56
@@clockFontSize = 56
#===============================================================================
# Methods
#===============================================================================
def initialize
# Internatl - Organisation
# Reset all variables
@moving = false
@options = []
@optionsIdx = []
@selectedIdx = 0
@debugSelected = false
pbSEPlay("menu") if @@startSound
# Set the icon path
folder = @@style==1 ? "Single/" : "Dual/"
@iconPath = "Graphics/Pictures/Menu/"+ folder
# Getting the icon sizes
tempBitmap = Bitmap.new(@iconPath+@@menuItems.values[0][1])
@width = tempBitmap.width
@height = tempBitmap.height
@height /= 2 if @@style==2 || @@style==3
tempBitmap.dispose
# setting the source rectangles for style 2+3
@inactiveRect = Rect.new(0,0,@width,@height) if @@style>1
@activeRect = Rect.new(0,@height,@width,@height) if @@style>1
# calculating the starting point
@startingPointX = (@@viewportWidth/2).floor
# Viewport for menu background image
@viewportBackground = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewportBackground.z = 99998
# Viewport for all icons
@viewportIcons = Viewport.new(@@viewportX,@@viewportY,@@viewportWidth,@@viewportHeight)
@viewportIcons.z = 99998
@background = Sprite.new(@viewportBackground)
@background.bitmap = Bitmap.new("Graphics/Pictures/Menu/background")
@background.x = 0
@background.y = 0
counter = 0
@menuIcons = {}
@menuText = {}
# Make sure everything is in the right order
@orderedMenu = Array.new(@@menuItems.length)
@@menuItems.each{|key,value|
@orderedMenu[value[0]] = key
}
# now use the ordered Array to iterate over it and create the icons
for i in @orderedMenu
value = @@menuItems[i]
next if value[3] && value[3].call
@menuIcons[value[1]] = Sprite.new(@viewportIcons)
@menuIcons[value[1]].bitmap = Bitmap.new(@iconPath+value[1])
# Set the transformation point to the center of the icon
@menuIcons[value[1]].ox = @menuIcons[value[1]].bitmap.width/2
@menuIcons[value[1]].oy = @height/2
@menuIcons[value[1]].x = @startingPointX + @@space*counter
@menuIcons[value[1]].y = @@iconY
# If style 2 or 3 make only top half visible
@menuIcons[value[1]].src_rect = @inactiveRect
@options.push(@menuIcons[value[1]])
# Holds the keys to the selected index
@optionsIdx.push(i)
# Draw the icon names
# Do so by creating new sprites with drawn text on it
textBmpWidth = @menuIcons[value[1]].bitmap.width*2
textBmpHeight = @menuIcons[value[1]].bitmap.height/4
@menuText[value[1]+"Text"] = Sprite.new(@viewportIcons)
@menuText[value[1]+"Text"].bitmap = Bitmap.new(textBmpWidth,textBmpHeight)
@menuText[value[1]+"Text"].ox = @menuText[value[1]+"Text"].bitmap.width/2
@menuText[value[1]+"Text"].oy = textBmpHeight/2
@menuText[value[1]+"Text"].x = @menuIcons[value[1]].x
@menuText[value[1]+"Text"].y = @@iconY + @menuIcons[value[1]].y/2 + @@textOffset
bitmap = @menuText[value[1]+"Text"].bitmap
pbSetSystemFont(bitmap)
tx = textBmpWidth/2
ty = 0
textPositions = [[_INTL("#{value[1]}"),tx,ty,2,@@textColor,@@textShadow]]
pbDrawTextPositions(bitmap,textPositions) if @@showText
counter+=1
end
# If style 2 or 3 is selected, color the active icon
selectedIcon = @menuIcons[getValueFromHash(@optionsIdx[@selectedIdx])] if @@style>1
selectedIcon.src_rect = @activeRect if @@style>1
# Zoom in if zoom is activated
selectedIcon.zoom_x = @@zoomFactor if @@zoomIcons
selectedIcon.zoom_y = @@zoomFactor if @@zoomIcons
# Show Debug Icon in Debug Mode only
if $DEBUG
# Store the bitmaps for easy swapping
@debugIconActive=Bitmap.new("Graphics/Pictures/Menu/debug2")
@debugIconInactive=Bitmap.new("Graphics/Pictures/Menu/debug")
@debugIcon=Sprite.new(@viewportBackground)
@debugIcon.bitmap=@debugIconInactive
@debugIcon.x=460
@debugIcon.y=330
end
if @@clock
if @@clockGraphic
@clock = Sprite.new(@viewportBackground)
@clock.bitmap = Bitmap.new("Graphics/Pictures/Menu/clock")
@clock.x = @@clockX
@clock.y = @@clockY
end
bitmap = @@clockGraphic ? @clock.bitmap : @background.bitmap
if @@clockFont
bitmap.font.size = @@clockFontSize
bitmap.font.name = @@clockFont
else
pbSetSystemFont(bitmap)
end
# Draw the time
# For bigger clocks it's better to use font bitmaps
textPositions = [[_INTL("#{getTimeString}"),@@timeX,@@timeY,0,@@clockColor,@@clockShadow]]
pbDrawTextPositions(bitmap,textPositions)
end
end
#===============================================================================
# Main Loop
# handles input
#===============================================================================
def mainLoop
frameSkip = 0
loop do # Begin of the loop
Graphics.update
Input.update
# Clock
if @@clock && hasTimePassed?
layer = @@clockGraphic ? @clock : @background
layer.bitmap.clear
btmp = @@clockGraphic ? Bitmap.new("Graphics/Pictures/Menu/clock") : Bitmap.new("Graphics/Pictures/Menu/background")
layer.bitmap = btmp
if @@clockFont
layer.bitmap.font.size = @@clockFontSize
layer.bitmap.font.name = @@clockFont
else
pbSetSystemFont(layer.bitmap)
end
textPositions=[[_INTL("#{getTimeString}"),@@timeX,@@timeY,0,@@clockColor,@@clockShadow]]
pbDrawTextPositions(layer.bitmap,textPositions)
end
#===============================================================================
# Animation
#===============================================================================
if (@@style==1 || @@style==3) && frameSkip==@@animSpeed
currentSelection=@menuIcons[getValueFromHash(@optionsIdx[@selectedIdx])]
direction= currentSelection.y==@@iconY + @@jumpAmt*-1 ? @@jumpAmt : @@jumpAmt*-1
for i in @menuIcons
i[1].y+=direction if i[1]==currentSelection
i[1].y = @@iconY if i[1]!=currentSelection && !i[0].include?("Text")
end
frameSkip = 0
end
#===============================================================================
# Controls
#===============================================================================
# ----------------- Right Input ----------------------
if Input.trigger?(Input::RIGHT) && !@debugSelected && !@moving
oldIdx = @selectedIdx
@selectedIdx += 1
@selectedIdx = @selectedIdx>@menuIcons.length-1 ? 0 : @selectedIdx
direction = oldIdx>@selectedIdx ? "right" : "left"
@@graphicsUpdateRate = oldIdx>@selectedIdx ? @@space/(@@animSpeed/2) : @@space/@@animSpeed
moveIcons(direction,oldIdx)
end
# ----------------- Left Input ----------------------
if Input.trigger?(Input::LEFT) && !@debugSelected && !@moving
oldIdx = @selectedIdx
@selectedIdx -=1
@selectedIdx = @selectedIdx<0 ? @menuIcons.length-1 : @selectedIdx
direction = oldIdx>@selectedIdx ? "right" : "left"
@@graphicsUpdateRate = oldIdx>@selectedIdx ? @@space/@@animSpeed : @@space/(@@animSpeed/2)
moveIcons(direction,oldIdx)
end
# ----------------- C Input ----------------------
if Input.trigger?(Input::C) && !@moving
# Debug
if @debugSelected && $DEBUG
pbFadeOutIn(99999) { pbDebugMenu }
else
# Get what to do as a proc (defined above)
proc = getValueFromHash(@optionsIdx[@selectedIdx],2)
result = proc.call(self)
PBDebugAll.log("Result: #{result}")
break if result
end
end
# ----------------- Other Input ----------------------
# Select/Deselect Debug Icon
if Input.trigger?(Input::DOWN) && $DEBUG
pbSEPlay("choose") if @@moveSound
@debugSelected=true
@debugIcon.bitmap=@debugIconActive
end
if Input.trigger?(Input::UP) && $DEBUG
pbSEPlay("choose") if @@moveSound
@debugSelected=false
@debugIcon.bitmap=@debugIconInactive
end
# Cancel with X
if Input.trigger?(Input::B)
break
end
frameSkip += 1
end # end of loop
pbSEPlay("exit") if @@startSound
disposeMenu
end # end of def main
#===============================================================================
# Class Helpers
#===============================================================================
# Get the value from a hash by key
# Only for @@menuItems
# valueIdx = index of the value to retrieve
def getValueFromHash(key,valueIdx=1)
return @@menuItems[key][valueIdx]
end
# Moves the icons accordingly
def moveIcons(direction,oldIdx)
pbSEPlay("choose") if @@moveSound
oldSelectedIcon = @menuIcons[getValueFromHash(@optionsIdx[oldIdx])]
newSelectedIcon = @menuIcons[getValueFromHash(@optionsIdx[@selectedIdx])]
dir = direction=="left" ? -1 : 1
@moving = true
counter = 0
# Make nlock transfer to decolor old selction
# Only if the style is set to 2 or 3
oldSelectedIcon.src_rect = @inactiveRect if @@style>1
# Resets zoom to 0
oldSelectedIcon.zoom_x = 1
oldSelectedIcon.zoom_y = 1
# Every icon gets only moved by 1 pixel each frame
# Graphics are updated when the counter is equal to the calculated update rate
# This makes it so that the player doesn't see the movement in 1px steps
# The loop stops when the selected icon is in the starting point (=@startingPointX)
loop do
for i in @menuIcons
i[1].x += dir
@menuText[i[0]+"Text"].x +=dir
end
counter += 1
Graphics.update if counter == @@graphicsUpdateRate
counter = counter == @@graphicsUpdateRate ? 0 : counter # reset counter
break if newSelectedIcon.x == @startingPointX
end
# make block transfer to color the new selection
newSelectedIcon.src_rect = @activeRect if @@style>1
# Zooms in on selected icon
newSelectedIcon.zoom_x = @@zoomFactor if @@zoomIcons
newSelectedIcon.zoom_y = @@zoomFactor if @@zoomIcons
Graphics.update
@moving=false
end
# Gets rid of all viewports and graphics
def disposeMenu
pbDisposeSpriteHash(@menuIcons)
pbDisposeSpriteHash(@menuText)
@background.dispose
@clock.dispose if @clock
@viewportBackground.dispose
@viewportIcons.dispose
$game_temp.in_menu = false
end
def pbHideMenu2
@viewportBackground.visible=false
@viewportIcons.visible=false
end
def pbShowMenu2
@viewportBackground.visible=true
@viewportIcons.visible=true
end
end # End of class
#===============================================================================
# General Purpose Helpers
#===============================================================================
# Use this line to open the menu
def startMenu
$game_temp.in_menu = true
sgm = GUIMenu.new
sgm.mainLoop
end
def startBenchMarkTest
mark = Benchmark.measure {
2.times do
GUIMenu.new
end
}
PBDebug.log("Opening the menu: #{mark}")
end
# Time related methods
$lastHour = 0
$lastMinute = 0
def getTimeString
$lastHour = getHour
$lastMinute = getMinute
return "#{$lastHour}:#{$lastMinute}"
end
def hasTimePassed?
return $lastHour!=getHour || $lastMinute!=getMinute
end
def getHour
time=pbGetTimeNow
return time.hour
end
def getMinute
time=pbGetTimeNow
if time.min<10
return "0#{time.min}"
else return time.min
end
end