-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToggleSettingEvent.lua
62 lines (53 loc) · 1.82 KB
/
ToggleSettingEvent.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
-- ============================================================= --
-- TOGGLE SETTING EVENT
-- ============================================================= --
ToggleSettingEvent = {}
ToggleSettingEvent_mt = Class(ToggleSettingEvent, Event)
InitEventClass(ToggleSettingEvent, "ToggleSettingEvent")
function ToggleSettingEvent.emptyNew()
--print("ToggleSetting - EMPTY NEW")
local self = Event.new(ToggleSettingEvent_mt)
return self
end
function ToggleSettingEvent.new(id, value)
--print("ToggleSetting - NEW")
local self = ToggleSettingEvent.emptyNew()
self.id = id
self.value = value
return self
end
function ToggleSettingEvent:readStream(streamId, connection)
--print("ToggleSetting - READ STREAM")
local id = streamReadString(streamId)
local value = streamReadBool(streamId)
self.id = id
self.value = value
TipAnywhere.insertMenuItem(id)
TipAnywhere.setValue(id, value)
if connection:getIsServer() then
--print(" APPLY SETTINGS")
local menuOption = TipAnywhere.CONTROLS[id]
local isAdmin = g_currentMission:getIsServer() or g_currentMission.isMasterUser
menuOption:setState(TipAnywhere.getStateIndex(id))
menuOption:setDisabled(not isAdmin)
else
--print(" RESEND EVENT")
ToggleSettingEvent.sendEvent(id, value)
end
end
function ToggleSettingEvent:writeStream(streamId, connection)
--print("ToggleSetting - WRITE STREAM");
streamWriteString(streamId, self.id)
streamWriteBool(streamId, self.value)
end
function ToggleSettingEvent.sendEvent(id, value, noEventSend)
if noEventSend == nil or noEventSend == false then
if g_server ~= nil then
--print("server: Toggle Setting Event")
g_server:broadcastEvent(ToggleSettingEvent.new(id, value), false)
else
--print("client: Toggle Setting Event")
g_client:getServerConnection():sendEvent(ToggleSettingEvent.new(id, value))
end
end
end