189 lines
9.3 KiB
Plaintext
189 lines
9.3 KiB
Plaintext
@page "/admin/resistances"
|
|
@model Resistances.IndexModel
|
|
@{
|
|
ViewData["Title"] = "Damage Resistance Types";
|
|
}
|
|
|
|
<div class="space-y-6 max-w-4xl">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<h1 class="text-3xl font-bold text-white">Damage Resistance Types</h1>
|
|
<p class="text-gray-400 mt-1">Define resistance types for mobs, players, and items</p>
|
|
</div>
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(Model.Message))
|
|
{
|
|
<div class="p-4 rounded-lg @(Model.IsError ? "bg-red-900/50 border border-red-700 text-red-300" : "bg-green-900/50 border border-green-700 text-green-300")">
|
|
@Model.Message
|
|
</div>
|
|
}
|
|
|
|
<!-- Add New Type -->
|
|
<form method="post" asp-page-handler="Create" class="card p-6">
|
|
@Html.AntiForgeryToken()
|
|
<h2 class="text-lg font-semibold text-white mb-4">Add New Resistance Type</h2>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-6 gap-4 mb-4">
|
|
<div class="md:col-span-2">
|
|
<label class="label">Key (lowercase, no spaces)</label>
|
|
<input type="text" name="key" class="input" required pattern="[a-z0-9_]+" maxlength="32" placeholder="e.g., bleed"
|
|
oninput="this.value = this.value.toLowerCase().replace(/[^a-z0-9_]/g, '')" />
|
|
</div>
|
|
<div class="md:col-span-2">
|
|
<label class="label">Display Name</label>
|
|
<input type="text" name="displayName" class="input" required maxlength="64" placeholder="e.g., Bleeding" />
|
|
</div>
|
|
<div>
|
|
<label class="label">Color</label>
|
|
<div class="flex gap-2">
|
|
<input type="color" id="newColor" value="#888888" class="w-10 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer"
|
|
oninput="document.getElementById('newColorText').value=this.value" />
|
|
<input type="text" id="newColorText" name="color" value="#888888" class="input flex-1" maxlength="16" />
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="label">Order</label>
|
|
<input type="number" name="sortOrder" value="@(Model.Types.Count * 10)" class="input" min="0" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<label class="label">Description (optional)</label>
|
|
<input type="text" name="description" class="input" maxlength="256" placeholder="What this damage type represents..." />
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Add Resistance Type</button>
|
|
</form>
|
|
|
|
<!-- Existing Types -->
|
|
<div class="card overflow-hidden">
|
|
<table class="w-full">
|
|
<thead class="bg-gray-800">
|
|
<tr>
|
|
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Color</th>
|
|
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Key</th>
|
|
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Display Name</th>
|
|
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Description</th>
|
|
<th class="px-4 py-3 text-left text-xs font-medium text-gray-400 uppercase">Order</th>
|
|
<th class="px-4 py-3 text-right text-xs font-medium text-gray-400 uppercase">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-700">
|
|
@foreach (var type in Model.Types)
|
|
{
|
|
<tr class="hover:bg-gray-800/50">
|
|
<td class="px-4 py-3">
|
|
<div class="w-6 h-6 rounded" style="background-color: @type.Color"></div>
|
|
</td>
|
|
<td class="px-4 py-3">
|
|
<code class="text-indigo-400 bg-gray-800 px-2 py-0.5 rounded text-sm">@type.Key</code>
|
|
</td>
|
|
<td class="px-4 py-3 text-white">@type.DisplayName</td>
|
|
<td class="px-4 py-3 text-gray-400 text-sm">@(string.IsNullOrEmpty(type.Description) ? "-" : type.Description)</td>
|
|
<td class="px-4 py-3 text-gray-400">@type.SortOrder</td>
|
|
<td class="px-4 py-3 text-right">
|
|
<button type="button" onclick="editType(@type.Id, '@type.Key', '@type.DisplayName', '@type.Description', '@type.Color', @type.SortOrder)"
|
|
class="btn btn-secondary text-xs px-2 py-1">Edit</button>
|
|
<form method="post" asp-page-handler="Delete" class="inline">
|
|
@Html.AntiForgeryToken()
|
|
<input type="hidden" name="id" value="@type.Id" />
|
|
<button type="submit" class="btn bg-red-700 hover:bg-red-600 text-white text-xs px-2 py-1"
|
|
onclick="return confirm('Delete @type.DisplayName? This may break existing resistances using this type.')">Delete</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
}
|
|
|
|
@if (!Model.Types.Any())
|
|
{
|
|
<tr>
|
|
<td colspan="6" class="px-4 py-8 text-center text-gray-400">
|
|
No resistance types defined. Add the base types above.
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Seed Base Types -->
|
|
@if (!Model.Types.Any())
|
|
{
|
|
<form method="post" asp-page-handler="SeedDefaults" class="card p-6 text-center">
|
|
@Html.AntiForgeryToken()
|
|
<p class="text-gray-400 mb-4">Want to start with the default damage types?</p>
|
|
<button type="submit" class="btn btn-primary">Seed Default Resistance Types</button>
|
|
</form>
|
|
}
|
|
</div>
|
|
|
|
<!-- Edit Modal -->
|
|
<div id="editModal" class="fixed inset-0 bg-black/70 hidden items-center justify-center z-50">
|
|
<div class="bg-gray-800 rounded-xl p-6 max-w-md w-full mx-4 border border-gray-700">
|
|
<h3 class="text-lg font-semibold text-white mb-4">Edit Resistance Type</h3>
|
|
<form method="post" asp-page-handler="Update">
|
|
@Html.AntiForgeryToken()
|
|
<input type="hidden" name="id" id="editId" />
|
|
|
|
<div class="space-y-4">
|
|
<div>
|
|
<label class="label">Key (read-only)</label>
|
|
<input type="text" id="editKey" class="input bg-gray-900" readonly />
|
|
</div>
|
|
<div>
|
|
<label class="label">Display Name</label>
|
|
<input type="text" name="displayName" id="editDisplayName" class="input" required maxlength="64" />
|
|
</div>
|
|
<div>
|
|
<label class="label">Description</label>
|
|
<input type="text" name="description" id="editDescription" class="input" maxlength="256" />
|
|
</div>
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="label">Color</label>
|
|
<div class="flex gap-2">
|
|
<input type="color" id="editColorPicker" class="w-10 h-10 rounded border border-gray-700 bg-gray-800 cursor-pointer"
|
|
oninput="document.getElementById('editColor').value=this.value" />
|
|
<input type="text" name="color" id="editColor" class="input flex-1" maxlength="16" />
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<label class="label">Sort Order</label>
|
|
<input type="number" name="sortOrder" id="editSortOrder" class="input" min="0" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex justify-end gap-3 pt-4 mt-4 border-t border-gray-700">
|
|
<button type="button" onclick="closeEditModal()" class="btn btn-secondary">Cancel</button>
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
@section Scripts {
|
|
<script>
|
|
function editType(id, key, displayName, description, color, sortOrder) {
|
|
document.getElementById('editId').value = id;
|
|
document.getElementById('editKey').value = key;
|
|
document.getElementById('editDisplayName').value = displayName;
|
|
document.getElementById('editDescription').value = description || '';
|
|
document.getElementById('editColor').value = color;
|
|
document.getElementById('editColorPicker').value = color;
|
|
document.getElementById('editSortOrder').value = sortOrder;
|
|
|
|
document.getElementById('editModal').classList.remove('hidden');
|
|
document.getElementById('editModal').classList.add('flex');
|
|
}
|
|
|
|
function closeEditModal() {
|
|
document.getElementById('editModal').classList.add('hidden');
|
|
document.getElementById('editModal').classList.remove('flex');
|
|
}
|
|
|
|
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeEditModal(); });
|
|
</script>
|
|
}
|