Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Normal Checklist #10

Draft
wants to merge 14 commits into
base: Cross
Choose a base branch
from
Draft
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
23 changes: 22 additions & 1 deletion B78XH/B78XH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<LinkIncremental>true</LinkIncremental>
<TargetExt>.wasm</TargetExt>
<IncludePath>$(MSFS_IncludePath);$(CPP_EXTERNALS)\include\NANOVG;</IncludePath>
<OutDir>..\..\..\..\WebstormProjects\B78XH-INTERIOR\SimObjects\Airplanes\Asobo_B787_10\panel</OutDir>
<OutDir>..\..\B78XH\SimObjects\Airplanes\Heavy-Division-B78XH-mod\panel</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|MSFS'">
<LinkIncremental>false</LinkIncremental>
Expand Down Expand Up @@ -153,6 +153,15 @@
<ClCompile Include="CDURoutePageControl.cpp" />
<ClCompile Include="CDUScratchpadControl.cpp" />
<ClCompile Include="CDUSelectKeyButtonControl.cpp" />
<ClCompile Include="CheckList.cpp" />
<ClCompile Include="CheckListButton.cpp" />
<ClCompile Include="CheckListItem.cpp" />
<ClCompile Include="CheckListLine.cpp" />
<ClCompile Include="CheckListLineSingle.cpp" />
<ClCompile Include="CheckListLineStateIndicator.cpp" />
<ClCompile Include="CheckListStatus.cpp" />
<ClCompile Include="CheckListTitle.cpp" />
<ClCompile Include="MFDCHKLControl.cpp" />
<ClCompile Include="MFDMouseCursorControl.cpp" />
<ClCompile Include="CDUMouseMoveResolver.cpp" />
<ClCompile Include="CDUMouseResolver.cpp" />
Expand Down Expand Up @@ -258,6 +267,7 @@
<ClCompile Include="PFDTargetAltitudeApplication.cpp" />
<ClCompile Include="PFDVerticalSpeedIndicator.cpp" />
<ClCompile Include="PFDVerticalSpeedIndicatorApplication.cpp" />
<ClCompile Include="PreFlightCheckList.cpp" />
<ClCompile Include="RadioNav.cpp" />
<ClCompile Include="RedApplication.cpp" />
<ClCompile Include="RightInboardDisplay.cpp" />
Expand Down Expand Up @@ -371,6 +381,16 @@
<ClInclude Include="CDURoutePageControl.h" />
<ClInclude Include="CDUScratchpadControl.h" />
<ClInclude Include="CDUSelectKeyButtonControl.h" />
<ClInclude Include="CheckList.h" />
<ClInclude Include="CheckListButton.h" />
<ClInclude Include="CheckListDimensions.h" />
<ClInclude Include="CheckListItem.h" />
<ClInclude Include="CheckListLine.h" />
<ClInclude Include="CheckListLineSingle.h" />
<ClInclude Include="CheckListLineStateIndicator.h" />
<ClInclude Include="CheckListStatus.h" />
<ClInclude Include="CheckListTitle.h" />
<ClInclude Include="MFDCHKLControl.h" />
<ClInclude Include="MFDMouseCursorControl.h" />
<ClInclude Include="CDUMouseMoveResolver.h" />
<ClInclude Include="CDUMouseResolver.h" />
Expand Down Expand Up @@ -471,6 +491,7 @@
<ClInclude Include="PFDTargetAirspeedApplication.h" />
<ClInclude Include="PFDTargetAltitudeApplication.h" />
<ClInclude Include="PFDVerticalSpeedIndicatorApplication.h" />
<ClInclude Include="PreFlightCheckList.h" />
<ClInclude Include="RadioNav.h" />
<ClInclude Include="RedApplication.h" />
<ClInclude Include="RightInboardDisplay.h" />
Expand Down
72 changes: 72 additions & 0 deletions B78XH/B78XH.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,36 @@
<ClCompile Include="MFDNDControl.cpp">
<Filter>Source Files\Controls\Controls\MFD\ND</Filter>
</ClCompile>
<ClCompile Include="MFDCHKLControl.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList</Filter>
</ClCompile>
<ClCompile Include="CheckListLineStateIndicator.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="CheckListLine.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="CheckListItem.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="CheckListButton.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="CheckListTitle.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="CheckListLineSingle.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="CheckList.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
<ClCompile Include="PreFlightCheckList.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckLists</Filter>
</ClCompile>
<ClCompile Include="CheckListStatus.cpp">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MCPAltitudeGauge.h">
Expand Down Expand Up @@ -1332,6 +1362,39 @@
<ClInclude Include="MFDNDControl.h">
<Filter>Source Files\Controls\Controls\MFD\ND</Filter>
</ClInclude>
<ClInclude Include="MFDCHKLControl.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList</Filter>
</ClInclude>
<ClInclude Include="CheckListItem.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckListLineStateIndicator.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckListLine.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckListDimensions.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckListButton.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckListTitle.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckListLineSingle.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="CheckList.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
<ClInclude Include="PreFlightCheckList.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckLists</Filter>
</ClInclude>
<ClInclude Include="CheckListStatus.h">
<Filter>Source Files\Controls\Controls\MFD\CheckList\CheckListBasics</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down Expand Up @@ -1652,6 +1715,15 @@
<Filter Include="Source Files\Controls\Controls\MFD\ND">
<UniqueIdentifier>{983f63d5-9b41-4db6-a45a-80ca39311e9c}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Controls\Controls\MFD\CheckList">
<UniqueIdentifier>{41a37572-c463-484a-bf96-160e9f8155a2}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Controls\Controls\MFD\CheckList\CheckListBasics">
<UniqueIdentifier>{1b4f3874-894c-4757-b210-c6ef873b9b07}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Controls\Controls\MFD\CheckList\CheckLists">
<UniqueIdentifier>{39e6dbd1-ca13-4115-a6a3-f07a70a71a11}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="TODO.txt">
Expand Down
89 changes: 89 additions & 0 deletions B78XH/CheckList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "CheckList.h"

