<?xml version="1.0"?>

<PropertyList>
	<nasal>
		<open><![CDATA[
		
var assignButton = func(cmd) {

  var i = getprop("/sim/gui/dialogs/joystick-config/current-button");
  setprop("/sim/gui/dialogs/joystick-config/button[" ~ i ~ "]/binding", cmd);
  
  joystick.writeConfig();
  fgcommand("reinit", props.Node.new({"subsystem": "input"}));
  fgcommand("dialog-close", props.Node.new({"dialog-name": "button-config"}));
  fgcommand("dialog-close", props.Node.new({"dialog-name": "joystick-config"}));
  fgcommand("dialog-show", props.Node.new({"dialog-name": "joystick-config"}));
}
		]]></open>

		<close><![CDATA[
		]]></close>
	</nasal>


	<name>button-config</name>
	<layout>vbox</layout>
	<resizable>true</resizable>
	<modal>true</modal>
	<default-padding>3</default-padding>

	<group>
		<layout>hbox</layout>
		<default-padding>1</default-padding>

		<empty><stretch>true</stretch></empty>

		<text>
			<label>Button Configuration</label>
		</text>

		<empty><stretch>true</stretch></empty>

		<button>
			<legend></legend>
			<key>Esc</key>
			<pref-width>16</pref-width>
			<pref-height>16</pref-height>
			<border>2</border>
			<binding>
				<command>dialog-close</command>
			</binding>
		</button>
	</group>

	<hrule/>
	
	<text>
	  <halign>left</halign>
	  <label>Select the command you wish to assign to this button.</label>
  </text>
  
  <hrule/>
  
  <group>
    <layout>table</layout>
    
    <text>
      <row>0</row>
      <col>0</col>
      <label>Flight surface trim</label>
    </text>
    
    <button>
      <row>1</row>
      <col>0</col>
      <halign>fill</halign>
      <legend>Elevator Trim Up</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Elevator Trim Up");
        </script>
      </binding>
    </button>
    
    <button>
      <row>2</row>
      <col>0</col>
      <halign>fill</halign>
      <legend>Elevator Trim Down</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Elevator Trim Down");
        </script>
      </binding>
    </button>

    <button>
      <row>3</row>
      <col>0</col>
      <halign>fill</halign>
      <legend>Rudder Trim Left</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Rudder Trim Left");
        </script>
      </binding>
    </button>
    
    <button>
      <row>4</row>
      <col>0</col>
      <halign>fill</halign>
      <legend>Rudder Trim Right</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Rudder Trim Right");
        </script>
      </binding>
    </button>

    <button>
      <row>5</row>
      <col>0</col>
      <halign>fill</halign>
      <legend>Aileron Trim Left</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Aileron Trim Left");
        </script>
      </binding>
    </button>
    
    <button>
      <row>6</row>
      <col>0</col>
      <halign>fill</halign>
      <legend>Aileron Trim Right</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Aileron Trim Right");
        </script>
      </binding>
    </button>

    <text>
      <row>0</row>
      <col>1</col>
      <label>Control Surfaces</label>
    </text>

    <button>
      <row>1</row>
      <col>1</col>
      <halign>fill</halign>
      <legend>Flaps Up</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Flaps Up");
        </script>
      </binding>
    </button>

    <button>
      <row>2</row>
      <col>1</col>
      <halign>fill</halign>
      <legend>Flaps Down</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Flaps Down");
        </script>
      </binding>
    </button>

    <button>
      <row>3</row>
      <col>1</col>
      <halign>fill</halign>
      <legend>Gear Up</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Gear Up");
        </script>
      </binding>
    </button>

    <button>
      <row>4</row>
      <col>1</col>
      <halign>fill</halign>
      <legend>Gear Down</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Gear Down");
        </script>
      </binding>
    </button>

    <button>
      <row>5</row>
      <col>1</col>
      <halign>fill</halign>
      <legend>Spoilers Retract</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Spoilers Retract");
        </script>
      </binding>
    </button>

    <button>
      <row>6</row>
      <col>1</col>
      <halign>fill</halign>
      <legend>Spoilers Deploy</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Spoilers Deploy");
        </script>
      </binding>
    </button>

    <text>
      <row>0</row>
      <col>2</col>
      <label>Other Aircraft Controls</label>
    </text>
    
    <button>
      <row>1</row>
      <col>2</col>
      <halign>fill</halign>
      <legend>Brakes</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Brakes");
        </script>
      </binding>
    </button>

    <button>
      <row>2</row>
      <col>2</col>
      <halign>fill</halign>
      <legend>FGCom PTT</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("FGCom PTT");
        </script>
      </binding>
    </button>

    <button>
      <row>3</row>
      <col>2</col>
      <halign>fill</halign>
      <legend>Trigger</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Trigger");
        </script>
      </binding>
    </button>
    
    <button>
      <row>4</row>
      <col>2</col>
      <halign>fill</halign>
      <legend>Custom</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("Custom");
        </script>
      </binding>
    </button>

    <button>
      <row>5</row>
      <col>2</col>
      <halign>fill</halign>
      <legend>None</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("None");
        </script>
      </binding>
    </button>
        
    <text>
      <row>0</row>
      <col>3</col>
      <label>View</label>
    </text>
    
    <button>
      <row>1</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Decrease</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Decrease");
        </script>
      </binding>
    </button>
    
    <button>
      <row>2</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Increase</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Increase");
        </script>
      </binding>
    </button>

    <button>
      <row>3</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Cycle Forwards</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Cycle Forwards");
        </script>
      </binding>
    </button>

    <button>
      <row>4</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Cycle Backwards</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Cycle Backwards");
        </script>
      </binding>
    </button>

    <button>
      <row>5</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Left</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Left");
        </script>
      </binding>
    </button>

    <button>
      <row>6</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Right</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Right");
        </script>
      </binding>
    </button>

    <button>
      <row>7</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Up</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Up");
        </script>
      </binding>
    </button>

    <button>
      <row>8</row>
      <col>3</col>
      <halign>fill</halign>
      <legend>View Down</legend>
      <binding>
        <command>nasal</command>
        <script>
          assignButton("View Down");
        </script>
      </binding>
    </button>
    
  </group>
  
  <group>
    <empty>
      <stretch>true</stretch>
    </empty>
    <layout>hbox</layout>

    <button>
      <legend>Close</legend>
      <default>true</default>
      <key>Esc</key>
      <binding>
        <command>dialog-close</command>
      </binding>
    </button>
    <empty>
      <stretch>true</stretch>
    </empty>
  </group>
    
</PropertyList>