Simplified button input
This commit is contained in:
@@ -37,6 +37,7 @@ function badr.__add(self, component)
|
||||
component.parent = self
|
||||
component.x = self.x + component.x
|
||||
component.y = self.y + component.y
|
||||
if self.input then component.input = self.input end
|
||||
|
||||
local childrenSize = { width = 0, hight = 0 }
|
||||
for _, child in ipairs(self.children) do
|
||||
|
||||
@@ -23,19 +23,17 @@ end
|
||||
-- Screens
|
||||
|
||||
function GameOver:_createRoot()
|
||||
local root = component { column = true, gap = 10 }
|
||||
local root = component { column = true, gap = 10, input = self.input }
|
||||
+ label { text = 'Game Over' }
|
||||
+ button {
|
||||
text = 'Retry',
|
||||
width = 200,
|
||||
onClick = function() self.core:switchState(self.core.states.mainmenu) end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit to desktop',
|
||||
width = 200,
|
||||
onClick = function() love.event.quit() end,
|
||||
input = self.input
|
||||
}
|
||||
root:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - root.width * 0.5,
|
||||
|
||||
@@ -25,30 +25,26 @@ end
|
||||
-- Screens
|
||||
|
||||
function MainMenu:_createMain(settings, credits)
|
||||
local main = component { column = true, gap = 10 }
|
||||
local main = component { column = true, gap = 10, input = self.input }
|
||||
+ button {
|
||||
text = 'New game',
|
||||
width = 200,
|
||||
onClick = function() self.core:switchState(self.core.states.game) end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Settings',
|
||||
width = 200,
|
||||
onClick = function() self:_pushScreen(settings) end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Credits',
|
||||
width = 200,
|
||||
onClick = function() self:_pushScreen(credits) end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit',
|
||||
width = 200,
|
||||
onClick = function() love.event.quit() end,
|
||||
input = self.input
|
||||
}
|
||||
main:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - main.width * 0.5,
|
||||
@@ -59,13 +55,12 @@ function MainMenu:_createMain(settings, credits)
|
||||
end
|
||||
|
||||
function MainMenu:_createSettings()
|
||||
local settings = component { column = true, gap = 10 }
|
||||
local settings = component { column = true, gap = 10, input = self.input }
|
||||
+ label { text = 'Settings' }
|
||||
+ button {
|
||||
text = 'Back',
|
||||
width = 200,
|
||||
onClick = function() self:_popScreen() end,
|
||||
input = self.input
|
||||
}
|
||||
settings:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - settings.width * 0.5,
|
||||
@@ -76,13 +71,12 @@ function MainMenu:_createSettings()
|
||||
end
|
||||
|
||||
function MainMenu:_createCredits()
|
||||
local credits = component { column = true, gap = 10 }
|
||||
local credits = component { column = true, gap = 10, input = self.input }
|
||||
+ label { text = 'Credits' }
|
||||
+ button {
|
||||
text = 'Back',
|
||||
width = 200,
|
||||
onClick = function() self:_popScreen() end,
|
||||
input = self.input
|
||||
}
|
||||
credits:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - credits.width * 0.5,
|
||||
|
||||
@@ -23,25 +23,22 @@ end
|
||||
-- Screens
|
||||
|
||||
function PauseMenu:_createRoot()
|
||||
local root = component { column = true, gap = 10 }
|
||||
local root = component { column = true, gap = 10, input = self.input }
|
||||
+ label { text = 'Game Paused' }
|
||||
+ button {
|
||||
text = 'Resume',
|
||||
width = 200,
|
||||
onClick = function() self.core:popState() end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit to main menu',
|
||||
width = 200,
|
||||
onClick = function() self.core:switchState(self.core.states.mainmenu) end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit to desktop',
|
||||
width = 200,
|
||||
onClick = function() love.event.quit() end,
|
||||
input = self.input
|
||||
}
|
||||
root:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - root.width * 0.5,
|
||||
|
||||
@@ -23,19 +23,17 @@ end
|
||||
-- Screens
|
||||
|
||||
function Victory:_createRoot()
|
||||
local root = component { column = true, gap = 10 }
|
||||
local root = component { column = true, gap = 10, input = self.input }
|
||||
+ label { text = 'You win' }
|
||||
+ button {
|
||||
text = 'Play again',
|
||||
width = 200,
|
||||
onClick = function() self.core:switchState(self.core.states.mainmenu) end,
|
||||
input = self.input
|
||||
}
|
||||
+ button {
|
||||
text = 'Quit to desktop',
|
||||
width = 200,
|
||||
onClick = function() love.event.quit() end,
|
||||
input = self.input
|
||||
}
|
||||
root:updatePosition(
|
||||
love.graphics.getWidth() * 0.5 - root.width * 0.5,
|
||||
|
||||
@@ -48,7 +48,7 @@ return function(props)
|
||||
disabled = props.disabled or false,
|
||||
hoverCalled = false,
|
||||
onUpdate = function(self)
|
||||
if props.input:pressed 'select' and self:isMouseInside() and self.parent.visible then
|
||||
if self.input:pressed 'select' and self:isMouseInside() and self.parent.visible then
|
||||
if props.onClick then self:onClick() end
|
||||
end
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user