void CheckList::setupControls() {
CheckListItem::setupControls();
addOnBeforeRender([this](BaseControl&) -> bool {
serviceChecklistUpdateLoop();
return true;
});
setupChecklistLayout();
}

void CheckList::prepareControls() {
CheckListItem::prepareControls();
addChecklistControls();
}

auto CheckList::setupChecklistLayout() -> void {
title_->position.setPosition(200, 0, 500,
CheckListDimensions::TOTAL_LINE_HEIGHT * 1);
for (auto i = 0; i < lines_.size(); i++) {
// TODO: No pagination yet, no normal checklist needs pagination
const std::shared_ptr<CheckListLine> line = lines_.at(i);
line->position.setPosition(0, CheckListDimensions::TOTAL_LINE_HEIGHT * (i + 1),
CheckListDimensions::TOTAL_WIDTH,
CheckListDimensions::TOTAL_LINE_HEIGHT * (i + 2));
}
status_->position.setPosition(200, position.getHeight() - CheckListDimensions::TOTAL_LINE_HEIGHT / 2 - CheckListDimensions::MARGIN, 500,
position.getHeight() - CheckListDimensions::MARGIN);
}

auto CheckList::checkChecklistCompleted() -> void {
if (getCurrentState() == CHECKLIST_ITEM_STATE::OVERRIDDEN) {
return; // overridden checklist must be explicitly cleared
}
for (const std::shared_ptr<CheckListLine> l : lines_) {
if (l->getCurrentState() == CHECKLIST_ITEM_STATE::OPEN) {
setCurrentState(CHECKLIST_ITEM_STATE::OPEN);
return;
}
}
setCurrentState(CHECKLIST_ITEM_STATE::COMPLETED);
}

auto CheckList::advanceCurrentLine() -> void {
toggleCurrentLineHighlight(false);
currentLine_++;
toggleCurrentLineHighlight(true);
checkChecklistCompleted();
}

auto CheckList::resetChecklist() -> void {
for (const std::shared_ptr<CheckListLine> l : lines_) {
l->setCurrentState(CHECKLIST_ITEM_STATE::OPEN);
}
setCurrentState(CHECKLIST_ITEM_STATE::OPEN);
currentLine_ = 0;
toggleCurrentLineHighlight(true);
}

auto CheckList::checkClosedLoopItems() -> void {
}

auto CheckList::addChecklistControls() -> void {
add(title_);
add(status_);
for (std::shared_ptr<CheckListLine> l : lines_) {
add(l);
}
}

auto CheckList::serviceChecklistUpdateLoop() -> void {
if (currentLine_ >= lines_.size()) {
// overrun, so the checklist is either completed or overridden.
return;
}
checkClosedLoopItems();
const std::shared_ptr<CheckListLine> currentLine = lines_.at(currentLine_);
if (currentLine->getCurrentState() != CHECKLIST_ITEM_STATE::OPEN) {
advanceCurrentLine();
}
}

auto CheckList::toggleCurrentLineHighlight(bool isCurrent) -> void {
if (currentLine_ >= lines_.size()) {
return;
}
const std::shared_ptr<CheckListLine> currentLine = lines_.at(currentLine_);
currentLine->setIsCurrent(isCurrent);
}
69 changes: 69 additions & 0 deletions B78XH/CheckList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once
#include "CheckListItem.h"
#include "CheckListLine.h"
#include "CheckListTitle.h"
#include "CheckListStatus.h"
#include "CheckListLineSingle.h"

class CheckList : public CheckListItem {
public:
CheckList(const string& name, const CheckListTitle::TITLE_TYPE titleType, const string& titleText)
: CheckListItem(name),
currentLine_(0), title_(std::make_shared<CheckListTitle>("TITLE", titleType, titleText)),
status_(std::make_shared<CheckListStatus>("STATUS", this)) {
}

auto setupControls() -> void override;
auto prepareControls() -> void override;

protected:
/**
* \brief The lines in this checklist.
* These lines have operational effects and counts towards the checklists overall completeness
*/
std::vector<std::shared_ptr<CheckListLine>> lines_{};

/**
* \brief Evaluates the entire checklists status. This does not care about overridden checklist.
*/
auto checkChecklistCompleted() -> void;
/**
* \brief Advances the current line pointer. This also check if the checklist is completed.
*/
auto advanceCurrentLine() -> void;
/**
* \brief Resets all checklist lines
*/
auto resetChecklist() -> void;
/**
* \brief Used to check all closed loop items and set their completeness state.
*/
virtual auto checkClosedLoopItems() -> void;
/**
* \brief Add controls for a basic checklist with the title and all the item in lines_.
* This will suffice for most of the checklist.
* For special checklist with more items to render other than these, override this.
*/
virtual auto addChecklistControls() -> void;
/**
* \brief Setup layout for a basic checklist with all items in lines_ being 1 line height.
* This will suffice for most of the checklist.
* For special checklist (e.g. with branch items), override this with its own layout.
*/
virtual auto setupChecklistLayout() -> void;

private:
int currentLine_;
const std::shared_ptr<CheckListTitle> title_;
const std::shared_ptr<CheckListStatus> status_;

/**
* \brief Invoked periodically to check the checklist
*/
auto serviceChecklistUpdateLoop() -> void;
/**
* \brief Lower level UI utility. Highlight/Unhighlight the line pointed at currentLine_ if valid.
* For normal usage, use advanceCurrentLine, resetChecklist
*/
auto toggleCurrentLineHighlight(bool isCurrent) -> void;
};
30 changes: 30 additions & 0 deletions B78XH/CheckListButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "CheckListButton.h"

void CheckListButton::render() {
Control::render();
drawButtonBorder(Tools::Colors::cduButtonGray,
Tools::Colors::cduButtonBorderTopGray,
Tools::Colors::cduButtonBorderRightGray,
Tools::Colors::cduButtonBorderBottomGray,
Tools::Colors::cduButtonBorderLeftGray);

nvgFontFace(getContext(), "heavy-fmc");
nvgFontSize(getContext(), 24.0f);
nvgFillColor(getContext(), Tools::Colors::white);
nvgTextAlign(getContext(), NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
nvgBeginPath(getContext());
{
nvgTextBoxBounds(getContext(), 0, position.height / 2, position.width, displayText_.c_str(), nullptr, textBounds_);
const auto boundsHeight = textBounds_[3] - textBounds_[1];
nvgTextBox(getContext(), 0, position.height / 2 - boundsHeight / 2 + CheckListDimensions::BORDER_WIDTH, position.width, displayText_.c_str(), nullptr);
nvgFill(getContext());
}
nvgClosePath(getContext());

if (shouldTriggerEvent()) {
Console::log("Checklist button triggered {}", displayText_.c_str());
if(invoke_ != nullptr) {
invoke_();
}
}
}
23 changes: 23 additions & 0 deletions B78XH/CheckListButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <functional>
#include "CheckListItem.h"
#include "Control.h"
#include "Tools/Console.h"

/**
* \brief A clickable button on the checklist. This mostly shows up at the header/footer and in the menus
*/
class CheckListButton : public CheckListItem {
public:
CheckListButton(const string& name, const std::function<void()>& invoke, const string& displayText)
: CheckListItem(name),
invoke_(invoke), displayText_(displayText) {
}

auto render() -> void override;

private:
const std::function<void()> invoke_;
const string displayText_;
float textBounds_[4] = {0, 0, 0, 0};
};
14 changes: 14 additions & 0 deletions B78XH/CheckListDimensions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

class CheckListDimensions {
public:
static constexpr float TOTAL_LINE_HEIGHT = 70;
static constexpr float TOTAL_WIDTH = 700; // should match half MFD width
static constexpr float MARGIN = 8;
static constexpr float BORDER_WIDTH = 5;
static constexpr float INNER_Y_START = MARGIN + BORDER_WIDTH / 2;
static constexpr float INNER_HEIGHT = TOTAL_LINE_HEIGHT - 2 * INNER_Y_START;
static constexpr float ONE_FORTH_INNER_HEIGHT = INNER_HEIGHT / 4;
static constexpr float INNER_Y_END = TOTAL_LINE_HEIGHT - INNER_Y_START;
static constexpr float INNER_TEXT_X_START = INNER_Y_END + 2 * MARGIN + BORDER_WIDTH / 2;
};
Loading