forked from Kolyah35/minecraft-pe-0.6.1
Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -12,11 +12,13 @@
|
||||
SimpleChooseLevelScreen::SimpleChooseLevelScreen(const std::string& levelName)
|
||||
: bHeader(0),
|
||||
bGamemode(0),
|
||||
bCheats(0),
|
||||
bBack(0),
|
||||
bCreate(0),
|
||||
levelName(levelName),
|
||||
hasChosen(false),
|
||||
gamemode(GameType::Survival),
|
||||
cheatsEnabled(false),
|
||||
tLevelName(0, "World name"),
|
||||
tSeed(1, "World seed")
|
||||
{
|
||||
@@ -26,12 +28,20 @@ SimpleChooseLevelScreen::~SimpleChooseLevelScreen()
|
||||
{
|
||||
if (bHeader) delete bHeader;
|
||||
delete bGamemode;
|
||||
delete bCheats;
|
||||
delete bBack;
|
||||
delete bCreate;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::init()
|
||||
{
|
||||
// make sure the base class loads the existing level list; the
|
||||
// derived screen uses ChooseLevelScreen::getUniqueLevelName(), which
|
||||
// depends on `levels` being populated. omitting this used to result
|
||||
// in duplicate IDs ("creating the second world would load the
|
||||
// first") when the name already existed.
|
||||
ChooseLevelScreen::init();
|
||||
|
||||
tLevelName.text = "New world";
|
||||
|
||||
// header + close button
|
||||
@@ -48,18 +58,22 @@ void SimpleChooseLevelScreen::init()
|
||||
}
|
||||
if (minecraft->useTouchscreen()) {
|
||||
bGamemode = new Touch::TButton(1, "Survival mode");
|
||||
bCheats = new Touch::TButton(4, "Cheats: Off");
|
||||
bCreate = new Touch::TButton(3, "Create");
|
||||
} else {
|
||||
bGamemode = new Button(1, "Survival mode");
|
||||
bCheats = new Button(4, "Cheats: Off");
|
||||
bCreate = new Button(3, "Create");
|
||||
}
|
||||
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(bBack);
|
||||
buttons.push_back(bGamemode);
|
||||
buttons.push_back(bCheats);
|
||||
buttons.push_back(bCreate);
|
||||
|
||||
tabButtons.push_back(bGamemode);
|
||||
tabButtons.push_back(bCheats);
|
||||
tabButtons.push_back(bBack);
|
||||
tabButtons.push_back(bCreate);
|
||||
|
||||
@@ -94,16 +108,26 @@ void SimpleChooseLevelScreen::setupPositions()
|
||||
tSeed.x = tLevelName.x;
|
||||
tSeed.y = tLevelName.y + 30;
|
||||
|
||||
bGamemode->width = 140;
|
||||
bGamemode->x = centerX - bGamemode->width / 2;
|
||||
// compute vertical centre for gamemode in remaining space
|
||||
const int buttonWidth = 120;
|
||||
const int buttonSpacing = 10;
|
||||
const int totalButtonWidth = buttonWidth * 2 + buttonSpacing;
|
||||
|
||||
bGamemode->width = buttonWidth;
|
||||
bCheats->width = buttonWidth;
|
||||
|
||||
bGamemode->x = centerX - totalButtonWidth / 2;
|
||||
bCheats->x = bGamemode->x + buttonWidth + buttonSpacing;
|
||||
|
||||
// compute vertical centre for buttons in remaining space
|
||||
{
|
||||
int bottomPad = 20;
|
||||
int availTop = buttonHeight + 20 + 30 + 10; // just below seed
|
||||
int availBottom = height - bottomPad - bCreate->height - 10; // leave some gap before create
|
||||
int availHeight = availBottom - availTop;
|
||||
if (availHeight < 0) availHeight = 0;
|
||||
bGamemode->y = availTop + (availHeight - bGamemode->height) / 2;
|
||||
int y = availTop + (availHeight - bGamemode->height) / 2;
|
||||
bGamemode->y = y;
|
||||
bCheats->y = y;
|
||||
}
|
||||
|
||||
bCreate->width = 100;
|
||||
@@ -124,14 +148,14 @@ void SimpleChooseLevelScreen::render( int xm, int ym, float a )
|
||||
renderDirtBackground(0);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
const char* str = NULL;
|
||||
const char* modeDesc = NULL;
|
||||
if (gamemode == GameType::Survival) {
|
||||
str = "Mobs, health and gather resources";
|
||||
modeDesc = "Mobs, health and gather resources";
|
||||
} else if (gamemode == GameType::Creative) {
|
||||
str = "Unlimited resources and flying";
|
||||
modeDesc = "Unlimited resources and flying";
|
||||
}
|
||||
if (str) {
|
||||
drawCenteredString(minecraft->font, str, width/2, bGamemode->y + bGamemode->height + 4, 0xffcccccc);
|
||||
if (modeDesc) {
|
||||
drawCenteredString(minecraft->font, modeDesc, width / 2, bGamemode->y + bGamemode->height + 4, 0xffcccccc);
|
||||
}
|
||||
|
||||
drawString(minecraft->font, "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
@@ -188,6 +212,12 @@ void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCheats) {
|
||||
cheatsEnabled = !cheatsEnabled;
|
||||
bCheats->msg = cheatsEnabled ? "Cheats: On" : "Cheats: Off";
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCreate && !tLevelName.text.empty()) {
|
||||
int seed = getEpochTimeS();
|
||||
if (!tSeed.text.empty()) {
|
||||
@@ -200,7 +230,7 @@ void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
||||
}
|
||||
}
|
||||
std::string levelId = getUniqueLevelName(tLevelName.text);
|
||||
LevelSettings settings(seed, gamemode);
|
||||
LevelSettings settings(seed, gamemode, cheatsEnabled);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
|
||||
Reference in New Issue
Block a user