aboutsummaryrefslogtreecommitdiff
path: root/window.lua
blob: a0afc7addbea3bf69e069fa1e6b73ffc1b218f89 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
function drawWindow(id)
  if win[id].update == true then
    love.graphics.setCanvas(win[id].cvs)
    drawUpBox(0, 0, win[id].w, win[id].h, 4)
    love.graphics.setColor(255,255,255)
    if win[id].bar == "active" then
      love.graphics.draw(window.bar, 0+3, 0+3, 0, (win[id].w-7)/643, 1)
    else
      love.graphics.draw(window.barGrey, 0+3, 0+3, 0, (win[id].w-7)/643, 1)
    end
    drawXBox(win[id].w-22, 5)
    drawMinBox(win[id].w-40, 5)
    love.graphics.setColor(240, 240, 240)
    love.graphics.print(win[id].title, 28, 9)
    love.graphics.setColor(256, 256, 256)
    love.graphics.draw(win[id].icon16, 6, 5)
    if id == 4 then
      drawAntivirus()
    elseif id == 1 then
      drawChat()
    elseif id == 2 then
      drawInternet()
    elseif id == 6 then
      drawSettings()
    elseif id == 3 then
      drawFiles()
    elseif id == 5 then
      drawHelp()
    elseif id == 7 then
      drawPicture()
    elseif id == 9 then
      drawMusic()
    elseif id == 8 then
      drawVideo()
    end
    love.graphics.setCanvas()
    win[id].update = false
  end
  if(sys.mouse.x >= win[id].x and sys.mouse.x <= win[id].x+win[id].w
  and sys.mouse.y >= win[id].y and sys.mouse.y <= win[id].y+win[id].h and win[id].ex == false) then
    win[id].hov = true
    winHover = true
  else
    win[id].hov = false
  end
  if layer[1] ~= 0 and win[id].ex == false then
    if win[id].layer ~= 1 and win[layer[1]].hov == true then
      win[id].hover = false
    elseif win[id].layer ~= 1 and win[id].layer ~= 2 and layer[1] ~= 0 and layer[2] ~= 0 and v1.timer <= 4 then
      if win[layer[1]].hov == true or win[layer[2]].hov == true then
        win[id].hover = false
      else
        win[id].hover = true
      end
    elseif win[id].hov == false then
      win[id].hover = false
    else
      win[id].hover = true
    end
    if win[id].layer ~= 1 and v1.timer <= 4 then
      for i=1,win[id].layer-1 do
        if win[layer[i]].hov == true then
          win[id].hover = false
        end
      end
    end
  end
  if win[id].hov == false then
    win[id].hover = false
  end
  if sys.mouse.y >= sys.h-panel.thick then
    win[id].hover = false
  end
  if win[id].ex == true then
    win[id].hover = false
  end
  if(sys.mouse.p.x >= win[id].x and sys.mouse.p.x <= win[id].x+win[id].w
  and sys.mouse.p.y >= win[id].y and sys.mouse.p.y <= win[id].y+win[id].h) then
  else
    win[id].hover = false
  end
  if win[id].hover == true and sys.mouse.p.p == true and sys.mouse.drag == false then
    layer.sentToFront = id
  end
  if(sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+2 and sys.mouse.p.x <= (win[id].x+2)+(win[id].w-44)
  and sys.mouse.p.y >= win[id].y+2 and sys.mouse.p.y <= win[id].y+22 and win[id].hover == true) then
    sys.mouse.drag = true
  end
  if sys.mouse.p.p == false then
    sys.mouse.drag = false
    win[id].px = win[id].x
    win[id].py = win[id].y
  end
  if sys.mouse.drag == true and win[id].min == false and win[id].ex == false and layer[1] == id then
    if id == 4 and v1.yes == true then
      windowMouseMove(id,0,sys.w-win[id].w,sys.h/2,sys.h-win[id].h-panel.thick-1)
    else
      windowMouseMove(id,0,sys.w-win[id].w,0,sys.h-win[id].h-panel.thick-1)
    end
  end
  if win[id].min ~= true and win[id].miny <= 0 then
    if win[id].x > sys.w-win[id].w then
      win[id].x = sys.w-win[id].w
    elseif win[id].x < 0 then
      win[id].x = 0
    end
    if win[id].y > sys.h-win[id].h then
      win[id].y = sys.h-win[id].h
    elseif win[id].y < 0 then
      win[id].y = 0
    end
  end
  if v1.yes == true and id ~= 2 and win[id].ex == false and v1.timer >= 4 and v1.c.chat.msgs < 7 then
    win[id].ex = true
  end
  if v1.yes == true and id == 2 and v1.timer >= 4 then
    layer.sendToFront = 2
  end
  if (sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+win[id].w-22 and sys.mouse.p.x <= (win[id].x+win[id].w-22)+16 and win[id].ex == false
  and sys.mouse.drag == false and sys.mouse.p.y >= win[id].y+5 and sys.mouse.p.y <= (win[id].y+5)+16 and win[id].hover == true) and v1.yes == false then
    win[id].ex = true
  end
  if win[id].ex == true and win[id].s ~= 0 then
    win[id].s = win[id].s - (0.4*win[id].s)*sys.s
  elseif win[id].ex == false and win[id].s ~= 0 then
    win[id].s = win[id].s + (0.075/win[id].s)*sys.s
  end
  if win[id].s > 1 then
    win[id].s = 1
  elseif win[id].s < 0 then
    win[id].s = 0
  end
  if (win[id].min == false and sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+win[id].w-40
  and sys.mouse.p.x <= (win[id].x+win[id].w-40)+16 and sys.mouse.drag == false and sys.mouse.p.y >= win[id].y+5
  and sys.mouse.p.y <= (win[id].y+5)+16 and win[id].hover == true) and v1.yes == false then
    win[id].min = true
  end
  if win[id].min == true and win[id].miny < minim then
    win[id].y = win[id].y + 150*sys.s
    win[id].miny = win[id].miny + 150*sys.s
  end
  if win[id].miny > minim then
    win[id].miny = minim
  end
  if win[id].min == false and win[id].miny > 0 then
    win[id].y = win[id].y - 150*sys.s
    win[id].miny = win[id].miny - 150*sys.s
  end
  if win[id].miny < 0 then
    win[id].miny = 0
  end
  if id == 4 and win[4].crazy == true then
    if win[4].crazyLeft == true and win[4].x >= 100 then
      win[4].x = win[4].x - 10+v1.spm*sys.s
    elseif win[4].crazyLeft == false and win[4].x <= sys.w-300 then
      win[4].x = win[4].x + 10+v1.spm*sys.s
    end
    if win[4].x <= 150 then
      win[4].crazyLeft = false
    elseif win[4].x >= sys.w-350 then
      win[4].crazyLeft = true
    end
    if win[4].crazyUp == true and win[4].y >= sys.h/2+50 then
      win[4].y = win[4].y - 6+v1.spm*sys.s
    elseif win[4].crazyUp == false and win[4].y <= sys.h-panel.thick-200 then
      win[4].y = win[4].y + 6+v1.spm*sys.s
    end
    if win[4].y <= sys.h/2+50 then
      win[4].crazyUp = false
    elseif win[4].y >= sys.h-panel.thick-200 then
      win[4].crazyUp = true
    end
    if sys.mouse.drag == true or v1.c.chat.msgs >= 41 then
      win[4].crazy = false
    end
  end
  if id == 4 then
    updateAntivirus()
  elseif id == 1 then
    updateChat()
  elseif id == 2 then
    updateInternet()
  elseif id == 6 then
    updateSettings()
  elseif id == 3 then
    updateFiles()
  elseif id == 9 then
    updateMusic()
  elseif id == 8 then
    updateVideo()
  end
  if id == layer[1] and win[id].bar == "grey" then
    win[id].bar = "active"
    win[id].update = true
  elseif id ~= layer[1] and win[id].bar == "active" then
    win[id].bar = "grey"
    win[id].update = true
  end
  love.graphics.setColor(255,255,255)
