| 1 |
# Copyright 2018 Stuart Buchanan |
| 2 |
# This file is part of FlightGear. |
| 3 |
# |
| 4 |
# FlightGear is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# FlightGear is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# FG1000 Base clearStyles |
| 18 |
|
| 19 |
print("\n############"); |
| 20 |
print("# FG1000 #"); |
| 21 |
print("############\n"); |
| 22 |
|
| 23 |
io.include("Constants.nas"); |
| 24 |
io.include("Commands.nas"); |
| 25 |
|
| 26 |
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/"; |
| 27 |
|
| 28 |
io.load_nasal(nasal_dir ~ '/ConfigStore.nas', "fg1000"); |
| 29 |
io.load_nasal(nasal_dir ~ '/MFDPage.nas', "fg1000"); |
| 30 |
io.load_nasal(nasal_dir ~ '/MFDPageController.nas', "fg1000"); |
| 31 |
io.load_nasal(nasal_dir ~ '/PFD.nas', "fg1000"); |
| 32 |
io.load_nasal(nasal_dir ~ '/MFD.nas', "fg1000"); |
| 33 |
io.load_nasal(nasal_dir ~ '/GUI.nas', "fg1000"); |
| 34 |
io.load_nasal(nasal_dir ~ '/NavMap.nas', "fg1000"); |
| 35 |
|
| 36 |
var FG1000 = { |
| 37 |
|
| 38 |
_instance : nil, |
| 39 |
|
| 40 |
# Factory method |
| 41 |
getOrCreateInstance : func(EIS_Class = nil, EIS_SVG = nil, SVG_Path = nil) { |
| 42 |
if (FG1000._instance == nil) { |
| 43 |
FG1000._instance = FG1000.new(EIS_Class, EIS_SVG, SVG_Path); |
| 44 |
} |
| 45 |
|
| 46 |
return FG1000._instance; |
| 47 |
}, |
| 48 |
|
| 49 |
new : func(EIS_Class = nil, EIS_SVG = nil, SVG_Path = nil) { |
| 50 |
var obj = { |
| 51 |
parents : [FG1000], |
| 52 |
displays : {} |
| 53 |
}; |
| 54 |
|
| 55 |
if (EIS_Class == nil) { |
| 56 |
# Load the default EIS class. |
| 57 |
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/"; |
| 58 |
io.load_nasal(nasal_dir ~ '/EIS/EIS-C182T.nas', "fg1000"); |
| 59 |
io.load_nasal(nasal_dir ~ '/EIS/EISController.nas', "fg1000"); |
| 60 |
io.load_nasal(nasal_dir ~ '/EIS/EISStyles.nas', "fg1000"); |
| 61 |
io.load_nasal(nasal_dir ~ '/EIS/EISOptions.nas', "fg1000"); |
| 62 |
obj.EIS_Class = fg1000.EIS; |
| 63 |
} else { |
| 64 |
obj.EIS_Class = EIS_Class; |
| 65 |
} |
| 66 |
|
| 67 |
if (EIS_SVG == nil) { |
| 68 |
obj.EIS_SVG = "/Aircraft/Instruments-3d/FG1000/MFDPages/EIS-C182T.svg"; |
| 69 |
} else { |
| 70 |
obj.EIS_SVG = EIS_SVG; |
| 71 |
} |
| 72 |
|
| 73 |
if (SVG_Path == nil) { |
| 74 |
obj.SVG_Path = "/Aircraft/Instruments-3d/FG1000/MFDPages/"; |
| 75 |
} else { |
| 76 |
obj.SVG_Path = SVG_Path; |
| 77 |
} |
| 78 |
|
| 79 |
obj.ConfigStore = fg1000.ConfigStore.new(); |
| 80 |
|
| 81 |
return obj; |
| 82 |
}, |
| 83 |
|
| 84 |
setSVGPath : func(SVG_Path) { |
| 85 |
me.SVG_Path = SVG_Path; |
| 86 |
}, |
| 87 |
|
| 88 |
setEIS : func(EIS_Class, EIS_SVG) { |
| 89 |
me.EIS_Class = EIS_Class; |
| 90 |
me.EIS_SVG = EIS.SVG; |
| 91 |
}, |
| 92 |
|
| 93 |
getDisplay : func(index) { |
| 94 |
return me.displays[index]; |
| 95 |
}, |
| 96 |
|
| 97 |
# Add an MFD, optionally setting the index. Returns the index of the MFD. |
| 98 |
addMFD : func(index=nil, targetcanvas=nil) { |
| 99 |
|
| 100 |
if (index == nil) { |
| 101 |
index = size(keys(me.displays)); |
| 102 |
} else if (me.displays[index] != nil) { |
| 103 |
print("FG1000 Index " ~ index ~ " already exists!"); |
| 104 |
return index; |
| 105 |
} |
| 106 |
|
| 107 |
if (targetcanvas == nil) { |
| 108 |
targetcanvas = canvas.new({ |
| 109 |
"name" : "MFD Canvas", |
| 110 |
"size" : [1024, 768], |
| 111 |
"view" : [1024, 768], |
| 112 |
"mipmapping": 0, |
| 113 |
}); |
| 114 |
} |
| 115 |
|
| 116 |
targetcanvas.set("visible", 0); |
| 117 |
|
| 118 |
var mfd = fg1000.MFDDisplay.new(me, me.EIS_Class, me.EIS_SVG, me.SVG_Path, targetcanvas, index); |
| 119 |
me.displays[index] = mfd; |
| 120 |
return index; |
| 121 |
}, |
| 122 |
|
| 123 |
# Add a PFD, optionally setting the index. Returns the index of the PFD. |
| 124 |
addPFD : func(index=nil, targetcanvas=nil) { |
| 125 |
|
| 126 |
if (index == nil) { |
| 127 |
index = size(keys(me.displays)); |
| 128 |
} else if (me.displays[index] != nil) { |
| 129 |
print("FG1000 Index " ~ index ~ " already exists!"); |
| 130 |
return index; |
| 131 |
} |
| 132 |
|
| 133 |
if (targetcanvas == nil) { |
| 134 |
targetcanvas = canvas.new({ |
| 135 |
"name" : "PFD Canvas", |
| 136 |
"size" : [1024, 768], |
| 137 |
"view" : [1024, 768], |
| 138 |
"mipmapping": 0, |
| 139 |
}); |
| 140 |
} |
| 141 |
|
| 142 |
targetcanvas.set("visible", 0); |
| 143 |
|
| 144 |
var pfd = fg1000.PFDDisplay.new(me, me.EIS_Class, me.EIS_SVG, me.SVG_Path, targetcanvas, index); |
| 145 |
me.displays[index] = pfd; |
| 146 |
return index; |
| 147 |
}, |
| 148 |
|
| 149 |
# Display the PFD/MFD on a particular target_object (defaults to "Screen{index}") |
| 150 |
display : func(index, target_object=nil) { |
| 151 |
if (me.displays[index] == nil) { |
| 152 |
print("displayMFD: unknown display index " ~ index); |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
if (target_object == nil) target_object = "Screen" ~ index; |
| 157 |
|
| 158 |
var targetcanvas = me.displays[index].getCanvas(); |
| 159 |
targetcanvas.addPlacement({"node": target_object}); |
| 160 |
}, |
| 161 |
|
| 162 |
displayGUI : func(index, scale=1.0) { |
| 163 |
if (me.displays[index] == nil) { |
| 164 |
print("displayMFD: unknown display index " ~ index); |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
var mfd_canvas = me.displays[index].getCanvas(); |
| 169 |
mfd_canvas.set("visible", 1); |
| 170 |
var gui = fg1000.GUI.new(me.displays[index], mfd_canvas, index, scale); |
| 171 |
}, |
| 172 |
|
| 173 |
getConfigStore : func() { |
| 174 |
return me.ConfigStore; |
| 175 |
}, |
| 176 |
|
| 177 |
setVisible : func(index = nil, visible = 1) { |
| 178 |
if (index == nil) { |
| 179 |
foreach(var display; values(me.displays)) { |
| 180 |
display.getCanvas().set("visible", visible); |
| 181 |
} |
| 182 |
} else { |
| 183 |
if (me.displays[index] == nil) { |
| 184 |
print("displayMFD: unknown display index " ~ index); |
| 185 |
} else { |
| 186 |
me.displays[index].getCanvas().set("visible", visible); |
| 187 |
} |
| 188 |
} |
| 189 |
}, |
| 190 |
|
| 191 |
show : func(index = nil) { |
| 192 |
me.setVisible(index, 1); |
| 193 |
}, |
| 194 |
|
| 195 |
hide : func(index = nil) { |
| 196 |
me.setVisible(index, 0); |
| 197 |
}, |
| 198 |
|
| 199 |
}; |