mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-20 15:03:32 +00:00
Fixes and enhancements from my MCPE repository. (https://github.com/mschiller890/mcpe64)
This commit is contained in:
223
src/client/gui/screens/ConsoleScreen.cpp
Normal file
223
src/client/gui/screens/ConsoleScreen.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
#include "ConsoleScreen.h"
|
||||
#include "../Gui.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../player/LocalPlayer.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "../../../world/level/Level.h"
|
||||
#include "../../../network/RakNetInstance.h"
|
||||
#include "../../../network/ServerSideNetworkHandler.h"
|
||||
#include "../../../network/packet/ChatPacket.h"
|
||||
#include "../../../platform/log.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
|
||||
ConsoleScreen::ConsoleScreen()
|
||||
: _input(""),
|
||||
_cursorBlink(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ConsoleScreen::init()
|
||||
{
|
||||
}
|
||||
|
||||
void ConsoleScreen::tick()
|
||||
{
|
||||
_cursorBlink++;
|
||||
}
|
||||
|
||||
bool ConsoleScreen::handleBackEvent(bool /*isDown*/)
|
||||
{
|
||||
minecraft->setScreen(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ConsoleScreen::keyPressed(int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->setScreen(NULL);
|
||||
} else if (eventKey == Keyboard::KEY_RETURN) {
|
||||
execute();
|
||||
} else if (eventKey == Keyboard::KEY_BACKSPACE) {
|
||||
if (!_input.empty())
|
||||
_input.erase(_input.size() - 1, 1);
|
||||
} else {
|
||||
super::keyPressed(eventKey);
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleScreen::keyboardNewChar(char inputChar)
|
||||
{
|
||||
if (inputChar >= 32 && inputChar < 127)
|
||||
_input += inputChar;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// execute: run _input as a command, print result, close screen
|
||||
// ---------------------------------------------------------------------------
|
||||
void ConsoleScreen::execute()
|
||||
{
|
||||
if (_input.empty()) {
|
||||
minecraft->setScreen(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_input[0] == '/') {
|
||||
// Command
|
||||
std::string result = processCommand(_input);
|
||||
if (!result.empty())
|
||||
minecraft->gui.addMessage(result);
|
||||
} else {
|
||||
// Chat message: <name> message
|
||||
std::string msg = std::string("<") + minecraft->player->name + "> " + _input;
|
||||
if (minecraft->netCallback && minecraft->raknetInstance->isServer()) {
|
||||
// Hosting a LAN game: displayGameMessage shows locally + broadcasts MessagePacket to clients
|
||||
static_cast<ServerSideNetworkHandler*>(minecraft->netCallback)->displayGameMessage(msg);
|
||||
} else if (minecraft->netCallback) {
|
||||
// Connected client: send ChatPacket to server; server echoes it back as MessagePacket
|
||||
ChatPacket chatPkt(msg);
|
||||
minecraft->raknetInstance->send(chatPkt);
|
||||
} else {
|
||||
// Singleplayer: show locally only
|
||||
minecraft->gui.addMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
minecraft->setScreen(NULL);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// processCommand
|
||||
// ---------------------------------------------------------------------------
|
||||
static std::string trim(const std::string& s) {
|
||||
size_t a = s.find_first_not_of(" \t");
|
||||
if (a == std::string::npos) return "";
|
||||
size_t b = s.find_last_not_of(" \t");
|
||||
return s.substr(a, b - a + 1);
|
||||
}
|
||||
|
||||
std::string ConsoleScreen::processCommand(const std::string& raw)
|
||||
{
|
||||
// strip leading '/'
|
||||
std::string line = raw;
|
||||
if (!line.empty() && line[0] == '/') line = line.substr(1);
|
||||
line = trim(line);
|
||||
|
||||
// tokenise
|
||||
std::vector<std::string> args;
|
||||
{
|
||||
std::istringstream ss(line);
|
||||
std::string tok;
|
||||
while (ss >> tok) args.push_back(tok);
|
||||
}
|
||||
|
||||
if (args.empty()) return "";
|
||||
|
||||
Level* level = minecraft->level;
|
||||
if (!level) return "No level loaded.";
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// /time ...
|
||||
// -----------------------------------------------------------------------
|
||||
if (args[0] == "time") {
|
||||
if (args.size() < 2)
|
||||
return "Usage: /time <add|set|query> ...";
|
||||
|
||||
const std::string& sub = args[1];
|
||||
|
||||
// -- time add <value> -----------------------------------------------
|
||||
if (sub == "add") {
|
||||
if (args.size() < 3) return "Usage: /time add <value>";
|
||||
long delta = std::atol(args[2].c_str());
|
||||
long newTime = level->getTime() + delta;
|
||||
level->setTime(newTime);
|
||||
std::ostringstream out;
|
||||
out << "Set the time to " << (newTime % Level::TICKS_PER_DAY);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
// -- time set <value|day|night|noon|midnight> -----------------------
|
||||
if (sub == "set") {
|
||||
if (args.size() < 3) return "Usage: /time set <value|day|night|noon|midnight>";
|
||||
const std::string& val = args[2];
|
||||
|
||||
long t = -1;
|
||||
if (val == "day") t = 1000;
|
||||
else if (val == "noon") t = 6000;
|
||||
else if (val == "night") t = 13000;
|
||||
else if (val == "midnight") t = 18000;
|
||||
else {
|
||||
// numeric — accept positive integers only
|
||||
bool numeric = true;
|
||||
for (char c : val)
|
||||
if (!std::isdigit((unsigned char)c)) { numeric = false; break; }
|
||||
if (!numeric) return std::string("Unknown value: ") + val;
|
||||
t = std::atol(val.c_str());
|
||||
}
|
||||
|
||||
// Preserve the total day count so only the time-of-day changes
|
||||
long dayCount = level->getTime() / Level::TICKS_PER_DAY;
|
||||
long newTime = dayCount * Level::TICKS_PER_DAY + (t % Level::TICKS_PER_DAY);
|
||||
level->setTime(newTime);
|
||||
std::ostringstream out;
|
||||
out << "Set the time to " << t;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
// -- time query <daytime|gametime|day> ------------------------------
|
||||
if (sub == "query") {
|
||||
if (args.size() < 3) return "Usage: /time query <daytime|gametime|day>";
|
||||
const std::string& what = args[2];
|
||||
|
||||
long total = level->getTime();
|
||||
long daytime = total % Level::TICKS_PER_DAY;
|
||||
long day = total / Level::TICKS_PER_DAY;
|
||||
|
||||
std::ostringstream out;
|
||||
if (what == "daytime") { out << "The time of day is " << daytime; }
|
||||
else if (what == "gametime") { out << "The game time is " << total; }
|
||||
else if (what == "day") { out << "The day is " << day; }
|
||||
else return std::string("Unknown query: ") + what;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
return "Unknown sub-command. Usage: /time <add|set|query> ...";
|
||||
}
|
||||
|
||||
return std::string("Unknown command: /") + args[0];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// render
|
||||
// ---------------------------------------------------------------------------
|
||||
void ConsoleScreen::render(int /*xm*/, int /*ym*/, float /*a*/)
|
||||
{
|
||||
// Dim the game world slightly
|
||||
fillGradient(0, 0, width, height, 0x00000000, 0x40000000);
|
||||
|
||||
const int boxH = 12;
|
||||
const int boxY = height - boxH - 2;
|
||||
const int boxX0 = 2;
|
||||
const int boxX1 = width - 2;
|
||||
|
||||
// Input box background
|
||||
fill(boxX0, boxY, boxX1, boxY + boxH, 0xc0000000);
|
||||
// Border
|
||||
fill(boxX0, boxY, boxX1, boxY + 1, 0xff808080);
|
||||
fill(boxX0, boxY + boxH - 1, boxX1, boxY + boxH, 0xff808080);
|
||||
fill(boxX0, boxY, boxX0 + 1, boxY + boxH, 0xff808080);
|
||||
fill(boxX1 - 1, boxY, boxX1, boxY + boxH, 0xff808080);
|
||||
|
||||
// Input text + blinking cursor
|
||||
std::string displayed = _input;
|
||||
if ((_cursorBlink / 10) % 2 == 0)
|
||||
displayed += '_';
|
||||
|
||||
// Placeholder hint when empty
|
||||
if (_input.empty() && (_cursorBlink / 10) % 2 != 0)
|
||||
font->drawShadow("Type a message or /command", (float)(boxX0 + 2), (float)(boxY + 2), 0xff606060);
|
||||
else
|
||||
font->drawShadow(displayed, (float)(boxX0 + 2), (float)(boxY + 2), 0xffffffff);
|
||||
}
|
||||
34
src/client/gui/screens/ConsoleScreen.h
Normal file
34
src/client/gui/screens/ConsoleScreen.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS__ConsoleScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS__ConsoleScreen_H__
|
||||
|
||||
#include "../Screen.h"
|
||||
#include <string>
|
||||
|
||||
class ConsoleScreen: public Screen
|
||||
{
|
||||
typedef Screen super;
|
||||
public:
|
||||
ConsoleScreen();
|
||||
virtual ~ConsoleScreen() {}
|
||||
|
||||
void init();
|
||||
void render(int xm, int ym, float a);
|
||||
void tick();
|
||||
|
||||
virtual bool renderGameBehind() { return true; }
|
||||
virtual bool isInGameScreen() { return true; }
|
||||
virtual bool isPauseScreen() { return false; }
|
||||
|
||||
virtual void keyPressed(int eventKey);
|
||||
virtual void keyboardNewChar(char inputChar);
|
||||
virtual bool handleBackEvent(bool isDown);
|
||||
|
||||
private:
|
||||
void execute();
|
||||
std::string processCommand(const std::string& cmd);
|
||||
|
||||
std::string _input;
|
||||
int _cursorBlink; // tick counter for cursor blink
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__ConsoleScreen_H__*/
|
||||
118
src/client/gui/screens/CreditsScreen.cpp
Normal file
118
src/client/gui/screens/CreditsScreen.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
#include "CreditsScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "OptionsScreen.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/ImageButton.h"
|
||||
|
||||
CreditsScreen::CreditsScreen()
|
||||
: bHeader(NULL), btnBack(NULL)
|
||||
{}
|
||||
CreditsScreen::~CreditsScreen() {
|
||||
if (bHeader) delete bHeader;
|
||||
if (btnBack) delete btnBack;
|
||||
}
|
||||
|
||||
void CreditsScreen::init() {
|
||||
bHeader = new Touch::THeader(0, "Credits");
|
||||
btnBack = new ImageButton(1, "");
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
btnBack->setImageDef(def, true);
|
||||
}
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(btnBack);
|
||||
|
||||
// prepare text lines
|
||||
_lines.clear();
|
||||
_lines.push_back("Minecraft: Pocket Edition");
|
||||
_lines.push_back("Original game by Mojang");
|
||||
_lines.push_back("");
|
||||
_lines.push_back("Programmers:");
|
||||
_lines.push_back("mschiller890");
|
||||
_lines.push_back("InviseDivine");
|
||||
_lines.push_back("Kolyah35");
|
||||
_lines.push_back("");
|
||||
_lines.push_back("[Gold]Join our Discord server:[/Gold] [Green]url.....[/Green]");
|
||||
_scrollSpeed = 0.5f;
|
||||
_scrollY = height; // start below screen
|
||||
}
|
||||
|
||||
void CreditsScreen::setupPositions() {
|
||||
int buttonHeight = btnBack->height;
|
||||
btnBack->x = width - btnBack->width;
|
||||
btnBack->y = 0;
|
||||
if (bHeader) {
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - btnBack->width;
|
||||
bHeader->height = btnBack->height;
|
||||
}
|
||||
|
||||
// reset scroll starting position when screen size changes
|
||||
_scrollY = height;
|
||||
}
|
||||
|
||||
void CreditsScreen::tick() {
|
||||
// move text upward
|
||||
_scrollY -= _scrollSpeed;
|
||||
// if text has scrolled off the top, restart
|
||||
float totalHeight = _lines.size() * (minecraft->font->lineHeight + 8);
|
||||
if (_scrollY + totalHeight < 0) {
|
||||
_scrollY = height;
|
||||
}
|
||||
}
|
||||
|
||||
void CreditsScreen::render(int xm, int ym, float a) {
|
||||
renderBackground();
|
||||
super::render(xm, ym, a);
|
||||
int w = width;
|
||||
Font* font = minecraft->font;
|
||||
float y = _scrollY;
|
||||
const float lineHeight = font->lineHeight + 8;
|
||||
for (size_t i = 0; i < _lines.size(); ++i) {
|
||||
const std::string& line = _lines[i];
|
||||
// use color-tag-aware drawing, centre by total width
|
||||
float lineWidth = Gui::getColoredWidth(font, line);
|
||||
Gui::drawColoredString(font, line, w/2 - lineWidth/2, (int)y, 255);
|
||||
// underline hyperlink lines manually
|
||||
if (line.find("http") != std::string::npos || line.find("discord.gg") != std::string::npos) {
|
||||
float x0 = w/2 - lineWidth/2;
|
||||
float y0 = y + font->lineHeight - 1;
|
||||
this->fill(x0, y0, x0 + lineWidth, y0 + 1, 0xffffffff);
|
||||
}
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void CreditsScreen::buttonClicked(Button* button) {
|
||||
if (button->id == 1) {
|
||||
minecraft->setScreen(new OptionsScreen());
|
||||
}
|
||||
}
|
||||
|
||||
void CreditsScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
// map click to a line in the scrolling text
|
||||
const float lineHeight = minecraft->font->lineHeight + 8;
|
||||
for (size_t i = 0; i < _lines.size(); ++i) {
|
||||
float lineY = _scrollY + i * lineHeight;
|
||||
if (y >= lineY && y < lineY + lineHeight) {
|
||||
const std::string& line = _lines[i];
|
||||
size_t start = line.find("http");
|
||||
if (start == std::string::npos)
|
||||
start = line.find("discord.gg");
|
||||
if (start != std::string::npos) {
|
||||
// extract until space
|
||||
size_t end = line.find(' ', start);
|
||||
std::string url = line.substr(start, (end == std::string::npos) ? std::string::npos : end - start);
|
||||
minecraft->platform()->openURL(url);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
32
src/client/gui/screens/CreditsScreen.h
Normal file
32
src/client/gui/screens/CreditsScreen.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS__CreditsScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS__CreditsScreen_H__
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
|
||||
class ImageButton;
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class CreditsScreen: public Screen {
|
||||
public:
|
||||
typedef Screen super;
|
||||
CreditsScreen();
|
||||
virtual ~CreditsScreen();
|
||||
void init();
|
||||
void setupPositions();
|
||||
virtual void tick();
|
||||
void render(int xm, int ym, float a);
|
||||
void buttonClicked(Button* button);
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
private:
|
||||
Touch::THeader* bHeader;
|
||||
ImageButton* btnBack;
|
||||
|
||||
std::vector<std::string> _lines;
|
||||
float _scrollY;
|
||||
float _scrollSpeed;
|
||||
};
|
||||
|
||||
#endif /* NET_MINECRAFT_CLIENT_GUI_SCREENS__CreditsScreen_H__ */
|
||||
@@ -1,46 +1,69 @@
|
||||
#include "OptionsScreen.h"
|
||||
|
||||
#include "StartMenuScreen.h"
|
||||
#include "UsernameScreen.h"
|
||||
#include "DialogDefinitions.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
#include "CreditsScreen.h"
|
||||
|
||||
#include "../components/OptionsPane.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "../components/OptionsGroup.h"
|
||||
|
||||
OptionsScreen::OptionsScreen()
|
||||
: btnClose(NULL),
|
||||
bHeader(NULL),
|
||||
selectedCategory(0) {
|
||||
: btnClose(NULL),
|
||||
bHeader(NULL),
|
||||
btnChangeUsername(NULL),
|
||||
btnCredits(NULL),
|
||||
selectedCategory(0) {
|
||||
}
|
||||
|
||||
OptionsScreen::~OptionsScreen() {
|
||||
if(btnClose != NULL) {
|
||||
|
||||
if (btnClose != NULL) {
|
||||
delete btnClose;
|
||||
btnClose = NULL;
|
||||
}
|
||||
if(bHeader != NULL) {
|
||||
delete bHeader,
|
||||
|
||||
if (bHeader != NULL) {
|
||||
delete bHeader;
|
||||
bHeader = NULL;
|
||||
}
|
||||
for(std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
if(*it != NULL) {
|
||||
delete *it;
|
||||
|
||||
if (btnChangeUsername != NULL) {
|
||||
delete btnChangeUsername;
|
||||
btnChangeUsername = NULL;
|
||||
}
|
||||
|
||||
if (btnCredits != NULL) {
|
||||
delete btnCredits;
|
||||
btnCredits = NULL;
|
||||
}
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
if (*it != NULL) {
|
||||
delete* it;
|
||||
*it = NULL;
|
||||
}
|
||||
}
|
||||
for(std::vector<OptionsPane*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
if(*it != NULL) {
|
||||
delete *it;
|
||||
|
||||
for (std::vector<OptionsPane*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
if (*it != NULL) {
|
||||
delete* it;
|
||||
*it = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
categoryButtons.clear();
|
||||
}
|
||||
|
||||
void OptionsScreen::init() {
|
||||
|
||||
bHeader = new Touch::THeader(0, "Options");
|
||||
|
||||
btnClose = new ImageButton(1, "");
|
||||
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
@@ -53,129 +76,199 @@ void OptionsScreen::init() {
|
||||
categoryButtons.push_back(new Touch::TButton(3, "Game"));
|
||||
categoryButtons.push_back(new Touch::TButton(4, "Controls"));
|
||||
categoryButtons.push_back(new Touch::TButton(5, "Graphics"));
|
||||
|
||||
btnChangeUsername = new Button(10, "Username");
|
||||
btnCredits = new Button(11, "Credits");
|
||||
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(btnClose);
|
||||
for(std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
buttons.push_back(btnChangeUsername);
|
||||
buttons.push_back(btnCredits);
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
buttons.push_back(*it);
|
||||
tabButtons.push_back(*it);
|
||||
}
|
||||
generateOptionScreens();
|
||||
|
||||
generateOptionScreens();
|
||||
// start with first category selected
|
||||
selectCategory(0);
|
||||
}
|
||||
|
||||
void OptionsScreen::setupPositions() {
|
||||
|
||||
int buttonHeight = btnClose->height;
|
||||
|
||||
btnClose->x = width - btnClose->width;
|
||||
btnClose->y = 0;
|
||||
|
||||
int offsetNum = 1;
|
||||
for(std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
(*it)->x = 0;
|
||||
(*it)->y = offsetNum * buttonHeight;
|
||||
(*it)->selected = false;
|
||||
|
||||
offsetNum++;
|
||||
}
|
||||
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - btnClose->width;
|
||||
bHeader->height = btnClose->height;
|
||||
for(std::vector<OptionsPane*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
if(categoryButtons.size() > 0 && categoryButtons[0] != NULL) {
|
||||
|
||||
// Username button (bottom-left)
|
||||
if (btnChangeUsername != NULL) {
|
||||
|
||||
btnChangeUsername->width = categoryButtons.empty() ? 80 : categoryButtons[0]->width;
|
||||
btnChangeUsername->height = btnClose->height;
|
||||
|
||||
btnChangeUsername->x = 0;
|
||||
btnChangeUsername->y = height - btnChangeUsername->height;
|
||||
}
|
||||
|
||||
// Credits button (bottom-right)
|
||||
if (btnCredits != NULL) {
|
||||
|
||||
btnCredits->width = btnChangeUsername->width;
|
||||
btnCredits->height = btnChangeUsername->height;
|
||||
|
||||
btnCredits->x = width - btnCredits->width;
|
||||
btnCredits->y = height - btnCredits->height;
|
||||
}
|
||||
|
||||
for (std::vector<OptionsPane*>::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) {
|
||||
|
||||
if (categoryButtons.size() > 0 && categoryButtons[0] != NULL) {
|
||||
|
||||
(*it)->x = categoryButtons[0]->width;
|
||||
(*it)->y = bHeader->height;
|
||||
(*it)->width = width - categoryButtons[0]->width;
|
||||
|
||||
(*it)->setupPositions();
|
||||
}
|
||||
}
|
||||
selectCategory(0);
|
||||
|
||||
// don't override user selection on resize
|
||||
}
|
||||
|
||||
void OptionsScreen::render( int xm, int ym, float a ) {
|
||||
|
||||
void OptionsScreen::render(int xm, int ym, float a) {
|
||||
|
||||
renderBackground();
|
||||
|
||||
super::render(xm, ym, a);
|
||||
|
||||
int xmm = xm * width / minecraft->width;
|
||||
int ymm = ym * height / minecraft->height - 1;
|
||||
if(currentOptionPane != NULL)
|
||||
|
||||
if (currentOptionPane != NULL)
|
||||
currentOptionPane->render(minecraft, xmm, ymm);
|
||||
}
|
||||
|
||||
void OptionsScreen::removed()
|
||||
{
|
||||
void OptionsScreen::removed() {
|
||||
}
|
||||
void OptionsScreen::buttonClicked( Button* button ) {
|
||||
if(button == btnClose) {
|
||||
minecraft->reloadOptions();
|
||||
|
||||
void OptionsScreen::buttonClicked(Button* button) {
|
||||
|
||||
if (button == btnClose) {
|
||||
|
||||
minecraft->options.save();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
} else if(button->id > 1 && button->id < 7) {
|
||||
// This is a category button
|
||||
|
||||
}
|
||||
else if (button == btnChangeUsername) {
|
||||
|
||||
minecraft->options.save();
|
||||
minecraft->setScreen(new UsernameScreen());
|
||||
|
||||
}
|
||||
else if (button->id > 1 && button->id < 7) {
|
||||
|
||||
int categoryButton = button->id - categoryButtons[0]->id;
|
||||
selectCategory(categoryButton);
|
||||
|
||||
}
|
||||
else if (button == btnCredits) {
|
||||
|
||||
minecraft->setScreen(new CreditsScreen());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsScreen::selectCategory( int index ) {
|
||||
void OptionsScreen::selectCategory(int index) {
|
||||
|
||||
int currentIndex = 0;
|
||||
for(std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
if(index == currentIndex) {
|
||||
|
||||
for (std::vector<Touch::TButton*>::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) {
|
||||
|
||||
if (index == currentIndex)
|
||||
(*it)->selected = true;
|
||||
} else {
|
||||
else
|
||||
(*it)->selected = false;
|
||||
}
|
||||
|
||||
currentIndex++;
|
||||
}
|
||||
if(index < (int)optionPanes.size())
|
||||
|
||||
if (index < (int)optionPanes.size())
|
||||
currentOptionPane = optionPanes[index];
|
||||
}
|
||||
|
||||
void OptionsScreen::generateOptionScreens() {
|
||||
|
||||
optionPanes.push_back(new OptionsPane());
|
||||
optionPanes.push_back(new OptionsPane());
|
||||
optionPanes.push_back(new OptionsPane());
|
||||
optionPanes.push_back(new OptionsPane());
|
||||
// Mojang Pane
|
||||
|
||||
// Login Pane
|
||||
optionPanes[0]->createOptionsGroup("options.group.mojang")
|
||||
//.addOptionItem(&Options::Option::THIRD_PERSON, minecraft);
|
||||
.addOptionItem(&Options::Option::SENSITIVITY, minecraft);
|
||||
// int mojangGroup = optionPanes[0]->createOptionsGroup("Mojang");
|
||||
// static const int arr[] = {5,4,3,15};
|
||||
// std::vector<int> vec (arr, arr + sizeof(arr) / sizeof(arr[0]) );
|
||||
// optionPanes[0]->createStepSlider(minecraft, mojangGroup, "This works?", &Options::Option::DIFFICULTY, vec);
|
||||
//
|
||||
// // Game Pane
|
||||
// int gameGroup = optionPanes[1]->createOptionsGroup("Game");
|
||||
// optionPanes[1]->createToggle(gameGroup, "Third person camera", &Options::Option::THIRD_PERSON);
|
||||
// optionPanes[1]->createToggle(gameGroup, "Server visible", &Options::Option::SERVER_VISIBLE);
|
||||
//
|
||||
// // Input Pane
|
||||
// int controlsGroup = optionPanes[2]->createOptionsGroup("Controls");
|
||||
// optionPanes[2]->createToggle(controlsGroup, "Invert X-axis", &Options::Option::INVERT_MOUSE);
|
||||
// optionPanes[2]->createToggle(controlsGroup, "Lefty", &Options::Option::LEFT_HANDED);
|
||||
// optionPanes[2]->createToggle(controlsGroup, "Use touch screen", &Options::Option::USE_TOUCHSCREEN);
|
||||
// optionPanes[2]->createToggle(controlsGroup, "Split touch controls", &Options::Option::USE_TOUCH_JOYPAD);
|
||||
// int feedBackGroup = optionPanes[2]->createOptionsGroup("Feedback");
|
||||
// optionPanes[2]->createToggle(feedBackGroup, "Vibrate on destroy", &Options::Option::DESTROY_VIBRATION);
|
||||
//
|
||||
// int graphicsGroup = optionPanes[3]->createOptionsGroup("Graphics");
|
||||
// optionPanes[3]->createProgressSlider(minecraft, graphicsGroup, "Gui Scale", &Options::Option::PIXELS_PER_MILLIMETER, 3, 4);
|
||||
// optionPanes[3]->createToggle(graphicsGroup, "Fancy Graphics", &Options::Option::INVERT_MOUSE);
|
||||
// optionPanes[3]->createToggle(graphicsGroup, "Fancy Skies", &Options::Option::INVERT_MOUSE);
|
||||
// optionPanes[3]->createToggle(graphicsGroup, "Animated water", &Options::Option::INVERT_MOUSE);
|
||||
// int experimentalGraphicsGroup = optionPanes[3]->createOptionsGroup("Experimental graphics");
|
||||
// optionPanes[3]->createToggle(experimentalGraphicsGroup, "Soft shadows", &Options::Option::INVERT_MOUSE);
|
||||
|
||||
// Game Pane
|
||||
optionPanes[1]->createOptionsGroup("options.group.game")
|
||||
.addOptionItem(&Options::Option::DIFFICULTY, minecraft)
|
||||
.addOptionItem(&Options::Option::SERVER_VISIBLE, minecraft)
|
||||
.addOptionItem(&Options::Option::THIRD_PERSON, minecraft)
|
||||
.addOptionItem(&Options::Option::GUI_SCALE, minecraft);
|
||||
|
||||
// Controls Pane
|
||||
optionPanes[2]->createOptionsGroup("options.group.controls")
|
||||
.addOptionItem(&Options::Option::INVERT_MOUSE, minecraft);
|
||||
|
||||
// Graphics Pane
|
||||
optionPanes[3]->createOptionsGroup("options.group.graphics")
|
||||
.addOptionItem(&Options::Option::GRAPHICS, minecraft)
|
||||
.addOptionItem(&Options::Option::VIEW_BOBBING, minecraft)
|
||||
.addOptionItem(&Options::Option::AMBIENT_OCCLUSION, minecraft)
|
||||
.addOptionItem(&Options::Option::ANAGLYPH, minecraft)
|
||||
.addOptionItem(&Options::Option::LIMIT_FRAMERATE, minecraft)
|
||||
.addOptionItem(&Options::Option::VSYNC, minecraft)
|
||||
.addOptionItem(&Options::Option::MUSIC, minecraft)
|
||||
.addOptionItem(&Options::Option::SOUND, minecraft);
|
||||
}
|
||||
|
||||
void OptionsScreen::mouseClicked( int x, int y, int buttonNum ) {
|
||||
if(currentOptionPane != NULL)
|
||||
void OptionsScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
|
||||
if (currentOptionPane != NULL)
|
||||
currentOptionPane->mouseClicked(minecraft, x, y, buttonNum);
|
||||
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void OptionsScreen::mouseReleased( int x, int y, int buttonNum ) {
|
||||
if(currentOptionPane != NULL)
|
||||
void OptionsScreen::mouseReleased(int x, int y, int buttonNum) {
|
||||
|
||||
if (currentOptionPane != NULL)
|
||||
currentOptionPane->mouseReleased(minecraft, x, y, buttonNum);
|
||||
|
||||
super::mouseReleased(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void OptionsScreen::tick() {
|
||||
if(currentOptionPane != NULL)
|
||||
|
||||
if (currentOptionPane != NULL)
|
||||
currentOptionPane->tick(minecraft);
|
||||
|
||||
super::tick();
|
||||
}
|
||||
}
|
||||
@@ -10,29 +10,37 @@ class OptionsPane;
|
||||
class OptionsScreen: public Screen
|
||||
{
|
||||
typedef Screen super;
|
||||
void init();
|
||||
|
||||
void init();
|
||||
void generateOptionScreens();
|
||||
|
||||
public:
|
||||
OptionsScreen();
|
||||
~OptionsScreen();
|
||||
|
||||
void setupPositions();
|
||||
void buttonClicked( Button* button );
|
||||
void buttonClicked(Button* button);
|
||||
void render(int xm, int ym, float a);
|
||||
void removed();
|
||||
void selectCategory(int index);
|
||||
|
||||
virtual void mouseClicked( int x, int y, int buttonNum );
|
||||
virtual void mouseReleased( int x, int y, int buttonNum );
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
virtual void mouseReleased(int x, int y, int buttonNum);
|
||||
virtual void tick();
|
||||
|
||||
private:
|
||||
Touch::THeader* bHeader;
|
||||
ImageButton* btnClose;
|
||||
|
||||
Button* btnChangeUsername;
|
||||
Button* btnCredits; // <-- ADD THIS
|
||||
|
||||
std::vector<Touch::TButton*> categoryButtons;
|
||||
std::vector<OptionsPane*> optionPanes;
|
||||
|
||||
OptionsPane* currentOptionPane;
|
||||
|
||||
int selectedCategory;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__OptionsScreen_H__*/
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__OptionsScreen_H__*/
|
||||
@@ -230,7 +230,6 @@ SelectWorldScreen::SelectWorldScreen()
|
||||
bBack (3, "Back"),
|
||||
bWorldView(4, ""),
|
||||
worldsList(NULL),
|
||||
_state(_STATE_DEFAULT),
|
||||
_hasStartedLevel(false)
|
||||
{
|
||||
bDelete.active = false;
|
||||
@@ -244,17 +243,11 @@ SelectWorldScreen::~SelectWorldScreen()
|
||||
void SelectWorldScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bCreate.id) {
|
||||
//minecraft->setScreen( new CreateWorldScreen() );
|
||||
//minecraft->locateMultiplayer();
|
||||
//minecraft->setScreen(new JoinGameScreen());
|
||||
|
||||
//minecraft->hostMultiplayer();
|
||||
//minecraft->setScreen(new ProgressScreen());
|
||||
|
||||
if (_state == _STATE_DEFAULT && !_hasStartedLevel) {
|
||||
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_CREATE_NEW_WORLD);
|
||||
_state = _STATE_CREATEWORLD;
|
||||
}
|
||||
// open in-game world-creation screen instead of using platform dialog
|
||||
if (!_hasStartedLevel) {
|
||||
std::string name = getUniqueLevelName("world");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
}
|
||||
}
|
||||
if (button->id == bDelete.id) {
|
||||
if (isIndexValid(worldsList->selectedItem)) {
|
||||
@@ -294,70 +287,6 @@ static char ILLEGAL_FILE_CHARACTERS[] = {
|
||||
|
||||
void SelectWorldScreen::tick()
|
||||
{
|
||||
if (_state == _STATE_CREATEWORLD) {
|
||||
#if defined(RPI)
|
||||
std::string levelId = getUniqueLevelName("world");
|
||||
LevelSettings settings(getEpochTimeS(), GameType::Creative);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
#elif defined(WIN32)
|
||||
std::string name = getUniqueLevelName("perf");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
#else
|
||||
int status = minecraft->platform()->getUserInputStatus();
|
||||
if (status > -1) {
|
||||
if (status == 1) {
|
||||
StringVector sv = minecraft->platform()->getUserInput();
|
||||
|
||||
// Read the level name.
|
||||
// 1) Trim name 2) Remove all bad chars 3) Append '-' chars 'til the name is unique
|
||||
std::string levelName = Util::stringTrim(sv[0]);
|
||||
std::string levelId = levelName;
|
||||
|
||||
for (int i = 0; i < sizeof(ILLEGAL_FILE_CHARACTERS) / sizeof(char); ++i)
|
||||
levelId = Util::stringReplace(levelId, std::string(1, ILLEGAL_FILE_CHARACTERS[i]), "");
|
||||
if ((int)levelId.length() == 0) {
|
||||
levelId = "no_name";
|
||||
}
|
||||
levelId = getUniqueLevelName(levelId);
|
||||
|
||||
// Read the seed
|
||||
int seed = getEpochTimeS();
|
||||
if (sv.size() >= 2) {
|
||||
std::string seedString = Util::stringTrim(sv[1]);
|
||||
if (seedString.length() > 0) {
|
||||
int tmpSeed;
|
||||
// Try to read it as an integer
|
||||
if (sscanf(seedString.c_str(), "%d", &tmpSeed) > 0) {
|
||||
seed = tmpSeed;
|
||||
} // Hash the "seed"
|
||||
else {
|
||||
seed = Util::hashCode(seedString);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Read the game mode
|
||||
bool isCreative = true;
|
||||
if (sv.size() >= 3 && sv[2] == "survival")
|
||||
isCreative = false;
|
||||
|
||||
// Start a new level with the given name and seed
|
||||
LevelSettings settings(seed, isCreative? GameType::Creative : GameType::Survival);
|
||||
LOGI("Creating a level with id '%s', name '%s' and seed '%d'\n", levelId.c_str(), levelName.c_str(), seed);
|
||||
minecraft->selectLevel(levelId, levelName, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
}
|
||||
_state = _STATE_DEFAULT;
|
||||
}
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
worldsList->tick();
|
||||
|
||||
if (worldsList->hasPickedLevel) {
|
||||
|
||||
@@ -104,9 +104,6 @@ private:
|
||||
|
||||
bool _mouseHasBeenUp;
|
||||
bool _hasStartedLevel;
|
||||
int _state;
|
||||
static const int _STATE_DEFAULT = 0;
|
||||
static const int _STATE_CREATEWORLD = 1;
|
||||
//LevelStorageSource* levels;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,143 +2,233 @@
|
||||
#include "ProgressScreen.h"
|
||||
#include "ScreenChooser.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../components/ImageButton.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../../world/level/LevelSettings.h"
|
||||
#include "../../../platform/time.h"
|
||||
#include "client/gamemode/GameMode.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "../../../platform/log.h"
|
||||
|
||||
SimpleChooseLevelScreen::SimpleChooseLevelScreen(const std::string& levelName)
|
||||
:
|
||||
// bCreative(0),
|
||||
bGamemode(0),
|
||||
bBack(0),
|
||||
bCreate(0),
|
||||
levelName(levelName),
|
||||
hasChosen(false),
|
||||
gamemode(GameType::Survival),
|
||||
tLevelName(0, "World name"),
|
||||
tSeed(1, "World seed")
|
||||
: bHeader(0),
|
||||
bGamemode(0),
|
||||
bBack(0),
|
||||
bCreate(0),
|
||||
levelName(levelName),
|
||||
hasChosen(false),
|
||||
gamemode(GameType::Survival),
|
||||
tLevelName(0, "World name"),
|
||||
tSeed(1, "World seed")
|
||||
{
|
||||
}
|
||||
|
||||
SimpleChooseLevelScreen::~SimpleChooseLevelScreen()
|
||||
{
|
||||
// delete bCreative;
|
||||
delete bGamemode;
|
||||
delete bBack;
|
||||
if (bHeader) delete bHeader;
|
||||
delete bGamemode;
|
||||
delete bBack;
|
||||
delete bCreate;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::init()
|
||||
{
|
||||
if (minecraft->useTouchscreen()) {
|
||||
// bCreative = new Touch::TButton(1, "Creative mode");
|
||||
bGamemode = new Touch::TButton(2, "Survival mode");
|
||||
bBack = new Touch::TButton(3, "Back");
|
||||
bCreate = new Touch::TButton(4, "Create");
|
||||
} else {
|
||||
// bCreative = new Button(1, "Creative mode");
|
||||
bGamemode = new Button(2, "Survival mode");
|
||||
bBack = new Button(3, "Back");
|
||||
bCreate = new Button(4, "Create");
|
||||
}
|
||||
// buttons.push_back(bCreative);
|
||||
buttons.push_back(bGamemode);
|
||||
buttons.push_back(bBack);
|
||||
buttons.push_back(bCreate);
|
||||
// header + close button
|
||||
bHeader = new Touch::THeader(0, "Create World");
|
||||
// create the back/X button as ImageButton like CreditsScreen
|
||||
bBack = new ImageButton(2, "");
|
||||
{
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bBack->setImageDef(def, true);
|
||||
}
|
||||
if (minecraft->useTouchscreen()) {
|
||||
bGamemode = new Touch::TButton(1, "Survival mode");
|
||||
bCreate = new Touch::TButton(3, "Create");
|
||||
} else {
|
||||
bGamemode = new Button(1, "Survival mode");
|
||||
bCreate = new Button(3, "Create");
|
||||
}
|
||||
|
||||
textBoxes.push_back(&tLevelName);
|
||||
textBoxes.push_back(&tSeed);
|
||||
buttons.push_back(bHeader);
|
||||
buttons.push_back(bBack);
|
||||
buttons.push_back(bGamemode);
|
||||
buttons.push_back(bCreate);
|
||||
|
||||
// tabButtons.push_back(bCreative);
|
||||
tabButtons.push_back(bGamemode);
|
||||
tabButtons.push_back(bBack);
|
||||
tabButtons.push_back(bCreate);
|
||||
tabButtons.push_back(bGamemode);
|
||||
tabButtons.push_back(bBack);
|
||||
tabButtons.push_back(bCreate);
|
||||
|
||||
textBoxes.push_back(&tLevelName);
|
||||
textBoxes.push_back(&tSeed);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::setupPositions()
|
||||
{
|
||||
const int padding = 5;
|
||||
int buttonHeight = bBack->height;
|
||||
|
||||
/* bCreative->width = */ bGamemode->width = 120;
|
||||
tLevelName.width = tSeed.width = 120;
|
||||
bBack->width = bCreate->width = 60 - padding;
|
||||
// bCreative->x = (width - bCreative->width) / 2;
|
||||
// bCreative->y = height/3 - 40;
|
||||
bGamemode->x = (width - bGamemode->width) / 2;
|
||||
bGamemode->y = 2*height/3 - 30;
|
||||
bBack->x = bGamemode->x;
|
||||
bCreate->x = bGamemode->x + bGamemode->width - bCreate->width;
|
||||
bBack->y = bCreate->y = height - 40;
|
||||
// position back button in upper-right
|
||||
bBack->x = width - bBack->width;
|
||||
bBack->y = 0;
|
||||
|
||||
tLevelName.x = tSeed.x = bGamemode->x;
|
||||
tLevelName.y = 20;
|
||||
tSeed.y = tLevelName.y + 30;
|
||||
// header occupies remaining top bar
|
||||
if (bHeader) {
|
||||
bHeader->x = 0;
|
||||
bHeader->y = 0;
|
||||
bHeader->width = width - bBack->width;
|
||||
bHeader->height = buttonHeight;
|
||||
}
|
||||
|
||||
// layout the form elements below the header
|
||||
int centerX = width / 2;
|
||||
const int padding = 5;
|
||||
|
||||
tLevelName.width = tSeed.width = 200;
|
||||
tLevelName.x = centerX - tLevelName.width / 2;
|
||||
tLevelName.y = buttonHeight + 20;
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
bCreate->width = 100;
|
||||
bCreate->x = centerX - bCreate->width / 2;
|
||||
int bottomPadding = 20;
|
||||
bCreate->y = height - bottomPadding - bCreate->height;
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::tick()
|
||||
{
|
||||
// let any textboxes handle their own blinking/input
|
||||
for (auto* tb : textBoxes)
|
||||
tb->tick(minecraft);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
renderDirtBackground(0);
|
||||
renderDirtBackground(0);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
const char* str = NULL;
|
||||
const char* str = NULL;
|
||||
if (gamemode == GameType::Survival) {
|
||||
str = "Mobs, health and gather resources";
|
||||
} else if (gamemode == GameType::Creative) {
|
||||
str = "Unlimited resources and flying";
|
||||
}
|
||||
if (str) {
|
||||
drawCenteredString(minecraft->font, str, width/2, bGamemode->y + bGamemode->height + 4, 0xffcccccc);
|
||||
}
|
||||
|
||||
if (gamemode == GameType::Survival) {
|
||||
str = "Mobs, health and gather resources";
|
||||
} else if (gamemode == GameType::Creative) {
|
||||
str = "Unlimited resources and flying";
|
||||
}
|
||||
drawString(minecraft->font, "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
drawString(minecraft->font, "World seed:", tSeed.x, tSeed.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
|
||||
if (str) {
|
||||
drawCenteredString(minecraft->font, str, 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 seed:", tSeed.x, tSeed.y - Font::DefaultLineHeight - 2, 0xffcccccc);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
Screen::render(xm, ym, a);
|
||||
glDisable2(GL_BLEND);
|
||||
}
|
||||
|
||||
// mouse clicks should also manage textbox focus explicitly
|
||||
void SimpleChooseLevelScreen::mouseClicked(int x, int y, int buttonNum)
|
||||
{
|
||||
if (buttonNum == MouseAction::ACTION_LEFT) {
|
||||
// determine if the click landed on either textbox or its label above
|
||||
int lvlTop = tLevelName.y - (Font::DefaultLineHeight + 4);
|
||||
int lvlBottom = tLevelName.y + tLevelName.height;
|
||||
int lvlLeft = tLevelName.x;
|
||||
int lvlRight = tLevelName.x + tLevelName.width;
|
||||
bool clickedLevel = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom;
|
||||
|
||||
int seedTop = tSeed.y - (Font::DefaultLineHeight + 4);
|
||||
int seedBottom = tSeed.y + tSeed.height;
|
||||
int seedLeft = tSeed.x;
|
||||
int seedRight = tSeed.x + tSeed.width;
|
||||
bool clickedSeed = x >= seedLeft && x < seedRight && y >= seedTop && y < seedBottom;
|
||||
|
||||
if (clickedLevel) {
|
||||
LOGI("SimpleChooseLevelScreen: level textbox clicked (%d,%d)\n", x, y);
|
||||
tLevelName.setFocus(minecraft);
|
||||
tSeed.loseFocus(minecraft);
|
||||
} else if (clickedSeed) {
|
||||
LOGI("SimpleChooseLevelScreen: seed textbox clicked (%d,%d)\n", x, y);
|
||||
tSeed.setFocus(minecraft);
|
||||
tLevelName.loseFocus(minecraft);
|
||||
} else {
|
||||
// click outside both fields -> blur both
|
||||
tLevelName.loseFocus(minecraft);
|
||||
tSeed.loseFocus(minecraft);
|
||||
}
|
||||
}
|
||||
|
||||
// allow normal button and textbox handling too
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::buttonClicked( Button* button )
|
||||
{
|
||||
if (button == bBack) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return;
|
||||
}
|
||||
if (hasChosen)
|
||||
return;
|
||||
if (hasChosen)
|
||||
return;
|
||||
|
||||
if (button == bGamemode) {
|
||||
gamemode ^= 1;
|
||||
bGamemode->msg = (gamemode == GameType::Survival) ? "Survival mode" : "Creative mode";
|
||||
}
|
||||
if (button == bGamemode) {
|
||||
gamemode ^= 1;
|
||||
bGamemode->msg = (gamemode == GameType::Survival) ? "Survival mode" : "Creative mode";
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == bCreate) {
|
||||
int seed = getEpochTimeS();
|
||||
if (button == bCreate) {
|
||||
int seed = getEpochTimeS();
|
||||
if (!tSeed.text.empty()) {
|
||||
std::string seedString = Util::stringTrim(tSeed.text);
|
||||
int tmpSeed;
|
||||
if (sscanf(seedString.c_str(), "%d", &tmpSeed) > 0) {
|
||||
seed = tmpSeed;
|
||||
} else {
|
||||
seed = Util::hashCode(seedString);
|
||||
}
|
||||
}
|
||||
std::string levelId = getUniqueLevelName(tLevelName.text);
|
||||
LevelSettings settings(seed, gamemode);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
hasChosen = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tSeed.text.empty()) {
|
||||
std::string seedString = Util::stringTrim(tSeed.text);
|
||||
int tmpSeed;
|
||||
// Try to read it as an integer
|
||||
if (sscanf(seedString.c_str(), "%d", &tmpSeed) > 0) {
|
||||
seed = tmpSeed;
|
||||
} // Hash the "seed"
|
||||
else {
|
||||
seed = Util::hashCode(seedString);
|
||||
}
|
||||
}
|
||||
if (button == bBack) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
std::string levelId = getUniqueLevelName(tLevelName.text);
|
||||
LevelSettings settings(seed, gamemode);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
hasChosen = true;
|
||||
}
|
||||
void SimpleChooseLevelScreen::keyPressed(int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_ESCAPE) {
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return;
|
||||
}
|
||||
// let base class handle navigation and text box keys
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
void SimpleChooseLevelScreen::keyboardNewChar(char inputChar)
|
||||
{
|
||||
// forward character input to focused textbox(s)
|
||||
for (auto* tb : textBoxes) tb->handleChar(inputChar);
|
||||
}
|
||||
|
||||
bool SimpleChooseLevelScreen::handleBackEvent(bool isDown) {
|
||||
if (!isDown)
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
#include "ChooseLevelScreen.h"
|
||||
#include "../components/TextBox.h"
|
||||
|
||||
#include "../components/Button.h" // for Touch::THeader
|
||||
class Button;
|
||||
class ImageButton;
|
||||
|
||||
class SimpleChooseLevelScreen: public ChooseLevelScreen
|
||||
{
|
||||
@@ -14,23 +15,25 @@ public:
|
||||
virtual ~SimpleChooseLevelScreen();
|
||||
|
||||
void init();
|
||||
|
||||
void setupPositions();
|
||||
void tick();
|
||||
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
void buttonClicked(Button* button);
|
||||
bool handleBackEvent(bool isDown);
|
||||
virtual void keyPressed(int eventKey);
|
||||
virtual void keyboardNewChar(char inputChar);
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
|
||||
private:
|
||||
// Button* bCreative;
|
||||
Touch::THeader* bHeader;
|
||||
Button* bGamemode;
|
||||
Button* bBack;
|
||||
ImageButton* bBack;
|
||||
Button* bCreate;
|
||||
bool hasChosen;
|
||||
|
||||
std::string levelName;
|
||||
|
||||
int gamemode;
|
||||
|
||||
TextBox tLevelName;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "StartMenuScreen.h"
|
||||
#include "UsernameScreen.h"
|
||||
#include "SelectWorldScreen.h"
|
||||
#include "ProgressScreen.h"
|
||||
#include "JoinGameScreen.h"
|
||||
@@ -38,6 +39,10 @@ StartMenuScreen::~StartMenuScreen()
|
||||
|
||||
void StartMenuScreen::init()
|
||||
{
|
||||
if (minecraft->options.username.empty()) {
|
||||
return; // tick() will redirect to UsernameScreen
|
||||
}
|
||||
|
||||
buttons.push_back(&bHost);
|
||||
buttons.push_back(&bJoin);
|
||||
//buttons.push_back(&bTest);
|
||||
@@ -57,11 +62,8 @@ void StartMenuScreen::init()
|
||||
|
||||
copyright = "\xffMojang AB";//. Do not distribute!";
|
||||
|
||||
#ifdef PRE_ANDROID23
|
||||
std::string versionString = Common::getGameVersionString("j");
|
||||
#else
|
||||
std::string versionString = Common::getGameVersionString();
|
||||
#endif
|
||||
// always show base version string, suffix was previously added for Android builds
|
||||
std::string versionString = Common::getGameVersionString();
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
#ifdef __APPLE__
|
||||
@@ -106,6 +108,10 @@ void StartMenuScreen::setupPositions() {
|
||||
}
|
||||
|
||||
void StartMenuScreen::tick() {
|
||||
if (minecraft->options.username.empty()) {
|
||||
minecraft->setScreen(new UsernameScreen());
|
||||
return;
|
||||
}
|
||||
_updateLicense();
|
||||
}
|
||||
|
||||
@@ -181,8 +187,19 @@ void StartMenuScreen::render( int xm, int ym, float a )
|
||||
|
||||
drawString(font, version, versionPosX, 62, /*50,*/ 0xffcccccc);//0x666666);
|
||||
drawString(font, copyright, copyrightPosX, height - 10, 0xffffff);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
glEnable2(GL_BLEND);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/github.png")))
|
||||
blit(2, height - 10, 0, 0, 8, 8, 256, 256);
|
||||
{
|
||||
std::string txt = "Kolyah35/minecraft-pe-0.6.1";
|
||||
float wtxt = font->width(txt);
|
||||
Gui::drawColoredString(font, txt, 12, height - 10, 255);
|
||||
// underline link
|
||||
float y0 = height - 10 + font->lineHeight - 1;
|
||||
this->fill(12, (int)y0, 12 + (int)wtxt, (int)(y0 + 1), 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
void StartMenuScreen::_updateLicense()
|
||||
@@ -202,6 +219,17 @@ void StartMenuScreen::_updateLicense()
|
||||
}
|
||||
}
|
||||
|
||||
void StartMenuScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
const int logoX = 2;
|
||||
const int logoW = 8 + 2 + font->width("Kolyah35/minecraft-pe-0.6.1");
|
||||
const int logoY = height - 10;
|
||||
const int logoH = 10;
|
||||
if (x >= logoX && x <= logoX + logoW && y >= logoY && y <= logoY + logoH)
|
||||
minecraft->platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1");
|
||||
else
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
bool StartMenuScreen::handleBackEvent( bool isDown ) {
|
||||
minecraft->quit();
|
||||
return true;
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
void buttonClicked(Button* button);
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
bool handleBackEvent(bool isDown);
|
||||
bool isInGameScreen();
|
||||
private:
|
||||
|
||||
128
src/client/gui/screens/UsernameScreen.cpp
Normal file
128
src/client/gui/screens/UsernameScreen.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "UsernameScreen.h"
|
||||
#include "StartMenuScreen.h"
|
||||
#include "../../Minecraft.h"
|
||||
#include "../../User.h"
|
||||
#include "../Font.h"
|
||||
#include "../components/Button.h"
|
||||
#include "../../../platform/input/Keyboard.h"
|
||||
#include "../../../AppPlatform.h"
|
||||
|
||||
UsernameScreen::UsernameScreen()
|
||||
: _btnDone(0, "Done"),
|
||||
_input(""),
|
||||
_cursorBlink(0)
|
||||
{
|
||||
}
|
||||
|
||||
UsernameScreen::~UsernameScreen()
|
||||
{
|
||||
}
|
||||
|
||||
void UsernameScreen::init()
|
||||
{
|
||||
_input = "";
|
||||
_btnDone.active = false; // disabled until name typed
|
||||
buttons.push_back(&_btnDone);
|
||||
setupPositions();
|
||||
}
|
||||
|
||||
void UsernameScreen::setupPositions()
|
||||
{
|
||||
_btnDone.width = 120;
|
||||
_btnDone.height = 20;
|
||||
_btnDone.x = (width - _btnDone.width) / 2;
|
||||
_btnDone.y = height / 2 + 52;
|
||||
}
|
||||
|
||||
void UsernameScreen::tick()
|
||||
{
|
||||
_cursorBlink++;
|
||||
}
|
||||
|
||||
void UsernameScreen::keyPressed(int eventKey)
|
||||
{
|
||||
if (eventKey == Keyboard::KEY_BACKSPACE) {
|
||||
if (!_input.empty())
|
||||
_input.erase(_input.size() - 1, 1);
|
||||
} else if (eventKey == Keyboard::KEY_RETURN) {
|
||||
if (!_input.empty())
|
||||
buttonClicked(&_btnDone);
|
||||
}
|
||||
// deliberately do NOT call super::keyPressed — that would close the screen on Escape
|
||||
_btnDone.active = !_input.empty();
|
||||
}
|
||||
|
||||
void UsernameScreen::keyboardNewChar(char inputChar)
|
||||
{
|
||||
if (_input.size() < 16 && inputChar >= 32 && inputChar < 127)
|
||||
_input += inputChar;
|
||||
_btnDone.active = !_input.empty();
|
||||
}
|
||||
|
||||
void UsernameScreen::mouseClicked(int x, int y, int button)
|
||||
{
|
||||
int cx = width / 2;
|
||||
int cy = height / 2;
|
||||
int boxW = 160;
|
||||
int boxH = 18;
|
||||
int boxX = cx - boxW / 2;
|
||||
int boxY = cy - 5;
|
||||
if (x >= boxX && x <= boxX + boxW && y >= boxY && y <= boxY + boxH) {
|
||||
minecraft->platform()->showKeyboard();
|
||||
} else {
|
||||
super::mouseClicked(x, y, button);
|
||||
}
|
||||
}
|
||||
|
||||
void UsernameScreen::removed()
|
||||
{
|
||||
minecraft->platform()->hideKeyboard();
|
||||
}
|
||||
|
||||
void UsernameScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button == &_btnDone && !_input.empty()) {
|
||||
minecraft->options.username = _input;
|
||||
minecraft->options.save();
|
||||
minecraft->user->name = _input;
|
||||
minecraft->setScreen(NULL); // goes to StartMenuScreen
|
||||
}
|
||||
}
|
||||
|
||||
void UsernameScreen::render(int xm, int ym, float a)
|
||||
{
|
||||
// Dark dirt background
|
||||
renderBackground();
|
||||
|
||||
int cx = width / 2;
|
||||
int cy = height / 2;
|
||||
|
||||
// Title
|
||||
drawCenteredString(font, "Enter your username", cx, cy - 70, 0xffffffff);
|
||||
|
||||
// Subtitle
|
||||
drawCenteredString(font, "Please choose a username so others can easily", cx, cy - 52, 0xffaaaaaa);
|
||||
drawCenteredString(font, "identify you in chat. Don't worry, you can", cx, cy - 40, 0xffaaaaaa);
|
||||
drawCenteredString(font, "change it anytime.", cx, cy - 28, 0xffaaaaaa);
|
||||
|
||||
// Input box background
|
||||
int boxW = 160;
|
||||
int boxH = 18;
|
||||
int boxX = cx - boxW / 2;
|
||||
int boxY = cy - 5;
|
||||
fill(boxX - 1, boxY - 1, boxX + boxW + 1, boxY + boxH + 1, 0xff000000);
|
||||
fill(boxX, boxY, boxX + boxW, boxY + boxH, 0xff202020);
|
||||
|
||||
// Build display string with cursor
|
||||
std::string display = _input;
|
||||
if ((_cursorBlink / 10) % 2 == 0)
|
||||
display += '|';
|
||||
|
||||
font->draw(display, (float)(boxX + 4), (float)(boxY + (boxH - 8) / 2 + 1), 0xffffffff, false);
|
||||
|
||||
// Hint below box
|
||||
drawCenteredString(font, "Max 16 characters", cx, cy + 20, 0xff808080);
|
||||
|
||||
// Buttons (Done)
|
||||
super::render(xm, ym, a);
|
||||
}
|
||||
37
src/client/gui/screens/UsernameScreen.h
Normal file
37
src/client/gui/screens/UsernameScreen.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS__UsernameScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS__UsernameScreen_H__
|
||||
|
||||
#include "../Screen.h"
|
||||
#include "../components/Button.h"
|
||||
#include <string>
|
||||
|
||||
class UsernameScreen : public Screen
|
||||
{
|
||||
typedef Screen super;
|
||||
public:
|
||||
UsernameScreen();
|
||||
virtual ~UsernameScreen();
|
||||
|
||||
void init();
|
||||
virtual void setupPositions() override;
|
||||
void render(int xm, int ym, float a);
|
||||
void tick();
|
||||
|
||||
virtual bool isPauseScreen() { return false; }
|
||||
|
||||
virtual void keyPressed(int eventKey);
|
||||
virtual void keyboardNewChar(char inputChar);
|
||||
virtual bool handleBackEvent(bool isDown) { return true; } // block back/escape
|
||||
virtual void removed();
|
||||
virtual void mouseClicked(int x, int y, int button);
|
||||
|
||||
protected:
|
||||
virtual void buttonClicked(Button* button);
|
||||
|
||||
private:
|
||||
Button _btnDone;
|
||||
std::string _input;
|
||||
int _cursorBlink;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS__UsernameScreen_H__*/
|
||||
@@ -283,8 +283,7 @@ SelectWorldScreen::SelectWorldScreen()
|
||||
bHeader (0, "Select world"),
|
||||
bWorldView(4, ""),
|
||||
worldsList(NULL),
|
||||
_hasStartedLevel(false),
|
||||
_state(_STATE_DEFAULT)
|
||||
_hasStartedLevel(false)
|
||||
{
|
||||
bDelete.active = false;
|
||||
|
||||
@@ -349,9 +348,9 @@ void SelectWorldScreen::setupPositions() {
|
||||
void SelectWorldScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bCreate.id) {
|
||||
if (_state == _STATE_DEFAULT && !_hasStartedLevel) {
|
||||
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_CREATE_NEW_WORLD);
|
||||
_state = _STATE_CREATEWORLD;
|
||||
if (!_hasStartedLevel) {
|
||||
std::string name = getUniqueLevelName("World");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
}
|
||||
}
|
||||
if (button->id == bDelete.id) {
|
||||
@@ -392,9 +391,10 @@ static char ILLEGAL_FILE_CHARACTERS[] = {
|
||||
|
||||
void SelectWorldScreen::tick()
|
||||
{
|
||||
#if 0
|
||||
if (_state == _STATE_CREATEWORLD) {
|
||||
#if defined(RPI)
|
||||
std::string levelId = getUniqueLevelName("perf");
|
||||
std::string levelId = getUniqueLevelName("World");
|
||||
//int seed = Util::hashCode("/r/Minecraft");
|
||||
LevelSettings settings(getEpochTimeS(), GameType::Creative);
|
||||
minecraft->selectLevel(levelId, levelId, settings);
|
||||
@@ -402,7 +402,7 @@ void SelectWorldScreen::tick()
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
#elif defined(PLATFORM_DESKTOP)
|
||||
std::string name = getUniqueLevelName("perf");
|
||||
std::string name = getUniqueLevelName("World");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
#else
|
||||
int status = minecraft->platform()->getUserInputStatus();
|
||||
@@ -461,14 +461,15 @@ void SelectWorldScreen::tick()
|
||||
worldsList->hasPickedLevel = false;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
worldsList->tick();
|
||||
|
||||
if (worldsList->hasPickedLevel) {
|
||||
if (worldsList->pickedIndex == worldsList->levels.size()) {
|
||||
worldsList->hasPickedLevel = false;
|
||||
minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_CREATE_NEW_WORLD);
|
||||
_state = _STATE_CREATEWORLD;
|
||||
std::string name = getUniqueLevelName("World");
|
||||
minecraft->setScreen(new SimpleChooseLevelScreen(name));
|
||||
} else {
|
||||
minecraft->selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None());
|
||||
minecraft->hostMultiplayer();
|
||||
|
||||
@@ -112,9 +112,6 @@ private:
|
||||
|
||||
bool _mouseHasBeenUp;
|
||||
bool _hasStartedLevel;
|
||||
int _state;
|
||||
static const int _STATE_DEFAULT = 0;
|
||||
static const int _STATE_CREATEWORLD = 1;
|
||||
//LevelStorageSource* levels;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -22,6 +22,62 @@
|
||||
#include "../DialogDefinitions.h"
|
||||
#include "../SimpleChooseLevelScreen.h"
|
||||
|
||||
//
|
||||
// Buy Button implementation
|
||||
//
|
||||
BuyButton::BuyButton(int id)
|
||||
: super(id, "")
|
||||
{
|
||||
ImageDef def;
|
||||
// Setup the source rectangle
|
||||
def.setSrc(IntRectangle(64, 182, 190, 55));
|
||||
def.width = 75;//rc.w / 3;
|
||||
def.height = 75 * (55.0f / 190.0f);//rc.h / 3;
|
||||
def.name = "gui/gui.png";
|
||||
|
||||
setImageDef(def, true);
|
||||
}
|
||||
|
||||
void BuyButton::render(Minecraft* minecraft, int xm, int ym) {
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
bool hovered = active && (minecraft->useTouchscreen()? (xm >= x && ym >= y && xm < x + width && ym < y + height) : false);
|
||||
renderBg(minecraft, xm, ym);
|
||||
TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId;
|
||||
if ( Textures::isTextureIdValid(texId) ) {
|
||||
const ImageDef& d = _imageDef;
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
if (!active) t.color(0xff808080);
|
||||
else if (hovered||selected) t.color(0xffcccccc);
|
||||
//else t.color(0xffe0e0e0);
|
||||
else t.color(0xffffffff);
|
||||
|
||||
float hx = ((float) d.width) * 0.5f;
|
||||
float hy = ((float) d.height) * 0.5f;
|
||||
const float cx = ((float)x+d.x) + hx;
|
||||
const float cy = ((float)y+d.y) + hy;
|
||||
if (hovered) {
|
||||
hx *= 0.95f;
|
||||
hy *= 0.95f;
|
||||
}
|
||||
|
||||
const TextureData* td = minecraft->textures->getTemporaryTextureData(texId);
|
||||
const IntRectangle* src = _imageDef.getSrc();
|
||||
if (td != NULL && src != NULL) {
|
||||
float u0 = (src->x) / (float)td->w;
|
||||
float u1 = (src->x+src->w) / (float)td->w;
|
||||
float v0 = (src->y) / (float)td->h;
|
||||
float v1 = (src->y+src->h) / (float)td->h;
|
||||
t.vertexUV(cx-hx, cy-hy, blitOffset, u0, v0);
|
||||
t.vertexUV(cx-hx, cy+hy, blitOffset, u0, v1);
|
||||
t.vertexUV(cx+hx, cy+hy, blitOffset, u1, v1);
|
||||
t.vertexUV(cx+hx, cy-hy, blitOffset, u1, v0);
|
||||
}
|
||||
t.draw();
|
||||
}
|
||||
}
|
||||
|
||||
namespace Touch {
|
||||
|
||||
//
|
||||
@@ -32,7 +88,8 @@ namespace Touch {
|
||||
StartMenuScreen::StartMenuScreen()
|
||||
: bHost( 2, "Start Game"),
|
||||
bJoin( 3, "Join Game"),
|
||||
bOptions( 4, "Options")
|
||||
bOptions( 4, "Options"),
|
||||
bBuy( 5)
|
||||
{
|
||||
ImageDef def;
|
||||
bJoin.width = 75;
|
||||
@@ -61,19 +118,21 @@ void StartMenuScreen::init()
|
||||
buttons.push_back(&bJoin);
|
||||
buttons.push_back(&bOptions);
|
||||
|
||||
//buttons.push_back(&bTest);
|
||||
|
||||
|
||||
tabButtons.push_back(&bHost);
|
||||
tabButtons.push_back(&bJoin);
|
||||
tabButtons.push_back(&bOptions);
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
buttons.push_back(&bBuy);
|
||||
tabButtons.push_back(&bBuy);
|
||||
#endif
|
||||
|
||||
copyright = "\xffMojang AB";//. Do not distribute!";
|
||||
|
||||
#ifdef PRE_ANDROID23
|
||||
std::string versionString = Common::getGameVersionString("j");
|
||||
#else
|
||||
std::string versionString = Common::getGameVersionString();
|
||||
#endif
|
||||
// always show base version string
|
||||
std::string versionString = Common::getGameVersionString();
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
#ifdef __APPLE__
|
||||
@@ -103,31 +162,26 @@ void StartMenuScreen::setupPositions() {
|
||||
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);
|
||||
//bBuy.y = bOptions.y - bBuy.h - 6;
|
||||
//bBuy.x = bOptions.x + bOptions.w - bBuy.w;
|
||||
|
||||
bBuy.y = height - bBuy.height - 3;
|
||||
bBuy.x = (width - bBuy.width) / 2;
|
||||
|
||||
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)
|
||||
@@ -149,6 +203,11 @@ void StartMenuScreen::buttonClicked(::Button* button) {
|
||||
{
|
||||
minecraft->setScreen(new OptionsScreen());
|
||||
}
|
||||
if (button->id == bBuy.id)
|
||||
{
|
||||
minecraft->platform()->buyGame();
|
||||
//minecraft->setScreen(new BuyGameScreen());
|
||||
}
|
||||
}
|
||||
|
||||
bool StartMenuScreen::isInGameScreen() { return false; }
|
||||
@@ -187,6 +246,10 @@ void StartMenuScreen::render( int xm, int ym, float a )
|
||||
|
||||
drawString(font, version, versionPosX, (int)(y+h)+2, /*50,*/ 0xffcccccc);//0x666666);
|
||||
drawString(font, copyright, copyrightPosX, height - 10, 0xffffff);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/github.png")))
|
||||
blit(2, height - 10, 0, 0, 8, 8, 256, 256);
|
||||
drawString(font, "Kolyah35/minecraft-pe-0.6.1", 12, height - 10, 0xffcccccc);
|
||||
//patch->draw(t, 0, 20);
|
||||
}
|
||||
Screen::render(xm, ym, a);
|
||||
@@ -210,9 +273,21 @@ void StartMenuScreen::_updateLicense()
|
||||
}
|
||||
}
|
||||
|
||||
void StartMenuScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
const int logoX = 2;
|
||||
const int logoW = 8 + 2 + font->width("Kolyah35/minecraft-pe-0.6.1");
|
||||
const int logoY = height - 10;
|
||||
const int logoH = 10;
|
||||
if (x >= logoX && x <= logoX + logoW && y >= logoY && y <= logoY + logoH)
|
||||
minecraft->platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1");
|
||||
else
|
||||
Screen::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
bool StartMenuScreen::handleBackEvent( bool isDown ) {
|
||||
minecraft->quit();
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
} // namespace Touch
|
||||
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
#include "../../components/LargeImageButton.h"
|
||||
#include "../../components/TextBox.h"
|
||||
|
||||
class BuyButton: public ImageButton {
|
||||
typedef ImageButton super;
|
||||
public:
|
||||
BuyButton(int id);
|
||||
void render(Minecraft* minecraft, int xm, int ym);
|
||||
};
|
||||
|
||||
|
||||
namespace Touch {
|
||||
|
||||
class StartMenuScreen: public Screen
|
||||
@@ -20,6 +28,7 @@ public:
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
void buttonClicked(Button* button);
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
bool handleBackEvent(bool isDown);
|
||||
bool isInGameScreen();
|
||||
private:
|
||||
@@ -28,6 +37,7 @@ private:
|
||||
LargeImageButton bHost;
|
||||
LargeImageButton bJoin;
|
||||
LargeImageButton bOptions;
|
||||
BuyButton bBuy;
|
||||
|
||||
std::string copyright;
|
||||
int copyrightPosX;
|
||||
|
||||
Reference in New Issue
Block a user