Remove a bunch of dead code and clean up more.
This commit is contained in:
parent
8a30fafabb
commit
94c9cd75a8
6 changed files with 47 additions and 256 deletions
51
gui.cpp
51
gui.cpp
|
@ -16,11 +16,14 @@
|
|||
|
||||
using std::string, std::vector;
|
||||
|
||||
GUI::GUI(SFMLBackend &backend, int timer_seconds) :
|
||||
sfml(backend), $timer_seconds(timer_seconds)
|
||||
GUI::GUI(int timer_seconds) :
|
||||
$timer_seconds(timer_seconds),
|
||||
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Turing's Tarpit")
|
||||
{
|
||||
using namespace guecs;
|
||||
|
||||
$timer_end = std::chrono::system_clock::now() + std::chrono::seconds(timer_seconds);
|
||||
|
||||
$gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
$gui.layout(
|
||||
"[*%(200,300)face|_|*%(100,300)status|*%(200,500)log|_]"
|
||||
|
@ -43,10 +46,10 @@ GUI::GUI(SFMLBackend &backend, int timer_seconds) :
|
|||
auto status = $gui.entity("status");
|
||||
$gui.set<Textual>(status, {L""});
|
||||
|
||||
auto log = $gui.entity("log");
|
||||
auto& rect = $gui.get<Rectangle>(log);
|
||||
$log = $gui.entity("log");
|
||||
auto& rect = $gui.get<Rectangle>($log);
|
||||
rect.color = {255,255,255,255};
|
||||
$gui.set<Effect>(log, {(float)$timer_seconds, "build_status"});
|
||||
$gui.set<Effect>($log, {(float)$timer_seconds, "build_status"});
|
||||
|
||||
auto clock = $gui.entity("clock");
|
||||
$gui.set<Label>(clock, {L"00:00:00", 110});
|
||||
|
@ -58,22 +61,19 @@ GUI::GUI(SFMLBackend &backend, int timer_seconds) :
|
|||
}
|
||||
|
||||
void GUI::output(const string msg) {
|
||||
// _lines.push_back(msg);
|
||||
std::cout << msg << std::endl;
|
||||
}
|
||||
|
||||
void GUI::main_loop() {
|
||||
auto clock_time = std::chrono::system_clock::now();
|
||||
auto clock_time = $timer_end - std::chrono::system_clock::now();
|
||||
std::wstring time = std::format(L"{:%H:%M:%OS}", clock_time);
|
||||
|
||||
$gui.show_label("clock", time);
|
||||
$gui.show_text("status", $status);
|
||||
$gui.render(sfml.window);
|
||||
$gui.render($window);
|
||||
|
||||
// $gui.debug_layout(sfml.window);
|
||||
sfml.handle_events();
|
||||
// sfml.update_entities();
|
||||
sfml.update_log(_lines);
|
||||
$window.display();
|
||||
handle_events();
|
||||
}
|
||||
|
||||
void GUI::build_success() {
|
||||
|
@ -96,10 +96,8 @@ void GUI::build_failed(bool play_sound, const string &command) {
|
|||
output(fmt::format("!!! BUILD FAILED. Your command correct? '{}'", command));
|
||||
}
|
||||
|
||||
void GUI::update_status(GameEngine &game, size_t line_length, bool is_error) {
|
||||
|
||||
auto log = $gui.entity("log");
|
||||
auto& effect = $gui.get<guecs::Effect>(log);
|
||||
void GUI::configure_status_shader(size_t line_length, bool is_error) {
|
||||
auto& effect = $gui.get<guecs::Effect>($log);
|
||||
effect.$shader->setUniform("line_length", (int)line_length);
|
||||
if(!$hit_error && is_error) {
|
||||
$hit_error = is_error;
|
||||
|
@ -107,6 +105,10 @@ void GUI::update_status(GameEngine &game, size_t line_length, bool is_error) {
|
|||
|
||||
effect.$shader->setUniform("is_error", $hit_error);
|
||||
effect.run();
|
||||
}
|
||||
|
||||
void GUI::update_status(GameEngine &game, size_t line_length, bool is_error) {
|
||||
configure_status_shader(line_length, is_error);
|
||||
|
||||
$status = fmt::format(L"HP {}\nRounds {}\nStreaks {}\nDeaths {}",
|
||||
game.hit_points, game.rounds,
|
||||
|
@ -131,3 +133,20 @@ void GUI::building() {
|
|||
output(">>>> Will it Build?");
|
||||
sound::play("building");
|
||||
}
|
||||
|
||||
void GUI::handle_events() {
|
||||
// is this a main event loop
|
||||
while(const auto ev = $window.pollEvent()) {
|
||||
if(ev->is<sf::Event::Closed>()) {
|
||||
fmt::print("Exiting...\n");
|
||||
$window.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::startup() {
|
||||
$window.setPosition({0,0});
|
||||
|
||||
$window.setFramerateLimit(FRAME_LIMIT);
|
||||
$window.setVerticalSyncEnabled(VSYNC);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue