The new SFMLGui is now worked into the code and barely works. Cleanup is next.
This commit is contained in:
parent
70d1389c54
commit
4bd2d12219
5 changed files with 41 additions and 121 deletions
42
sfmlgui.cpp
42
sfmlgui.cpp
|
@ -30,9 +30,9 @@ void SFMLGui::ImGui_update() {
|
|||
|
||||
TextColored(ImVec4(1,1,0,1), "Build Log");
|
||||
BeginChild("Scrolling");
|
||||
for(int n = 0; n < 50; n++) {
|
||||
TextWrapped("%04d: Some Text", n);
|
||||
}
|
||||
for(string &line : log) {
|
||||
TextWrapped(line.c_str());
|
||||
}
|
||||
EndChild();
|
||||
End();
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ sf::Vector2f translate(int x, int y) {
|
|||
}
|
||||
|
||||
|
||||
void SFMLGui::write_text(int x, int y, const char *content) {
|
||||
void SFMLGui::write_text(int x, int y, string content) {
|
||||
sf::Vector2f position = translate(x,y);
|
||||
sf::Text text;
|
||||
text.setFont(font);
|
||||
|
@ -107,25 +107,24 @@ void SFMLGui::update_entities() {
|
|||
face_box.setFillColor(sf::Color(200, 250, 200));
|
||||
window.draw(face_box);
|
||||
|
||||
sf::RectangleShape hp_bar(translate(32,2));
|
||||
constexpr int hp_box_len = 44;
|
||||
|
||||
int current_hp = (float(game.hit_points) / float(game.starting_hp)) * float(hp_box_len);
|
||||
|
||||
sf::RectangleShape hp_bar(translate(current_hp,2));
|
||||
hp_bar.setPosition(translate(2,21));
|
||||
hp_bar.setFillColor(sf::Color(100, 250, 50));
|
||||
window.draw(hp_bar);
|
||||
|
||||
sf::RectangleShape hp_box(translate(44,2));
|
||||
sf::RectangleShape hp_box(translate(hp_box_len,2));
|
||||
hp_box.setPosition(translate(2,21));
|
||||
hp_box.setOutlineColor(sf::Color(100, 200, 50));
|
||||
hp_box.setOutlineThickness(10);
|
||||
hp_box.setFillColor(sf::Color::Transparent);
|
||||
window.draw(hp_box);
|
||||
|
||||
write_text(2, 18, "HP 222");
|
||||
// rounds text
|
||||
write_text(9, 18, "Rounds 333");
|
||||
// // streaks text
|
||||
write_text(21, 18, "Streaks 444");
|
||||
// // deaths text
|
||||
write_text(33, 18, "Deaths 555");
|
||||
string status = fmt::format("HP {} Rounds {} Streaks {} Deaths XXX", game.hit_points, game.rounds, game.streak);
|
||||
write_text(2, 18, status);
|
||||
|
||||
if(show_build_log) {
|
||||
ImGui_update();
|
||||
|
@ -135,10 +134,18 @@ void SFMLGui::update_entities() {
|
|||
show_build_log = window_active_out;
|
||||
}
|
||||
|
||||
SFMLGui::SFMLGui() : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings) {
|
||||
SFMLGui::SFMLGui(GameEngine &g) : window(sf::VideoMode(X_DIM, Y_DIM), "Turing's Tarpit", sf::Style::None, settings), game(g)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SFMLGui::update_log(vector<string> &lines) {
|
||||
log.clear();
|
||||
for(string &line : lines) {
|
||||
log.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
void SFMLGui::startup() {
|
||||
fmt::print("Setting up a window for you...\n");
|
||||
settings.antialiasingLevel = 8;
|
||||
|
@ -152,13 +159,6 @@ void SFMLGui::startup() {
|
|||
window.setFramerateLimit(FPS);
|
||||
window.setVerticalSyncEnabled(true);
|
||||
ImGui_setup();
|
||||
|
||||
// fake image here
|
||||
if(!texture.loadFromFile("./assets/turing_tarpit_main_screen.png")) {
|
||||
fmt::println("Error loading sprite!");
|
||||
}
|
||||
texture.setSmooth(true);
|
||||
background.setTexture(texture);
|
||||
}
|
||||
|
||||
bool SFMLGui::is_open() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue