feat(gui): add base dialogs
This commit is contained in:
parent
e1dc82e70f
commit
eb5e6c6db9
252
gui.c
252
gui.c
@ -5,6 +5,8 @@
|
||||
#include "gui.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dcimgui.h"
|
||||
#include "dcimgui_impl_sdl3.h"
|
||||
#include "dcimgui_impl_sdlrenderer3.h"
|
||||
@ -27,7 +29,9 @@ void Gui_Init(Gui_t *gui) {
|
||||
cImGui_ImplSDLRenderer3_Init(renderer);
|
||||
|
||||
gui->isPreferencesDialogOpen = false;
|
||||
gui->statusBarText = "Welcome to Tibia!";
|
||||
gui->isNewGameDialogOpen = false;
|
||||
gui->isJourneyOnwardDialogOpen = false;
|
||||
Gui_UpdateStatusBar(gui, "Welcome to Tibia!");
|
||||
}
|
||||
|
||||
void Gui_ProcessEvent(const SDL_Event *event) {
|
||||
@ -40,10 +44,13 @@ void Gui_StartRender() {
|
||||
ImGui_NewFrame();
|
||||
}
|
||||
|
||||
void Gui_Render(Gui_t *gui, ConfigParams_t *configParams) {
|
||||
void Gui_Render(Gui_t *gui, Network_t *network, ConfigParams_t *configParams) {
|
||||
Gui_RenderMainMenu(gui);
|
||||
Gui_RenderStatusBar(gui);
|
||||
|
||||
Gui_RenderPreferences_Dialog(gui, configParams);
|
||||
Gui_RenderNewGame_Dialog(gui, configParams, network);
|
||||
Gui_RenderJourneyOnward_Dialog(gui, configParams, network);
|
||||
}
|
||||
|
||||
void Gui_FinishRender() {
|
||||
@ -79,9 +86,11 @@ void Gui_RenderMainMenu(Gui_t *gui) {
|
||||
|
||||
if (ImGui_BeginMenu("Game")) {
|
||||
if (ImGui_MenuItem("New Game")) {
|
||||
gui->isNewGameDialogOpen = true;
|
||||
}
|
||||
|
||||
if (ImGui_MenuItem("Journey Onward")) {
|
||||
gui->isJourneyOnwardDialogOpen = true;
|
||||
}
|
||||
|
||||
if (ImGui_MenuItem("End Game")) {
|
||||
@ -191,7 +200,7 @@ void Gui_RenderPreferences_Dialog(Gui_t *gui, ConfigParams_t *configParams) {
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
ImGui_InputText("##Address", configParams->serverAddress, IM_ARRAYSIZE(configParams->serverAddress), 0);
|
||||
|
||||
// Server Address
|
||||
// Server Port
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
@ -266,3 +275,240 @@ void Gui_RenderPreferences_Dialog(Gui_t *gui, ConfigParams_t *configParams) {
|
||||
|
||||
ImGui_End();
|
||||
}
|
||||
|
||||
void Gui_RenderNewGame_Dialog(Gui_t *gui, const ConfigParams_t* configParams, Network_t *network) {
|
||||
if (!gui->isNewGameDialogOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ImGuiViewport *viewport = ImGui_GetMainViewport();
|
||||
const ImVec2 viewportCenter = {
|
||||
viewport->Pos.x + viewport->Size.x * 0.5f,
|
||||
viewport->Pos.y + viewport->Size.y * 0.5f
|
||||
};
|
||||
ImGui_SetNextWindowPosEx(viewportCenter, ImGuiCond_Appearing, (ImVec2){0.5f, 0.5f});
|
||||
ImGui_SetNextWindowSize((ImVec2){550, 0}, ImGuiCond_Always);
|
||||
|
||||
if (ImGui_Begin("New Game", &gui->isNewGameDialogOpen,
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) {
|
||||
if (ImGui_BeginTable("TopLayout", 2, ImGuiTableFlags_BordersInnerV)) {
|
||||
ImGui_TableSetupColumnEx("TopInputs", ImGuiTableColumnFlags_WidthStretch, 0.0f, 0);
|
||||
ImGui_TableSetupColumnEx("TopButtons", ImGuiTableColumnFlags_WidthFixed, 140.0f, 0);
|
||||
|
||||
ImGui_TableNextRow();
|
||||
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
if (ImGui_BeginTable("TopForm", 2, ImGuiTableFlags_SizingFixedFit)) {
|
||||
ImGui_TableSetupColumnEx("Label", ImGuiTableColumnFlags_WidthFixed, 90.0f, 0);
|
||||
ImGui_TableSetupColumn("Input", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
// Real Name
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Real Name:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
static char realName[64] = "";
|
||||
ImGui_InputText("##RealName", realName, sizeof(realName), 0);
|
||||
|
||||
// Location
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Location:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
static char location[64] = "";
|
||||
ImGui_InputText("##Location", location, sizeof(location), 0);
|
||||
|
||||
// E-Mail
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("E-Mail:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
static char email[64] = "";
|
||||
ImGui_InputText("##Email", email, sizeof(email), 0);
|
||||
|
||||
ImGui_EndTable();
|
||||
}
|
||||
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
|
||||
// "Create Character"
|
||||
if (ImGui_ButtonEx("Create Character", (ImVec2){-FLT_MIN, 0})) {
|
||||
Network_ConnectAndReportStatus(network, configParams, gui);
|
||||
}
|
||||
|
||||
ImGui_Dummy((ImVec2){0.0f, 10.0f}); // Spacing between buttons
|
||||
|
||||
// "Oops, Cancel"
|
||||
if (ImGui_ButtonEx("Oops, Cancel", (ImVec2){-FLT_MIN, 0})) {
|
||||
gui->isNewGameDialogOpen = false;
|
||||
}
|
||||
|
||||
ImGui_EndTable();
|
||||
}
|
||||
|
||||
ImGui_Spacing();
|
||||
ImGui_Separator();
|
||||
ImGui_Spacing();
|
||||
|
||||
if (ImGui_BeginTable("BottomLayout", 2, ImGuiTableFlags_BordersInnerV)) {
|
||||
ImGui_TableSetupColumnEx("BotInputs", ImGuiTableColumnFlags_WidthStretch, 0.0f, 0);
|
||||
ImGui_TableSetupColumnEx("BotVisuals", ImGuiTableColumnFlags_WidthFixed, 180.0f, 0);
|
||||
|
||||
ImGui_TableNextRow();
|
||||
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
if (ImGui_BeginTable("BotForm", 2, ImGuiTableFlags_SizingFixedFit)) {
|
||||
ImGui_TableSetupColumnEx("Label", ImGuiTableColumnFlags_WidthFixed, 130.0f, 0);
|
||||
ImGui_TableSetupColumn("Input", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
// Your Name
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Your Name:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
static char charName[64] = "";
|
||||
ImGui_InputText("##CharName", charName, sizeof(charName), 0);
|
||||
|
||||
// Your Sex (Radio Buttons)
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Your Sex:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
static int sex = 0;
|
||||
ImGui_RadioButtonIntPtr("male", &sex, 0);
|
||||
ImGui_SameLine();
|
||||
ImGui_RadioButtonIntPtr("female", &sex, 1);
|
||||
|
||||
// Enter Password
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Enter Password:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
static char pass1[64] = "";
|
||||
ImGui_InputText("##Pass1", pass1, sizeof(pass1), ImGuiInputTextFlags_Password);
|
||||
|
||||
// Retype Password
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Retype Password:");
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
static char pass2[64] = "";
|
||||
ImGui_InputText("##Pass2", pass2, sizeof(pass2), ImGuiInputTextFlags_Password);
|
||||
|
||||
ImGui_EndTable();
|
||||
}
|
||||
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
|
||||
// Calculate where the cursor is to draw the rectangle
|
||||
const ImVec2 p0 = ImGui_GetCursorScreenPos();
|
||||
float placeholderHeight = 90.0f; // Roughly matching the input area height
|
||||
ImVec2 p1 = { p0.x + 160.0f, p0.y + placeholderHeight };
|
||||
|
||||
// Draw Gray Rectangle
|
||||
ImDrawList* draw_list = ImGui_GetWindowDrawList();
|
||||
ImDrawList_AddRectFilled(draw_list,p0, p1, IM_COL32(200, 200, 200, 255));
|
||||
ImDrawList_AddRectFilled(draw_list, p0, p1, IM_COL32(100, 100, 100, 255));
|
||||
|
||||
// Add text "Placeholder" inside it just for clarity
|
||||
ImGui_SetCursorPosY(ImGui_GetCursorPosY() + placeholderHeight * 0.4f);
|
||||
ImGui_SetCursorPosX(ImGui_GetCursorPosX() + 40.0f);
|
||||
ImGui_TextColored((ImVec4){0.3f,0.3f,0.3f,1.0f}, "Character\nControls");
|
||||
|
||||
ImGui_EndTable();
|
||||
}
|
||||
}
|
||||
ImGui_End();
|
||||
}
|
||||
|
||||
void Gui_RenderJourneyOnward_Dialog(Gui_t *gui, ConfigParams_t *configParams, Network_t *network) {
|
||||
if (!gui->isJourneyOnwardDialogOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ImGuiViewport *viewport = ImGui_GetMainViewport();
|
||||
const ImVec2 viewportCenter = {
|
||||
viewport->Pos.x + viewport->Size.x * 0.5f,
|
||||
viewport->Pos.y + viewport->Size.y * 0.5f
|
||||
};
|
||||
ImGui_SetNextWindowPosEx(viewportCenter, ImGuiCond_Appearing, (ImVec2){0.5f, 0.5f});
|
||||
ImGui_SetNextWindowSize((ImVec2){380, 0}, ImGuiCond_Always);
|
||||
|
||||
if (ImGui_Begin("Journey Onward", &gui->isJourneyOnwardDialogOpen,
|
||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) {
|
||||
if (ImGui_BeginTable("Split", 2, ImGuiTableFlags_BordersInnerV)) {
|
||||
ImGui_TableSetupColumnEx("Data", ImGuiTableColumnFlags_WidthStretch, 0.0f, 0);
|
||||
ImGui_TableSetupColumnEx("Actions", ImGuiTableColumnFlags_WidthFixed, 100.0f, 0);
|
||||
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
|
||||
ImGui_Text("Player Data:");
|
||||
|
||||
if (ImGui_BeginTable("InputTable", 2, ImGuiTableFlags_SizingFixedFit)) {
|
||||
ImGui_TableSetupColumnEx("Label", ImGuiTableColumnFlags_WidthFixed, 110.0f, 0);
|
||||
ImGui_TableSetupColumn("Input", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
// Player Name
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Player Name:");
|
||||
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
ImGui_InputText("##PName", configParams->lastAccount, IM_ARRAYSIZE(configParams->lastAccount), 0);
|
||||
|
||||
// Player Password
|
||||
ImGui_TableNextRow();
|
||||
ImGui_TableSetColumnIndex(0);
|
||||
ImGui_AlignTextToFramePadding();
|
||||
ImGui_Text("Player Password:");
|
||||
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
ImGui_SetNextItemWidth(-FLT_MIN);
|
||||
ImGui_InputText("##PPass", configParams->lastPassword, IM_ARRAYSIZE(configParams->lastPassword),
|
||||
ImGuiInputTextFlags_Password);
|
||||
|
||||
ImGui_EndTable();
|
||||
}
|
||||
|
||||
ImGui_TableSetColumnIndex(1);
|
||||
|
||||
// Cancel
|
||||
if (ImGui_ButtonEx("Cancel", (ImVec2){-FLT_MIN, 0})) {
|
||||
gui->isJourneyOnwardDialogOpen = false;
|
||||
}
|
||||
|
||||
ImGui_Dummy((ImVec2){0.0f, 10.0f});
|
||||
|
||||
// Let's Go
|
||||
if (ImGui_ButtonEx("Let's Go", (ImVec2){-FLT_MIN, 0})) {
|
||||
gui->isJourneyOnwardDialogOpen = false;
|
||||
Network_ConnectAndReportStatus(network, configParams, gui);
|
||||
}
|
||||
|
||||
ImGui_EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui_End();
|
||||
}
|
||||
|
||||
void Gui_UpdateStatusBar(Gui_t *gui, const char *message) {
|
||||
strncpy(gui->statusBarText, message, sizeof(gui->statusBarText) - 1);
|
||||
gui->statusBarText[sizeof(gui->statusBarText) - 1] = '\0';
|
||||
}
|
||||
|
||||
11
gui.h
11
gui.h
@ -8,16 +8,19 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "network.h"
|
||||
|
||||
typedef struct Gui {
|
||||
bool isPreferencesDialogOpen;
|
||||
char* statusBarText;
|
||||
bool isNewGameDialogOpen;
|
||||
bool isJourneyOnwardDialogOpen;
|
||||
char statusBarText[255];
|
||||
} Gui_t;
|
||||
|
||||
void Gui_Init(Gui_t* gui);
|
||||
void Gui_ProcessEvent(const SDL_Event* event);
|
||||
void Gui_StartRender();
|
||||
void Gui_Render(Gui_t* gui, ConfigParams_t* configParams);
|
||||
void Gui_Render(Gui_t* gui, Network_t* network, ConfigParams_t* configParams);
|
||||
void Gui_FinishRender();
|
||||
void Gui_Shutdown();
|
||||
|
||||
@ -25,5 +28,9 @@ void Gui_RenderMainMenu(Gui_t* gui);
|
||||
void Gui_RenderStatusBar(const Gui_t* gui);
|
||||
|
||||
void Gui_RenderPreferences_Dialog(Gui_t* gui, ConfigParams_t* configParams);
|
||||
void Gui_RenderNewGame_Dialog(Gui_t* gui, const ConfigParams_t* configParams, Network_t* network);
|
||||
void Gui_RenderJourneyOnward_Dialog(Gui_t* gui, ConfigParams_t* configParams, Network_t* network);
|
||||
|
||||
void Gui_UpdateStatusBar(Gui_t* gui, const char* message);
|
||||
|
||||
#endif //TIBIA_GUI_H
|
||||
Loading…
x
Reference in New Issue
Block a user