aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog17
-rw-r--r--include/events.hpp8
-rw-r--r--include/inventory.hpp1
-rw-r--r--include/vector2.hpp8
-rw-r--r--src/inventory.cpp45
-rw-r--r--src/ui.cpp5
6 files changed, 78 insertions, 6 deletions
diff --git a/Changelog b/Changelog
index b13a786..94f0a4d 100644
--- a/Changelog
+++ b/Changelog
@@ -1093,3 +1093,20 @@ Late June (6/16/2016 - 6/27/2016)
- created render.cpp, moved shader management to there
- this game will be kinda decent now???
- input bugs, because we're awful
+
+
+
+
+1/19/2017:
+==========
+
+ What's been happening:
+
+ - major rewrite, full on EntityX
+ - everything is actually decent now
+ - keeping an eye on optimization, perf, ...
+ - basically no segfaults? like what the heck
+ - new inventory system
+ - new entity animation system
+ - almost ready to really get some story work done
+
diff --git a/include/events.hpp b/include/events.hpp
index 5939c3d..6251fac 100644
--- a/include/events.hpp
+++ b/include/events.hpp
@@ -40,6 +40,14 @@ struct MouseClickEvent {
int button;
};
+struct MouseReleaseEvent {
+ MouseReleaseEvent(vec2 pos, int b)
+ : position(pos), button(b) {}
+
+ vec2 position;
+ int button;
+};
+
struct KeyDownEvent {
KeyDownEvent(SDL_Keycode kc = 0)
: keycode(kc) {}
diff --git a/include/inventory.hpp b/include/inventory.hpp
index 2e261ae..084a2d6 100644
--- a/include/inventory.hpp
+++ b/include/inventory.hpp
@@ -86,6 +86,7 @@ public:
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
void receive(const KeyDownEvent &kde);
void receive(const MouseClickEvent &mce);
+ void receive(const MouseReleaseEvent &mce);
void render(void);
diff --git a/include/vector2.hpp b/include/vector2.hpp
index 17e47d1..d335a4b 100644
--- a/include/vector2.hpp
+++ b/include/vector2.hpp
@@ -71,6 +71,14 @@ struct vector2 {
return (x == v.x) && (y == v.y);
}
+ bool operator>(const vector2<T>& v) const {
+ return (x > v.x) && (y > v.y);
+ }
+
+ bool operator<(const vector2<T>& v) const {
+ return (x < v.x) && (y < v.y);
+ }
+
// other functions
std::string toString(void) const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
diff --git a/src/inventory.cpp b/src/inventory.cpp
index f222ef1..83bdeb2 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -23,10 +23,13 @@ constexpr int hotbarSize = 4;
constexpr float inventoryZ = -6.0f;
constexpr unsigned int rowSize = 8;
+static int movingItem = -1;
+
void InventorySystem::configure(entityx::EventManager &ev)
{
ev.subscribe<KeyDownEvent>(*this);
ev.subscribe<MouseClickEvent>(*this);
+ ev.subscribe<MouseReleaseEvent>(*this);
}
void InventorySystem::loadItems(void) {
@@ -99,16 +102,21 @@ void InventorySystem::render(void)
i.item->sprite.use();
static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1};
glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
- vec2 end = i.loc + i.item->sprite.getDim();
+
+ vec2 sta ((n == movingItem) ? ui::mouse - i.item->sprite.getDim() / 2 : i.loc);
+ vec2 end = (n == movingItem) ? ui::mouse + i.item->sprite.getDim() / 2 : i.loc + i.item->sprite.getDim();
GLfloat coords[18] = {
- i.loc.x, i.loc.y, inventoryZ - 0.2, end.x, i.loc.y, inventoryZ - 0.2, end.x, end.y, inventoryZ - 0.2,
- end.x, end.y, inventoryZ - 0.2, i.loc.x, end.y, inventoryZ - 0.2, i.loc.x, i.loc.y, inventoryZ - 0.2
+ sta.x, sta.y, inventoryZ - 0.2, end.x, sta.y, inventoryZ - 0.2, end.x, end.y, inventoryZ - 0.2,
+ end.x, end.y, inventoryZ - 0.2, sta.x, end.y, inventoryZ - 0.2, sta.x, sta.y, inventoryZ - 0.2
};
glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
+ if (n == movingItem)
+ glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8);
glDrawArrays(GL_TRIANGLES, 0, 6);
ui::setFontZ(-7.2); // TODO fix z's
- ui::putText(i.loc.x, i.loc.y, std::to_string(i.count).c_str());
+ ui::putText(sta.x, sta.y, std::to_string(i.count).c_str());
ui::setFontZ(-6);
+ glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
}
}
@@ -118,7 +126,34 @@ void InventorySystem::render(void)
void InventorySystem::receive(const MouseClickEvent &mce)
{
- (void)mce;
+ int end = fullInventory ? items.size() : hotbarSize;
+ movingItem = -1;
+ for (int i = 0; i < end; i++) {
+ if (mce.position > items[i].loc && mce.position < items[i].loc + entrySize) {
+ movingItem = i;
+ break;
+ }
+ }
+}
+
+void InventorySystem::receive(const MouseReleaseEvent &mre)
+{
+ if (movingItem != -1) {
+ int end = fullInventory ? items.size() : hotbarSize;
+ for (int i = 0; i < end; i++) {
+ if (mre.position > items[i].loc && mre.position < items[i].loc + entrySize) {
+ if (items[i].count > 0) {
+ std::swap(items[movingItem], items[i]);
+ } else {
+ items[i] = items[movingItem];
+ items[movingItem].item = nullptr;
+ items[movingItem].count = 0;
+ }
+ break;
+ }
+ }
+ movingItem = -1;
+ }
}
void InventorySystem::receive(const KeyDownEvent &kde)
diff --git a/src/ui.cpp b/src/ui.cpp
index dad9454..7a81bd5 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -1202,7 +1202,10 @@ void InputSystem::receive(const MainSDLEvent& event)
premouse.y=e.motion.y;
break;
- //case SDL_MOUSEBUTTONUP:
+ case SDL_MOUSEBUTTONUP:
+ ev.emit<MouseReleaseEvent>(mouse, e.button.button);
+ break;
+
case SDL_MOUSEBUTTONDOWN:
ev.emit<MouseClickEvent>(mouse, e.button.button);