FIX: Now we're using useTouchsceen() right way!!!!

This commit is contained in:
2026-03-22 02:12:04 +03:00
parent 91ce365a26
commit 4f8b18b735
23 changed files with 193 additions and 209 deletions

View File

@@ -51,7 +51,8 @@ Gui::Gui(Minecraft* minecraft)
_currentDropTicks(-1),
_currentDropSlot(-1),
MAX_MESSAGE_WIDTH(240),
itemNameOverlayTime(2)
itemNameOverlayTime(2),
_openInventorySlot(minecraft->useTouchscreen())
{
glGenBuffers2(1, &_inventoryRc.vboId);
glGenBuffers2(1, &rcFeedbackInner.vboId);
@@ -75,11 +76,8 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
//minecraft->gameRenderer->setupGuiScreen();
Font* font = minecraft->font;
#ifdef PLATFORM_DESKTOP
const bool isTouchInterface = false;
#else
const bool isTouchInterface = minecraft->useTouchscreen();
#endif
const int screenWidth = (int)(minecraft->width * InvGuiScale);
const int screenHeight = (int)(minecraft->height * InvGuiScale);
blitOffset = -90;
@@ -206,16 +204,10 @@ void Gui::handleClick(int button, int x, int y) {
if (button != MouseAction::ACTION_LEFT) return;
int slot = getSlotIdAt(x, y);
if (slot != -1)
{
#ifndef PLATFORM_DESKTOP
if (slot == (getNumSlots()-1))
{
if (slot != -1) {
if (_openInventorySlot && slot == (getNumSlots()-1)) {
minecraft->screenChooser.setScreen(SCREEN_BLOCKSELECTION);
}
else
#endif
{
} else {
minecraft->player->inventory->selectSlot(slot);
itemNameOverlayTime = 0;
}
@@ -537,11 +529,7 @@ void Gui::tickItemDrop()
static bool isCurrentlyActive = false;
isCurrentlyActive = false;
int slots = getNumSlots();
#ifndef PLATFORM_DESKTOP
slots--;
#endif
int slots = getNumSlots() - _openInventorySlot;
if (Mouse::isButtonDown(MouseAction::ACTION_LEFT)) {
int slot = getSlotIdAt(Mouse::getX(), Mouse::getY());
@@ -1083,13 +1071,7 @@ void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) {
float x = baseItemX;
int slots = getNumSlots();
// TODO: if using touchscreen
#ifndef PLATFORM_DESKTOP
slots--;
#endif
int slots = getNumSlots() - _openInventorySlot;
for (int i = 0; i < slots; i++) {
renderSlot(i, (int)x, ySlot, a);
@@ -1097,9 +1079,10 @@ void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) {
}
_inventoryNeedsUpdate = false;
#ifndef PLATFORM_DESKTOP
blit(screenWidth / 2 + 10 * getNumSlots() - 20 + 4, ySlot + 6, 242, 252, 14, 4, 14, 4);
#endif
if (_openInventorySlot) {
blit(screenWidth / 2 + 10 * getNumSlots() - 20 + 4, ySlot + 6, 242, 252, 14, 4, 14, 4);
}
minecraft->textures->loadAndBindTexture("gui/gui_blocks.png");
t.endOverrideAndDraw();

View File

@@ -127,6 +127,8 @@ private:
static const float DropTicks;
float _currentDropTicks;
int _currentDropSlot;
bool _openInventorySlot;
};
#endif /*NET_MINECRAFT_CLIENT_GUI__Gui_H__*/

View File

@@ -177,9 +177,11 @@ void Screen::keyPressed( int eventKey )
textbox->keyPressed(minecraft, eventKey);
}
#ifdef TABBING
if (minecraft->useTouchscreen())
return;
// "Tabbing" the buttons (walking with keys)
const int tabButtonCount = tabButtons.size();
if (!tabButtonCount)
@@ -199,6 +201,7 @@ void Screen::keyPressed( int eventKey )
}
updateTabButtonSelection();
#endif
}
void Screen::charPressed(char inputChar) {
@@ -209,11 +212,13 @@ void Screen::charPressed(char inputChar) {
void Screen::updateTabButtonSelection()
{
#ifdef TABBING
if (minecraft->useTouchscreen())
return;
for (unsigned int i = 0; i < tabButtons.size(); ++i)
tabButtons[i]->selected = (i == tabButtonIndex);
#endif
}
void Screen::mouseClicked( int x, int y, int buttonNum )

View File

@@ -95,7 +95,7 @@ void Button::renderBg( Minecraft* minecraft, int xm, int ym )
}
bool Button::hovered(Minecraft* minecraft, int xm , int ym) {
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : false;
return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym);
}
bool Button::isInside( int xm, int ym ) {
@@ -143,7 +143,8 @@ TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg )
void TButton::renderBg( Minecraft* minecraft, int xm, int ym )
{
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : false);
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
// bool hovered = active && (_currentlyDown && isInside(xm, ym));
minecraft->textures->loadAndBindTexture("gui/touchgui.png");

View File

@@ -42,7 +42,7 @@ void ImageButton::render(Minecraft* minecraft, int xm, int ym) {
//minecraft->textures->loadAndBindTexture("gui/gui.png");
glColor4f2(1, 1, 1, 1);
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : false);
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
bool IsSecondImage = isSecondImage(hovered);
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);

View File

@@ -33,7 +33,7 @@ void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) {
//minecraft->textures->loadAndBindTexture("gui/gui.png");
glColor4f2(1, 1, 1, 1);
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : false);
bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
//printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym);
//int yImage = getYImage(hovered || selected);

View File

@@ -31,7 +31,7 @@ ConfirmScreen::~ConfirmScreen() {
void ConfirmScreen::init()
{
if (minecraft->useTouchscreen()) {
if (/* minecraft->useTouchscreen() */ true) {
yesButton = new Touch::TButton(0, 0, 0, yesButtonText),
noButton = new Touch::TButton(1, 0, 0, noButtonText);
} else {

View File

@@ -23,7 +23,7 @@ DeathScreen::~DeathScreen()
void DeathScreen::init()
{
if (minecraft->useTouchscreen()) {
if (/* minecraft->useTouchscreen() */ true) {
bRespawn = new Touch::TButton(1, "Respawn!");
bTitle = new Touch::TButton(2, "Main menu");
} else {

View File

@@ -21,7 +21,7 @@ public:
}
void init() {
if (minecraft->useTouchscreen())
if (/* minecraft->useTouchscreen() */ true)
_back = new Touch::TButton(1, "Ok");
else
_back = new Button(1, "Ok");

View File

@@ -17,7 +17,7 @@ InBedScreen::~InBedScreen() {
}
void InBedScreen::init() {
if (minecraft->useTouchscreen()) {
if (/* minecraft->useTouchscreen() */ true) {
bWakeUp = new Touch::TButton(1, "Leave Bed");
} else {
bWakeUp = new Button(1, "Leave Bed");

View File

@@ -48,7 +48,7 @@ PauseScreen::~PauseScreen() {
}
void PauseScreen::init() {
if (minecraft->useTouchscreen()) {
if (/* minecraft->useTouchscreen() */ true) {
bContinue = new Touch::TButton(1, "Back to game");
bOptions = new Touch::TButton(5, "Options");
bQuit = new Touch::TButton(2, "Quit to title");

View File

@@ -11,6 +11,8 @@ public:
void render(int xm, int ym, float a);
bool isInGameScreen();
virtual void keyPressed(int eventKey) {}
void tick();
private:
int ticks;

View File

@@ -21,7 +21,7 @@ Screen* ScreenChooser::createScreen( ScreenId id )
Screen* screen = NULL;
// :sob:
if (_mc->useTouchscreen()) {
if (/* _mc->useTouchscreen() */ true) {
switch (id) {
case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break;
case SCREEN_SELECTWORLD: screen = new Touch::SelectWorldScreen();break;

View File

@@ -56,7 +56,7 @@ void SimpleChooseLevelScreen::init()
def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height));
bBack->setImageDef(def, true);
}
if (minecraft->useTouchscreen()) {
if (/* minecraft->useTouchscreen() */ true) {
bGamemode = new Touch::TButton(1, "Survival mode");
bCheats = new Touch::TButton(4, "Cheats: Off");
bCreate = new Touch::TButton(3, "Create");

View File

@@ -41,7 +41,7 @@ public:
//fill(x+1, y+1, x+w-1, y+h-1, 0xff999999);
bool hovered = active && (minecraft->useTouchscreen()?
(_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : false);
(_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
if (hovered || *selectedPtr == this)
statePressed->draw(Tesselator::instance, (float)x, (float)y);
@@ -547,7 +547,7 @@ void CraftButton::renderBg(Minecraft* minecraft, int xm, int ym) {
//fill(x+1, y+1, x+w-1, y+h-1, 0xff999999);
bool hovered = active && (minecraft->useTouchscreen()?
(_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : false);
(_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym));
if (hovered || selected)
bgSelected->draw(Tesselator::instance, (float)x, (float)y);