0

Add customizable overlay colors, works for base overlay, spawn, and slime.

I left minerals as it is so you have to still define the minerals option to get that to work.
This commit is contained in:
Richard Pastrick
2012-06-08 12:07:21 -07:00
parent a432382bc1
commit 28099deaf6
5 changed files with 56 additions and 12 deletions

View File

@@ -17,28 +17,59 @@
#include "overlay.h"
static OverlayColor default_color[] = { 200, 200, 255, 155 };
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
*r = 200;
*g = 200;
*b = 255;
*a = 155;
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay *)data;
*r = self->color->r;
*g = self->color->g;
*b = self->color->b;
*a = self->color->a;
}
static int
overlay_start(void *data, RenderState *state, PyObject *support) {
PyObject *opt = NULL;
OverlayColor *color = NULL;
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
self->facemask_top = PyObject_GetAttrString(support, "facemask_top");
self->white_color = PyObject_GetAttrString(support, "whitecolor");
self->get_color = get_color;
color = self->color = calloc(1, sizeof(OverlayColor));
if (color == NULL) {
return 1;
}
if(!render_mode_parse_option(support, "overlay_color", "bbbb", &(color->r), &(color->g), &(color->b), &(color->a))) {
if(PyErr_Occurred())
PyErr_Clear();
free(color);
self->color = default_color;
// Check if it is None, if it is, continue and use the default, if it isn't, return an error
if(render_mode_parse_option(support, "overlay_color", "O", &(opt))) {
// If it is an object, check to see if it is None, if it is, use the default.
if(opt && opt != Py_None) {
return 1;
}
} else {
return 1;
}
}
return 0;
}
static void
overlay_finish(void *data, RenderState *state) {
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
if (self->color && self->color != default_color) {
free(self->color);
}
Py_DECREF(self->facemask_top);
Py_DECREF(self->white_color);