mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-20 23:13:33 +00:00
the whole game
This commit is contained in:
268
src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp
Executable file
268
src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp
Executable file
@@ -0,0 +1,268 @@
|
||||
#include "TouchIngameBlockSelectionScreen.h"
|
||||
#include "../crafting/WorkbenchScreen.h"
|
||||
#include "../../Screen.h"
|
||||
#include "../../components/ImageButton.h"
|
||||
#include "../../components/InventoryPane.h"
|
||||
#include "../../../gamemode/GameMode.h"
|
||||
#include "../../../renderer/TileRenderer.h"
|
||||
#include "../../../player/LocalPlayer.h"
|
||||
#include "../../../renderer/gles.h"
|
||||
#include "../../../renderer/entity/ItemRenderer.h"
|
||||
#include "../../../renderer/Tesselator.h"
|
||||
#include "../../../renderer/Textures.h"
|
||||
#include "../../../Minecraft.h"
|
||||
#include "../../../sound/SoundEngine.h"
|
||||
#include "../../../../world/entity/player/Inventory.h"
|
||||
#include "../../../../platform/input/Mouse.h"
|
||||
#include "../../../../util/Mth.h"
|
||||
#include "../../../../world/item/ItemInstance.h"
|
||||
#include "../../../../world/entity/player/Player.h"
|
||||
#include "../../../../world/item/crafting/Recipe.h"
|
||||
#include "../../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../ArmorScreen.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
#if defined(__APPLE__)
|
||||
static const std::string demoVersionString("Not available in the Lite version");
|
||||
#else
|
||||
static const std::string demoVersionString("Not available in the demo version");
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const float BorderPixels = 4;
|
||||
#ifdef DEMO_MODE
|
||||
static const float BlockPixels = 22;
|
||||
#else
|
||||
static const float BlockPixels = 22;
|
||||
#endif
|
||||
#else
|
||||
static const float BorderPixels = 4;
|
||||
static const float BlockPixels = 24;
|
||||
#endif
|
||||
|
||||
static const int ItemSize = (int)(BlockPixels + 2*BorderPixels);
|
||||
|
||||
static const int Bx = 10; // Border Frame width
|
||||
static const int By = 6; // Border Frame height
|
||||
|
||||
//
|
||||
// Block selection screen
|
||||
//
|
||||
IngameBlockSelectionScreen::IngameBlockSelectionScreen()
|
||||
: selectedItem(0),
|
||||
_blockList(NULL),
|
||||
_pendingClose(false),
|
||||
bArmor (4, "Armor"),
|
||||
bDone (3, ""),
|
||||
//bDone (3, "Done"),
|
||||
bMenu (2, "Menu"),
|
||||
bCraft (1, "Craft"),
|
||||
bHeader (0, "Select blocks")
|
||||
{
|
||||
}
|
||||
|
||||
IngameBlockSelectionScreen::~IngameBlockSelectionScreen()
|
||||
{
|
||||
delete _blockList;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::init()
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
|
||||
//const int itemWidth = 2 * BorderPixels +
|
||||
|
||||
int maxWidth = width - Bx - Bx;
|
||||
InventoryColumns = maxWidth / ItemSize;
|
||||
const int realWidth = InventoryColumns * ItemSize;
|
||||
const int realBx = (width - realWidth) / 2;
|
||||
|
||||
IntRectangle rect(realBx,
|
||||
#ifdef __APPLE__
|
||||
24 + By - ((width==240)?1:0), realWidth, ((width==240)?1:0) + height-By-By-20-24);
|
||||
#else
|
||||
24 + By, realWidth, height-By-By-20-24);
|
||||
#endif
|
||||
|
||||
_blockList = new InventoryPane(this, minecraft, rect, width, BorderPixels, inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE, ItemSize, (int)BorderPixels);
|
||||
_blockList->fillMarginX = realBx;
|
||||
|
||||
//for (int i = 0; i < inventory->getContainerSize(); ++i)
|
||||
//LOGI("> %d - %s\n", i, inventory->getItem(i)? inventory->getItem(i)->getDescriptionId().c_str() : "<-->\n");
|
||||
|
||||
InventorySize = inventory->getContainerSize();
|
||||
InventoryRows = 1 + (InventorySize-1) / InventoryColumns;
|
||||
|
||||
//
|
||||
// Buttons
|
||||
//
|
||||
ImageDef def;
|
||||
def.name = "gui/spritesheet.png";
|
||||
def.x = 0;
|
||||
def.y = 1;
|
||||
def.width = def.height = 18;
|
||||
def.setSrc(IntRectangle(60, 0, 18, 18));
|
||||
bDone.setImageDef(def, true);
|
||||
bDone.width = bDone.height = 19;
|
||||
|
||||
bDone.scaleWhenPressed = false;
|
||||
|
||||
buttons.push_back(&bHeader);
|
||||
buttons.push_back(&bDone);
|
||||
if (!minecraft->isCreativeMode()) {
|
||||
buttons.push_back(&bCraft);
|
||||
buttons.push_back(&bArmor);
|
||||
}
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::setupPositions() {
|
||||
bHeader.y = bDone.y = bCraft.y = 0;
|
||||
bDone.x = width - bDone.width;
|
||||
bCraft.x = 0;//width - bDone.w - bCraft.w;
|
||||
bCraft.width = bArmor.width = 48;
|
||||
bArmor.x = bCraft.width;
|
||||
|
||||
if (minecraft->isCreativeMode()) {
|
||||
bHeader.x = 0;
|
||||
bHeader.width = width;// - bDone.w;
|
||||
bHeader.xText = width/2; // Center of the screen
|
||||
} else {
|
||||
bHeader.x = bCraft.width + bArmor.width;
|
||||
bHeader.width = width - bCraft.width - bArmor.width;// - bDone.w;
|
||||
bHeader.xText = bHeader.x + (bHeader.width - bDone.width) /2;
|
||||
}
|
||||
|
||||
clippingArea.x = 0;
|
||||
clippingArea.w = minecraft->width;
|
||||
clippingArea.y = 0;
|
||||
clippingArea.h = (int)(Gui::GuiScale * 24);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::removed()
|
||||
{
|
||||
minecraft->gui.inventoryUpdated();
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotPosX(int slotX) {
|
||||
// @todo: Number of columns
|
||||
return width / 2 - InventoryColumns * 10 + slotX * 20 + 2;
|
||||
}
|
||||
|
||||
int IngameBlockSelectionScreen::getSlotPosY(int slotY) {
|
||||
return height - 16 - 3 - 22 * 2 - 22 * slotY;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum) {
|
||||
_pendingClose = _blockList->_clickArea->isInside((float)x, (float)y);
|
||||
if (!_pendingClose)
|
||||
super::mouseClicked(x, y, buttonNum);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum) {
|
||||
if (_pendingClose && _blockList->_clickArea->isInside((float)x, (float)y))
|
||||
minecraft->setScreen(NULL);
|
||||
else
|
||||
super::mouseReleased(x, y, buttonNum);
|
||||
}
|
||||
|
||||
bool IngameBlockSelectionScreen::addItem(const InventoryPane* pane, int itemId)
|
||||
{
|
||||
Inventory* inventory = minecraft->player->inventory;
|
||||
itemId += Inventory::MAX_SELECTION_SIZE;
|
||||
|
||||
if (!inventory->getItem(itemId))
|
||||
return false;
|
||||
|
||||
inventory->moveToSelectionSlot(0, itemId, true);
|
||||
|
||||
inventory->selectSlot(0);
|
||||
#ifdef __APPLE__
|
||||
minecraft->soundEngine->playUI("random.pop", 0.3f, 0.3f);//1.0f + 0.2f*(Mth::random()-Mth::random()));
|
||||
#else
|
||||
minecraft->soundEngine->playUI("random.pop2", 1.0f, 0.3f);//1.0f + 0.2f*(Mth::random()-Mth::random()));
|
||||
#endif
|
||||
|
||||
// Flash the selected gui item
|
||||
minecraft->gui.flashSlot(inventory->selected);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::tick()
|
||||
{
|
||||
_blockList->tick();
|
||||
super::tick();
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
glDisable2(GL_DEPTH_TEST);
|
||||
glEnable2(GL_BLEND);
|
||||
|
||||
Screen::render(xm, ym, a);
|
||||
_blockList->render(xm, ym, a);
|
||||
|
||||
// render frame
|
||||
IntRectangle& bbox = _blockList->rect;
|
||||
Tesselator::instance.colorABGR(0xffffffff);
|
||||
minecraft->textures->loadAndBindTexture("gui/itemframe.png");
|
||||
glEnable2(GL_BLEND);
|
||||
glColor4f2(1, 1, 1, 1);
|
||||
glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
blit(0, bbox.y-By, 0, 0, width, bbox.h+By+By, 215, 256); // why bbox.h + 1*B?
|
||||
glDisable2(GL_BLEND);
|
||||
|
||||
glEnable2(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::renderDemoOverlay() {
|
||||
#ifdef DEMO_MODE
|
||||
fill( getSlotPosX(0) - 3, getSlotPosY(1) - 3,
|
||||
getSlotPosX(9) - 3, getSlotPosY(-1) - 3, 0xa0 << 24);
|
||||
|
||||
const int centerX = (getSlotPosX(4) + getSlotPosX(5)) / 2;
|
||||
const int centerY = (getSlotPosY(0) + getSlotPosY(1)) / 2 + 5;
|
||||
drawCenteredString(minecraft->font, demoVersionString, centerX, centerY, 0xffffffff);
|
||||
#endif /*DEMO_MODE*/
|
||||
}
|
||||
|
||||
void IngameBlockSelectionScreen::buttonClicked(Button* button) {
|
||||
if (button->id == bDone.id)
|
||||
minecraft->setScreen(NULL);
|
||||
|
||||
if (button->id == bMenu.id)
|
||||
minecraft->screenChooser.setScreen(SCREEN_PAUSE);
|
||||
|
||||
if (button->id == bCraft.id)
|
||||
minecraft->setScreen(new WorkbenchScreen(Recipe::SIZE_2X2));
|
||||
|
||||
if (button == &bArmor)
|
||||
minecraft->setScreen(new ArmorScreen());
|
||||
}
|
||||
|
||||
bool IngameBlockSelectionScreen::isAllowed( int slot )
|
||||
{
|
||||
if (slot < 0 || slot >= minecraft->player->inventory->getContainerSize())
|
||||
return false;
|
||||
|
||||
#ifdef DEMO_MODE
|
||||
if (slot >= (minecraft->isCreativeMode()? 28 : 27)) return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IngameBlockSelectionScreen::hasClippingArea( IntRectangle& out )
|
||||
{
|
||||
out = clippingArea;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<const ItemInstance*> IngameBlockSelectionScreen::getItems( const InventoryPane* forPane )
|
||||
{
|
||||
std::vector<const ItemInstance*> out;
|
||||
for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i)
|
||||
out.push_back(minecraft->player->inventory->getItem(i));
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
69
src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.h
Executable file
69
src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.h
Executable file
@@ -0,0 +1,69 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchIngameBlockSelectionScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchIngameBlockSelectionScreen_H__
|
||||
|
||||
#include "../../Screen.h"
|
||||
#include "../../components/InventoryPane.h"
|
||||
#include "../../components/Button.h"
|
||||
#include "../../components/ScrollingPane.h"
|
||||
#include "../../components/ItemPane.h"
|
||||
#include "../../TweenData.h"
|
||||
#include "../../../player/input/touchscreen/TouchAreaModel.h"
|
||||
#include "../../../../AppPlatform.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
class IngameBlockSelectionScreen : public Screen,
|
||||
public IInventoryPaneCallback
|
||||
{
|
||||
typedef Screen super;
|
||||
|
||||
public:
|
||||
IngameBlockSelectionScreen();
|
||||
virtual ~IngameBlockSelectionScreen();
|
||||
|
||||
virtual void init();
|
||||
virtual void setupPositions();
|
||||
virtual void removed();
|
||||
|
||||
void tick();
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
bool hasClippingArea(IntRectangle& out);
|
||||
|
||||
// IInventoryPaneCallback
|
||||
bool addItem(const InventoryPane* pane, int itemId);
|
||||
bool isAllowed(int slot);
|
||||
std::vector<const ItemInstance*> getItems(const InventoryPane* forPane);
|
||||
|
||||
void buttonClicked(Button* button);
|
||||
protected:
|
||||
virtual void mouseClicked(int x, int y, int buttonNum);
|
||||
virtual void mouseReleased(int x, int y, int buttonNum);
|
||||
private:
|
||||
void renderDemoOverlay();
|
||||
|
||||
//int getLinearSlotId(int x, int y);
|
||||
int getSlotPosX(int slotX);
|
||||
int getSlotPosY(int slotY);
|
||||
|
||||
private:
|
||||
int selectedItem;
|
||||
bool _pendingClose;
|
||||
InventoryPane* _blockList;
|
||||
|
||||
THeader bHeader;
|
||||
ImageButton bDone;
|
||||
TButton bCraft;
|
||||
TButton bArmor;
|
||||
TButton bMenu;
|
||||
|
||||
IntRectangle clippingArea;
|
||||
|
||||
int InventoryRows;
|
||||
int InventorySize;
|
||||
int InventoryColumns;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchIngameBlockSelectionScreen_H__*/
|
||||
233
src/client/gui/screens/touch/TouchJoinGameScreen.cpp
Executable file
233
src/client/gui/screens/touch/TouchJoinGameScreen.cpp
Executable file
@@ -0,0 +1,233 @@
|
||||
#include "TouchJoinGameScreen.h"
|
||||
#include "../StartMenuScreen.h"
|
||||
#include "../ProgressScreen.h"
|
||||
#include "../../Font.h"
|
||||
#include "../../../Minecraft.h"
|
||||
#include "../../../renderer/Textures.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
//
|
||||
// Games list
|
||||
//
|
||||
|
||||
void AvailableGamesList::selectStart( int item) {
|
||||
startSelected = item;
|
||||
}
|
||||
|
||||
void AvailableGamesList::selectCancel() {
|
||||
startSelected = -1;
|
||||
}
|
||||
|
||||
void AvailableGamesList::selectItem( int item, bool doubleClick ) {
|
||||
LOGI("selected an item! %d\n", item);
|
||||
selectedItem = item;
|
||||
}
|
||||
|
||||
void AvailableGamesList::renderItem( int i, int x, int y, int h, Tesselator& t )
|
||||
{
|
||||
if (startSelected == i && Multitouch::getFirstActivePointerIdEx() >= 0) {
|
||||
fill((int)x0, y, (int)x1, y+h, 0x809E684F);
|
||||
}
|
||||
|
||||
//static int colors[2] = {0xffffb0, 0xcccc90};
|
||||
const PingedCompatibleServer& s = copiedServerList[i];
|
||||
unsigned int color = s.isSpecial? 0x6090a0 : 0xffffb0;
|
||||
unsigned int color2 = 0xffffa0;//colors[i&1];
|
||||
|
||||
int xx1 = (int)x0 + 24;
|
||||
int xx2 = xx1;
|
||||
|
||||
if (s.isSpecial) {
|
||||
xx1 += 50;
|
||||
|
||||
glEnable2(GL_TEXTURE_2D);
|
||||
glColor4f2(1,1,1,1);
|
||||
glEnable2(GL_BLEND);
|
||||
minecraft->textures->loadAndBindTexture("gui/badge/minecon140.png");
|
||||
blit(xx2, y + 6, 0, 0, 37, 8, 140, 240);
|
||||
}
|
||||
|
||||
drawString(minecraft->font, s.name.C_String(), xx1, y + 4 + 2, color);
|
||||
drawString(minecraft->font, s.address.ToString(false), xx2, y + 18, color2);
|
||||
|
||||
/*
|
||||
drawString(minecraft->font, copiedServerList[i].name.C_String(), (int)x0 + 24, y + 4, color);
|
||||
drawString(minecraft->font, copiedServerList[i].address.ToString(false), (int)x0 + 24, y + 18, color);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Join Game screen
|
||||
//
|
||||
JoinGameScreen::JoinGameScreen()
|
||||
: bJoin( 2, "Join Game"),
|
||||
bBack( 3, "Back"),
|
||||
bHeader(0, ""),
|
||||
gamesList(NULL)
|
||||
{
|
||||
bJoin.active = false;
|
||||
//gamesList->yInertia = 0.5f;
|
||||
}
|
||||
|
||||
JoinGameScreen::~JoinGameScreen()
|
||||
{
|
||||
delete gamesList;
|
||||
}
|
||||
|
||||
void JoinGameScreen::init()
|
||||
{
|
||||
//buttons.push_back(&bJoin);
|
||||
buttons.push_back(&bBack);
|
||||
buttons.push_back(&bHeader);
|
||||
|
||||
minecraft->raknetInstance->clearServerList();
|
||||
gamesList = new AvailableGamesList(minecraft, width, height);
|
||||
|
||||
#ifdef ANDROID
|
||||
//tabButtons.push_back(&bJoin);
|
||||
tabButtons.push_back(&bBack);
|
||||
#endif
|
||||
}
|
||||
|
||||
void JoinGameScreen::setupPositions() {
|
||||
//int yBase = height - 26;
|
||||
|
||||
//#ifdef ANDROID
|
||||
bJoin.y = 0;
|
||||
bBack.y = 0;
|
||||
bHeader.y = 0;
|
||||
//#endif
|
||||
|
||||
// Center buttons
|
||||
//bJoin.x = width / 2 - 4 - bJoin.w;
|
||||
bBack.x = 0;//width / 2 + 4;
|
||||
bHeader.x = bBack.width;
|
||||
bHeader.width = width - bHeader.x;
|
||||
}
|
||||
|
||||
void JoinGameScreen::buttonClicked(Button* button)
|
||||
{
|
||||
if (button->id == bJoin.id)
|
||||
{
|
||||
if (isIndexValid(gamesList->selectedItem))
|
||||
{
|
||||
PingedCompatibleServer selectedServer = gamesList->copiedServerList[gamesList->selectedItem];
|
||||
minecraft->joinMultiplayer(selectedServer);
|
||||
{
|
||||
bJoin.active = false;
|
||||
bBack.active = false;
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
}
|
||||
}
|
||||
//minecraft->locateMultiplayer();
|
||||
//minecraft->setScreen(new JoinGameScreen());
|
||||
}
|
||||
if (button->id == bBack.id)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinGameScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool JoinGameScreen::isIndexValid( int index )
|
||||
{
|
||||
return gamesList && index >= 0 && index < gamesList->getNumberOfItems();
|
||||
}
|
||||
|
||||
void JoinGameScreen::tick()
|
||||
{
|
||||
if (isIndexValid(gamesList->selectedItem)) {
|
||||
buttonClicked(&bJoin);
|
||||
return;
|
||||
}
|
||||
|
||||
//gamesList->tick();
|
||||
|
||||
const ServerList& orgServerList = minecraft->raknetInstance->getServerList();
|
||||
ServerList serverList;
|
||||
for (unsigned int i = 0; i < orgServerList.size(); ++i)
|
||||
if (orgServerList[i].name.GetLength() > 0)
|
||||
serverList.push_back(orgServerList[i]);
|
||||
|
||||
if (serverList.size() != gamesList->copiedServerList.size())
|
||||
{
|
||||
// copy the currently selected item
|
||||
PingedCompatibleServer selectedServer;
|
||||
bool hasSelection = false;
|
||||
if (isIndexValid(gamesList->selectedItem))
|
||||
{
|
||||
selectedServer = gamesList->copiedServerList[gamesList->selectedItem];
|
||||
hasSelection = true;
|
||||
}
|
||||
|
||||
gamesList->copiedServerList = serverList;
|
||||
gamesList->selectItem(-1, false);
|
||||
|
||||
// re-select previous item if it still exists
|
||||
if (hasSelection)
|
||||
{
|
||||
for (unsigned int i = 0; i < gamesList->copiedServerList.size(); i++)
|
||||
{
|
||||
if (gamesList->copiedServerList[i].address == selectedServer.address)
|
||||
{
|
||||
gamesList->selectItem(i, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = (int)gamesList->copiedServerList.size()-1; i >= 0 ; --i) {
|
||||
for (int j = 0; j < (int) serverList.size(); ++j)
|
||||
if (serverList[j].address == gamesList->copiedServerList[i].address)
|
||||
gamesList->copiedServerList[i].name = serverList[j].name;
|
||||
}
|
||||
}
|
||||
|
||||
bJoin.active = isIndexValid(gamesList->selectedItem);
|
||||
}
|
||||
|
||||
void JoinGameScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
bool hasNetwork = minecraft->platform()->isNetworkEnabled(true);
|
||||
#ifdef WIN32
|
||||
hasNetwork = hasNetwork && !GetAsyncKeyState(VK_TAB);
|
||||
#endif
|
||||
|
||||
renderBackground();
|
||||
if (hasNetwork) gamesList->render(xm, ym, a);
|
||||
else gamesList->renderDirtBackground();
|
||||
Screen::render(xm, ym, a);
|
||||
|
||||
const int baseX = bHeader.x + bHeader.width / 2;
|
||||
|
||||
if (hasNetwork) {
|
||||
std::string s = "Scanning for WiFi Games...";
|
||||
drawCenteredString(minecraft->font, s, baseX, 8, 0xffffffff);
|
||||
|
||||
const int textWidth = minecraft->font->width(s);
|
||||
const int spinnerX = baseX + textWidth / 2 + 6;
|
||||
|
||||
static const char* spinnerTexts[] = {"-", "\\", "|", "/"};
|
||||
int n = ((int)(5.5f * getTimeS()) % 4);
|
||||
drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, 8, 0xffffffff);
|
||||
} else {
|
||||
drawCenteredString(minecraft->font, "WiFi is disabled", baseX, 8, 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
bool JoinGameScreen::isInGameScreen() { return false; }
|
||||
|
||||
};
|
||||
74
src/client/gui/screens/touch/TouchJoinGameScreen.h
Executable file
74
src/client/gui/screens/touch/TouchJoinGameScreen.h
Executable file
@@ -0,0 +1,74 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchJoinGameScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchJoinGameScreen_H__
|
||||
|
||||
#include "../../Screen.h"
|
||||
#include "../../components/Button.h"
|
||||
#include "../../components/SmallButton.h"
|
||||
#include "../../components/RolledSelectionListV.h"
|
||||
#include "../../../Minecraft.h"
|
||||
#include "../../../../platform/input/Multitouch.h"
|
||||
#include "../../../../network/RakNetInstance.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
class JoinGameScreen;
|
||||
|
||||
class AvailableGamesList : public RolledSelectionListV
|
||||
{
|
||||
int startSelected;
|
||||
int selectedItem;
|
||||
ServerList copiedServerList;
|
||||
|
||||
friend class JoinGameScreen;
|
||||
|
||||
public:
|
||||
AvailableGamesList(Minecraft* _minecraft, int _width, int _height)
|
||||
: RolledSelectionListV(_minecraft, _width, _height, 0, _width, 24, _height, 34),
|
||||
selectedItem(-1),
|
||||
startSelected(-1)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual int getNumberOfItems() { return (int)copiedServerList.size(); }
|
||||
|
||||
virtual void selectCancel();
|
||||
virtual void selectStart(int item);
|
||||
virtual void selectItem(int item, bool doubleClick);
|
||||
|
||||
virtual bool isSelectedItem(int item) { return item == selectedItem; }
|
||||
|
||||
virtual void renderBackground() {}
|
||||
virtual void renderItem(int i, int x, int y, int h, Tesselator& t);
|
||||
};
|
||||
|
||||
class JoinGameScreen: public Screen
|
||||
{
|
||||
public:
|
||||
JoinGameScreen();
|
||||
virtual ~JoinGameScreen();
|
||||
|
||||
void init();
|
||||
void setupPositions();
|
||||
|
||||
virtual bool handleBackEvent(bool isDown);
|
||||
|
||||
virtual bool isIndexValid(int index);
|
||||
|
||||
virtual void tick();
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
void buttonClicked(Button* button);
|
||||
|
||||
bool isInGameScreen();
|
||||
private:
|
||||
Button bJoin;
|
||||
TButton bBack;
|
||||
THeader bHeader;
|
||||
AvailableGamesList* gamesList;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchJoinGameScreen_H__*/
|
||||
584
src/client/gui/screens/touch/TouchSelectWorldScreen.cpp
Executable file
584
src/client/gui/screens/touch/TouchSelectWorldScreen.cpp
Executable file
@@ -0,0 +1,584 @@
|
||||
#include "TouchSelectWorldScreen.h"
|
||||
#include "../StartMenuScreen.h"
|
||||
#include "../ProgressScreen.h"
|
||||
#include "../DialogDefinitions.h"
|
||||
#include "../../components/ImageButton.h" //weird!
|
||||
#include "../../../renderer/Textures.h"
|
||||
#include "../../../renderer/Tesselator.h"
|
||||
#include "../../../../world/level/LevelSettings.h"
|
||||
#include "../../../../AppPlatform.h"
|
||||
#include "../../../../util/StringUtils.h"
|
||||
#include "../../../../util/Mth.h"
|
||||
#include "../../../../platform/input/Mouse.h"
|
||||
#include "../../../../Performance.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "../SimpleChooseLevelScreen.h"
|
||||
|
||||
namespace Touch {
|
||||
|
||||
//
|
||||
// World Selection List
|
||||
//
|
||||
TouchWorldSelectionList::TouchWorldSelectionList( Minecraft* minecraft, int width, int height )
|
||||
: _height(height),
|
||||
hasPickedLevel(false),
|
||||
pickedIndex(-1),
|
||||
currentTick(0),
|
||||
stoppedTick(-1),
|
||||
mode(0),
|
||||
_newWorldSelected(false),
|
||||
RolledSelectionListH(minecraft, width, height, 0, width, 24, height-32, 120)
|
||||
{
|
||||
_renderBottomBorder = false;
|
||||
//setRenderSelection(false);
|
||||
}
|
||||
|
||||
int TouchWorldSelectionList::getNumberOfItems() {
|
||||
return (int)levels.size() + 1;
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::selectItem( int item, bool doubleClick ) {
|
||||
if (selectedItem < 0)
|
||||
return;
|
||||
|
||||
const int delta = item - selectedItem;
|
||||
|
||||
if (delta == -1)
|
||||
stepLeft();
|
||||
if (delta == +1)
|
||||
stepRight();
|
||||
if (delta == 0 ) {
|
||||
if (!hasPickedLevel) {
|
||||
hasPickedLevel = true;
|
||||
pickedIndex = item;
|
||||
if (item < (int)levels.size())
|
||||
pickedLevel = levels[item];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TouchWorldSelectionList::isSelectedItem( int item ) {
|
||||
return item == selectedItem;
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::selectStart(int item, int localX, int localY) {
|
||||
if (selectedItem != (int) levels.size() || item != selectedItem)
|
||||
return;
|
||||
_newWorldSelected = true;
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::selectCancel() {
|
||||
_newWorldSelected = false;
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::renderItem( int i, int x, int y, int h, Tesselator& t ) {
|
||||
int centerx = x + itemWidth/2;
|
||||
float a0 = Mth::Max(1.1f - std::abs( width / 2 - centerx ) * 0.0055f, 0.2f);
|
||||
if (a0 > 1) a0 = 1;
|
||||
int textColor = (int)(255.0f * a0) * 0x010101;
|
||||
int textColor2 = (int)(140.0f * a0) * 0x010101;
|
||||
const int TX = centerx - itemWidth / 2 + 5;
|
||||
const int TY = y + 44; //@kindle-res:42
|
||||
|
||||
if (i < (int)levels.size()) {
|
||||
// Draw the worlds
|
||||
StringVector v = _descriptions[i];
|
||||
drawString(minecraft->font, v[0].c_str(), TX, TY + 0, textColor);
|
||||
drawString(minecraft->font, v[1].c_str(), TX, TY + 10, textColor2);
|
||||
drawString(minecraft->font, v[2].c_str(), TX, TY + 20, textColor2);
|
||||
drawString(minecraft->font, v[3].c_str(), TX, TY + 30, textColor2);
|
||||
|
||||
minecraft->textures->loadAndBindTexture(_imageNames[i]);
|
||||
t.color(0.3f, 1.0f, 0.2f);
|
||||
|
||||
//float x0 = (float)x;
|
||||
//float x1 = (float)x + (float)itemWidth;
|
||||
|
||||
const float IY = (float)y - 8; // @kindle-res: -3
|
||||
t.begin();
|
||||
t.color(textColor);
|
||||
t.vertexUV((float)(centerx-32), IY, blitOffset, 0, 0.125f);
|
||||
t.vertexUV((float)(centerx-32), IY + 48, blitOffset, 0, 0.875f); //@kindle-res: +44
|
||||
t.vertexUV((float)(centerx+32), IY + 48, blitOffset, 1, 0.875f); //@kindle-res: +44
|
||||
t.vertexUV((float)(centerx+32), IY, blitOffset, 1, 0.125f);
|
||||
t.draw();
|
||||
} else {
|
||||
// Draw the "Create new world" icon
|
||||
drawCenteredString(minecraft->font, "Create new", centerx, TY + 12, textColor);
|
||||
|
||||
minecraft->textures->loadAndBindTexture("gui/touchgui.png");
|
||||
|
||||
const bool selected = _newWorldSelected;
|
||||
|
||||
const float W = 54.0f;
|
||||
const float H = 54.0f;
|
||||
const float IY = (float)y;
|
||||
const float u0 = (168.0f ) / 256.0f;
|
||||
const float u1 = (168.0f + W) / 256.0f;
|
||||
float v0 = (32.0f ) / 256.0f;
|
||||
float v1 = (32.0f + H) / 256.0f;
|
||||
if (selected) {
|
||||
v0 += H / 256.0f;
|
||||
v1 += H / 256.0f;
|
||||
}
|
||||
|
||||
t.begin();
|
||||
t.color(textColor);
|
||||
t.vertexUV((float)centerx - W*0.5f, IY, blitOffset, u0, v0);
|
||||
t.vertexUV((float)centerx - W*0.5f, IY + H, blitOffset, u0, v1);
|
||||
t.vertexUV((float)centerx + W*0.5f, IY + H, blitOffset, u1, v1);
|
||||
t.vertexUV((float)centerx + W*0.5f, IY, blitOffset, u1, v0);
|
||||
t.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::stepLeft() {
|
||||
if (selectedItem > 0) {
|
||||
int xoffset = (int)(xo - ((float)(selectedItem * itemWidth) + ((float)(itemWidth-width)) * 0.5f));
|
||||
td.start = xo;
|
||||
td.stop = xo - itemWidth - xoffset;
|
||||
td.cur = 0;
|
||||
td.dur = 8;
|
||||
mode = 1;
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::stepRight() {
|
||||
if (selectedItem >= 0 && selectedItem < getNumberOfItems()-1) {
|
||||
int xoffset = (int)(xo - ((float)(selectedItem * itemWidth) + ((float)(itemWidth-width)) * 0.5f));
|
||||
td.start = xo;
|
||||
td.stop = xo + itemWidth - xoffset;
|
||||
td.cur = 0;
|
||||
td.dur = 8;
|
||||
mode = 1;
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::commit() {
|
||||
for (unsigned int i = 0; i < levels.size(); ++i) {
|
||||
LevelSummary& level = levels[i];
|
||||
|
||||
std::stringstream ss;
|
||||
ss << level.name << "/preview.png";
|
||||
TextureId id = Textures::InvalidId;//minecraft->textures->loadTexture(ss.str(), false);
|
||||
|
||||
if (id != Textures::InvalidId) {
|
||||
_imageNames.push_back( ss.str() );
|
||||
} else {
|
||||
_imageNames.push_back("gui/default_world.png");
|
||||
}
|
||||
|
||||
StringVector lines;
|
||||
lines.push_back(levels[i].name);
|
||||
lines.push_back(minecraft->platform()->getDateString(levels[i].lastPlayed));
|
||||
lines.push_back(levels[i].id);
|
||||
lines.push_back(LevelSettings::gameTypeToString(level.gameType));
|
||||
_descriptions.push_back(lines);
|
||||
|
||||
selectedItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static float quadraticInOut(float t, float dur, float start, float stop) {
|
||||
const float delta = stop - start;
|
||||
const float T = (t / dur) * 2.0f;
|
||||
if (T < 1) return 0.5f*delta*T*T + start;
|
||||
return -0.5f*delta * ((T-1)*(T-3) - 1) + start;
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::tick()
|
||||
{
|
||||
RolledSelectionListH::tick();
|
||||
|
||||
++currentTick;
|
||||
|
||||
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT) || dragState == 0)
|
||||
return;
|
||||
|
||||
// Handle the tween (when in "mode 1")
|
||||
selectedItem = -1;
|
||||
if (mode == 1) {
|
||||
if (++td.cur == td.dur) {
|
||||
mode = 0;
|
||||
xInertia = 0;
|
||||
xoo = xo = td.stop;
|
||||
selectedItem = getItemAtPosition(width/2, height/2);
|
||||
} else {
|
||||
tweenInited();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// It's still going fast, let it run
|
||||
float speed = Mth::abs(xInertia);
|
||||
bool slowEnoughToBeBothered = speed < 5.0f;
|
||||
if (!slowEnoughToBeBothered) {
|
||||
xInertia = xInertia * .9f;
|
||||
return;
|
||||
}
|
||||
|
||||
xInertia *= 0.8f;
|
||||
|
||||
if (speed < 1 && dragState < 0) {
|
||||
const int offsetx = (width-itemWidth) / 2;
|
||||
const float pxo = xo + offsetx;
|
||||
int index = getItemAtXPositionRaw((int)(pxo - 10*xInertia));
|
||||
int indexPos = index*itemWidth;
|
||||
|
||||
// Pick closest
|
||||
float diff = (float)indexPos - pxo;
|
||||
if (diff < -itemWidth/2) {
|
||||
diff += itemWidth;
|
||||
index++;
|
||||
//indexPos += itemWidth;
|
||||
}
|
||||
if (Mth::abs(diff) < 1 && speed < 0.1f) {
|
||||
selectedItem = getItemAtPosition(width/2, height/2);
|
||||
return;
|
||||
}
|
||||
|
||||
td.start = xo;
|
||||
td.stop = xo + diff;
|
||||
td.cur = 0;
|
||||
td.dur = (float) Mth::Min(7, 1 + (int)(Mth::abs(diff) * 0.25f));
|
||||
mode = 1;
|
||||
//LOGI("inited-t %d\n", dragState);
|
||||
tweenInited();
|
||||
}
|
||||
}
|
||||
|
||||
float TouchWorldSelectionList::getPos( float alpha )
|
||||
{
|
||||
if (mode != 1) return RolledSelectionListH::getPos(alpha);
|
||||
|
||||
float x0 = quadraticInOut(td.cur, td.dur, td.start, td.stop);
|
||||
float x1 = quadraticInOut(td.cur+1, td.dur, td.start, td.stop);
|
||||
return x0 + (x1-x0)*alpha;
|
||||
}
|
||||
|
||||
bool TouchWorldSelectionList::capXPosition() {
|
||||
bool capped = RolledSelectionListH::capXPosition();
|
||||
if (capped) mode = 0;
|
||||
return capped;
|
||||
}
|
||||
|
||||
void TouchWorldSelectionList::tweenInited() {
|
||||
float x0 = quadraticInOut(td.cur, td.dur, td.start, td.stop);
|
||||
float x1 = quadraticInOut(td.cur+1, td.dur, td.start, td.stop);
|
||||
_xinertia = 0;
|
||||
xInertia = x0-x1; // yes, it's all backwards and messed up..
|
||||
}
|
||||
|
||||
//
|
||||
// Select World Screen
|
||||
//
|
||||
SelectWorldScreen::SelectWorldScreen()
|
||||
: bDelete (1, ""),
|
||||
bCreate (2, "Create new"),
|
||||
bBack (3, "Back"),
|
||||
bHeader (0, "Select world"),
|
||||
bWorldView(4, ""),
|
||||
worldsList(NULL),
|
||||
_hasStartedLevel(false),
|
||||
_state(_STATE_DEFAULT)
|
||||
{
|
||||
bDelete.active = false;
|
||||
|
||||
// Delete button
|
||||
ImageDef def;
|
||||
def.name = "gui/touchgui.png";
|
||||
def.width = 34;
|
||||
def.height = 26;
|
||||
|
||||
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
|
||||
bDelete.setImageDef(def, true);
|
||||
|
||||
// Create new, and Back button
|
||||
/*
|
||||
def.src.y = 26; // @ 0, 26
|
||||
def.src.w = def.w = 66; // 66, 26 size
|
||||
bBack.setImageDef(def, true);
|
||||
bCreate.setImageDef(def, true);
|
||||
*/
|
||||
}
|
||||
|
||||
SelectWorldScreen::~SelectWorldScreen()
|
||||
{
|
||||
delete worldsList;
|
||||
}
|
||||
|
||||
void SelectWorldScreen::init()
|
||||
{
|
||||
worldsList = new TouchWorldSelectionList(minecraft, width, height);
|
||||
loadLevelSource();
|
||||
worldsList->commit();
|
||||
|
||||
buttons.push_back(&bDelete);
|
||||
buttons.push_back(&bCreate);
|
||||
buttons.push_back(&bBack);
|
||||
buttons.push_back(&bHeader);
|
||||
|
||||
_mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
|
||||
tabButtons.push_back(&bWorldView);
|
||||
tabButtons.push_back(&bDelete);
|
||||
tabButtons.push_back(&bCreate);
|
||||
tabButtons.push_back(&bBack);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::setupPositions() {
|
||||
//#ifdef ANDROID
|
||||
bCreate.y = 0;
|
||||
bBack.y = 0;
|
||||
bHeader.y = 0;
|
||||
bDelete.y = height - 30;
|
||||
|
||||
// Center buttons
|
||||
bDelete.x = (width - bDelete.width) / 2;
|
||||
bCreate.x = width - bCreate.width;//width / 2 - bCreate.w / 2;
|
||||
bBack.x = 0;//width / 2 + 4 + bCreate.w - bBack.w / 2;
|
||||
bHeader.x = bBack.width;
|
||||
bHeader.width = width - (bBack.width + bCreate.width);
|
||||
bHeader.height = bCreate.height;
|
||||
}
|
||||
|
||||
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 (button->id == bDelete.id) {
|
||||
if (isIndexValid(worldsList->selectedItem)) {
|
||||
LevelSummary level = worldsList->levels[worldsList->selectedItem];
|
||||
LOGI("level: %s, %s\n", level.id.c_str(), level.name.c_str());
|
||||
minecraft->setScreen( new TouchDeleteWorldScreen(level) );
|
||||
}
|
||||
}
|
||||
if (button->id == bBack.id) {
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
if (button->id == bWorldView.id) {
|
||||
// Try to "click" the item in the middle
|
||||
worldsList->selectItem( worldsList->getItemAtPosition(width/2, height/2), false );
|
||||
}
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::handleBackEvent(bool isDown)
|
||||
{
|
||||
if (!isDown)
|
||||
{
|
||||
minecraft->cancelLocateMultiplayer();
|
||||
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::isIndexValid( int index )
|
||||
{
|
||||
return worldsList && index >= 0 && index < worldsList->getNumberOfItems() - 1;
|
||||
}
|
||||
|
||||
static char ILLEGAL_FILE_CHARACTERS[] = {
|
||||
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
|
||||
};
|
||||
|
||||
void SelectWorldScreen::tick()
|
||||
{
|
||||
if (_state == _STATE_CREATEWORLD) {
|
||||
#if defined(RPI)
|
||||
std::string levelId = getUniqueLevelName("perf");
|
||||
//int seed = Util::hashCode("/r/Minecraft");
|
||||
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();
|
||||
//LOGI("Status is: %d\n", status);
|
||||
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
|
||||
LOGI("Creating a level with id '%s', name '%s' and seed '%d'\n", levelId.c_str(), levelName.c_str(), seed);
|
||||
LevelSettings settings(seed, isCreative? GameType::Creative : GameType::Survival);
|
||||
minecraft->selectLevel(levelId, levelName, settings);
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
}
|
||||
_state = _STATE_DEFAULT;
|
||||
// Reset the world list
|
||||
worldsList->hasPickedLevel = false;
|
||||
worldsList->pickedIndex = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
worldsList->hasPickedLevel = false;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
minecraft->selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None());
|
||||
minecraft->hostMultiplayer();
|
||||
minecraft->setScreen(new ProgressScreen());
|
||||
_hasStartedLevel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// copy the currently selected item
|
||||
LevelSummary selectedWorld;
|
||||
//bool hasSelection = false;
|
||||
if (isIndexValid(worldsList->selectedItem))
|
||||
{
|
||||
selectedWorld = worldsList->levels[worldsList->selectedItem];
|
||||
//hasSelection = true;
|
||||
}
|
||||
|
||||
bDelete.active = isIndexValid(worldsList->selectedItem);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::render( int xm, int ym, float a )
|
||||
{
|
||||
//Performance::watches.get("sws-full").start();
|
||||
//Performance::watches.get("sws-renderbg").start();
|
||||
renderBackground();
|
||||
//Performance::watches.get("sws-renderbg").stop();
|
||||
//Performance::watches.get("sws-worlds").start();
|
||||
|
||||
worldsList->setComponentSelected(bWorldView.selected);
|
||||
|
||||
if (_mouseHasBeenUp)
|
||||
worldsList->render(xm, ym, a);
|
||||
else {
|
||||
worldsList->render(0, 0, a);
|
||||
_mouseHasBeenUp = !Mouse::getButtonState(MouseAction::ACTION_LEFT);
|
||||
}
|
||||
|
||||
//Performance::watches.get("sws-worlds").stop();
|
||||
//Performance::watches.get("sws-screen").start();
|
||||
Screen::render(xm, ym, a);
|
||||
//Performance::watches.get("sws-screen").stop();
|
||||
|
||||
//minecraft->textures->loadAndBindTexture("gui/selectworld/trash.png");
|
||||
|
||||
//Performance::watches.get("sws-string").start();
|
||||
//Performance::watches.get("sws-string").stop();
|
||||
|
||||
//Performance::watches.get("sws-full").stop();
|
||||
//Performance::watches.printEvery(128);
|
||||
}
|
||||
|
||||
void SelectWorldScreen::loadLevelSource()
|
||||
{
|
||||
LevelStorageSource* levelSource = minecraft->getLevelSource();
|
||||
levelSource->getLevelList(levels);
|
||||
std::sort(levels.begin(), levels.end());
|
||||
|
||||
for (unsigned int i = 0; i < levels.size(); ++i) {
|
||||
if (levels[i].id != LevelStorageSource::TempLevelId)
|
||||
worldsList->levels.push_back( levels[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string SelectWorldScreen::getUniqueLevelName( const std::string& level )
|
||||
{
|
||||
std::set<std::string> Set;
|
||||
for (unsigned int i = 0; i < levels.size(); ++i)
|
||||
Set.insert(levels[i].id);
|
||||
|
||||
std::string s = level;
|
||||
while ( Set.find(s) != Set.end() )
|
||||
s += "-";
|
||||
return s;
|
||||
}
|
||||
|
||||
bool SelectWorldScreen::isInGameScreen() { return true; }
|
||||
|
||||
void SelectWorldScreen::keyPressed( int eventKey )
|
||||
{
|
||||
if (bWorldView.selected) {
|
||||
if (eventKey == minecraft->options.keyLeft.key)
|
||||
worldsList->stepLeft();
|
||||
if (eventKey == minecraft->options.keyRight.key)
|
||||
worldsList->stepRight();
|
||||
}
|
||||
|
||||
Screen::keyPressed(eventKey);
|
||||
}
|
||||
|
||||
//
|
||||
// Delete World Screen
|
||||
//
|
||||
TouchDeleteWorldScreen::TouchDeleteWorldScreen(const LevelSummary& level)
|
||||
: ConfirmScreen(NULL, "Are you sure you want to delete this world?",
|
||||
"'" + level.name + "' will be lost forever!",
|
||||
"Delete", "Cancel", 0),
|
||||
_level(level)
|
||||
{
|
||||
tabButtonIndex = 1;
|
||||
}
|
||||
|
||||
void TouchDeleteWorldScreen::postResult( bool isOk )
|
||||
{
|
||||
if (isOk) {
|
||||
LevelStorageSource* storageSource = minecraft->getLevelSource();
|
||||
storageSource->deleteLevel(_level.id);
|
||||
}
|
||||
minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD);
|
||||
}
|
||||
|
||||
};
|
||||
122
src/client/gui/screens/touch/TouchSelectWorldScreen.h
Executable file
122
src/client/gui/screens/touch/TouchSelectWorldScreen.h
Executable file
@@ -0,0 +1,122 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchSelectWorldScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchSelectWorldScreen_H__
|
||||
|
||||
#include "../ConfirmScreen.h"
|
||||
#include "../../Screen.h"
|
||||
#include "../../TweenData.h"
|
||||
#include "../../components/ImageButton.h"
|
||||
#include "../../components/Button.h"
|
||||
#include "../../components/RolledSelectionListH.h"
|
||||
#include "../../../Minecraft.h"
|
||||
#include "../../../../world/level/storage/LevelStorageSource.h"
|
||||
|
||||
|
||||
namespace Touch {
|
||||
|
||||
class SelectWorldScreen;
|
||||
|
||||
//
|
||||
// Scrolling World selection list
|
||||
//
|
||||
class TouchWorldSelectionList : public RolledSelectionListH
|
||||
{
|
||||
public:
|
||||
TouchWorldSelectionList(Minecraft* _minecraft, int _width, int _height);
|
||||
virtual void tick();
|
||||
void stepLeft();
|
||||
void stepRight();
|
||||
|
||||
void commit();
|
||||
protected:
|
||||
virtual int getNumberOfItems();
|
||||
virtual void selectItem(int item, bool doubleClick);
|
||||
virtual bool isSelectedItem(int item);
|
||||
|
||||
virtual void renderBackground() {}
|
||||
virtual void renderItem(int i, int x, int y, int h, Tesselator& t);
|
||||
virtual float getPos(float alpha);
|
||||
virtual void touched() { mode = 0; }
|
||||
virtual bool capXPosition();
|
||||
|
||||
virtual void selectStart(int item, int localX, int localY);
|
||||
virtual void selectCancel();
|
||||
private:
|
||||
TweenData td;
|
||||
void tweenInited();
|
||||
|
||||
int selectedItem;
|
||||
bool _newWorldSelected; // Is the PLUS button pressed?
|
||||
int _height;
|
||||
LevelSummaryList levels;
|
||||
std::vector<StringVector> _descriptions;
|
||||
StringVector _imageNames;
|
||||
|
||||
bool hasPickedLevel;
|
||||
LevelSummary pickedLevel;
|
||||
int pickedIndex;
|
||||
|
||||
int stoppedTick;
|
||||
int currentTick;
|
||||
float accRatio;
|
||||
int mode;
|
||||
|
||||
friend class SelectWorldScreen;
|
||||
};
|
||||
|
||||
//
|
||||
// Delete World screen
|
||||
//
|
||||
class TouchDeleteWorldScreen: public ConfirmScreen
|
||||
{
|
||||
public:
|
||||
TouchDeleteWorldScreen(const LevelSummary& levelId);
|
||||
protected:
|
||||
virtual void postResult(bool isOk);
|
||||
private:
|
||||
LevelSummary _level;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Select world screen
|
||||
//
|
||||
class SelectWorldScreen: public Screen
|
||||
{
|
||||
public:
|
||||
SelectWorldScreen();
|
||||
virtual ~SelectWorldScreen();
|
||||
|
||||
virtual void init();
|
||||
virtual void setupPositions();
|
||||
|
||||
virtual void tick();
|
||||
virtual void render(int xm, int ym, float a);
|
||||
|
||||
virtual bool isIndexValid(int index);
|
||||
virtual bool handleBackEvent(bool isDown);
|
||||
virtual void buttonClicked(Button* button);
|
||||
virtual void keyPressed(int eventKey);
|
||||
|
||||
bool isInGameScreen();
|
||||
private:
|
||||
void loadLevelSource();
|
||||
std::string getUniqueLevelName(const std::string& level);
|
||||
|
||||
ImageButton bDelete;
|
||||
TButton bCreate;
|
||||
THeader bHeader;
|
||||
TButton bBack;
|
||||
Button bWorldView;
|
||||
TouchWorldSelectionList* worldsList;
|
||||
LevelSummaryList levels;
|
||||
|
||||
bool _mouseHasBeenUp;
|
||||
bool _hasStartedLevel;
|
||||
int _state;
|
||||
static const int _STATE_DEFAULT = 0;
|
||||
static const int _STATE_CREATEWORLD = 1;
|
||||
//LevelStorageSource* levels;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchSelectWorldScreen_H__*/
|
||||
292
src/client/gui/screens/touch/TouchStartMenuScreen.cpp
Executable file
292
src/client/gui/screens/touch/TouchStartMenuScreen.cpp
Executable file
@@ -0,0 +1,292 @@
|
||||
#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"
|
||||
|
||||
//
|
||||
// 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 {
|
||||
|
||||
//
|
||||
// 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"),
|
||||
bBuy( 5),
|
||||
bTest( 9, "Create")
|
||||
{
|
||||
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);
|
||||
|
||||
#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
|
||||
|
||||
#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);
|
||||
//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;
|
||||
|
||||
bTest.x = 4;
|
||||
bTest.y = height - bTest.height - 4;
|
||||
|
||||
copyrightPosX = width - minecraft->font->width(copyright) - 1;
|
||||
versionPosX = (width - minecraft->font->width(version)) / 2;// - minecraft->font->width(version) - 2;
|
||||
}
|
||||
|
||||
void StartMenuScreen::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());
|
||||
}
|
||||
if (button->id == bBuy.id)
|
||||
{
|
||||
minecraft->platform()->buyGame();
|
||||
//minecraft->setScreen(new BuyGameScreen());
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
50
src/client/gui/screens/touch/TouchStartMenuScreen.h
Executable file
50
src/client/gui/screens/touch/TouchStartMenuScreen.h
Executable file
@@ -0,0 +1,50 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchStartMenuScreen_H__
|
||||
#define NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchStartMenuScreen_H__
|
||||
|
||||
#include "../../Screen.h"
|
||||
#include "../../components/LargeImageButton.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
|
||||
{
|
||||
public:
|
||||
StartMenuScreen();
|
||||
virtual ~StartMenuScreen();
|
||||
|
||||
void init();
|
||||
void setupPositions();
|
||||
|
||||
void tick();
|
||||
void render(int xm, int ym, float a);
|
||||
|
||||
void buttonClicked(Button* button);
|
||||
bool handleBackEvent(bool isDown);
|
||||
bool isInGameScreen();
|
||||
private:
|
||||
void _updateLicense();
|
||||
|
||||
LargeImageButton bHost;
|
||||
LargeImageButton bJoin;
|
||||
LargeImageButton bOptions;
|
||||
TButton bTest;
|
||||
BuyButton bBuy;
|
||||
|
||||
std::string copyright;
|
||||
int copyrightPosX;
|
||||
|
||||
std::string version;
|
||||
int versionPosX;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_GUI_SCREENS_TOUCH__TouchStartMenuScreen_H__*/
|
||||
Reference in New Issue
Block a user