Hi, I am making great work.
My Alert Buttons {OK, Dismiss} are based on a text and a hit function. My Dismiss Button doesn’t work. Why?
The other thing what I want to know is, how to create that if there are more then xxx symbols in the alert information there will be a new line. Is there anyone going to help me?
Main class:
displayMode(OVERLAY)
displayMode(FULLSCREEN)
function setup()
al = Alert(500, 200, nil)
end
function draw()
background(0, 0, 0, 255)
al:draw()
font("AmericanTypewriter")
fontSize(25)
if al.alertdraw == false then
text("Touch to see the alert", WIDTH/2, HEIGHT/2)
end
end
function touched(t)
al:touched(t)
al.alertdraw = true
end
Alert class:
Alert = class()
function Alert:init(x, y, action, title, txt)
if action == nil then
action = function() print("Action!") end
end
if title == nil then
title = "Alert"
end
if txt == nil then
txt = "The Alert has no content"
end
self.x = x
self.y = y
self.alertdraw = false
self.action = action
self.headtext = title
self.informationtext = txt
end
function Alert:draw()
if self.alertdraw == true then
-- Alert Box
fill(255, 255, 255, 255)
rectMode(CORNER)
rect(self.x, self.y, 350, 200)
-- Alert Title Text
font("AmericanTypewriter-Bold")
fontSize(25)
fill(42, 64, 74, 255)
text(self.headtext, self.x + 175, self.y + 175)
-- Alert Information Text
font("AmericanTypewriter")
fontSize(15)
fill(0, 0, 0, 255)
text(self.informationtext, self.x + 175, self.y + 150)
-- Buttons
font("AmericanTypewriter")
fontSize(25)
fill(255, 0, 0, 255)
text("Dismiss", self.x + 280, self.y + 25)
fill(0, 0, 255, 255)
text("OK", self.x + 35, self.y + 25)
end
end
function Alert:touched(t)
if t.state == ENDED and self:OKhit(vec2(t.x,t.y)) then
if self.action then
self.action()
end
end
if t.state == ENDED and self:Dismiss(vec2(t.x,t.y)) then
self.alertdraw = false
print("No Alert Draw")
end
end
function Alert:OKhit(p)
local OKT = self.y + 50
local OKB = self.y
local OKR = self.x + 50
local OKL = self.x
if p.x > OKL and p.x < OKR and p.y > OKB and p.y < OKT then
return true
end
return false
end
function Alert:Dismiss(d)
local t = self.y - 50
local b = self.y + 50
local r = self.x + 350
local l = self.x + 250
if d.x > l and d.x < r and d.y > b and d.y < t then
return true
end
return false
end