A really bad quick SFML based UI to get started with the FTXUI removal, and a slight reworking of the default .tarpit.json so that it's just a sample and I can use my own config for my dev and have different sounds.

master
Zed A. Shaw 4 months ago
parent 015b4aac45
commit df6944b0fb
  1. 1
      .gitignore
  2. 2
      .tarpit_sample.json
  3. BIN
      assets/sprite.png
  4. 69
      sfmltest.cpp

1
.gitignore vendored

@ -4,6 +4,7 @@
*.sqlite3-wal
*.sqlite3-shm
debug
imgui.ini
coverage/
.coverage
builddir

@ -3,7 +3,7 @@
"you_died": "./assets/you_died.mp3",
"build_works": "./assets/build_works.mp3",
"build_failed": "./assets/build_failed.mp3",
"building": "./assets/nothing.mp3"
"building": "./assets/building.mp3"
},
"git_path": ".\\",
"build_cmd": "meson compile -C builddir"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

@ -10,30 +10,53 @@
#include <SFML/Audio.hpp>
#include <SFML/Window/Event.hpp>
using namespace ImGui;
constexpr int FPS=30;
constexpr int X_DIM = 1920 / 2;
constexpr int Y_DIM = 1080 / 2;
bool window_active_out = true;
void ImGui_setup(sf::RenderWindow &window) {
bool res = ImGui::SFML::Init(window);
bool res = SFML::Init(window);
fmt::println("IMGUI returned {}", res);
}
void ImGui_update(sf::RenderWindow &window, sf::Clock &deltaClock, sf::Time &tick) {
ImGui::SFML::Update(window, deltaClock.restart());
// ImGui::ShowDemoWindow();
ImGui::Begin("Clock");
sf::Vector2u size = window.getSize();
ImGui::SetWindowPos(ImVec2(size.x - 150, 0));
ImGui::SetWindowSize(ImVec2(150, 50));
std::string msg = fmt::format("Time: {}\n", tick.asSeconds());
ImGui::Button(msg.c_str());
ImGui::End();
SFML::Update(window, deltaClock.restart());
SetNextWindowPos(ImVec2(0, size.y / 2));
SetNextWindowSize(ImVec2(size.x, size.y / 2));
Begin("Turing's Tarpit", &window_active_out);
// HP | Hits Taken | Round | Streak
Text("HP X"); SameLine();
Text("Hits Taken X"); SameLine();
Text("Round X"); SameLine();
Text("Streak X");
// HP BAR
float hp = 50.0f;
SliderFloat("HP", &hp, 0.0f, 100.0f);
// Build Log
TextColored(ImVec4(1,1,0,1), "Build Log");
BeginChild("Scrolling");
for(int n = 0; n < 50; n++) {
TextWrapped("%04d: Some Text", n);
}
EndChild();
// image placeholder
End();
}
void Window_update(sf::RenderWindow &window) {
void Window_update(sf::RenderWindow &window, sf::Sprite &player) {
window.clear();
ImGui::SFML::Render(window);
window.draw(player);
SFML::Render(window);
window.display();
}
@ -42,7 +65,7 @@ void Handle_events(sf::RenderWindow &window) {
// is this a main event loop
while (window.pollEvent(event)) {
ImGui::SFML::ProcessEvent(window, event);
SFML::ProcessEvent(window, event);
switch(event.type) {
@ -62,14 +85,17 @@ void Handle_events(sf::RenderWindow &window) {
}
}
sf::Time Update_entities(sf::RenderWindow &window, sf::Clock &clock, sf::Clock &deltaClock, sf::Time &tick) {
sf::Time Update_entities(sf::RenderWindow &window, sf::Sprite &player, sf::Clock &clock, sf::Clock &deltaClock, sf::Time &tick) {
sf::Vector2u winSize = window.getSize();
float timeStep = 1.0f / FPS;
sf::Time since = clock.getElapsedTime();
sf::Time nextTick = since - tick > sf::seconds(1) ? since : tick;
player.setPosition(winSize.x/2, 0);
player.setScale({2.0f, 2.0f});
ImGui_update(window, deltaClock, tick);
Window_update(window);
Window_update(window, player);
return nextTick;
}
@ -91,12 +117,21 @@ int main() {
sf::Clock deltaClock;
sf::Clock clock;
sf::Time tick = clock.getElapsedTime();
sf::Texture texture;
sf::Sprite player;
// fake image here
if(!texture.loadFromFile("./assets/sprite.png")) {
fmt::println("Error loading sprite!");
}
texture.setSmooth(true);
player.setTexture(texture);
while (window.isOpen()) {
while (window.isOpen() && window_active_out) {
Handle_events(window);
// preparing for refactoring this into a class or struct for everything
tick = Update_entities(window, clock, deltaClock, tick);
tick = Update_entities(window, player, clock, deltaClock, tick);
}
ImGui::SFML::Shutdown();
SFML::Shutdown();
}

Loading…
Cancel
Save