More changes to ensure that switching between selectMode stuff works properly (won't get stuck or trigger on mouseup when it shouldn't)

Hopefully no bugs but lots of the previous commits had bugs.
Also, remove wasd shortcuts for shifting stamps because they conflicted with being able to press 's' to switch selectMode at any point.
This commit is contained in:
jacob1 2015-09-24 01:11:49 -04:00
parent a0c77fe6e8
commit e5ef3cd4a8
2 changed files with 68 additions and 63 deletions

View File

@ -673,7 +673,7 @@ bool GameController::KeyPress(int key, Uint16 character, bool shift, bool ctrl,
sim->player2.comm = (int)(sim->player2.comm)|0x04; //Jump command sim->player2.comm = (int)(sim->player2.comm)|0x04; //Jump command
} }
if((!sim->elementCount[PT_STKM2] || ctrl) && gameView->GetSelectMode() == SelectNone) if (!sim->elementCount[PT_STKM2] || ctrl)
{ {
switch(key) switch(key)
{ {

View File

@ -1101,6 +1101,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
button = BUTTON_MIDDLE; button = BUTTON_MIDDLE;
if (!(zoomEnabled && !zoomCursorFixed)) if (!(zoomEnabled && !zoomCursorFixed))
{ {
isMouseDown = true;
if (selectMode != SelectNone) if (selectMode != SelectNone)
{ {
if (button == BUTTON_LEFT && selectPoint1.X == -1) if (button == BUTTON_LEFT && selectPoint1.X == -1)
@ -1118,7 +1119,6 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
toolIndex = 1; toolIndex = 1;
if (button == BUTTON_MIDDLE) if (button == BUTTON_MIDDLE)
toolIndex = 2; toolIndex = 2;
isMouseDown = true;
c->HistorySnapshot(); c->HistorySnapshot();
if (drawMode == DrawRect || drawMode == DrawLine) if (drawMode == DrawRect || drawMode == DrawLine)
{ {
@ -1142,8 +1142,9 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
drawMode = DrawPoints; drawMode = DrawPoints;
isMouseDown = false; isMouseDown = false;
} }
else else if (isMouseDown)
{ {
isMouseDown = false;
if (selectMode != SelectNone) if (selectMode != SelectNone)
{ {
if (button == BUTTON_LEFT && selectPoint1.X != -1 && selectPoint1.Y != -1 && selectPoint2.X != -1 && selectPoint2.Y != -1) if (button == BUTTON_LEFT && selectPoint1.X != -1 && selectPoint1.Y != -1 && selectPoint2.X != -1 && selectPoint2.Y != -1)
@ -1186,46 +1187,43 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
return; return;
} }
if (isMouseDown) ui::Point finalDrawPoint2 = c->PointTranslate(currentMouse);
if (drawMode == DrawRect || drawMode == DrawLine)
{ {
isMouseDown = false; drawPoint2 = finalDrawPoint2;
ui::Point finalDrawPoint2 = c->PointTranslate(currentMouse); if (drawSnap && drawMode == DrawLine)
if (drawMode == DrawRect || drawMode == DrawLine)
{ {
drawPoint2 = finalDrawPoint2; finalDrawPoint2 = lineSnapCoords(c->PointTranslate(drawPoint1), drawPoint2);
if (drawSnap && drawMode == DrawLine)
{
finalDrawPoint2 = lineSnapCoords(c->PointTranslate(drawPoint1), drawPoint2);
}
if (drawSnap && drawMode == DrawRect)
{
finalDrawPoint2 = rectSnapCoords(c->PointTranslate(drawPoint1), drawPoint2);
}
if (drawMode == DrawRect)
{
c->DrawRect(toolIndex, c->PointTranslate(drawPoint1), finalDrawPoint2);
}
if (drawMode == DrawLine)
{
c->DrawLine(toolIndex, c->PointTranslate(drawPoint1), finalDrawPoint2);
}
} }
else if (drawMode == DrawPoints) if (drawSnap && drawMode == DrawRect)
{ {
// draw final line finalDrawPoint2 = rectSnapCoords(c->PointTranslate(drawPoint1), drawPoint2);
c->DrawPoints(toolIndex, lastPoint, finalDrawPoint2, true);
// plop tool stuff (like STKM)
c->ToolClick(toolIndex, finalDrawPoint2);
} }
// update the drawing mode for the next line if (drawMode == DrawRect)
// since ctrl/shift state may have changed since we started drawing {
UpdateDrawMode(); c->DrawRect(toolIndex, c->PointTranslate(drawPoint1), finalDrawPoint2);
}
if (drawMode == DrawLine)
{
c->DrawLine(toolIndex, c->PointTranslate(drawPoint1), finalDrawPoint2);
}
} }
else if (drawMode == DrawPoints)
{
// draw final line
c->DrawPoints(toolIndex, lastPoint, finalDrawPoint2, true);
// plop tool stuff (like STKM)
c->ToolClick(toolIndex, finalDrawPoint2);
}
// update the drawing mode for the next line
// since ctrl/shift state may have changed since we started drawing
UpdateDrawMode();
} }
// this shouldn't happen, but do this just in case
else if (selectMode != SelectNone && button != BUTTON_LEFT)
selectMode = SelectNone;
} }
void GameView::ExitPrompt() void GameView::ExitPrompt()
@ -1275,13 +1273,13 @@ void GameView::ToolTip(ui::Point senderPosition, std::string toolTip)
void GameView::OnMouseWheel(int x, int y, int d) void GameView::OnMouseWheel(int x, int y, int d)
{ {
if(!d) if (!d)
return; return;
if(selectMode!=SelectNone) if (selectMode != SelectNone)
{ {
return; return;
} }
if(zoomEnabled && !zoomCursorFixed) if (zoomEnabled && !zoomCursorFixed)
{ {
c->AdjustZoomSize(d); c->AdjustZoomSize(d);
} }
@ -1294,7 +1292,8 @@ void GameView::OnMouseWheel(int x, int y, int d)
void GameView::BeginStampSelection() void GameView::BeginStampSelection()
{ {
selectMode = SelectStamp; selectMode = SelectStamp;
selectPoint1 = ui::Point(-1, -1); selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to create a stamp (right click = cancel)"; buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to create a stamp (right click = cancel)";
buttonTipShow = 120; buttonTipShow = 120;
} }
@ -1313,19 +1312,15 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
switch (key) switch (key)
{ {
case KEY_RIGHT: case KEY_RIGHT:
case 'd':
c->TranslateSave(ui::Point(1, 0)); c->TranslateSave(ui::Point(1, 0));
return; return;
case KEY_LEFT: case KEY_LEFT:
case 'a':
c->TranslateSave(ui::Point(-1, 0)); c->TranslateSave(ui::Point(-1, 0));
return; return;
case KEY_UP: case KEY_UP:
case 'w':
c->TranslateSave(ui::Point(0, -1)); c->TranslateSave(ui::Point(0, -1));
return; return;
case KEY_DOWN: case KEY_DOWN:
case 's':
c->TranslateSave(ui::Point(0, 1)); c->TranslateSave(ui::Point(0, 1));
return; return;
case 'r': case 'r':
@ -1483,6 +1478,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{ {
selectMode = SelectCopy; selectMode = SelectCopy;
selectPoint1 = selectPoint2 = ui::Point(-1, -1); selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)"; buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)";
buttonTipShow = 120; buttonTipShow = 120;
} }
@ -1492,15 +1488,19 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
{ {
selectMode = SelectCut; selectMode = SelectCut;
selectPoint1 = selectPoint2 = ui::Point(-1, -1); selectPoint1 = selectPoint2 = ui::Point(-1, -1);
isMouseDown = false;
buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy then cut (right click = cancel)"; buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy then cut (right click = cancel)";
buttonTipShow = 120; buttonTipShow = 120;
} }
break; break;
case 'v': case 'v':
if(ctrl) if (ctrl)
{ {
if (c->LoadClipboard()); if (c->LoadClipboard())
{
selectPoint1 = selectPoint2 = mousePosition; selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false;
}
} }
break; break;
case 'l': case 'l':
@ -1515,6 +1515,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
} }
} }
case 'k': case 'k':
selectMode = SelectNone;
selectPoint1 = selectPoint2 = ui::Point(-1, -1); selectPoint1 = selectPoint2 = ui::Point(-1, -1);
c->OpenStamps(); c->OpenStamps();
break; break;
@ -1600,21 +1601,24 @@ void GameView::OnTick(float dt)
selectMode = SelectNone; selectMode = SelectNone;
if (zoomEnabled && !zoomCursorFixed) if (zoomEnabled && !zoomCursorFixed)
c->SetZoomPosition(currentMouse); c->SetZoomPosition(currentMouse);
if (drawMode == DrawPoints) if (selectMode == SelectNone)
{ {
if (isMouseDown) if (drawMode == DrawPoints)
{ {
c->DrawPoints(toolIndex, lastPoint, currentPoint, true); if (isMouseDown)
lastPoint = currentPoint; {
c->DrawPoints(toolIndex, lastPoint, currentPoint, true);
lastPoint = currentPoint;
}
}
else if (drawMode == DrawFill && isMouseDown)
{
c->DrawFill(toolIndex, c->PointTranslate(currentMouse));
}
else if (windTool && isMouseDown && drawMode == DrawLine)
{
c->DrawLine(toolIndex, c->PointTranslate(drawPoint1), lineSnapCoords(c->PointTranslate(drawPoint1), currentMouse));
} }
}
else if (drawMode == DrawFill && isMouseDown)
{
c->DrawFill(toolIndex, c->PointTranslate(currentMouse));
}
else if (windTool && isMouseDown && drawMode == DrawLine)
{
c->DrawLine(toolIndex, c->PointTranslate(drawPoint1), lineSnapCoords(c->PointTranslate(drawPoint1), currentMouse));
} }
sign * foundSign = c->GetSignAt(mousePosition.X, mousePosition.Y); sign * foundSign = c->GetSignAt(mousePosition.X, mousePosition.Y);
@ -1776,6 +1780,7 @@ void GameView::DoTick(float dt)
if (!c->MouseTick()) if (!c->MouseTick())
{ {
isMouseDown = false; isMouseDown = false;
selectMode = SelectNone;
drawMode = DrawPoints; drawMode = DrawPoints;
} }
Window::DoTick(dt); Window::DoTick(dt);
@ -1888,9 +1893,9 @@ void GameView::enableShiftBehaviour()
if(!shiftBehaviour) if(!shiftBehaviour)
{ {
shiftBehaviour = true; shiftBehaviour = true;
if (!isMouseDown) if (!isMouseDown || selectMode != SelectNone)
UpdateDrawMode(); UpdateDrawMode();
if (isMouseDown || (toolBrush && drawMode == DrawPoints)) else if (toolBrush && drawMode == DrawPoints)
c->SetToolStrength(10.0f); c->SetToolStrength(10.0f);
} }
} }
@ -1900,7 +1905,7 @@ void GameView::disableShiftBehaviour()
if(shiftBehaviour) if(shiftBehaviour)
{ {
shiftBehaviour = false; shiftBehaviour = false;
if (!isMouseDown) if (!isMouseDown || selectMode != SelectNone)
UpdateDrawMode(); UpdateDrawMode();
if (!ctrlBehaviour) if (!ctrlBehaviour)
c->SetToolStrength(1.0f); c->SetToolStrength(1.0f);
@ -1932,7 +1937,7 @@ void GameView::enableCtrlBehaviour()
if(!ctrlBehaviour) if(!ctrlBehaviour)
{ {
ctrlBehaviour = true; ctrlBehaviour = true;
if (!isMouseDown) if (!isMouseDown || selectMode != SelectNone)
UpdateDrawMode(); UpdateDrawMode();
//Show HDD save & load buttons //Show HDD save & load buttons
@ -1948,7 +1953,7 @@ void GameView::enableCtrlBehaviour()
searchButton->SetToolTip("Open a simulation from your hard drive."); searchButton->SetToolTip("Open a simulation from your hard drive.");
if (currentSaveType == 2) if (currentSaveType == 2)
((SplitButton*)saveSimulationButton)->SetShowSplit(true); ((SplitButton*)saveSimulationButton)->SetShowSplit(true);
if(isMouseDown || (toolBrush && drawMode == DrawPoints)) if ((isMouseDown && selectMode == SelectNone) || (toolBrush && drawMode == DrawPoints))
{ {
if(!shiftBehaviour) if(!shiftBehaviour)
c->SetToolStrength(.1f); c->SetToolStrength(.1f);
@ -1963,7 +1968,7 @@ void GameView::disableCtrlBehaviour()
if(ctrlBehaviour) if(ctrlBehaviour)
{ {
ctrlBehaviour = false; ctrlBehaviour = false;
if (!isMouseDown) if (!isMouseDown || selectMode != SelectNone)
UpdateDrawMode(); UpdateDrawMode();
//Hide HDD save & load buttons //Hide HDD save & load buttons