Add title label

This commit is contained in:
fnicon 2026-03-22 21:32:56 +09:00
parent 7f0b9101b3
commit 7398450404
6 changed files with 147 additions and 80 deletions

View File

@ -1,4 +1,8 @@
local vm = require"lib.vornmath"
local uib = require"love_src.src.system.ui_behavior"
local uir = require"love_src.src.system.ui_render"
local sfx = require"love_src.wrapper.lappy.new.source".obj
local main_wrapper = require "love_src.wrapper.lappy.world"
---@class wrappers.Concord.world : lappy.world
@ -32,38 +36,25 @@ function world:load(entity, data)
self.data = data or default
self.data.temp_color = self.data.bg_color
self.mouse = "not click"
self.sfx_highlight = love.audio.newSource("love_src/asset/audio/sfx/book_flip.4.ogg", "static")
self.sfx_click = love.audio.newSource("love_src/asset/audio/sfx/book_flip.8.ogg", "static")
end
-- x1 y1 -- (x1 + w1) y1
-- x2 y2
-- x1 (y1 + h1) -- (x1 + w1) (y1 + h1)
local function is_inside(x1,y1,w1,h1, x2,y2)
return x1 < x2 and
x2 < x1+w1 and
y1 < y2 and
y2 < y1+h1
end
local function transform(x, y, w, h, ox, oy,lox, loy, s)
x = x * s
y = y * s
ox = ox * s
oy = oy * s
lox = lox *s
loy = loy * s
w = w * s
h = h * s
x = x + ox
y = y + oy
return x, y, w, h, ox, oy, lox, loy
self.sfx_highlight = sfx:load_to("love_src/asset/audio/sfx/book_flip.4.ogg", "love_src/asset/audio/sfx/book_flip.4.ogg", "static")
self.sfx_click = sfx:load_to("love_src/asset/audio/sfx/book_flip.8.ogg", "love_src/asset/audio/sfx/book_flip.8.ogg", "static")
self.sfx_non_highlight = sfx:load_to("love_src/asset/audio/sfx/book_flip.1.ogg", "love_src/asset/audio/sfx/book_flip.1.ogg", "static")
end
function world:highlight()
self.data.temp_color = self.data.highlight_color
self.sfx_highlight:play()
if (not self.inside) then
self.sfx_highlight:play()
self.inside = true
end
end
function world:non_highlight()
if (self.inside) then
self.inside = false
self.data.temp_color = self.data.bg_color
self.sfx_non_highlight:play()
end
end
function world:click()
@ -78,8 +69,8 @@ function world:update(dt)
self.data.origin[1], self.data.origin[2],
self.data.label_origin[1], self.data.label_origin[2],
self.data.scale
x, y, w, h, ox, oy, lox, loy = transform(x, y, w, h, ox, oy, lox, loy, s)
if (is_inside(x, y, w, h, xm, ym)) then
x, y, w, h, ox, oy, lox, loy = uib.transform(x, y, w, h, ox, oy, lox, loy, s)
if (uib.is_inside(x, y, w, h, xm, ym)) then
self:highlight()
if (love.mouse.isDown(1)) then
if (self.mouse == "not click") then
@ -92,60 +83,18 @@ function world:update(dt)
end
end
else
self.data.temp_color = self.data.bg_color
self:non_highlight()
end
end
local function draw_text(text, x, y, c)
local font_ix = test.draw_font_start()
test.draw_font_set_base_color(c[1], c[2], c[3])
test.draw_font(font_ix, text, x, y)
end
local function draw_outline(x, y, w, h, c)
test.draw_set_color(c[1], c[2], c[3])
-- 2──1
-- │ │ valid (counter clockwise)
-- 3──4
test.draw_line(
x + w, y,
x, y
)
test.draw_line(
x, y,
x, y + h
)
test.draw_line(
x, y + h,
x + w, y + h
)
test.draw_line(
x + w, y + h,
x + w, y
)
end
local function draw_box(x, y, w, h, c)
test.draw_set_color(c[1], c[2], c[3])
-- 2──1
-- │ │ valid (counter clockwise)
-- 3──4
test.draw_quad(
x + w, y,
x, y,
x, y + h,
x + w, y + h
)
end
local function draw_button(text, x, y, w, h, ox, oy, lox, loy, s, ct, cl, cb)
x, y, w, h, ox, oy, lox, loy = transform(x, y, w, h, ox, oy, lox, loy, s)
x, y, w, h, ox, oy, lox, loy = uib.transform(x, y, w, h, ox, oy, lox, loy, s)
test.draw_line_quad_start()
draw_box(x, y, w, h, cb)
draw_outline(x, y, w, h, cl)
uir.draw_box(x, y, w, h, cb)
uir.draw_outline(x, y, w, h, cl)
x = x + lox
y = y + loy
draw_text(text, x, y, ct)
uir.draw_text(text, x, y, ct)
end
function world:ui_draw()

