Updated hex info UI, added UI objects for color pick UI

main
noah metz 2024-11-11 14:02:57 -07:00
parent b3cef0cf18
commit 3ab7ed46dc
3 changed files with 220 additions and 24 deletions

@ -19,6 +19,8 @@
extern vec3 hex_vertices[];
extern vec3 hex_starts[];
extern vec3 hex_directions[];
extern int32_t hex_starts_qr[][2];
extern int32_t hex_directions_qr[][2];
extern int hex_indices[];
typedef struct GPUHexStruct {

@ -23,6 +23,24 @@ vec3 hex_starts[] = {
{ HEX_X, 0, HEX_Z/2},
};
int32_t hex_starts_qr[][2] = {
{ 0, -1},
{-1, 0},
{-1, 1},
{ 0, 1},
{ 1, 0},
{ 1, -1},
};
int32_t hex_directions_qr[][2] = {
{-1, 1},
{ 0, 1},
{ 1, 0},
{ 1, -1},
{ 0, -1},
{-1, 0},
};
vec3 hex_directions[] = {
{-HEX_X, 0, -HEX_Z/2},
{ 0, 0, -HEX_Z},

@ -96,8 +96,136 @@ uint32_t add_hex_region(ClientContext* context) {
return i;
}
VkResult hex_info_ui(ClientContext* context) {
VkResult color_ui(ClientContext* context) {
GPUString strings[] = {
{
.pos = {-2, 168},
.color = {1, 1, 1, 1},
.size = 32,
.offset = 0,
.length = 9,
.font = 0,
},
};
GPUDrawable drawables[] = {
{
.pos = {0, 0},
.size = {178, 168},
.color = {0.4, 0.4, 0.4, 0.4},
},
{
.pos = {2, 2},
.size = {130, 130},
.color = {1, 1, 1, 1},
.id = 0x01,
},
{
.pos = {36, 136},
.size = {140, 30},
.color = {0, 0, 1, 0.4},
.id = 0x02,
},
{
.pos = {134, 2},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x03,
},
{
.pos = {156, 2},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x04,
},
{
.pos = {134, 24},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x05,
},
{
.pos = {156, 24},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x06,
},
{
.pos = {134, 46},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x07,
},
{
.pos = {156, 46},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x08,
},
{
.pos = {134, 68},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x09,
},
{
.pos = {156, 68},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x0A,
},
{
.pos = {134, 90},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x0B,
},
{
.pos = {156, 90},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x0C,
},
{
.pos = {134, 112},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x0D,
},
{
.pos = {156, 112},
.size = {20, 20},
.color = {1, 1, 1, 1},
.id = 0x0E,
},
};
uint32_t codes[9];
VkResult result;
VK_RESULT(map_string("#FFFFFFFF", codes, 0, 0, context->ui));
LayerInput layer = {
.strings = strings,
.num_strings = sizeof(strings)/sizeof(GPUString),
.codes = codes,
.num_codes = sizeof(codes)/sizeof(uint32_t),
.drawables = drawables,
.num_drawables = sizeof(drawables)/sizeof(GPUDrawable),
};
ContainerInput container = {
.layers = &layer,
.layer_count = 1,
.anchor = ANCHOR_BOTTOM_LEFT,
.id = 0x03,
.offset = {0, 0},
.size = {178, 168},
};
return create_container(&container, context->render, context->ui);
}
VkResult hex_info_ui(ClientContext* context) {
GPUString strings[] = {
{
.pos = {0, 33},
@ -108,7 +236,7 @@ VkResult hex_info_ui(ClientContext* context) {
.font = 0,
},
{
.pos = {0, 73},
.pos = {2, 50},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 20,
@ -116,7 +244,7 @@ VkResult hex_info_ui(ClientContext* context) {
.font = 0,
},
{
.pos = {0, 93},
.pos = {2, 73},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 40,
@ -124,7 +252,7 @@ VkResult hex_info_ui(ClientContext* context) {
.font = 0,
},
{
.pos = {0, 113},
.pos = {2, 93},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 60,
@ -132,15 +260,15 @@ VkResult hex_info_ui(ClientContext* context) {
.font = 0,
},
{
.pos = {0, 133},
.pos = {2, 113},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 80,
.length = 0,
.font = 0,
},
{
.pos = {0, 153},
{
.pos = {2, 133},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 100,
@ -148,20 +276,28 @@ VkResult hex_info_ui(ClientContext* context) {
.font = 0,
},
{
.pos = {0, 173},
.pos = {2, 153},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 120,
.length = 0,
.font = 0,
},
{
.pos = {2, 173},
.color = {1, 1, 1, 1},
.size = 16,
.offset = 140,
.length = 0,
.font = 0,
},
};
GPUDrawable drawables[] = {
{
.pos = {0, 0},
.size = {225, 200},
.size = {150, 175},
.color = {0.4, 0.4, 0.4, 0.4},
},
};
@ -176,8 +312,8 @@ VkResult hex_info_ui(ClientContext* context) {
};
ContainerInput container = {
.id = 0x01,
.size = {225, 200},
.id = 0x02,
.size = {150, 175},
.offset = {0, 0},
.anchor = ANCHOR_BOTTOM_RIGHT,
.layers = &layer,
@ -309,15 +445,14 @@ VkResult update_hex_info_ui(ClientContext* context) {
VkResult result;
HexRegion* region = context->hex->regions[context->hex->data.clicked_region];
snprintf(temp,
sizeof(temp),
"Hex %d-%d.%d",
context->hex->data.clicked_region,
context->hex->data.clicked_hex,
context->hex->data.clicked_vertex);
VK_RESULT(update_ui_string(temp, 1, 0, 0, context->ui, context->render));
if(region == NULL) {
snprintf(
temp,
sizeof(temp),
"");
VK_RESULT(update_ui_string(temp, 1, 0, 0, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
@ -353,49 +488,89 @@ VkResult update_hex_info_ui(ClientContext* context) {
sizeof(temp),
"");
VK_RESULT(update_ui_string(temp, 1, 0, 6, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"");
VK_RESULT(update_ui_string(temp, 1, 0, 7, context->ui, context->render));
} else {
GPUHex* hex = &region->data.hexes[context->hex->data.clicked_hex];
snprintf(temp,
sizeof(temp),
"%d-%d",
context->hex->data.clicked_region,
context->hex->data.clicked_hex);
VK_RESULT(update_ui_string(temp, 1, 0, 0, context->ui, context->render));
int32_t hex_index = context->hex->data.clicked_hex;
float radius = 0;
float ring = 0;
int side = 0;
if(hex_index != 0) {
radius = floor(0.5 + sqrt(12*hex_index-3)/6);
ring = hex_index - (3*radius*radius - 3*radius + 1);
side = floor(ring/radius);
}
int32_t hex_q = hex_starts_qr[side][0]*radius + hex_directions_qr[side][0]*(ring-(radius*side));
int32_t hex_r = hex_starts_qr[side][1]*radius + hex_directions_qr[side][1]*(ring-(radius*side));
int32_t world_q = hex_q + region->data.q*(REGION_SIZE*2 + 1) + region->data.r*REGION_SIZE;
int32_t world_r = hex_r + region->data.q*(REGION_SIZE + 0.5) + region->data.r*(REGION_SIZE*2+1);
snprintf(
temp,
sizeof(temp),
"%d, %d, %d, %d",
world_q,
world_r,
region->data.y,
context->hex->data.clicked_vertex);
VK_RESULT(update_ui_string(temp, 1, 0, 1, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"%02.02f %02.02f %02.02f",
hex->height[0], hex->height[1], hex->height[2]);
VK_RESULT(update_ui_string(temp, 1, 0, 1, context->ui, context->render));
VK_RESULT(update_ui_string(temp, 1, 0, 2, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"%02.02f %02.02f %02.02f",
hex->height[3], hex->height[4], hex->height[5]);
VK_RESULT(update_ui_string(temp, 1, 0, 2, context->ui, context->render));
VK_RESULT(update_ui_string(temp, 1, 0, 3, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"%08X",
hex->color[0]);
VK_RESULT(update_ui_string(temp, 1, 0, 3, context->ui, context->render));
VK_RESULT(update_ui_string(temp, 1, 0, 4, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"%08X %08X",
hex->color[1], hex->color[2]);
VK_RESULT(update_ui_string(temp, 1, 0, 4, context->ui, context->render));
VK_RESULT(update_ui_string(temp, 1, 0, 5, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"%08X %08X",
hex->color[3], hex->color[4]);
VK_RESULT(update_ui_string(temp, 1, 0, 5, context->ui, context->render));
VK_RESULT(update_ui_string(temp, 1, 0, 6, context->ui, context->render));
snprintf(
temp,
sizeof(temp),
"%08X %08X",
hex->color[5], hex->color[6]);
VK_RESULT(update_ui_string(temp, 1, 0, 6, context->ui, context->render));
VK_RESULT(update_ui_string(temp, 1, 0, 7, context->ui, context->render));
}
return VK_SUCCESS;
@ -406,6 +581,7 @@ VkResult main_thread(ClientContext* context) {
VK_RESULT(region_info_ui(context));
VK_RESULT(hex_info_ui(context));
VK_RESULT(color_ui(context));
//
double last_frame_time = 0;