<?xml version="1.0" encoding="utf-8" ?>
<sector name="ExitMenu">

  <tExitMenu prototype="ScreenEntity">
    <!-- Set index of arrow location -->
    <iArrowIndex> 0 </iArrowIndex>

    <!-- Set defaults for font type -->
    <iFontSize> 20 </iFontSize>
    <sFont> Courier New </sFont>
    <vFontColor> {0, 0, 1} </vFontColor>
    
    <sText index="0"> Resume </sText>
    <sText index="1"> Quit to Main Menu </sText>
    <sText index="2"> Quit to Desktop </sText>
    <vPosition> {150, 200, 0, 0} </vPosition>
    
    <sArrow> ---> </sArrow>
    <vArrowPos1> {90,200,0,0} </vArrowPos1>
    <vArrowPos2> {90,220,0,0} </vArrowPos2>
    <vArrowPos3> {90,240,0,0} </vArrowPos3>
    
    <Render>
      <!-- Render menu text -->
      <tText prototype = "ActionRenderText">
        <rText> sText </rText>
        <rPosition> vPosition </rPosition>
        <rColor> vFontColor </rColor>
        <rFont> sFont </rFont>
        <rSize> iFontSize </rSize>
      </tText>
      
      <!-- Render arrow based on iArrowIndex -->
      <iCondition0> 0 </iCondition0>
      <iCondition1> 0 </iCondition1>
      <vCurrentArrowPos> {0, 0, 0} </vCurrentArrowPos>
      
      <!-- Set arrow position -->
      <expr> iCondition0 = ( iArrowIndex == 0 ) </expr>
      <if>
        <rCondition> iCondition0 </rCondition>
        <then>
          <expr> vCurrentArrowPos = vArrowPos1 </expr>
        </then>
        <else>
          <expr> iCondition1 = ( iArrowIndex == 1 ) </expr>
          <if>
            <rCondition> iCondition1 </rCondition>
            <then>
              <expr> vCurrentArrowPos = vArrowPos2 </expr>
            </then>
            <else>
              <expr> vCurrentArrowPos = vArrowPos3 </expr>
            </else>
          </if>
        </else>
      </if>
      
      <!-- Render arrow -->
      <tArrowText prototype="ActionRenderText">
        <rText> sArrow </rText>
        <rPosition> vCurrentArrowPos </rPosition>
        <rColor> vFontColor </rColor>
        <rFont> sFont </rFont>
        <rSize> iFontSize </rSize>
      </tArrowText>
    </Render>
    
    <!-- Input Reactions -->
    
    <!-- Up reaction -->
    <tUpReaction prototype="ReactionInput">
	  <iSoughtInputs>btup</iSoughtInputs>
	  
	  <!-- Increment value, check if index needs to loop -->
	  <iCondition> 0 </iCondition>
	  <expr> iCondition = ( iArrowIndex == 0 ) </expr>
	  <if>
	    <rCondition> iCondition </rCondition>
	    <then>
	      <expr> iArrowIndex = 2 </expr>
	    </then>
	    <else>
	      <expr> iArrowIndex = ( iArrowIndex - 1 ) </expr>
	    </else>
	  </if>
	</tUpReaction>
	
	<!-- Down reaction -->
	<tDownReaction prototype="ReactionInput">
	  <iSoughtInputs>btdn</iSoughtInputs>
	
      <iCondition> 0 </iCondition>
      <expr> iCondition = ( iArrowIndex == 2 ) </expr>
      <if>
        <rCondition> iCondition </rCondition>
        <then>
          <expr> iArrowIndex = 0 </expr>
        </then>
        <else>
          <expr> iArrowIndex = ( iArrowIndex + 1 )  </expr>
        </else>
      </if>
    </tDownReaction>
    
    <!-- Enter reaction -->
    <tEnterReaction prototype="ReactionInput">
        <iSoughtInputs> entr </iSoughtInputs>
          
        <iCondition> 0 </iCondition>
        <iCondition1> 0 </iCondition1>

        <expr> iCondition = ( iArrowIndex == 0 ) </expr>
        <if>
            <rCondition> iCondition </rCondition>
            <then>
            <tUnloadExitMenu prototype="ActionUnloadSector">
                <sSectorName> ExitMenu </sSectorName>
            </tUnloadExitMenu>
            </then>
            <else>
                <expr> iCondition1 = ( iArrowIndex == 1 ) </expr>
                <if>
                    <rCondition> iCondition1 </rCondition>
                    <then>
                        <tStopVehicleSound prototype="ActionStopSound">
                            <sFilename> vehicle.wav </sFilename>
                        </tStopVehicleSound>
                          
                        <tStopDrumLoop prototype="ActionStopSound">
                            <sFilename> drums.wav </sFilename>
                        </tStopDrumLoop>
                          
                        <tPlayWinSound prototype="ActionPlaySound">
                            <sFilename> win.wav </sFilename>
                        </tPlayWinSound>
                        
                        <tActionUnloadKeyBoard prototype="ActionUnloadSector">
                            <sSectorName>GeneralInput</sSectorName>
                        </tActionUnloadKeyBoard>
                          
                        <tUnloadExitMenu prototype="ActionUnloadSector">
                            <sSectorName> ExitMenu </sSectorName>
                        </tUnloadExitMenu>
                          
                        <tLoadGameOver prototype="ActionLoad">
                            <sFilename> GameOver.xml </sFilename>
                            <iSynch>1</iSynch>
                        </tLoadGameOver>
                          
                        <tThrowEndGame prototype="ActionEvent">
                            <iSubtype>over</iSubtype>
                            <fDelay>5.0</fDelay>
                        </tThrowEndGame>

                        <tSendOverMsg prototype="ActionList">
                            <sMsg1>0</sMsg1>
                            <iMsgLength>-1</iMsgLength>
                            <iSeqNum>0</iSeqNum>
                            <fTimePrevRcvd>0</fTimePrevRcvd>
                            <fLocalTimePrevRcvd>0</fLocalTimePrevRcvd>
                            <!-- Read the data type backwards: "over" -->
                            <expr>sMsg1 = "DATA;revo;"</expr>
                            <expr>iMsgLength = - 1</expr>
                            <tNetSend prototype="ActionNetworkSend">
                                <rTimePrevRcvd>fTimePrevRcvd</rTimePrevRcvd>
                                <rLocalTimePrevRcvd>fLocalTimePrevRcvd</rLocalTimePrevRcvd>
                                <rSeqNum>iSeqNum</rSeqNum>
                                <rMsgData>sMsg1</rMsgData>
                                <rMsgLengths>iMsgLength</rMsgLengths>
                                <rSocket>iSocket</rSocket>
                                <rPeerPortNum>iPeerPort</rPeerPortNum>
                                <rPeerIPAddr>iChosenIPAddress</rPeerIPAddr>
                            </tNetSend>
                        </tSendOverMsg>
                    </then>
                <else>
                    <tSendOverMsg prototype="ActionList">
                        <sMsg1>0</sMsg1>
                        <iMsgLength>-1</iMsgLength>
                        <iSeqNum>0</iSeqNum>
                        <fTimePrevRcvd>0</fTimePrevRcvd>
                        <fLocalTimePrevRcvd>0</fLocalTimePrevRcvd>
                        <!-- Read the data type backwards: "frst" -->
                        <expr>sMsg1 = "DATA;revo;"</expr>
                        <expr>iMsgLength = - 1</expr>
                        <tNetSend prototype="ActionNetworkSend">
                        <rTimePrevRcvd>fTimePrevRcvd</rTimePrevRcvd>
                        <rLocalTimePrevRcvd>fLocalTimePrevRcvd</rLocalTimePrevRcvd>
                        <rSeqNum>iSeqNum</rSeqNum>
                        <rMsgData>sMsg1</rMsgData>
                        <rMsgLengths>iMsgLength</rMsgLengths>
                        <rSocket>iSocket</rSocket>
                        <rPeerPortNum>iPeerPort</rPeerPortNum>
                        <rPeerIPAddr>iChosenIPAddress</rPeerIPAddr>
                        </tNetSend>
                    </tSendOverMsg>
                    <tQuit prototype="ActionQuit" />
                </else>
                </if>
            </else>
        </if>
    </tEnterReaction>
    
  </tExitMenu>
  
</sector>
