Building out container class, move classes to their own headers.
This commit is contained in:
@@ -35,25 +35,9 @@ namespace CaveGame::Client {
|
||||
class CraftingStation {};
|
||||
|
||||
|
||||
class Container
|
||||
{
|
||||
public:
|
||||
Container(int rows, int columns);
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class Storage : Container {};
|
||||
class PlayerHotbar : Container {};
|
||||
class PlayerPockets : Container {};
|
||||
class PlayerBackpack : Container {};
|
||||
class TradeMenu : Container {};
|
||||
|
||||
class PlayerInventory : Container
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
class ContainerGUI {
|
||||
|
||||
@@ -114,7 +98,7 @@ namespace CaveGame::Client {
|
||||
JUI::Scene* hud = nullptr;
|
||||
Vector2 mouse_pos = {0,0};
|
||||
RNG tool_rng;
|
||||
ContainerWindow* test_container = nullptr;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
@@ -29,8 +29,7 @@ void CaveGame::Client::GameSession::Load() {
|
||||
hotbar.Load(world);
|
||||
hotbar.GetRootWidget()->Parent(hud);
|
||||
|
||||
auto conn = jstick::ButtonPressed += [&, this] (jstick::XBoxButton btn) mutable
|
||||
{
|
||||
auto conn = jstick::ButtonPressed += [&, this] (jstick::XBoxButton btn) mutable {
|
||||
if (btn == jstick::XBoxButton::BumperL)
|
||||
hotbar.PrevSlot();
|
||||
|
||||
@@ -55,7 +54,7 @@ void CaveGame::Client::GameSession::Load() {
|
||||
World()->DoTileTiccs(0.f);
|
||||
};
|
||||
|
||||
test_container = new ContainerWindow(hud, 5, 5, "Test Container");
|
||||
|
||||
}
|
||||
|
||||
void CaveGame::Client::GameSession::Draw() {
|
||||
@@ -189,15 +188,15 @@ void CaveGame::Client::GameSession::Update(float elapsed) {
|
||||
|
||||
if (rstick.Magnitude() > 0.1f)
|
||||
{
|
||||
mouse_pos += rstick*elapsed*100;
|
||||
float joystick_cursor_speed = 250.f;
|
||||
mouse_pos += rstick*elapsed*joystick_cursor_speed;
|
||||
}
|
||||
|
||||
|
||||
// FIXME: Temporary hack, we poll the bumper button state each frame, cause the jstick event doesn't propagate for some reason.
|
||||
bool lprn = jstick::IsButtonDown(jstick::XBoxButton::BumperL);
|
||||
/* bool lprn = jstick::IsButtonDown(jstick::XBoxButton::BumperL);
|
||||
bool rprn = jstick::IsButtonDown(jstick::XBoxButton::BumperR);
|
||||
|
||||
|
||||
if (lprn && !lp)
|
||||
hotbar.PrevSlot();
|
||||
|
||||
@@ -205,7 +204,7 @@ void CaveGame::Client::GameSession::Update(float elapsed) {
|
||||
hotbar.NextSlot();
|
||||
|
||||
lp = lprn;
|
||||
rp = rprn;
|
||||
rp = rprn;*/
|
||||
|
||||
|
||||
/*
|
||||
@@ -218,7 +217,6 @@ void CaveGame::Client::GameSession::Update(float elapsed) {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// TODO: Do this once JUI can consume input.
|
||||
//
|
||||
// WorldEditToolControlsUpdate(elapsed);
|
||||
|
46
Core/include/Core/Container.hpp
Normal file
46
Core/include/Core/Container.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.hpp>
|
||||
#include <map>
|
||||
#include <Core/Itemstack.hpp>
|
||||
#include "Core/v2i_hash.hpp"
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
enum RestrictListMode
|
||||
{
|
||||
ALLOWLIST,
|
||||
DENYLIST
|
||||
};
|
||||
|
||||
class Container {
|
||||
public:
|
||||
|
||||
RestrictListMode whitelist_mode;
|
||||
|
||||
Container(int rows, int columns);
|
||||
|
||||
ItemStack &At(const Vector2i &cell);
|
||||
|
||||
/// Returns how much of the stack would be left-over if inserted into this container.
|
||||
/// Storing onto existing non-full item stacks of the same type will occur.
|
||||
int CanFitItemStack(const ItemStack &item)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IsSlotEmpty(const Vector2i& cell)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int Insert(const ItemStack &item)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::unordered_map<Vector2i, ItemStack> contents;
|
||||
};
|
||||
}
|
@@ -1,14 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <Core/Item.hpp>
|
||||
#include <Core/PhysicsEntity.hpp>
|
||||
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
class ItemStack
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
private:
|
||||
struct ItemStack {
|
||||
Core::Item* type;
|
||||
uint16_t stack;
|
||||
};
|
||||
|
||||
class ItemStackEntity : public PhysicsEntity, public ItemStack {
|
||||
public:
|
||||
protected:
|
||||
|
Reference in New Issue
Block a user