Skip to content

Commit

Permalink
Fix #4816
Browse files Browse the repository at this point in the history
  • Loading branch information
ashdnazg committed Jul 29, 2015
1 parent bec78c2 commit e8c007f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions rts/Game/SelectedUnitsHandler.cpp
Expand Up @@ -291,7 +291,7 @@ void CSelectedUnitsHandler::HandleUnitBoxSelection(const float4& planeRight, con
}


void CSelectedUnitsHandler::HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest)
void CSelectedUnitsHandler::HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest, bool selectType)
{
//FIXME make modular?
const CMouseHandler::ButtonPressEvt& bp = mouse->buttons[SDL_BUTTON_LEFT];
Expand All @@ -301,7 +301,7 @@ void CSelectedUnitsHandler::HandleSingleUnitClickSelection(CUnit* unit, bool doI
if (unit->team != gu->myTeam && !gu->spectatingFullSelect && !gs->godMode)
return;

if (bp.lastRelease < (gu->gameTime - mouse->doubleClickTime)) {
if (!selectType) {
if (KeyInput::GetKeyModState(KMOD_CTRL) && (selectedUnits.find(unit) != selectedUnits.end())) {
RemoveUnit(unit);
} else {
Expand Down
2 changes: 1 addition & 1 deletion rts/Game/SelectedUnitsHandler.h
Expand Up @@ -40,7 +40,7 @@ class CSelectedUnitsHandler : public CObject

/// used by MouseHandler.cpp & MiniMap.cpp
void HandleUnitBoxSelection(const float4& planeRight, const float4& planeLeft, const float4& planeTop, const float4& planeBottom);
void HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest);
void HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest, bool selectType);

void ToggleBuildIconsFirst();
bool BuildIconsFirst() const { return buildIconsFirst; }
Expand Down
11 changes: 9 additions & 2 deletions rts/Game/UI/MiniMap.cpp
Expand Up @@ -95,6 +95,7 @@ CMiniMap::CMiniMap()
, renderToTexture(true)
, multisampledFBO(false)
, minimapTex(0)
, lastClicked(nullptr)
{
lastWindowSizeX = globalRendering->viewSizeX;
lastWindowSizeY = globalRendering->viewSizeY;
Expand Down Expand Up @@ -475,8 +476,10 @@ void CMiniMap::MoveView(int x, int y)
}


void CMiniMap::SelectUnits(int x, int y) const
void CMiniMap::SelectUnits(int x, int y)
{
const CUnit *_lastClicked = lastClicked;
lastClicked = nullptr;
if (!KeyInput::GetKeyModState(KMOD_SHIFT) && !KeyInput::GetKeyModState(KMOD_CTRL)) {
selectedUnitsHandler.ClearSelected();
}
Expand Down Expand Up @@ -510,9 +513,13 @@ void CMiniMap::SelectUnits(int x, int y) const
} else {
unit = CGameHelper::GetClosestFriendlyUnit(NULL, pos, size, gu->myAllyTeam);
}
lastClicked = unit;
const bool selectType = bp.lastRelease >= (gu->gameTime - mouse->doubleClickTime) && unit == _lastClicked;

selectedUnitsHandler.HandleSingleUnitClickSelection(unit, false);
selectedUnitsHandler.HandleSingleUnitClickSelection(unit, false, selectType);
}

bp.lastRelease = gu->gameTime;
}

/******************************************************************************/
Expand Down
4 changes: 3 additions & 1 deletion rts/Game/UI/MiniMap.h
Expand Up @@ -76,7 +76,7 @@ class CMiniMap : public CInputReceiver {
void ToggleMaximized(bool maxspect);
void SetMaximizedGeometry();

void SelectUnits(int x, int y) const;
void SelectUnits(int x, int y);
void ProxyMousePress(int x, int y, int button);
void ProxyMouseRelease(int x, int y, int button);

Expand Down Expand Up @@ -180,6 +180,8 @@ class CMiniMap : public CInputReceiver {
float color[4];
};
std::deque<Notification> notes;

CUnit* lastClicked;
};


Expand Down
8 changes: 7 additions & 1 deletion rts/Game/UI/MouseHandler.cpp
Expand Up @@ -97,6 +97,7 @@ CMouseHandler::CMouseHandler()
, dragScrollThreshold(0.0f)
, scrollx(0.0f)
, scrolly(0.0f)
, lastClicked(nullptr)
{
const int2 mousepos = IMouseInput::GetInstance()->GetPos();
lastx = mousepos.x;
Expand Down Expand Up @@ -371,6 +372,9 @@ void CMouseHandler::GetSelectionBoxCoeff(const float3& pos1, const float3& dir1,

void CMouseHandler::MouseRelease(int x, int y, int button)
{
const CUnit *_lastClicked = lastClicked;
lastClicked = nullptr;

if (button > NUM_BUTTONS)
return;

Expand Down Expand Up @@ -439,8 +443,10 @@ void CMouseHandler::MouseRelease(int x, int y, int button)
CUnit* unit;
CFeature* feature;
TraceRay::GuiTraceRay(camera->GetPos(), dir, globalRendering->viewRange * 1.4f, NULL, unit, feature, false);
lastClicked = unit;
const bool selectType = bp.lastRelease >= (gu->gameTime - doubleClickTime) && unit == _lastClicked;

selectedUnitsHandler.HandleSingleUnitClickSelection(unit, true);
selectedUnitsHandler.HandleSingleUnitClickSelection(unit, true, selectType);
}

bp.lastRelease = gu->gameTime;
Expand Down
4 changes: 3 additions & 1 deletion rts/Game/UI/MouseHandler.h
Expand Up @@ -15,7 +15,7 @@ static const int NUM_BUTTONS = 10;

class CInputReceiver;
class CCameraController;

class CUnit;

class CMouseHandler
{
Expand Down Expand Up @@ -128,6 +128,8 @@ class CMouseHandler
float scrollx;
float scrolly;

CUnit* lastClicked;

std::map<std::string, CMouseCursor*> cursorFileMap;
std::map<std::string, CMouseCursor*> cursorCommandMap;
};
Expand Down

0 comments on commit e8c007f

Please sign in to comment.