aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2026-01-20 13:39:03 +0000
committernathan <nathansmith@disroot.org>2026-01-20 13:39:03 +0000
commit602bfee943ac7810d0ca961851883c8909f5d7ff (patch)
tree7f790cdadd55a4e6766c6599415fddf7b4006840
parentf44d154d1372597742642596fe91c619613f81ef (diff)
downloadFindThings-602bfee943ac7810d0ca961851883c8909f5d7ff.tar.gz
FindThings-602bfee943ac7810d0ca961851883c8909f5d7ff.tar.bz2
FindThings-602bfee943ac7810d0ca961851883c8909f5d7ff.zip
Intractable inventory items
-rw-r--r--src/entities/oldMint.c16
-rw-r--r--src/player.c11
-rw-r--r--src/ui.c140
-rw-r--r--src/ui.h9
4 files changed, 161 insertions, 15 deletions
diff --git a/src/entities/oldMint.c b/src/entities/oldMint.c
index 9e43fd9..87b3583 100644
--- a/src/entities/oldMint.c
+++ b/src/entities/oldMint.c
@@ -31,9 +31,19 @@ InteractionCommand interactWithOldMint(Entity* entity, Game* game,
addItemToInventory(&game->inventory, item);
return INTERACTION_TALK;
case SELECTION_USE:
- return INTERACTION_KILL_ITEM;
+ setInteractionChat(&game->interactionChat,
+ "Bad idea. I am very old and stale.");
+ entity->data = (void*)1;
+ return INTERACTION_TALK;
default:
- entity->visable = false;
- return INTERACTION_END;
+ if (entity->data == NULL)
+ {
+ entity->visable = false;
+ return INTERACTION_END;
+ }
+ else
+ {
+ return INTERACTION_KILL_ITEM;
+ }
}
}
diff --git a/src/player.c b/src/player.c
index 3720762..082c87d 100644
--- a/src/player.c
+++ b/src/player.c
@@ -347,13 +347,9 @@ bool playerCanEntityBeSelected(Player* player, Entity entity)
void playerEndInteraction(Player* player, Game* game)
{
+ endInteraction(game);
player->selectedEntity = ENTITY_NONE;
player->isInteracting = false;
-
- hideInteractionChat(&game->interactionChat);
- hideInteractionMenu(&game->interactionMenu);
- game->interactionChat.entityId = ENTITY_NONE;
- game->interactionMenu.entityId = ENTITY_NONE;
}
void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
@@ -368,10 +364,7 @@ void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
switch (selection)
{
case SELECTION_INTERACT:
- clearInteractionChat(chat);
- resetInteractionMenu(menu);
- chat->entityId = entity->id;
- menu->entityId = entity->id;
+ startInteraction(game, entity->id);
player->selectedEntity = uid;
player->isInteracting = true;
break;
diff --git a/src/ui.c b/src/ui.c
index cca77cf..436b54a 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -228,6 +228,25 @@ void updateInteractionMenu(InteractionMenu* menu, Game* game)
}
}
+void startInteraction(Game* game, EntityId entityId)
+{
+ InteractionChat* chat = &game->interactionChat;
+ InteractionMenu* menu = &game->interactionMenu;
+
+ clearInteractionChat(chat);
+ resetInteractionMenu(menu);
+ chat->entityId = entityId;
+ menu->entityId = entityId;
+}
+
+void endInteraction(Game* game)
+{
+ hideInteractionChat(&game->interactionChat);
+ hideInteractionMenu(&game->interactionMenu);
+ game->interactionChat.entityId = ENTITY_NONE;
+ game->interactionMenu.entityId = ENTITY_NONE;
+}
+
void resizeInventory(Inventory* inventory, const Settings* settings)
{
float outlineThickness = settings->uiOutlineSize;
@@ -237,11 +256,14 @@ void resizeInventory(Inventory* inventory, const Settings* settings)
inventory->rect.x = GetRenderWidth() / 2.0 - inventory->rect.width / 2.0;
inventory->rect.y = GetRenderHeight() / 2.0 - inventory->rect.height / 2.0;
}
+
void initInventory(Inventory* inventory, const Settings* settings)
{
resizeInventory(inventory, settings);
inventory->visable = false;
inventory->itemCount = 0;
+ inventory->interactingEntity = NULL;
+ inventory->interactingIndex = 0;
}
void showInventory(Inventory* inventory, Game* game)
@@ -310,6 +332,103 @@ void removeInventoryItem(Inventory* inventory, int itemIndex)
}
}
+void inventoryEndInteraction(Inventory* inventory, Game* game)
+{
+ inventory->interactingEntity = NULL;
+ endInteraction(game);
+}
+
+// Yup, pretty much a rewrite of player interaction code.
+
+// Returns true if item should be killed.
+bool inventoryInteractWithEntity(Inventory* inventory, Game* game,
+ Entity* entity, Selection selection)
+{
+ InteractionChat* chat = &game->interactionChat;
+ InteractionMenu* menu = &game->interactionMenu;
+
+ // Handle selection.
+ switch (selection)
+ {
+ case SELECTION_USE:
+ startInteraction(game, entity->id);
+ inventory->interactingEntity = entity;
+ break;
+ case SELECTION_LEAVE:
+ inventoryEndInteraction(inventory, game);
+ break;
+ default:
+ break;
+ }
+
+ // Interact with it.
+ switch (interactWithEntity(entity, game, selection))
+ {
+ case INTERACTION_TALK:
+ hideInteractionMenu(menu);
+ showInteractionChat(chat);
+ break;
+ case INTERACTION_SHOW_MENU:
+ hideInteractionChat(chat);
+ showInteractionMenu(menu);
+ break;
+ case INTERACTION_TALK_AND_SHOW_MENU:
+ showInteractionChat(chat);
+ showInteractionMenu(menu);
+ break;
+ case INTERACTION_END:
+ inventoryEndInteraction(inventory, game);
+ break;
+ case INTERACTION_KILL_ITEM:
+ inventoryEndInteraction(inventory, game);
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+void inventoryHandleInteraction(Inventory* inventory, Game* game)
+{
+ InteractionChat* chat = &game->interactionChat;
+ InteractionMenu* menu = &game->interactionMenu;
+ int keyPressed = GetKeyPressed();
+
+ bool shouldKill = false;
+
+ if (IsKeyPressed(game->settings.leaveKey))
+ {
+ shouldKill = inventoryInteractWithEntity(inventory, game,
+ inventory->interactingEntity,
+ SELECTION_LEAVE);
+ }
+ else if (IsKeyPressed(game->settings.nextMessageKey))
+ {
+ if (isInteractionChatAnimationDone(chat))
+ {
+ shouldKill = inventoryInteractWithEntity(inventory, game,
+ inventory->interactingEntity,
+ SELECTION_LEAVE);
+ }
+ else
+ {
+ endInteractionChatAnimation(chat);
+ }
+ }
+ else if (keyPressed >= KEY_ONE && keyPressed <= KEY_NINE)
+ {
+ shouldKill = inventoryInteractWithEntity(
+ inventory, game, inventory->interactingEntity,
+ SELECTION_MENU_ITEM + (keyPressed - KEY_ONE));
+ }
+
+ if (shouldKill)
+ {
+ removeInventoryItem(inventory, inventory->interactingIndex);
+ }
+}
+
void updateInventory(Inventory* inventory, Game* game)
{
if (IsWindowResized())
@@ -317,6 +436,19 @@ void updateInventory(Inventory* inventory, Game* game)
resizeInventory(inventory, &game->settings);
}
+ // Is interacting.
+ if (inventory->interactingEntity != NULL)
+ {
+ inventoryHandleInteraction(inventory, game);
+ return;
+ }
+
+ // Hide with interaction chat/menu.
+ if (game->interactionChat.visible || game->interactionMenu.visible)
+ {
+ return;
+ }
+
// Handle toggle key.
if (IsKeyPressed(game->settings.toggleInventoryKey))
{
@@ -329,7 +461,8 @@ void updateInventory(Inventory* inventory, Game* game)
showInventory(inventory, game);
}
}
-
+
+ // Not visable.
if (!inventory->visable)
{
return;
@@ -397,8 +530,9 @@ void updateInventory(Inventory* inventory, Game* game)
// Use item.
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
{
- killItem = interactWithEntity(item->parent, game, SELECTION_USE) ==
- INTERACTION_KILL_ITEM;
+ killItem = inventoryInteractWithEntity(inventory, game, item->parent,
+ SELECTION_USE);
+ inventory->interactingIndex = index;
killIndex = index;
}
}
diff --git a/src/ui.h b/src/ui.h
index 738f630..eadaff0 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -45,8 +45,13 @@ typedef struct {
typedef struct {
Rectangle rect;
bool visable;
+
InventoryItem items[INVENTORY_MAX];
int itemCount;
+
+ // NULL if not interacting.
+ Entity* interactingEntity;
+ int interactingIndex;
} Inventory;
// Interaction chat procedures.
@@ -70,6 +75,10 @@ void showInteractionMenu(InteractionMenu* menu);
void hideInteractionMenu(InteractionMenu* menu);
void updateInteractionMenu(InteractionMenu* menu, Game* game);
+// Generic interaction thingies.
+void startInteraction(Game* game, EntityId entityId);
+void endInteraction(Game* game);
+
// Inventory
void initInventory(Inventory* inventory, const Settings* settings);
void showInventory(Inventory* inventory, Game* game);