From 27e3d87844476e9324371d84e09d6d3ae17a1b4a Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Thu, 4 Aug 2022 22:56:12 +0200 Subject: [PATCH] added disabling of some Game properties widgets for multi carts added ROM name to Game properties title --- src/emucore/Bankswitch.hxx | 3 +- src/gui/GameInfoDialog.cxx | 85 +++++++++++++++++++++++++++++--------- src/gui/GameInfoDialog.hxx | 5 ++- src/gui/TabWidget.cxx | 27 ++++++------ src/gui/TabWidget.hxx | 2 +- 5 files changed, 87 insertions(+), 35 deletions(-) diff --git a/src/emucore/Bankswitch.hxx b/src/emucore/Bankswitch.hxx index 1fa7c4ca9..31be35f50 100644 --- a/src/emucore/Bankswitch.hxx +++ b/src/emucore/Bankswitch.hxx @@ -48,7 +48,8 @@ class Bankswitch #ifdef CUSTOM_ARM _CUSTOM, #endif - NumSchemes + NumSchemes, + NumMulti = _128IN1 - _2IN1 + 1, }; #ifdef GUI_SUPPORT diff --git a/src/gui/GameInfoDialog.cxx b/src/gui/GameInfoDialog.cxx index 08a2e07bd..50008bf0c 100644 --- a/src/gui/GameInfoDialog.cxx +++ b/src/gui/GameInfoDialog.cxx @@ -112,39 +112,36 @@ void GameInfoDialog::addEmulationTab() VGAP = Dialog::vGap(); WidgetArray wid; VariantList items; - StaticTextWidget* t = nullptr; // 1) Emulation properties int tabID = myTab->addTab("Emulation", TabWidget::AUTO_WIDTH); int ypos = VBORDER; - t = new StaticTextWidget(myTab, _font, HBORDER, ypos + 1, "Type (*) "); + myBSTypeLabel = new StaticTextWidget(myTab, _font, HBORDER, ypos + 1, "Type (*) "); int pwidth = _font.getStringWidth("CM (SpectraVideo CompuMate)"); items.clear(); - myBSType = new PopUpWidget(myTab, _font, t->getRight() + fontWidth, ypos, - pwidth, lineHeight, items); + myBSType = new PopUpWidget(myTab, _font, myBSTypeLabel->getRight() + fontWidth, ypos, + pwidth, lineHeight, items, "", 0, kBSTypeChanged); wid.push_back(myBSType); - myBSFilter = new CheckboxWidget(myTab, _font, myBSType->getRight()+ fontWidth, ypos + 1, + myBSFilter = new CheckboxWidget(myTab, _font, myBSType->getRight() + fontWidth, ypos + 1, "Filter", kBSFilterChanged); myBSFilter->setToolTip("Enable to filter types by ROM size"); wid.push_back(myBSFilter); ypos += lineHeight + VGAP; - myTypeDetected = new StaticTextWidget(myTab, ifont, t->getRight() + fontWidth, ypos, + myTypeDetected = new StaticTextWidget(myTab, ifont, myBSTypeLabel->getRight() + fontWidth, ypos, "CM (SpectraVideo CompuMate) detected"); ypos += ifont.getLineHeight() + VGAP; // Start bank - myStartBankLabel = new StaticTextWidget(myTab, _font, HBORDER, ypos + 1, "Start bank (*) "); items.clear(); - myStartBank = new PopUpWidget(myTab, _font, myStartBankLabel->getRight(), ypos, - _font.getStringWidth("AUTO"), lineHeight, items); + myStartBank = new PopUpWidget(myTab, _font, HBORDER, ypos, + _font.getStringWidth("AUTO"), lineHeight, items, "Start bank (*) "); wid.push_back(myStartBank); ypos += lineHeight + VGAP * 4; pwidth = _font.getStringWidth("Auto-detect"); - t = new StaticTextWidget(myTab, _font, HBORDER, ypos + 1, "TV format "); items.clear(); VarList::push_back(items, "Auto-detect", "AUTO"); VarList::push_back(items, "NTSC", "NTSC"); @@ -153,8 +150,8 @@ void GameInfoDialog::addEmulationTab() VarList::push_back(items, "NTSC-50", "NTSC50"); VarList::push_back(items, "PAL-60", "PAL60"); VarList::push_back(items, "SECAM-60", "SECAM60"); - myFormat = new PopUpWidget(myTab, _font, t->getRight(), ypos, - pwidth, lineHeight, items); + myFormat = new PopUpWidget(myTab, _font, HBORDER, ypos, + pwidth, lineHeight, items, "TV format "); myFormat->setToolTip(Event::FormatDecrease, Event::FormatIncrease); wid.push_back(myFormat); @@ -178,8 +175,7 @@ void GameInfoDialog::addEmulationTab() wid.push_back(myPPBlend); ypos += lineHeight + VGAP; - t = new StaticTextWidget(myTab, _font, HBORDER, ypos + 1, "V-Center "); - myVCenter = new SliderWidget(myTab, _font, t->getRight(), ypos, "", + myVCenter = new SliderWidget(myTab, _font, HBORDER, ypos, "V-Center ", 0, kVCenterChanged, 7 * fontWidth, "px", 0, true); myVCenter->setMinValue(TIAConstants::minVcenter); @@ -709,6 +705,11 @@ void GameInfoDialog::loadConfig() myGameFile = FSNode(instance().launcher().selectedRom()); } + string title = "Game properties - " + myGameProperties.get(PropType::Cart_Name); + if(_font.getStringWidth(title) > getWidth() - fontWidth() * 6) + title = title.substr(0, getWidth() / fontWidth() - 7) + ELLIPSIS; + setTitle(title); + loadEmulationProperties(myGameProperties); loadConsoleProperties(myGameProperties); loadControllerProperties(myGameProperties); @@ -753,6 +754,7 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) } } myTypeDetected->setLabel(bsDetected); + updateMultiCart(); // Start bank VarList::push_back(items, "Auto", "AUTO"); @@ -762,14 +764,12 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) for(uInt16 i = 0; i < numBanks; ++i) VarList::push_back(items, i, i); - myStartBank->setEnabled(true); } else { const string& startBank = props.get(PropType::Cart_StartBank); VarList::push_back(items, startBank, startBank); - myStartBank->setEnabled(false); } myStartBank->addItems(items); myStartBank->setSelected(props.get(PropType::Cart_StartBank), "AUTO"); @@ -792,12 +792,10 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) const bool alwaysPhosphor = instance().settings().getString("tv.phosphor") == "always"; const bool usePhosphor = props.get(PropType::Display_Phosphor) == "YES"; myPhosphor->setState(usePhosphor); - myPhosphor->setEnabled(!alwaysPhosphor); if (alwaysPhosphor) myPhosphor->setLabel("Phosphor (enabled for all ROMs)"); else myPhosphor->setLabel("Phosphor"); - myPPBlend->setEnabled(!alwaysPhosphor && usePhosphor); const string& blend = props.get(PropType::Display_PPBlend); myPPBlend->setValue(stringToInt(blend)); @@ -809,8 +807,6 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props) myVCenter->setValueUnit(vcenter ? "px" : ""); mySound->setState(props.get(PropType::Cart_Sound) == "STEREO"); - // if stereo is always enabled, disable game specific stereo setting - mySound->setEnabled(!instance().audioSettings().stereo()); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1125,6 +1121,51 @@ void GameInfoDialog::setDefaults() } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void GameInfoDialog::updateMultiCart() +{ + const std::array(Bankswitch::Type::NumMulti)> MultiCart + = { "2IN1", "4IN1", "8IN1", "16IN1", "32IN1", "64IN1", "128IN1" }; + const string& selected = myBSType->getSelectedTag().toString(); + const string& detected = myTypeDetected->getLabel(); + + bool isMulti = false; + bool isInMulti = false; + for each(auto entry in MultiCart) + { + if(entry == selected) + { + isMulti = true; + break; + } + if(detected.find(entry + " [") != string::npos) + { + isInMulti = true; + break; + } + } + + // en/disable Emulation tab widgets + myBSTypeLabel->setEnabled(!isInMulti); + myBSType->setEnabled(!isInMulti); + myBSFilter->setEnabled(!isInMulti); + myStartBank->setEnabled(!isMulti && instance().hasConsole()); + myFormat->setEnabled(!isMulti); + + // if phosphor is always enabled, disable game specific phosphor settings + const bool alwaysPhosphor = isMulti || instance().settings().getString("tv.phosphor") == "always"; + myPhosphor->setEnabled(!alwaysPhosphor); + myPPBlend->setEnabled(!alwaysPhosphor && myPhosphor->getState()); + + myVCenter->setEnabled(!isMulti); + // if stereo is always enabled, disable game specific stereo setting + mySound->setEnabled(!instance().audioSettings().stereo() && !isMulti); + + myTab->enableTab(1, !isMulti); // en/disable Console tab + myTab->enableTab(2, !isMulti); // en/disable Controller tab + myTab->enableTab(4, !isMulti); // en/disable Highscore tab +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void GameInfoDialog::updateBSTypes() { @@ -1476,6 +1517,10 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd, eraseEEPROM(); break; + case kBSTypeChanged: + updateMultiCart(); + break; + case kBSFilterChanged: updateBSTypes(); break; diff --git a/src/gui/GameInfoDialog.hxx b/src/gui/GameInfoDialog.hxx index 6e04c6242..f470afc2e 100644 --- a/src/gui/GameInfoDialog.hxx +++ b/src/gui/GameInfoDialog.hxx @@ -68,6 +68,8 @@ class GameInfoDialog : public Dialog, public CommandSender // save properties from all tabs into the local properties object void saveProperties(); + // en/disable tabs and widgets depending on multicart bankswitch type selected + void updateMultiCart(); // update 'BS Type' list void updateBSTypes(); // update 'Controller' tab widgets @@ -87,10 +89,10 @@ class GameInfoDialog : public Dialog, public CommandSender TabWidget* myTab{nullptr}; // Emulation properties + StaticTextWidget* myBSTypeLabel{nullptr}; PopUpWidget* myBSType{nullptr}; CheckboxWidget* myBSFilter{nullptr}; StaticTextWidget* myTypeDetected{nullptr}; - StaticTextWidget* myStartBankLabel{nullptr}; PopUpWidget* myStartBank{nullptr}; PopUpWidget* myFormat{nullptr}; StaticTextWidget* myFormatDetected{nullptr}; @@ -176,6 +178,7 @@ class GameInfoDialog : public Dialog, public CommandSender EditTextWidget* myHighScoreNotes{nullptr}; enum { + kBSTypeChanged = 'Btch', kBSFilterChanged = 'Bfch', kVCenterChanged = 'Vcch', kPhosphorChanged = 'PPch', diff --git a/src/gui/TabWidget.cxx b/src/gui/TabWidget.cxx index 47dd2d89b..66c604f2a 100644 --- a/src/gui/TabWidget.cxx +++ b/src/gui/TabWidget.cxx @@ -121,16 +121,15 @@ void TabWidget::setActiveTab(int tabID, bool show) sendCommand(TabWidget::kTabChangedCmd, _activeTab, _id); } -#if 0 // FIXME // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void TabWidget::disableTab(int tabID) +void TabWidget::enableTab(int tabID, bool enable) { assert(0 <= tabID && tabID < int(_tabs.size())); - _tabs[tabID].enabled = false; - // TODO - also disable all widgets belonging to this tab + _tabs[tabID].enabled = enable; + // Note: We do not have to disable the widgets because the tab is disabled + // and therefore cannot be selected. } -#endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TabWidget::updateActiveTab() @@ -163,15 +162,19 @@ void TabWidget::cycleTab(int direction) if(direction == -1) // Go to the previous tab, wrap around at beginning { - tabID--; - if(tabID == -1) - tabID = static_cast(_tabs.size()) - 1; + do { + tabID--; + if(tabID == -1) + tabID = static_cast(_tabs.size()) - 1; + } while(!_tabs[tabID].enabled); } else if(direction == 1) // Go to the next tab, wrap around at end { - tabID++; - if(tabID == static_cast(_tabs.size())) - tabID = 0; + do { + tabID++; + if(tabID == static_cast(_tabs.size())) + tabID = 0; + } while(!_tabs[tabID].enabled); } // Finally, select the active tab @@ -222,7 +225,7 @@ void TabWidget::handleMouseDown(int x, int y, MouseButton b, int clickCount) } // If a tab was clicked, switch to that pane - if (tabID >= 0) + if (tabID >= 0 && _tabs[tabID].enabled) { setActiveTab(tabID, true); updateActiveTab(); diff --git a/src/gui/TabWidget.hxx b/src/gui/TabWidget.hxx index 327870e5a..21b692edf 100644 --- a/src/gui/TabWidget.hxx +++ b/src/gui/TabWidget.hxx @@ -48,7 +48,7 @@ class TabWidget : public Widget, public CommandSender //void removeTab(int tabID); // Setting the active tab: void setActiveTab(int tabID, bool show = false); -// void disableTab(int tabID); + void enableTab(int tabID, bool enable = true); void activateTabs(); void cycleTab(int direction); // setActiveTab changes the value of _firstWidget. This means Widgets added afterwards