From bdd03803300dc703f2f3d4ea339dabb909c94d36 Mon Sep 17 00:00:00 2001 From: "Squishy (C6H12O6+NaCl+H2O)" <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Sat, 18 May 2024 16:50:05 +0700 Subject: [PATCH] TEST --- load.lua | 25 +++++++++++++++++-------- scene/touch_config.lua | 18 ++++++++++++++++-- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/load.lua b/load.lua index f56ec0e..aedc934 100644 --- a/load.lua +++ b/load.lua @@ -3,14 +3,23 @@ bigint = require "libs.bigint.bigint" number_names = require "libs.bigint.named-powers-of-ten" BUTTON = require "libs.simple-button" -BUTTON.setDefaultDrawingTextFunction( - function(name, x, y, w, h) - love.graphics.setLineWidth(1) - love.graphics.line(0, y + (h * 0.25), 640, y + (h * 0.25)) - love.graphics.line(0, y + (h * 0.75), 640, y + (h * 0.75)) - drawText(name, x, y + (h * 0.25), w, 'center') - end -) +BUTTON.setDefaultOption{ + draw = function(self) + love.graphics.setColor(self.backgroundColor) + love.graphics.rectangle('fill', self.x, self.y, self.w, self.h, self.r) + + if self._hovering then + love.graphics.setColor(self.hoverColor) + love.graphics.rectangle('fill', self.x, self.y, self.w, self.h, self.r) + end + + drawText(self.name, self.x, self.y + (self.h * 0.25), self.w, 'center') + + love.graphics.setColor(self.borderColor) + love.graphics.rectangle('line', self.x, self.y, self.w, self.h, self.r) + end, + backgroundColor = {0, 0, 0, 0.7} +} -- Fonts FONT_tromi = love.graphics.newFont('res/fonts/monofonto rg.otf', 28) diff --git a/scene/touch_config.lua b/scene/touch_config.lua index 681d377..9ef009d 100644 --- a/scene/touch_config.lua +++ b/scene/touch_config.lua @@ -8,7 +8,12 @@ function TouchConfigScene:update() -- TODO end -local test_button = BUTTON.new('PHÍM THỬ - Chọn widget', 50, 50, 200, 30) +local test_button = BUTTON.new{ + name = 'PHÍM THỬ - Chọn widget', + x = 50, y = 50, w = 200, h = 30, textColor = {1,1,1,1}, + codeWhenPressed = function() PlaySE("promote") end, + codeWhenReleased = function() PlaySE("lock") end, +} local function drawButtons() -- drawText('Select button', 10, 10, 100, 'center') @@ -16,7 +21,6 @@ local function drawButtons() -- love.graphics.setLineWidth(3) -- love.graphics.rectangle('line',0,0,120,40) test_button:draw() - end function TouchConfigScene:render() @@ -24,8 +28,18 @@ function TouchConfigScene:render() drawButtons() end +function TouchConfigScene:onInputMove(e) + if e.type == "mouse" then + test_button:isHovering(e.x, e.y) + end +end function TouchConfigScene:onInputPress(e) if e.input == 'menu_back' then SCENE = InputConfigScene() end + if e.type == 'mouse' then test_button:press() end + if e.type == 'touch' then test_button:press(true) end +end +function TouchConfigScene:onInputRelease(e) + if e.type == 'mouse' then test_button:press() end end return TouchConfigScene \ No newline at end of file