add crafting tooltip

efd/v1
Dominik Madarász 2023-01-15 20:21:56 +01:00
parent f24ab7dc04
commit ba78e5360e
7 changed files with 80 additions and 16 deletions

View File

@ -33,7 +33,7 @@ static uint8_t game_should_close;
static world_view *world_viewers;
static world_view *active_viewer;
static struct nk_context *game_ui = 0;
struct nk_context *game_ui = 0;
static WORLD_PKT_READER(pkt_reader) {
pkt_header header = {0};
@ -259,10 +259,13 @@ void game_update() {
void game_render() {
if (game_mode != GAMEKIND_HEADLESS) {
platform_render();
DrawNuklear(game_ui);
}
}
void game_draw_ui() {
DrawNuklear(game_ui);
}
void game_action_send_keystate(game_keystate_data *data) {
pkt_send_keystate_send(active_viewer->view_id, data);
}

View File

@ -23,6 +23,9 @@ void game_input();
void game_update();
void game_render();
//~ Called from platform.c
void game_draw_ui();
//~ NOTE(zaklaus): world view management
world_view *game_world_view_get_active(void);
world_view *game_world_view_get(uint16_t idx);

View File

@ -89,6 +89,23 @@ inv_draw_result inventory_draw_crafting_btn(float xpos, float ypos, const char *
inv_is_inside = true;
player_inv.craft_item = id;
}
if (check_mouse_area(xpos, ypos, name_width, 22) != DAREA_OUTSIDE) {
Vector2 mpos = GetMousePosition();
recipe rp = craft_get_recipe_data(craft_get_recipe_id_from_product(id));
int num_reagents = 0;
for (int i = 0; rp.reagents[i].id; i++) num_reagents++;
if (nk_begin(game_ui , name, nk_rect(mpos.x+15, mpos.y+15, name_width+5, 80+25*(float)num_reagents),
NK_WINDOW_BORDER | NK_WINDOW_TITLE | NK_WINDOW_NO_INPUT)) {
if (nk_tree_push_id(game_ui, NK_TREE_NODE, "Reagents", NK_MAXIMIZED, id)) {
for (asset_id i = 0; rp.reagents[i].id; i++) {
nk_label(game_ui, asset_names[rp.reagents[i].id], NK_TEXT_LEFT);
}
nk_tree_pop(game_ui);
}
nk_end(game_ui);
}
}
Color _c_compare_lol = BLACK;
if (!zpl_memcompare(&color, &_c_compare_lol, sizeof(Color))) {
@ -97,6 +114,7 @@ inv_draw_result inventory_draw_crafting_btn(float xpos, float ypos, const char *
inv_draw_result res = DrawColoredText(xpos, ypos, text, new_color);
ypos = res.y;
return res;
}

View File

@ -1,19 +1,6 @@
#include "crafting.h"
#include "models/items.h"
typedef struct {
asset_id id;
uint32_t qty;
} reagent;
typedef struct {
asset_id product;
uint32_t product_qty;
int32_t process_ticks;
asset_id producer;
reagent *reagents;
} recipe;
#include "lists/crafting_list.c"
uint32_t craft__find_num_recipes_by_reagent(asset_id producer, asset_id id) {
@ -46,6 +33,20 @@ recipe *craft__find_recipe_by_reagent(asset_id producer, asset_id id, uint32_t s
}
}
return NULL;
}
uint16_t craft_get_recipe_id_from_product(asset_id id) {
for (int i = 0; i < (int)MAX_RECIPES; ++i) {
if (id == recipes[i].product) {
return i;
}
}
return ASSET_INVALID;
}
recipe craft_get_recipe_data(uint16_t i) {
ZPL_ASSERT(i >= 0 && i < MAX_RECIPES);
return recipes[i];
}
bool craft_is_reagent_used_in_producer(asset_id reagent, asset_id producer) {
@ -53,7 +54,6 @@ bool craft_is_reagent_used_in_producer(asset_id reagent, asset_id producer) {
}
bool craft_is_item_produced_by_producer(asset_id item, asset_id producer) {
uint32_t num_recipes=0;
for (int i = 0; i < (int)MAX_RECIPES; ++i) {
if (recipes[i].producer == producer && item == recipes[i].product) {
return true;
@ -62,6 +62,18 @@ bool craft_is_item_produced_by_producer(asset_id item, asset_id producer) {
return false;
}
bool craft_is_item_produced_by_reagent(asset_id item, asset_id reagent) {
for (int i = 0; i < (int)MAX_RECIPES; ++i) {
if (item == recipes[i].product) {
for (int j = 0; recipes[i].reagents[j].id; ++j) {
if (recipes[i].reagents[j].id == reagent)
return true;
}
}
}
return false;
}
uint16_t craft_get_num_recipes(void) {
return MAX_RECIPES;
}

View File

@ -4,6 +4,19 @@
#include "models/components.h"
typedef struct {
asset_id id;
uint32_t qty;
} reagent;
typedef struct {
asset_id product;
uint32_t product_qty;
int32_t process_ticks;
asset_id producer;
reagent *reagents;
} recipe;
// NOTE(zaklaus): resolves recipe dependencies and consumes reagents
// to enqueue a production of a new item.
// TODO(zaklaus): "items" is assumed to come from ItemContainer component.
@ -15,9 +28,14 @@ bool craft_is_reagent_used_in_producer(asset_id reagent, asset_id producer);
// used to filter out craftables
bool craft_is_item_produced_by_producer(asset_id item, asset_id producer);
// used to filter out reagents
bool craft_is_item_produced_by_reagent(asset_id item, asset_id reagent);
// NOTE(zaklaus): utilities
uint16_t craft_get_num_recipes(void);
asset_id craft_get_recipe_asset(uint16_t id);
uint16_t craft_get_recipe_id_from_product(asset_id id);
recipe craft_get_recipe_data(uint16_t i);
//~TODO(zaklaus): not implemented and might get removed

View File

@ -14,6 +14,10 @@
#include "utils/raylib_helpers.h"
#include "platform/renderer.h"
ZPL_DIAGNOSTIC_PUSH_WARNLEVEL(0)
#include "raylib-nuklear.h"
ZPL_DIAGNOSTIC_POP
#define ARCH_IMPL
#include "platform/arch.h"
@ -95,6 +99,7 @@ void platform_render() {
}
debug_draw();
game_draw_ui();
}
EndDrawing();

View File

@ -16,6 +16,10 @@
#include "utils/raylib_helpers.h"
#include "platform/renderer.h"
ZPL_DIAGNOSTIC_PUSH_WARNLEVEL(0)
#include "raylib-nuklear.h"
ZPL_DIAGNOSTIC_POP
#define ARCH_IMPL
#include "platform/arch.h"
@ -186,6 +190,7 @@ void platform_render() {
}
display_conn_status();
debug_draw();
game_draw_ui();
}
EndDrawing();