Announcement

Collapse
No announcement yet.

Modifying the HUD

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Modifying the HUD

    Hi guys,

    Another newbie question, hopefully this one's a bit more straightforward and will get some suggestions

    I've made a class called GiftigBombcopter extending ONSAttackCraft (i.e. a raptor) which has a modified alt fire, which now drops nuclear warheads (redeemer projectiles modified to just drop, with the smoke removed, etc.). The class has warheads and max_warheads variables to keep track of number of warheads onboard, and will play the MenuSounds.Denied1 sound instead of dropping a bomb when warheads reaches 0.

    This works great. What I would like to do now, however, is to modify the HUD for this vehicle to indicate how many warheads are currently onboard. I've never played around with the HUD before and I'm new to UT editing in general, so any tips are appreciated.

    Thanks in advance.

    #2
    As I’m sure you know, the HUD differs slightly from gametype to gametype. The different HUDs each have their own class, and which class is used for a given gametype is determined by the "HUDType" variable in that gametype’s class. xDeathMatch, for example, uses XInterface.HudCDeathMatch. Since you don’t want to go modifying preexisting code, you’ll want to begin by extending one of the gametype classes (the natural choice here is ONS) and switch that variable to your custom HUD class.

    I myself am trying to dissect the code that displays the weapon bar in DeathMatch, and I’ll be taking a look at other elements of the HUD as well. From what I learn I may be able to give you a lot more information, but I’m eager to see what others may post all the same. I too could always a few pointers from the pros, being a bit of a newbie myself.

    EDIT: Hmm, ya know, I'm not sure if a mutator could change the HUDType. I'm not familiar with the full capabilities of mutators, being that I don't use many myself and I haven't gone digging through the code thoroughly, but it would be much cleaner than subclassing gametypes. It's a question for someone better informed than me.

    Comment


      #3
      You do not want to change the hud type unless its a new gametype altogether. You can use mutators (or even other actors that exist clientside) though to add HUDOverlays to a player's HUD (which can do much of the same thing as a HUD Canvas).

      Actually, vehicles already support the spawning and use of HUDOverlays (take a look through Vehicle.uc). The ONSVehicle class also has a DrawHUD function. You could either modify the drawHUD function, or make a customized HUOverlay to draw the remaining bomb count information.

      Comment


        #4
        Never heard of customizing the Hud but It would be nice if someone could port the UT3 Hud to UT2004.

        Comment


          #5
          Thanks guys, I'm looking at ONSVehicle and I can see how the HUD overlay is being drawn to the screen. What I really need to do then, is create a HUD overlay... which is where there's another problem as so far I've just been scripting and using existing graphics from the game.

          I tried creating a static mesh in UnrealEd, by putting together an object using brushes and then converting to a static mesh, but it wanted to save it as part of my package, and then simply created a separate file in a different directory, rather than putting it with the classes for my package. I don't yet know how to even begin editing textures, HUD overlays, etc. This is probably best asked in one of the other forums, but could anyone give me some ideas of how to do this?

          Thanks for the information so far.

          Comment


            #6
            Making a new HUD Overlay is easy. Here is a code stub, but you should read the canvas class and the material at this link to understand all of the canvas functions.
            Code:
            class HudOverlay_YourBomberClass extends HudOverlay;
            
            // bomb variables
            var int MaxBombs, CurrentBombs;
            
            function Render( Canvas C ){
                // draw things using the Canvas functions e.g: C.DrawText
                // grab the values from your bomber class, which since it is being driven, *should* be the pawn of the playercontroller owner (hence casting PlayerOwner.Pawn to your bomber)
                CurrentBombs = yourbomberclass(PlayerOwner.Pawn).NumberOfBombs;
                MAxBombs = yourbomberclass(PlayerOwner.Pawn).MaxBombs;
                
                C.Font = C.MedFont; // set the correct font size for the text, check the canvas class to see your other choices
                // Now draw the text on the HudOverlay
                C.DrawTextJustified(CurrentBombs@"/"@MaxBombs, 1, Blah, Blah , Blah, blah);// fill in the blahs to set the correct screen position of the text
            }

            Comment


              #7
              Thanks for the example meowcat; I'll give that a try in a little while. I was also hoping to put an icon representing the bomb next to it to make it clearer for quick reference, and change this text while loading warheads. I assume the latter could be simply achieved by adding something like this to the render function:

              Code:
              local GiftigBombcopter gbc;
              
              gbc=GiftigBombcopter(PlayerOwner.Pawn);
              
              if(gbc!=None)
               {
               if(gbc.isInState('LoadingWarheads'))
                {
                //...do loading text here
                }
               }
              Thanks for the link as well by the way, going to be having a look through that

              Comment


                #8
                Yup! For all of the drawing functions review that link about the Canvas class, and do some digging through the normal UT2k4 GUI classes (they have all kinds of examples of how to draw icons and text on the Canvas). The assaultRifle.uc file also has some good example code if I recall correctly for those little grenade icons.

                Comment


                  #9
                  Thanks, I was planning on looking at stuff like that for the drawn-on icons, yeah. At the moment I'm more concerned about how to create the icons etc to be drawn onto the screen; as I said, I've only used pre-existing graphics so far, and I don't know how to properly create my own static meshes and textures. UnrealEd said it added it to my package but I assume that means it added it to the compiled package file, which seems a bit inconvenient as it sounds like it'll be overwritten the next time I recompile my scripts.


                  EDIT:

                  Error when trying to use PlayerOwner, and on further inspection there is no variable with that name. Did you mean to imply this?

                  Code:
                  local PlayerController PlayerOwner;
                  
                  PlayerOwner=PlayerController(Owner);
                  
                  if(PlayerOwner==None)
                   return;
                  That's what I'm trying now, anyway.

                  Comment


                    #10
                    Hmm it's not even attempting to load the HUD overlay, and I'm not sure why...

                    Code:
                    // HUD OVERLAY CLASS
                    
                    class HudOverlay_GiftigBombcopter extends HudOverlay;
                    
                    function render(Canvas c)
                     {
                     local PlayerController p;
                     local GiftigBombcopter vehicle;
                     local GiftigBombcopterWeapon weapon;
                     
                     log("render function reached");
                     
                     p=PlayerController(owner);
                     
                     if(p==None)
                      return;
                     
                     vehicle=GiftigBombcopter(p.pawn);
                     
                     if(vehicle==None)
                      return;
                     log("vehicle != None"); //remove
                     
                     weapon=GiftigBombcopterWeapon(vehicle.weapons[0]);
                     
                     if(weapon==None)
                      return;
                     log("weapon != None"); //remove
                     
                     c.font=c.medFont;
                     c.drawTextJustified(weapon.warheads@" / "@weapon.max_warheads@" warheads",1,10,10,100,100); //pure guess with the dimensions, need to read that page a bit more
                     }
                    
                    
                    
                    //GIFTIGBOMBCOPTER: DEFAULT PROPERTIES
                    
                    DefaultProperties
                     {
                     VehicleNameString="Giftig Bomber";
                     VehiclePositionString="in a Giftig Bomber";
                     
                     DriverWeapons(0)=(WeaponClass=class'Giftig01.GiftigBombcopterWeapon',WeaponBone=PlasmaGunAttachment);
                     
                     HUDOverlayClass=class'HudOverlay_GiftigBombcopter';
                     }
                    Any ideas what's wrong? I'm not getting any log messages.

                    EDIT:
                    Looking at the Vehicle class, the overlay is spawned if the HUDOverlayClass variable is not None, upon calling of ActivateOverlay(true). This is called from the ClientKDriverEnter function, as long as the bBehindView variable of the PlayerController is false... can someone tell me what this variable means? Maybe it's set to true...

                    FURTHER EDIT:

                    To test this, I tried triggering the vehicle's activateOverlay(true); at the start of the altFire function for the weapon, but I still didn't get any log messages.

                    Comment


                      #11
                      Did you read through the code in the vehicle (or maybe it was SVehicle, or ONS vehicle) that explains when the HUDOverlay is spawned? You can't be in third person view when in the vehicle, otherwise the overlay wont spawn. To test this, get into your vehicle, scorll the mousewheel so the view is in FP, then hop out and hop back in and see if the HUD shows up.

                      Comment


                        #12
                        Okay two issues:

                        1 - I always use third-person mode in vehicles, and so does everyone else I know. Is there a way I can make the overlay appear while in third-person mode?

                        2 - The overlay isn't appearing when I do as you suggested, and I'm not getting any log messages either.

                        Comment


                          #13
                          Modify the ClientKDriverEnter function to always spawn the overlay. Or alternatively (and this is probably the way to go) modify the DrawHUD function itself to draw the ammo stuff to the screen.

                          Comment


                            #14
                            Originally posted by meowcat View Post
                            Or alternatively (and this is probably the way to go) modify the DrawHUD function itself to draw the ammo stuff to the screen.
                            Did that, worked immediately. I don't know why I was messing about with overlays to begin with

                            Thanks for the help. Now I just need to sort out the icon, and look through that link to figure out how to draw it correctly.

                            Comment


                              #15
                              Can I have the sripts when ur done, im kinda stuck at hud's. Would appreciate it!

                              Comment

                              Working...
                              X