Skip to content

Commit

Permalink
adding location hud (#12)
Browse files Browse the repository at this point in the history
* adding location hud

* adjusting font size

* skipping content pipeline for appveyor
  • Loading branch information
gmriggs authored Aug 12, 2020
1 parent 8ffb9cd commit b228fff
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 2 deletions.
22 changes: 22 additions & 0 deletions DatExplorer/Content/Content.mgcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#----------------------------- Global Properties ----------------------------#

/outputDir:bin/$(Platform)
/intermediateDir:obj/$(Platform)
/platform:Windows
/config:
/profile:Reach
/compress:False

#-------------------------------- References --------------------------------#


#---------------------------------- Content ---------------------------------#

#begin Fonts/Consolas.spritefont
/importer:FontDescriptionImporter
/processor:FontDescriptionProcessor
/processorParam:PremultiplyAlpha=True
/processorParam:TextureFormat=Color
/build:Fonts/Consolas.spritefont

60 changes: 60 additions & 0 deletions DatExplorer/Content/Fonts/Consolas.spritefont
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
<Asset Type="Graphics:FontDescription">

<!--
Modify this string to change the font that will be imported.
-->
<FontName>Consolas</FontName>

<!--
Size is a float value, measured in points. Modify this value to change
the size of the font.
-->
<Size>11</Size>

<!--
Spacing is a float value, measured in pixels. Modify this value to change
the amount of spacing in between characters.
-->
<Spacing>0</Spacing>

<!--
UseKerning controls the layout of the font. If this value is true, kerning information
will be used when placing characters.
-->
<UseKerning>true</UseKerning>

<!--
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
and "Bold, Italic", and are case sensitive.
-->
<Style>Regular</Style>

<!--
If you uncomment this line, the default character will be substituted if you draw
or measure text that contains characters which were not included in the font.
-->
<!-- <DefaultCharacter>*</DefaultCharacter> -->

<!--
CharacterRegions control what letters are available in the font. Every
character from Start to End will be built and made available for drawing. The
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
character set. The characters are ordered according to the Unicode standard.
See the documentation for more information.
-->
<CharacterRegions>
<CharacterRegion>
<Start>&#32;</Start>
<End>&#126;</End>
</CharacterRegion>
</CharacterRegions>
</Asset>
</XnaContent>
Binary file added DatExplorer/Content/Fonts/Consolas.xnb
Binary file not shown.
6 changes: 6 additions & 0 deletions DatExplorer/DatExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@
<EmbeddedResource Include="Content\texture.mgfxo">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<MonoGameContentReference Include="Content\Content.mgcb" />
<None Include="Content\Fonts\Consolas.spritefont" />
<None Include="Content\Fonts\Consolas.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -529,6 +534,7 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!--<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />-->
<PropertyGroup>
<PostBuildEvent>robocopy $(SolutionDir)docs $(TargetDir)docs /S /E /COPY:DAT /MIR /NP /TEE /V

Expand Down
5 changes: 5 additions & 0 deletions DatExplorer/Physics/Common/LScape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public static bool unload_landblock(uint landblockID)
return Landblocks.TryRemove(landblockID, out _);
}

public static void unload_landblocks_all()
{
Landblocks.Clear();
}

public static ObjCell get_landcell(uint blockCellID)
{
//Console.WriteLine($"get_landcell({blockCellID:X8}");
Expand Down
56 changes: 56 additions & 0 deletions DatExplorer/Render/Camera.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using System;
using System.Linq;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using MonoGame.Framework.WpfInterop.Input;

using DatExplorer.Model;
using DatExplorer.Render;

using ACE.Server.Physics.Common;

namespace DatExplorer
{
public class Camera
Expand Down Expand Up @@ -297,5 +302,56 @@ public void SetMouse()
//Mouse.SetCursor((int)StartPos.X, (int)StartPos.Y);
//PrevMouseState = Mouse.GetState();
}

public string GetPosition()
{
// 255 landblocks across * 192 meters for each landblock = 48,960 meters across Dereth
if (Position.X < 0.0f || Position.Y < 0.0f || Position.X > 48960.0f || Position.Y > 48960.0f)
return null;

var lbx = (int)(Position.X / 192.0f);
var lby = (int)(Position.Y / 192.0f);

var x = Position.X % 192.0f;
var y = Position.Y % 192.0f;

var cellX = (int)(x / 24.0f);
var cellY = (int)(y / 24.0f);

var cell = cellX * 8 + cellY + 1;

var objCellId = (uint)(lbx << 24 | lby << 16 | cell);

var yaw = Math.Atan2(-Dir.X, Dir.Y);

var q = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)yaw);

// test if we are in any loaded indoor cells
foreach (var landblock in LScape.Landblocks.Values)
{
// find origin in terms of this landblock
var blockX = landblock.ID >> 24;
var blockY = landblock.ID >> 16 & 0xFF;

var blockX_start = blockX * 192.0f;
var blockY_start = blockY * 192.0f;

var blockPosX = Position.X - blockX_start;
var blockPosY = Position.Y - blockY_start;

var origin = new System.Numerics.Vector3(blockPosX, blockPosY, Position.Z);

var envCells = landblock.get_envcells();

foreach (var envCell in envCells)
{
if (envCell.point_in_cell(origin))
return $"0x{envCell.ID:X8} [{blockPosX} {blockPosY} {Position.Z}] {q.W} {q.X} {q.Y} {q.Z}";
}
}

