• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX Modeldef code for map zoom button

Messages
3
Hi,

I need help setting code for a map zoom button. The current gauge code works, but I want the vc button I have for the map range to be coded in the modeldef instead.

Here is the gauge code:

Code:
<Macro id="ZOOMINButton" Name="ZOOMINButton">
  <MacroValue>(L:Range,enum)  --  0 max  (&gt;L:Range,enum)
       (L:map_ZoomStep, number) -- 1 max (&gt;L:map_ZoomStep, number)
       @CalculateZoomFactor((L:map_ZoomStep, number)) (&gt;L:map_ZoomFactor, number)</MacroValue>
  </Macro>
  <Macro id="ZOOMOUTButton" Name="ZOOMOUTButton">
  <MacroValue>(L:Range,enum)  ++  4 min  (&gt;L:Range,enum)
       (L:map_ZoomStep, number) ++ 5 min (&gt;L:map_ZoomStep, number)
       @CalculateZoomFactor((L:map_ZoomStep, number)) (&gt;L:map_ZoomFactor, number)
<MouseArea id="INCR">
  <Visibility>1</Visibility>
  <FloatPosition>20.000,34.000</FloatPosition>
  <Size>15,30</Size>
  <CursorType>UpArrow</CursorType>
  <MouseClick id="MouseClick">
  <Script>(L:var_INC_BUT, bool) ! (&gt;L:var_INC_BUT, bool)
  (L:SEL,enum)  ++ 10 min  (&gt;L:SEL,enum)
  </Script>
  <ClickRepeat>True</ClickRepeat>
  </MouseClick>
  <Tooltip id="Tooltip">
  <DefaultScript></DefaultScript>
  </Tooltip>
  </MouseArea>
  
  <MouseArea id="DEC">
  <Visibility>1</Visibility>
  <FloatPosition>3.000,68.000</FloatPosition>
  <Size>15,30</Size>
  <CursorType>DownArrow</CursorType>
  <MouseClick id="MouseClick">
  <Script>(L:var_DEC_BUT, bool) ! (&gt;L:var_DEC_BUT, bool)
  (L:SEL,enum)  -- 0 max  (&gt;L:SEL,enum)
  </Script>
  <ClickRepeat>True</ClickRepeat>
  </MouseClick>
  <Tooltip id="Tooltip">
  <DefaultScript></DefaultScript>
  </Tooltip>
  </MouseArea>

Thanks in advance!
 
Code:
<Animation name="a2002_GPSZoomIBt" guid="5EDF7E01-6243-4E89-A58F-E57BB21F03CB" type="Sim" typeParam2="a2002_GPSZoomIBt" length="10" typeParam="AutoPlay" /><PartInfo>   
        <Name>a2002_GPSZoomIBt</Name>
        <AnimLength>10</AnimLength>
        <Animation>
            <Parameter>
                 <Code>
                       (L:A2002_GPSZoomIBt,bool) 10 *
                </Code>
        <Lag>50</Lag>
            </Parameter>
        </Animation>
        <MouseRect>
            <Cursor>Hand</Cursor>
            <TooltipID>TOOLTIPTEXT_GPS_IN_BUTTON</TooltipID>
            <MouseFlags>LeftSingle</MouseFlags>
            <CallbackCode>
                (L:A2002_GPSZoomIBt,bool) ! (&gt;L:A2002_GPSZoomIBt,bool)
               1 (&gt;L:296_VC_input,number)
            </CallbackCode>
        </MouseRect>  
</PartInfo>

This code will animate a zoom in button in the VC. (L:A2002_GPSZoomIBt,bool) is the animation of the button going in and out. Animate the button and set keyframes so that 0 = fully out, 5 = fully in and 10 = fully out.

1 (&gt;L:296_VC_input,number) Sets a variable that is read by the GPS gauge. Use different values for different keys, eg Zoom Out could be 2 (&gt;L:296_VC_input,number). The GPS gauge checks this variable and when it is greater than 0 it will process the code, evaluating what it should do (based on the value, 1 = Zoom in , 2 = zoom out) and then doing what needs to be done. Once processed the GPS code will reset 296_VC_input to 0.

If your heart is set on having the code embedded into the model then replace 1 (&gt;L:296_VC_input,number) with whatever code you like.

This code will not do click repeat though. It will only handle single clicks. If you want click repeat let me know and I can show you how to do that.
 
Here is an alternate method making use of "Custom EventIDs":
Code:
  <PartInfo>
    <Name>B737_TCAS_ZoomOut</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:B737_TCAS_ZoomOut,number) 50 *
        </Code>
        <Lag>250</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle</MouseFlags>
      <EventID>0x00011003</EventID>
    </MouseRect>
  </PartInfo>
 
  <PartInfo>
    <Name>B737_TCAS_ZoomIn</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:B737_TCAS_ZoomIn,number) 50 *
        </Code>
        <Lag>250</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <MouseFlags>LeftSingle</MouseFlags>
      <EventID>0x00011002</EventID>
    </MouseRect>
  </PartInfo>