end
function orderWindows()
  if layer.sentToFront ~= 0 and layer[1] ~= layer.sentToFront then
    if win[layer.sentToFront].layer ~= 0 then
      table.remove(layer, win[layer.sentToFront].layer)
    end
    table.insert(layer, 1, layer.sentToFront)
    win[layer.sentToFront].oldlayer = win[layer.sentToFront].layer
    win[layer.sentToFront].layer = 1
    layer.sentToFront = 0
  end
  for i=1,#win do
    closeWindow((#win+1)-i)
  end
  for i=1,#win do
    setWindow((#win+1)-i)
    setPanel((#win+1)-i)
    drawWindow((#win+1)-i)
  end
end
function setWindow(id)
  if layer[id] ~= nil then
    win[layer[id]].oldlayer = win[layer[id]].layer
    win[layer[id]].layer = id
  end
end
function setPanel(id)
  if win[id].ex == false and win[id].pan == 0 then
    table.insert(panel.b, id)
    win[id].pan = #panel.b
  end
  if win[id].ex == true and win[id].pan ~= 0 then
   table.remove(panel.b, win[id].panel)
   for i=1,#panel.b do
     if panel.b[i] == id then
       table.remove(panel.b, i)
     end
   end
   win[id].pan = 0
  end
end
function closeWindow(id)
  if win[id].ex == true and win[id].s == 0 then
    win[id].exit = true
    win[id].oldlayer = win[id].layer
  else
    win[id].exit = false
  end
  if win[id].layer ~= 0 and win[id].exit == true then
    table.remove(layer, win[id].layer)
    win[id].oldlayer = win[id].layer
    win[id].layer = 0
  end
end
function windowMouseMove(id,limitx,limitw,limity,limith)
  if win[id].px+(sys.mouse.x - sys.mouse.p.x) >= limitx and win[id].px+(sys.mouse.x - sys.mouse.p.x) <= limitw then
    win[id].x = win[id].px + (sys.mouse.x - sys.mouse.p.x)
  elseif win[id].px+(sys.mouse.x - sys.mouse.p.x) < limitx then
    win[id].x = limitx
  elseif win[id].px+(sys.mouse.x - sys.mouse.p.x) > limitw then
    win[id].x = limitw
  end
  if win[id].py+(sys.mouse.y - sys.mouse.p.y) >= limity and win[id].py+(sys.mouse.y - sys.mouse.p.y) <= limith then
    win[id].y = win[id].py + (sys.mouse.y - sys.mouse.p.y)
  elseif win[id].py+(sys.mouse.y - sys.mouse.p.y) < limity then
    win[id].y = limity
  elseif win[id].py+(sys.mouse.y - sys.mouse.p.y) > limith then
    win[id].y = limith
  end
end
function mouseClick(x,y,w,h)
  if sys.mouse.p.x >= x and sys.mouse.p.x <= x+w and
  sys.mouse.p.y >= y and sys.mouse.p.y <= y+h and
  sys.mouse.p.p == true and sys.mouse.drag == false then
    return true
  end
end