Allow modifying selected block outline appearance

I've added three new options which can be added into options.txt:

`selected-block-outline-color`
`selected-block-outline-opacity`
`selected-block-outline-scale`
This commit is contained in:
Derek 2023-11-21 16:19:34 +10:00
parent c82364f886
commit 911df3d1ca
2 changed files with 31 additions and 12 deletions

View file

@ -78,6 +78,10 @@ Copyright 2014-2023 ClassiCube | Licensed under BSD-3
#define OPT_DPI_SCALING "win-dpi-scaling"
#define OPT_GAME_VERSION "game-version"
#define OPT_SELECTED_BLOCK_OUTLINE_COLOR "selected-block-outline-color"
#define OPT_SELECTED_BLOCK_OUTLINE_OPACITY "selected-block-outline-opacity"
#define OPT_SELECTED_BLOCK_OUTLINE_SCALE "selected-block-outline-scale"
#define LOPT_SESSION "launcher-session"
#define LOPT_USERNAME "launcher-cc-username"
#define LOPT_PASSWORD "launcher-cc-password"
@ -112,15 +116,15 @@ void Options_PauseSaving(void);
/* Sets value to value of option directly in Options.Buffer if found, String_Empty if not. */
/* Returns whether the option was actually found. */
STRING_REF cc_bool Options_UNSAFE_Get(const char* keyRaw, cc_string* value);
/* Returns value of given option, or defalt value if not found. */
/* Returns value of given option, or default value if not found. */
CC_API void Options_Get(const char* key, cc_string* value, const char* defValue);
/* Returns value of given option as an integer, or defalt value if could not be converted. */
/* Returns value of given option as an integer, or default value if could not be converted. */
CC_API int Options_GetInt(const char* key, int min, int max, int defValue);
/* Returns value of given option as a bool, or defalt value if could not be converted. */
/* Returns value of given option as a bool, or default value if could not be converted. */
CC_API cc_bool Options_GetBool(const char* key, cc_bool defValue);
/* Returns value of given option as a float, or defalt value if could not be converted. */
/* Returns value of given option as a float, or default value if could not be converted. */
CC_API float Options_GetFloat(const char* key, float min, float max, float defValue);
/* Returns value of given option as an integer, or defalt value if could not be converted. */
/* Returns value of given option as an integer, or default value if could not be converted. */
/* NOTE: Conversion is done by going through all elements of names, returning index of a match. */
CC_API int Options_GetEnum(const char* key, int defValue, const char* const* names, int namesCount);
/* Attempts to parse the value of the given option into an RGB (3 byte) colour. */

View file

@ -6,6 +6,7 @@
#include "Picking.h"
#include "Funcs.h"
#include "Camera.h"
#include "Options.h"
static GfxResourceID pickedPos_vb;
#define PICKEDPOS_NUM_VERTICES (16 * 6)
@ -28,13 +29,17 @@ x,3,0, x,2,0, x,2,3, x,3,3,
0,0,z, 0,1,z, 3,1,z, 3,0,z,\
0,3,z, 0,2,z, 3,2,z, 3,3,z,
float scale;
int opacity;
PackedCol col;
static void BuildMesh(struct RayTracer* selected) {
static const cc_uint8 indices[288] = {
PickedPos_Y(0) PickedPos_Y(3) /* YMin, YMax */
PickedPos_X(0) PickedPos_X(3) /* XMin, XMax */
PickedPos_Z(0) PickedPos_Z(3) /* ZMin, ZMax */
};
PackedCol col = PackedCol_Make(0, 0, 0, 102);
struct VertexColoured* ptr;
int i;
Vec3 delta;
@ -48,12 +53,12 @@ static void BuildMesh(struct RayTracer* selected) {
if (dist < 4.0f * 4.0f) offset = 0.00625f;
if (dist < 2.0f * 2.0f) offset = 0.00500f;
size = 1.0f/16.0f;
if (dist < 32.0f * 32.0f) size = 1.0f/32.0f;
if (dist < 16.0f * 16.0f) size = 1.0f/64.0f;
if (dist < 8.0f * 8.0f) size = 1.0f/96.0f;
if (dist < 4.0f * 4.0f) size = 1.0f/128.0f;
if (dist < 2.0f * 2.0f) size = 1.0f/192.0f;
size = scale / 16.0f;
if (dist < 32.0f * 32.0f) size = scale / 32.0f;
if (dist < 16.0f * 16.0f) size = scale / 64.0f;
if (dist < 8.0f * 8.0f) size = scale / 96.0f;
if (dist < 4.0f * 4.0f) size = scale / 128.0f;
if (dist < 2.0f * 2.0f) size = scale / 192.0f;
/* How a face is laid out:
#--#-------#--#<== OUTER_MAX (3)
@ -113,6 +118,16 @@ static void OnContextLost(void* obj) {
static void OnInit(void) {
Event_Register_(&GfxEvents.ContextLost, NULL, OnContextLost);
scale = Options_GetFloat(OPT_SELECTED_BLOCK_OUTLINE_SCALE, 1, 16, 1);
opacity = Options_GetInt(OPT_SELECTED_BLOCK_OUTLINE_OPACITY, 0, 255, 102);
col = PackedCol_Make(0, 0, 0, opacity); // Black by default
cc_uint8 rgb[3];
if (Options_GetColor(OPT_SELECTED_BLOCK_OUTLINE_COLOR, rgb)) {
col = PackedCol_Make(rgb[0], rgb[1], rgb[2], opacity);
}
}
static void OnFree(void) { OnContextLost(NULL); }