Jump to content

More Map Icons addition thru mods


Denis Kosher

Recommended Posts

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:

  1. Map layers are loaded as part of vsesssentials mod
  2. If player has mini-map loaded - game initializes texturesByIcon list, and once it's defined - it's not re-generated
  3. 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:

  1. 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?
  2. Is there any way how we can suggest change above to @Tyron?
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.