can i build task simple task manager? it just date, task,status
thx
You seem to be new to this community, so welcome :-). It’s certainly possible to make a task manager! Look around on the forums for some examples to get you started and feel free to ask for help whenever you have questions.
@wigianim this is your lucky day
--# Main
-- tasks
function setup()
t = tasks()
t:save()
end
function draw()
background(255, 255, 255, 255)
t:draw()
end
function touched(touch)
t:touched(touch)
end
--# bloc
bloc = class()
function bloc:init(x,y,w,h,txt)
self.x = x
self.y = y
self.w = w
self.h = h
self.txt = txt or "?"
self.textMode = CENTER
self.className = "bloc"
end
function bloc:tostring()
local s
s = self.className .."( "
s = s .. tostring(self.x) ..",".. tostring(self.y) ..","
s = s .. tostring(self.w) ..",".. tostring(self.h) ..","
s = s .. "'"..tostring(self.txt) .."'" ..")"
return s
end
function bloc:draw()
stroke(0)
strokeWidth(2)
fill(255)
rect(self.x, self.y, self.w, self.h)
textMode(self.textMode)
fill(0)
text( self.txt, self.x+self.w/2, self.y+self.h/2)
end
local abs = math.abs
function bloc:touched(t)
if t.state ~= BEGAN then return end
if abs(t.y-self.y-self.h/2)<self.h/2 and abs(t.x-self.x-self.w/2)<self.w/2 then
return self:onTap()
end
end
function bloc:onTap()
print(self.txt)
return true
end
--# Status
Status = class(bloc)
function Status:init(...)
bloc.init(self,...)
self.className = "Status"
end
function Status:onTap()
local a = "done"
local b = "pending"
if self.txt == a or self.txt == "?" then
self.txt = b
elseif self.txt == b then
self.txt = a
end
sound("Game Sounds One:Bell 2")
return true
end
--# Task
Task = class(bloc)
function Task:init(...)
bloc.init(self,...)
self.className = "Task"
end
local taskBeingEdited
function Task:onTap()
showKeyboard()
keyboardBuffer(self.txt)
taskBeingEdited = self
return true
end
function Task:draw()
bloc.draw(self)
if taskBeingEdited == self then
taskBeingEdited.txt = keyboardBuffer()
if not isKeyboardShowing() then
taskBeingEdited = nil
end
end
end
--# tasks
tasks = class()
function tasks:init()
if data then
self.list = data
else
-- self:firstInit(10)
end
end
function tasks:firstInit(n)
self.list = {}
local h = 50
local w = 150
local border = 50
for i = 1,n do
table.insert(self.list, {
status=Status( border, HEIGHT- i*h - border, w-border, h),
task= Task( w, HEIGHT- i*h - border, WIDTH-w-2*border, h),
})
end
end
function tasks:save()
local list = {}
local function ins(str) table.insert(list, str) end
ins("data = {")
for i,t in ipairs(self.list) do
ins( "{status="..t.status:tostring()..",task="..t.task:tostring().."},")
end
ins("}")
list = table.concat(list,"\
")
saveProjectTab("data",list)
end
function tasks:draw()
for i,t in ipairs(self.list) do
t.task:draw()
t.status:draw()
end
end
function tasks:touched(touch)
local change
for i,t in ipairs(self.list) do
local c1,c2
c1 = t.task:touched(touch)
c2 = t.status:touched(touch)
change = change or c1 or c2
end
if change then self:save() end
end
--# data
data = {
{status=Status( 50,668,100,50,'done'),task=Task( 150,668,499,50,'make a new task manager')},
{status=Status( 50,618,100,50,'pending'),task=Task( 150,618,499,50,'get some feedback')},
{status=Status( 50,568,100,50,'?'),task=Task( 150,568,499,50,'?')},
{status=Status( 50,518,100,50,'?'),task=Task( 150,518,499,50,'?')},
{status=Status( 50,468,100,50,'?'),task=Task( 150,468,499,50,'?')},
{status=Status( 50,418,100,50,'?'),task=Task( 150,418,499,50,'?')},
{status=Status( 50,368,100,50,'?'),task=Task( 150,368,499,50,'?')},
{status=Status( 50,318,100,50,'?'),task=Task( 150,318,499,50,'?')},
{status=Status( 50,268,100,50,'?'),task=Task( 150,268,499,50,'?')},
{status=Status( 50,218,100,50,'?'),task=Task( 150,218,499,50,'?')},
}