Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomHUD extends UTHUD;
- //var MaterialInstanceConstant GameMinimapMIC; // doesn't work at least for me
- //var Material GameMinimapp; // same
- var MU_Minimap GameMinimap;
- var Float TileSize;
- var Int MapDim;
- var Int BoxSize;
- var color PlayerColors[2];
- //var float MPosXMap; // not needed
- //var float MPosYMap; // not needed
- // create Material Instances in code, did not found an other solution
- var MaterialInstanceConstant MiniMapInst; // new
- var MaterialInstanceConstant CompassInst; // new
- var float ResScaleX; // see comment in PostRender
- simulated function PostBeginPlay()
- {
- Super.PostBeginPlay();
- GameMinimap = TaskGame(WorldInfo.Game).GameMinimap;
- // create Material Instances
- MiniMapInst = new(none) class'MaterialInstanceConstant';
- MiniMapInst.SetParent( GameMinimap.Minimap );
- CompassInst = new(none) class'MaterialInstanceConstant';
- CompassInst.SetParent( GameMinimap.CompassOverlay );
- }
- event PostRender()
- {
- // my Hud is based on 1280x1024, for other resolutions it will be scaled up/down
- // Canvas.ClipX returns your current Width, ClipY the Height res.
- ResScaleX = Canvas.ClipX/1280;
- DrawMap();
- }
- /////////////////////////////////
- //Radar/Minimap
- /////////////////////////////////
- function float GetPlayerHeading()
- {
- local Float PlayerHeading;
- local Rotator PlayerRotation;
- local Vector v;
- PlayerRotation.Yaw = PlayerOwner.Pawn.Rotation.Yaw;
- v = vector(PlayerRotation);
- PlayerHeading = GetHeadingAngle(v);
- PlayerHeading = UnwindHeading(PlayerHeading);
- while (PlayerHeading < 0)
- PlayerHeading += PI * 2.0f;
- return PlayerHeading;
- }
- //There will be a warning on the screen
- //You can disable it, be typing "DisableAllScreenMessages"
- function DrawMap()
- {
- local Float TrueNorth,PlayerHeading;
- local Float MapRotation,CompassRotation;
- local Vector PlayerPos, ClampedPlayerPos, RotPlayerPos, DisplayPlayerPos, StartPos;
- local LinearColor MapOffset;
- local Float ActualMapRange;
- local Controller C;
- //Set MapDim & BoxSize accounting for the current resolution
- /*doesn't work, ResolutionScale is Always 0, MPosXMap and MapPosYMap are always outside the Screen
- MapPosition.X = MPosXMap; //default.MapPosition.X * FullWidth;
- MapPosition.Y = MPosYMap; //default.MapPosition.Y * FullHeight;
- MapDim = default.MapDim * ResolutionScale;
- BoxSize = default.BoxSize * ResolutionScale;*/
- MapDim = default.MapDim * ResScaleX; // this works for me
- BoxSize = default.BoxSize * ResScaleX; // this works for me
- //Calculate map range values
- ActualMapRange = FMax( GameMinimap.MapRangeMax.X - GameMinimap.MapRangeMin.X,
- GameMinimap.MapRangeMax.Y - GameMinimap.MapRangeMin.Y);
- //Calculate normalized player position
- PlayerPos.X = (PlayerOwner.Pawn.Location.Y - GameMinimap.MapCenter.Y) / ActualMapRange;
- PlayerPos.Y = (GameMinimap.MapCenter.X - PlayerOwner.Pawn.Location.X) / ActualMapRange;
- //Calculate clamped player position
- ClampedPlayerPos.X = FClamp(PlayerPos.X,-0.5 + (TileSize / 2.0),0.5 - (TileSize / 2.0));
- ClampedPlayerPos.Y = FClamp(PlayerPos.Y,-0.5 + (TileSize / 2.0),0.5 - (TileSize / 2.0));
- //Get north direction and player's heading
- TrueNorth = GameMinimap.GetRadianHeading();
- Playerheading = GetPlayerHeading();
- //Calculate rotation values
- if(GameMinimap.bForwardAlwaysUp)
- {
- MapRotation = PlayerHeading;
- CompassRotation = PlayerHeading - TrueNorth;
- }
- else
- {
- MapRotation = PlayerHeading - TrueNorth;
- CompassRotation = MapRotation;
- }
- // Replace ATan with ATan2!
- //Calculate position for displaying the player in the map
- //DisplayPlayerPos.X = VSize(PlayerPos) * Cos( ATan(PlayerPos.X) - MapRotation);
- //DisplayPlayerPos.Y = VSize(PlayerPos) * Sin( ATan(PlayerPos.Y) - MapRotation);
- DisplayPlayerPos.X = VSize(PlayerPos) * Cos( ATan2(PlayerPos.Y, PlayerPos.X) - MapRotation);
- DisplayPlayerPos.Y = VSize(PlayerPos) * Sin( ATan2(PlayerPos.Y, PlayerPos.X) - MapRotation);
- // Replace ATan with ATan2!
- //Calculate player location after rotation
- //RotPlayerPos.X = VSize(ClampedPlayerPos) * Cos( ATan(ClampedPlayerPos.X) - MapRotation);
- //RotPlayerPos.Y = VSize(ClampedPlayerPos) * Sin( ATan(ClampedPlayerPos.Y) - MapRotation);
- RotPlayerPos.X = VSize(ClampedPlayerPos) * Cos( ATan2(ClampedPlayerPos.Y, ClampedPlayerPos.X) - MapRotation);
- RotPlayerPos.Y = VSize(ClampedPlayerPos) * Sin( ATan2(ClampedPlayerPos.Y, ClampedPlayerPos.X) - MapRotation);
- //Calculate upper left UV coordinate
- StartPos.X = FClamp(RotPlayerPos.X + (0.5 - (TileSize / 2.0)),0.0,1.0 - TileSize);
- StartPos.Y = FClamp(RotPlayerPos.Y + (0.5 - (TileSize / 2.0)),0.0,1.0 - TileSize);
- StartPos.X = FClamp(DisplayPlayerPos.X + (0.5 - (TileSize / 2.0)),TileSize/-2,1.0 - TileSize/2);
- StartPos.Y = FClamp(DisplayPlayerPos.Y + (0.5 - (TileSize / 2.0)),TileSize/-2,1.0 - TileSize/2);
- //Calculate texture panning for alpha
- MapOffset.R = FClamp(-1.0 * RotPlayerPos.X,-0.5 + (TileSize / 2.0),0.5 - (TileSize / 2.0));
- MapOffset.G = FClamp(-1.0 * RotPlayerPos.Y,-0.5 + (TileSize / 2.0),0.5 - (TileSize / 2.0));
- MapOffset.R = FClamp(-1.0 * DisplayPlayerPos.X,-0.5,0.5);
- MapOffset.G = FClamp(-1.0 * DisplayPlayerPos.Y,-0.5,0.5);
- //Set the material parameter values
- /* direct Modification of Instanced Material is not allowed, Instead use your created Instances
- GameMinimap.Minimap.SetScalarParameterValue('MapRotation',MapRotation);
- GameMinimap.Minimap.SetScalarParameterValue('TileSize',TileSize);
- GameMinimap.Minimap.SetVectorParameterValue('MapOffset',MapOffset);
- GameMinimap.CompassOverlay.SetScalarParameterValue('CompassRotation',CompassRotation);*/
- MiniMapInst.SetScalarParameterValue('MapRotation',MapRotation);
- MiniMapInst.SetScalarParameterValue('TileSize',TileSize);
- MiniMapInst.SetVectorParameterValue('MapOffset',MapOffset);
- CompassInst.SetScalarParameterValue('CompassRotation',CompassRotation);
- //Draw the map
- Canvas.SetPos(MapPosition.X,MapPosition.Y);
- //Canvas.DrawMaterialTile(GameMinimap.Minimap,MapDim,MapDim,StartPos.X,StartPos.Y,TileSize,TileSize);
- Canvas.DrawMaterialTile(MiniMapInst,MapDim,MapDim,StartPos.X,StartPos.Y,TileSize,TileSize); // use own Materialinstance
- //Draw the player's location
- Canvas.SetPos( MapPosition.X + MapDim * (((DisplayPlayerPos.X + 0.5) - StartPos.X) / TileSize) - (BoxSize / 2),
- MapPosition.Y + MapDim * (((DisplayPlayerPos.Y + 0.5) - StartPos.Y) / TileSize) - (BoxSize / 2));
- Canvas.SetDrawColor(PlayerColors[0].R,
- PlayerColors[0].G,
- PlayerColors[0].B,
- PlayerColors[0].A);
- Canvas.DrawBox(BoxSize,BoxSize);
- /*****************************
- * Draw Other Players
- *****************************/
- foreach WorldInfo.AllControllers(class'Controller',C)
- {
- if(PlayerController(C) != PlayerOwner)
- {
- //Calculate normalized player position
- PlayerPos.Y = (GameMinimap.MapCenter.X - C.Pawn.Location.X) / ActualMapRange;
- PlayerPos.X = (C.Pawn.Location.Y - GameMinimap.MapCenter.Y) / ActualMapRange;
- //Calculate position for displaying the player in the map, same as above ATan->ATan2
- //DisplayPlayerPos.X = VSize(PlayerPos) * Cos( ATan(PlayerPos.X) - MapRotation);
- //DisplayPlayerPos.Y = VSize(PlayerPos) * Sin( ATan(PlayerPos.Y) - MapRotation);
- DisplayPlayerPos.X = VSize(PlayerPos) * Cos( ATan2(PlayerPos.Y, PlayerPos.X) - MapRotation);
- DisplayPlayerPos.Y = VSize(PlayerPos) * Sin( ATan2(PlayerPos.Y, PlayerPos.X) - MapRotation);
- if(VSize(DisplayPlayerPos - RotPlayerPos) <= ((TileSize / 2.0) -
- (TileSize * Sqrt(2 * Square(BoxSize / 2)) / MapDim)))
- {
- //Draw the player's location
- Canvas.SetPos( MapPosition.X + MapDim * (((DisplayPlayerPos.X + 0.5) -
- StartPos.X) / TileSize) - (BoxSize / 2),
- MapPosition.Y + MapDim * (((DisplayPlayerPos.Y + 0.5) -
- StartPos.Y) / TileSize) - (BoxSize / 2));
- Canvas.SetDrawColor(PlayerColors[1].R,
- PlayerColors[1].G,
- PlayerColors[1].B,
- PlayerColors[1].A);
- Canvas.DrawBox(BoxSize,BoxSize);
- }
- }
- }
- //Draw the compass overlay
- Canvas.SetPos(MapPosition.X,MapPosition.Y);
- //Canvas.DrawMaterialTile(GameMinimap.CompassOverlay,MapDim,MapDim,0.0,0.0,1.0,1.0);
- Canvas.DrawMaterialTile(CompassInst,MapDim,MapDim,0.0,0.0,1.0,1.0); // use own Materialinstance
- }
- exec function ChangeMapsize(int size)
- {
- MapDim = size;
- }
- exec function MapSizeUp()
- {
- MapDim *= 2;
- BoxSize *= 2;
- }
- exec function MapSizeDown()
- {
- MapDim /= 2;
- BoxSize /= 2;
- }
- exec function MapZoomIn()
- {
- TileSize = 1.0 / FClamp(int((1.0 / TileSize) + 1.0) + 0.5,1.5,10.5);
- TileSize = 1.0 / FClamp(int((1.0 / TileSize) + 1.0) + 0.5,1.5,10.5);
- }
- exec function MapZoomOut()
- {
- TileSize = 1.0 / FClamp(Int((1.0 / TileSize) - 1.0) + 0.5,1.5,10.5);
- }
- defaultproperties
- {
- MapDim=256
- BoxSize=12
- PlayerColors(0)=(R=255,G=255,B=255,A=255)
- PlayerColors(1)=(R=96,G=255,B=96,A=255)
- TileSize=1
- MapPosition=(X=0.000000,Y=0.000000)
- }
Add Comment
Please, Sign In to add comment