Cursor highlighting feature

pull/58/head
Tetro48 2022-02-28 10:16:15 +07:00
parent 481a9ae1a3
commit f6db5d22af
6 changed files with 30 additions and 8 deletions

View File

@ -93,7 +93,8 @@ function ConfigScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(option[2], 40, 100 + i * 20, 150, "left")
for j, setting in ipairs(option[4]) do
love.graphics.setColor(1, 1, 1, config.gamesettings[option[1]] == j and 1 or 0.5)
local b = CursorHighlight(100 + 110 * j, 100 + i * 20,100,20)
love.graphics.setColor(1, 1, b, config.gamesettings[option[1]] == j and 1 or 0.5)
love.graphics.printf(setting, 100 + 110 * j, 100 + i * 20, 100, "center")
end
end

View File

@ -48,6 +48,8 @@ function ConfigScene:render()
love.graphics.setFont(font_3x5_3)
love.graphics.setColor(1, 1, 1, 1)
for i, screen in pairs(menu_screens) do
local b = CursorHighlight(80,120 + 50 * i,200,50)
love.graphics.setColor(1,1,b,1)
love.graphics.printf(screen.title, 80, 120 + 50 * i, 200, "left")
end
end

View File

@ -111,34 +111,44 @@ function ModeSelectScene:render()
elseif self.menu_state.select == "ruleset" then
love.graphics.setColor(1, 1, 1, 0.25)
end
love.graphics.rectangle("fill", 20, 258, 240, 22)
self.menu_mode_height = interpolateListHeight(self.menu_mode_height / 20, self.menu_state.mode) * 20
self.menu_ruleset_height = interpolateListHeight(self.menu_ruleset_height / 20, self.menu_state.ruleset) * 20
love.graphics.rectangle("fill", 20, 258 + (self.menu_state.mode * 20) - self.menu_mode_height, 240, 22)
if self.menu_state.select == "mode" then
love.graphics.setColor(1, 1, 1, 0.25)
elseif self.menu_state.select == "ruleset" then
love.graphics.setColor(1, 1, 1, 0.5)
end
love.graphics.rectangle("fill", 340, 258, 200, 22)
love.graphics.rectangle("fill", 340, 258 + (self.menu_state.ruleset * 20) - self.menu_ruleset_height, 200, 22)
love.graphics.setColor(1, 1, 1, 1)
self.menu_mode_height = interpolateListHeight(self.menu_mode_height / 20, self.menu_state.mode) * 20
self.menu_ruleset_height = interpolateListHeight(self.menu_ruleset_height / 20, self.menu_state.ruleset) * 20
love.graphics.setFont(font_3x5_2)
for idx, mode in pairs(game_modes) do
if(idx >= self.menu_mode_height / 20-10 and idx <= self.menu_mode_height / 20+10) then
love.graphics.setColor(1,1,1,FadeoutAtEdges((-self.menu_mode_height) + 20 * idx, 180, 20))
local b = CursorHighlight(0,(260 - self.menu_mode_height) + 20 * idx,320,20)
love.graphics.setColor(1,1,b,FadeoutAtEdges((-self.menu_mode_height) + 20 * idx, 180, 20))
love.graphics.printf(mode.name, 40, (260 - self.menu_mode_height) + 20 * idx, 200, "left")
end
end
for idx, ruleset in pairs(rulesets) do
if(idx >= self.menu_ruleset_height / 20-10 and idx <= self.menu_ruleset_height / 20+10) then
love.graphics.setColor(1,1,1,FadeoutAtEdges(-self.menu_ruleset_height + 20 * idx, 180, 20))
local b = CursorHighlight(320,(260 - self.menu_ruleset_height) + 20 * idx,320,20)
love.graphics.setColor(1,1,b,FadeoutAtEdges(-self.menu_ruleset_height + 20 * idx, 180, 20))
love.graphics.printf(ruleset.name, 360, (260 - self.menu_ruleset_height) + 20 * idx, 160, "left")
end
end
love.graphics.setColor(1,1,1,1)
end
function CursorHighlight(x,y,w,h)
local mouse_x, mouse_y = getScaledPos(love.mouse.getPosition())
if mouse_x > x and mouse_x < x+w and mouse_y > y and mouse_y < y+h then
return 0
else
return 1
end
end
function FadeoutAtEdges(input, edge_distance, edge_width)
if input < 0 then
input = input * -1

View File

@ -55,6 +55,10 @@ function ReplaySelectScene:update()
local mouse_x, mouse_y = getScaledPos(love.mouse.getPosition())
if love.mouse.isDown(1) and not left_clicked_before then
if self.display_error then
scene = TitleScene()
return
end
self.auto_menu_offset = math.floor((mouse_y - 260)/20)
if self.auto_menu_offset == 0 then
self:startReplay()
@ -136,7 +140,7 @@ function ReplaySelectScene:render()
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setFont(font_3x5_2)
for idx, replay in ipairs(replays) do
if(idx >= self.height_offset/20-9.5 and idx <= self.height_offset/20+9.5) then
if(idx >= self.height_offset/20-10 and idx <= self.height_offset/20+10) then
local display_string = os.date("%c", replay["timestamp"]).." - "..replay["mode"].." - "..replay["ruleset"]
if replay["level"] ~= nil then
display_string = display_string.." - Level: "..replay["level"]
@ -147,6 +151,7 @@ function ReplaySelectScene:render()
if #display_string > 75 then
display_string = display_string:sub(1, 75) .. "..."
end
love.graphics.setColor(1,1,CursorHighlight(0, (260 - self.height_offset) + 20 * idx, 640, 20),FadeoutAtEdges((-self.height_offset) + 20 * idx, 180, 20))
love.graphics.printf(display_string, 6, (260 - self.height_offset) + 20 * idx, 640, "left")
end
end

View File

@ -57,6 +57,8 @@ function SettingsScene:render()
love.graphics.setFont(font_3x5_3)
love.graphics.setColor(1, 1, 1, 1)
for i, screen in pairs(menu_screens) do
local b = CursorHighlight(80,120 + 50 * i,200,50)
love.graphics.setColor(1,1,b,1)
love.graphics.printf(screen.title, 80, 120 + 50 * i, 200, "left")
end
end

View File

@ -129,6 +129,8 @@ function TitleScene:render()
love.graphics.setColor(1, 1, 1, 1)
for i, screen in pairs(main_menu_screens) do
local b = CursorHighlight(40,280 + 20 * i,120,20)
love.graphics.setColor(1,1,b,1)
love.graphics.printf(screen.title, 40, 280 + 20 * i, 120, "left")
end
end