Skip to content

Commit

Permalink
Fixed text overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
lud99 committed Jul 30, 2023
1 parent c093bdf commit 24058c7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
36 changes: 31 additions & 5 deletions source/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "Graphics/BasicVertices.h"
#include "Graphics/LineRenderer.h"
Expand Down Expand Up @@ -36,6 +41,12 @@ float lerp(float a, float b, float t)
return a * (1.0 - t) + (b * t);
}

bool IsApplet()
{
AppletType at = appletGetAppletType();
return (at != AppletType_Application && at != AppletType_SystemApplication);
}

void Map::Init()
{
Log("LoadFromJSON ");
Expand Down Expand Up @@ -496,11 +507,25 @@ void Map::Render()
}

// Toggle QR code
if (padGetButtonsDown(m_Pad) & HidNpadButton_X)
if ((padGetButtonsDown(m_Pad) & HidNpadButton_X) && IsApplet()) // Fails to get local ip adress in application mode
{
if (!m_QrCodeImage.m_Show)
{
u32 ip = gethostid();
Log("Checking internet connection");

/*char *ipBuffer;
char hostbuffer[256];
gethostname(hostbuffer, sizeof(hostbuffer));
struct hostent* host_entry = gethostbyname(hostbuffer);
ipBuffer = inet_ntoa(*((struct in_addr*)
host_entry->h_addr_list[0]));
std::string ipAdress = ipBuffer;*/


uint32_t ip = gethostid();

if (ip == INADDR_LOOPBACK)
{
Log("Not connected to internet. Cant generate Qr code");
Expand Down Expand Up @@ -528,6 +553,7 @@ void Map::Render()

m_Font.m_ViewMatrix = &m_ViewMatrix;

Log("Creating qr code and saving it");
std::string url = "http://" + ipString + ":1234/" + filename;
std::string filepath = "sdmc:/switch/totk-unexplored/" + filename;
SaveMapImage(filepath);
Expand Down Expand Up @@ -559,15 +585,15 @@ void Map::Render()

if (!m_Legend->m_IsOpen && !m_ObjectInfo->m_IsOpen && SavefileIO::Get().LoadedSavefile)
m_Font.AddTextToBatch("Press B to open legend", glm::vec2(m_ScreenLeft + 20, m_ScreenTop - 30), 0.5f);
if (!m_QrCodeImage.m_Show && SavefileIO::Get().LoadedSavefile)
if (!m_QrCodeImage.m_Show && SavefileIO::Get().LoadedSavefile && IsApplet())
m_Font.AddTextToBatch("Press X show QR Code", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 30), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT);

if (SavefileIO::Get().LoadedSavefile)
{
if (SavefileIO::Get().GameIsRunning)
{
m_Font.AddTextToBatch("Totk is running.", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 30), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT);
m_Font.AddTextToBatch("Loaded older save", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 60), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT);
m_Font.AddTextToBatch("Totk is running.", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 60), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT);
m_Font.AddTextToBatch("Loaded older save", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 90), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT);
}

float bottomTextX = m_ScreenRight - 30;
Expand Down
33 changes: 30 additions & 3 deletions source/Network/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
#include <iostream>
#include <fstream>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <unistd.h>
#include <cstdint>
Expand Down Expand Up @@ -32,8 +39,28 @@ void HttpServer::Stop()
void HttpServer::ThreadEntryPoint(int port)
{
// Check if online
u32 ip = gethostid();
if (ip == INADDR_LOOPBACK) // Offline
// char *ipBuffer;
// char hostbuffer[256];
// gethostname(hostbuffer, sizeof(hostbuffer));
// struct hostent* host_entry = gethostbyname(hostbuffer);

// ipBuffer = inet_ntoa(*((struct in_addr*)
// host_entry->h_addr_list[0]));

// std::string ipAdress = ipBuffer;


// std::cout << ipAdress << "\n";

// if (ipAdress == "127.0.0.1")
// {
// Log("Not connected to internet, not starting server");
// return;
// }

// Check if online
uint32_t ip = gethostid();
if (ip == INADDR_LOOPBACK)
return;

// Create socket
Expand All @@ -49,7 +76,7 @@ void HttpServer::ThreadEntryPoint(int port)
Log("Error calling fcntl");
// handle the error. By the way, I've never seen fcntl fail in this way
}

// Prepare the sockaddr_in structure
m_Server.sin_family = AF_INET; // TCP
m_Server.sin_addr.s_addr = INADDR_ANY;
Expand Down

0 comments on commit 24058c7

Please sign in to comment.