Skip to content

Commit

Permalink
Load icons from game instead of hardcoding
Browse files Browse the repository at this point in the history
  • Loading branch information
egocarib committed Jun 25, 2023
1 parent d593728 commit b23af33
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
11 changes: 6 additions & 5 deletions mods/egocaribautomapmarkers/egocaribautomapmarkers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>$(ProjectDir)\bin</OutputPath>
<OutputPath>bin\Debug\</OutputPath>
<IntermediateOutputPath>..\..\obj\Debug\egocaribautomapmarkers\</IntermediateOutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
Expand Down Expand Up @@ -50,6 +50,10 @@
<HintPath>..\..\..\..\..\..\AppData\Roaming\Vintagestory\Lib\cairo-sharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\AppData\Roaming\Vintagestory\Lib\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="protobuf-net">
<HintPath>..\..\..\..\..\..\AppData\Roaming\Vintagestory\Lib\protobuf-net.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -79,10 +83,6 @@
<HintPath>..\..\..\..\..\..\AppData\Roaming\Vintagestory\Mods\VSCreativeMod.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>D:\Program Files\Vintagestory\Lib\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="assets\automapmarkers\lang\en.json" />
Expand Down Expand Up @@ -112,6 +112,7 @@
</ItemGroup>
<ItemGroup>
<None Include=".ignore" />
<None Include="assets\automapmarkers\lang\de.json" />
<None Include="assets\automapmarkers\lang\ru.json" />
<None Include="README.md" />
</ItemGroup>
Expand Down
Binary file modified mods/egocaribautomapmarkers/egocaribautomapmarkers.dll
Binary file not shown.
Binary file modified mods/egocaribautomapmarkers/egocaribautomapmarkers.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions mods/egocaribautomapmarkers/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"name": "Auto Map Markers",
"authors": [ "egocarib" ],
"description": "Automatically adds map markers to your map when you interact with certain objects. Fully configurable.",
"version": "2.5.0",
"version": "2.6.0",
"requiredOnServer": true,
"requiredOnClient": true,
"dependencies": {
"game": "1.18.0"
"game": "1.18.6-rc.2"
}
}
35 changes: 31 additions & 4 deletions mods/egocaribautomapmarkers/src/GUI/MapMarkerGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class MapMarkerGUI : GuiDialog
public int DynamicDrawColor;
private Action RegisterCustomHotkeys;
private Action RegisterDeleteHotkey;
public string[] iconsPrefixed;
public string[] icons;
public string[] iconsVTML;

public override string ToggleKeyCombinationCode { get { return HotkeyCode; } }

Expand All @@ -54,6 +57,7 @@ public override void OnGuiOpened()
{
ModSettings = MapMarkerConfig.GetSettings(capi);
AutoMapMarkerSettings = ModSettings.GetMapMarkerSettingCollection();
LoadIconStrings();
SetupDialog();
}
catch (Exception e)
Expand All @@ -63,15 +67,38 @@ public override void OnGuiOpened()
base.OnGuiOpened();
}

/// <summary>
/// Loads all the world map waypoint icons, which typically are loaded from the following directory:
/// %appdata%\Roaming\Vintagestory\assets\survival\textures\icons\worldmap
/// </summary>
private void LoadIconStrings()
{
iconsPrefixed = capi.Gui.Icons.CustomIcons.Keys
.Where(k => k.Substring(0,2) == "wp" && k != "wpCross" && k.Length > 2)
.ToArray();
List<string> tmpStrings = new List<string>();
foreach (string icon in iconsPrefixed)
{
//example: wpBee -> bee
string s = icon.Substring(2, 1).ToLower() + (icon.Length > 3 ? icon.Substring(3) : "");
tmpStrings.Add(s);
}
icons = tmpStrings.ToArray();
tmpStrings.Clear();
foreach (string icon in iconsPrefixed)
{
//example: wpBee -> <icon name=\"wpBee\">
string s = $"<icon name=\"{icon}\">";
tmpStrings.Add(s);
}
iconsVTML = tmpStrings.ToArray();
}

/// <summary>
/// Composes or re-composes the GUI. Called each time the menu tab changes or an option is toggled off/on
/// </summary>
private void SetupDialog()
{
// Icon info
string[] icons = MapMarkerConfig.Settings.Icons.Split(',');
string[] iconsVTML = MapMarkerConfig.Settings.IconsVTML.Split(',');

CairoFont headerFont = CairoFont.WhiteSmallishText().Clone().WithWeight(Cairo.FontWeight.Bold);
headerFont.Color[3] = 0.6; // Adjust transparency
CairoFont disabledFont = CairoFont.WhiteSmallishText().Clone().WithSlant(FontSlant.Italic);
Expand Down
2 changes: 0 additions & 2 deletions mods/egocaribautomapmarkers/src/Settings/MapMarkerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public static class MapMarkerConfig
public class Settings
{
private OrderedDictionary<string, OrderedDictionary<string, AutoMapMarkerSetting>> _MapMarkerSettingsCollection = null;
public const string Icons = "circle,bee,cave,home,ladder,pick,rocks,ruins,spiral,star1,star2,trader,vessel";
public const string IconsVTML = "<icon name=\"wpCircle\">,<icon name=\"wpBee\">,<icon name=\"wpCave\">,<icon name=\"wpHome\">,<icon name=\"wpLadder\">,<icon name=\"wpPick\">,<icon name=\"wpRocks\">,<icon name=\"wpRuins\">,<icon name=\"wpSpiral\">,<icon name=\"wpStar1\">,<icon name=\"wpStar2\">,<icon name=\"wpTrader\">,<icon name=\"wpVessel\">";

[ProtoMember(1, IsRequired = true)]
public bool ChatNotifyOnWaypointCreation = false;
Expand Down

0 comments on commit b23af33

Please sign in to comment.