summaryrefslogtreecommitdiff
path: root/src/port/ui/GameInfoWindow.cpp
blob: d7a9ecf2d9bc41ff521897942819d73bf141a905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "GameInfoWindow.h"
#include "UIWidgets.h"
#include "libultraship/src/Context.h"

#include <imgui.h>
#include <libultraship/libultraship.h>
#include "spdlog/spdlog.h"
#include <common_structs.h>
#include <defines.h>

extern "C" {
#include "../../../src/main.h"
#include "networking/networking.h"
}

namespace GameInfo {
GameInfoWindow::~GameInfoWindow() {
    SPDLOG_TRACE("destruct game info window");
}

void GameInfoWindow::InitElement() {
}

static s32 sReadyUpBool = false;

void GameInfoWindow::DrawElement() {
    const float framerate = ImGui::GetIO().Framerate;
    const float deltatime = ImGui::GetIO().DeltaTime;
    ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));

    static char username[NETWORK_USERNAME_LENGTH] = "TestUser";

    ImGui::Text("Username:");
    ImGui::InputText("##edit", username, IM_ARRAYSIZE(username));

    static char address[32] = "127.0.0.1:64010";
    static char addressCopy[32];
    strncpy(addressCopy, address, sizeof(addressCopy));
    addressCopy[sizeof(addressCopy) - 1] = '\0'; // Ensure null termination

    ImGui::Text("Host:");
    ImGui::InputText("##edit3", addressCopy, IM_ARRAYSIZE(addressCopy));

    if (ImGui::Button("Connect!")) {
        char* ip = NULL;
        uint16_t port = 0;

        char* token = strtok(addressCopy, ":");
        ip = token;

        token = strtok(NULL, ":");
        if (token != NULL) {
            port = (uint16_t) atoi(token);
        }

        gNetwork.enabled = true;
        ConnectToServer(ip, port, username);
    }

    char buttonLabel[32];

    if (sReadyUpBool) {
        strcpy(buttonLabel, "Lets Go!");
    } else {
        strcpy(buttonLabel, "Ready Up!");
    }

    if (ImGui::Button(buttonLabel)) {
        sReadyUpBool = !sReadyUpBool;
        networking_ready_up(sReadyUpBool);
    }

    if (gGamestate == RACING) {

         ImGui::Text("Player %f, %f, %f", gPlayers[0].pos[0], gPlayers[0].pos[1], gPlayers[0].pos[2]);

        for (int i = 0; i < NUM_PLAYERS; i++) {
            ImGui::Text("Player %d: type: %X, char: %d, rank: %d, hasAuthority: %d", i, gPlayers[i].type,
                        gPlayers[i].characterId, gPlayers[i].currentRank, gPlayers[i].nHasAuthority);
        }
    }
    ImGui::PopStyleColor();
}

void GameInfoWindow::UpdateElement() {
}
} // namespace GameInfo