Real Update System, Open to LAN, and Fix Connect Button - v2.0.8

This commit is contained in:
Michael Howard 2026-04-23 18:44:59 -05:00
parent de7c60d9d7
commit 8983f05b2a
3 changed files with 82 additions and 39 deletions

Binary file not shown.

Binary file not shown.

View File

@ -775,7 +775,7 @@ int main(void)
// By default, windows have minimize, maximize, and close buttons on the top bar.
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
InitWindow(screenWidth, screenHeight, "MorriCraft v2.0.7");
InitWindow(screenWidth, screenHeight, "MorriCraft v2.0.8");
LoadConfig();
SetExitKey(KEY_NULL); // Prevent ESC from closing the window
@ -1631,24 +1631,53 @@ int main(void)
if (isNoteHovered && IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) currentState = UPDATE_NOTES;
} else if (currentState == DOWNLOADING_UPDATE) {
downloadProgress += 0.003f;
DrawRectangle(0, 0, currentWidth, currentHeight, (Color){ 20, 20, 20, 255 });
DrawTextEx(customFont, "REPLACING ALL SYSTEM FILES...", (Vector2){ (float)currentWidth/2 - 200, (float)currentHeight/2 - 40 }, 24, 1.0f, YELLOW);
static bool startedDownload = false;
static bool downloadFailed = false;
static float fakeProgress = 0.0f;
// Progress Bar
if (!startedDownload) {
startedDownload = true;
// REAL DOWNLOAD ATTEMPT
std::string binaryUrl = "https://git.linology.tech/michael/MorriCraft/raw/branch/master/build-linux/MorriCraft";
std::string versionUrl = "https://git.linology.tech/michael/MorriCraft/raw/branch/master/version.txt";
// We run these in background-ish or just block for a bit since it's a small app
int r1 = system(("curl -L -s -o MorriCraft.new " + binaryUrl).c_str());
int r2 = system(("curl -L -s -o version.txt.new " + versionUrl).c_str());
if (r1 == 0 && r2 == 0) {
system("chmod +x MorriCraft.new");
system("mv MorriCraft MorriCraft.old 2>/dev/null");
system("mv MorriCraft.new MorriCraft");
system("mv version.txt.new version.txt");
system("cp version.txt assets/version.txt 2>/dev/null");
fakeProgress = 1.0f;
} else {
downloadFailed = true;
}
}
DrawRectangle(0, 0, currentWidth, currentHeight, (Color){ 20, 20, 20, 255 });
if (downloadFailed) {
DrawTextEx(customFont, "DOWNLOAD FAILED! Check internet connection.", (Vector2){ (float)currentWidth/2 - 250, (float)currentHeight/2 - 40 }, 24, 1.0f, RED);
Rectangle backBtn = { (float)currentWidth/2 - 100, (float)currentHeight/2 + 20, 200, 40 };
if (CheckCollisionPointRec(mousePos, backBtn) && IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {
currentState = MAIN_MENU;
startedDownload = false;
downloadFailed = false;
}
DrawRectangleRec(backBtn, DARKGRAY);
DrawTextEx(customFont, "BACK", (Vector2){ backBtn.x + 70, backBtn.y + 10 }, 20, 1.0f, WHITE);
} else {
fakeProgress += 0.001f; // Slow visual for user
if (fakeProgress > 1.0f) fakeProgress = 1.0f;
DrawTextEx(customFont, "DOWNLOADING & REPLACING SYSTEM FILES...", (Vector2){ (float)currentWidth/2 - 250, (float)currentHeight/2 - 40 }, 24, 1.0f, YELLOW);
int bw = 450, bh = 30;
DrawRectangle(currentWidth/2 - bw/2, currentHeight/2, bw, bh, BLACK);
DrawRectangle(currentWidth/2 - bw/2, currentHeight/2, (int)(bw * downloadProgress), bh, GREEN);
DrawRectangleLines(currentWidth/2 - bw/2, currentHeight/2, bw, bh, GRAY);
DrawRectangle(currentWidth/2 - bw/2, currentHeight/2, (int)(bw * (fakeProgress > 0.9f ? 0.9f : fakeProgress)), bh, GREEN);
if (downloadProgress >= 1.0f) {
// Simulation of replacing files
std::ofstream vout("version.txt");
if (vout.is_open()) { vout << latestVersion; vout.close(); }
std::ofstream vout2("assets/version.txt");
if (vout2.is_open()) { vout2 << latestVersion; vout2.close(); }
// Show Restart Popup
if (fakeProgress >= 1.0f) {
DrawRectangle(0, 0, currentWidth, currentHeight, (Color){ 0, 0, 0, 230 });
int pw = 450, ph = 200;
Rectangle pBox = { (float)currentWidth/2 - pw/2, (float)currentHeight/2 - ph/2, (float)pw, (float)ph };
@ -1659,12 +1688,9 @@ int main(void)
DrawTextEx(customFont, "PLEASE RESTART THE CLIENT.", (Vector2){ pBox.x + 60, pBox.y + 80 }, 20, 1.0f, WHITE);
Rectangle exitBtn = { pBox.x + pw/2 - 75, pBox.y + 130, 150, 40 };
bool isExitHovered = CheckCollisionPointRec(mousePos, exitBtn);
DrawRectangleRec(exitBtn, isExitHovered ? RED : MAROON);
if (CheckCollisionPointRec(mousePos, exitBtn) && IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) exit(0);
DrawRectangleRec(exitBtn, MAROON);
DrawTextEx(customFont, "EXIT GAME", (Vector2){ exitBtn.x + 30, exitBtn.y + 10 }, 20, 1.0f, WHITE);
if (isExitHovered && IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {
exit(0);
}
}
} else if (currentState == CONNECT_MENU) {
@ -1769,8 +1795,8 @@ int main(void)
DrawTexturePro(titleTexture, sourceRec, destRec, origin, 0.0f, WHITE);
EndMode2D();
// Show Version Number (v2.0.7) in Red
DrawTextEx(customFont, "v2.0.7", (Vector2){ (float)currentWidth - 140, (float)currentHeight - 40 }, 22, 1.0f, RED);
// Show Version Number (v2.0.8) in Red
DrawTextEx(customFont, "v2.0.8", (Vector2){ (float)currentWidth - 140, (float)currentHeight - 40 }, 22, 1.0f, RED);
// --- PLAYER NAME POPUP (IF MISSING) ---
if (playerName == "") {
@ -1849,7 +1875,7 @@ int main(void)
} else if (i == 1) { // Load World button
currentState = LOAD_WORLD_MENU;
} else if (i == 2) { // Connect button
// Future: Open Direct Connect UI
currentState = CONNECT_MENU;
} else if (i == 3) { // Options button
optionsReturnState = MAIN_MENU;
currentState = OPTIONS_MENU;
@ -2757,8 +2783,8 @@ int main(void)
// Draw dark overlay
DrawRectangle(0, 0, currentWidth, currentHeight, (Color){ 0, 0, 0, 150 });
const char* pButtons[] = { "Resume", "Options", "Save & Exit" };
int pNumButtons = 3;
const char* pButtons[] = { "Resume", "Open to LAN", "Options", "Save & Exit" };
int pNumButtons = 4;
int pBtnWidth = 400;
int pBtnHeight = 60;
int pBtnSpacing = 15;
@ -2784,10 +2810,27 @@ int main(void)
if (i == 0) { // Resume
currentState = GAMEPLAY;
DisableCursor();
} else if (i == 1) { // Options
} else if (i == 1) { // Open to LAN
if (serverSocket == INVALID_SOCKET_VAL) {
serverSocket = socket(AF_INET, SOCK_STREAM, 0);
if (serverSocket != INVALID_SOCKET_VAL) {
SetNonBlocking(serverSocket);
struct sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons(12345);
bind(serverSocket, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
listen(serverSocket, 5);
serverMode = true;
chatLog.push_back({ "World opened to LAN on port 12345", 5.0f });
currentState = GAMEPLAY;
DisableCursor();
}
}
} else if (i == 2) { // Options
optionsReturnState = PAUSE_MENU;
currentState = OPTIONS_MENU;
} else if (i == 2) { // Save & Exit
} else if (i == 3) { // Save & Exit
currentState = MAIN_MENU;
inventoryOpen = false;