Denis Kosher Posted December 2, 2022 Report Share Posted December 2, 2022 Hi All, I've been working on the mod to add more map icons, and found it really challenging to add them. I've investigated this issue for a while, and was able to resolve them by changing game source code, but since there is no way to create pool request - posting details of investigation and suggested change here. Issue (RCA) Right now game works in the following way: Map layers are loaded as part of vsesssentials mod If player has mini-map loaded - game initializes texturesByIcon list, and once it's defined - it's not re-generated If mini-map is disabled - texturesByIcon list is initialized only when player opens map Therefore if modder wants to create a mod that adds more icons - this mod needs to inject icons between actions 1 and 2, which is not currently achievable. As an alternative you can try to copy logic from WaypintMapLayer.OnMapOpenedClient and try to add texture for your icon, but when I've tried this approach (please see code snipped below) - on the map my maps were shown as 100% transparent texture Code that I've used: public void AddIconTexture(String iconName) { if (_wpManager.texturesByIcon.ContainsKey(iconName)) { continue; } ImageSurface surface = new ImageSurface(Format.Argb32, size, size); Context ctx = new Context(surface); double scale = RuntimeEnv.GUIScale; int size = (int)(27 * scale); ctx.Operator = Operator.Clear; ctx.SetSourceRGBA(0, 0, 0, 0); ctx.Paint(); ctx.Operator = Operator.Over; _capi.Gui.Icons.DrawIcon(ctx, "wp" + iconName.UcFirst(), 1, 1, size - 2, size - 2, new double[] { 0, 0, 0, 1 }); _capi.Gui.Icons.DrawIcon(ctx, "wp" + iconName.UcFirst(), 2, 2, size - 4, size - 4, ColorUtil.WhiteArgbDouble); texturesByIcon[iconName] = new LoadedTexture(_capi, _capi.Gui.LoadCairoTexture(surface, false), (int)(20 * scale), (int)(20 * scale)); ctx.Dispose(); surface.Dispose(); _wpManager.OnMapOpenedClient(); } Solution In order to resolve this issue we need to - update WaypintMapLayer.OnMapOpenedClient so on each reload of the map - it will check if all of the icon textures are loaded, and if no, will generate missing ones (game sources, vsesentials): public override void OnMapOpenedClient() { if (texturesByIcon == null) { texturesByIcon = new Dictionary<string, LoadedTexture>(); } ImageSurface surface = null; Context ctx = null; ICoreClientAPI capi = api as ICoreClientAPI; double scale = RuntimeEnv.GUIScale; int size = (int)(27 * scale); foreach (var val in WaypointIcons) { if (texturesByIcon.ContainsKey(val)) { continue; } if (ctx == null) { surface = new ImageSurface(Format.Argb32, size, size); ctx = new Context(surface); } ctx.Operator = Operator.Clear; ctx.SetSourceRGBA(0, 0, 0, 0); ctx.Paint(); ctx.Operator = Operator.Over; capi.Gui.Icons.DrawIcon(ctx, "wp" + val.UcFirst(), 1, 1, size - 2, size - 2, new double[] { 0, 0, 0, 1 }); capi.Gui.Icons.DrawIcon(ctx, "wp" + val.UcFirst(), 2, 2, size - 4, size - 4, ColorUtil.WhiteArgbDouble); texturesByIcon[val] = new LoadedTexture(capi, capi.Gui.LoadCairoTexture(surface, false), (int)(20 * scale), (int)(20 * scale)); } if (ctx != null) { ctx.Dispose(); surface.Dispose(); } RebuildMapComponents(); } Questions I have two questions to the community: I'm a bit confused why same code in game sources, and copied to my mod gets different result (why when I use it - empty texture is rendered), maybe I'm missing something? Is there any way how we can suggest change above to @Tyron? 1 Link to comment Share on other sites More sharing options...
Tyron Posted December 2, 2022 Report Share Posted December 2, 2022 This is pretty much fully rewritten for 1.18. Adding new map icons is simplified to adding a .svg file to textures/icons/worldmap, so no code or config changes needed. 6 1 Link to comment Share on other sites More sharing options...
Denis Kosher Posted December 2, 2022 Author Report Share Posted December 2, 2022 I've spent so much time working on that mod and reading game sources But I'm really glad that it's going to be simplified, thank you for awesome news, will be looking forward to see 1.18! Link to comment Share on other sites More sharing options...
Maelstrom Posted December 2, 2022 Report Share Posted December 2, 2022 43 minutes ago, Denis Kosher said: Is there any way how we can suggest change above to @Tyron? There's a number of forums on the VS Discord specifically for these kinds of questions/discussions. 1 Link to comment Share on other sites More sharing options...
Gamer62 Posted January 16, 2023 Report Share Posted January 16, 2023 Maybe numbers 1 to 10 as i think you will see numbers better then some icons when zoomed out further on the map Link to comment Share on other sites More sharing options...
Recommended Posts