Jump to content

Archived

This topic is now archived and is closed to further replies.

Jonathan Lueb

Changing Needle BMPs depending on a particular value in XML gauge

Recommended Posts

Is it possible to change a needle BMP based on the value of a variable in a XML gauge?

For example lower values needle is green.

warning level needle is yellow

danger level needle is red.

I also want to change the background color of the digital display based on the same values.

I have tried using the case function and using the visible function but I'm obviously doing something wrong because the gauge disappears in the panel when I go to test the gauge.

Anybody have suggestions on how to make this happen?

 

Jonathan

Share this post


Link to post
Share on other sites

Use the visibility function:

 

<Element>
<Visible>(A:Autopilot Heading Lock,bool)</Visible>
     <Position X="439" Y="0"/>
            <Image Name="AP_HDGON.bmp" />
</Element>

<Element>
<Visible>(A:Autopilot Nav1 Lock,bool)</Visible>
     <Position X="621" Y="0"/>
            <Image Name="AP_NAVON.bmp" />
</Element>


<Element>
<Visible>(A:Autopilot Approach Hold,bool)</Visible>
     <Position X="729" Y="0"/>
            <Image Name="AP_APRON.bmp" />
</Element>

 

You have three elements and only one shows up at a time.

 

If you make any syntax/grammar error in XML, the whole gauge disappears..

which can make it tough to troubleshoot.

 

I usually find a section of code in an existing gauge and carefully modify it, testing at every change.

Share this post


Link to post
Share on other sites

Needles aren't static elements, so not certain they can be turned on/off.

Share this post


Link to post
Share on other sites

Needles aren't static elements, so not certain they can be turned on/off.

 

Try it!  Sample:

<Element id="VOR 1 CYAN">
					<FloatPosition>255.000,249.000</FloatPosition>
					<Visibility>(L:BRG1 Button, number) 1 ==</Visibility>
					<Image Name="mfd_centred_vor_1_bearing_pointer1.bmp">
						<Transparent>True</Transparent>
						<Axis>10.000,152.000</Axis>
						<Bright>True</Bright>
					</Image>
					<Rotation id="Rotation">
						<PointsTo>NORTH</PointsTo>
						<Expression id="Expression">
							<Script>(A:NAV HAS NAV:1, bool) if{
								(A:NAV1 radial, radians) (A:Plane heading degrees gyro, radians) - pi  + } els{ pi 2 / }
							</Script>
						</Expression>
						<Delay id="Delay">
							<DelayValue>180.000</DelayValue>
							<DelayUnits>DEGREES_PER_SECOND</DelayUnits>
						</Delay>
					</Rotation>
				</Element>

Another option entirely is to draw the needle and vary the color..

Share this post


Link to post
Share on other sites

Thanks guys for the input!

Here is what I've been working on and I thought I'd pursue it as it initially seemed to be heading the right way but on this first example only the first BMP appears and then the needles disappear completely.

 

First Example:

     <Element>
      <Position X="125" Y="125"/>
      <Select>
         <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 35 >=</Value>
          <Case Value="0">
             <Image Name="ENG_Needle_Gray.bmp" PointsTo="East" Bright="Yes">
                <Axis X="5" Y="5"/>
             </Image>
          </Case>
          <Case Value="1">
            <Select>
               <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 65 >=</Value>
                  <Case Value="0">
                     <Image Name="ENG_Needle_Green.bmp" PointsTo="East" Bright="Yes">
                        <Axis X="5" Y="5"/>
                     </Image>
                  </Case>
                  <Case Value="1">
                    <Select>
                       <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 95 >=</Value>
                          <Case Value="0">
                             <Image Name="ENG_Needle_Yellow.bmp" PointsTo="East" Bright="Yes">
                                <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                          <Case Value="1">
                             <Image Name="ENG_Needle_Red.bmp" PointsTo="East" Bright="Yes">
                               <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                   </Select>
                  </Case>
            </Select>
          </Case>
      </Select>
      <Rotate>
         <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
         <Failures>
            <SYSTEM_ENGINE Action="0"/>
            <SYSTEM_ELECTRICAL_PANELS Action="0"/>
         </Failures>
         <Nonlinearity>
             <Item Value="0" X="219" Y="125"/>
             <Item Value="100" X="30" Y="125"/>
         </Nonlinearity>
        <Delay DegreesPerSecond="20"/>
      </Rotate>
      </Element>

 

