1
0
Fork 0

Set up dialog to list nearby AI-objects which can be controlled, interface Truman with dialog

This commit is contained in:
Thorsten Renk 2017-09-05 10:18:55 +03:00
parent a6dac604eb
commit f8dc5cd7c7
4 changed files with 157 additions and 2 deletions

View file

@ -23,6 +23,9 @@ by Thorsten Renk 2017
var pathc = cmdarg().getPath();
var self = cmdarg();
# register the dialog
setprop(pathc~"/dlg-name", "Truman");
# times for components to move to their position
@ -3899,7 +3902,7 @@ by Thorsten Renk 2017
<repeatable>false</repeatable>
<binding>
<command>dialog-show</command>
<dialog-name>TrumanControls</dialog-name>
<dialog-name>Truman</dialog-name>
<property></property>
</binding>
</action>

107
gui/dialogs/ai-objects.xml Normal file
View file

@ -0,0 +1,107 @@
<?xml version="1.0"?>
<PropertyList>
<name>ai-objects</name>
<layout>vbox</layout>
<default-padding>1</default-padding>
<modal>false</modal>
<width>400</width>
<empty>
<pref-height>6</pref-height>
</empty>
<text>
<label>Control nearby AI objects</label>
</text>
<empty>
<pref-height>4</pref-height>
</empty>
<hrule/>
<group>
<layout>table</layout>
<text>
<label>Select an AI object to bring up its own control dialog</label>
<halign>left</halign>
<row>0</row>
<col>0</col>
</text>
<combo>
<row>1</row>
<col>0</col>
<name>object-selection</name>
<halign>left</halign>
<stretch>true</stretch>
<pref-width>300</pref-width>
<property>/ai/control/object-selected</property>
<properties>/ai/control/objects-nearby/</properties>
<value>Truman</value>
<binding>
<command>dialog-apply</command>
<object-name>object-selection</object-name>
</binding>
</combo>
</group>
<empty>
<pref-height>12</pref-height>
</empty>
<hrule/>
<empty>
<pref-height>20</pref-height>
</empty>
<group>
<layout>table</layout>
<button>
<row>0</row>
<col>0</col>
<legend>OK</legend>
<default>true</default>
<equal>true</equal>
<binding>
<command>dialog-apply</command>
</binding>
<binding>
<command>nasal</command>
<script>
var obj_dlg_id = getprop("/ai/control/object-selected");
var dlg = gui.Dialog.new(obj_dlg_id);
dlg.open();
</script>
</binding>
<binding>
<command>dialog-close</command>
</binding>
</button>
<button>
<row>0</row>
<col>1</col>
<legend>Close</legend>
<default>true</default>
<key>Esc</key>
<binding>
<command>dialog-close</command>
</binding>
</button>
</group>
</PropertyList>

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<PropertyList>
<name>TrumanControls</name>
<name>Truman</name>
<modal>false</modal>
<layout>vbox</layout>

View file

@ -492,6 +492,51 @@
</binding>
</item>
<item>
<label>AI Objects</label>
<name>ai-objects</name>
<binding>
<command>nasal</command>
<script>
<![CDATA[
var carriers = props.globals.getNode("/ai/models").getChildren("carrier");
var i = 0;
foreach(c; carriers)
{
var name = c.getNode("dlg-name",1).getValue();
if (name != nil) # check whether a dialog is defined at all
{
var aircraft_pos = geo.aircraft_position();
var carrier_lat = c.getNode("position").getNode("latitude-deg").getValue();
var carrier_lon = c.getNode("position").getNode("longitude-deg").getValue();
var carrier_pos = geo.Coord.new();
carrier_pos.set_latlon(carrier_lat, carrier_lon);
var distance = aircraft_pos.distance_to(carrier_pos);
if (distance < 50000.0) # only add nearby objects
{
setprop("/ai/control/objects-nearby/value["~i~"]", name);
if (i==0)
{setprop("/ai/control/object-selected", name);}
i=i+1;
}
}
}
]]>
</script>
</binding>
<binding>
<command>dialog-show</command>
<dialog-name>ai-objects</dialog-name>
</binding>
</item>
</menu>
<menu>