// return outdoor location
return $"0x{objCellId:X8} [{x} {y} {Position.Z}] {q.W} {q.X} {q.Y} {q.Z}";
}
}
}
21 changes: 21 additions & 0 deletions DatExplorer/Render/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class Render

public Buffer Buffer;

// text rendering
public SpriteBatch SpriteBatch => GameView.SpriteBatch;

public SpriteFont Font;

public Render()
{
Init();
Expand All @@ -35,6 +40,8 @@ public void Init()
Effect.Parameters["xProjection"].SetValue(Camera.ProjectionMatrix);

Buffer = new Buffer();

Font = GameView.Content.Load<SpriteFont>("Fonts/Consolas");
}

public void Draw()
Expand Down Expand Up @@ -163,5 +170,19 @@ public void Draw(Dictionary<uint, R_Landblock> landblocks)
//landblock.Draw();
Buffer.Draw();
}

private static readonly Vector2 TextPos = new Vector2(10, 10);

public void DrawHUD()
{
var cameraPos = GameView.Camera.GetPosition();

if (cameraPos != null)
{
SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearClamp);
SpriteBatch.DrawString(Font, $"Location: {cameraPos}", TextPos, Color.White);
SpriteBatch.End();
}
}
}
}
2 changes: 2 additions & 0 deletions DatExplorer/View/MainMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
</MenuItem>
<MenuItem Header="_View">
<MenuItem Header="_World Map" Click="WorldMap_Click" />
<MenuItem x:Name="optionShowHUD" Header="Show _HUD" Click="ShowHUD_Click" />
<MenuItem Header="Show _Location" Click="ShowLocation_Click" />
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_View Help" Click="Guide_Click" />
Expand Down
24 changes: 24 additions & 0 deletions DatExplorer/View/MainMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public partial class MainMenu : UserControl

public static Options Options;

public static bool ShowHUD;

public static MainMenu Instance;

public MainMenu()
{
InitializeComponent();
Instance = this;
}

private async void OpenFile_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -75,6 +80,25 @@ private void WorldMap_Click(object sender, RoutedEventArgs e)
GameView.ViewMode = ViewMode.Map;
}

private void ShowHUD_Click(object sender, RoutedEventArgs e)
{
ToggleHUD();
}

public static bool ToggleHUD()
{
ShowHUD = !ShowHUD;
Instance.optionShowHUD.IsChecked = ShowHUD;

return ShowHUD;
}

private void ShowLocation_Click(object sender, RoutedEventArgs e)
{
if (WorldViewer.Instance != null)
WorldViewer.Instance.ShowLocation();
}

private void About_Click(object sender, RoutedEventArgs e)
{
var about = new About();
Expand Down
27 changes: 25 additions & 2 deletions DatExplorer/WorldViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public void LoadLandblock(uint landblockID, uint radius = 1)
Buffer.ClearBuffer();
TextureCache.Init();

LScape.unload_landblocks_all();

var landblock = LScape.get_landblock(landblockID);
if (landblock.IsDungeon)
radius = 0;
Expand Down Expand Up @@ -78,7 +80,7 @@ public void LoadLandblock(uint landblockID, uint radius = 1)
timer.Stop();

r_landblock = new R_Landblock(landblock);
LScape.unload_landblock(lbid);
//LScape.unload_landblock(lbid);

if (landblockID == lbid)
centerBlock = r_landblock;
Expand Down Expand Up @@ -106,6 +108,8 @@ public async void LoadLandblocks(Vector2 startBlock, Vector2 endBlock)
{
Buffer.ClearBuffer();
TextureCache.Init();

LScape.unload_landblocks_all();

DungeonMode = false;

Expand Down Expand Up @@ -141,7 +145,7 @@ public async void LoadLandblocks(Vector2 startBlock, Vector2 endBlock)
timer.Stop();

r_landblock = new R_Landblock(landblock);
LScape.unload_landblock(lbid);
//LScape.unload_landblock(lbid);

if (lbid == landblockID)
centerBlock = r_landblock;
Expand Down Expand Up @@ -181,6 +185,16 @@ public void Update(GameTime time)
GameView.ViewMode = ViewMode.Map;
}

if (keyboardState.IsKeyDown(Keys.H) && !PrevKeyboardState.IsKeyDown(Keys.H))
{
MainMenu.ToggleHUD();
}

if (keyboardState.IsKeyDown(Keys.L) && !PrevKeyboardState.IsKeyDown(Keys.L))
{
ShowLocation();
}

PrevKeyboardState = keyboardState;

if (Camera != null)
Expand All @@ -189,10 +203,19 @@ public void Update(GameTime time)
DrawCount.Update();
}

public void ShowLocation()
{
var pos = Camera.GetPosition() ?? "unknown";
MainWindow.Status.WriteLine($"Location: {pos}");
}

public void Draw(GameTime time)
{
//Render.Draw(Landblocks);
Render.Draw(null);

if (MainMenu.ShowHUD)
Render.DrawHUD();
}
}
}

0 comments on commit b228fff

Please sign in to comment.