From 73984504047ce4c8e153acb9cdaa30cf55e9f788 Mon Sep 17 00:00:00 2001 From: fnicon Date: Sun, 22 Mar 2026 21:32:56 +0900 Subject: [PATCH] Add title label --- .../new/world/main_menu/components/button.lua | 103 +++++------------- .../new/world/main_menu/components/label.lua | 27 +++++ .../new/world/main_menu/data/main_menu.lua | 14 +++ game/love_src/src/new/world/race/init.lua | 7 +- game/love_src/src/system/ui_behavior.lua | 29 +++++ game/love_src/src/system/ui_render.lua | 47 ++++++++ 6 files changed, 147 insertions(+), 80 deletions(-) create mode 100644 game/love_src/src/new/world/main_menu/components/label.lua create mode 100644 game/love_src/src/system/ui_behavior.lua create mode 100644 game/love_src/src/system/ui_render.lua diff --git a/game/love_src/src/new/world/main_menu/components/button.lua b/game/love_src/src/new/world/main_menu/components/button.lua index 52ad725..51fea29 100644 --- a/game/love_src/src/new/world/main_menu/components/button.lua +++ b/game/love_src/src/new/world/main_menu/components/button.lua @@ -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() diff --git a/game/love_src/src/new/world/main_menu/components/label.lua b/game/love_src/src/new/world/main_menu/components/label.lua new file mode 100644 index 0000000..0293936 --- /dev/null +++ b/game/love_src/src/new/world/main_menu/components/label.lua @@ -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 diff --git a/game/love_src/src/new/world/main_menu/data/main_menu.lua b/game/love_src/src/new/world/main_menu/data/main_menu.lua index ea1ce94..e17318a 100644 --- a/game/love_src/src/new/world/main_menu/data/main_menu.lua +++ b/game/love_src/src/new/world/main_menu/data/main_menu.lua @@ -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", + } + }, } } diff --git a/game/love_src/src/new/world/race/init.lua b/game/love_src/src/new/world/race/init.lua index 0260207..fc463fa 100644 --- a/game/love_src/src/new/world/race/init.lua +++ b/game/love_src/src/new/world/race/init.lua @@ -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") } } diff --git a/game/love_src/src/system/ui_behavior.lua b/game/love_src/src/system/ui_behavior.lua new file mode 100644 index 0000000..a9698c9 --- /dev/null +++ b/game/love_src/src/system/ui_behavior.lua @@ -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 +} diff --git a/game/love_src/src/system/ui_render.lua b/game/love_src/src/system/ui_render.lua new file mode 100644 index 0000000..90d42dc --- /dev/null +++ b/game/love_src/src/system/ui_render.lua @@ -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 +}