The above script will send Custom EventID numbers to the panel system. In your GPS gauge script, you need only add this to capture the Custom EventID numbers and perform the action(s) defined:
Code:
  <Keys>
    <On Event="0x00011002">@TCAS_ZoomIn</On>
    <On Event="0x00011003">@TCAS_ZoomOut</On>
  </Keys>
To complete the example the following is all of the relevant script to make this work. Note the extensive use of @Macros in order to keep the script as clean as possible. I've also removed the script for the other sixteen 'buttons' on my TCAS/WxRadar to focus on these two specific buttons you asked about. Obviously their script uses pretty much the same technique though. I added a short 'timer' which provides a short delay before resetting the model's button animation variable. :teacher:
Code:
<Macro Name="ResetButtons">(L:TimeCount,enum) ++ (>L:TimeCount,enum) (L:TimeCount,enum) 4 &gt;</Macro>
 
<Update Hidden="Yes">
  <!-- calculate zoom factor range -->
  (@g:map_ZoomStep0) 0 == if{ 13 (>@g:map_ZoomStep0) }
  (@g:map_ZoomStep1) 0 == if{ 15 (>@g:map_ZoomStep1) }
  (@g:currentPageNAV) @kNAVPageDflt == if{ (@g:map_ZoomStep0) } els{ (@g:map_ZoomStep1) } (>@g:map_ZoomStep)
  @CalculateZoomFactor((@g:map_ZoomStep)) (>@g:map_ZoomFactor)
  (@g:smallmap_ZoomStep) 0 == if{ 10 (>@g:smallmap_ZoomStep) } @CalculateZoomFactor((@g:smallmap_ZoomStep)) (>@g:smallmap_ZoomFactor)
  <!-- make sure current element exist -->
 
  (L:B737_TCAS_ZoomOut,number) if{ @ResetButtons if{ 0 (>L:B737_TCAS_ZoomOut,number) 0 (>L:TimeCount,enum) } }
  (L:B737_TCAS_ZoomIn,number)  if{ @ResetButtons if{ 0 (>L:B737_TCAS_ZoomIn,number) 0 (>L:TimeCount,enum) } }
</Update>
 
 
<Macro Name="TCAS_ZoomIn">
  (@g:map_ZoomStep0) -- 1 max (>@g:map_ZoomStep0)
  1 (>L:XMLSND5,bool)
  1 (>L:B737_TCAS_ZoomIn,number)
</Macro>
<Macro Name="TCAS_ZoomOut">
  (@g:map_ZoomStep0) ++ 20 min (>@g:map_ZoomStep0)
  1 (>L:XMLSND5,bool)
  1 (>L:B737_TCAS_ZoomOut,number)
</Macro>
 
<Keys>
  <On Event="0x00011002">@TCAS_ZoomIn</On>
  <On Event="0x00011003">@TCAS_ZoomOut</On>
</Keys>
 
Got the modeldef code in place but having problems transferring the code you guys provided to the map gauge.

Here is the map code I started with:

Code:
<Update id="Update">
            <Frequency>9</Frequency>
            <Script>(L:map_ZoomStep, number) 0 == if{
    1 (&gt;L:map_ZoomStep, number)
    @CalculateZoomFactor((L:map_ZoomStep, number)) (&gt;L:map_ZoomFactor, number)
}
(L:MapInit) 0 == if{
    0 (&gt;L:LayerAirports)  
    0 (&gt;L:LayerTerrain)
    0 (&gt;L:LayerVORs)
    0 (&gt;L:LayerILSs)
    0 (&gt;L:LayerNDBs)      
        0 (&gt;L:LayerFlightPlan)      
    0 (&gt;L:LayerTags)
    0 (&gt;L:LayerCompass)  
        0 (&gt;L:LayerVehicles)
    7 (&gt;L:VehicleObjectDetail)
        0 (&gt;L:Filter)      
    1 (&gt;L:MapInit)
}</Script>
        </Update>

And here is the current code for the controls gauge that I transferred over from the default radar.xml, that I am trying to port over to the modeldef. (Similar layout as the code above) You'll notice that I have specific zoom levels. This corresponds with range and the markers I have in place in the gauge to gauge distance:

Code:
<Macro id="ZOOMINButton" Name="ZOOMINButton">
  <MacroValue>(L:Range,enum)  --  0 max  (&gt;L:Range,enum)
       (L:map_ZoomStep, number) -- 1 max (&gt;L:map_ZoomStep, number)
       @CalculateZoomFactor((L:map_ZoomStep, number)) (&gt;L:map_ZoomFactor, number)</MacroValue>
  </Macro>
  <Macro id="ZOOMOUTButton" Name="ZOOMOUTButton">
  <MacroValue>(L:Range,enum)  ++  4 min  (&gt;L:Range,enum)
       (L:map_ZoomStep, number) ++ 5 min (&gt;L:map_ZoomStep, number)
       @CalculateZoomFactor((L:map_ZoomStep, number)) (&gt;L:map_ZoomFactor, number)
