summaryrefslogtreecommitdiffstats
path: root/src/Render.cpp
diff options
context:
space:
mode:
authorElisey Puzko <puzko.e02@gmail.com>2018-02-20 11:09:39 +0100
committerElisey Puzko <puzko.e02@gmail.com>2018-02-20 11:09:39 +0100
commit99354db9db9be0f921980f081ee7ed6515d2dcdc (patch)
treec48ef29357234ea618472bf3ec796c03b7f2a647 /src/Render.cpp
parentAnother attempt at increasing readability (diff)
downloadAltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.tar
AltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.tar.gz
AltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.tar.bz2
AltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.tar.lz
AltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.tar.xz
AltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.tar.zst
AltCraft-99354db9db9be0f921980f081ee7ed6515d2dcdc.zip
Diffstat (limited to '')
-rw-r--r--src/Render.cpp329
1 files changed, 166 insertions, 163 deletions
diff --git a/src/Render.cpp b/src/Render.cpp
index d126326..c5c295d 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -186,10 +186,10 @@ void Render::HandleEvents() {
switch (event.key.keysym.scancode) {
case SDL_SCANCODE_ESCAPE: {
auto state = GlobalState::GetState();
- if (state == State::Playing ||
- state == State::Inventory) {
+ if (state == State::Playing) {
GlobalState::SetState(State::Paused);
} else if (state == State::Paused ||
+ state == State::Inventory ||
state == State::Chat) {
GlobalState::SetState(State::Playing);
} else if (state == State::MainMenu) {
@@ -216,10 +216,8 @@ void Render::HandleEvents() {
auto state = GlobalState::GetState();
if (state == State::Playing) {
GlobalState::SetState(State::Chat);
- SetMouseCapture(false);
} else if (state == State::Chat) {
GlobalState::SetState(State::Playing);
- SetMouseCapture(true);
}
}
@@ -286,7 +284,6 @@ void Render::SetMouseCapture(bool IsCaptured) {
}
void Render::Update() {
-
HandleEvents();
if (HasFocus && GlobalState::GetState() == State::Playing) UpdateKeyboard();
if (isMouseCaptured) HandleMouseCapture();
@@ -359,192 +356,198 @@ void Render::RenderGui() {
switch (GlobalState::GetState()) {
- case State::MainMenu: {
- ImGui::SetNextWindowPosCenter();
- ImGui::Begin("Menu", 0, windowFlags);
- static char buff[512] = "127.0.0.1";
- static int port = 25565;
- static char buffName[512] = "HelloOne";
- if (ImGui::Button("Connect")) {
- PUSH_EVENT("ConnectToServer", std::make_tuple(std::string(buff),
- (unsigned short) port, std::string(buffName)));
- }
- ImGui::InputText("Username", buffName, 512);
- ImGui::InputText("Address", buff, 512);
- ImGui::InputInt("Port", &port);
- ImGui::Separator();
- if (ImGui::Button("Exit"))
- PUSH_EVENT("Exit",0);
- ImGui::End();
- break;
- }
- case State::Loading:
- break;
- case State::Chat: {
- ImGui::SetNextWindowPosCenter();
- ImGui::Begin("Chat", 0, windowFlags);
- for (const auto& msg : chatMessages) {
- ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,1,1,1));
- ImGui::TextWrapped("%s", msg.c_str());
- ImGui::PopStyleColor();
- }
- static char buff[256];
- ImGui::InputText("", buff, 256);
- ImGui::SameLine();
- if (ImGui::Button("Send")) {
- PUSH_EVENT("SendChatMessage", std::string(buff));
+ case State::MainMenu: {
+ ImGui::SetNextWindowPosCenter();
+ ImGui::Begin("Menu", 0, windowFlags);
+ static char buff[512] = "127.0.0.1";
+ static int port = 25565;
+ static char buffName[512] = "HelloOne";
+ if (ImGui::Button("Connect")) {
+ PUSH_EVENT("ConnectToServer", std::make_tuple(std::string(buff),
+ (unsigned short) port, std::string(buffName)));
+ }
+ ImGui::InputText("Username", buffName, 512);
+ ImGui::InputText("Address", buff, 512);
+ ImGui::InputInt("Port", &port);
+ ImGui::Separator();
+ if (ImGui::Button("Exit"))
+ PUSH_EVENT("Exit",0);
+ ImGui::End();
+ break;
}
- ImGui::End();
- break;
- }
- case State::Inventory: {
- auto renderSlot = [](const SlotDataType &slot, int i) -> bool {
- return ImGui::Button(((slot.BlockId == -1 ? " ##" :
- AssetManager::Instance().GetAssetNameByBlockId(BlockId{ (unsigned short)slot.BlockId,0 }) + " x" + std::to_string(slot.ItemCount) + "##")
- + std::to_string(i)).c_str());
- };
- ImGui::SetNextWindowPosCenter();
- ImGui::Begin("Inventory", 0, windowFlags);
- Window& inventory = world->GameStatePtr()->playerInventory;
- //Hand and drop slots
- if (renderSlot(inventory.handSlot, -1)) {
- }
- ImGui::SameLine();
- if (ImGui::Button("Drop")) {
- inventory.MakeClick(-1, true, true);
- }
- ImGui::SameLine();
- ImGui::Text("Hand slot and drop mode");
- ImGui::Separator();
- //Crafting
- if (renderSlot(inventory.slots[1], 1)) {
- inventory.MakeClick(1, true);
- }
- ImGui::SameLine();
- if (renderSlot(inventory.slots[2], 2)) {
- inventory.MakeClick(2, true);
- }
- //Crafting result
- ImGui::SameLine();
- ImGui::Text("Result");
- ImGui::SameLine();
- if (renderSlot(inventory.slots[0], 0)) {
- inventory.MakeClick(0, true);
- }
- //Crafting second line
- if (renderSlot(inventory.slots[3], 3)) {
- inventory.MakeClick(3, true);
- }
- ImGui::SameLine();
- if (renderSlot(inventory.slots[4], 4)) {
- inventory.MakeClick(4, true);
- }
- ImGui::Separator();
- //Armor and offhand
- for (int i = 5; i < 8 + 1; i++) {
- if (renderSlot(inventory.slots[i], i)) {
- inventory.MakeClick(i, true);
+ case State::Loading:
+ break;
+
+ case State::Chat: {
+ ImGui::SetNextWindowPosCenter();
+ ImGui::Begin("Chat", 0, windowFlags);
+ for (const auto& msg : chatMessages) {
+ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,1,1,1));
+ ImGui::TextWrapped("%s", msg.c_str());
+ ImGui::PopStyleColor();
}
+ static char buff[256];
+ ImGui::InputText("", buff, 256);
ImGui::SameLine();
+ if (ImGui::Button("Send")) {
+ PUSH_EVENT("SendChatMessage", std::string(buff));
+ }
+ ImGui::End();
+ break;
}
- if (renderSlot(inventory.slots[45], 45)) {
- inventory.MakeClick(45, true);
- }
- ImGui::SameLine();
- ImGui::Text("Armor and offhand");
- ImGui::Separator();
- for (int i = 36; i < 44 + 1; i++) {
- if (renderSlot(inventory.slots[i], i)) {
- inventory.MakeClick(i, true);
+
+ case State::Inventory: {
+ auto renderSlot = [](const SlotDataType &slot, int i) -> bool {
+ return ImGui::Button(((slot.BlockId == -1 ? " ##" :
+ AssetManager::Instance().GetAssetNameByBlockId(BlockId{ (unsigned short)slot.BlockId,0 }) + " x" + std::to_string(slot.ItemCount) + "##")
+ + std::to_string(i)).c_str());
+ };
+ ImGui::SetNextWindowPosCenter();
+ ImGui::Begin("Inventory", 0, windowFlags);
+ Window& inventory = world->GameStatePtr()->playerInventory;
+ //Hand and drop slots
+ if (renderSlot(inventory.handSlot, -1)) {
+
}
ImGui::SameLine();
- }
- ImGui::Text("Hotbar");
- ImGui::Separator();
- ImGui::Text("Main inventory");
- for (int i = 9; i < 17 + 1; i++) {
- if (renderSlot(inventory.slots[i], i)) {
- inventory.MakeClick(i, true);
+ if (ImGui::Button("Drop")) {
+ inventory.MakeClick(-1, true, true);
}
ImGui::SameLine();
- }
- ImGui::Text("");
- for (int i = 18; i < 26 + 1; i++) {
- if (renderSlot(inventory.slots[i], i)) {
- inventory.MakeClick(i, true);
+ ImGui::Text("Hand slot and drop mode");
+ ImGui::Separator();
+ //Crafting
+ if (renderSlot(inventory.slots[1], 1)) {
+ inventory.MakeClick(1, true);
}
ImGui::SameLine();
- }
- ImGui::Text("");
- for (int i = 27; i < 35 + 1; i++) {
- if (renderSlot(inventory.slots[i], i)) {
- inventory.MakeClick(i, true);
+ if (renderSlot(inventory.slots[2], 2)) {
+ inventory.MakeClick(2, true);
}
+ //Crafting result
ImGui::SameLine();
- }
- ImGui::End();
+ ImGui::Text("Result");
+ ImGui::SameLine();
+ if (renderSlot(inventory.slots[0], 0)) {
+ inventory.MakeClick(0, true);
+ }
+ //Crafting second line
+ if (renderSlot(inventory.slots[3], 3)) {
+ inventory.MakeClick(3, true);
+ }
+ ImGui::SameLine();
+ if (renderSlot(inventory.slots[4], 4)) {
+ inventory.MakeClick(4, true);
+ }
+ ImGui::Separator();
+ //Armor and offhand
+ for (int i = 5; i < 8 + 1; i++) {
+ if (renderSlot(inventory.slots[i], i)) {
+ inventory.MakeClick(i, true);
+ }
+ ImGui::SameLine();
+ }
+ if (renderSlot(inventory.slots[45], 45)) {
+ inventory.MakeClick(45, true);
+ }
+ ImGui::SameLine();
+ ImGui::Text("Armor and offhand");
+ ImGui::Separator();
+ for (int i = 36; i < 44 + 1; i++) {
+ if (renderSlot(inventory.slots[i], i)) {
+ inventory.MakeClick(i, true);
+ }
+ ImGui::SameLine();
+ }
+ ImGui::Text("Hotbar");
+ ImGui::Separator();
+ ImGui::Text("Main inventory");
+ for (int i = 9; i < 17 + 1; i++) {
+ if (renderSlot(inventory.slots[i], i)) {
+ inventory.MakeClick(i, true);
+ }
+ ImGui::SameLine();
+ }
+ ImGui::Text("");
+ for (int i = 18; i < 26 + 1; i++) {
+ if (renderSlot(inventory.slots[i], i)) {
+ inventory.MakeClick(i, true);
+ }
+ ImGui::SameLine();
+ }
+ ImGui::Text("");
+ for (int i = 27; i < 35 + 1; i++) {
+ if (renderSlot(inventory.slots[i], i)) {
+ inventory.MakeClick(i, true);
+ }
+ ImGui::SameLine();
+ }
+ ImGui::End();
- break;
- }
- case State::Paused: {
- ImGui::SetNextWindowPosCenter();
- ImGui::Begin("Pause Menu", 0, windowFlags);
- if (ImGui::Button("Continue")) {
- GlobalState::SetState(State::Playing);
+ break;
}
- ImGui::Separator();
- static float distance = world->MaxRenderingDistance;
- ImGui::SliderFloat("Render distance", &distance, 1.0f, 16.0f);
- static float sense = sensetivity;
- ImGui::SliderFloat("Sensetivity", &sense, 0.01f, 1.0f);
+ case State::Paused: {
+ ImGui::SetNextWindowPosCenter();
+ ImGui::Begin("Pause Menu", 0, windowFlags);
+ if (ImGui::Button("Continue")) {
+ GlobalState::SetState(State::Playing);
+ }
+ ImGui::Separator();
+ static float distance = world->MaxRenderingDistance;
+ ImGui::SliderFloat("Render distance", &distance, 1.0f, 16.0f);
+
+ static float sense = sensetivity;
+ ImGui::SliderFloat("Sensetivity", &sense, 0.01f, 1.0f);
- static float targetFps = 60.0f;
- ImGui::SliderFloat("Target FPS", &targetFps, 1.0f, 300.0f);
+ static float targetFps = 60.0f;
+ ImGui::SliderFloat("Target FPS", &targetFps, 1.0f, 300.0f);
- static bool wireframe = isWireframe;
+ static bool wireframe = isWireframe;
- ImGui::Checkbox("Wireframe", &wireframe);
+ ImGui::Checkbox("Wireframe", &wireframe);
- static bool vsync = false;
+ static bool vsync = false;
- ImGui::Checkbox("VSync", &vsync);
+ ImGui::Checkbox("VSync", &vsync);
- if (ImGui::Button("Apply settings")) {
- if (distance != world->MaxRenderingDistance) {
- world->MaxRenderingDistance = distance;
- PUSH_EVENT("UpdateSectionsRender", 0);
- }
+ if (ImGui::Button("Apply settings")) {
+ if (distance != world->MaxRenderingDistance) {
+ world->MaxRenderingDistance = distance;
+ PUSH_EVENT("UpdateSectionsRender", 0);
+ }
- if (sense != sensetivity)
- sensetivity = sense;
+ if (sense != sensetivity)
+ sensetivity = sense;
- isWireframe = wireframe;
- timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / targetFps * 1000.0));
- if (vsync) {
- timer.SetDelayLength(std::chrono::milliseconds(0));
- SDL_GL_SetSwapInterval(1);
- } else
- SDL_GL_SetSwapInterval(0);
+ isWireframe = wireframe;
+ timer.SetDelayLength(std::chrono::duration<double, std::milli>(1.0 / targetFps * 1000.0));
+ if (vsync) {
+ timer.SetDelayLength(std::chrono::milliseconds(0));
+ SDL_GL_SetSwapInterval(1);
+ } else
+ SDL_GL_SetSwapInterval(0);
+ }
+ ImGui::Separator();
+
+ if (ImGui::Button("Disconnect")) {
+ PUSH_EVENT("Disconnect", std::string("Disconnected by user"));
+ }
+ ImGui::End();
+ break;
}
- ImGui::Separator();
- if (ImGui::Button("Disconnect")) {
- PUSH_EVENT("Disconnect", std::string("Disconnected by user"));
+ case State::InitialLoading:
+ break;
+
+ case State::Playing: {
+ ImGui::SetNextWindowPosCenter();
+ ImGui::Begin("",0,windowFlags);
+ ImGui::End();
+ break;
}
- ImGui::End();
- break;
- }
- case State::InitialLoading:
- break;
- case State::Playing: {
- ImGui::SetNextWindowPosCenter();
- ImGui::Begin("",0,windowFlags);
- ImGui::End();
- break;
- }
}
ImGui::Render();