* Add the CreateWorldScreen.

This commit is contained in:
iProgramInCpp
2023-08-02 22:36:23 +03:00
parent e5f942c194
commit 4c81c728f6
6 changed files with 153 additions and 5 deletions

View File

@@ -0,0 +1,110 @@
#include "CreateWorldScreen.hpp"
#include "SelectWorldScreen.hpp"
#include "ProgressScreen.hpp"
#include "Util.hpp"
CreateWorldScreen::CreateWorldScreen() :
m_textName(1, 0, 0, 0, 0, "", "Unnamed world"),
m_textSeed(2, 0, 0, 0, 0, ""),
m_btnBack(3, "Back"),
m_btnCreate(4, "Create!")
{
}
void CreateWorldScreen::init()
{
m_textName.m_width = m_textSeed.m_width = 200;
m_textName.m_height = m_textSeed.m_height = 20;
m_textName.m_xPos = m_textSeed.m_xPos = (m_width - 200) / 2;
m_textName.m_yPos = 60;
m_textSeed.m_yPos = 100;
m_btnBack.m_yPos = m_btnCreate.m_yPos = m_height - 30;
m_btnBack.m_width = m_btnCreate.m_width = 60;
m_btnBack.m_xPos = m_width / 2 - 64;
m_btnCreate.m_xPos = m_width / 2 + 4;
m_textInputs.push_back(&m_textName);
m_textInputs.push_back(&m_textSeed);
m_buttons.push_back(&m_btnBack);
m_buttons.push_back(&m_btnCreate);
m_buttonTabList.push_back(&m_btnBack);
m_buttonTabList.push_back(&m_btnCreate);
m_textName.init(m_pFont);
m_textSeed.init(m_pFont);
}
static char g_CreateWorldFilterArray[] = { '/','\n','\r','\x09','\0','\xC','`','?','*','\\','<','>','|','"',':' };
static std::string GetUniqueLevelName(LevelStorageSource* pSource, const std::string& in)
{
std::set<std::string> maps;
std::vector<LevelSummary> vls;
pSource->getLevelList(vls);
for (const auto& ls : vls)
{
maps.insert(ls.field_0);
}
std::string out = in;
while (maps.find(out) != maps.end())
out += "-";
return out;
}
void CreateWorldScreen::buttonClicked(Button* pButton)
{
if (pButton->field_30 == m_btnBack.field_30)
{
m_pMinecraft->setScreen(new SelectWorldScreen);
}
if (pButton->field_30 = m_btnCreate.field_30)
{
std::string nameStr = m_textName.m_text;
std::string seedStr = m_textSeed.m_text;
std::string levelNickname = Util::stringTrim(nameStr);
std::string levelUniqueName = levelNickname;
for (int i = 0; i < sizeof(g_CreateWorldFilterArray); i++)
{
std::string str;
str.push_back(g_CreateWorldFilterArray[i]);
Util::stringReplace(levelUniqueName, str, "");
}
levelUniqueName = GetUniqueLevelName(m_pMinecraft->m_pLevelStorageSource, levelUniqueName);
int seed = int(getEpochTimeS());
std::string seedThing = Util::stringTrim(seedStr);
if (!seedThing.empty())
{
int num;
if (sscanf(seedThing.c_str(), "%d", &num) > 0)
seed = num;
else
seed = Util::hashCode(seedThing);
}
m_pMinecraft->selectLevel(levelUniqueName, levelNickname, seed);
m_pMinecraft->hostMultiplayer();
m_pMinecraft->setScreen(new ProgressScreen);
}
}
void CreateWorldScreen::render(int mouseX, int mouseY, float f)
{
renderBackground();
Screen::render(mouseX, mouseY, f);
drawCenteredString(m_pFont, "Create New World", m_width / 2, 30, 0xFFFFFF);
drawString(m_pFont, "World name", m_textName.m_xPos, m_textName.m_yPos - 10, 0xDDDDDD);
drawString(m_pFont, "Seed for the World Generator", m_textSeed.m_xPos, m_textSeed.m_yPos - 10, 0xDDDDDD);
drawString(m_pFont, "Leave blank for a random seed", m_textSeed.m_xPos, m_textSeed.m_yPos + 22, 0x999999);
}

View File

@@ -0,0 +1,23 @@
#pragma once
#include "Screen.hpp"
#ifndef ORIGINAL_CODE
class CreateWorldScreen : public Screen
{
public:
CreateWorldScreen();
void init() override;
void buttonClicked(Button* pButton) override;
void render(int mouseX, int mouseY, float f) override;
public:
TextInputBox m_textName;
TextInputBox m_textSeed;
Button m_btnBack;
Button m_btnCreate;
};
#endif

View File

