mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-01 05:27:39 +01:00
Added HighlightTileRenderer (thanks in part to rockNme2349)
This commit is contained in:
parent
eb276dd59d
commit
d53b3bc340
@ -43,6 +43,14 @@ worlds:
|
|||||||
prefix: t
|
prefix: t
|
||||||
maximumheight: 127
|
maximumheight: 127
|
||||||
colorscheme: default
|
colorscheme: default
|
||||||
|
#- class: org.dynmap.kzedmap.HighlightTileRenderer
|
||||||
|
# prefix: ht
|
||||||
|
# maximumheight: 127
|
||||||
|
# colorscheme: default
|
||||||
|
# highlight: # For highlighting multiple block-types.
|
||||||
|
# - 56 # Highlight diamond-ore
|
||||||
|
# - 66 # Highlight minecart track
|
||||||
|
# highlight: 56 # For highlighting a single block-type.
|
||||||
- class: org.dynmap.kzedmap.CaveTileRenderer
|
- class: org.dynmap.kzedmap.CaveTileRenderer
|
||||||
prefix: ct
|
prefix: ct
|
||||||
maximumheight: 127
|
maximumheight: 127
|
||||||
@ -101,6 +109,10 @@ web:
|
|||||||
title: Surface
|
title: Surface
|
||||||
name: surface
|
name: surface
|
||||||
prefix: t
|
prefix: t
|
||||||
|
#- type: KzedMapType
|
||||||
|
# title: Highlighted Map
|
||||||
|
# name: highlight
|
||||||
|
# prefix: ht
|
||||||
- type: KzedMapType
|
- type: KzedMapType
|
||||||
title: Cave
|
title: Cave
|
||||||
name: cave
|
name: cave
|
||||||
|
@ -5,6 +5,7 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.awt.image.WritableRaster;
|
import java.awt.image.WritableRaster;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
@ -15,9 +16,12 @@ import org.dynmap.debug.Debug;
|
|||||||
|
|
||||||
public class DefaultTileRenderer implements MapTileRenderer {
|
public class DefaultTileRenderer implements MapTileRenderer {
|
||||||
protected static final Color translucent = new Color(0, 0, 0, 0);
|
protected static final Color translucent = new Color(0, 0, 0, 0);
|
||||||
private String name;
|
protected String name;
|
||||||
protected int maximumHeight = 127;
|
protected int maximumHeight = 127;
|
||||||
private ColorScheme colorScheme;
|
protected ColorScheme colorScheme;
|
||||||
|
|
||||||
|
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
|
||||||
|
protected Color highlightColor = new Color(255, 0, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -135,6 +139,9 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||||||
seq = (seq + 1) & 3;
|
seq = (seq + 1) & 3;
|
||||||
|
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
|
if (highlightBlocks.contains(id)) {
|
||||||
|
return highlightColor;
|
||||||
|
}
|
||||||
Color[] colors = colorScheme.colors.get(id);
|
Color[] colors = colorScheme.colors.get(id);
|
||||||
if (colors != null) {
|
if (colors != null) {
|
||||||
Color c = colors[seq];
|
Color c = colors[seq];
|
||||||
|
93
src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java
Normal file
93
src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package org.dynmap.kzedmap;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
public class HighlightTileRenderer extends DefaultTileRenderer {
|
||||||
|
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
|
||||||
|
|
||||||
|
public HighlightTileRenderer(Map<String, Object> configuration) {
|
||||||
|
super(configuration);
|
||||||
|
Object highlightObj = configuration.get("highlight");
|
||||||
|
if (highlightObj instanceof List<?>) {
|
||||||
|
for(Object o : (List<?>)highlightObj) {
|
||||||
|
highlightBlocks.add((Integer)o);
|
||||||
|
}
|
||||||
|
} else if (highlightObj instanceof Integer) {
|
||||||
|
highlightBlocks.add((Integer)highlightObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Color scan(World world, int x, int y, int z, int seq) {
|
||||||
|
Color result = translucent;
|
||||||
|
for (;;) {
|
||||||
|
if (y < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = world.getBlockTypeIdAt(x, y, z);
|
||||||
|
|
||||||
|
switch (seq) {
|
||||||
|
case 0:
|
||||||
|
x--;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
y--;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
z++;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
y--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
seq = (seq + 1) & 3;
|
||||||
|
|
||||||
|
if (id != 0) {
|
||||||
|
Color[] colors = colorScheme.colors.get(id);
|
||||||
|
if (colors != null) {
|
||||||
|
Color c = colors[seq];
|
||||||
|
|
||||||
|
if (highlightBlocks.contains(id)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.getAlpha() > 0) {
|
||||||
|
|
||||||
|
/* we found something that isn't transparent! */
|
||||||
|
/*
|
||||||
|
* if (c.getAlpha() == 255) { return c; }
|
||||||
|
*/
|
||||||
|
/* this block is transparent, so recurse */
|
||||||
|
|
||||||
|
// No need to blend if result is opaque.
|
||||||
|
if (result.getAlpha() < 255) {
|
||||||
|
Color bg = c;
|
||||||
|
c = result;
|
||||||
|
|
||||||
|
int cr = c.getRed();
|
||||||
|
int cg = c.getGreen();
|
||||||
|
int cb = c.getBlue();
|
||||||
|
int ca = c.getAlpha();
|
||||||
|
cr *= ca;
|
||||||
|
cg *= ca;
|
||||||
|
cb *= ca;
|
||||||
|
int na = 255 - ca;
|
||||||
|
|
||||||
|
result = new Color((bg.getRed() * na + cr) >> 8, (bg.getGreen() * na + cg) >> 8, (bg.getBlue() * na + cb) >> 8,
|
||||||
|
Math.min(255, bg.getAlpha()+c.getAlpha()) // Not really correct, but gets the job done without recursion while still looking ok.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -282,8 +282,11 @@ DynMap.prototype = {
|
|||||||
$.each(me.options.components, function(index, configuration) {
|
$.each(me.options.components, function(index, configuration) {
|
||||||
loadjs('js/' + configuration.type + '.js', function() {
|
loadjs('js/' + configuration.type + '.js', function() {
|
||||||
var componentconstructor = componentconstructors[configuration.type];
|
var componentconstructor = componentconstructors[configuration.type];
|
||||||
me.components.push(new componentconstructor(me, configuration));
|
if (componentconstructor) {
|
||||||
|
me.components.push(new componentconstructor(me, configuration));
|
||||||
|
} else {
|
||||||
|
// Could not load component. We'll ignore this for the moment.
|
||||||
|
}
|
||||||
componentstoload--;
|
componentstoload--;
|
||||||
if (componentstoload == 0) {
|
if (componentstoload == 0) {
|
||||||
// Actually start updating once all components are loaded.
|
// Actually start updating once all components are loaded.
|
||||||
|
Loading…
Reference in New Issue
Block a user