Display refactor, minor fixes
This commit is contained in:
mrSkortch 2015-05-07 00:11:15 -06:00
parent 941ff9708c
commit b82ade5d21
2 changed files with 132 additions and 271 deletions

392
mist.lua
View File

@ -7,8 +7,8 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 3 mist.majorVersion = 3
mist.minorVersion = 6 mist.minorVersion = 7
mist.build = 44 mist.build = 45
@ -140,12 +140,14 @@ do
newTable.modulation = data.modulation newTable.modulation = data.modulation
newTable.uncontrolled = data.uncontrolled newTable.uncontrolled = data.uncontrolled
newTable.radioSet = data.radioSet newTable.radioSet = data.radioSet
newTable.hidden = data.hidden
mistAddedGroups[index] = nil mistAddedGroups[index] = nil
end end
end end
if gfound == false then if gfound == false then
newTable.uncontrolled = false newTable.uncontrolled = false
newTable.hidden = false
end end
newTable.units = {} newTable.units = {}
@ -610,6 +612,10 @@ do
newGroup['name'] = tostring(tostring(cntry) .. tostring(typeName) .. mistDynAddIndex) newGroup['name'] = tostring(tostring(cntry) .. tostring(typeName) .. mistDynAddIndex)
end end
if not newGroup.hidden then
newGroup.hidden = false
end
for unitIndex, unitData in pairs(newGroup.units) do for unitIndex, unitData in pairs(newGroup.units) do
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
@ -688,7 +694,6 @@ do
newGroup.country = nil newGroup.country = nil
newGroup.tasks = {} newGroup.tasks = {}
newGroup.visible = false
for unitIndex, unitData in pairs(newGroup.units) do for unitIndex, unitData in pairs(newGroup.units) do
newGroup.units[unitIndex].unitName = nil newGroup.units[unitIndex].unitName = nil
@ -1842,12 +1847,16 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
mist.DBs.units[coa_name][countryName][category][group_num]["countryId"] = cntry_data.id mist.DBs.units[coa_name][countryName][category][group_num]["countryId"] = cntry_data.id
mist.DBs.units[coa_name][countryName][category][group_num]["startTime"] = group_data.start_time mist.DBs.units[coa_name][countryName][category][group_num]["startTime"] = group_data.start_time
mist.DBs.units[coa_name][countryName][category][group_num]["task"] = group_data.task mist.DBs.units[coa_name][countryName][category][group_num]["task"] = group_data.task
mist.DBs.units[coa_name][countryName][category][group_num]["hidden"] = group_data.hidden
mist.DBs.units[coa_name][countryName][category][group_num]["units"] = {} mist.DBs.units[coa_name][countryName][category][group_num]["units"] = {}
mist.DBs.units[coa_name][countryName][category][group_num]["radioSet"] = group_data.radioSet mist.DBs.units[coa_name][countryName][category][group_num]["radioSet"] = group_data.radioSet
mist.DBs.units[coa_name][countryName][category][group_num]["uncontrolled"] = group_data.uncontrolled mist.DBs.units[coa_name][countryName][category][group_num]["uncontrolled"] = group_data.uncontrolled
mist.DBs.units[coa_name][countryName][category][group_num]["frequency"] = group_data.frequency mist.DBs.units[coa_name][countryName][category][group_num]["frequency"] = group_data.frequency
mist.DBs.units[coa_name][countryName][category][group_num]["modulation"] = group_data.modulation mist.DBs.units[coa_name][countryName][category][group_num]["modulation"] = group_data.modulation
for unit_num, unit_data in pairs(group_data.units) do for unit_num, unit_data in pairs(group_data.units) do
local units_tbl = mist.DBs.units[coa_name][countryName][category][group_num]["units"] --pointer to the units table for this group local units_tbl = mist.DBs.units[coa_name][countryName][category][group_num]["units"] --pointer to the units table for this group
@ -1885,6 +1894,11 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
units_tbl[unit_num]["groupName"] = group_data.name units_tbl[unit_num]["groupName"] = group_data.name
units_tbl[unit_num]["groupId"] = group_data.groupId units_tbl[unit_num]["groupId"] = group_data.groupId
if unit_data.AddPropAircraft then
units_tbl[unit_num]["AddPropAircraft"] = unit_data.AddPropAircraft
end
end --for unit_num, unit_data in pairs(group_data.units) do end --for unit_num, unit_data in pairs(group_data.units) do
end --if group_data and group_data.units then end --if group_data and group_data.units then
end --for group_num, group_data in pairs(obj_type_data.group) do end --for group_num, group_data in pairs(obj_type_data.group) do
@ -3937,55 +3951,13 @@ end
-------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------
-------MESAGGES------ -------MESAGGES------
--[[
local msg = {}
msg.text = string (required)
msg.displayTime = number (required)
msg.msgFor = table (required)
msg.name = string (optional)
mist.message.add(msg)
msgFor accepts a table
]]
--[[
Need to change to this format...
scope:
{
units = {...}, -- unit names.
coa = {...}, -- coa names
countries = {...}, -- country names
CA = {...}, -- looks just like coa.
unitTypes = { red = {}, blue = {}, all = {}, Russia = {},}
}
scope examples:
{ units = { 'Hawg11', 'Hawg12' }, CA = {'blue'} }
{ countries = {'Georgia'}, unitTypes = {blue = {'A-10C', 'A-10A'}}}
{ coa = {'all'}}
{unitTypes = { blue = {'A-10C'}}}
]]
--[[ vars for mist.message.add
vars.text = 'Hello World'
vars.displayTime = 20
vars.msgFor = {coa = {'red'}, countries = {'Ukraine', 'Georgia'}, unitTypes = {'A-10C'}}
]]
do do
local messageList = {} local messageList = {}
local messageDisplayRate = 0.1 -- this defines the max refresh rate of the message box it honestly only needs to go faster than this for precision timing stuff (which could be its own function) local messageDisplayRate = 0.1 -- this defines the max refresh rate of the message box it honestly only needs to go faster than this for precision timing stuff (which could be its own function)
local messageID = 0 local messageID = 0
local displayActive = false
mist.message = { mist.message = {
@ -4020,15 +3992,26 @@ do
new.displayedFor = 0 -- how long the message has been displayed so far new.displayedFor = 0 -- how long the message has been displayed so far
new.name = vars.name -- ID to overwrite the older message (if it exists) Basically it replaces a message that is displayed with new text. new.name = vars.name -- ID to overwrite the older message (if it exists) Basically it replaces a message that is displayed with new text.
new.addedAt = timer.getTime() new.addedAt = timer.getTime()
new.update = true
if vars.multSound and vars.multSound[1] then
new.multSound = vars.multSound
else
new.multSound = {}
end
if vars.sound or vars.fileName then -- has no function yet, basic idea is to play the sound file for designated players. Had considered a more complex system similar to On Station audio messaging with staggering mesages, but that isn't entirely needed. if vars.sound or vars.fileName then -- converts old sound file system into new multSound format
-- additionally we could have an "outSound" function that will do just the audio alone with no text local sound = vars.sound
new.sound = vars.sound
if vars.fileName then if vars.fileName then
new.sound = vars.fileName sound = vars.fileName
end
new.multSound[#new.multSound+1] = {time = 0.1, file = sound}
end
if #new.multSound > 0 then
for i, data in pairs(new.multSound) do
data.played = false
end end
new.playAudio = true
end end
local newMsgFor = {} -- list of all groups message displays for local newMsgFor = {} -- list of all groups message displays for
@ -4093,6 +4076,8 @@ do
messageList[i].sound = new.sound messageList[i].sound = new.sound
messageList[i].text = new.text messageList[i].text = new.text
messageList[i].msgFor = new.msgFor messageList[i].msgFor = new.msgFor
messageList[i].multSound = new.multSound
messageList[i].update = true
return messageList[i].messageID return messageList[i].messageID
end end
end end
@ -4118,19 +4103,6 @@ do
end, end,
-- remove = function(self) -- not a self variable in this case; this function should be passed a self variable and does not need a message id; see example below.
-- for i, msgData in pairs(messageList) do
-- if messageList[i].messageID == self then
-- table.remove(messageList, i)
-- return true --removal successful
-- end
-- end
-- return false -- removal not successful this script fails at life!
-- end,
------------------------------------------------------
------------------------------------------------------
-- proposed changes:
remove = function(self) -- Now a self variable; the former functionality taken up by mist.message.removeById. remove = function(self) -- Now a self variable; the former functionality taken up by mist.message.removeById.
for i, msgData in pairs(messageList) do for i, msgData in pairs(messageList) do
if messageList[i] == self then if messageList[i] == self then
@ -4157,247 +4129,121 @@ do
------------------------------------------------------ ------------------------------------------------------
} }
----------------------------------------------------------------- local function mistdisplayV4()
-- No longer necessary, use the self:remove() instead.
-- Local function now
-- local function mistMSGDestroy(self) -- not a self variable
-- for i, msgData in pairs(messageList) do
-- if messageList[i] == self then
-- table.remove(messageList, i)
-- return true --removal successful
-- end
-- end
-- return false -- removal not successful this script fails at life!
-- end
-------------------------------------------------------------------------------
-- local function now
--[[
audio design concept
Need to stagger messages?
]]
-- local function now
local function mistdisplayV3() -- adding audio file support
-- CA roles
local caMessageRed = false
local caMessageBlue = false
local audioRed = false
local audioBlue = false
local audioPlaying = false
if #messageList > 0 then
--mist.debug.writeData(mist.utils.serialize,{'msg', messageList}, 'messageList.lua')
for messageId, messageData in pairs(messageList) do
if messageData.displayedFor > messageData.displayTime then
--mistMSGDestroy(messageData)
messageData:remove() -- now using the remove/destroy function.
else
if messageList[messageId].displayedFor then
messageList[messageId].displayedFor = messageList[messageId].displayedFor + messageDisplayRate
end
--[[else
if messageData.fileName then
audioPlaying = true
end]]
end
end
for coaData, coaId in pairs(coalition.side) do
local CAmsg = {}
local newestMsg = 100000000
for messageIndex, messageData in pairs(messageList) do
for forIndex, forData in pairs(messageData.msgFor) do
if coaData == forData then
if messageData.addedAt < newestMsg then
newestMsg = messageData.addedAt
end
if messageData.text then
CAmsg[#CAmsg + 1] = messageData.text
CAmsg[#CAmsg + 1] = '\n ---------------- \n'
end
if type(messageData.sound) == 'string' and messageData.addedAt + messageDisplayRate > timer.getTime() then
if coaData == 'RED' then
audioRed = true
trigger.action.outSoundForCoalition(coalition.side.RED, messageData.sound)
elseif coaData == 'BLUE' then
audioBlue = true
trigger.action.outSoundForCoalition(coalition.side.BLUE, messageData.sound)
end
end
end
end
end
if #CAmsg > 0 then
if newestMsg < timer.getTime() + .5 then
if coaData == 'BLUE' then
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(CAmsg), 1)
caMessageBlue = true
elseif coaData == 'RED' then
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(CAmsg), 1)
caMessageRed = true
end
end
end
end
for clientId, clientData in pairs(mist.DBs.humansById) do
local clientDisplay = {}
for messageIndex, messageData in pairs(messageList) do if displayActive == false then
for forIndex, forData in pairs(messageData.msgFor) do displayActive = true
if clientId == forData and Group.getByName(clientData.groupName) then end
if messageData.text then local activeClients = {}
clientDisplay[#clientDisplay + 1] = messageData.text
clientDisplay[#clientDisplay + 1] = '\n ---------------- \n' for clientId, clientData in pairs(mist.DBs.humansById) do
end if Unit.getByName(clientData.unitName) and Unit.getByName(clientData.unitName):isExist() == true then
if string.lower(clientData.coalition) == 'red' and audioRed == false or string.lower(clientData.coalition) == 'blue' and audioBlue == false then activeClients[clientData.groupId] = clientData.groupName
if type(messageData.sound) == 'string' and messageData.addedAt + messageDisplayRate > timer.getTime() then
trigger.action.outSoundForGroup(clientData.groupId, messageData.sound)
end
end
end
end
end
if #clientDisplay > 0 then
trigger.action.outTextForGroup(clientData.groupId, table.concat(clientDisplay), 1)
elseif #clientDisplay == 0 then
if clientData.coalition == 'blue' and caMessageBlue == true then
trigger.action.outTextForGroup(clientData.groupId, 'Blue CA Recieving Message', 1) -- I'd rather this recive the message with a note that its for CA than a blank message box.
elseif clientData.coalition == 'red' and caMessageRed == true then
trigger.action.outTextForGroup(clientData.groupId, 'Red CA Recieving Message', 1)
end
end
end end
end end
end
local function mistdisplayV4()
-- goal of v4, send new messages only if message has changed, rather than at a constant rate
-- make process more effecient!
-- possibly change messages for CA players
local caMessageRed = false
local caMessageBlue = false
local audioRed = false
local audioBlue = false
local audioPlaying = false
if #messageList > 0 then if #messageList > 0 then
--mist.debug.writeData(mist.utils.serialize,{'msg', messageList}, 'messageList.lua') --mist.debug.writeData(mist.utils.serialize,{'msg', messageList}, 'messageList.lua')
local msgTableText = {}
local msgTableSound = {}
for messageId, messageData in pairs(messageList) do for messageId, messageData in pairs(messageList) do
if messageData.displayedFor > messageData.displayTime then if messageData.displayedFor > messageData.displayTime then
--mistMSGDestroy(messageData)
messageData:remove() -- now using the remove/destroy function. messageData:remove() -- now using the remove/destroy function.
else else
if messageList[messageId].displayedFor then if messageList[messageId].displayedFor then
messageList[messageId].displayedFor = messageList[messageId].displayedFor + messageDisplayRate messageList[messageId].displayedFor = messageList[messageId].displayedFor + messageDisplayRate
end end
--[[else local nextSound = 1000
if messageData.fileName then local soundIndex = 0
audioPlaying = true
end]]
end
end
for coaData, coaId in pairs(coalition.side) do
local CAmsg = {}
local newestMsg = 100000000
for messageIndex, messageData in pairs(messageList) do
for forIndex, forData in pairs(messageData.msgFor) do
if coaData == forData then if messageData.multSound then
if messageData.addedAt < newestMsg then for index, sData in pairs(messageData.multSound) do
newestMsg = messageData.addedAt if sData.time < messageData.displayedFor and sData.played == false and sData.time < nextSound then -- find index of the next sound to be played
nextSound = sData.time
soundIndex = index
end end
if messageData.text then end
CAmsg[#CAmsg + 1] = messageData.text if soundIndex ~= 0 then
CAmsg[#CAmsg + 1] = '\n ---------------- \n' messageData.multSound[soundIndex].played = true
end
if type(messageData.sound) == 'string' and messageData.addedAt + messageDisplayRate > timer.getTime() then
if coaData == 'RED' then
audioRed = true
trigger.action.outSoundForCoalition(coalition.side.RED, messageData.sound)
elseif coaData == 'BLUE' then
audioBlue = true
trigger.action.outSoundForCoalition(coalition.side.BLUE, messageData.sound)
end
end
end end
end end
end
if #CAmsg > 0 then for recIndex, recData in pairs(messageData.msgFor) do -- iterate recipiants
if newestMsg < timer.getTime() + .5 then if recData == 'RED' or recData == 'BLUE' or activeClients[recData] then -- rec exists
if coaData == 'BLUE' then if messageData.text then -- text
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(CAmsg), 1) if not msgTableText[recData] then -- create table entry for text
caMessageBlue = true msgTableText[recData] = {}
elseif coaData == 'RED' then msgTableText[recData].text = {}
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(CAmsg), 1) if recData == 'RED' or recData == 'BLUE' then
caMessageRed = true msgTableText[recData].text[1] = '---------------- Combined Arms Message: \n'
end end
end msgTableText[recData].text[2] = messageData.text
end msgTableText[recData].displayTime = messageData.displayTime - messageData.displayedFor
end else -- add to table entry and adjust display time if needed
for clientId, clientData in pairs(mist.DBs.humansById) do if recData == 'RED' or recData == 'BLUE' then
local clientDisplay = {} msgTableText[recData].text[#msgTableText[recData].text + 1] = '\n ---------------- Combined Arms Message: \n'
else
for messageIndex, messageData in pairs(messageList) do msgTableText[recData].text[#msgTableText[recData].text + 1] = '\n ---------------- \n'
for forIndex, forData in pairs(messageData.msgFor) do end
if clientId == forData and Group.getByName(clientData.groupName) then msgTableText[recData].text[#msgTableText[recData].text + 1] = messageData.text
if messageData.text then if msgTableText[recData].displayTime < messageData.displayTime - messageData.displayedFor then
clientDisplay[#clientDisplay + 1] = messageData.text msgTableText[recData].displayTime = messageData.displayTime - messageData.displayedFor
clientDisplay[#clientDisplay + 1] = '\n ---------------- \n' end
end
if string.lower(clientData.coalition) == 'red' and audioRed == false or string.lower(clientData.coalition) == 'blue' and audioBlue == false then
if type(messageData.sound) == 'string' and messageData.addedAt + messageDisplayRate > timer.getTime() then
trigger.action.outSoundForGroup(clientData.groupId, messageData.sound)
end end
end end
if soundIndex ~= 0 then
msgTableSound[recData] = messageData.multSound[soundIndex].file
end
end end
end end
end
if #clientDisplay > 0 then
trigger.action.outTextForGroup(clientData.groupId, table.concat(clientDisplay), 1)
elseif #clientDisplay == 0 then
if clientData.coalition == 'blue' and caMessageBlue == true then
trigger.action.outTextForGroup(clientData.groupId, 'Blue CA Recieving Message', 1) -- I'd rather this recive the message with a note that its for CA than a blank message box.
elseif clientData.coalition == 'red' and caMessageRed == true then
trigger.action.outTextForGroup(clientData.groupId, 'Red CA Recieving Message', 1)
end
end end
end
------- new display
if msgTableText['RED'] then
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(msgTableText['RED'].text), msgTableText['RED'].displayTime)
end
if msgTableText['BLUE'] then
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime)
end
for index, msgData in pairs(msgTableText) do
if type(index) == 'number' then -- its a groupNumber
trigger.action.outTextForGroup(index, table.concat(msgData.text), msgData.displayTime)
end
end end
--- new audio
if msgTableSound['RED'] then
trigger.action.outSoundForCoalition(coalition.side.RED, msgTableSound['RED'])
end
if msgTableSound['BLUE'] then
trigger.action.outSoundForCoalition(coalition.side.BLUE, msgTableSound['BLUE'])
end
for index, file in pairs(msgTableSound) do
if type(index) == 'number' then -- its a groupNumber
trigger.action.outSoundForGroup(index, file)
end
end
--- old code
end end
end end
local funcId = 0 local funcId = 0
local function displayManager() local function displayManager()
if #messageList > 0 and funcId > 0 then if #messageList > 0 and funcId > 0 then
mistdisplayV3() mistdisplayV4()
funcId = mist.scheduleFunction(displayManager, {}, timer.getTime() + messageDisplayRate, messageDisplayRate) funcId = mist.scheduleFunction(displayManager, {}, timer.getTime() + messageDisplayRate, messageDisplayRate)
else else
mist.removeFunction(funcId)-- kill mist.removeFunction(funcId)-- kill
end end
end end
--mistdisplayV4()
mist.scheduleFunction(mistdisplayV3, {}, timer.getTime() + messageDisplayRate, messageDisplayRate) -- add this to the main mist thing mist.scheduleFunction(mistdisplayV4, {}, timer.getTime() + messageDisplayRate, messageDisplayRate) -- add this to the main mist thing
end end
-- End of message system -- End of message system
@ -4940,13 +4786,16 @@ end
mist.getCurrentGroupData = function(gpName) mist.getCurrentGroupData = function(gpName)
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
local dbData = mist.getGroupData(gpName)
local newGroup = Group.getByName(gpName) local newGroup = Group.getByName(gpName)
local newData = {} local newData = {}
newData.name = gpName newData.name = gpName
newData.groupId = tonumber(newGroup:getID()) newData.groupId = tonumber(newGroup:getID())
newData.category = newGroup:getCategory() newData.category = newGroup:getCategory()
newData.groupName = gpName newData.groupName = gpName
newData.hidden = dbData.hidden
if newData.category == 2 then if newData.category == 2 then
newData.category = 'vehicle' newData.category = 'vehicle'
elseif newData.category == 3 then elseif newData.category == 3 then
@ -5001,7 +4850,7 @@ mist.getGroupData = function(gpName)
payloads = mist.getGroupPayload(newData.groupName) payloads = mist.getGroupPayload(newData.groupName)
end end
if found == true then if found == true then
newData.hidden = false -- maybe add this to DBs --newData.hidden = false -- maybe add this to DBs
for unitNum, unitData in pairs(newData.units) do for unitNum, unitData in pairs(newData.units) do
newData.units[unitNum] = {} newData.units[unitNum] = {}
@ -5025,6 +4874,7 @@ mist.getGroupData = function(gpName)
newData.units[unitNum]['livery_id'] = unitData.livery_id newData.units[unitNum]['livery_id'] = unitData.livery_id
newData.units[unitNum]['onboard_num'] = unitData.onboard_num newData.units[unitNum]['onboard_num'] = unitData.onboard_num
newData.units[unitNum]['callsign'] = unitData.callsign newData.units[unitNum]['callsign'] = unitData.callsign
newData.units[unitNum]['AddPropAircraft'] = unitData.AddPropAircraft
end end
end end

View File

@ -1,4 +1,15 @@
-- changelog -- changelog
v45
-Added values to DBs
--hidden
--AddPropAircraft
-getGroupData now returns hidden and addPropAircraft values
-getCurrentGroupData now returns hidden value
-mist message handling has been updated
--Refactored message display code to be more effecient and remove repeated code.
--Added "multSound" for mist.message.add. This allows for multiple sound files to be attached to a single message. Files are given a user defined timestamp for when the play within the message.
v44 v44
-fxed getPayload for real this time -fxed getPayload for real this time
-addEventHandler now correctly returns the Id value -addEventHandler now correctly returns the Id value