View File

@ -0,0 +1,27 @@
local vm = require"lib.vornmath"
local uib = require"love_src.src.system.ui_behavior"
local uir = require"love_src.src.system.ui_render"
local main_wrapper = require "love_src.wrapper.lappy.world"
---@class wrappers.Concord.world : lappy.world
local world = main_wrapper:extend()
local reap = require("lib.reap")
local BASE = reap.base_path(...)
function world:new()
world.super.new(self, BASE, "button")
end
function world:load(entity, data)
self.data = data
end
function world:ui_draw()
uir.draw_text(self.data.label,
self.data.pos[1], self.data.pos[2],
self.data.label_color
)
end
return world

View File

@ -32,5 +32,19 @@ return {
label = "Play",
}
},
},
{
type = "label",
name = "title",
components = {
button = require"love_src.src.new.world.main_menu.components.label"
},
data = {
button = {
pos = vm.vec2(lw/2 - 100, 100),
label_color = {255/255, 255/255, 255/255},
label = "Bibliotheca",
}
},
}
}

View File

@ -1,3 +1,4 @@
local sfx = require"love_src.wrapper.lappy.new.source".obj
local vm = require"lib.vornmath"
local main_wrapper = require "love_src.wrapper.lappy.world"
@ -110,15 +111,15 @@ end
local phases = {
intro = {
is_played = false,
source = love.audio.newSource("love_src/asset/audio/sfx/race/va/test1.mp3", "static"),
source = sfx:load_to("love_src/asset/audio/sfx/race/va/test1.mp3", "love_src/asset/audio/sfx/race/va/test1.mp3", "static"),
},
mid = {
is_played = false,
source = love.audio.newSource("love_src/asset/audio/sfx/race/va/Test2.mp3", "static"),
source = sfx:load_to("love_src/asset/audio/sfx/race/va/Test2.mp3", "love_src/asset/audio/sfx/race/va/Test2.mp3", "static"),
},
ed = {
is_played = false,
source = love.audio.newSource("love_src/asset/audio/sfx/race/va/Test3.mp3", "static")
source = sfx:load_to("love_src/asset/audio/sfx/race/va/Test3.mp3", "love_src/asset/audio/sfx/race/va/Test3.mp3", "static")
}
}

View File

@ -0,0 +1,29 @@
-- x1 y1 -- (x1 + w1) y1
-- x2 y2
-- x1 (y1 + h1) -- (x1 + w1) (y1 + h1)
local function is_inside(x1,y1,w1,h1, x2,y2)
return x1 < x2 and
x2 < x1+w1 and
y1 < y2 and
y2 < y1+h1
end
local function transform(x, y, w, h, ox, oy,lox, loy, s)
x = x * s
y = y * s
ox = ox * s
oy = oy * s
lox = lox *s
loy = loy * s
w = w * s
h = h * s
x = x + ox
y = y + oy
return x, y, w, h, ox, oy, lox, loy
end
return {
is_inside = is_inside,
transform = transform
}

View File

@ -0,0 +1,47 @@
local function draw_text(text, x, y, c)
local font_ix = test.draw_font_start()
test.draw_font_set_base_color(c[1], c[2], c[3])
test.draw_font(font_ix, text, x, y)
end
local function draw_outline(x, y, w, h, c)
test.draw_set_color(c[1], c[2], c[3])
-- 2──1
-- │ │ valid (counter clockwise)
-- 3──4
test.draw_line(
x + w, y,
x, y
)
test.draw_line(
x, y,
x, y + h
)
test.draw_line(
x, y + h,
x + w, y + h
)
test.draw_line(
x + w, y + h,
x + w, y
)
end
local function draw_box(x, y, w, h, c)
test.draw_set_color(c[1], c[2], c[3])
-- 2──1
-- │ │ valid (counter clockwise)
-- 3──4
test.draw_quad(
x + w, y,
x, y,
x, y + h,
x + w, y + h
)
end
return {
draw_text = draw_text,
draw_box = draw_box,
draw_outline = draw_outline
}