-
Notifications
You must be signed in to change notification settings - Fork 0
/
newAnimationView.lua
131 lines (111 loc) · 3.44 KB
/
newAnimationView.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
local INPUT_NAME = 1
local INPUT_X = 2
local INPUT_Y = 3
local LAYER_NAME = "newAnimation"
local image
local selectedInput = 1
local inputs = {"","",""}
local buttons = {{x = 202, y = 100,
width = 50, height = 20,
onClick = function()
selectedInput = INPUT_NAME
end
},
{x = 202, y = 120,
width = 50, height = 20,
onClick = function()
selectedInput = INPUT_X
end
},
{x = 202, y = 140,
width = 50, height = 20,
onClick = function()
selectedInput = INPUT_Y
end
},
{x = 202, y = 160,
width = 50, height = 20,
onClick = function()
newAnimationView.submit()
end
},
}
uimanager.layer.addLayer(LAYER_NAME)
local newAnimationView = {}
newAnimationView.show = function()
uimanager.layer.enableLayer(LAYER_NAME)
uimanager.layer.showLayer(LAYER_NAME)
end
newAnimationView.hide = function()
uimanager.layer.hideLayer(LAYER_NAME)
end
newAnimationView.submit = function()
local x = 0
local y = 0
if inputs[INPUT_X] then
x = tonumber(inputs[INPUT_X])
else
love.errhand("X value not provided")
end
if inputs[INPUT_Y] then
y = tonumber(inputs[INPUT_Y])
else
love.errhand("Y value not provided")
end
love.event.push("newAnimationCreated", inputs[INPUT_NAME], x, y)
end
newAnimationView.init = function(newImage)
image = newImage
end
newAnimationView.draw = function()
if selectedInput == INPUT_NAME then
love.graphics.print("name: [".. inputs[INPUT_NAME].."]", buttons[1].x, buttons[1].y)
else
love.graphics.print("name: " .. inputs[INPUT_NAME], buttons[1].x, buttons[1].y)
end
if selectedInput == INPUT_X then
love.graphics.print("x: ["..inputs[INPUT_X].."]", buttons[2].x, buttons[2].y)
else
love.graphics.print("x:" .. inputs[INPUT_X], buttons[2].x, buttons[2].y)
end
if selectedInput == INPUT_Y then
love.graphics.print("y: ["..inputs[INPUT_Y].."]", buttons[3].x, buttons[3].y)
else
love.graphics.print("y:" .. inputs[INPUT_Y], buttons[3].x, buttons[3].y)
end
love.graphics.print("Submit", buttons[4].x, buttons[4].y)
if image ~= nil then
love.graphics.draw(image, 300, 300)
end
end
newAnimationView.mousePressed = function(x, y)
for index, button in ipairs(buttons) do
if x > button.x and x < button.x + button.width and
y > button.y and y < button.y + button.height then
button.onClick()
end
end
end
newAnimationView.keyPressed = function(key)
if key == "tab" or key == "return" then
if key == "return" and selectedInput <= 0 then
newAnimationView.submit()
elseif selectedInput < 3 then
selectedInput = selectedInput + 1
else
selectedInput = 0
end
elseif key == "backspace" then
inputs[selectedInput] = string.sub(inputs[selectedInput], 1, #inputs[selectedInput] - 1)
end
end
newAnimationView.textInput = function(text)
if selectedInput == INPUT_NAME then
inputs[INPUT_NAME] = inputs[INPUT_NAME] .. text
elseif selectedInput == INPUT_X then
inputs[INPUT_X] = inputs[INPUT_X] .. text
elseif selectedInput == INPUT_Y then
inputs[INPUT_Y] = inputs[INPUT_Y] .. text
end
end
return newAnimationView