Files
minecraft-pe-0.6.1/src/client/gui/screens/touch/TouchStartMenuScreen.cpp

219 lines
5.6 KiB
C++
Executable File

#include "TouchStartMenuScreen.h"
#include "../ProgressScreen.h"
#include "../OptionsScreen.h"
#include "../PauseScreen.h"
#include "../InvalidLicenseScreen.h"
//#include "BuyGameScreen.h"
#include "../../Font.h"
#include "../../components/SmallButton.h"
#include "../../components/ScrolledSelectionList.h"
#include "../../components/GuiElement.h"
#include "../../../Minecraft.h"
#include "../../../renderer/Tesselator.h"
#include "../../../renderer/Textures.h"
#include "../../../renderer/TextureData.h"
#include "../../../../SharedConstants.h"
#include "../../../../AppPlatform.h"
#include "../../../../LicenseCodes.h"
#include "../../../../util/Mth.h"
#include "../DialogDefinitions.h"
#include "../SimpleChooseLevelScreen.h"
namespace Touch {
//
// Start menu screen implementation
//
// Some kind of default settings, might be overridden in ::init
StartMenuScreen::StartMenuScreen()
: bHost( 2, "Start Game"),
bJoin( 3, "Join Game"),
bOptions( 4, "Options")
{
ImageDef def;
bJoin.width = 75;
def.width = def.height = (float) bJoin.width;
def.setSrc(IntRectangle(0, 26, (int)def.width, (int)def.width));
def.name = "gui/touchgui.png";
IntRectangle& defSrc = *def.getSrc();
bOptions.setImageDef(def, true);
defSrc.y += defSrc.h;
bHost.setImageDef(def, true);
defSrc.y += defSrc.h;
bJoin.setImageDef(def, true);
}
StartMenuScreen::~StartMenuScreen()
{
}
void StartMenuScreen::init()
{
buttons.push_back(&bHost);
buttons.push_back(&bJoin);
buttons.push_back(&bOptions);
//buttons.push_back(&bTest);
tabButtons.push_back(&bHost);
tabButtons.push_back(&bJoin);
tabButtons.push_back(&bOptions);
copyright = "\xffMojang AB";//. Do not distribute!";
#ifdef PRE_ANDROID23
std::string versionString = Common::getGameVersionString("j");
#else
std::string versionString = Common::getGameVersionString();
#endif
#ifdef DEMO_MODE
#ifdef __APPLE__
version = versionString + " (Lite)";
#else
version = versionString + " (Demo)";
#endif
#else
version = versionString;
#endif
#ifdef APPLE_DEMO_PROMOTION
version = versionString + " (Demo)";
#endif
bJoin.active = bHost.active = bOptions.active = false;
}
void StartMenuScreen::setupPositions() {
int yBase = 2 + height / 3;
int buttonWidth = bHost.width;
float spacing = (width - (3.0f * buttonWidth)) / 4;
//#ifdef ANDROID
bHost.y = yBase;
bJoin.y = yBase;
bOptions.y = yBase;
//#endif
//bTest.x = 0; //width - bTest.w;
//bTest.y = height - bTest.h;
// Center buttons
bJoin.x = 0*buttonWidth + (int)(1*spacing);
bHost.x = 1*buttonWidth + (int)(2*spacing);
bOptions.x = 2*buttonWidth + (int)(3*spacing);
copyrightPosX = width - minecraft->font->width(copyright) - 1;
versionPosX = (width - minecraft->font->width(version)) / 2;// - minecraft->font->width(version) - 2;
}
void StartMenuScreen::tick() {
Screen::tick();
_updateLicense();
}
void StartMenuScreen::buttonClicked(::Button* button) {
//if (button->id == bTest.id) {
// minecraft->selectLevel("Broken", "Broken", 1317199248);
// minecraft->hostMultiplayer();
// minecraft->setScreen(new ProgressScreen());
//}
if (button->id == bHost.id)
{
#if defined(DEMO_MODE) || defined(APPLE_DEMO_PROMOTION)
minecraft->setScreen( new SimpleChooseLevelScreen("_DemoLevel") );
#else
minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD);
#endif
}
if (button->id == bJoin.id)
{
#ifdef APPLE_DEMO_PROMOTION
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_DEMO_FEATURE_DISABLED);
#else
minecraft->locateMultiplayer();
minecraft->screenChooser.setScreen(SCREEN_JOINGAME);
#endif
}
if (button->id == bOptions.id)
{
minecraft->setScreen(new OptionsScreen());
}
}
bool StartMenuScreen::isInGameScreen() { return false; }
void StartMenuScreen::render( int xm, int ym, float a )
{
renderBackground();
glEnable2(GL_BLEND);
#if defined(RPI)
TextureId id = minecraft->textures->loadTexture("gui/pi_title.png");
#else
TextureId id = minecraft->textures->loadTexture("gui/title.png");
#endif
const TextureData* data = minecraft->textures->getTemporaryTextureData(id);
if (data) {
minecraft->textures->bind(id);
const float x = (float)width / 2;
const float y = 4;
const float wh = 0.5f * Mth::Min((float)width/2.0f, (float)data->w / 2);
const float scale = 2.0f * wh / (float)data->w;
const float h = scale * (float)data->h;
// Render title text
Tesselator& t = Tesselator::instance;
glColor4f2(1, 1, 1, 1);
t.begin();
t.vertexUV(x-wh, y+h, blitOffset, 0, 1);
t.vertexUV(x+wh, y+h, blitOffset, 1, 1);
t.vertexUV(x+wh, y+0, blitOffset, 1, 0);
t.vertexUV(x-wh, y+0, blitOffset, 0, 0);
t.draw();
drawString(font, version, versionPosX, (int)(y+h)+2, /*50,*/ 0xffcccccc);//0x666666);
drawString(font, copyright, copyrightPosX, height - 10, 0xffffff);
//patch->draw(t, 0, 20);
}
Screen::render(xm, ym, a);
glDisable2(GL_BLEND);
}
void StartMenuScreen::_updateLicense()
{
int id = minecraft->getLicenseId();
if (LicenseCodes::isReady(id))
{
if (LicenseCodes::isOk(id))
bJoin.active = bHost.active = bOptions.active = true;
else
{
bool hasBuyButton = minecraft->platform()->hasBuyButtonWhenInvalidLicense();
minecraft->setScreen(new InvalidLicenseScreen(id, hasBuyButton));
}
} else {
bJoin.active = bHost.active = bOptions.active = false;
}
}
bool StartMenuScreen::handleBackEvent( bool isDown ) {
minecraft->quit();
return true;
}
};