# Settlement Interaction Debugging and Setup Guide

## Problem
Settlement interaction UI shows but E key doesn't work to enter settlements.

## Quick Diagnosis

### Step 1: Add the Debugger
1. Add `SettlementInteractionDebugger.cs` component to any GameObject in MapScene2
2. Run the scene and check the console output
3. The debugger will show exactly what's missing

### Step 2: Common Issues and Solutions

#### Issue A: No SettlementInteractionManager in Scene
**Symptoms**: Debugger shows "❌ SettlementInteractionManager NOT FOUND!"
**Solution**:
1. Create empty GameObject in MapScene2 named "SettlementInteractionManager"
2. Add `SettlementInteractionManager` component to it
3. Configure settings:
   - Team Marker: Will auto-find "TeamMarker"
   - Interaction Distance: 2.0
   - Enter Settlement Key: E
   - Town Scene Name: "TownSceen"
   - Enable Debug Logs: true

#### Issue B: Missing UI Setup
**Symptoms**: Logic works but no UI shows
**Solution**:
1. Create GameObject named "SettlementInteractionUI" 
2. Add `UIDocument` component
3. Add `SettlementInteractionUI` component
4. Set UI Document asset to `SettlementInteractionUI.uxml`
5. Make sure UXML file exists in `Assets/Resources/UI/MapScene/`

#### Issue C: TeamMarker Not Found
**Symptoms**: Debugger shows "❌ TeamMarker GameObject not found!"
**Solution**:
1. Make sure GameObject named "TeamMarker" exists in scene
2. Or manually assign teamMarker reference in SettlementInteractionManager

#### Issue D: MapData Not Available
**Symptoms**: "Settlements count: 0" or MapData null
**Solution**:
1. Ensure MapMaker2 component exists in scene
2. Ensure map has been generated with settlements
3. Check that MapData.GetAllSettlements() returns settlements

#### Issue E: Input System Issues
**Symptoms**: Manual entry works but E key doesn't
**Solution**:
1. Check if project uses new Input System (Package Manager)
2. If using new Input System, might need to update input handling
3. Test with debugger's "Test Input Detection" to see if keys register

### Step 3: Testing Process

1. **Add Debugger**: Put SettlementInteractionDebugger on any GameObject
2. **Run Scene**: Check console for component diagnosis
3. **Move TeamMarker**: Move near settlements and watch debug output
4. **Test Keys**: Press F1 to test detection, F2 to test manual entry
5. **Check Console**: Look for debug messages when moving near settlements

### Step 4: Verification

When working correctly, you should see:
1. ✅ All components found in diagnosis
2. Debug messages when moving TeamMarker near settlements
3. UI prompt appears/disappears based on proximity
4. E key successfully loads town scene
5. Settlement context properly configured

## Quick Fix Commands

### Force Enable All Debug Logging
```csharp
// In Unity Console or attached to a button
var manager = FindFirstObjectByType<SettlementInteractionManager>();
if (manager != null) manager.enableDebugLogs = true;
```

### Manual Settlement Entry Test
```csharp
// Test if the logic works without input
var manager = FindFirstObjectByType<SettlementInteractionManager>();
if (manager != null) manager.TestEnterCurrentSettlement();
```

### Check Current Settlement Detection
```csharp
// See if any settlement is currently detected
var manager = FindFirstObjectByType<SettlementInteractionManager>();
var settlement = manager?.GetCurrentNearbySettlement();
Debug.Log($"Current settlement: {settlement?.name ?? "None"}");
```

## Debug UI Overlay

The SettlementInteractionDebugger provides an on-screen debug panel that shows:
- Current settlement detection status
- TeamMarker position
- Quick test buttons
- Real-time component status

Toggle with `enableDebugOverlay = true` in the debugger component.

## Expected Debug Output

When working correctly, moving TeamMarker near a settlement should show:
```
[SettlementInteraction] Near settlement: Riverside Town (Town)
[SettlementInteraction] SettlementContext configured: Riverside Town (Town) - Harbor: true
[SettlementInteraction] Loading town scene: TownSceen
```

When the E key is pressed near a settlement:
```
[SettlementInteraction] Entering settlement: Riverside Town (Town)
```
