-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
126 lines (110 loc) · 2.9 KB
/
Copy pathinit.lua
File metadata and controls
126 lines (110 loc) · 2.9 KB
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
local nis = { _version = "0.1" }
local utils = require "nis.utils"
nis.active = {}
nis.screen = {
w = love.graphics.getPixelWidth(),
h = love.graphics.getPixelHeight(),
lastw = love.graphics.getPixelWidth(),
lasth = love.graphics.getPixelHeight(),
}
function nis.Create( type, parent )
local loader, error = love.filesystem.load( "nis/Objects/"..type..".lua" )
if error then
love.errhand( error )
else
local this = loader( type, parent )
table.insert( nis.active, this )
if parent then
parent.children[this.id] = this
end
return nis.active[this.id]
end
end
function nis.draw()
for k, v in pairs( nis.active ) do
v:Draw()
end
end
function nis.update( dt )
for k, v in pairs( nis.active ) do
v:InternalThink( dt )
end
end
function nis.resize( w, h )
nis.screen.lastw = nis.screen.w
nis.screen.lasth = nis.screen.h
nis.screen.w = w
nis.screen.h = h
for k, v in pairs( nis.active ) do
v:Resize( w, h, nis.screen.lastw, nis.screen.lasth )
end
end
function nis.mousepressed( x, y, button )
for k, v in pairs( nis.active ) do
if v.hovered then
v:OnPressed( button )
end
end
if button == 1 then
for k, v in pairs( nis.active ) do
if v:IsHovered() and v:IsEnabled() then
v.pressed = true
end
end
end
end
function nis.mousereleased( x, y, button )
for k, v in pairs( nis.active ) do
if v.hovered then
v:OnReleased( button )
end
end
if button == 1 then
for k, v in pairs( nis.active ) do
if v:IsHovered() and v:IsPressed() and v:IsEnabled() then
v.pressed = false
v:DoClick()
end
end
end
end
function nis.mousemoved( x, y, dx, dy )
for k, v in pairs( nis.active ) do
v:MouseMoved( x, y, dx, dy )
end
end
local function PopUpType(type)
local types = {
["error"] = {
bg = { r = 150, g = 58, b = 58 },
title = { r = 58, g = 58, b = 58 },
bar = { r = 150, g = 150, b = 150 },
},
["info"] = {
bg = { r = 58, g = 150, b = 150 },
title = { r = 58, g = 58, b = 58 },
bar = { r = 150, g = 150, b = 150 },
},
}
return types[type] or types["error"]
end
function nis.PopUp(title, message, type)
local colors = PopUpType(type)
local popup = nis.Create("Frame")
popup:SetSize(250,100)
popup:SetTitle(title or "Error")
popup:SetColor( colors.bg.r, colors.bg.g, colors.bg.b )
popup:SetBarColor( colors.bar.r, colors.bar.g, colors.bar.b )
popup:SetTitleColor( colors.title.r, colors.title.g, colors.title.b )
popup:Center()
local popup_text = nis.Create("MultilineLabel", popup)
popup_text:SetText(message or "nil")
popup_text:SetAlign("left")
popup_text:Center()
return popup
end
function DerivePanel( parent, child )
local PANEL = love.filesystem.load( "nis/Objects/"..parent..".lua" )( parent, child.parent )
return utils.fusionTable( PANEL, child )
end
return nis