mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-19 22:43:32 +00:00
Added a dummy cheats toggle to the world creation screen.
This commit is contained in:
@@ -12,11 +12,13 @@
|
|||||||
SimpleChooseLevelScreen::SimpleChooseLevelScreen(const std::string& levelName)
|
SimpleChooseLevelScreen::SimpleChooseLevelScreen(const std::string& levelName)
|
||||||
: bHeader(0),
|
: bHeader(0),
|
||||||
bGamemode(0),
|
bGamemode(0),
|
||||||
|
bCheats(0),
|
||||||
bBack(0),
|
bBack(0),
|
||||||
bCreate(0),
|
bCreate(0),
|
||||||
levelName(levelName),
|
levelName(levelName),
|
||||||
hasChosen(false),
|
hasChosen(false),
|
||||||
gamemode(GameType::Survival),
|
gamemode(GameType::Survival),
|
||||||
|
cheatsEnabled(false),
|
||||||
tLevelName(0, "World name"),
|
tLevelName(0, "World name"),
|
||||||
tSeed(1, "World seed")
|
tSeed(1, "World seed")
|
||||||
{
|
{
|
||||||
@@ -26,6 +28,7 @@ SimpleChooseLevelScreen::~SimpleChooseLevelScreen()
|
|||||||
{
|
{
|
||||||
if (bHeader) delete bHeader;
|
if (bHeader) delete bHeader;
|
||||||
delete bGamemode;
|
delete bGamemode;
|
||||||
|
delete bCheats;
|
||||||
delete bBack;
|
delete bBack;
|
||||||
delete bCreate;
|
delete bCreate;
|
||||||
}
|
}
|
||||||
@@ -55,18 +58,22 @@ void SimpleChooseLevelScreen::init()
|
|||||||
}
|
}
|
||||||
if (minecraft->useTouchscreen()) {
|
if (minecraft->useTouchscreen()) {
|
||||||
bGamemode = new Touch::TButton(1, "Survival mode");
|
bGamemode = new Touch::TButton(1, "Survival mode");
|
||||||
|
bCheats = new Touch::TButton(4, "Cheats: Off");
|
||||||
bCreate = new Touch::TButton(3, "Create");
|
bCreate = new Touch::TButton(3, "Create");
|
||||||
} else {
|
} else {
|
||||||
bGamemode = new Button(1, "Survival mode");
|
bGamemode = new Button(1, "Survival mode");
|
||||||
|
bCheats = new Button(4, "Cheats: Off");
|
||||||
bCreate = new Button(3, "Create");
|
bCreate = new Button(3, "Create");
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons.push_back(bHeader);
|
buttons.push_back(bHeader);
|
||||||
buttons.push_back(bBack);
|
buttons.push_back(bBack);
|
||||||
buttons.push_back(bGamemode);
|
buttons.push_back(bGamemode);
|
||||||
|
buttons.push_back(bCheats);
|
||||||
buttons.push_back(bCreate);
|
buttons.push_back(bCreate);
|
||||||
|
|
||||||
tabButtons.push_back(bGamemode);
|
tabButtons.push_back(bGamemode);
|
||||||
|
tabButtons.push_back(bCheats);
|
||||||
tabButtons.push_back(bBack);
|
tabButtons.push_back(bBack);
|
||||||
tabButtons.push_back(bCreate);
|
tabButtons.push_back(bCreate);
|
||||||
|
|
||||||
@@ -101,16 +108,26 @@ void SimpleChooseLevelScreen::setupPositions()
|
|||||||
tSeed.x = tLevelName.x;
|
tSeed.x = tLevelName.x;
|
||||||
tSeed.y = tLevelName.y + 30;
|
tSeed.y = tLevelName.y + 30;
|
||||||
|
|
||||||
bGamemode->width = 140;
|
const int buttonWidth = 120;
|
||||||
bGamemode->x = centerX - bGamemode->width / 2;
|
const int buttonSpacing = 10;
|
||||||
// compute vertical centre for gamemode in remaining space
|
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 bottomPad = 20;
|
||||||
int availTop = buttonHeight + 20 + 30 + 10; // just below seed
|
int availTop = buttonHeight + 20 + 30 + 10; // just below seed
|
||||||
int availBottom = height - bottomPad - bCreate->height - 10; // leave some gap before create
|
int availBottom = height - bottomPad - bCreate->height - 10; // leave some gap before create
|
||||||
int availHeight = availBottom - availTop;
|
int availHeight = availBottom - availTop;
|
||||||
if (availHeight < 0) availHeight = 0;
|
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;
|
bCreate->width = 100;
|
||||||
@@ -131,14 +148,14 @@ void SimpleChooseLevelScreen::render( int xm, int ym, float a )
|
|||||||
renderDirtBackground(0);
|
renderDirtBackground(0);
|
||||||
glEnable2(GL_BLEND);
|
glEnable2(GL_BLEND);
|
||||||
|
|
||||||
const char* str = NULL;
|
const char* modeDesc = NULL;
|
||||||
if (gamemode == GameType::Survival) {
|
if (gamemode == GameType::Survival) {
|
||||||
str = "Mobs, health and gather resources";
|
modeDesc = "Mobs, health and gather resources";
|
||||||
} else if (gamemode == GameType::Creative) {
|
} else if (gamemode == GameType::Creative) {
|
||||||
str = "Unlimited resources and flying";
|
modeDesc = "Unlimited resources and flying";
|
||||||
}
|
}
|
||||||
if (str) {
|
if (modeDesc) {
|
||||||
drawCenteredString(minecraft->font, str, width/2, bGamemode->y + bGamemode->height + 4, 0xffcccccc);
|
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);
|
drawString(minecraft->font, "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||||
@@ -195,6 +212,12 @@ void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (button == bCheats) {
|
||||||
|
cheatsEnabled = !cheatsEnabled;
|
||||||
|
bCheats->msg = cheatsEnabled ? "Cheats: On" : "Cheats: Off";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (button == bCreate && !tLevelName.text.empty()) {
|
if (button == bCreate && !tLevelName.text.empty()) {
|
||||||
int seed = getEpochTimeS();
|
int seed = getEpochTimeS();
|
||||||
if (!tSeed.text.empty()) {
|
if (!tSeed.text.empty()) {
|
||||||
@@ -207,7 +230,7 @@ void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string levelId = getUniqueLevelName(tLevelName.text);
|
std::string levelId = getUniqueLevelName(tLevelName.text);
|
||||||
LevelSettings settings(seed, gamemode);
|
LevelSettings settings(seed, gamemode, cheatsEnabled);
|
||||||
minecraft->selectLevel(levelId, levelId, settings);
|
minecraft->selectLevel(levelId, levelId, settings);
|
||||||
minecraft->hostMultiplayer();
|
minecraft->hostMultiplayer();
|
||||||
minecraft->setScreen(new ProgressScreen());
|
minecraft->setScreen(new ProgressScreen());
|
||||||
|
|||||||
@@ -29,12 +29,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
Touch::THeader* bHeader;
|
Touch::THeader* bHeader;
|
||||||
Button* bGamemode;
|
Button* bGamemode;
|
||||||
|
Button* bCheats;
|
||||||
ImageButton* bBack;
|
ImageButton* bBack;
|
||||||
Button* bCreate;
|
Button* bCreate;
|
||||||
bool hasChosen;
|
bool hasChosen;
|
||||||
|
|
||||||
std::string levelName;
|
std::string levelName;
|
||||||
int gamemode;
|
int gamemode;
|
||||||
|
bool cheatsEnabled;
|
||||||
|
|
||||||
TextBox tLevelName;
|
TextBox tLevelName;
|
||||||
TextBox tSeed;
|
TextBox tSeed;
|
||||||
|
|||||||
@@ -14,13 +14,14 @@ namespace GameType {
|
|||||||
class LevelSettings
|
class LevelSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LevelSettings(long seed, int gameType)
|
LevelSettings(long seed, int gameType, bool allowCheats = false)
|
||||||
: seed(seed),
|
: seed(seed),
|
||||||
gameType(gameType)
|
gameType(gameType),
|
||||||
|
allowCheats(allowCheats)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
static LevelSettings None() {
|
static LevelSettings None() {
|
||||||
return LevelSettings(-1,-1);
|
return LevelSettings(-1,-1,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
long getSeed() const {
|
long getSeed() const {
|
||||||
@@ -31,6 +32,10 @@ public:
|
|||||||
return gameType;
|
return gameType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool getAllowCheats() const {
|
||||||
|
return allowCheats;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Those two should actually not be here
|
// Those two should actually not be here
|
||||||
// @todo: Move out when we add LevelSettings.cpp :p
|
// @todo: Move out when we add LevelSettings.cpp :p
|
||||||
@@ -53,6 +58,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
const long seed;
|
const long seed;
|
||||||
const int gameType;
|
const int gameType;
|
||||||
|
const bool allowCheats;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*NET_MINECRAFT_WORLD_LEVEL__LevelSettings_H__*/
|
#endif /*NET_MINECRAFT_WORLD_LEVEL__LevelSettings_H__*/
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ LevelData::LevelData()
|
|||||||
dimension(Dimension::NORMAL),
|
dimension(Dimension::NORMAL),
|
||||||
playerDataVersion(-1),
|
playerDataVersion(-1),
|
||||||
storageVersion(0),
|
storageVersion(0),
|
||||||
gameType(GameType::Default),
|
gameType(GameType::Default), spawnMobs(false),
|
||||||
loadedPlayerTag(NULL)
|
allowCheats(false), loadedPlayerTag(NULL)
|
||||||
{
|
{
|
||||||
//LOGI("ctor 1: %p\n", this);
|
//LOGI("ctor 1: %p\n", this);
|
||||||
spawnMobs = (gameType == GameType::Survival);
|
spawnMobs = (gameType == GameType::Survival);
|
||||||
@@ -21,8 +21,7 @@ LevelData::LevelData()
|
|||||||
|
|
||||||
LevelData::LevelData( const LevelSettings& settings, const std::string& levelName, int generatorVersion /*= -1*/ )
|
LevelData::LevelData( const LevelSettings& settings, const std::string& levelName, int generatorVersion /*= -1*/ )
|
||||||
: seed(settings.getSeed()),
|
: seed(settings.getSeed()),
|
||||||
gameType(settings.getGameType()),
|
gameType(settings.getGameType()), allowCheats(settings.getAllowCheats()), levelName(levelName),
|
||||||
levelName(levelName),
|
|
||||||
xSpawn(128),
|
xSpawn(128),
|
||||||
ySpawn(64),
|
ySpawn(64),
|
||||||
zSpawn(128),
|
zSpawn(128),
|
||||||
@@ -62,6 +61,7 @@ LevelData::LevelData( const LevelData& rhs )
|
|||||||
playerDataVersion(rhs.playerDataVersion),
|
playerDataVersion(rhs.playerDataVersion),
|
||||||
generatorVersion(rhs.generatorVersion),
|
generatorVersion(rhs.generatorVersion),
|
||||||
spawnMobs(rhs.spawnMobs),
|
spawnMobs(rhs.spawnMobs),
|
||||||
|
allowCheats(rhs.allowCheats),
|
||||||
loadedPlayerTag(NULL),
|
loadedPlayerTag(NULL),
|
||||||
playerData(rhs.playerData)
|
playerData(rhs.playerData)
|
||||||
{
|
{
|
||||||
@@ -84,6 +84,7 @@ LevelData& LevelData::operator=( const LevelData& rhs )
|
|||||||
time = rhs.time;
|
time = rhs.time;
|
||||||
dimension = rhs.dimension;
|
dimension = rhs.dimension;
|
||||||
spawnMobs = rhs.spawnMobs;
|
spawnMobs = rhs.spawnMobs;
|
||||||
|
allowCheats = rhs.allowCheats;
|
||||||
playerData = rhs.playerData;
|
playerData = rhs.playerData;
|
||||||
playerDataVersion = rhs.playerDataVersion;
|
playerDataVersion = rhs.playerDataVersion;
|
||||||
generatorVersion = rhs.generatorVersion;
|
generatorVersion = rhs.generatorVersion;
|
||||||
@@ -161,6 +162,7 @@ void LevelData::setTagData( CompoundTag* tag, CompoundTag* playerTag )
|
|||||||
if (!tag) return;
|
if (!tag) return;
|
||||||
tag->putLong("RandomSeed", seed);
|
tag->putLong("RandomSeed", seed);
|
||||||
tag->putInt("GameType", gameType);
|
tag->putInt("GameType", gameType);
|
||||||
|
tag->putBoolean("AllowCommands", allowCheats);
|
||||||
tag->putInt("SpawnX", xSpawn);
|
tag->putInt("SpawnX", xSpawn);
|
||||||
tag->putInt("SpawnY", ySpawn);
|
tag->putInt("SpawnY", ySpawn);
|
||||||
tag->putInt("SpawnZ", zSpawn);
|
tag->putInt("SpawnZ", zSpawn);
|
||||||
@@ -181,6 +183,7 @@ void LevelData::getTagData( const CompoundTag* tag )
|
|||||||
if (!tag) return;
|
if (!tag) return;
|
||||||
seed = (long)tag->getLong("RandomSeed");
|
seed = (long)tag->getLong("RandomSeed");
|
||||||
gameType = tag->getInt("GameType");
|
gameType = tag->getInt("GameType");
|
||||||
|
allowCheats = tag->getBoolean("AllowCommands");
|
||||||
xSpawn = tag->getInt("SpawnX");
|
xSpawn = tag->getInt("SpawnX");
|
||||||
ySpawn = tag->getInt("SpawnY");
|
ySpawn = tag->getInt("SpawnY");
|
||||||
zSpawn = tag->getInt("SpawnZ");
|
zSpawn = tag->getInt("SpawnZ");
|
||||||
@@ -362,3 +365,13 @@ void LevelData::setSpawnMobs( bool doSpawn )
|
|||||||
{
|
{
|
||||||
spawnMobs = doSpawn;
|
spawnMobs = doSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LevelData::getAllowCheats() const
|
||||||
|
{
|
||||||
|
return allowCheats;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelData::setAllowCheats( bool allow )
|
||||||
|
{
|
||||||
|
allowCheats = allow;
|
||||||
|
}
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ public:
|
|||||||
bool getSpawnMobs() const;
|
bool getSpawnMobs() const;
|
||||||
void setSpawnMobs(bool doSpawn);
|
void setSpawnMobs(bool doSpawn);
|
||||||
|
|
||||||
|
bool getAllowCheats() const;
|
||||||
|
void setAllowCheats(bool allow);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayerData playerData;
|
PlayerData playerData;
|
||||||
int playerDataVersion;
|
int playerDataVersion;
|
||||||
@@ -89,6 +92,7 @@ private:
|
|||||||
int gameType;
|
int gameType;
|
||||||
int storageVersion;
|
int storageVersion;
|
||||||
bool spawnMobs;
|
bool spawnMobs;
|
||||||
|
bool allowCheats;
|
||||||
//@note: This version is never written or loaded to disk. The only purpose
|
//@note: This version is never written or loaded to disk. The only purpose
|
||||||
// is to use it in the level generator on server and clients.
|
// is to use it in the level generator on server and clients.
|
||||||
int generatorVersion;
|
int generatorVersion;
|
||||||
|
|||||||
Reference in New Issue
Block a user