</MacroValue>
  </Macro>
  <Macro id="g" Name="g">
  <MacroValue>C:fs9gps</MacroValue>
  </Macro>
  <Macro id="CalculateZoomFactor" Name="CalculateZoomFactor">
  <MacroValue>56.000020 28.000010 14.000000 7.000002 3.498848 0 6 @1 case</MacroValue>
  </Macro>

So now I need help tying what I put into the modeldef into working with the map code.

Code:
<PartInfo>
    <Name>radar_range_inc</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:Radar_ZoomOut,number) 50 *
        </Code>
        <Lag>250</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Radar Range Increase</TooltipText>
      <MouseFlags>LeftSingle</MouseFlags>
      <EventID>0x00011003</EventID>
    </MouseRect>
  </PartInfo>

  <PartInfo>
    <Name>radar_range_dec</Name>
    <AnimLength>50</AnimLength>
    <Animation>
      <Parameter>
        <Code>
          (L:Radar_ZoomIn,number) 50 *
        </Code>
        <Lag>250</Lag>
      </Parameter>
    </Animation>
    <MouseRect>
      <Cursor>Hand</Cursor>
      <TooltipText>Radar Range Decrease</TooltipText>
      <MouseFlags>LeftSingle</MouseFlags>
      <EventID>0x00011002</EventID>
    </MouseRect>
  </PartInfo>

You guys have provided excellent examples, but I still need a bit more help translating what you've posted to what should go into my map code in order for this thing to work.


Thanks again and I really do appreciate the help!!!
 
I think you still might need to add the <Keys> section. This links the <EventID> with the macro.

Here is an example of some code from a GPS I have done. This goes at the end of the gauge and captures keyboard input events. Notice how one of them is GPS_ZOOMIN_BUTTON.

One other option you could have used in your modeldef was instead of creating a user eventid you could have triggered a standard (>;K:GPS_ZOOMIN_BUTTON) event. The Keys section in your GPS would then capture this and process the macro @ZOOMINButton.

It may be worthwhile adding a section like this one as it will allow anyone who has mapped these standard commands to their keyboard to be able to control your GPS without needing mouse input.

I have a demo aircraft which includes a 296 GPS which is where I took this code from. You can download this demo for free from here: http://www.antsairplanes.com/eaglet.html . You may like to refer to the XML code for the GPS for any further hints.

Code:
<Keys>
    <On Event="GPS_NEAREST_BUTTON">@NRSTButton</On>
    <On Event="GPS_ZOOMIN_BUTTON">@ZOOMINButton</On>
    <On Event="GPS_ZOOMOUT_BUTTON">@ZOOMOUTButton</On>
    <On Event="GPS_DIRECTTO_BUTTON">@GOTOButton</On>
    <On Event="GPS_MENU_BUTTON">@MENUButton</On>
    <On Event="GPS_POWER_BUTTON">@POWERButton</On>
    <On Event="GPS_CLEAR_BUTTON">@CLRButton</On>
    <On Event="GPS_ENTER_BUTTON">@ENTERButton</On>
    <On Event="GPS_GROUP_KNOB_INC">@Upcursor</On>
    <On Event="GPS_GROUP_KNOB_DEC">@Downcursor</On>
    <On Event="GPS_PAGE_KNOB_DEC">@Leftcursor</On>
    <On Event="GPS_PAGE_KNOB_INC">@Rightcursor</On>
    <On Event="GPS_TERRAIN_BUTTON">@PAGEButton</On>
</Keys>

Refer also to Bills keys example on how to map the user events to macros.

Code:
<Keys>
  <On Event="0x00011002">@TCAS_ZoomIn</On>
  <On Event="0x00011003">@TCAS_ZoomOut</On>
</Keys>
Also note: It looks like the code you are writing is done using the ACE tool. THis has a bit of a different format from what I will call "old XML". I never really bothered with this new style of XML that FSX introduced but write everything in old XML. So you may need to convert the code above into the new XML style you are using.
 
The primary reason I used Custom EventID numbers was because I scripted a custom WxRadar and TCAS "gauge" and needed to not use the default GPS and/or G1000 Events in case anyone decided to add a G500 or other custom GPS to their aircraft's panel, yet still had to use something that would work in Shared Cockpit seamlessly. :)

As it happens that was serendipitous because that is what immediately brought up the fact that the P3Dv2.1 'hot fix' broke the Custom EventID feature altogether! Since I notified Wes Bard at L-M and provided the required information, they have now fixed that broken feature in the v2.2 'hot fix...'

I also have avoided the new "FSX XML schema" like the boated plague it is... :rotfl:
 
Back
Top