commit 2a460c9c
Also resize the spell select menu
Changed files
| M | src/saland/GameDraw.cpp before |
| M | src/saland/GameDraw.hpp before |
| M | src/saland/GameSpellState.cpp before |
diff --git a/src/saland/GameDraw.cpp b/src/saland/GameDraw.cpp
index 3806000..f3e932a 100644
--- a/src/saland/GameDraw.cpp
+++ b/src/saland/GameDraw.cpp
@@ -285,7 +285,7 @@ void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const
DrawCollision(target, entity, offsetX, offsetY, drawCollision, resize);
}
-static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int width, const std::string& name) {
+static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int width, const std::string& name, sago::SagoLogicalResize* resize = nullptr) {
const int size = 32;
SDL_Rect bounds_ns = {topx, topy+size, width, height-2*size}; //bounds for south
SDL_Rect bounds_e = {topx, topy, width-size, height};
@@ -295,31 +295,31 @@ static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int w
const sago::SagoSprite& w = globalData.spriteHolder->GetSprite(name+"w");
const sago::SagoSprite& fill = globalData.spriteHolder->GetSprite(name+"fill");
for (int i = 1; i < width/size; ++i) {
- n.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy, bounds_e);
+ n.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy, bounds_e, resize);
for (int j = 1; j < height/size; ++j) {
- w.DrawBounded(target, SDL_GetTicks(), topx, topy+j*size, bounds_ns);
- fill.Draw(target, SDL_GetTicks(),topx+i*size, topy+j*size);
- e.DrawBounded(target, SDL_GetTicks(), topx+width-size, topy+j*size, bounds_ns);
+ w.DrawBounded(target, SDL_GetTicks(), topx, topy+j*size, bounds_ns, resize);
+ fill.Draw(target, SDL_GetTicks(),topx+i*size, topy+j*size, resize);
+ e.DrawBounded(target, SDL_GetTicks(), topx+width-size, topy+j*size, bounds_ns, resize);
}
- s.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy+height-size, bounds_e);
+ s.DrawBounded(target, SDL_GetTicks(), topx+i*size, topy+height-size, bounds_e, resize);
}
//Corners
const sago::SagoSprite& nw = globalData.spriteHolder->GetSprite(name+"nw");
const sago::SagoSprite& ne = globalData.spriteHolder->GetSprite(name+"ne");
const sago::SagoSprite& se = globalData.spriteHolder->GetSprite(name+"se");
const sago::SagoSprite& sw = globalData.spriteHolder->GetSprite(name+"sw");
- nw.Draw(target, SDL_GetTicks(), topx, topy);
- ne.Draw(target, SDL_GetTicks(), topx+width-size, topy);
- se.Draw(target, SDL_GetTicks(), topx+width-size, topy+height-size);
- sw.Draw(target, SDL_GetTicks(), topx, topy+height-size);
+ nw.Draw(target, SDL_GetTicks(), topx, topy, resize);
+ ne.Draw(target, SDL_GetTicks(), topx+width-size, topy, resize);
+ se.Draw(target, SDL_GetTicks(), topx+width-size, topy+height-size, resize);
+ sw.Draw(target, SDL_GetTicks(), topx, topy+height-size, resize);
}
-void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width) {
+void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width, sago::SagoLogicalResize* resize) {
std::string name = "ui_rect_white_";
- DrawRect(target, topx, topy, height, width, name);
+ DrawRect(target, topx, topy, height, width, name, resize);
}
-void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width) {
+void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width, sago::SagoLogicalResize* resize) {
std::string name = "ui_rect_yellow_";
- DrawRect(target, topx, topy, height, width, name);
+ DrawRect(target, topx, topy, height, width, name, resize);
}
\ No newline at end of file
diff --git a/src/saland/GameDraw.hpp b/src/saland/GameDraw.hpp
index 3567c1b..3d2f025 100644
--- a/src/saland/GameDraw.hpp
+++ b/src/saland/GameDraw.hpp
@@ -38,8 +38,8 @@ void DrawHumanEntity(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, cons
void DrawMonster(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Monster* entity, float time, int offsetX, int offsetY, bool drawCollision, sago::SagoLogicalResize* resize = nullptr);
void DrawProjectile(SDL_Renderer* target, sago::SagoSpriteHolder* sHolder, const Projectile* entity, float time, int offsetX, int offsetY, bool drawCollision, sago::SagoLogicalResize* resize = nullptr);
-void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width);
-void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width);
+void DrawRectWhite(SDL_Renderer* target, int topx, int topy, int height, int width, sago::SagoLogicalResize* resize = nullptr);
+void DrawRectYellow(SDL_Renderer* target, int topx, int topy, int height, int width, sago::SagoLogicalResize* resize = nullptr);
void DrawTile(SDL_Renderer* renderer, sago::SagoSpriteHolder* sHolder, const sago::tiled::TileMap& tm, uint32_t gid, int x, int y, sago::SagoLogicalResize* resize = nullptr);
#endif /* GAMEDRAW_HPP */
diff --git a/src/saland/GameSpellState.cpp b/src/saland/GameSpellState.cpp
index b156606..18cc2d1 100644
--- a/src/saland/GameSpellState.cpp
+++ b/src/saland/GameSpellState.cpp
@@ -58,21 +58,22 @@ static int spell_slot_y(int slot) {
void GameSpellState::GameSpellState::Draw(SDL_Renderer* target) {
int sideBoarder = 20;
+ sago::SagoLogicalResize* resize = &globalData.logicalResize;
for (size_t i = 0; i < 10; ++i) {
if (spell_holder->slot_selected == i) {
- DrawRectWhite(target, BOX_OFFSET+i*BOX_SPACING, BOX_OFFSET, BOX_SIZE, BOX_SIZE);
+ DrawRectWhite(target, BOX_OFFSET+i*BOX_SPACING, BOX_OFFSET, BOX_SIZE, BOX_SIZE, resize);
}
else {
- DrawRectYellow(target, BOX_OFFSET+i*BOX_SPACING, BOX_OFFSET, BOX_SIZE, BOX_SIZE);
+ DrawRectYellow(target, BOX_OFFSET+i*BOX_SPACING, BOX_OFFSET, BOX_SIZE, BOX_SIZE, resize);
}
int key_number = (i+1)%10;
- data->number_labels.at(key_number).Draw(target, 10+i*BOX_SPACING, 10);
+ data->number_labels.at(key_number).Draw(target, 10+i*BOX_SPACING, 10, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, resize);
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);
+ globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), 36+i*56, 36, resize);
}
if (current_spell.tile > 0) {
- DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, 20+i*BOX_SPACING, 20);
+ DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, 20+i*BOX_SPACING, 20, resize);
}
}
if (!data->spellSelectActive) {
@@ -81,13 +82,13 @@ void GameSpellState::GameSpellState::Draw(SDL_Renderer* target) {
for (size_t i = 0; i < spell_holder->get_spell_count(); ++i) {
int x = spell_slot_x(i);
int y = spell_slot_y(i);
- DrawRectYellow(target, x, y, BOX_SIZE, BOX_SIZE);
+ DrawRectYellow(target, x, y, BOX_SIZE, BOX_SIZE, resize);
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(), x+BOX_SIZE/2, y+BOX_SIZE/2);
+ globalData.spriteHolder.get()->GetSprite(current_spell.icon).Draw(target, SDL_GetTicks(), x+BOX_SIZE/2, y+BOX_SIZE/2, resize);
}
if (current_spell.tile > 0) {
- DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, x+10, y+10);
+ DrawTile(target, globalData.spriteHolder.get(), *tm, current_spell.tile, x+10, y+10, resize);
}
}
}
@@ -113,12 +114,15 @@ void GameSpellState::ProcessInput(const SDL_Event& event, bool& processed) {
}
if (event.type == SDL_MOUSEBUTTONDOWN) {
if (event.button.button == SDL_BUTTON_LEFT) {
- std::cout << "Left click " << globalData.mousex << "," << globalData.mousey << "\n";
+ // Convert physical mouse coordinates to logical coordinates
+ int logical_mousex, logical_mousey;
+ globalData.logicalResize.PhysicalToLogical(globalData.mousex, globalData.mousey, logical_mousex, logical_mousey);
+ std::cout << "Left click " << logical_mousex << "," << logical_mousey << "\n";
for (size_t i = 0; i < spell_holder->get_spell_count(); ++i) {
int x = spell_slot_x(i);
int y = spell_slot_y(i);
- if (globalData.mousex >= x && globalData.mousex <= x + BOX_SIZE &&
- globalData.mousey >= y && globalData.mousey <= y + BOX_SIZE) {
+ if (logical_mousex >= x && logical_mousex <= x + BOX_SIZE &&
+ logical_mousey >= y && logical_mousey <= y + BOX_SIZE) {
std::cout << "Clicked: " << i << "\n";
if (spell_holder->slot_selected < 9) {
//We do not update slot 9.