SerialEventHexHighlight

Thalassicus

Bytes and Nibblers
Joined
Nov 9, 2005
Messages
11,057
Location
Texas
How do I properly use SerialEventHexHighlight? I tried this:

PHP:
local maxID = Map.GetNumPlots() - 1
for plotID = 0, maxID, 1 do
    local plot = Map.GetPlotByIndex(plotID)
    local hex = ToHexFromGrid(Vector2(plot:GetX(), plot:GetY()))
    local color = Color(plotID / maxID, 0.0, 0.0, 1.0)
    Events.SerialEventHexHighlight(hex, true, color);
end
In theory this should give each plot a red intensity corresponding to its plot ID. However, what actually happens is all the plots are black except the last one, which is red. I've seen it use decimal values, such as:

workerSuggestHighlightColor = Vector4( 0.0, 0.5, 1.0, 0.65 );
 
If you want a good example of how the game uses this, look at Bombardment.lua (select which hex to attack with a ranged unit), which draws a red border around the hex using the command
Code:
local redColor = Vector4( 0.7, 0, 0, 1 );
local highlightColor = Vector4( 0.7, 0.7, 0, 1 ); -- depending on the theme these may not actually be used (for example SplineBorder do not)

...

if thingThatCanActuallyFire:CanRangeStrikeAt(plotX,plotY) then
	Events.SerialEventHexHighlight( hexID, true, highlightColor, "FireRangeBorder" );
	Events.SerialEventHexHighlight( hexID, true, redColor, "ValidFireTargetBorder");
else
	Events.SerialEventHexHighlight( hexID, true, highlightColor, "FireRangeBorder" );
end

It looks like you're missing the fourth argument, which apparently selects the style to use for the overlay (with Bombardment using a red border around the hex). Not sure if this is hard-coded internally or what.
 
The fourth parameter is optional - if you specify it you get one of the pre-defined highlight styles.

Your issue is to do with integer maths - x/y is always 0 unless x=y when it is 1

Try

Code:
local color = Color((plotID / (maxID * 1.0)), 0.0, 0.0, 1.0)

or some other way of forcing the divisor to be a float
 
I did some more research and learned that this function only accepts specific combinations of color values; others just display black, regardless of if we pass it a decimal or not. It's strange to see something like this in a post-256-color era...
 
Custom styles can be created by changing the file highlights.xml
Spoiler :
Code:
<?xml version="1.0" encoding="utf-8"?>
<Highlights>
    <style name="" type="HexContour" width=".2" texture="hex_contour2.dds"/>
    <style name="SampleFilledHex" type="FilledHex" width ="1" color ="0,0,0,128"/>
    <style name="SampleStaticTexture" type ="StaticTexture" texture = "static_texture_highlight.dds"/>
    <style name="SampleHexModel" type="HexModel" model = "SelectedAniOneTurn.fxsxml" />
    <style name="EditorHexStyle1" type="HexContour" width=".15" texture="Solid_Contour.dds"/>
    <style name="EditorHexStyle2" type="HexContour" width=".08" texture="Solid_Contour.dds"/>
    <style name="EditorHexStyle3" type="HexContour" width=".03" texture="Solid_Contour.dds"/>
    <style name="TempBorder"		type="HexContour"	width=".2"	texture="hex_contour2.dds"/>
    <style name="GroupBorder"		type="SplineBorder"	width ="6"	texture="spline_border_contour2.dds"	color="255,128,0,200"/>
    <style name="ValidFireTargetBorder"	type="StaticTexture"	texture="static_texture_highlight.dds" />
    <style name="FireRangeBorder"	type="SplineBorder"	width ="6"	texture="spline_border_contour2.dds"	color="255,0,0,200"/>
    <style name="MovementRangeBorder"	type="SplineBorder"	width ="6"	texture="spline_border_contour2.dds"	color="100,185,245,200"/>
    <style name="AMRBorder"		type="StaticTexture"	texture="static_texture_highlight.dds" />
    <style name="GUHB"			type="HexContour"	width=".2"	texture="hex_contour2.dds"/>
</Highlights>
 
Possibly a daft question - but where is highlights.xml?
 
Which is fine until the one that ships with the game gets updated and I don't know where to get the original from to compare it to ...

I'll just unpack all the fpk files

Ta

W
 
Back
Top Bottom