Map Location Names and Legend System Setup Guide
Overview
This system adds named geographic features (forests, lakes, plains, mountains, rivers) and a toggleable map legend to MapScene2. The legend allows players to toggle the visibility of different types of location names and implements click blocking to prevent map interaction when the UI is active.
Components Created
1. Geographic Feature System
GeographicFeature.cs: Data structure for named geographic features
GeographicFeatureGenerator.cs: Analyzes the map and creates named features
GeographicFeatureManager.cs: Manages the feature generation process
2. Map Legend and Name Display
MapSceneLegendUI.cs: Interactive legend with terrain colors and name toggles
MapLocationNameDisplay.cs: Displays location names on the map
MapLegend.uss: Updated styles for the legend and location names
3. Integration
- Uses existing
IClickBlocker.cs and ClickManager.cs for UI interaction
Features
🏰 Named Locations
- Settlements: Town and village names (existing system enhanced)
- Forests: "Whispering Woods", "Ancient Grove", "Darkwood Forest", etc.
- Lakes: "Crystal Lake", "Mirror Waters", "Dragon's Rest Lake", etc.
- Plains: "Golden Plains", "Emerald Fields", "Windswept Meadows", etc.
- Mountains: "Frostpeak Mountains", "Dragon's Spine", "Stormhaven Peaks", etc.
- Rivers: "Swift Current", "Silver Stream", "Moonflow River", etc.
🗺️ Interactive Map Legend
- Terrain Colors: Visual legend showing terrain types
- Name Toggles: Individual toggles for each location name type
- Collapsible: Toggle button to show/hide the legend
- Click Blocking: Prevents map interaction when legend is active
🎨 Visual Design
- Color-coded Names: Different colors for each feature type
- Proper Sizing: Larger names for important features
- Discovery System: Support for discovered/undiscovered features
- Non-intrusive: Names don't block map interaction
Setup Instructions
Step 1: Add Geographic Feature System to MapScene2
- Create an empty GameObject called "GeographicFeatureManager"
- Add the
GeographicFeatureManager component to it
- Configure settings:
- Auto Generate Features: ✓ (checked)
- Regenerate On Map Change: ✓ (checked)
- Debug Mode: ✓ (optional for testing)
Step 2: Add Location Name Display
- Create an empty GameObject called "MapLocationNameDisplay"
- Add the
MapLocationNameDisplay component to it
- Configure settings:
- Map UI Document: Assign your map's UIDocument
- Show [Feature Type] Names: Configure which types to show by default
- [Feature Type] Name Color: Customize colors for each feature type
- Map UI Size: Set to match your map UI dimensions (e.g., 1920x1080)
Step 3: Add Map Legend UI
- Create an empty GameObject called "MapSceneLegendUI"
- Add a
UIDocument component to it
- Add the
MapSceneLegendUI component to it
- Configure settings:
- UI Document: The UIDocument component on the same GameObject
- Start Visible: ✓ (if you want legend visible by default)
- Toggle Key: L (or your preferred key)
Step 4: Verify Integration
The system will automatically:
- Generate geographic features when the map loads
- Display settlement names from existing settlements
- Create and display the map legend
- Register click blocking with the ClickManager
Configuration Options
GeographicFeatureManager Settings
[Header("Feature Configuration")]
public bool autoGenerateFeatures = true; // Auto-generate on start
public bool regenerateOnMapChange = true; // Update when map changes
public bool debugMode = false; // Enable debug logging
MapLocationNameDisplay Settings
[Header("Display Settings")]
public bool showSettlementNames = true; // Show town/village names
public bool showForestNames = true; // Show forest names
public bool showLakeNames = true; // Show lake names
public bool showPlainNames = true; // Show plain names
public bool showMountainNames = true; // Show mountain names
public bool showRiverNames = true; // Show river names
[Header("Visual Settings")]
public Color settlementNameColor = Color.white; // Settlement name color
public Color forestNameColor = Color.green; // Forest name color
// ... (other color settings)
MapSceneLegendUI Settings
[Header("Settings")]
public bool startVisible = true; // Legend visible on start
public KeyCode toggleKey = KeyCode.L; // Key to toggle legend
How It Works
Feature Generation Process
- Map Analysis: System analyzes terrain types in the generated map
- Cluster Detection: Finds connected areas of the same terrain type
- Size Filtering: Only names areas above minimum size thresholds
- Name Assignment: Randomly assigns appropriate names from predefined lists
- Center Calculation: Determines optimal position for name display
Legend Integration
- Terrain Legend: Shows color codes for all terrain types
- Name Toggles: Individual switches for each location name type
- Real-time Updates: Immediately shows/hides names when toggled
- Click Blocking: Prevents map clicks when legend area is active
Click Management
- IClickBlocker: Legend implements the interface for click blocking
- ClickManager: Centralized system manages all UI click blocking
- Position Detection: Checks if clicks fall within legend bounds
- Map Protection: Prevents accidental map interaction
Testing
Verify Feature Generation
- Play the scene - Features should generate automatically
- Check Console - Enable debug mode to see generation messages
- Context Menu - Use "Regenerate Features" on GeographicFeatureManager
Test Legend Functionality
- Toggle Visibility - Press L (or configured key) to show/hide legend
- Name Toggles - Turn individual name types on/off
- Click Blocking - Verify map doesn't respond to clicks over legend
- Visual Feedback - Check that legend shows proper terrain colors
Debug Features
- Console Logs: Enable debug mode for detailed generation info
- Context Menus: Use component context menus for manual testing
- Feature Counts: Check console for number of features generated
Customization
Adding New Feature Types
- Update GeographicFeatureType enum in
GeographicFeature.cs
- Add name arrays in
GeographicFeatureGenerator.cs
- Create generation method following existing patterns
- Update display systems to handle the new type
Adjusting Generation Parameters
// In GeographicFeatureGenerator.cs
var forestClusters = FindConnectedAreas(mapData, TerrainType.Forest, 6); // Min 6 tiles
var lakeClusters = FindConnectedAreas(mapData, TerrainType.Lake, 4); // Min 4 tiles
var plainClusters = FindConnectedAreas(mapData, TerrainType.Plains, 25); // Min 25 tiles
Customizing Names
Edit the name arrays in GeographicFeatureGenerator.cs:
private static readonly string[] forestNames = {
"Whispering Woods", "Ancient Grove", "Your Custom Forest Name"
};
Troubleshooting
No Names Appearing
- Check Generation: Verify GeographicFeatureManager is in scene and active
- Check Display: Ensure MapLocationNameDisplay has correct UI references
- Check Map Size: Verify mapUISize settings match your actual UI
- Check Toggles: Make sure name types are enabled in the legend
Legend Not Showing
- Check UIDocument: Verify MapSceneLegendUI has UIDocument component
- Check Key Binding: Press L or configured toggle key
- Check Start Visible: Verify startVisible setting
- Check Console: Look for UI setup errors
Click Blocking Issues
- Check ClickManager: Verify ClickManager exists in scene
- Check Registration: Legend should auto-register with ClickManager
- Check Position: Verify legend bounds detection is working
Performance Issues
- Reduce Feature Count: Increase minimum cluster sizes
- Limit Name Updates: Avoid frequent RefreshLocationNames() calls
- Optimize Generation: Consider caching generated features
Integration with Existing Systems
MapMaker2 Integration
- Automatic Detection: System finds and uses existing MapMaker2
- MapData Access: Reads terrain and settlement data from MapMaker2
- Coordinate Conversion: Handles world-to-UI coordinate mapping
Settlement System Integration
- Existing Names: Preserves and displays existing settlement names
- Color Coding: Towns and villages have distinct visual styles
- Discovery System: Ready for integration with discovery mechanics
UI System Integration
- IClickBlocker: Follows established UI interaction patterns
- ClickManager: Integrates with existing click management system
- UI Toolkit: Built with Unity's modern UI system
Future Enhancements
- Discovery System: Show/hide names based on exploration
- Interactive Features: Click names for more information
- Dynamic Names: Generate contextual names based on surroundings
- Distance Filtering: Show different names at different zoom levels
- Custom Icons: Add visual markers for different feature types
- Save/Load: Persist discovered features between sessions
This system provides a solid foundation for map location naming while maintaining clean integration with your existing RPG systems.