Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Kolyah35
2026-03-14 14:51:25 +03:00
82 changed files with 1998 additions and 221 deletions

View File

@@ -1,6 +1,7 @@
#include "Gui.h"
#include "Font.h"
#include "client/Options.h"
#include "platform/input/Keyboard.h"
#include "screens/IngameBlockSelectionScreen.h"
#include "../Minecraft.h"
#include "../player/LocalPlayer.h"
@@ -87,14 +88,16 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
// F: 3
int ySlot = screenHeight - 16 - 3;
if (minecraft->gameMode->canHurtPlayer()) {
minecraft->textures->loadAndBindTexture("gui/icons.png");
Tesselator& t = Tesselator::instance;
t.beginOverride();
t.colorABGR(0xffffffff);
renderHearts();
renderBubbles();
t.endOverrideAndDraw();
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
if (minecraft->gameMode->canHurtPlayer()) {
minecraft->textures->loadAndBindTexture("gui/icons.png");
Tesselator& t = Tesselator::instance;
t.beginOverride();
t.colorABGR(0xffffffff);
renderHearts();
renderBubbles();
t.endOverrideAndDraw();
}
}
if(minecraft->player->getSleepTimer() > 0) {
@@ -106,7 +109,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
}
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
renderToolBar(a, ySlot, screenWidth);
glEnable(GL_BLEND);
@@ -122,6 +125,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
if (minecraft->options.getBooleanValue(OPTIONS_RENDER_DEBUG))
renderDebugInfo();
#endif
}
glDisable(GL_BLEND);
glEnable2(GL_ALPHA_TEST);
@@ -201,6 +205,10 @@ void Gui::handleClick(int button, int x, int y) {
void Gui::handleKeyPressed(int key)
{
if (key == Keyboard::KEY_F1) {
minecraft->options.toggle(OPTIONS_HIDEGUI);
}
if (key == 99)
{
if (minecraft->player->inventory->selected > 0)
@@ -516,7 +524,8 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen
ItemInstance* currentItem = minecraft->player->inventory->getSelected();
bool bowEquipped = currentItem != NULL ? currentItem->getItem() == Item::bow : false;
bool itemInUse = currentItem != NULL ? currentItem->getItem() == minecraft->player->getUseItem()->getItem() : false;
if (!isTouchInterface || minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) || (bowEquipped && itemInUse)) {
if ((!isTouchInterface || minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)
|| (bowEquipped && itemInUse)) && !minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
minecraft->textures->loadAndBindTexture("gui/icons.png");
glEnable(GL_BLEND);
glBlendFunc2(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR);
@@ -585,11 +594,14 @@ void Gui::renderHearts() {
int oh = minecraft->player->lastHealth;
random.setSeed(tickCount * 312871);
int xx = 2;//screenWidth / 2 - getNumSlots() * 10;
int screenWidth = (int)(minecraft->width * InvGuiScale);
int screenHeight = (int)(minecraft->height * InvGuiScale);
int xx = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenWidth / 2 - getNumSlots() * 10 - 1 : 2;
int armor = minecraft->player->getArmorValue();
for (int i = 0; i < Player::MAX_HEALTH / 2; i++) {
int yo = 2;
int yo = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenHeight - 32 : 2;
int ip2 = i + i + 1;
if (armor > 0) {
@@ -617,11 +629,15 @@ void Gui::renderHearts() {
void Gui::renderBubbles() {
if (minecraft->player->isUnderLiquid(Material::water)) {
int yo = 12;
int screenWidth = (int)(minecraft->width * InvGuiScale);
int screenHeight = (int)(minecraft->height * InvGuiScale);
int xx = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenWidth / 2 - getNumSlots() * 10 - 1 : 2;
int yo = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenHeight - 42 : 12;
int count = (int) std::ceil((minecraft->player->airSupply - 2) * 10.0f / Player::TOTAL_AIR_SUPPLY);
int extra = (int) std::ceil((minecraft->player->airSupply) * 10.0f / Player::TOTAL_AIR_SUPPLY) - count;
for (int i = 0; i < count + extra; i++) {
int xo = i * 8 + 2;
int xo = i * 8 + xx;
if (i < count) blit(xo, yo, 16, 9 * 2, 9, 9);
else blit(xo, yo, 16 + 9, 9 * 2, 9, 9);
}

View File

@@ -78,6 +78,14 @@ void Screen::updateEvents()
void Screen::mouseEvent()
{
const MouseAction& e = Mouse::getEvent();
// forward wheel events to subclasses
if (e.action == MouseAction::ACTION_WHEEL) {
int xm = e.x * width / minecraft->width;
int ym = e.y * height / minecraft->height - 1;
mouseWheel(e.dx, e.dy, xm, ym);
return;
}
if (!e.isButton())
return;

View File

@@ -57,6 +57,9 @@ protected:
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
// mouse wheel movement (dx/dy are wheel deltas, xm/ym are GUI coords)
virtual void mouseWheel(int dx, int dy, int xm, int ym) {}
virtual void keyPressed(int eventKey);
virtual void charPressed(char inputChar);
public:

View File

@@ -548,6 +548,14 @@ void ScrollingPane::stepThroughDecelerationAnimation(bool noAnimation) {
}
}
void ScrollingPane::scrollBy(float dx, float dy) {
// adjust the translation offsets fpx/fpy by the requested amount
float nfpx = fpx + dx;
float nfpy = fpy + dy;
// convert back to content offset (fpx = -contentOffset.x)
setContentOffset(Vec3(-nfpx, -nfpy, 0));
}
void ScrollingPane::setContentOffset(float x, float y) {
this->setContentOffsetWithAnimation(Vec3(x, y, 0), false);
}

View File

@@ -51,6 +51,10 @@ public:
void tick();
void render(int xm, int ym, float alpha);
// scroll the content by the given amount (dx horizontal, dy vertical)
// positive values move content downward/rightward
void scrollBy(float dx, float dy);
bool getGridItemFor_slow(int itemIndex, GridItem& out);
void setSelected(int id, bool selected);

View File

@@ -38,7 +38,8 @@ void CreditsScreen::init() {
_lines.push_back("InviseDivine");
_lines.push_back("Kolyah35");
_lines.push_back("");
_lines.push_back("[Gold]Join our Discord server:[/Gold] [Green]url.....[/Green]");
// avoid color tags around the URL so it isn't mangled by the parser please
_lines.push_back("Join our Discord server: https://discord.gg/c58YesBxve");
_scrollSpeed = 0.5f;
_scrollY = height; // start below screen
}

View File

@@ -202,6 +202,25 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey)
#endif
}
//------------------------------------------------------------------------------
// wheel support for creative inventory; scroll moves selection vertically
void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym)
{
if (dy == 0) return;
// just move selection up/down one row; desktop UI doesn't have a pane
int cols = InventoryCols;
int maxIndex = InventorySize - 1;
int idx = selectedItem;
if (dy > 0) {
// wheel up -> previous row
if (idx >= cols) idx -= cols;
} else {
// wheel down -> next row
if (idx + cols <= maxIndex) idx += cols;
}
selectedItem = idx;
}
int IngameBlockSelectionScreen::getSelectedSlot(int x, int y)
{
int left = width / 2 - InventoryCols * 10;

View File

@@ -23,6 +23,9 @@ protected:
virtual void buttonClicked(Button* button);
// wheel input for creative inventory scrolling
virtual void mouseWheel(int dx, int dy, int xm, int ym) override;
virtual void keyPressed(int eventKey);
private:
void renderSlots();

View File

@@ -0,0 +1,140 @@
#include "JoinByIPScreen.h"
#include "JoinGameScreen.h"
#include "StartMenuScreen.h"
#include "ProgressScreen.h"
#include "../Font.h"
#include "../../../network/RakNetInstance.h"
#include "client/gui/components/TextBox.h"
#include "network/ClientSideNetworkHandler.h"
JoinByIPScreen::JoinByIPScreen() :
tIP(0, "Server IP"),
bHeader(1, "Join on server"),
bJoin( 2, "Join Game"),
bBack( 3, "")
{
bJoin.active = false;
//gamesList->yInertia = 0.5f;
}
JoinByIPScreen::~JoinByIPScreen()
{
}
void JoinByIPScreen::buttonClicked(Button* button)
{
if (button->id == bJoin.id)
{
minecraft->isLookingForMultiplayer = true;
minecraft->netCallback = new ClientSideNetworkHandler(minecraft, minecraft->raknetInstance);
minecraft->joinMultiplayerFromString(tIP.text);
{
bJoin.active = false;
bBack.active = false;
minecraft->setScreen(new ProgressScreen());
}
}
if (button->id == bBack.id)
{
minecraft->cancelLocateMultiplayer();
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
}
}
bool JoinByIPScreen::handleBackEvent(bool isDown)
{
if (!isDown)
{
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
}
return true;
}
void JoinByIPScreen::tick()
{
bJoin.active = !tIP.text.empty();
}
void JoinByIPScreen::init()
{
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);
buttons.push_back(&bJoin);
buttons.push_back(&bBack);
buttons.push_back(&bHeader);
textBoxes.push_back(&tIP);
#ifdef ANDROID
tabButtons.push_back(&bJoin);
tabButtons.push_back(&bBack);
tabButtons.push_back(&bHeader);
#endif
}
void JoinByIPScreen::setupPositions() {
int tIpDiff = 40;
bJoin.y = height * 2 / 3;
bBack.y = 0;
bHeader.y = 0;
// Center buttons
//bJoin.x = width / 2 - 4 - bJoin.w;
bBack.x = width - bBack.width;//width / 2 + 4;
bJoin.x = (width - bJoin.width) / 2;
bHeader.x = 0;
bHeader.width = width - bBack.width;
tIP.width = bJoin.width + tIpDiff;
tIP.height = 16;
tIP.x = bJoin.x - tIpDiff / 2;
tIP.y = ((height - bJoin.height) / 2) - tIP.height - 4;
}
void JoinByIPScreen::mouseClicked(int x, int y, int buttonNum) {
int lvlTop = tIP.y - (Font::DefaultLineHeight + 4);
int lvlBottom = tIP.y + tIP.height;
int lvlLeft = tIP.x;
int lvlRight = tIP.x + tIP.width;
bool clickedIP = x >= lvlLeft && x < lvlRight && y >= lvlTop && y < lvlBottom;
if (clickedIP) {
tIP.setFocus(minecraft);
} else {
tIP.loseFocus(minecraft);
}
Screen::mouseClicked(x, y, buttonNum);
}
void JoinByIPScreen::render( int xm, int ym, float a )
{
renderBackground();
Screen::render(xm, ym, a);
}
void JoinByIPScreen::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 JoinByIPScreen::keyboardNewChar(char inputChar)
{
// forward character input to focused textbox(s)
for (auto* tb : textBoxes) tb->handleChar(inputChar);
}

View File

@@ -0,0 +1,30 @@
#include "../Screen.h"
#include "../components/Button.h"
#include "../../Minecraft.h"
#include "client/gui/components/ImageButton.h"
#include "client/gui/components/TextBox.h"
class JoinByIPScreen: public Screen
{
public:
JoinByIPScreen();
virtual ~JoinByIPScreen();
void init();
void setupPositions();
virtual void tick();
void render(int xm, int ym, float a);
virtual void keyPressed(int eventKey);
virtual void keyboardNewChar(char inputChar);
void buttonClicked(Button* button);
virtual void mouseClicked(int x, int y, int buttonNum);
virtual bool handleBackEvent(bool isDown);
private:
TextBox tIP;
Touch::THeader bHeader;
Touch::TButton bJoin;
ImageButton bBack;
};

View File

@@ -69,6 +69,7 @@ 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"));
categoryButtons.push_back(new Touch::TButton(6, "Tweaks"));
btnCredits = new Touch::TButton(11, "Credits");
@@ -192,6 +193,7 @@ void OptionsScreen::generateOptionScreens() {
optionPanes.push_back(new OptionsGroup("options.group.game"));
optionPanes.push_back(new OptionsGroup("options.group.control"));
optionPanes.push_back(new OptionsGroup("options.group.graphics"));
optionPanes.push_back(new OptionsGroup("options.group.tweaks"));
// General Pane
optionPanes[0]->addOptionItem(OPTIONS_USERNAME, minecraft)
@@ -228,6 +230,9 @@ void OptionsScreen::generateOptionScreens() {
.addOptionItem(OPTIONS_ANAGLYPH_3D, minecraft)
.addOptionItem(OPTIONS_VIEW_BOBBING, minecraft)
.addOptionItem(OPTIONS_AMBIENT_OCCLUSION, minecraft);
optionPanes[4]->addOptionItem(OPTIONS_ALLOW_SPRINT, minecraft)
.addOptionItem(OPTIONS_BAR_ON_TOP, minecraft);
}
void OptionsScreen::mouseClicked(int x, int y, int buttonNum) {

View File

@@ -5,6 +5,7 @@
#include "PauseScreen.h"
#include "RenameMPLevelScreen.h"
#include "IngameBlockSelectionScreen.h"
#include "JoinByIPScreen.h"
#include "touch/TouchStartMenuScreen.h"
#include "touch/TouchSelectWorldScreen.h"
#include "touch/TouchJoinGameScreen.h"
@@ -20,13 +21,13 @@ Screen* ScreenChooser::createScreen( ScreenId id )
if (_mc->useTouchscreen()) {
switch (id) {
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
case SCREEN_SELECTWORLD:screen = new Touch::SelectWorldScreen();break;
case SCREEN_JOINGAME: screen = new Touch::JoinGameScreen(); break;
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
case SCREEN_BLOCKSELECTION: screen = new Touch::IngameBlockSelectionScreen(); break;
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
case SCREEN_SELECTWORLD: screen = new Touch::SelectWorldScreen();break;
case SCREEN_JOINGAME: screen = new Touch::JoinGameScreen(); break;
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
case SCREEN_BLOCKSELECTION: screen = new Touch::IngameBlockSelectionScreen(); break;
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
case SCREEN_NONE:
default:
// Do nothing
@@ -34,12 +35,13 @@ Screen* ScreenChooser::createScreen( ScreenId id )
}
} else {
switch (id) {
case SCREEN_STARTMENU: screen = new StartMenuScreen(); break;
case SCREEN_SELECTWORLD:screen = new SelectWorldScreen();break;
case SCREEN_JOINGAME: screen = new JoinGameScreen(); break;
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
case SCREEN_BLOCKSELECTION: screen = new IngameBlockSelectionScreen(); break;
case SCREEN_STARTMENU: screen = new StartMenuScreen(); break;
case SCREEN_SELECTWORLD: screen = new SelectWorldScreen();break;
case SCREEN_JOINGAME: screen = new JoinGameScreen(); break;
case SCREEN_PAUSE: screen = new PauseScreen(false); break;
case SCREEN_PAUSEPREV: screen = new PauseScreen(true); break;
case SCREEN_BLOCKSELECTION: screen = new IngameBlockSelectionScreen(); break;
case SCREEN_JOINBYIP: screen = new JoinByIPScreen(); break;
case SCREEN_NONE:
default:

View File

@@ -8,7 +8,8 @@ enum ScreenId {
SCREEN_PAUSE,
SCREEN_PAUSEPREV,
SCREEN_SELECTWORLD,
SCREEN_BLOCKSELECTION
SCREEN_BLOCKSELECTION,
SCREEN_JOINBYIP
};
class Screen;

View File

@@ -356,7 +356,7 @@ void SelectWorldScreen::render( int xm, int ym, float a )
worldsList->setComponentSelected(bWorldView.selected);
// #ifdef PLATFORM_DESKTOP
// We should add scrolling with mouse wheel but currently i dont know how to implement it
// desktop: render the list normally (mouse wheel handled separately below)
if (_mouseHasBeenUp)
worldsList->render(xm, ym, a);
else {
@@ -412,6 +412,28 @@ std::string SelectWorldScreen::getUniqueLevelName( const std::string& level )
bool SelectWorldScreen::isInGameScreen() { return true; }
void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym)
{
if (!worldsList)
return;
if (dy == 0)
return;
int num = worldsList->getNumberOfItems();
int idx = worldsList->selectedItem;
if (dy > 0) {
if (idx > 0) {
idx--;
worldsList->stepLeft();
}
} else {
if (idx < num - 1) {
idx++;
worldsList->stepRight();
}
}
worldsList->selectedItem = idx;
}
void SelectWorldScreen::keyPressed( int eventKey )
{
if (bWorldView.selected) {

View File

@@ -89,6 +89,9 @@ public:
void render(int xm, int ym, float a);
// mouse wheel scroll (new in desktop implementation)
virtual void mouseWheel(int dx, int dy, int xm, int ym);
bool isInGameScreen();
private:
void loadLevelSource();

View File

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

View File

@@ -28,12 +28,14 @@ public:
private:
Touch::THeader* bHeader;
Button* bGamemode;
Button* bCheats;
ImageButton* bBack;
Button* bCreate;
bool hasChosen;
std::string levelName;
int gamemode;
bool cheatsEnabled;
TextBox tLevelName;
TextBox tSeed;

View File

@@ -6,6 +6,7 @@
#include "OptionsScreen.h"
#include "PauseScreen.h"
#include "PrerenderTilesScreen.h" // test button
#include "../components/ImageButton.h"
#include "../../../util/Mth.h"
@@ -24,7 +25,8 @@
StartMenuScreen::StartMenuScreen()
: bHost( 2, 0, 0, 160, 24, "Start Game"),
bJoin( 3, 0, 0, 160, 24, "Join Game"),
bOptions( 4, 0, 0, 78, 22, "Options")
bOptions( 4, 0, 0, 78, 22, "Options"),
bQuit( 5, "")
{
}
@@ -53,10 +55,18 @@ void StartMenuScreen::init()
tabButtons.push_back(&bOptions);
#endif
#ifdef DEMO_MODE
buttons.push_back(&bBuy);
tabButtons.push_back(&bBuy);
#endif
// add quit button (top right X icon) match OptionsScreen style
{
ImageDef def;
def.name = "gui/touchgui.png";
def.width = 34;
def.height = 26;
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
bQuit.setImageDef(def, true);
bQuit.scaleWhenPressed = false;
buttons.push_back(&bQuit);
// don't include in tab navigation
}
copyright = "\xffMojang AB";//. Do not distribute!";
@@ -99,8 +109,9 @@ void StartMenuScreen::setupPositions() {
bJoin.x = (width - bJoin.width) / 2;
bOptions.x = (width - bJoin.width) / 2;
copyrightPosX = width - minecraft->font->width(copyright) - 1;
versionPosX = (width - minecraft->font->width(version)) / 2;// - minecraft->font->width(version) - 2;
// position quit icon at top-right (use image-defined size)
bQuit.x = width - bQuit.width;
bQuit.y = 0;
}
void StartMenuScreen::tick() {
@@ -129,6 +140,10 @@ void StartMenuScreen::buttonClicked(Button* button) {
{
minecraft->setScreen(new OptionsScreen());
}
if (button == &bQuit)
{
minecraft->quit();
}
}
bool StartMenuScreen::isInGameScreen() { return false; }
@@ -137,6 +152,10 @@ void StartMenuScreen::render( int xm, int ym, float a )
{
renderBackground();
// Show current username in the top-left corner
std::string username = minecraft->options.username.empty() ? "unknown" : minecraft->options.username;
drawString(font, std::string("Username: ") + username, 2, 2, 0xffffffff);
#if defined(RPI)
TextureId id = minecraft->textures->loadTexture("gui/pi_title.png");
#else

View File

@@ -3,6 +3,7 @@
#include "../Screen.h"
#include "../components/Button.h"
#include "../components/ImageButton.h"
class StartMenuScreen: public Screen
{
@@ -25,6 +26,7 @@ private:
Button bHost;
Button bJoin;
Button bOptions;
ImageButton bQuit; // X button in top-right corner
std::string copyright;
int copyrightPosX;

View File

@@ -33,15 +33,16 @@ void UsernameScreen::setupPositions()
int cx = width / 2;
int cy = height / 2;
_btnDone.width = 120;
_btnDone.height = 20;
// Make the done button match the touch-style option tabs
_btnDone.width = 66;
_btnDone.height = 26;
_btnDone.x = (width - _btnDone.width) / 2;
_btnDone.y = height / 2 + 52;
tUsername.x = _btnDone.x;
tUsername.y = _btnDone.y - 60;
tUsername.width = 120;
tUsername.height = 20;
tUsername.x = (width - tUsername.width) / 2;
tUsername.y = _btnDone.y - 60;
}
void UsernameScreen::tick()
@@ -58,9 +59,10 @@ void UsernameScreen::keyPressed(int eventKey)
}
// deliberately do NOT call super::keyPressed — that would close the screen on Escape
_btnDone.active = !tUsername.text.empty();
Screen::keyPressed(eventKey);
// enable the Done button only when there is some text (and ensure it updates after backspace)
_btnDone.active = !tUsername.text.empty();
}
void UsernameScreen::removed()

View File

@@ -153,6 +153,11 @@ int IngameBlockSelectionScreen::getSlotPosY(int slotY) {
return height - 16 - 3 - 22 * 2 - 22 * slotY;
}
int IngameBlockSelectionScreen::getSlotHeight() {
// same as non-touch implementation
return 22;
}
void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum) {
_pendingClose = _blockList->_clickArea->isInside((float)x, (float)y);
if (!_pendingClose)
@@ -166,6 +171,24 @@ void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum) {
super::mouseReleased(x, y, buttonNum);
}
void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym)
{
if (dy == 0) return;
if (_blockList) {
float amount = -dy * getSlotHeight();
_blockList->scrollBy(0, amount);
}
int cols = InventoryColumns;
int maxIndex = InventorySize - 1;
int idx = selectedItem;
if (dy > 0) {
if (idx >= cols) idx -= cols;
} else {
if (idx + cols <= maxIndex) idx += cols;
}
selectedItem = idx;
}
bool IngameBlockSelectionScreen::addItem(const InventoryPane* pane, int itemId)
{
Inventory* inventory = minecraft->player->inventory;

View File

@@ -39,12 +39,16 @@ public:
protected:
virtual void mouseClicked(int x, int y, int buttonNum);
virtual void mouseReleased(int x, int y, int buttonNum);
// also support wheel scrolling
virtual void mouseWheel(int dx, int dy, int xm, int ym) override;
private:
void renderDemoOverlay();
//int getLinearSlotId(int x, int y);
int getSlotPosX(int slotX);
int getSlotPosY(int slotY);
int getSlotHeight();
private:
int selectedItem;

View File

@@ -129,6 +129,11 @@ void JoinGameScreen::buttonClicked(Button* button)
//minecraft->locateMultiplayer();
//minecraft->setScreen(new JoinGameScreen());
}
if(button->id == bJoinByIp.id) {
minecraft->cancelLocateMultiplayer();
minecraft->screenChooser.setScreen(SCREEN_JOINBYIP);
}
if (button->id == bBack.id)
{
minecraft->cancelLocateMultiplayer();

View File

@@ -389,6 +389,26 @@ static char ILLEGAL_FILE_CHARACTERS[] = {
'/', '\n', '\r', '\t', '\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':'
};
void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym)
{
if (!worldsList) return;
if (dy == 0) return;
int num = worldsList->getNumberOfItems();
int idx = worldsList->selectedItem;
if (dy > 0) {
if (idx > 0) {
idx--;
worldsList->stepLeft();
}
} else {
if (idx < num - 1) {
idx++;
worldsList->stepRight();
}
}
worldsList->selectedItem = idx;
}
void SelectWorldScreen::tick()
{
#if 0

View File

@@ -97,6 +97,9 @@ public:
virtual void buttonClicked(Button* button);
virtual void keyPressed(int eventKey);
// support for mouse wheel when desktop code uses touch variant
virtual void mouseWheel(int dx, int dy, int xm, int ym) override;
bool isInGameScreen();
private:
void loadLevelSource();

View File

@@ -29,7 +29,8 @@ namespace Touch {
StartMenuScreen::StartMenuScreen()
: bHost( 2, "Start Game"),
bJoin( 3, "Join Game"),
bOptions( 4, "Options")
bOptions( 4, "Options"),
bQuit( 5, "")
{
ImageDef def;
bJoin.width = 75;
@@ -58,6 +59,17 @@ void StartMenuScreen::init()
buttons.push_back(&bJoin);
buttons.push_back(&bOptions);
// add quit icon (same look as options header)
{
ImageDef def;
def.name = "gui/touchgui.png";
def.width = 34;
def.height = 26;
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
bQuit.setImageDef(def, true);
bQuit.scaleWhenPressed = false;
buttons.push_back(&bQuit);
}
tabButtons.push_back(&bHost);
tabButtons.push_back(&bJoin);
@@ -106,6 +118,10 @@ void StartMenuScreen::setupPositions() {
bHost.x = 1*buttonWidth + (int)(2*spacing);
bOptions.x = 2*buttonWidth + (int)(3*spacing);
// quit icon top-right (use size assigned in init)
bQuit.x = width - bQuit.width;
bQuit.y = 0;
copyrightPosX = width - minecraft->font->width(copyright) - 1;
versionPosX = (width - minecraft->font->width(version)) / 2;// - minecraft->font->width(version) - 2;
}
@@ -133,6 +149,10 @@ void StartMenuScreen::buttonClicked(::Button* button) {
{
minecraft->setScreen(new OptionsScreen());
}
if (button == &bQuit)
{
minecraft->quit();
}
}
bool StartMenuScreen::isInGameScreen() { return false; }
@@ -140,6 +160,10 @@ bool StartMenuScreen::isInGameScreen() { return false; }
void StartMenuScreen::render( int xm, int ym, float a )
{
renderBackground();
// Show current username in the top-left corner
std::string username = minecraft->options.username.empty() ? "unknown" : minecraft->options.username;
drawString(font, std::string("Username: ") + username, 2, 2, 0xffffffff);
glEnable2(GL_BLEND);

View File

@@ -3,6 +3,7 @@
#include "../../Screen.h"
#include "../../components/LargeImageButton.h"
#include "../../components/ImageButton.h"
#include "../../components/TextBox.h"
namespace Touch {
@@ -27,6 +28,7 @@ private:
LargeImageButton bHost;
LargeImageButton bJoin;
LargeImageButton bOptions;
ImageButton bQuit; // X close icon
std::string copyright;
int copyrightPosX;