mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-20 15:03:32 +00:00
Added mouse wheel support to the world selection screen.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -90,6 +90,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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user