Integration Guide for Unsupported Map Mods

If you're using a map mod that isn't natively supported by NinjinsPvPPvE, you can integrate it yourself to enable zone drawing and callbacks.

Step 1: Find the Map Menu Class

Identify the class name of your map mod's menu. Common patterns:

Step 2: Create Integration File

Create a new file in your mod (or modify the map mod if you have access):

// Example: MyCustomMap.c
modded class MyCustomMapMenu  // Replace with your map menu class name
{
    private ref MapDrawer m_MapDrawer;
    private CanvasWidget m_DrawCanvas;
    private MapWidget m_MapWidget;
    private float m_LastZoneRequestTime = 0;
    private const float ZONE_REQUEST_COOLDOWN = 10.0;
    
    override Widget Init()  // Or OnInit(), or whatever initialization method exists
    {
        super.Init();  // Call parent initialization
        
        // Find the MapWidget - adjust widget name as needed
        m_MapWidget = MapWidget.Cast(layoutRoot.FindAnyWidget("Map"));
        // Alternative widget names to try:
        // - "Map_Widget"
        // - "map_widget"
        // - "MapWidget"
        
        if (!m_MapWidget)
        {
            NinjinsPvPPvE.LogWarning("[MyCustomMap] ERROR: MapWidget not found.");
            return layoutRoot;
        }
        
        // Clean up any existing canvas
        CanvasWidget oldCanvas = CanvasWidget.Cast(m_MapWidget.FindAnyWidget("ninjindrawCanvas"));
        if (oldCanvas)
        {
            oldCanvas.Unlink();
            oldCanvas = null;
        }
        
        // Reset any existing MapDrawer instance
        MapDrawer.ResetInstance(m_MapWidget);
        
        // Create the drawing canvas
        Widget canvasLayout = GetGame().GetWorkspace().CreateWidgets(
            "NinjinsPvPPvE/gui/layouts/NinjinsMapCanvasOnly.layout", 
            m_MapWidget
        );
        
        if (!canvasLayout)
        {
            NinjinsPvPPvE.LogWarning("[MyCustomMap] ERROR: Failed to load canvas layout.");
            return layoutRoot;
        }
        
        // Get the canvas widget
        m_DrawCanvas = CanvasWidget.Cast(canvasLayout.FindAnyWidget("ninjindrawCanvas"));
        if (!m_DrawCanvas)
        {
            NinjinsPvPPvE.LogWarning("[MyCustomMap] ERROR: drawCanvas not found in layout.");
            return layoutRoot;
        }
        
        // Initialize MapDrawer
        m_MapDrawer = MapDrawer.GetInstance(m_MapWidget, m_DrawCanvas);
        if (!m_MapDrawer)
        {
            NinjinsPvPPvE.LogWarning("[MyCustomMap] ERROR: Failed to initialize MapDrawer.");
        }
        
        return layoutRoot;
    }
    
    override void OnShow()  // Or whatever method is called when map opens
    {
        super.OnShow();
        
        // Request zones from server (with cooldown)
        float currentTime = GetGame().GetTickTime();
        float timeSinceLastRequest = currentTime - m_LastZoneRequestTime;
        if (timeSinceLastRequest > ZONE_REQUEST_COOLDOWN)
        {
            GetRPCManager().SendRPC("NinjinsPvPPvE", "RequestZones", NULL, true, null);
            m_LastZoneRequestTime = currentTime;
        }
        
        // Update zones on map
        if (!m_MapDrawer)
            return;
            
        MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
        if (!mission)
            return;
            
        array zones = mission.GetCachedZones();
        if (zones && zones.Count() > 0)
        {
            bool drawLabels = g_MainConfig && g_MainConfig.DrawNamesOnZones;
            m_MapDrawer.UpdateZones(zones, drawLabels);
        }
    }
    
    override void Update(float timeslice)  // Or OnUpdate(), etc.
    {
        super.Update(timeslice);
        
        // Trigger map updates
        if (m_MapDrawer && m_MapDrawer.HasValidWidget())
        {
            m_MapDrawer.TriggerUpdate();
        }
    }
    
    override void OnHide()  // Or OnClose(), etc.
    {
        super.OnHide();
        
        // Clean up
        MapDrawer.ResetInstance(m_MapWidget);
        m_MapDrawer = null;
        m_DrawCanvas = null;
    }
}

Step 3: Key Points

  1. Widget Name: The MapWidget name may vary. Common names:
    • "Map"
    • "Map_Widget"
    • "map_widget"
    • "MapWidget"
  2. Method Names: The method names may differ:
    • Init() vs OnInit()
    • OnShow() vs Show()
    • Update() vs OnUpdate()
    • OnHide() vs OnClose() vs Close()
  3. Layout Path: The canvas layout path is always:
    "NinjinsPvPPvE/gui/layouts/NinjinsMapCanvasOnly.layout"
  4. RPC Call: To request zones from server:
    GetRPCManager().SendRPC("NinjinsPvPPvE", "RequestZones", NULL, true, null);

Step 4: Testing

  1. Open your map mod
  2. Check the RPT log for any errors
  3. Zones should appear on the map
  4. Your drawing callbacks should fire

Troubleshooting

Problem: MapWidget not found

Problem: Canvas not drawing

Problem: Zones not appearing