98 lines
2.7 KiB
C++
98 lines
2.7 KiB
C++
|
#include "gui/common/NamedField.hpp"
|
||
|
#include "gui/containers/ConfigItem.hpp"
|
||
|
#include "main.h"
|
||
|
#include <cstdint>
|
||
|
#include <gui/vehicleconfig_screen/VehicleConfigView.hpp>
|
||
|
|
||
|
VehicleConfigView::VehicleConfigView() : selectedParam{0} {}
|
||
|
|
||
|
void VehicleConfigView::setupScreen() {
|
||
|
VehicleConfigViewBase::setupScreen();
|
||
|
params.setNumberOfItems(ParamFieldType_COUNT);
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::tearDownScreen() {
|
||
|
VehicleConfigViewBase::tearDownScreen();
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::paramsUpdateItem(ConfigItem &item, int16_t itemIndex) {
|
||
|
item.setType(static_cast<ParamFieldType>(itemIndex));
|
||
|
item.setSelected(itemIndex == selectedParam);
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::selectPrevParam() {
|
||
|
if (selectedParam == 0) {
|
||
|
updateSelectedParam(ParamFieldType_COUNT - 1);
|
||
|
} else {
|
||
|
updateSelectedParam(selectedParam - 1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::selectNextParam() {
|
||
|
updateSelectedParam((selectedParam + 1) % ParamFieldType_COUNT);
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::decParam() {
|
||
|
// TODO: How to handle this for different parameter types?
|
||
|
}
|
||
|
void VehicleConfigView::incParam() {
|
||
|
// TODO: How to handle this for different parameter types?
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::confirmParam() {
|
||
|
// TODO: How to handle this for different parameter types?
|
||
|
}
|
||
|
|
||
|
void VehicleConfigView::updateSelectedParam(int select) {
|
||
|
int previousSelected = selectedParam;
|
||
|
selectedParam = select;
|
||
|
params.itemChanged(previousSelected);
|
||
|
params.itemChanged(selectedParam);
|
||
|
|
||
|
ConfigItem *firstItem = nullptr;
|
||
|
int16_t firstY = INT16_MAX;
|
||
|
ConfigItem *lastItem = nullptr;
|
||
|
int16_t lastY = INT16_MIN;
|
||
|
for (int16_t i = 0; i < paramsListItems.getNumberOfDrawables(); ++i) {
|
||
|
ConfigItem *item =
|
||
|
static_cast<ConfigItem *>(paramsListItems.getDrawable(i));
|
||
|
int16_t y = item->getY();
|
||
|
if (y + item->getHeight() > params.getHeight() || y < 0) {
|
||
|
continue;
|
||
|
}
|
||
|
if (y < firstY) {
|
||
|
firstY = y;
|
||
|
firstItem = item;
|
||
|
}
|
||
|
if (y > lastY) {
|
||
|
lastY = y;
|
||
|
lastItem = item;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int16_t firstVisible = firstItem->getType();
|
||
|
int16_t lastVisible = lastItem->getType();
|
||
|
if (lastVisible < firstVisible) {
|
||
|
Error_Handler();
|
||
|
}
|
||
|
int16_t numVisible = lastVisible - firstVisible + 1;
|
||
|
if (selectedParam >= firstVisible && selectedParam <= lastVisible) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
int16_t firstWanted;
|
||
|
if (selectedParam == 0 && previousSelected == ParamFieldType_COUNT - 1) {
|
||
|
firstWanted = 0;
|
||
|
} else if (selectedParam > previousSelected) {
|
||
|
firstWanted = selectedParam - numVisible + 1;
|
||
|
} else {
|
||
|
firstWanted = selectedParam;
|
||
|
}
|
||
|
if (firstWanted < 0) {
|
||
|
firstWanted = 0;
|
||
|
} else if (firstWanted > ParamFieldType_COUNT - 1) {
|
||
|
firstWanted = ParamFieldType_COUNT - 1;
|
||
|
}
|
||
|
params.animateToItem(firstWanted, 0);
|
||
|
}
|