1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

UE2 - UT2kX Hud Help [Ammo Meters]

Discussion in 'Programming' started by forrestmark9, Apr 5, 2014.

  1. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    I need help with getting a certain type of ammo meter to work correctly.

    What I want to do is use a for loop and draw only a single icon from the bitmap below and based on how much ammo I have it draw more to the right but when it gets to a certain point, move down and continue the row, and when the ammo is used change the color of the very last icon to a disabled color and move up as you use ammo.

    Sadly due to my extreme limited knowledge of hud stuff I can't really figure out how to exactly do this

    Here is the bitmap that is used by all of them
    [SCREENSHOT]https://dl.dropboxusercontent.com/u/52828637/hud_ammo_alphas.bmp[/SCREENSHOT]
     
  2. meowcat

    meowcat take a chance

    Joined:
    Jun 7, 2001
    Messages:
    803
    Likes Received:
    3
    The "slantiness" is the only possible problem with that hud texture.

    There are several functions in the canvas.uc class that allow you to draw only a boxed shape portion of a texture (by passing in the starting point coordinate in the texture and how many pixels to the right and down, or left and up if I recall correctly by using negative pixel values). See the DrawTile and SetPos function specifically.

    The only way I can think of dealing with the slanted texture is to optionally place a mask texture that is shifted into the base texture (using a Shader combined with a TexScaler and the UOffset
     
    Last edited: Apr 5, 2014
  3. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    Hmm I see, I know how to do most of it by using DrawTile and stuff but I do not know how to make it only place it along the X until it gets to a certain point then changes the Y. I also do know how to do what you mentioned about the shader
     
  4. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
    Pro tip: Don't post BMPs or TGAs on the internet, use PNG instead. The PNG format can be saved with or without alpha channel, allowing it to losslessly store anything you'd also store in a BMP or TGA file - except that PNG usually is much smaller. (Your 1MB BMP's content could be squeezed into a 20kB PNG file.)

    But to elaborate on meowcat's masking idea: The type of mask obviously depends on the draw style you use. If you draw the texture using STY_Alpha (Style = 5), you will need to modify the alpha channel. If, however, you draw it using STY_Translucent (Style = 3), you will actually have to use a Combiner to multiply the texture with a white mask shifted to the appropriate position using the same TexScaler method.
    I've attached an example modification of your HUD texture to show this kind of mask shape. The first mask can be used for the small bullet icons. The black space below it also belongs to this mask, so you can move it upwards to mask out the entire lower line(s). Use an inverted version of this mask to draw the other bullets in a different color. Alternatively, if you only want to dim used-up bullets, you can brighten up the black part to some gray value.
    The second mask should work for all three of the other small bullet types and possibly also for the bomb-shaped icons, though obviously they all need different start offsets.
    The third mask is supposed to be used for the large bullets.
     

    Attached Files:

  5. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    Sorry about that, I wanted to see if BMP would actually show the alphas but it didn't but I was too lazy to change it to a PNG.

    I see, I'll experiment with this as I'm still stumped on how to do this but I'll practice and see how exactly it's done as currently I only know how to mix together a TexEnv with a texture using a combiner. I'm more of a code guy and I never really did much involving many assets, I'd most likely need an example in the editor or code if needed and sorry if I seem rather stupid in this situation

    Edit: Original I planned to use these textures and just draw them to the right then down
    [​IMG]
    [​IMG]
    [​IMG]
     
    Last edited by a moderator: Apr 6, 2014
  6. VendorX

    VendorX Member

    Joined:
    Aug 2, 2010
    Messages:
    224
    Likes Received:
    5
    Use SpriteWidget ... You don't need separate textures to each type of ammo - texture from your first post is all you need, only add alpha channel to it if you don't have one.
     
    Last edited: Apr 7, 2014
  7. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    I had planned to do something like that as it came with another texture that had alpha going from black to white up the meters but sadly due to the way they are the first 2 bullets will always be invisible even at AlphaRef 0, as I increase it the bullets did not disappear one by one instead they disappeared 3 by 3 or more

    Here is that texture:
    https://dl.dropboxusercontent.com/u/52828637/hud_ammo_meters.tif

    Make sure to look at the alpha channel

    How Halo handles the alpha is it uses 2 values, Alpha Bias and Alpha Multiplier
     
    Last edited by a moderator: Apr 7, 2014
  8. VendorX

    VendorX Member

    Joined:
    Aug 2, 2010
    Messages:
    224
    Likes Received:
    5
    To be honest, I have no idea why there is gradient alpha - maybe for colour shifting ...

    You can do this in two ways:
    - use from original texture the same part of image for every row.

    - or delete original alpha channel and make new one. If you have Photoshop go to Image -> Calculations and in Blending select Color Dodge - this should give you nice new alpha channel.

    To change colour use Tints ...
    To progress bar by one more / less bullet use Scale or change the TextureCoords.

    To display ammo rows use if statements, e.g.:
    - first row will be always displayed
    - second only if ammo count is greater than 20
    - third only if ammo count is greater than 40

    Another way (as you mentioned ...) is to draw image of one bullet multiplied by ammo count - choice is yours ...

    As for Halo shaders, it's like with .pcx in UE - you can choose colour to become transparent.
     
    Last edited: Apr 7, 2014
  9. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    Hmm most of those may work but I'm still unsure of how to setup everything and to look if the ammo changes then change color of only that icon
     
  10. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    Edit:

    I see, I had actually found a easier way to do this by doing it how Halo does it kinda

    here is what I have, I can not make it change the alpharef only when the ammo changes as whenever I add anything involving MagCapacity it gets ignored
    Code:
        if ( PawnOwner != none && PawnOwner.Weapon != none )
        {        
            if (HaloPlayer(PlayerOwner).Grenades != none)
                GrenadesDigits.Value = HaloPlayer(PlayerOwner).Grenades.GrenadeAmount;
                
            if( ClassIsChildOf(PawnOwner.Weapon.Class, class'AssualtRifle') )
            {
                AmmoMeterUsed.WidgetTexture = ARBulletsMeter;
                AlphaMultiplier = 4;
                
                DrawSpriteWidget(C, AmmoBG);
                DrawSpriteWidget(C, AmmoOutline);
                DrawSpriteWidget(C, AmmoIcon);
                DrawSpriteWidget(C, AmmoMeter);
                DrawSpriteWidget(C, AmmoMeterUsed);
                
                ARBulletsMeter.AlphaRef = (ARBulletsMeter.AlphaRef - AlphaMultiplier);
            }
            DrawNumericWidget(C, ClipsDigits, DigitsSmall);
        }
    For some super odd reason the alpha ref seen in the editor is different then in-game, in the editor the bullets don't start appearing until AlphaRef 240 but in-game they start appearing at 204 which is super inconsistent
     
    Last edited by a moderator: Apr 8, 2014
  11. meowcat

    meowcat take a chance

    Joined:
    Jun 7, 2001
    Messages:
    803
    Likes Received:
    3
    ForrestMarkX; Do you have UT2k4 to run some tests? Here is some sample code that I placed in a test subclass of the Assault Rifle. It uses the version of the texture that Wormbo modified so nicely (which I converted to a .dds file), to correctly shift ammo icons. Note that there is some slight adjustments needed to the pixel offsets as some icon get only partially cutoff, but in general works the way you want (I think).

    Code:
    //===============
    // Assault Rifle
    // Also use as a test bed for the alpha ammo icons
    //===============
    class ddar extends AssaultRifle
        config(user);
    
    /* This texture is 512 x 512 pixels wide
      AR: the bullets are 10 pixels wide by 17 pixels tall
          bullet row icons (3 rows) can be drawn from pixels (0, 0) to (226, 52)
          bullet row mask (3 rows) can be drawn from pixels (0, 170) to (226, 224)
      Shotgun: the shells are 18 pixels wide by 34 pixels tall
            shell row icons (1 row) can be drawn from pixels (0, 53) to (221, 86)
            shell row mask (1 rows) can be drawn from pixels (0, 266) to (224, 303)
    
    */
    #exec TEXTURE IMPORT File=classes\hud_ammo_alphas.dds Name=hud_ammo_alphas Mips=Off MASKED=0 ALPHA=1 LODSET=5 UCLAMPMODE=CLAMP VCLAMPMODE=CLAMP
    
    var shader Ammo_Shad;
    var TexScaler Ammo_Scaler;
    var FinalBlend Ammo_FB;
    var	int ClipCount, OldClipCount; // just a test/convenience variable to show the clip count display changing.
    var int ClipSize;
    
    simulated function PostBeginPlay(){
         super.PostBeginPlay();
    
         ClipCount = ClipSize;
         // Adjust the AmmoScaler.UOffset variable (in pixels) to move it along
         Ammo_Scaler = TexScaler(Level.ObjectPool.AllocateObject(class'TexScaler'));
         Ammo_Scaler.Material = texture'hud_ammo_alphas';
    
         Ammo_Shad = shader(Level.ObjectPool.AllocateObject(class'shader'));
         Ammo_shad.Diffuse = Ammo_Scaler;
         Ammo_shad.Opacity = texture'hud_ammo_alphas';
    
         Ammo_FB = FinalBlend(Level.ObjectPool.AllocateObject(class'FinalBlend'));
         Ammo_FB.Material = Ammo_shad;
         Ammo_FB.FrameBufferBlending = FB_brighten; // or maybe FB_AlphaBlend
    }
    
    simulated function Destroyed(){
         // now free the materials.
         Level.ObjectPool.FreeObject(Ammo_FB);
         Level.ObjectPool.FreeObject(Ammo_shad);
         Level.ObjectPool.FreeObject(Ammo_scaler);
         super.Destroyed();
    }
    
    simulated function IncrementFlashCount(int Mode)
    {
        super.IncrementFlashCount(Mode);
        ClipCount--;
        if(ClipCount < 0) ClipCount = ClipSize; // constantly roll over
    }
    
    simulated event RenderOverlays( Canvas C )
    {
        local int ClipRemainder;
        if (Instigator == None)
            return;
        Super.RenderOverlays(C);
        // now draw the ammo status to the upper left corner of the canvas
        // AR bullet list
        if(true){
           //ClipSize = 60; // this is how many little icons are in the texture
           if(OldClipCount != ClipCount){
               //ClipRemainder = ClipCount % ClipSize;// constantly roll this over and grab the amount less than the clip size
    
               ClipRemainder = ClipCount; // yeah this is redundant, but left it in incase you want to roll-over a byte for this example purposes
               // three rows with three different cases to take into account the skew
               // since each row is slightly offset to the left from the one above
               if(ClipRemainder > 40){
                   // UOffset = Initial pixel skew offset into the row + (AR Bullet Pixel width * (empties in row))
                   Ammo_Scaler.UOffset = 0 + (10 * (20 - (ClipRemainder - 40)));
                   Ammo_Scaler.VOffset = 170;
               }else if (ClipRemainder > 20){
                   Ammo_Scaler.UOffset = 5 + (10 * (20 - (ClipRemainder - 20)));
                   Ammo_Scaler.VOffset = 188;
               }else{
                   Ammo_Scaler.UOffset = 10 + (10 * (20 - ClipRemainder));
                   Ammo_Scaler.VOffset = 206; // so that only the top row gets a color, the bottom two rows will be in black
               }
               OldClipCount = ClipCount;
           }
           C.Style = 5;
       	   C.SetDrawColor (255, 255, 255, 255); // tweak this for a different color
       	   C.SetPos(C.SizeX * 0.03, C.SizeY * 0.15); // start a little ways away from the upper left corner
           // now draw AR bullet 'chunk' out of the Final blend
           C.DrawTile(Ammo_FB, C.SizeX * 0.2, C.SizeY * 0.055, 0.0, 0.0, 226, 52);
        }
    }
    
    
    defaultproperties
    {
        ClipSize=60 // adjust this based on which bullet icons you are using
        PickupClass=class'ddarPickup'
        AttachmentClass=class'AssaultAttachment'
    }
    
    You will have to tweak the other fixed/hard coded pixel offset values for the other icons and you may need to further adjust the texture, though Wormbo's edited version should be able to be worked for all of those icons.
     
    Last edited: Apr 27, 2014
  12. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0

    Awesome I'll try it out once I get everything working on a FFA Team color system I've been working on
     
  13. forrestmark9

    forrestmark9 New Member

    Joined:
    Aug 6, 2009
    Messages:
    56
    Likes Received:
    0
    Okay so I finally got to test this and it doesn't seem to work but this could be that my package is incredibly broken cause for some reason it wanted to load everything from UT2004 which doesn't exist at compile, but for now my project is on hold until KF2 is released as I believe UE3 would be a much easier engine to work with
     

Share This Page