collection maps

This commit is contained in:
Robert Janetzko 2022-05-11 07:45:17 +00:00
parent f13fa945e6
commit efd75d9102
19 changed files with 112 additions and 52 deletions

View File

@ -127,6 +127,45 @@ var AddMapRiver = func(w *DfWorld, id int) template.HTML {
return ""
}
func AddMapCollection(w *DfWorld, id int) template.HTML {
if x, ok := w.HistoricalEventCollections[id]; ok {
r := ""
switch d := x.Details.(type) {
case *HistoricalEventCollectionBeastAttack:
r += string(AddMapSite(w, d.SiteId, false))
case *HistoricalEventCollectionDuel:
c1 := strings.Split(d.Coords, ",")
x, _ := strconv.Atoi(c1[0])
y, _ := strconv.Atoi(c1[1])
r += fmt.Sprintf(`<script>addBattle(%d, %d, %d)</script>`, id, x, y)
case *HistoricalEventCollectionSiteConquered:
r += string(AddMapSite(w, d.SiteId, false))
case *HistoricalEventCollectionBattle:
if d.SiteId != -1 {
r += string(AddMapSite(w, d.SiteId, false))
}
for _, s := range d.AttackingSquadSite {
r += string(AddMapSite(w, s, true))
}
for _, s := range d.DefendingSquadSite {
r += string(AddMapSite(w, s, true))
}
c1 := strings.Split(d.Coords, ",")
x, _ := strconv.Atoi(c1[0])
y, _ := strconv.Atoi(c1[1])
r += fmt.Sprintf(`<script>addBattle(%d, %d, %d)</script>`, id, x, y)
case *HistoricalEventCollectionWar:
for _, y := range x.Eventcol {
r += string(AddMapCollection(w, y))
}
}
return template.HTML(r)
}
return ""
}
var AndList = func(s []string) template.HTML { return template.HTML(andList(s)) }
func andList(list []string) string {

View File

@ -69,6 +69,7 @@ func (srv *DfServer) LoadTemplates() {
"addMountain": func(id int, color bool) template.HTML { return model.AddMapMountain(srv.context.world, id, color) },
"addWorldConstruction": func(id int) template.HTML { return model.AddMapWorldConstruction(srv.context.world, id) },
"addRiver": func(id int) template.HTML { return model.AddMapRiver(srv.context.world, id) },
"addCollection": func(id int) template.HTML { return model.AddMapCollection(srv.context.world, id) },
"events": func(obj any) *model.EventList {
return model.NewEventList(srv.context.world, obj)

View File

@ -28,6 +28,12 @@ a {
margin-bottom: 16px;
}
.page-tabs .tab-content {
overflow-y: auto;
max-height: 300px;
margin-bottom: 16px;
}
.popover {
max-width: fit-content;
}

View File

@ -189,7 +189,7 @@ function coord(y, x) {
return [x, y];
}
function addBattle(name, y, x) {
function addBattle(id, y, x) {
x = worldWidth - x - 1;
var polygon = L.polygon(
[[x + 0.5, y + battleOffset],
@ -201,7 +201,7 @@ function addBattle(name, y, x) {
weight: 3
}).addTo(map);
attachTooltip(polygon, name);
attachTooltip(polygon, urlToolTip("collection", id));
minx = Math.min(x, minx);
miny = Math.min(y, miny);

View File

@ -9,16 +9,16 @@
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{ $active := " active"}}
{{- range $t, $v := .DanceForms }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{
len $v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{
len $v }})</a>
{{ $active = ""}}{{- end}}
{{- range $t, $v := .MusicalForms }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</a>
{{ $active = ""}}{{- end}}
{{- range $t, $v := .PoeticForms }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</a>
{{ $active = ""}}{{- end}}
</div>
</nav>

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -4,6 +4,14 @@
{{define "content"}}
{{ if world.MapReady }}
<div class="object-map">
<div id="map" style="width: 300px; height: 300px"></div>
</div>
{{initMap}}
{{ addCollection .Id }}
{{- end }}
<h3>{{ html (capitalize (string (collection .Id))) }}</h3>
{{- if eq .Type "occasion" }}{{- with getOccasion .Details.CivId .Details.OccasionId }}{{- if ne .Event -1 }}

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -32,22 +32,19 @@
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{ $active := " active"}}
{{- if gt (len .Leaders) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-leaders" type="button"
role="tab">Leaders</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-leaders" type="button" role="tab">Leaders</a>
{{ $active = ""}}{{- end}}
{{- if gt (len .Sites) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-sites" type="button" role="tab">Sites</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-sites" type="button" role="tab">Sites</a>
{{ $active = ""}}{{- end}}
{{- if gt (len .HistfigId) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-members" type="button"
role="tab">Members</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-members" type="button" role="tab">Members</a>
{{ $active = ""}}{{- end}}
{{- if gt (len .Child) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-children" type="button"
role="tab">Groups</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-children" type="button" role="tab">Groups</a>
{{ $active = ""}}{{- end}}
{{- if gt (len .Wars) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-wars" type="button" role="tab">Wars</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-wars" type="button" role="tab">Wars</a>
{{ $active = ""}}{{- end}}
</div>
</nav>

View File

@ -9,20 +9,20 @@
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{ $active := " active"}}
{{- range $t, $v := .Regions }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{
len $v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{
len $v }})</a>
{{ $active = ""}}{{- end}}
{{- range $t, $v := .Landmasses }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</a>
{{ $active = ""}}{{- end}}
{{- range $t, $v := .MountainPeaks }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</a>
{{ $active = ""}}{{- end}}
{{- range $t, $v := .Rivers }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button" role="tab">{{$t}} ({{ len
$v }})</a>
{{ $active = ""}}{{- end}}
</div>
</nav>

View File

@ -89,12 +89,13 @@
var hash = document.location.hash;
if (hash && hash.startsWith("#nav-")) {
var hashPieces = hash.split('?');
activeTab = $('.nav-link[data-bs-target="' + hashPieces[0] + '"]');
console.log(hashPieces[0], activeTab);
activeTab && activeTab.click()
var someTabTriggerEl = document.querySelector('.nav-link[data-bs-target="' + hashPieces[0] + '"]')
var tab = new bootstrap.Tab(someTabTriggerEl)
tab.show()
}
$('.nav-tabs button').on('click', function (e) {
$('.nav-tabs button,.nav-tabs a').on('click', function (e) {
window.location.hash = $(this).data("bs-target")
});

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -8,19 +8,21 @@
<h3>{{ title .Name }}</h3>
<p>{{ .Type_ }}</p>
{{ $history := history .Id }}
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{ $active := " active"}}
{{- if gt (len .Structures) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-structures" type="button"
role="tab">Structures</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-structures" type="button" role="tab">Structures</a>
{{ $active = ""}}{{- end}}
{{- if gt (len .SiteProperties) 0 }}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-site-properties" type="button"
role="tab">Properties</button>
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-site-properties" type="button"
role="tab">Properties</a>
{{ $active = ""}}{{- end}}
{{- if gt (len $history) 0 }}
<a class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-history" type="button" role="tab">History</a>
{{ $active = ""}}{{- end}}
<button class="nav-link{{$active}}" data-bs-toggle="tab" data-bs-target="#nav-history" type="button"
role="tab">History</button>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
@ -58,9 +60,12 @@
</table>
</div>
{{ $active = ""}}{{- end}}
<div class="tab-pane{{$active}}" id="nav-history" role="tabpanel">
{{ template "events.html" events (history .Id) }}
{{ $history := history .Id }}
{{- if gt (len $history) 0 }}
<div class="tab-pane{{$active}} pt-3" id="nav-history" role="tabpanel">
{{ template "events.html" events $history }}
</div>
{{ $active = ""}}{{- end}}
</div>
</div>
{{ if world.MapReady }}

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -10,6 +10,9 @@
</div>
{{initMap}}
{{ addWorldConstruction .Id }}
{{- range .Parts }}
{{ addWorldConstruction . }}
{{- end }}
{{- end }}
<h3>{{ title .Name }}</h3>

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>

View File

@ -8,8 +8,8 @@
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</button>
<a class="nav-link{{ ifFirst $ $t " active" }}" data-bs-toggle="tab" data-bs-target="#nav-{{kebab $t}}" type="button"
role="tab">{{$t}} ({{ len $v }})</a>
{{- end}}
</div>
</nav>