-- Codea 界面控制器类 ver1.0
-- 作者:AK2806 QQ:642207429
-- 使用时请不要删除这条信息
-- 转载请注明
InterfaceController = class()
function InterfaceController:init() -- 实例化
self.setup = {[""] = function() end}
self.draw = {[""] = function() end}
self.touched = {[""] = function(touch) end}
self.presentInterface = ""
self.targetInterface = ""
self.animePerform = false
self.animeColor = color(255, 0)
self.presentTint = color(255, 255)
self.targetTint = color(255, 0)
self.animeType = ""
end
function InterfaceController:addInterface(name, setup, draw, touched) -- 添加界面
--(界面名(字符串),界面setup函数,界面draw函数,界面touched函数)
self.setup[name] = setup
self.draw[name] = draw
self.touched[name] = touched
end
function InterfaceController:changeInterface(targetInterface, animeType, time, animeColor) -- 界面切换
--(目标界面(字符串),动画类型(字符串),持续时间,中介颜色)
-- 注:当动画类型为none时,持续时间和中介颜色可以不填
-- 注:当动画类型为gradientOverchanging或者gradientOverlay时,
-- 中介颜色可以不填
if self.animePerform == true then
return
end
if animeType == "none" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.presentInterface = targetInterface
elseif animeType == "gradientColor" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.animeColor = color(animeColor.r, animeColor.g, animeColor.b, 0)
self.animeType = "gradientColor"
self.animePerform = true
tween(time / 2, self.animeColor, {a = 255}, tween.easing.linear,
function()
self.presentInterface = targetInterface
tween(time / 2, self.animeColor, {a = 0}, tween.easing.linear,
function()
self.animePerform = false
end)
end)
elseif animeType == "gradientOverchanging" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.animeType = "gradientOverchanging"
self.targetInterface = targetInterface
self.animePerform = true
tween(time, self.presentTint, {a = 0}, tween.easing.linear)
tween(time, self.targetTint, {a = 255}, tween.easing.linear,
function()
self.presentInterface = targetInterface
self.animePerform = false
self.presentTint = color(255, 255)
self.targetTint = color(255, 0)
end)
elseif animeType == "gradientOverlay" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.animeType = "gradientOverlay"
self.targetInterface = targetInterface
self.animePerform = true
tween(time, self.targetTint, {a = 255}, tween.easing.linear,
function()
self.presentInterface = targetInterface
self.animePerform = false
self.targetTint = color(255, 0)
end)
end
end
function InterfaceController:InterfaceDraw() -- 在draw()中调用
if self.animePerform == true and self.animeType == "gradientOverchanging" then
tint(self.presentTint)
else
tint(255)
end
self.draw[self.presentInterface]()
if self.animePerform == true and self.animeType == "gradientColor" then
pushStyle()
strokeWidth(0)
fill(self.animeColor)
rect(-1, -1, WIDTH + 2, HEIGHT + 2)
popStyle()
elseif self.animePerform == true and self.animeType == "gradientOverchanging" then
tint(self.targetTint)
self.draw[self.targetInterface]()
elseif self.animePerform == true and self.animeType == "gradientOverlay" then
tint(self.targetTint)
self.draw[self.targetInterface]()
end
end
function InterfaceController:InterfaceTouched(touch) -- 在touched(touch)中调用
if self.touched[self.presentInterface] ~= nil then
self.touched[self.presentInterface](touch)
end
end
-- 作者:AK2806 QQ:642207429
-- 使用时请不要删除这条信息
-- 转载请注明
InterfaceController = class()
function InterfaceController:init() -- 实例化
self.setup = {[""] = function() end}
self.draw = {[""] = function() end}
self.touched = {[""] = function(touch) end}
self.presentInterface = ""
self.targetInterface = ""
self.animePerform = false
self.animeColor = color(255, 0)
self.presentTint = color(255, 255)
self.targetTint = color(255, 0)
self.animeType = ""
end
function InterfaceController:addInterface(name, setup, draw, touched) -- 添加界面
--(界面名(字符串),界面setup函数,界面draw函数,界面touched函数)
self.setup[name] = setup
self.draw[name] = draw
self.touched[name] = touched
end
function InterfaceController:changeInterface(targetInterface, animeType, time, animeColor) -- 界面切换
--(目标界面(字符串),动画类型(字符串),持续时间,中介颜色)
-- 注:当动画类型为none时,持续时间和中介颜色可以不填
-- 注:当动画类型为gradientOverchanging或者gradientOverlay时,
-- 中介颜色可以不填
if self.animePerform == true then
return
end
if animeType == "none" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.presentInterface = targetInterface
elseif animeType == "gradientColor" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.animeColor = color(animeColor.r, animeColor.g, animeColor.b, 0)
self.animeType = "gradientColor"
self.animePerform = true
tween(time / 2, self.animeColor, {a = 255}, tween.easing.linear,
function()
self.presentInterface = targetInterface
tween(time / 2, self.animeColor, {a = 0}, tween.easing.linear,
function()
self.animePerform = false
end)
end)
elseif animeType == "gradientOverchanging" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.animeType = "gradientOverchanging"
self.targetInterface = targetInterface
self.animePerform = true
tween(time, self.presentTint, {a = 0}, tween.easing.linear)
tween(time, self.targetTint, {a = 255}, tween.easing.linear,
function()
self.presentInterface = targetInterface
self.animePerform = false
self.presentTint = color(255, 255)
self.targetTint = color(255, 0)
end)
elseif animeType == "gradientOverlay" then
if self.setup[targetInterface] ~= nil then
self.setup[targetInterface]()
end
self.animeType = "gradientOverlay"
self.targetInterface = targetInterface
self.animePerform = true
tween(time, self.targetTint, {a = 255}, tween.easing.linear,
function()
self.presentInterface = targetInterface
self.animePerform = false
self.targetTint = color(255, 0)
end)
end
end
function InterfaceController:InterfaceDraw() -- 在draw()中调用
if self.animePerform == true and self.animeType == "gradientOverchanging" then
tint(self.presentTint)
else
tint(255)
end
self.draw[self.presentInterface]()
if self.animePerform == true and self.animeType == "gradientColor" then
pushStyle()
strokeWidth(0)
fill(self.animeColor)
rect(-1, -1, WIDTH + 2, HEIGHT + 2)
popStyle()
elseif self.animePerform == true and self.animeType == "gradientOverchanging" then
tint(self.targetTint)
self.draw[self.targetInterface]()
elseif self.animePerform == true and self.animeType == "gradientOverlay" then
tint(self.targetTint)
self.draw[self.targetInterface]()
end
end
function InterfaceController:InterfaceTouched(touch) -- 在touched(touch)中调用
if self.touched[self.presentInterface] ~= nil then
self.touched[self.presentInterface](touch)
end
end