mirror of https://github.com/stella-emu/stella.git
auto detect controller in GameInfoDialog when started from Launcher
This commit is contained in:
parent
9fba356d8b
commit
e81326eefb
|
@ -24,6 +24,7 @@
|
||||||
#include "RadioButtonWidget.hxx"
|
#include "RadioButtonWidget.hxx"
|
||||||
#include "Launcher.hxx"
|
#include "Launcher.hxx"
|
||||||
#include "OSystem.hxx"
|
#include "OSystem.hxx"
|
||||||
|
#include "ControllerDetector.hxx"
|
||||||
#include "PopUpWidget.hxx"
|
#include "PopUpWidget.hxx"
|
||||||
#include "Props.hxx"
|
#include "Props.hxx"
|
||||||
#include "PropsSet.hxx"
|
#include "PropsSet.hxx"
|
||||||
|
@ -415,28 +416,60 @@ void GameInfoDialog::loadConsoleProperties(const Properties& props)
|
||||||
void GameInfoDialog::loadControllerProperties(const Properties& props)
|
void GameInfoDialog::loadControllerProperties(const Properties& props)
|
||||||
{
|
{
|
||||||
bool swapPorts = props.get(Console_SwapPorts) == "YES";
|
bool swapPorts = props.get(Console_SwapPorts) == "YES";
|
||||||
|
bool autoDetect = false;
|
||||||
|
BytePtr image;
|
||||||
|
string md5 = props.get(Cartridge_MD5);
|
||||||
|
uInt32 size = 0;
|
||||||
|
const FilesystemNode& node = FilesystemNode(instance().launcher().selectedRom());
|
||||||
|
|
||||||
myLeftPort->setSelected(props.get(Controller_Left), "AUTO");
|
// try to load the image for auto detection
|
||||||
if(instance().hasConsole() && myLeftPort->getSelectedTag().toString() == "AUTO")
|
if(!instance().hasConsole() &&
|
||||||
{
|
node.exists() && !node.isDirectory() && (image = instance().openROM(node, md5, size)) != nullptr)
|
||||||
myLeftPortDetected->setLabel((!swapPorts
|
autoDetect = true;
|
||||||
? instance().console().leftController().name()
|
|
||||||
: instance().console().rightController().name())
|
|
||||||
+ " detected");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
myLeftPortDetected->setLabel("");
|
|
||||||
|
|
||||||
myRightPort->setSelected(props.get(Controller_Right), "AUTO");
|
string label = "";
|
||||||
if(instance().hasConsole() && myRightPort->getSelectedTag().toString() == "AUTO")
|
string controller = props.get(Controller_Left);
|
||||||
|
|
||||||
|
myLeftPort->setSelected(controller, "AUTO");
|
||||||
|
if(myLeftPort->getSelectedTag().toString() == "AUTO")
|
||||||
{
|
{
|
||||||
myRightPortDetected->setLabel((!swapPorts
|
if(instance().hasConsole())
|
||||||
? instance().console().rightController().name()
|
{
|
||||||
: instance().console().leftController().name())
|
label = (!swapPorts ? instance().console().leftController().name()
|
||||||
+ " detected");
|
: instance().console().rightController().name())
|
||||||
|
+ " detected";
|
||||||
|
}
|
||||||
|
else if(autoDetect)
|
||||||
|
{
|
||||||
|
controller = ControllerDetector::detect(image.get(), size, controller,
|
||||||
|
!swapPorts ? Controller::Jack::Left : Controller::Jack::Right,
|
||||||
|
instance().settings());
|
||||||
|
label = getControllerName(controller) + " detected";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
myLeftPortDetected->setLabel(label);
|
||||||
myRightPortDetected->setLabel("");
|
|
||||||
|
label = "";
|
||||||
|
controller = props.get(Controller_Right);
|
||||||
|
|
||||||
|
myRightPort->setSelected(controller, "AUTO");
|
||||||
|
if(myRightPort->getSelectedTag().toString() == "AUTO")
|
||||||
|
{
|
||||||
|
if(instance().hasConsole())
|
||||||
|
{
|
||||||
|
label = (!swapPorts ? instance().console().rightController().name()
|
||||||
|
: instance().console().leftController().name())
|
||||||
|
+ " detected";
|
||||||
|
}
|
||||||
|
else if(autoDetect)
|
||||||
|
{
|
||||||
|
controller = ControllerDetector::detect(image.get(), size, controller,
|
||||||
|
!swapPorts ? Controller::Jack::Right : Controller::Jack::Left,
|
||||||
|
instance().settings());
|
||||||
|
label = getControllerName(controller) + " detected";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myRightPortDetected->setLabel(label);
|
||||||
|
|
||||||
mySwapPorts->setState(props.get(Console_SwapPorts) == "YES");
|
mySwapPorts->setState(props.get(Console_SwapPorts) == "YES");
|
||||||
mySwapPaddles->setState(props.get(Controller_SwapPaddles) == "YES");
|
mySwapPaddles->setState(props.get(Controller_SwapPaddles) == "YES");
|
||||||
|
@ -618,6 +651,29 @@ void GameInfoDialog::updateControllerStates()
|
||||||
myEraseEEPROMInfo->setEnabled(enableEEEraseButton);
|
myEraseEEPROMInfo->setEnabled(enableEEEraseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
const string GameInfoDialog::getControllerName(const string& type)
|
||||||
|
{
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "JOYSTICK"))
|
||||||
|
return "Joystick";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "SAVEKEY"))
|
||||||
|
return "SaveKey";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "TRAKBALL"))
|
||||||
|
return "TrakBall";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "ATA RIMOUSE"))
|
||||||
|
return "AtariMouse";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "AMIGAMOUSE"))
|
||||||
|
return "AmigaMouse";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "KEYBOARD"))
|
||||||
|
return "Keyboard";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "GENESIS"))
|
||||||
|
return "Genesis";
|
||||||
|
if(BSPF::equalsIgnoreCase(type, "PADDLES"))
|
||||||
|
return "Paddles";
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void GameInfoDialog::eraseEEPROM()
|
void GameInfoDialog::eraseEEPROM()
|
||||||
{
|
{
|
||||||
|
@ -698,4 +754,4 @@ void GameInfoDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
Dialog::handleCommand(sender, cmd, data, 0);
|
Dialog::handleCommand(sender, cmd, data, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -208,6 +208,16 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
|
||||||
myAllFiles->setState(!onlyROMs);
|
myAllFiles->setState(!onlyROMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
const string& LauncherDialog::selectedRom()
|
||||||
|
{
|
||||||
|
int item = myList->getSelected();
|
||||||
|
if(item < 0)
|
||||||
|
return EmptyString;
|
||||||
|
|
||||||
|
return myGameList->path(item);
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
const string& LauncherDialog::selectedRomMD5()
|
const string& LauncherDialog::selectedRomMD5()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue