Added Lua control window.
This commit is contained in:
parent
188320147a
commit
122473b575
|
@ -390,6 +390,7 @@ set(SRC_DRIVERS_SDL
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/HotKeyConf.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/HotKeyConf.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/PaletteConf.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/PaletteConf.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/GuiConf.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/GuiConf.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/LuaControl.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleVideoConf.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/ConsoleSoundConf.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/AboutWindow.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/drivers/Qt/AboutWindow.cpp
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "Qt/HotKeyConf.h"
|
#include "Qt/HotKeyConf.h"
|
||||||
#include "Qt/PaletteConf.h"
|
#include "Qt/PaletteConf.h"
|
||||||
#include "Qt/GuiConf.h"
|
#include "Qt/GuiConf.h"
|
||||||
|
#include "Qt/LuaControl.h"
|
||||||
#include "Qt/ConsoleSoundConf.h"
|
#include "Qt/ConsoleSoundConf.h"
|
||||||
#include "Qt/ConsoleVideoConf.h"
|
#include "Qt/ConsoleVideoConf.h"
|
||||||
#include "Qt/AboutWindow.h"
|
#include "Qt/AboutWindow.h"
|
||||||
|
@ -829,62 +830,18 @@ void consoleWin_t::takeScreenShot(void)
|
||||||
void consoleWin_t::loadLua(void)
|
void consoleWin_t::loadLua(void)
|
||||||
{
|
{
|
||||||
#ifdef _S9XLUA_H
|
#ifdef _S9XLUA_H
|
||||||
int ret, useNativeFileDialogVal;
|
LuaControlDialog_t *luaCtrlWin;
|
||||||
QString filename;
|
|
||||||
std::string last;
|
|
||||||
char dir[512];
|
|
||||||
QFileDialog dialog(this, tr("Open LUA Script") );
|
|
||||||
|
|
||||||
dialog.setFileMode(QFileDialog::ExistingFile);
|
//printf("Open Lua Control Window\n");
|
||||||
|
|
||||||
|
luaCtrlWin = new LuaControlDialog_t(this);
|
||||||
|
|
||||||
|
luaCtrlWin->show();
|
||||||
|
luaCtrlWin->exec();
|
||||||
|
|
||||||
dialog.setNameFilter(tr("LUA Scripts (*.lua *.LUA) ;; All files (*)"));
|
delete luaCtrlWin;
|
||||||
|
|
||||||
dialog.setViewMode(QFileDialog::List);
|
//printf("Lua Control Window Destroyed\n");
|
||||||
|
|
||||||
g_config->getOption ("SDL.LastLoadLua", &last );
|
|
||||||
|
|
||||||
if ( last.size() == 0 )
|
|
||||||
{
|
|
||||||
last.assign( "/usr/share/fceux/luaScripts" );
|
|
||||||
}
|
|
||||||
|
|
||||||
getDirFromFile( last.c_str(), dir );
|
|
||||||
|
|
||||||
dialog.setDirectory( tr(dir) );
|
|
||||||
|
|
||||||
// Check config option to use native file dialog or not
|
|
||||||
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
|
||||||
|
|
||||||
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
|
|
||||||
|
|
||||||
dialog.show();
|
|
||||||
ret = dialog.exec();
|
|
||||||
|
|
||||||
if ( ret )
|
|
||||||
{
|
|
||||||
QStringList fileList;
|
|
||||||
fileList = dialog.selectedFiles();
|
|
||||||
|
|
||||||
if ( fileList.size() > 0 )
|
|
||||||
{
|
|
||||||
filename = fileList[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( filename.isNull() )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qDebug() << "selected file path : " << filename.toUtf8();
|
|
||||||
|
|
||||||
g_config->setOption ("SDL.LastLoadLua", filename.toStdString().c_str() );
|
|
||||||
|
|
||||||
fceuWrapperLock();
|
|
||||||
if ( 0 == FCEU_LoadLuaCode( filename.toStdString().c_str() ) )
|
|
||||||
{
|
|
||||||
printf("Error: Could not open the selected lua script: '%s'\n", filename.toStdString().c_str() );
|
|
||||||
}
|
|
||||||
fceuWrapperUnLock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,246 @@
|
||||||
|
// LuaControl.cpp
|
||||||
|
//
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
#include "../../fceu.h"
|
||||||
|
|
||||||
|
#ifdef _S9XLUA_H
|
||||||
|
#include "../../fceulua.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Qt/LuaControl.h"
|
||||||
|
#include "Qt/main.h"
|
||||||
|
#include "Qt/input.h"
|
||||||
|
#include "Qt/config.h"
|
||||||
|
#include "Qt/keyscan.h"
|
||||||
|
#include "Qt/fceuWrapper.h"
|
||||||
|
|
||||||
|
static bool luaScriptRunning = false;
|
||||||
|
|
||||||
|
static std::list <LuaControlDialog_t*> winList;
|
||||||
|
//----------------------------------------------------
|
||||||
|
LuaControlDialog_t::LuaControlDialog_t(QWidget *parent)
|
||||||
|
: QDialog( parent )
|
||||||
|
{
|
||||||
|
QVBoxLayout *mainLayout;
|
||||||
|
QHBoxLayout *hbox;
|
||||||
|
QLabel *lbl;
|
||||||
|
std::string filename;
|
||||||
|
|
||||||
|
resize( 512, 512 );
|
||||||
|
|
||||||
|
setWindowTitle( tr("Lua Script Control") );
|
||||||
|
|
||||||
|
mainLayout = new QVBoxLayout();
|
||||||
|
|
||||||
|
lbl = new QLabel( tr("Script File:") );
|
||||||
|
|
||||||
|
scriptPath = new QLineEdit();
|
||||||
|
scriptArgs = new QLineEdit();
|
||||||
|
|
||||||
|
g_config->getOption ("SDL.LastLoadLua", &filename );
|
||||||
|
|
||||||
|
scriptPath->setText( filename.c_str() );
|
||||||
|
|
||||||
|
luaOutput = new QTextEdit();
|
||||||
|
luaOutput->setReadOnly(true);
|
||||||
|
|
||||||
|
hbox = new QHBoxLayout();
|
||||||
|
|
||||||
|
browseButton = new QPushButton( tr("Browse") );
|
||||||
|
stopButton = new QPushButton( tr("Stop") );
|
||||||
|
|
||||||
|
if ( luaScriptRunning )
|
||||||
|
{
|
||||||
|
startButton = new QPushButton( tr("Restart") );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startButton = new QPushButton( tr("Start") );
|
||||||
|
}
|
||||||
|
|
||||||
|
stopButton->setEnabled( luaScriptRunning );
|
||||||
|
|
||||||
|
connect(browseButton , SIGNAL(clicked()), this, SLOT(openLuaScriptFile(void)) );
|
||||||
|
connect(stopButton , SIGNAL(clicked()), this, SLOT(stopLuaScript(void)) );
|
||||||
|
connect(startButton , SIGNAL(clicked()), this, SLOT(startLuaScript(void)) );
|
||||||
|
|
||||||
|
hbox->addWidget( browseButton );
|
||||||
|
hbox->addWidget( stopButton );
|
||||||
|
hbox->addWidget( startButton );
|
||||||
|
|
||||||
|
mainLayout->addWidget( lbl );
|
||||||
|
mainLayout->addWidget( scriptPath );
|
||||||
|
mainLayout->addLayout( hbox );
|
||||||
|
|
||||||
|
hbox = new QHBoxLayout();
|
||||||
|
lbl = new QLabel( tr("Arguments:") );
|
||||||
|
|
||||||
|
hbox->addWidget( lbl );
|
||||||
|
hbox->addWidget( scriptArgs );
|
||||||
|
|
||||||
|
mainLayout->addLayout( hbox );
|
||||||
|
|
||||||
|
lbl = new QLabel( tr("Output Console:") );
|
||||||
|
mainLayout->addWidget( lbl );
|
||||||
|
mainLayout->addWidget( luaOutput );
|
||||||
|
|
||||||
|
//connect(useNativeFileDialog , SIGNAL(stateChanged(int)), this, SLOT(useNativeFileDialogChanged(int)) );
|
||||||
|
|
||||||
|
setLayout( mainLayout );
|
||||||
|
|
||||||
|
winList.push_back( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------
|
||||||
|
LuaControlDialog_t::~LuaControlDialog_t(void)
|
||||||
|
{
|
||||||
|
std::list <LuaControlDialog_t*>::iterator it;
|
||||||
|
|
||||||
|
for (it = winList.begin(); it != winList.end(); it++)
|
||||||
|
{
|
||||||
|
if ( (*it) == this )
|
||||||
|
{
|
||||||
|
winList.erase(it);
|
||||||
|
//printf("Removing Lua Window\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void LuaControlDialog_t::closeWindow(void)
|
||||||
|
{
|
||||||
|
//printf("Close Window\n");
|
||||||
|
done(0);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void LuaControlDialog_t::openLuaScriptFile(void)
|
||||||
|
{
|
||||||
|
#ifdef _S9XLUA_H
|
||||||
|
int ret, useNativeFileDialogVal;
|
||||||
|
QString filename;
|
||||||
|
std::string last;
|
||||||
|
//char dir[512];
|
||||||
|
QFileDialog dialog(this, tr("Open LUA Script") );
|
||||||
|
|
||||||
|
dialog.setFileMode(QFileDialog::ExistingFile);
|
||||||
|
|
||||||
|
dialog.setNameFilter(tr("LUA Scripts (*.lua *.LUA) ;; All files (*)"));
|
||||||
|
|
||||||
|
dialog.setViewMode(QFileDialog::List);
|
||||||
|
|
||||||
|
g_config->getOption ("SDL.LastLoadLua", &last );
|
||||||
|
|
||||||
|
if ( last.size() == 0 )
|
||||||
|
{
|
||||||
|
last.assign( "/usr/share/fceux/luaScripts" );
|
||||||
|
}
|
||||||
|
|
||||||
|
//getDirFromFile( last.c_str(), dir );
|
||||||
|
|
||||||
|
//dialog.setDirectory( tr(dir) );
|
||||||
|
|
||||||
|
// Check config option to use native file dialog or not
|
||||||
|
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
|
||||||
|
|
||||||
|
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
ret = dialog.exec();
|
||||||
|
|
||||||
|
if ( ret )
|
||||||
|
{
|
||||||
|
QStringList fileList;
|
||||||
|
fileList = dialog.selectedFiles();
|
||||||
|
|
||||||
|
if ( fileList.size() > 0 )
|
||||||
|
{
|
||||||
|
filename = fileList[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( filename.isNull() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug() << "selected file path : " << filename.toUtf8();
|
||||||
|
|
||||||
|
g_config->setOption ("SDL.LastLoadLua", filename.toStdString().c_str() );
|
||||||
|
|
||||||
|
scriptPath->setText( filename.toStdString().c_str() );
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void LuaControlDialog_t::startLuaScript(void)
|
||||||
|
{
|
||||||
|
#ifdef _S9XLUA_H
|
||||||
|
fceuWrapperLock();
|
||||||
|
if ( 0 == FCEU_LoadLuaCode( scriptPath->text().toStdString().c_str(), scriptArgs->text().toStdString().c_str() ) )
|
||||||
|
{
|
||||||
|
printf("Error: Could not open the selected lua script: '%s'\n", scriptPath->text().toStdString().c_str() );
|
||||||
|
}
|
||||||
|
fceuWrapperUnLock();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void LuaControlDialog_t::stopLuaScript(void)
|
||||||
|
{
|
||||||
|
#ifdef _S9XLUA_H
|
||||||
|
fceuWrapperLock();
|
||||||
|
FCEU_LuaStop();
|
||||||
|
fceuWrapperUnLock();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void LuaControlDialog_t::refreshState(void)
|
||||||
|
{
|
||||||
|
if ( luaScriptRunning )
|
||||||
|
{
|
||||||
|
stopButton->setEnabled( true );
|
||||||
|
startButton->setText( tr("Restart") );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stopButton->setEnabled( false );
|
||||||
|
startButton->setText( tr("Start") );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void updateLuaWindows( void )
|
||||||
|
{
|
||||||
|
std::list <LuaControlDialog_t*>::iterator it;
|
||||||
|
|
||||||
|
for (it = winList.begin(); it != winList.end(); it++)
|
||||||
|
{
|
||||||
|
(*it)->refreshState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void WinLuaOnStart(intptr_t hDlgAsInt)
|
||||||
|
{
|
||||||
|
luaScriptRunning = true;
|
||||||
|
|
||||||
|
printf("Lua Script Running: %i \n", luaScriptRunning );
|
||||||
|
|
||||||
|
updateLuaWindows();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void WinLuaOnStop(intptr_t hDlgAsInt)
|
||||||
|
{
|
||||||
|
luaScriptRunning = false;
|
||||||
|
|
||||||
|
printf("Lua Script Running: %i \n", luaScriptRunning );
|
||||||
|
|
||||||
|
updateLuaWindows();
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
||||||
|
void PrintToWindowConsole(intptr_t hDlgAsInt, const char* str)
|
||||||
|
{
|
||||||
|
printf("%s\n", str );
|
||||||
|
|
||||||
|
}
|
||||||
|
//----------------------------------------------------
|
|
@ -0,0 +1,47 @@
|
||||||
|
// LuaControl.h
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
|
#include "Qt/main.h"
|
||||||
|
|
||||||
|
class LuaControlDialog_t : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
LuaControlDialog_t(QWidget *parent = 0);
|
||||||
|
~LuaControlDialog_t(void);
|
||||||
|
|
||||||
|
void refreshState(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QLineEdit *scriptPath;
|
||||||
|
QLineEdit *scriptArgs;
|
||||||
|
QPushButton *browseButton;
|
||||||
|
QPushButton *stopButton;
|
||||||
|
QPushButton *startButton;
|
||||||
|
QTextEdit *luaOutput;
|
||||||
|
private:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void closeWindow(void);
|
||||||
|
private slots:
|
||||||
|
void openLuaScriptFile(void);
|
||||||
|
void startLuaScript(void);
|
||||||
|
void stopLuaScript(void);
|
||||||
|
|
||||||
|
};
|
|
@ -170,11 +170,11 @@ static intptr_t info_uid;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
extern HWND LuaConsoleHWnd;
|
extern HWND LuaConsoleHWnd;
|
||||||
extern INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
extern INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
void TaseditorDisableManualFunctionIfNeeded();
|
||||||
|
#endif
|
||||||
extern void PrintToWindowConsole(intptr_t hDlgAsInt, const char* str);
|
extern void PrintToWindowConsole(intptr_t hDlgAsInt, const char* str);
|
||||||
extern void WinLuaOnStart(intptr_t hDlgAsInt);
|
extern void WinLuaOnStart(intptr_t hDlgAsInt);
|
||||||
extern void WinLuaOnStop(intptr_t hDlgAsInt);
|
extern void WinLuaOnStop(intptr_t hDlgAsInt);
|
||||||
void TaseditorDisableManualFunctionIfNeeded();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static lua_State *L;
|
static lua_State *L;
|
||||||
|
|
||||||
|
@ -6249,9 +6249,10 @@ int FCEU_LoadLuaCode(const char *filename, const char *arg) {
|
||||||
LuaConsoleHWnd = CreateDialog(fceu_hInstance, MAKEINTRESOURCE(IDD_LUA), hAppWnd, DlgLuaScriptDialog);
|
LuaConsoleHWnd = CreateDialog(fceu_hInstance, MAKEINTRESOURCE(IDD_LUA), hAppWnd, DlgLuaScriptDialog);
|
||||||
info_uid = (intptr_t)LuaConsoleHWnd;
|
info_uid = (intptr_t)LuaConsoleHWnd;
|
||||||
#else
|
#else
|
||||||
info_print = NULL;
|
info_print = PrintToWindowConsole;
|
||||||
info_onstart = NULL;
|
info_onstart = WinLuaOnStart;
|
||||||
info_onstop = NULL;
|
info_onstop = WinLuaOnStop;
|
||||||
|
info_uid = (intptr_t)0;
|
||||||
#endif
|
#endif
|
||||||
if (info_onstart)
|
if (info_onstart)
|
||||||
info_onstart(info_uid);
|
info_onstart(info_uid);
|
||||||
|
|
Loading…
Reference in New Issue