-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverManager.lua
More file actions
123 lines (105 loc) · 5 KB
/
Copy pathserverManager.lua
File metadata and controls
123 lines (105 loc) · 5 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
--servermanager
require("_build._simulator_config")
require("LifeBoatAPI")
--local std = require("STDebugger")
--LBs stupid buttons
-- color palette, keeping them here makes UI easier to restyle
color_Highlight = LifeBoatAPI.LBColorRGBA:lbcolorrgba_newGammaCorrected(230, 230, 230) -- offwhite
color_Inactive = LifeBoatAPI.LBColorRGBA:lbcolorrgba_newGammaCorrected(100,100,100) -- grey
color_Active = LifeBoatAPI.LBColorRGBA:lbcolorrgba_newGammaCorrected(200,200,200) -- white
-- define out button
hostButton = LifeBoatAPI.LBTouchScreen:lbtouchscreen_newStyledButton(85, 13, 58, 9, "Host Server", color_Highlight, color_Inactive, color_Active, color_Highlight,color_Inactive) -- using the TouchScreen functionality from LifeBoatAPI - make a simple button
stopHostingButton = LifeBoatAPI.LBTouchScreen:lbtouchscreen_newStyledButton(79, 89, 58, 6, "Kill Server", color_Highlight, color_Inactive, color_Active, color_Highlight,color_Inactive) -- using the TouchScreen functionality from LifeBoatAPI - make a simple button
hosting = false
connected = false
tick = 0
userServerCode = ""
function onTick()
LifeBoatAPI.LBTouchScreen:lbtouchscreen_onTick() -- touchscreen handler provided by LifeBoatAPI. Handles checking for clicks/releases etc.
inputY = input.getNumber(4)
inputX = input.getNumber(3)
ppressed = input.getBool(1) and not isPressed
isPressed = input.getBool(1)
draw = input.getBool(2)
if not draw then
tick = 0
end
serverCode = property.getNumber("Server code")
if serverCode == 0 then
serverCode = '0'
else
serverCode = string.format("%.0f", serverCode)
end
if hostButton:lbstyledbutton_isReleased() and not hosting then
if serverCode ~= '0' then
hosting = true
else
--std:throw(400)
--TODO: draw error text here
end
end
if stopHostingButton:lbstyledbutton_isReleased() and hosting then
hosting = false
end
if hosting then
output.setBool(1, true)
output.setNumber(1, tonumber(serverCode))
else
output.setBool(1, false)
end
end
function onDraw()
if draw then
if tick <= 1 then
tick = (tick+0.05)
end
--if not connected then should probably prompt to connect or host
if not connected and not hosting then
screen.setColor(255,255,255)
screen.drawText(1,1, "Enter Server Code: "..userServerCode)
screen.drawText(1,15, "Or start hosting: ")
hostButton:lbstyledbutton_draw()
drawKeypad(lerp(161,138,tick),33,true)
end
if hosting then
screen.setColor(255,255,255)
screen.drawText(1,screen.getHeight() - 6, "Hosting:" .. serverCode)
stopHostingButton:lbstyledbutton_draw()
end
end
end
function drawKeypad(x,y,outline)
local table = {"1","2","3","4","5","6","7","8","9","d","0","e"}
if butt(x,y,table[1],{255,255,255},outline) then userServerCode = userServerCode .. "1" end
if butt(x+7,y,table[2],{255,255,255}, outline) then userServerCode = userServerCode .. "2" end
if butt(x+14,y,table[3],{255,255,255}, outline) then userServerCode = userServerCode .. "3" end
if butt(x,y+8,table[4],{255,255,255}, outline) then userServerCode = userServerCode .. "4" end
if butt(x+7,y+8,table[5],{255,255,255}, outline) then userServerCode = userServerCode .. "5" end
if butt(x+14,y+8,table[6],{255,255,255}, outline) then userServerCode = userServerCode .. "6" end
if butt(x,y+16,table[7],{255,255,255}, outline) then userServerCode = userServerCode .. "7" end
if butt(x+7,y+16,table[8],{255,255,255}, outline) then userServerCode = userServerCode .. "8" end
if butt(x+14,y+16,table[9],{255,255,255}, outline) then userServerCode = userServerCode .. "9" end
if butt(x,y+24,table[10],{255,0,0}, outline) then userServerCode = string.sub(userServerCode, 0, string.len(userServerCode)-1) end
if butt(x+7,y+24,table[11],{255,255,255}, outline) then userServerCode = userServerCode .. "0" end
if butt(x+14,y+24,table[12],{0,255,0}, outline) then connectServer(userServerCode) end
end
function butt(x,y,l,color,outline) --bottom left, letter, color (rgb table)
local sc = screen
sc.setColor(0,0,0)
local buttonPressed = ppressed and isPointInRectangle(inputX, inputY, x+1, y+1, 6, 7)
local drawFill = isPressed and isPointInRectangle(inputX, inputY, x+1, y+1, 6, 7)
if drawFill then sc.setColor(20,20,20) sc.drawRectF(x+1,y+1, 6, 7) else sc.drawRectF(x,y, 7, 8) end
if outline then sc.setColor(255,255,255) sc.drawRect(x,y, 7, 8) end
sc.setColor(color[1],color[2],color[3])
sc.drawText(x + 2, y + 2, l)
return buttonPressed
end
-- It's a function that checks if a point is within a rectangle.
function isPointInRectangle(x, y, rectX, rectY, rectW, rectH)
return x >= rectX and y >= rectY and x < rectX+rectW and y < rectY+rectH
end
function lerp(a,b,p) --start(0%),end(100%), percentage
return (1-p)*a+p*b
end
function connectServer(code)
end