@@ -8,6 +8,7 @@
#include "SelectWorldScreen.hpp"
#include "DeleteWorldScreen.hpp"
#include "CreateWorldScreen.hpp"
#include "ProgressScreen.hpp"
#include "StartMenuScreen.hpp"
#include "Util.hpp"
@@ -96,6 +97,7 @@ void SelectWorldScreen::tick()
}
std::vector<std::string> userInput = m_pMinecraft->platform()->getUserInput();
std::string levelNickname = Util::stringTrim(userInput[0]);
std::string levelUniqueName = levelNickname;
@@ -188,9 +190,13 @@ void SelectWorldScreen::buttonClicked(Button* pButton)
{
if (pButton->field_30 == m_btnCreateNew.field_30)
{
#ifndef ORIGINAL_CODE
m_pMinecraft->setScreen(new CreateWorldScreen);
#else
m_pMinecraft->platform()->showDialog(AppPlatform::DLG_CREATE_WORLD);
m_pMinecraft->platform()->createUserInput();
field_130 = true;
#endif
}
if (pButton->field_30 == m_btnDelete.field_30)

View File

@@ -235,23 +235,24 @@ void TextInputBox::charPressed(int k)
void TextInputBox::render()
{
fill(m_xPos, m_yPos, m_xPos + m_width, m_yPos + m_height, 0xFF000000);
fill(m_xPos, m_yPos, m_xPos + m_width, m_yPos + m_height, 0xFFAAAAAA);
fill(m_xPos + 1, m_yPos + 1, m_xPos + m_width - 1, m_yPos + m_height - 1, 0xFF000000);
int textYPos = (m_height - 8) / 2;
if (m_text.empty())
drawString(m_pFont, m_placeholder, m_xPos + 1, m_yPos + 1, 0x404040);
drawString(m_pFont, m_placeholder, m_xPos + 2, m_yPos + 2, 0x404040);
else
drawString(m_pFont, m_text, m_xPos + 1, m_yPos + textYPos, 0xFFFFFF);
drawString(m_pFont, m_text, m_xPos + 2, m_yPos + textYPos, 0xFFFFFF);
if (m_bCursorOn)
{
int xPos = 1;
int xPos = 2;
std::string substr = m_text.substr(0, m_insertHead);
xPos += m_pFont->width(substr);
drawString(m_pFont, "_", m_xPos + xPos, m_yPos + textYPos + 1, 0xFFFFFF);
drawString(m_pFont, "_", m_xPos + xPos, m_yPos + textYPos + 2, 0xFFFFFF);
}
}

View File

@@ -57,6 +57,7 @@
<ClInclude Include="..\source\GUI\RolledSelectionList.hpp" />
<ClInclude Include="..\source\GUI\Screen\ChatScreen.hpp" />
<ClInclude Include="..\source\GUI\Screen\ConfirmScreen.hpp" />
<ClInclude Include="..\source\GUI\Screen\CreateWorldScreen.hpp" />
<ClInclude Include="..\source\GUI\Screen\DeleteWorldScreen.hpp" />
<ClInclude Include="..\source\GUI\Screen\IngameBlockSelectionScreen.hpp" />
<ClInclude Include="..\source\GUI\Screen\InvalidLicenseScreen.hpp" />
@@ -351,6 +352,7 @@
<ClCompile Include="..\source\GUI\RolledSelectionList.cpp" />
<ClCompile Include="..\source\GUI\Screen\ChatScreen.cpp" />
<ClCompile Include="..\source\GUI\Screen\ConfirmScreen.cpp" />
<ClCompile Include="..\source\GUI\Screen\CreateWorldScreen.cpp" />
<ClCompile Include="..\source\GUI\Screen\DeleteWorldScreen.cpp" />
<ClCompile Include="..\source\GUI\Screen\IngameBlockSelectionScreen.cpp" />
<ClCompile Include="..\source\GUI\Screen\InvalidLicenseScreen.cpp" />

View File

@@ -1071,6 +1071,9 @@
<ClCompile Include="..\source\GUI\Screen\SavingWorldScreen.cpp">
<Filter>Source Files\GUI\Screen</Filter>
</ClCompile>
<ClCompile Include="..\source\GUI\Screen\CreateWorldScreen.cpp">
<Filter>Source Files\GUI\Screen</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\source\Options.hpp">
@@ -1949,6 +1952,9 @@
<ClInclude Include="..\source\GUI\Screen\SavingWorldScreen.hpp">
<Filter>Header Files\GUI\Screen</Filter>
</ClInclude>
<ClInclude Include="..\source\GUI\Screen\CreateWorldScreen.hpp">
<Filter>Header Files\GUI\Screen</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\thirdparty\raknet\CMakeLists.txt">