-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @file widets.cpp | ||
*/ | ||
|
||
#include <SFML/Graphics.hpp> | ||
|
||
#include "core/settings/colors.hpp" | ||
#include "widgets.hpp" | ||
|
||
namespace ui::widgets { | ||
|
||
Memo::Memo() | ||
{ | ||
// Appearance | ||
this->text_.setCharacterSize(16); | ||
this->text_.setFillColor(core::settings::colors::text); | ||
|
||
// Position | ||
this->text_.setPosition({core::settings::screen::CENTER.x, | ||
core::settings::screen::CENTER.y - 30.f}); | ||
} | ||
|
||
void Memo::hide() | ||
{ | ||
this->text_.setString(""); | ||
} | ||
|
||
void Memo::set(const std::string &str) | ||
{ | ||
this->text_.setString(str); | ||
this->text_.resetOrigin(); | ||
} | ||
|
||
void Memo::draw(sf::RenderWindow &window) const | ||
{ | ||
window.draw(this->text_); | ||
} | ||
|
||
Percentage::Percentage() | ||
: correct_answers_(0), | ||
total_answers_(0) | ||
{ | ||
// Appearance | ||
this->text_.setCharacterSize(18); | ||
this->text_.setFillColor(core::settings::colors::text); | ||
|
||
// Position | ||
constexpr float top_left_offset = 10.f; // Offset from the top-left corner | ||
this->text_.setPosition({core::settings::screen::TOP_LEFT.x + top_left_offset, | ||
core::settings::screen::TOP_LEFT.y + top_left_offset}); | ||
this->update_text(); | ||
} | ||
|
||
void Percentage::add_correct_answer() | ||
{ | ||
++this->correct_answers_; | ||
++this->total_answers_; | ||
this->update_text(); | ||
} | ||
|
||
void Percentage::add_incorrect_answer() | ||
{ | ||
++this->total_answers_; | ||
this->update_text(); | ||
} | ||
|
||
void Percentage::reset() | ||
{ | ||
this->correct_answers_ = 0; | ||
this->total_answers_ = 0; | ||
this->update_text(); | ||
} | ||
|
||
void Percentage::draw(sf::RenderWindow &window) const | ||
{ | ||
window.draw(this->text_); | ||
} | ||
|
||
void Percentage::update_text() | ||
{ | ||
float percent = 100.f; // If no answers yet, default to 100% | ||
if (this->total_answers_ > 0) { | ||
percent = (static_cast<float>(this->correct_answers_) / | ||
static_cast<float>(this->total_answers_)) * | ||
100.f; | ||
} | ||
this->text_.setString(fmt::format("게임 점수: {:.1f}%", percent)); | ||
} | ||
|
||
} // namespace ui::widgets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters