<Compile Include="Renderers\AlternateRenderer.cs" />
<Compile Include="Data\EntitiesOfInterest.cs" />
<Compile Include="Data\EntityDesignator.cs" />
+ <Compile Include="Data\StatusData.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="VS_libs\" />
_localAutomap = new AutomapSystem( this.ClientAPI, this.Logger);
_automapDialog = new AutomapGUIDialog(ClientAPI, _localAutomap);
- ClientAPI.Input.RegisterHotKey(AutomapGUIDialog._automapControlPanelKey, "Automap control panel", GlKeys.A, HotkeyType.GUIOrOtherControls);
+ ClientAPI.Input.RegisterHotKey(AutomapGUIDialog._automapControlPanelKey, "Automap control panel", GlKeys.M, HotkeyType.GUIOrOtherControls, shiftPressed: true);
ClientAPI.Input.SetHotKeyHandler(AutomapGUIDialog._automapControlPanelKey, ToggleAM_Dialog);
}
--- /dev/null
+using System;
+using System.IO;
+using Vintagestory.API.Common;
+using Vintagestory.API.Datastructures;
+
+namespace Automap
+{
+ public class StatusData : IAttribute
+ {
+ public uint TotalUpdates { get; set; }
+ public uint VoidChunks { get; set; }
+ public uint Delta { get; set; }
+
+
+ public StatusData(uint totalUpdates, uint voidChunks, uint delta )
+ {
+ TotalUpdates = totalUpdates;
+ VoidChunks = voidChunks;
+ Delta = delta;
+ }
+
+
+
+ public void FromBytes(BinaryReader stream)
+ {
+ TotalUpdates = stream.ReadUInt32( );
+ VoidChunks = stream.ReadUInt32( );
+ Delta = stream.ReadUInt32( );
+ }
+
+ public int GetAttributeId( )
+ {
+ return 12345;
+ }
+
+ public object GetValue( )
+ {
+ return this;
+ }
+
+ public void ToBytes(BinaryWriter stream)
+ {
+ stream.Write(TotalUpdates);
+ stream.Write(VoidChunks);
+ stream.Write(Delta);
+ }
+
+ public string ToJsonToken( )
+ {
+ return $"TotalUpdate:{TotalUpdates}, VoidChunks:{VoidChunks}, Delta:{Delta}";
+ }
+
+ public bool Equals(IWorldAccessor worldForResolve, IAttribute attr)
+ {
+ StatusData other = attr.GetValue( ) as StatusData;
+
+ if (this.TotalUpdates == other.TotalUpdates &&
+ this.VoidChunks == other.VoidChunks &&
+ this.Delta == other.Delta) {
+ return true;
+ }
+ return false;
+ }
+ }
+}
+
using Vintagestory.API.Client;
using Vintagestory.API.Common;
+using Vintagestory.API.Datastructures;
namespace Automap
{
public class AutomapGUIDialog : GuiDialog
{
public const string _automapControlPanelKey = "automapControlPanelKey";
+ private const string _statusTextKey = @"txtStatus";
private ILogger Logger;
private AutomapSystem _automapSystem;
+ private long dashTickHandle;
+
public override string ToggleKeyCombinationCode {
get
{
}
}
+ private uint totalShards, voidShards, changesThisTick;
+
public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi)
{
_automapSystem = ams;
Logger = capi.Logger;
SetupDialog( );
+ capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.automapStatusEventKey);
+
}
//Event for GUI status display
toggleBounds.fixedHeight = 24;
toggleBounds.fixedWidth = 64;
- ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 20, 2, 4);
+ ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 64, 2, 4);
txtStatusBounds.fixedHeight = 16;
txtStatusBounds.percentWidth = 1;
.AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked)
.AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds)
.AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun")
- .AddStaticText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), txtStatusBounds, "txtStatus")
+ .AddDynamicText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey)
.Compose( );
//Controls for ALL Block & Entity Designators (Enable/Disable)
{
_automapSystem.Enabled = toggle;
Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle);
- var statusText = this.SingleComposer.GetStaticText("txtStatus");
- statusText.SetValue($"Running: {this._automapSystem.Enabled}, Total: {this._automapSystem.updatedChunksTotal}, Nulls: {this._automapSystem.nullChunkCount} " );
+ var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
+ statusText.SetNewText($"Running: {this._automapSystem.Enabled}, Total: ?, Nulls: 0 " );
+
+ if (toggle) {
+ dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001);
+ }
+ else {
+ capi.Event.UnregisterGameTickListener(dashTickHandle);
+ }
+
+
+ }
+
+ private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data)
+ {
+ Logger.VerboseDebug("MsgBus - AutomapStatusMsg");
+ StatusData realData = data as StatusData;
+ totalShards = realData.TotalUpdates;
+ voidShards = realData.VoidChunks;
+ changesThisTick = realData.Delta;
+
}
+
+ private void UpdateDashDisplay(float delay )
+ {
+ var statusText = this.SingleComposer.GetDynamicText(_statusTextKey);
+ statusText.SetNewText($"Running: {this._automapSystem.Enabled}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} ");
+
+
+ }
+
+
}
}
using Vintagestory.Common;
namespace Automap
-{
+{
public class AutomapSystem
{
private Thread cartographer_thread;
internal bool Enabled { get; set; }
//Run status, Chunks processed, stats, center of map....
- internal uint nullChunkCount, updatedChunksTotal;
- internal Vec2i startChunkColumn;
+ private uint nullChunkCount, updatedChunksTotal;
+ private Vec2i startChunkColumn;
private readonly int chunkSize;
private string path;
private IAsset stylesFile;
+ public static string automapStatusEventKey = @"AutomapStatus";
+
public AutomapSystem(ICoreClientAPI clientAPI, ILogger logger)
{
}
}
+ UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks);
+
if (updatedChunks > 0) {
//What about chunk updates themselves; a update bitmap isn't kept...
updatedChunksTotal += updatedChunks;
}
}
+ private void UpdateStatus( uint totalUpdates, uint voidChunks, uint delta)
+ {
+ StatusData updateData = new StatusData(totalUpdates, voidChunks, delta);
+
+ this.ClientAPI.Event.PushEvent(automapStatusEventKey, updateData);
+ }
+
private void Prefill_POI_Designators( )
{
this.POIs = new PointsOfInterest( );