world map tooltips

This commit is contained in:
Robert Janetzko 2022-05-07 18:46:37 +00:00
parent ae51542d2e
commit 3ee0264c22
2 changed files with 19 additions and 19 deletions

View File

@ -40,22 +40,14 @@ var AddMapLandmass = func(w *DfWorld, id int) template.HTML {
c2 := strings.Split(x.Coord2, ",")
x2, _ := strconv.Atoi(c2[0])
y2, _ := strconv.Atoi(c2[1])
return template.HTML(fmt.Sprintf(`<script>addRegion('%s', %d, %d, %d, %d, '#FFF')</script>`, x.Name_, x1, y1, x2, y2))
return template.HTML(fmt.Sprintf(`<script>addLandmass(%d, %d, %d, %d, %d, '#FFF')</script>`, x.Id_, x1, y1, x2, y2))
}
return ""
}
var AddMapRegion = func(w *DfWorld, id int) template.HTML {
if x, ok := w.Regions[id]; ok {
r := "<script>"
r += "var polygon = L.polygon(["
r += strings.Join(util.Map(x.Outline(), func(c Coord) string { return fmt.Sprintf(`coord(%d,%d)`, c.X, c.Y-1) }), ",")
r += "], { color : '#fff', opacity: 1, fillOpacity: 0, weight : 1 }).addTo(regionsLayer);\n"
r += "attachTooltip(polygon, '" + x.Name_ + "');\n"
r += "polygon.on('mouseover', function (e) { this.setStyle({weight: 10}); });\n"
r += "polygon.on('mouseout', function (e) { this.setStyle({ weight: 3}); });\n"
coords := strings.Join(util.Map(x.Outline(), func(c Coord) string { return fmt.Sprintf(`coord(%d,%d)`, c.X, c.Y-1) }), ",")
fillColor := "transparent"
switch x.Evilness {
case RegionEvilness_Evil:
@ -63,12 +55,7 @@ var AddMapRegion = func(w *DfWorld, id int) template.HTML {
case RegionEvilness_Good:
fillColor = "aqua"
}
if fillColor != "transparent" {
r += "var evilPolygon = L.polygon(polygon.getLatLngs(), { color: 'transparent', opacity: 1, fillColor: '" + fillColor + "', fillOpacity: .3, interactive: false });\n"
r += "evilPolygon.addTo(evilnessLayer);\n"
}
r += "</script>"
return template.HTML(r)
return template.HTML(fmt.Sprintf(`<script>addRegion(%d, [%s], '%s')</script>`, x.Id_, coords, fillColor))
}
return ""
}
@ -110,7 +97,7 @@ var AddMapWorldConstruction = func(w *DfWorld, id int) template.HTML {
color := util.If(x.Type_ == WorldConstructionType_Tunnel, "#000", "#fff")
line := x.Line()
if len(line) == 1 {
return template.HTML(fmt.Sprintf(`<script>addWc('%s', %d, %d, '%s')</script>`, x.Name_, line[0].X, line[0].Y, color))
return template.HTML(fmt.Sprintf(`<script>addWc(%d, %d, %d, '%s')</script>`, x.Id_, line[0].X, line[0].Y, color))
} else {
r := "<script>"
r += "var polyline = L.polyline(["

View File

@ -151,7 +151,7 @@ function addWc(id, y, x, color) {
attachTooltip(polygon, urlToolTip("worldconstruction", id));
}
function addRegion(name, y1, x1, y2, x2, color) {
function addLandmass(id, y1, x1, y2, x2, color) {
x1--; y2++;
var polygon = L.polygon(
[coord(y1, x1), coord(y2, x1), coord(y2, x2), coord(y1, x2)], {
@ -160,7 +160,7 @@ function addRegion(name, y1, x1, y2, x2, color) {
weight: 1
}).addTo(landmassesLayer);
attachTooltip(polygon, name);
attachTooltip(polygon, urlToolTip("landmass", id));
}
function addMountain(id, y, x, color) {
@ -210,3 +210,16 @@ function addBattle(name, y, x) {
maxx = Math.max(x, maxx);
maxy = Math.max(y, maxy);
}
function addRegion(id, coords, fillColor) {
var polygon = L.polygon(coords, { color: '#fff', opacity: 1, fillOpacity: 0, weight: 1 }).addTo(regionsLayer);
attachTooltip(polygon, urlToolTip('region', id));
polygon.on('mouseover', function (e) { this.setStyle({ weight: 10 }); });
polygon.on('mouseout', function (e) { this.setStyle({ weight: 3 }); });
if (fillColor != "transparent") {
var evilPolygon = L.polygon(polygon.getLatLngs(), { color: 'transparent', opacity: 1, fillColor: fillColor, fillOpacity: .3, interactive: false });
evilPolygon.addTo(evilnessLayer);
}
}