Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions source/client/gui/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ Screen::~Screen()
m_elements.clear();
}

void Screen::_controllerEvent(GameController::ID controllerId)
{
// @TODO: this probably shouldn't be here
GameController::StickEvent event;
event.id = controllerId;
event.state = GameControllerManager::getDirection(controllerId);
if (event.state != GameController::STICK_STATE_NONE)
{
event.x = GameControllerManager::getX(controllerId);
event.y = GameControllerManager::getY(controllerId);
handleControllerStickEvent(event);
}
}

bool Screen::_nextElement()
{
if (!doElementTabbing())
Expand Down Expand Up @@ -831,16 +845,8 @@ void Screen::controllerEvent()
_processControllerDirection(1);
_processControllerDirection(2);

// @TODO: this probably shouldn't be here
GameController::StickEvent event;
event.id = 1;
event.state = GameControllerManager::getDirection(1);
if (event.state != GameController::STICK_STATE_NONE)
{
event.x = GameControllerManager::getX(1);
event.y = GameControllerManager::getY(1);
handleControllerStickEvent(event);
}
_controllerEvent(1);
_controllerEvent(2);
}

void Screen::checkForPointerEvent()
Expand Down Expand Up @@ -889,16 +895,6 @@ void Screen::handleScrollWheel(float force)

void Screen::handleControllerStickEvent(const GameController::StickEvent& stick)
{
/*if (stick.state == GameController::STICK_STATE_DOWN)
{
handleScrollWheel(stick.y);
}
else if (stick.state <= GameController::STICK_STATE_UP)
{
MenuGamePad::setX(directionId + 1, x);
MenuGamePad::setY(directionId + 1, y);
}*/

if (m_bRenderPointer && stick.id == 1)
{
// Behold pizzart's magic numbers
Expand Down Expand Up @@ -938,6 +934,13 @@ void Screen::handleControllerStickEvent(const GameController::StickEvent& stick)
m_targetMenuPointer.x = Mth::clamp(m_menuPointer.x + move.x, 0.0f, m_width);
m_targetMenuPointer.y = Mth::clamp(m_menuPointer.y - move.y, 0.0f, m_height);
}
else if (stick.id == 2)
{
if (stick.state == GameController::STICK_STATE_DOWN || stick.state == GameController::STICK_STATE_UP)
{
handleScrollWheel(stick.y);
}
}
}

void Screen::renderBackground(int vo)
Expand Down
5 changes: 4 additions & 1 deletion source/client/gui/Screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ class Screen : public GuiComponent
Screen();
virtual ~Screen();

private:
void _controllerEvent(GameController::ID controllerId);

protected:
bool _prevElement();
bool _nextElement();
bool _prevElement();
void _addElement(Button& element, bool isTabbable = true);
void _addElementToList(unsigned int index, Button& element, bool isTabbable = true);
bool _nextElementList();
Expand Down