The original piece looked like the following and it worked. As the RPM increased the needle changed colors. But when I wanted to increase the number of colors I thought I could nest them per the first example but that didn't work. Am I overlooking something?

 

Second Example:

                   <Select>
                       <Value>(A:PROP1 MAX RPM PERCENT, percent) abs 95 >=</Value>
                          <Case Value="0">
                             <Image Name="ENG_Needle_Gray.bmp" PointsTo="East" Bright="Yes">
                                <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                          <Case Value="1">
                             <Image Name="ENG_Needle_Green.bmp" PointsTo="East" Bright="Yes">
                               <Axis X="5" Y="5"/>
                             </Image>
                          </Case>
                   </Select>


 

Share this post


Link to post
Share on other sites

Try the visibility option and do not nest them.. sometimes you just have to duplicate the section, with a different visibility condition..

 

Keep it simple

Share this post


Link to post
Share on other sites

I tried this and the only one that is visible is the red.

         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 0 >=</Visability>
                  <Image Name="ENG_Needle_Gray.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>
         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 35 >=</Visability>
                  <Image Name="ENG_Needle_Green.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>
         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 65 >=</Visability>
                  <Image Name="ENG_Needle_Yellow.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>
         <Element>
            <Position X="125" Y="125"/>
               <Visability>(A:PROP1 MAX RPM PERCENT, percent) abs 95 >=</Visability>
                  <Image Name="ENG_Needle_Red.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>

Share this post


Link to post
Share on other sites

Bert, thanks a lot! I got it working. Made a mistake in the above code. Here is the final code, Just multiply it however many colors and change the greater than value for the different colors. Voila! It works! Thanks again!

         <Element>
            <Position X="125" Y="125"/>
               <Visible>(A:PROP1 MAX RPM PERCENT, percent) abs 120 >=</Visible>
                  <Image Name="ENG_Needle_Red.bmp" PointsTo="East" Bright="Yes">
                     <Axis X="5" Y="5"/>
                  </Image>
                  <Rotate>
                     <Value Minimum="0" Maximum="120">(A:PROP1 MAX RPM PERCENT, percent) abs</Value>
                        <Failures>
                           <SYSTEM_ENGINE Action="0"/>
                           <SYSTEM_ELECTRICAL_PANELS Action="0"/>
                        </Failures>
                        <Nonlinearity>
                           <Item Value="0" X="219" Y="125"/>
                           <Item Value="100" X="30" Y="125"/>
                        </Nonlinearity>
                        <Delay DegreesPerSecond="20"/>
                 </Rotate>
         </Element>

Share this post


Link to post
Share on other sites

:rolleyes:

 

If you only change the greater than condition, you may may be displaying several needles on top of each other..  better to define ranges

 

example:   ...120 >=   150 <  and..

Share this post


Link to post
Share on other sites

:rolleyes:

 

If you only change the greater than condition, you may may be displaying several needles on top of each other..  better to define ranges

 

example:   ...120 >=   150 <  and..

Better still, use the "range" function!

 

<Visible>120 150 (A:PROP1 MAX RPM PERCENT, percent) rng</Visible>

Please guys, when posting XML script or C code, use the <> icon in the editor to wrap it into a Code Box. It makes it ever so much easier to read as well as copy/paste. B)

Share this post


Link to post
Share on other sites

BTW, there is a problem in FSX with separate multiple Element sections, each with their own Visible lines.  In some cases the later changes will not display.  In those cases a solution is to use nested Elements, with the Visible line only in the "master" Element.

Share this post


Link to post
Share on other sites

×
×
  • Create New...