fixed some issues in GameInfoDialog (see #297)

This commit is contained in:
thrust26 2018-06-02 12:23:21 +02:00
parent 77bd416735
commit 5f59d10c51
2 changed files with 98 additions and 91 deletions

View File

@ -39,9 +39,7 @@ GameInfoDialog::GameInfoDialog(
OSystem& osystem, DialogContainer& parent, const GUI::Font& font, OSystem& osystem, DialogContainer& parent, const GUI::Font& font,
GuiObject* boss) GuiObject* boss)
: Dialog(osystem, parent, font, "Game properties"), : Dialog(osystem, parent, font, "Game properties"),
CommandSender(boss), CommandSender(boss)
myPropertiesLoaded(false),
myDefaultsSelected(false)
{ {
const GUI::Font& ifont = instance().frameBuffer().infoFont(); const GUI::Font& ifont = instance().frameBuffer().infoFont();
const int lineHeight = font.getLineHeight(), const int lineHeight = font.getLineHeight(),
@ -175,33 +173,32 @@ GameInfoDialog::GameInfoDialog(
wid.clear(); wid.clear();
tabID = myTab->addTab("Controller"); tabID = myTab->addTab("Controller");
ctrls.clear();
VarList::push_back(ctrls, "Joystick", "JOYSTICK");
VarList::push_back(ctrls, "Paddles", "PADDLES");
VarList::push_back(ctrls, "Paddles_IAxis", "PADDLES_IAXIS");
VarList::push_back(ctrls, "Paddles_IDir", "PADDLES_IDIR");
VarList::push_back(ctrls, "Paddles_IAxDr", "PADDLES_IAXDR");
VarList::push_back(ctrls, "BoosterGrip", "BOOSTERGRIP");
VarList::push_back(ctrls, "Driving", "DRIVING");
VarList::push_back(ctrls, "Keyboard", "KEYBOARD");
VarList::push_back(ctrls, "AmigaMouse", "AMIGAMOUSE");
VarList::push_back(ctrls, "AtariMouse", "ATARIMOUSE");
VarList::push_back(ctrls, "Trakball", "TRAKBALL");
VarList::push_back(ctrls, "AtariVox", "ATARIVOX");
VarList::push_back(ctrls, "SaveKey", "SAVEKEY");
VarList::push_back(ctrls, "Sega Genesis", "GENESIS");
// VarList::push_back(ctrls, "KidVid", "KIDVID" );
VarList::push_back(ctrls, "MindLink", "MINDLINK");
ypos = vBorder; ypos = vBorder;
pwidth = font.getStringWidth("Paddles_IAxis"); pwidth = font.getStringWidth("Paddles_IAxis");
myP0Label = new StaticTextWidget(myTab, font, hSpace, ypos+1, "P0 controller "); myP0Label = new StaticTextWidget(myTab, font, hSpace, ypos+1, "P0 controller ");
ctrls.clear();
VarList::push_back(ctrls, "Joystick", "JOYSTICK" );
VarList::push_back(ctrls, "Paddles", "PADDLES" );
VarList::push_back(ctrls, "Paddles_IAxis", "PADDLES_IAXIS");
VarList::push_back(ctrls, "Paddles_IDir", "PADDLES_IDIR" );
VarList::push_back(ctrls, "Paddles_IAxDr", "PADDLES_IAXDR");
VarList::push_back(ctrls, "BoosterGrip", "BOOSTERGRIP" );
VarList::push_back(ctrls, "Driving", "DRIVING" );
VarList::push_back(ctrls, "Keyboard", "KEYBOARD" );
VarList::push_back(ctrls, "AmigaMouse", "AMIGAMOUSE" );
VarList::push_back(ctrls, "AtariMouse", "ATARIMOUSE" );
VarList::push_back(ctrls, "Trakball", "TRAKBALL" );
VarList::push_back(ctrls, "AtariVox", "ATARIVOX" );
VarList::push_back(ctrls, "SaveKey", "SAVEKEY" );
VarList::push_back(ctrls, "Sega Genesis", "GENESIS" );
// VarList::push_back(ctrls, "KidVid", "KIDVID" );
VarList::push_back(ctrls, "MindLink", "MINDLINK" );
myP0Controller = new PopUpWidget(myTab, font, myP0Label->getRight(), myP0Label->getTop()-1, myP0Controller = new PopUpWidget(myTab, font, myP0Label->getRight(), myP0Label->getTop()-1,
pwidth, lineHeight, ctrls, "", 0, kLeftCChanged); pwidth, lineHeight, ctrls, "", 0, kLeftCChanged);
wid.push_back(myP0Controller); wid.push_back(myP0Controller);
ypos += lineHeight + VGAP; ypos += lineHeight + VGAP;
pwidth = font.getStringWidth("Paddles_IAxis");
myP1Label = new StaticTextWidget(myTab, font, hSpace, ypos+1, "P1 controller "); myP1Label = new StaticTextWidget(myTab, font, hSpace, ypos+1, "P1 controller ");
myP1Controller = new PopUpWidget(myTab, font, myP1Label->getRight(), myP1Label->getTop()-1, myP1Controller = new PopUpWidget(myTab, font, myP1Label->getRight(), myP1Label->getTop()-1,
pwidth, lineHeight, ctrls, "", 0, kRightCChanged); pwidth, lineHeight, ctrls, "", 0, kRightCChanged);
@ -243,7 +240,6 @@ GameInfoDialog::GameInfoDialog(
VarList::push_back(items, "MindLink 0", MouseControl::MindLink0); VarList::push_back(items, "MindLink 0", MouseControl::MindLink0);
VarList::push_back(items, "MindLink 1", MouseControl::MindLink1); VarList::push_back(items, "MindLink 1", MouseControl::MindLink1);
lwidth = font.getStringWidth("X-Axis is ");
xpos += 20; xpos += 20;
ypos += lineHeight + VGAP; ypos += lineHeight + VGAP;
myMouseX = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight, items, myMouseX = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight, items,
@ -256,9 +252,8 @@ GameInfoDialog::GameInfoDialog(
wid.push_back(myMouseY); wid.push_back(myMouseY);
xpos = hSpace; ypos += lineHeight + VGAP; xpos = hSpace; ypos += lineHeight + VGAP;
lwidth = font.getStringWidth("Mouse axis range ");
myMouseRange = new SliderWidget(myTab, font, hSpace, ypos, myMouseRange = new SliderWidget(myTab, font, hSpace, ypos,
"Mouse axis range ", lwidth, 0, fontWidth * 4, "%"); "Mouse axes range ", 0, 0, fontWidth * 4, "%");
myMouseRange->setMinValue(1); myMouseRange->setMaxValue(100); myMouseRange->setMinValue(1); myMouseRange->setMaxValue(100);
wid.push_back(myMouseRange); wid.push_back(myMouseRange);
@ -334,71 +329,66 @@ GameInfoDialog::GameInfoDialog(
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GameInfoDialog::loadConfig() void GameInfoDialog::loadConfig()
{ {
myPropertiesLoaded = false;
myDefaultsSelected = false;
if(instance().hasConsole()) if(instance().hasConsole())
{ {
myGameProperties = instance().console().properties(); myGameProperties = instance().console().properties();
myPropertiesLoaded = true;
loadView();
} }
else else
{ {
const string& md5 = instance().launcher().selectedRomMD5(); const string& md5 = instance().launcher().selectedRomMD5();
if(md5 != "") instance().propSet(md5).getMD5(md5, myGameProperties);
{
instance().propSet(md5).getMD5(md5, myGameProperties);
myPropertiesLoaded = true;
loadView();
}
} }
updateControllerStates(); loadCartridgeProperties(myGameProperties);
loadConsoleProperties(myGameProperties);
loadControllerProperties(myGameProperties);
loadDisplayProperties(myGameProperties);
myTab->loadConfig();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GameInfoDialog::loadView() void GameInfoDialog::loadCartridgeProperties(Properties properties)
{ {
if(!myPropertiesLoaded) myName->setText(properties.get(Cartridge_Name));
return; myMD5->setText(properties.get(Cartridge_MD5));
myManufacturer->setText(properties.get(Cartridge_Manufacturer));
myModelNo->setText(properties.get(Cartridge_ModelNo));
myRarity->setText(properties.get(Cartridge_Rarity));
myNote->setText(properties.get(Cartridge_Note));
mySound->setState(properties.get(Cartridge_Sound) == "STEREO");
myType->setSelected(properties.get(Cartridge_Type), "AUTO");
}
// Cartridge properties // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
myName->setText(myGameProperties.get(Cartridge_Name)); void GameInfoDialog::loadConsoleProperties(Properties properties)
myMD5->setText(myGameProperties.get(Cartridge_MD5)); {
myManufacturer->setText(myGameProperties.get(Cartridge_Manufacturer)); myLeftDiffGroup->setSelected(properties.get(Console_LeftDifficulty) == "A" ? 0 : 1);
myModelNo->setText(myGameProperties.get(Cartridge_ModelNo)); myRightDiffGroup->setSelected(properties.get(Console_RightDifficulty) == "A" ? 0 : 1);
myRarity->setText(myGameProperties.get(Cartridge_Rarity)); myTVTypeGroup->setSelected(properties.get(Console_TelevisionType) == "BW" ? 1 : 0);
myNote->setText(myGameProperties.get(Cartridge_Note)); }
mySound->setState(myGameProperties.get(Cartridge_Sound) == "STEREO");
myType->setSelected(myGameProperties.get(Cartridge_Type), "AUTO");
// Console properties // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
myLeftDiffGroup->setSelected(myGameProperties.get(Console_LeftDifficulty) == "A" ? 0 : 1); void GameInfoDialog::loadControllerProperties(Properties properties)
myRightDiffGroup->setSelected(myGameProperties.get(Console_RightDifficulty) == "A" ? 0 : 1); {
myTVTypeGroup->setSelected(myGameProperties.get(Console_TelevisionType) == "BW" ? 1 : 0); myP0Controller->setSelected(properties.get(Controller_Left), "JOYSTICK");
myP1Controller->setSelected(properties.get(Controller_Right), "JOYSTICK");
// Controller properties mySwapPorts->setState(properties.get(Console_SwapPorts) == "YES");
myP0Controller->setSelected(myGameProperties.get(Controller_Left), "JOYSTICK"); mySwapPaddles->setState(properties.get(Controller_SwapPaddles) == "YES");
myP1Controller->setSelected(myGameProperties.get(Controller_Right), "JOYSTICK");
mySwapPorts->setState(myGameProperties.get(Console_SwapPorts) == "YES");
mySwapPaddles->setState(myGameProperties.get(Controller_SwapPaddles) == "YES");
// MouseAxis property (potentially contains 'range' information) // MouseAxis property (potentially contains 'range' information)
istringstream m_axis(myGameProperties.get(Controller_MouseAxis)); istringstream m_axis(properties.get(Controller_MouseAxis));
string m_control, m_range; string m_control, m_range;
m_axis >> m_control; m_axis >> m_control;
bool autoAxis = BSPF::equalsIgnoreCase(m_control, "AUTO"); bool autoAxis = BSPF::equalsIgnoreCase(m_control, "AUTO");
myMouseControl->setState(!autoAxis); myMouseControl->setState(!autoAxis);
if(autoAxis) if(autoAxis)
{ {
//myMouseControl->setSelectedIndex(0);
myMouseX->setSelectedIndex(0); myMouseX->setSelectedIndex(0);
myMouseY->setSelectedIndex(0); myMouseY->setSelectedIndex(0);
} }
else else
{ {
//myMouseControl->setSelectedIndex(1);
myMouseX->setSelected(m_control[0] - '0'); myMouseX->setSelected(m_control[0] - '0');
myMouseY->setSelected(m_control[1] - '0'); myMouseY->setSelected(m_control[1] - '0');
} }
@ -413,37 +403,37 @@ void GameInfoDialog::loadView()
myMouseRange->setValue(100); myMouseRange->setValue(100);
} }
// Display properties updateControllerStates();
myFormat->setSelected(myGameProperties.get(Display_Format), "AUTO"); }
const string& ystart = myGameProperties.get(Display_YStart); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GameInfoDialog::loadDisplayProperties(Properties properties)
{
myFormat->setSelected(properties.get(Display_Format), "AUTO");
const string& ystart = properties.get(Display_YStart);
myYStart->setValue(atoi(ystart.c_str())); myYStart->setValue(atoi(ystart.c_str()));
myYStart->setValueLabel(ystart == "0" ? "Auto" : ystart); myYStart->setValueLabel(ystart == "0" ? "Auto" : ystart);
myYStart->setValueUnit(ystart == "0" ? "" : "px"); myYStart->setValueUnit(ystart == "0" ? "" : "px");
const string& height = myGameProperties.get(Display_Height); const string& height = properties.get(Display_Height);
myHeight->setValue(atoi(height.c_str())); myHeight->setValue(atoi(height.c_str()));
myHeight->setValueLabel(height == "0" ? "Auto" : height); myHeight->setValueLabel(height == "0" ? "Auto" : height);
myHeight->setValueUnit(height == "0" ? "" : "px"); myHeight->setValueUnit(height == "0" ? "" : "px");
bool usePhosphor = myGameProperties.get(Display_Phosphor) == "YES"; bool usePhosphor = properties.get(Display_Phosphor) == "YES";
myPhosphor->setState(usePhosphor); myPhosphor->setState(usePhosphor);
myPPBlend->setEnabled(usePhosphor); myPPBlend->setEnabled(usePhosphor);
const string& blend = myGameProperties.get(Display_PPBlend); const string& blend = properties.get(Display_PPBlend);
myPPBlend->setValue(atoi(blend.c_str())); myPPBlend->setValue(atoi(blend.c_str()));
myPPBlend->setValueLabel(blend == "0" ? "Default" : blend); myPPBlend->setValueLabel(blend == "0" ? "Default" : blend);
myPPBlend->setValueUnit(blend == "0" ? "" : "%"); myPPBlend->setValueUnit(blend == "0" ? "" : "%");
myTab->loadConfig();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void GameInfoDialog::saveConfig() void GameInfoDialog::saveConfig()
{ {
if(!myPropertiesLoaded)
return;
// Cartridge properties // Cartridge properties
myGameProperties.set(Cartridge_Name, myName->getText()); myGameProperties.set(Cartridge_Name, myName->getText());
myGameProperties.set(Cartridge_Manufacturer, myManufacturer->getText()); myGameProperties.set(Cartridge_Manufacturer, myManufacturer->getText());
@ -485,13 +475,9 @@ void GameInfoDialog::saveConfig()
myGameProperties.set(Display_PPBlend, myPPBlend->getValueLabel() == "Default" ? "0" : myGameProperties.set(Display_PPBlend, myPPBlend->getValueLabel() == "Default" ? "0" :
myPPBlend->getValueLabel()); myPPBlend->getValueLabel());
// Determine whether to add or remove an entry from the properties set
const string& md5 = myGameProperties.get(Cartridge_MD5); const string& md5 = myGameProperties.get(Cartridge_MD5);
if(myDefaultsSelected) // always insert, doesn't hurt
instance().propSet(md5).removeMD5(myGameProperties.get(Cartridge_MD5)); instance().propSet(md5).insert(myGameProperties);
else
instance().propSet(md5).insert(myGameProperties);
instance().saveGamePropSet(myGameProperties.get(Cartridge_MD5)); instance().saveGamePropSet(myGameProperties.get(Cartridge_MD5));
// In any event, inform the Console // In any event, inform the Console
@ -503,12 +489,32 @@ void GameInfoDialog::saveConfig()
void GameInfoDialog::setDefaults() void GameInfoDialog::setDefaults()
{ {
// Load the default properties // Load the default properties
Properties defaultProperties;
string md5 = myGameProperties.get(Cartridge_MD5); string md5 = myGameProperties.get(Cartridge_MD5);
instance().propSet(md5).getMD5(md5, myGameProperties, true);
// Reload the current dialog instance().propSet(md5).getMD5(md5, defaultProperties, true);
loadView();
myDefaultsSelected = true; switch(myTab->getActiveTab())
{
case 0: // Cartridge properties
loadCartridgeProperties(defaultProperties);
break;
case 1: // Console properties
loadConsoleProperties(defaultProperties);
break;
case 2: // Controller properties
loadControllerProperties(defaultProperties);
break;
case 3: // Display properties
loadDisplayProperties(defaultProperties);
break;
default: // make the complier happy
break;
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -643,7 +649,6 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd,
case kMCtrlChanged: case kMCtrlChanged:
{ {
//bool state = myMouseControl->getSelectedTag() != "AUTO";
bool state = myMouseControl->getState(); bool state = myMouseControl->getState();
myMouseX->setEnabled(state); myMouseX->setEnabled(state);
myMouseY->setEnabled(state); myMouseY->setEnabled(state);

View File

@ -44,7 +44,15 @@ class GameInfoDialog : public Dialog, public CommandSender
void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void setDefaults() override; void setDefaults() override;
void loadView();
// load the properties for the 'Cartridge' tab
void loadCartridgeProperties(Properties properties);
// load the properties for the 'Console' tab
void loadConsoleProperties(Properties properties);
// load the properties for the 'Controller' tab
void loadControllerProperties(Properties properties);
// load the properties for the 'Display' tab
void loadDisplayProperties(Properties properties);
void updateControllerStates(); void updateControllerStates();
void eraseEEPROM(); void eraseEEPROM();
@ -103,12 +111,6 @@ class GameInfoDialog : public Dialog, public CommandSender
// Game properties for currently loaded ROM // Game properties for currently loaded ROM
Properties myGameProperties; Properties myGameProperties;
// Indicates that we've got a valid properties entry
bool myPropertiesLoaded;
// Indicates that the default properties have been loaded
bool myDefaultsSelected;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
GameInfoDialog() = delete; GameInfoDialog() = delete;