Audio on/off changes, android gui fixes, android crash bugfix (1st step in internetlogindialog)

This commit is contained in:
doitux
2012-12-20 09:11:57 +01:00
parent 51ad6c5580
commit 31c3771d59
16 changed files with 156 additions and 64 deletions
+2 -2
View File
@@ -42,7 +42,6 @@
#include "cardsvalue.h"
#include "configfile.h"
#include "sdlplayer.h"
#include "soundevents.h"
#include "gametablestylereader.h"
#include "carddeckstylereader.h"
@@ -690,7 +689,6 @@ void gameTableImpl::applySettings(settingsDialogImpl* mySettingsDialog)
//apply game table style
myGameTableStyle->readStyleFile(QString::fromUtf8(myConfig->readConfigString("CurrentGameTableStyle").c_str()));
#ifdef GUI_800x480
//cardschancemonitor show/hide
if (!myConfig->readConfigInt("ShowCardsChanceMonitor")) {
@@ -838,6 +836,8 @@ void gameTableImpl::applySettings(settingsDialogImpl* mySettingsDialog)
refreshGroupbox();
provideMyActions();
}
mySoundEventHandler->reInitSoundEngine();
}
void gameTableImpl::initGui(int speed)
@@ -50,7 +50,7 @@
<item>
<widget class="QPushButton" name="pushButton_createGame">
<property name="styleSheet">
<string notr="true">QObject {font: bold 20px}</string>
<string notr="true">QObject {font: bold 30px}</string>
</property>
<property name="text">
<string>Create Game</string>
@@ -159,7 +159,7 @@
<string>Registered players only</string>
</property>
<property name="icon">
<iconset resource="../resources/pokerth.qrc">
<iconset resource="../resources/pokerth_android.qrc">
<normaloff>:/gfx/registered.png</normaloff>:/gfx/registered.png</iconset>
</property>
</item>
@@ -168,7 +168,7 @@
<string>Invited players only</string>
</property>
<property name="icon">
<iconset resource="../resources/pokerth.qrc">
<iconset resource="../resources/pokerth_android.qrc">
<normaloff>:/gfx/list_add_user.png</normaloff>:/gfx/list_add_user.png</iconset>
</property>
</item>
@@ -177,7 +177,7 @@
<string>Ranking game</string>
</property>
<property name="icon">
<iconset resource="../resources/pokerth.qrc">
<iconset resource="../resources/pokerth_android.qrc">
<normaloff>:/gfx/cup.png</normaloff>:/gfx/cup.png</iconset>
</property>
</item>
@@ -441,7 +441,7 @@
<tabstop>pushButton_createGame</tabstop>
</tabstops>
<resources>
<include location="../resources/pokerth.qrc"/>
<include location="../resources/pokerth_android.qrc"/>
</resources>
<connections>
<connection>
@@ -255,6 +255,19 @@
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@@ -265,6 +278,8 @@
<tabstop>spinBox_startCash</tabstop>
<tabstop>radioButton_useSavedBlindsSettings</tabstop>
<tabstop>radioButton_changeBlindsSettings</tabstop>
<tabstop>spinBox_netTimeOutPlayerAction</tabstop>
<tabstop>spinBox_netDelayBetweenHands</tabstop>
<tabstop>pushButton_createGame</tabstop>
</tabstops>
<resources/>
@@ -58,6 +58,9 @@
<property name="text">
<string>Username:</string>
</property>
<property name="buddy">
<cstring>lineEdit_username</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
@@ -72,6 +75,9 @@
<property name="text">
<string>Password:</string>
</property>
<property name="buddy">
<cstring>lineEdit_password</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
@@ -131,6 +137,9 @@
<property name="text">
<string>Login</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
@@ -185,7 +185,7 @@
</layout>
</item>
<item row="2" column="0" rowspan="2" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_animation">
<item>
<widget class="QLabel" name="label_animation">
<property name="text">
@@ -233,6 +233,19 @@
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
@@ -19,11 +19,13 @@
#include "configfile.h"
#include <tools.h>
#include <QtCore>
#include <QtGui>
internetGameLoginDialogImpl::internetGameLoginDialogImpl(QWidget *parent, ConfigFile *c) :
QDialog(parent), myConfig(c)
{
setupUi(this);
this->installEventFilter(this);
//html stuff
QString createAccount(QString("<a href='http://create-gaming-account.pokerth.net'>%1</a>").arg(tr("Create new user account")));
@@ -147,3 +149,27 @@ void internetGameLoginDialogImpl::okButtonCheck()
}
}
bool internetGameLoginDialogImpl::eventFilter(QObject *obj, QEvent *event)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
#ifdef ANDROID
//androi hack for crash bug (hopefully useless from necessitas beta2)
if (event->type() == QEvent::KeyPress && keyEvent->key() == Qt::Key_Return) {
if(lineEdit_username->hasFocus()) {
lineEdit_password->setFocus();
}
if(lineEdit_password->hasFocus()) {
QTimer::singleShot(1000, this, SLOT(clickLoginButton()));
}
event->ignore();
return false;
} else {
// pass the event on to the parent class
return QDialog::eventFilter(obj, event);
}
#else
return QDialog::eventFilter(obj, event);
#endif
}
@@ -35,11 +35,13 @@ public:
void exec();
void accept();
bool eventFilter(QObject *obj, QEvent *event);
public slots:
void regUserToggled(bool);
void guestUserToggled(bool);
void okButtonCheck();
void clickLoginButton() { pushButton_login->click(); }
private:
+43 -18
View File
@@ -1,25 +1,47 @@
#include "androidaudio.h"
#include "androidsoundeffect.h"
#include "configfile.h"
#include <QDebug>
AndroidAudio::AndroidAudio(QObject *parent) :
QObject(parent), mEngineObject(NULL), mEngineEngine(NULL), mOutputMixObject(NULL), mSounds(), mSoundCount(0), mPlayerObject(NULL)
AndroidAudio::AndroidAudio(ConfigFile *c, QObject *parent) :
QObject(parent), mEngineObject(NULL), mEngineEngine(NULL), mOutputMixObject(NULL), mSounds(), mSoundCount(0), mPlayerObject(NULL), myConfig(c), audioEnabled(FALSE)
{
createEngine();
startSoundPlayer();
initAudio();
}
AndroidAudio::~AndroidAudio()
{
destroyEngine();
for (int32_t i = 0; i < mSoundCount; ++i) {
qDeleteAll(mSounds);
closeAudio();
}
void AndroidAudio::initAudio()
{
if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
createEngine();
startSoundPlayer();
audioEnabled = TRUE;
}
}
void AndroidAudio::closeAudio()
{
if(audioEnabled) {
destroyEngine();
for (int32_t i = 0; i < mSoundCount; ++i) {
qDeleteAll(mSounds);
}
audioEnabled = FALSE;
}
}
void AndroidAudio::reInit()
{
initAudio();
}
// create the engine and output mix objects
void AndroidAudio::createEngine()
{
@@ -73,19 +95,19 @@ void AndroidAudio::destroyEngine()
void AndroidAudio::registerSound(const QString& path, const QString& name)
{
qDebug() << "registerSound:" << path << name;
// qDebug() << "registerSound:" << path << name;
AndroidSoundEffect *lSound = new AndroidSoundEffect(path, this);
qDebug() << "registerSound:created";
// qDebug() << "registerSound:created";
mSounds[name] = lSound;
qDebug() << "registerSound:loading";
// qDebug() << "registerSound:loading";
lSound->load();
qDebug() << "registerSound:loaded";
// qDebug() << "registerSound:loaded";
}
void AndroidAudio::startSoundPlayer()
{
qDebug() << "Starting Sound Player";
// qDebug() << "Starting Sound Player";
SLresult lRes;
@@ -121,12 +143,12 @@ void AndroidAudio::startSoundPlayer()
const SLInterfaceID lSoundPlayerIIDs[] = { SL_IID_PLAY, SL_IID_BUFFERQUEUE };
const SLboolean lSoundPlayerReqs[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
qDebug() << "Configured Sound Player";
// qDebug() << "Configured Sound Player";
lRes = (*mEngineEngine)->CreateAudioPlayer(mEngineEngine, &mPlayerObject, &lDataSource, &lDataSink, lSoundPlayerIIDCount, lSoundPlayerIIDs, lSoundPlayerReqs);
Q_ASSERT(SL_RESULT_SUCCESS == lRes);
qDebug() << "Created Sound Player";
// qDebug() << "Created Sound Player";
lRes = (*mPlayerObject)->Realize(mPlayerObject, SL_BOOLEAN_FALSE);
Q_ASSERT(SL_RESULT_SUCCESS == lRes);
@@ -141,13 +163,16 @@ void AndroidAudio::startSoundPlayer()
lRes = (*mPlayerPlay)->SetPlayState(mPlayerPlay, SL_PLAYSTATE_PLAYING);
Q_ASSERT(SL_RESULT_SUCCESS == lRes);
qDebug() << "Created Buffer Player";
// qDebug() << "Created Buffer Player";
}
void AndroidAudio::playSound(const std::string& name, int i) {
this->registerSound(QString(":/android/android-data/sounds/default/"+QString::fromStdString(name)+".wav"), QString::fromStdString(name));
this->reallyPlaySound(QString::fromStdString(name));
if(audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
this->registerSound(QString(":/android/android-data/sounds/default/"+QString::fromStdString(name)+".wav"), QString::fromStdString(name));
this->reallyPlaySound(QString::fromStdString(name));
}
}
void AndroidAudio::reallyPlaySound(const QString& name)
+8 -1
View File
@@ -13,11 +13,13 @@
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
class ConfigFile;
class AndroidAudio : public QObject
{
Q_OBJECT
public:
explicit AndroidAudio(QObject *parent = 0);
explicit AndroidAudio(ConfigFile *c, QObject *parent = 0);
~AndroidAudio();
signals:
@@ -27,6 +29,9 @@ public slots:
void registerSound(const QString& path, const QString &name);
void reallyPlaySound(const QString& name);
void playSound(const std::string& name, int i);
void initAudio();
void closeAudio();
void reInit();
private:
void createEngine();
@@ -48,6 +53,8 @@ private:
QMap<QString, AndroidSoundEffect*> mSounds;
int32_t mSoundCount;
ConfigFile *myConfig;
bool audioEnabled;
};
#endif // ANDROIDAUDIO_H
+10 -10
View File
@@ -19,7 +19,7 @@ bool AndroidSoundEffect::load()
{
QFile lSoundFile(mPath);
qDebug() << "opening:" << mPath;
// qDebug() << "opening:" << mPath;
if (!lSoundFile.open(QIODevice::ReadOnly)) {
qDebug() << "Could not open: " << mPath;
@@ -27,7 +27,7 @@ bool AndroidSoundEffect::load()
}
// parse WAV file
qDebug() << " reading header:";
// qDebug() << " reading header:";
char id[4];
lSoundFile.read(id, 4);
@@ -39,7 +39,7 @@ bool AndroidSoundEffect::load()
int size = 0;
lSoundFile.read((char *)&size, 4);
qDebug() << " size:" << size;
// qDebug() << " size:" << size;
lSoundFile.read(id, 4);
if( strncmp(id, "WAVE", 4) != 0 ) {
@@ -52,29 +52,29 @@ bool AndroidSoundEffect::load()
int format_length = 0;
lSoundFile.read((char *)&format_length, 4);
qDebug() << " format_length:" << format_length;
// qDebug() << " format_length:" << format_length;
short format_tag = 0;
lSoundFile.read((char *)&format_tag, 2);
short n_channels = 0;
lSoundFile.read((char *)&n_channels, 2);
qDebug() << " n_channels:" << n_channels;
// qDebug() << " n_channels:" << n_channels;
int sample_rate = 0;
lSoundFile.read((char *)&sample_rate, 4);
qDebug() << " sample_rate:" << sample_rate;
// qDebug() << " sample_rate:" << sample_rate;
int avg_bytes_sec = 0;
lSoundFile.read((char *)&avg_bytes_sec, 4);
qDebug() << " avg_bytes_sec:" << avg_bytes_sec;
// qDebug() << " avg_bytes_sec:" << avg_bytes_sec;
short block_align = 0;
lSoundFile.read((char *)&block_align, 2);
short bits_per_sample = 0;
lSoundFile.read((char *)&bits_per_sample, 2);
qDebug() << " bits_per_sample:" << bits_per_sample;
// qDebug() << " bits_per_sample:" << bits_per_sample;
lSoundFile.read(id, 4);
if( strncmp(id, "data", 4) != 0 ) {
@@ -85,7 +85,7 @@ bool AndroidSoundEffect::load()
lSoundFile.read((char *)&mLength, 4);
qDebug() << " reading data:" << mLength;
// qDebug() << " reading data:" << mLength;
mBuffer = (char*)malloc((mLength));
@@ -98,7 +98,7 @@ bool AndroidSoundEffect::load()
return false;
}
qDebug() << " closing:";
// qDebug() << " closing:";
lSoundFile.close();
return true;
}
+7 -16
View File
@@ -17,40 +17,31 @@
*****************************************************************************/
#include "sdlplayer.h"
#ifndef ANDROID
#if (defined __APPLE__)
#include <SDL.h>
#else
#include <SDL/SDL.h>
#endif
#endif
using namespace std;
SDLPlayer::SDLPlayer(ConfigFile *c)
#ifndef ANDROID
: sound(NULL), soundData(NULL), currentChannel(0), audioEnabled(FALSE), myConfig(c)
#endif
{
#ifndef ANDROID
myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str());
SDL_Init(SDL_INIT_AUDIO);
initAudio();
#endif
}
SDLPlayer::~SDLPlayer()
{
#ifndef ANDROID
closeAudio();
SDL_Quit();
#endif
}
void SDLPlayer::initAudio()
{
#ifndef ANDROID
if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */
@@ -66,12 +57,10 @@ void SDLPlayer::initAudio()
qDebug() << "Mix_OpenAudio() was not successfull, no sound possible :(";
}
}
#endif
}
void SDLPlayer::playSound(string audioString, int playerID)
{
#ifndef ANDROID
if(audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
QFile myFile(myAppDataPath + "sounds/default/" + QString::fromStdString(audioString)+".wav");
@@ -142,13 +131,10 @@ void SDLPlayer::playSound(string audioString, int playerID)
currentChannel = Mix_PlayChannel(-1, sound,0);
}
}
#endif
}
void SDLPlayer::closeAudio()
{
#ifndef ANDROID
if(audioEnabled) {
{ if(audioEnabled) {
Mix_HaltChannel(currentChannel);
Mix_FreeChunk(sound);
sound = NULL;
@@ -158,5 +144,10 @@ void SDLPlayer::closeAudio()
qDebug() << "Mix_CloseAudio()";
audioEnabled = false;
}
#endif
}
void SDLPlayer::reInitAudio()
{
closeAudio();
initAudio();
}
+1 -6
View File
@@ -23,12 +23,10 @@
#include "configfile.h"
#include <string>
#ifndef ANDROID
#ifdef __APPLE__
#include <SDL_mixer.h>
#else
#include <SDL/SDL_mixer.h>
#endif
#endif
struct Mix_Chunk;
@@ -48,18 +46,15 @@ public:
void initAudio();
void playSound(std::string, int playerID);
void closeAudio();
void reInitAudio();
private:
#ifndef ANDROID
Mix_Chunk *sound;
unsigned char *soundData;
int currentChannel;
bool audioEnabled;
ConfigFile *myConfig;
QString myAppDataPath;
#endif
};
#endif
+6 -1
View File
@@ -18,7 +18,7 @@ SoundEvents::SoundEvents(ConfigFile *c): myConfig(c), lastSBValue(0), lastSBLeve
{
#ifdef ANDROID
myPlayer = new AndroidAudio();
myPlayer = new AndroidAudio(myConfig);
#else
myPlayer = new SDLPlayer(myConfig);
#endif
@@ -30,6 +30,11 @@ SoundEvents::~SoundEvents()
myPlayer->deleteLater();
}
void SoundEvents::reInitSoundEngine()
{
myPlayer->reInit();
}
void SoundEvents::blindsWereSet(int sB)
{
if(newGameNow) {
+1
View File
@@ -21,6 +21,7 @@ public:
void blindsWereSet(int sB);
void newGameStarts();
void playSound(std::string audioString, int playerID);
void reInitSoundEngine();
protected:
// Prevent copy construction.