git repos / saland

commit 0fa5c89c

Poul Sander · 2022-11-05 20:46
0fa5c89c3da446516b6edf546a5b66d8909269fc patch · browse files
parent 9e22ce893831fa928628fecb3ac37e59e0a44084

It is now possible to change spells

Changed files

M src/saland/Game.cpp before
M src/saland/GameSpellState.cpp before
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index f475c89..d7002f9 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp
@@ -678,7 +678,7 @@ void Game::Update() {
if (selectedSpell.name == "weapon_slash_long_knife") {
data->human->weapon = "long_knife";
}
- if (SDL_GetMouseState(nullptr,nullptr) & 1 && !data->consoleActive && data->human->diedAt == 0) {
+ if (SDL_GetMouseState(nullptr,nullptr) & 1 && !data->consoleActive && data->human->diedAt == 0 && !data->spellSelect->IsSpellSelectActive()) {
if (data->spell_holder->slot_spell.at(data->spell_holder->slot_selected).name == "spell_fireball") {
if (data->human->castTimeRemaining == 0) {
data->human->castTimeRemaining = data->human->castTime;
diff --git a/src/saland/GameSpellState.cpp b/src/saland/GameSpellState.cpp index 3c48b9a..344f626 100644 --- a/src/saland/GameSpellState.cpp +++ b/src/saland/GameSpellState.cpp
@@ -24,6 +24,7 @@ https://github.com/sago007/saland
#include "GameSpellState.hpp"
#include "GameDraw.hpp"
#include "globals.hpp"
+#include "../global.hpp"
#include "../sago/SagoTextField.hpp"
#include <array>
@@ -42,36 +43,40 @@ GameSpellState::GameSpellState() {
}
}
+#define BOX_SPACING 56
+#define BOX_OFFSET 10
+#define BOX_SIZE 52
+
void GameSpellState::GameSpellState::Draw(SDL_Renderer* target) {
int sideBoarder = 20;
for (size_t i = 0; i < 10; ++i) {
if (spell_holder->slot_selected == i) {
- DrawRectWhite(target, 10+i*56, 10, 52, 52);
+ DrawRectWhite(target, BOX_OFFSET+i*BOX_SPACING, BOX_OFFSET, BOX_SIZE, BOX_SIZE);
}
else {
- DrawRectYellow(target, 10+i*56, 10, 52, 52);
+ DrawRectYellow(target, BOX_OFFSET+i*BOX_SPACING, BOX_OFFSET, BOX_SIZE, BOX_SIZE);
}
int key_number = (i+1)%10;
- data->number_labels.at(key_number).Draw(target, 10+i*56, 10);
+ data->number_labels.at(key_number).Draw(target, 10+i*BOX_SPACING, 10);
const Spell& current_spell = spell_holder->slot_spell.at(i);
if (current_spell.icon.length() > 0) {
globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), 36+i*56, 36);
}
if (current_spell.tile > 0) {
- DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, 20+i*56, 20);
+ DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, 20+i*BOX_SPACING, 20);
}
}
if (!data->spellSelectActive) {
return;
}
for (size_t i = 0; i < spell_holder->get_spell_count(); ++i) {
- DrawRectYellow(target, 10+i*56, 10+70, 52, 52);
+ DrawRectYellow(target, BOX_OFFSET+(int)i*BOX_SPACING, BOX_OFFSET+70, BOX_SIZE, BOX_SIZE);
const Spell& current_spell = spell_holder->get_spell(i);
if (current_spell.icon.length() > 0) {
- globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), 36+i*56, 36+70);
+ globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), 36+(int)i*BOX_SPACING, 36+70);
}
if (current_spell.tile > 0) {
- DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, 20+i*56, 20+70);
+ DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, 20+(int)i*BOX_SPACING, 20+70);
}
}
}
@@ -85,12 +90,28 @@ bool GameSpellState::IsSpellSelectActive() {
}
void GameSpellState::ProcessInput(const SDL_Event& event, bool& processed) {
+ UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey);
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
data->spellSelectActive = !data->spellSelectActive;
processed = true;
}
}
+ if (event.type == SDL_MOUSEBUTTONDOWN) {
+ if (event.button.button == SDL_BUTTON_LEFT) {
+ std::cout << "Left click " << globalData.mousex << "," << globalData.mousey << "\n";
+ for (size_t i = 0; i < spell_holder->get_spell_count(); ++i) {
+ if (globalData.mousex >= BOX_OFFSET+(int)i*BOX_SPACING && globalData.mousex <= BOX_OFFSET+(int)i*BOX_SPACING+BOX_SIZE &&
+ globalData.mousey >= BOX_OFFSET+70 && globalData.mousey <= BOX_OFFSET+70+BOX_SIZE) {
+ std::cout << "Clicked: " << i << "\n";
+ if (spell_holder->slot_selected < 9) {
+ //We do not update slot 9.
+ spell_holder->slot_spell.at(spell_holder->slot_selected) = spell_holder->get_spell(i);
+ }
+ }
+ }
+ }
+ }
};
void GameSpellState::Update() {};