Skip to content

Commit

Permalink
feat: display information for multiple published holds
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Jan 16, 2023
1 parent 43560cd commit c60b62c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/plugin/hold/HoldDisplay.cpp
Expand Up @@ -98,6 +98,19 @@ namespace UKControllerPlugin {
this->showHoldInformation = !this->showHoldInformation;
} else if (button == "options") {
this->dialogManager.OpenDialog(IDD_HOLD_PARAMS, reinterpret_cast<LPARAM>(this));
} else if (button == "prevhold") {
if (this->selectedPublishedHoldIndex == 0) {
return;
}

this->selectedPublishedHoldIndex--;
} else if (button == "nexthold") {
if (this->publishedHolds.empty() ||
this->selectedPublishedHoldIndex == this->publishedHolds.size() - 1) {
return;
}

this->selectedPublishedHoldIndex++;
}
}

Expand All @@ -120,6 +133,11 @@ namespace UKControllerPlugin {
}
}

unsigned int HoldDisplay::GetPublishedHoldIndex() const
{
return this->selectedPublishedHoldIndex;
}

/*
Get the rectangle to render the background of the hold display
*/
Expand Down Expand Up @@ -691,8 +709,37 @@ namespace UKControllerPlugin {
}

// Display the published hold selection buttons
const HoldingData* hold = *std::next(this->publishedHolds.cbegin(), this->selectedPublishedHoldIndex);

Gdiplus::Rect buttonRect = {this->windowPos.x + 5, this->titleArea.GetBottom() + 5, 20, 20};

const HoldingData* hold = *this->publishedHolds.cbegin();
// Left
graphics.DrawRect(buttonRect, this->sameLevelBoxPen);
graphics.DrawString(L"<", buttonRect, this->dataBrush);
radarScreen.RegisterScreenObject(
screenObjectId,
this->navaid.identifier + "/prevhold",
RECT{buttonRect.GetLeft(), buttonRect.GetTop(), buttonRect.GetRight(), buttonRect.GetBottom()},
false);

// Right
buttonRect.X = this->titleArea.GetRight() - 25;
graphics.DrawRect(buttonRect, this->sameLevelBoxPen);
graphics.DrawString(L">", buttonRect, this->dataBrush);
radarScreen.RegisterScreenObject(
screenObjectId,
this->navaid.identifier + "/nexthold",
RECT{buttonRect.GetLeft(), buttonRect.GetTop(), buttonRect.GetRight(), buttonRect.GetBottom()},
false);

// Text
buttonRect.X = this->windowPos.x + 30;
buttonRect.Width = this->titleArea.Width - 60;
graphics.DrawString(
L"Hold " + std::to_wstring(this->selectedPublishedHoldIndex + 1) + L" of " +
std::to_wstring(this->publishedHolds.size()),
buttonRect,
this->dataBrush);

// Render the data
graphics.DrawString(ConvertToTchar(hold->description), dataRect, this->dataBrush);
Expand Down
4 changes: 4 additions & 0 deletions src/plugin/hold/HoldDisplay.h
Expand Up @@ -82,6 +82,7 @@ namespace UKControllerPlugin {
int GetMinimumLevel(void) const;
void SetMaximumLevel(int level);
void SetMinimumLevel(int level);
unsigned int GetPublishedHoldIndex() const;
std::map<int, std::set<std::shared_ptr<HoldingAircraft>, CompareHoldingAircraft>> MapAircraftToLevels(
const std::set<std::shared_ptr<HoldingAircraft>, CompareHoldingAircraft>& aircraft) const;
bool IsInInformationMode(void) const;
Expand Down Expand Up @@ -206,6 +207,9 @@ namespace UKControllerPlugin {
// Should we display the information about the hold
bool showHoldInformation = false;

// The currently selected published hold to display in the information tab
unsigned int selectedPublishedHoldIndex = 0;

// Titlebar
Gdiplus::Rect titleArea = {0, 0, this->windowWidth, 15};
RECT titleRect = {0, 0, this->windowWidth, 15};
Expand Down
28 changes: 28 additions & 0 deletions test/plugin/hold/HoldDisplayTest.cpp
Expand Up @@ -212,6 +212,34 @@ namespace UKControllerPluginTest {
this->display.SaveDataToAsr(userSetting);
}

TEST_F(HoldDisplayTest, ClickingPreviousAndNextHoldChangesSelectedHold)
{
this->publishedHolds.Add({1, "TIMBA", "TIMBA", 2000, 3000});
this->publishedHolds.Add({2, "TIMBA", "TIMBA", 2000, 3000});
this->publishedHolds.Add({3, "TIMBA", "TIMBA", 2000, 3000});
this->publishedHolds.Add({4, "TIMBA", "TIMBA", 2000, 3000});

HoldDisplay display2(mockPlugin, holdManager, navaid, publishedHolds, dialogManager, addAircraftList);

EXPECT_EQ(0, display2.GetPublishedHoldIndex());
display2.ButtonClicked("nexthold");
EXPECT_EQ(1, display2.GetPublishedHoldIndex());
display2.ButtonClicked("nexthold");
EXPECT_EQ(2, display2.GetPublishedHoldIndex());
display2.ButtonClicked("nexthold");
EXPECT_EQ(3, display2.GetPublishedHoldIndex());
display2.ButtonClicked("nexthold");
EXPECT_EQ(3, display2.GetPublishedHoldIndex());
display2.ButtonClicked("prevhold");
EXPECT_EQ(2, display2.GetPublishedHoldIndex());
display2.ButtonClicked("prevhold");
EXPECT_EQ(1, display2.GetPublishedHoldIndex());
display2.ButtonClicked("prevhold");
EXPECT_EQ(0, display2.GetPublishedHoldIndex());
display2.ButtonClicked("prevhold");
EXPECT_EQ(0, display2.GetPublishedHoldIndex());
}

TEST_F(HoldDisplayTest, ClickingMinusDescreasesMaximumDisplayLevelUntilMinimum)
{
EXPECT_EQ(15000, this->display.GetMaximumLevel());
Expand Down

0 comments on commit c60b62c

Please sign in to comment.