Instantly share code, notes, and snippets.
-
Save josefnpat/4069304 to your computer and use it in GitHub Desktop.
diff menu.lua FOUR_schattenkind/scenes/menu.lua --ignore-space-change --ignore-case -U999999999999
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- menu.lua 2012-11-13 19:03:18.343543945 -0500 | |
+++ FOUR_schattenkind/scenes/menu.lua 2012-10-07 09:21:34.000000000 -0400 | |
@@ -1,145 +1,338 @@ | |
-menu = {} | |
+-- Class | |
+Menu = class("Menu") | |
-menu.font_title = love.graphics.newFont("menu/assets/Orbitron Black.ttf",64) | |
-menu.font_desc = love.graphics.newFont("menu/assets/League_Gothic-webfont.ttf",22) | |
-menu.font_menu = love.graphics.newFont("menu/assets/League_Gothic-webfont.ttf",26) | |
-menu.icon = love.graphics.newImage("menu/assets/icon.png") | |
-menu.bg = love.graphics.newImage("menu/assets/bg.png") | |
-menu.padding = 64 | |
-menu.option = 0 | |
-menu.state = 1 | |
-menu.run = false; | |
-function menu:load(views) | |
- menu.view = views | |
- menu:calc_offset() | |
- menu.iconpos = menu.option*menu.font_menu:getHeight()+menu.offset+menu.font_menu:getHeight()/2 | |
- menu.iconcurpos = menu.iconpos | |
+function Menu:initialize(views) | |
+ super.initialize(self) | |
+ | |
+ self.font_title = love.graphics.newFont("media/fonts/Orbitron Black.ttf",64) | |
+ self.font_title2 = love.graphics.newFont("media/fonts/Orbitron Black.ttf",128) | |
+ self.font_title3 = love.graphics.newFont("media/fonts/Orbitron Black.ttf",256) | |
+ self.font_desc = love.graphics.newFont("media/fonts/League_Gothic-webfont.ttf",28) | |
+ self.font_Menu = love.graphics.newFont("media/fonts/League_Gothic-webfont.ttf",26) | |
+ self.icon = love.graphics.newImage("media/images/icon.png") | |
+ self.bg = love.graphics.newImage("media/images/neon_circle5.png") | |
+ self.padding = 64 | |
+ self.option = 0 | |
+ self.state = 1 | |
+ self.delaycount = 0 | |
+ self.delay = 0.14 | |
+ self.active = true --false | |
+ | |
+ self.view = views | |
+ self:calc_offset() | |
+ self.iconpos = self.option*self.font_Menu:getHeight()+self.offset+self.font_Menu:getHeight()/2 | |
+ self.iconcurpos = self.iconpos | |
+ self.iconposx = love.graphics.getWidth()*8.5/9.25 --love.graphics.getWidth()*6.5/7.1 | |
+ self.circleCursor = Circle:new( self.iconposx, self.iconcurpos, 10, 255,231,0) --yellow | |
+ | |
+ self.title_fade = 0 | |
+ | |
+ TEsound.playLooping("media/music/music2.ogg", "menumusic", 0.30) | |
end | |
function menu:calc_offset() | |
- menu.offset = love.graphics.getHeight()/2-(menu.font_menu:getHeight()*#menu.view[menu.state])/2 | |
+ self.offset = love.graphics.getHeight()/2-(self.font_Menu:getHeight()*#self.view[self.state])/2 | |
end | |
function menu:toggle() | |
- menu.run = not menu.run | |
+ self.active = not self.active | |
end | |
-menu.title_fade = 0 | |
function menu:draw() | |
- if menu.run then | |
+ if self.active then | |
local orig_font = love.graphics.getFont() | |
local orig_r, orig_g, orig_b, orig_a | |
orig_r, orig_g, orig_b, orig_a = love.graphics.getColor( ) | |
- love.graphics.setColor(255,255,255,63) | |
- love.graphics.draw(menu.bg,0,0,0,love.graphics.getWidth()/menu.bg:getWidth(),love.graphics.getHeight()/menu.bg:getHeight()) | |
+ love.graphics.setColor(255,255,255,230) | |
+ love.graphics.draw(self.bg,0,0,0,love.graphics.getWidth()/self.bg:getWidth(),love.graphics.getHeight()/self.bg:getHeight()) | |
love.graphics.setColor(0,0,0,127) | |
- love.graphics.rectangle("fill",love.graphics.getWidth()*6/10,0,love.graphics.getWidth()*3/10,love.graphics.getHeight()) | |
- love.graphics.setColor(255,255,255,96+96*math.abs(math.sin(menu.title_fade))) | |
- love.graphics.setFont(menu.font_title) | |
+ love.graphics.rectangle("fill",love.graphics.getWidth()*6/9,0,love.graphics.getWidth()*3/10,love.graphics.getHeight()) | |
+ -- -------------- | |
+-- love.graphics.setColor(255,255,255,96+96*math.abs(math.sin(self.title_fade))) | |
+ love.graphics.setColor( HSL(150,100,96+96*math.abs(math.sin(self.title_fade))) ) | |
+ love.graphics.setFont(self.font_title) | |
+ love.graphics.print( | |
+ self.view[self.state].title, | |
+ (love.graphics.getWidth()*6/10)/3.5-(self.font_title:getWidth(self.view[self.state].title)/2), | |
+ love.graphics.getHeight()*1-(self.font_title:getHeight()) | |
+ ) | |
+ -- -------------- | |
+ love.graphics.setFont(self.font_title2) | |
+-- love.graphics.setColor(255,255,255,55) | |
+ love.graphics.setColor( HSL(150,100,105, 130 ) ) | |
love.graphics.print( | |
- menu.view[menu.state].title, | |
- (love.graphics.getWidth()*6/10)/2-(menu.font_title:getWidth(menu.view[menu.state].title)/2), | |
- love.graphics.getHeight()*0.9-(menu.font_title:getHeight()) | |
+ self.view[self.state].title, | |
+ (love.graphics.getWidth()*6/10)/3.5-(self.font_title:getWidth(self.view[self.state].title)/2)+2, | |
+ love.graphics.getHeight()*1-(self.font_title:getHeight()+51) | |
) | |
+ love.graphics.setFont(self.font_title3) | |
+-- love.graphics.setColor(255,255,255,25) | |
+ love.graphics.setColor( HSL(150,100,85, 100 ) ) | |
+ love.graphics.print( | |
+ self.view[self.state].title, | |
+ (love.graphics.getWidth()*6/10)/3.5-(self.font_title:getWidth(self.view[self.state].title)/2)+4, | |
+ love.graphics.getHeight()*1-(self.font_title:getHeight()+153) | |
+ ) | |
+ -- -------------- | |
love.graphics.setColor(255,255,255,192) | |
- love.graphics.setFont(menu.font_desc) | |
+ love.graphics.setFont(self.font_desc) | |
love.graphics.printf( | |
- menu.view[menu.state].desc, | |
- love.graphics.getWidth()*1/10, | |
+ self.view[self.state].desc, | |
+ love.graphics.getWidth()*1/2, | |
love.graphics.getHeight()*1/10, | |
love.graphics.getWidth()*4/10, | |
"right" | |
) | |
- love.graphics.setFont(menu.font_menu) | |
- for i,v in ipairs(menu.view[menu.state]) do | |
+ love.graphics.setFont(self.font_Menu) | |
+ for i,v in ipairs(self.view[self.state]) do | |
love.graphics.printf( | |
v.t, | |
love.graphics.getWidth()*6.5/10, | |
- (i-1)*menu.font_menu:getHeight()+menu.offset, | |
- love.graphics.getWidth()*2/10, | |
+ (i-1)*self.font_Menu:getHeight()+self.offset, | |
+ love.graphics.getWidth()*2/8, | |
"right" | |
) | |
end | |
+ | |
+--[[ | |
love.graphics.draw( | |
- menu.icon, | |
+ self.icon, | |
love.graphics.getWidth()*8.5/10, | |
- menu.iconcurpos,--wat | |
+ self.iconcurpos,--wat | |
0,1,1, | |
0, | |
- menu.icon:getHeight()/2 | |
+ self.icon:getHeight()/2 | |
) | |
+]]-- | |
+ | |
+ self.circleCursor:changeColor( 220+25*math.abs(math.sin(self.title_fade)), 231,0) | |
+ self.circleCursor:draw(love.graphics.getWidth()*8.5/9.25, self.iconcurpos) | |
love.graphics.setFont(orig_font) | |
love.graphics.setColor(orig_r,orig_g,orig_b,orig_a) | |
end | |
end | |
function menu:update(dt) | |
- if menu.run then | |
- menu.title_fade = menu.title_fade + dt | |
- menu.iconpos = menu.option*menu.font_menu:getHeight()+menu.offset+menu.font_menu:getHeight()/2 | |
- if menu.iconpos > menu.iconcurpos then | |
- menu.iconcurpos = menu.iconcurpos + math.abs(menu.iconcurpos-menu.iconpos)/2 | |
- elseif menu.iconpos < menu.iconcurpos then | |
- menu.iconcurpos = menu.iconcurpos - math.abs(menu.iconcurpos-menu.iconpos)/2 | |
+ if self.active then | |
+ TEsound.cleanup() | |
+ | |
+ self.title_fade = self.title_fade + dt | |
+ self.iconpos = self.option*self.font_Menu:getHeight()+self.offset+self.font_Menu:getHeight()/2 | |
+ if self.iconpos > self.iconcurpos then | |
+ self.iconcurpos = self.iconcurpos + math.abs(self.iconcurpos-self.iconpos)/2 | |
+ elseif self.iconpos < self.iconcurpos then | |
+ self.iconcurpos = self.iconcurpos - math.abs(self.iconcurpos-self.iconpos)/2 | |
end | |
- local temp_test = menu:determine_mouse_choice(love.mouse.getX(),love.mouse.getY()) | |
+--[[ | |
+ local temp_test = self:determine_mouse_choice(love.mouse.getX(),love.mouse.getY()) | |
if temp_test then | |
- menu.option = temp_test | |
+ self.option = temp_test | |
+ end | |
+]]-- | |
+ -- delay menu input | |
+ self.delaycount=self.delaycount+dt | |
+ | |
+ if(self.delaycount > self.delay) then | |
+ -- joystick | |
+ if love.joystick.getAxis( 0, 1 ) < -0.3 then | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self.option = (self.option - 1) % #self.view[self.state] | |
+ elseif love.joystick.getAxis( 0, 1 ) > 0.3 then | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self.option = (self.option + 1) % #self.view[self.state] | |
+ end | |
+ -- reset counter | |
+ self.delaycount=0 | |
end | |
end | |
end | |
-function menu:keypressed(key) | |
- if menu.run then | |
+function Menu:keypressed(key,unicode) | |
+ if self.active then | |
+ -- keyboard | |
if key == "escape" then | |
- menu.option = #menu.view[menu.state]-1 | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self.option = #self.view[self.state]-1 | |
elseif key == "up" then | |
- menu.option = (menu.option - 1) % #menu.view[menu.state] | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self.option = (self.option - 1) % #self.view[self.state] | |
elseif key == "down" then | |
- menu.option = (menu.option + 1) % #menu.view[menu.state] | |
- elseif key == "return" or key == "enter" or key ==" " then | |
- menu:callback_exec() | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self.option = (self.option + 1) % #self.view[self.state] | |
+ else --if key == "return" or key == "enter" or key ==" " then | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self:callback_exec(key,unicode) | |
+ end | |
+ end | |
+end | |
+ | |
+function Menu:keyreleased(key,unicode) | |
+ if self.active then | |
+ end | |
+end | |
+--[[ | |
+-- xBox360 Controller | |
+-- A - 0 | |
+-- B - 1 | |
+-- X - 2 | |
+-- Y - 3 | |
+ | |
+-- joystick handling | |
+function Menu:joystickreleased( joystick, button ) | |
+ if self.active then | |
+--print(love.joystick.getNumJoysticks()) | |
+--print(love.joystick.getName(joystick)) | |
+--print(love.joystick.getNumButtons(joystick)) | |
+--print(love.joystick.getNumHats(joystick)) | |
+--print(love.joystick.getNumBalls(joystick)) | |
+--print(love.joystick.getNumAxes(joystick)) | |
+ if button==0 then | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self:callback_exec() | |
+ elseif button==1 then | |
+ TEsound.play("media/sounds/click.ogg", "sfx") | |
+ self.option = #self.view[self.state]-1 | |
end | |
end | |
end | |
+]]-- | |
+function Menu:quit() | |
+ -- reset colors | |
+ love.graphics.setColor( 255, 255, 255, 255 ) | |
+ | |
+ print("quit titlemenu") | |
+end | |
-function menu:callback_exec() | |
- if menu.callback then | |
- menu:callback(menu.view[menu.state][menu.option+1].cb) | |
+function Menu:callback_exec(key,unicode) | |
+ if self.callback then | |
+ self:callback(self.view[self.state][self.option+1].cb, key,unicode) | |
else | |
print("menu:callback not defined.") | |
end | |
end | |
function menu:setstate(stateid) | |
- if menu.view[stateid] then | |
- menu.option = 0 | |
- menu.state = stateid | |
+ if self.view[stateid] then | |
+ self.option = 0 | |
+ self.state = stateid | |
else | |
print("Menu state does not exist.") | |
end | |
end | |
-function menu:determine_mouse_choice(x,y) | |
- local x_start = love.graphics.getWidth()*6.5/10 | |
- local limit = love.graphics.getWidth()*2/10 | |
- for i = 1,#menu.view[menu.state] do | |
- local y_start = (i-1)*menu.font_menu:getHeight()+menu.offset | |
- if x >= x_start and x <= x_start + limit and y >= y_start and y <= y_start + menu.font_menu:getHeight() then | |
- return i-1 | |
+function Menu:getKeysString(keyconfig) | |
+ local keystring="" | |
+ for i,v in ipairs(keyconfig) do | |
+ keystring=keystring .. "," .. v | |
+ end | |
+ return keystring | |
+end | |
+--[[ | |
+function Menu:getFreeJoystick(joyused) | |
+ local joynum=nil | |
+ | |
+ for i,v in ipairs(_joysticklist_) do | |
+ if not(joyused) then | |
+ -- if joystick is not used | |
+ if (v.active==false) then | |
+ joynum=v.nr | |
+ _joysticklist_[i].active=true | |
+ break | |
+ end | |
+ else | |
+ if (i>joyused and v.active==false) then | |
+ joynum=v.nr | |
+ _joysticklist_[i].active=true | |
+ break | |
+ end | |
end | |
end | |
+ | |
+ if joyused then _joysticklist_[joyused+1].active=false end | |
+ return joynum | |
end | |
-function menu:mousepressed(x,y,button) | |
- if menu.run then | |
- local temp_test = menu:determine_mouse_choice(x,y) | |
- if temp_test then | |
- menu.option = temp_test | |
- menu:callback_exec() | |
+function Menu:updateJoystickmenu(playernumber, joysticknumber) | |
+ _playerconfig_[playernumber].joy = joysticknumber | |
+ | |
+ if joysticknumber then | |
+ menu_view[5][playernumber].t = "Player ".. playernumber .. " - Joystick Nr." .. joysticknumber | |
+ else | |
+ menu_view[5][playernumber].t = "Player ".. playernumber .. " - none" | |
+ end | |
+end | |
+]]-- | |
+function Menu:updateKeymenu(playernumber, key) | |
+ _playerconfig_[playernumber].key = key | |
+ menu_view[5][playernumber+1].t = "Player ".. playernumber .. " - Key: " .. (key == " " and "space" or key) | |
+end | |
+ | |
+function Menu:callback(cb, key,unicode) | |
+ if cb == "handle1" then | |
+ self:updateKeymenu( 1, key ) | |
+ elseif cb == "handle2" then | |
+ self:updateKeymenu( 2, key ) | |
+ elseif cb == "handle3" then | |
+ self:updateKeymenu( 3, key ) | |
+ elseif cb == "handle4" then | |
+ self:updateKeymenu( 4, key ) | |
+ end | |
+ | |
+ if key == "left" or key == "right" then | |
+ if cb == "plcount" then | |
+ if key == "left" then | |
+ _playercount_ = _playercount_ -1 | |
+ end | |
+ if key == "right" then | |
+ _playercount_ = _playercount_ +1 | |
+ end | |
+ if _playercount_ < 1 then _playercount_=1 end | |
+ if _playercount_ > 4 then _playercount_=4 end | |
+ | |
+ menu_view[5][1].t = "Playercount=".. _playercount_ | |
+ end | |
+ end | |
+ | |
+ if key == "return" or key == "enter" or key ==" " then | |
+ if cb == "ng" then | |
+ TEsound.stop("menumusic", false) | |
+ scene = Game:new( getPlayers() ) | |
+ elseif cb == "st" then | |
+ self:setstate(5) | |
+ elseif cb == "op" then | |
+ self:setstate(2) | |
+ elseif cb == "cr" then | |
+ self:setstate(4) | |
+ elseif cb == "exit" then | |
+ self:setstate(3) | |
+ elseif cb == "cexit" then | |
+ love.event.push("quit") | |
+ elseif cb == "fs" then | |
+ love.graphics.toggleFullscreen() | |
+ _fullscreenmode=not _fullscreenmode | |
+ elseif cb == "res" then | |
+ love.graphics.setMode( _videomodes_[_currentmode_].width, _videomodes_[_currentmode_].height, _fullscreenmode, true ) | |
+ menu_view[2][2].t = "Resolution ("..love.graphics.getWidth().."x"..love.graphics.getHeight()..")" | |
+ _currentmode_ = ((_currentmode_ + 1)% #_videomodes_)+1 | |
+ _screenWidth_ = love.graphics.getWidth() | |
+ _screenHeight_ = love.graphics.getHeight() | |
+ elseif cb == "sound" then | |
+ _soundmode_ = not _soundmode_ | |
+ local temp_x = "" | |
+ if _soundmode_ then | |
+ temp_s = "on" | |
+ TEsound.playLooping("media/music/music2.ogg", "menumusic", 0.30) | |
+ else | |
+ temp_s = "off" | |
+ TEsound.stop("menumusic", false) | |
+ end | |
+ menu_view[2][3].t = "Sound ("..temp_s..")" | |
+ elseif cb == "mm" then | |
+ self:setstate(1) | |
+ else | |
+ print("unknown command:"..cb) | |
end | |
end | |
end | |
-return menu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment