void PD_UI_DissBattle::startNewFight(PD_Character * _enemy, bool _playerFirst){
	// clear existing friendship
	for(unsigned int i = 0; i < lives.size(); ++i){
		livesContainer->removeChild(lives.at(i));
		delete lives.at(i);
	}
	for(unsigned int i = 0; i < lostLives.size(); ++i){
		livesContainer->removeChild(lostLives.at(i));
		delete lostLives.at(i);
	}
	lives.clear();
	lostLives.clear();

	enemy = _enemy;

	// loop through friends and add tokens
	for(unsigned int i = 0; i < lifeTokens.size(); ++i){
		NodeUI * l = new NodeUI(world);
		livesContainer->addChild(l);
		Texture * tex = lifeTokens.at(i);
		l->background->mesh->pushTexture2D(tex);
		l->background->mesh->setScaleMode(GL_NEAREST);
		l->setRationalHeight(1.f, livesContainer);
		l->setSquareWidth(1.f);
		l->boxSizing = kCONTENT_BOX;
		l->setMarginLeft(5);
		l->setMarginRight(5);
		l->firstParent()->scale(1.f, 1.f, 1.f);
		lives.push_back(l);
	}

	confidence = 50.f;
	playerComboMultiplier = 1.f;
	enemyComboMultiplier = 1.f;

	setupDissValues();

	if(isGameOver){
		// Reset layout
		gameOverImage->setRationalHeight(0.5f, gameOverContainer);
		gameOverContainer->setVisible(false);
		gameOverDuration = 0;

		gameContainer->setVisible(true);
		childTransform->addChild(enemyCursor->firstParent(), false);
		interjectBubble->setVisible(true);

		win = false;
		isGameOver = false;
	}
	isComplete = false;

	interjected = false;
	interjectBubble->setVisible(false);
	setUIMode(_playerFirst);
	enable();

	eventManager->triggerEvent("fightStarted");
}
Example #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Register QtKeypadBridge for the virtual keyboard functionality
    ui->keypadWidget->installEventFilter(&qt_keypad_bridge);
    ui->lcdView->installEventFilter(&qt_keypad_bridge);

    //Emu -> GUI (QueuedConnection as they're different threads)
    connect(&emu, SIGNAL(serialChar(char)), this, SLOT(serialChar(char)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(debugStr(QString)), this, SLOT(debugStr(QString))); //Not queued connection as it may cause a hang
    connect(&emu, SIGNAL(speedChanged(double)), this, SLOT(showSpeed(double)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(statusMsg(QString)), ui->statusbar, SLOT(showMessage(QString)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(turboModeChanged(bool)), ui->buttonSpeed, SLOT(setChecked(bool)), Qt::QueuedConnection);
    connect(&emu, SIGNAL(usblinkChanged(bool)), this, SLOT(usblinkChanged(bool)), Qt::QueuedConnection);

    //Menu "Emulator"
    connect(ui->buttonReset, SIGNAL(clicked(bool)), &emu, SLOT(reset()));
    connect(ui->actionReset, SIGNAL(triggered()), &emu, SLOT(reset()));
    connect(ui->actionRestart, SIGNAL(triggered()), this, SLOT(restart()));
    connect(ui->actionDebugger, SIGNAL(triggered()), &emu, SLOT(enterDebugger()));
    connect(ui->buttonPause, SIGNAL(clicked(bool)), &emu, SLOT(setPaused(bool)));
    connect(ui->buttonPause, SIGNAL(clicked(bool)), ui->actionPause, SLOT(setChecked(bool)));
    connect(ui->actionPause, SIGNAL(toggled(bool)), &emu, SLOT(setPaused(bool)));
    connect(ui->actionPause, SIGNAL(toggled(bool)), ui->buttonPause, SLOT(setChecked(bool)));
    connect(ui->buttonSpeed, SIGNAL(clicked(bool)), &emu, SLOT(setTurboMode(bool)));
    QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_F11), this);
    shortcut->setAutoRepeat(false);
    connect(shortcut, SIGNAL(activated()), &emu, SLOT(toggleTurbo()));

    //Menu "Tools"
    connect(ui->buttonScreenshot, SIGNAL(clicked()), this, SLOT(screenshot()));
    connect(ui->actionScreenshot, SIGNAL(triggered()), this, SLOT(screenshot()));
    connect(ui->actionConnect, SIGNAL(triggered()), this, SLOT(connectUSB()));
    connect(ui->buttonUSB, SIGNAL(clicked(bool)), this, SLOT(connectUSB()));
    connect(ui->actionXModem, SIGNAL(triggered()), this, SLOT(xmodemSend()));
    ui->actionConnect->setShortcut(QKeySequence(Qt::Key_F10));
    ui->actionConnect->setAutoRepeat(false);

    //Menu "Flash"
    connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFlash()));
    connect(ui->actionCreate_flash, SIGNAL(triggered()), this, SLOT(createFlash()));

    //Debugging
    connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(debugCommand()));

    //File transfer
    connect(ui->refreshButton, SIGNAL(clicked(bool)), this, SLOT(reload_filebrowser()));
    connect(this, SIGNAL(usblink_progress_changed(int)), this, SLOT(changeProgress(int)), Qt::QueuedConnection);

    //Settings
    connect(ui->checkDebugger, SIGNAL(toggled(bool)), this, SLOT(setDebuggerOnStartup(bool)));
    connect(ui->checkWarning, SIGNAL(toggled(bool)), this, SLOT(setDebuggerOnWarning(bool)));
    connect(ui->uiDocks, SIGNAL(toggled(bool)), this, SLOT(setUIMode(bool)));
    connect(ui->checkAutostart, SIGNAL(toggled(bool)), this, SLOT(setAutostart(bool)));
    connect(ui->fileBoot1, SIGNAL(pressed()), this, SLOT(selectBoot1()));
    connect(ui->fileFlash, SIGNAL(pressed()), this, SLOT(selectFlash()));
    connect(ui->pathTransfer, SIGNAL(textEdited(QString)), this, SLOT(setUSBPath(QString)));
    connect(ui->spinGDB, SIGNAL(valueChanged(int)), this, SLOT(setGDBPort(int)));
    connect(ui->spinRDBG, SIGNAL(valueChanged(int)), this, SLOT(setRDBGPort(int)));
    connect(ui->orderDiags, SIGNAL(toggled(bool)), this, SLOT(setBootOrder(bool)));

    //Set up monospace fonts
    QFont monospace = QFontDatabase::systemFont(QFontDatabase::FixedFont);
    ui->debugConsole->setFont(monospace);
    ui->serialConsole->setFont(monospace);

    qRegisterMetaType<QVector<int>>();

#ifdef Q_OS_ANDROID
    //On android the settings file is deleted everytime you update or uninstall,
    //so choose a better, safer, location
    QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
    settings = new QSettings(path + "/nspire_emu.ini", QSettings::IniFormat);
#else
    settings = new QSettings();
#endif

    //Load settings
    setUIMode(settings->value("docksEnabled", true).toBool());
    restoreGeometry(settings->value("windowGeometry").toByteArray());
    restoreState(settings->value("windowState").toByteArray(), WindowStateVersion);
    selectBoot1(settings->value("boot1", "").toString());
    selectFlash(settings->value("flash", "").toString());
    setDebuggerOnStartup(settings->value("debugOnStart", false).toBool());
    setDebuggerOnWarning(settings->value("debugOnWarn", false).toBool());
    setUSBPath(settings->value("usbdir", QString("ndless")).toString());
    setGDBPort(settings->value("gdbPort", 3333).toUInt());
    setRDBGPort(settings->value("rdbgPort", 3334).toUInt());
    setBootOrder(false);

    bool autostart = settings->value("emuAutostart", false).toBool();
    setAutostart(autostart);
    if(emu.boot1 != "" && emu.flash != "" && autostart)
        emu.start();
    else
        ui->statusbar->showMessage(trUtf8("Start the emulation via Emulation->Restart."));

    #ifdef Q_OS_MAC
        QTimer::singleShot(50, [&] {dockVisibilityChanged(false);}); // Trigger dock update (after UI was shown)
    #endif
}
void PD_UI_DissBattle::update(Step * _step){
	if(isEnabled()){
		if(!isGameOver){
			if(modeOffensive && playerQuestionTimer >= playerQuestionTimerLength && !playerResult){
				if(player->wantsToInsultUp()){
					insult(pBubbleBtn1->isEffective, pBubbleBtn1->label->getText(false));
				}else if(player->wantsToInsultDown()){
					insult(pBubbleBtn2->isEffective, pBubbleBtn2->label->getText(false));
				}
			}else{
				if (canInterject && player->wantsToInterject()){
					interject();
				}

				if(player->interjecting()){
					tutorialSpacebarImage->background->mesh->replaceTextures(PD_ResourceManager::scenario->getTexture("DISS-TUTORIAL-SPACEBAR-PRESSED")->texture);
				}else{
					tutorialSpacebarImage->background->mesh->replaceTextures(PD_ResourceManager::scenario->getTexture("DISS-TUTORIAL-SPACEBAR")->texture);
				}
			}

			if(!modeOffensive){
				enemy->pr->talking = true;
				// update interject bubble
				if(interjectBubble->isVisible()){
					if(interjectBubbleTimer >= interjectBubbleTimerLength){
						// hide bubble
						interjectBubble->setVisible(false);
						if(interjected){
							// Switch to player turn
							setUIMode(true);
						}
					}else{
						interjectBubbleTimer += _step->getDeltaTime();

						float s = 0.f;
						// animate bubble
						if(!interjected){
							s = interjectBubbleTimer / interjectBubbleTimerLength <= 0.5 ? Easing::easeOutCubic(interjectBubbleTimer, 0, interjectBubbleScale, interjectBubbleTimerLength * 0.5f) : Easing::easeInCubic(interjectBubbleTimer - interjectBubbleTimerLength * 0.5f, interjectBubbleScale, -interjectBubbleScale, interjectBubbleTimerLength * 0.5f);
						}else{
							s = interjectBubbleTimer / interjectBubbleTimerLength <= 0.7 ? Easing::easeOutElastic(interjectBubbleTimer, 0, interjectBubbleScale, interjectBubbleTimerLength * 0.7f) : Easing::easeInBack(interjectBubbleTimer - interjectBubbleTimerLength * 0.7f, interjectBubbleScale, -interjectBubbleScale, interjectBubbleTimerLength * 0.3f);
						}
						interjectBubble->meshTransform->scale(s, s, 1, false);
					}
				}

				// update enemy turn
				if(!interjected){
					// INTERJECT
					interjectTimer += _step->getDeltaTime();
					// Cursor
					if(glyphIdx < glyphs.size()){
						glm::vec3 screenPos = glyphs.at(glyphIdx)->childTransform->getWorldPos();
						float w = glyphs.at(glyphIdx)->getWidth();

						glm::vec3 screenPos1 = screenPos;
						glm::vec3 screenPos2 = glm::vec3(screenPos.x + w, screenPos.y, screenPos.z);

						cursorDelayDuration += _step->getDeltaTime();

						if(cursorDelayDuration < cursorDelayLength){
							float dx = screenPos2.x - screenPos1.x;
							float dy = screenPos2.y - screenPos1.y;
							float tx = Easing::linear(cursorDelayDuration, screenPos1.x, dx, cursorDelayLength);
							float ty = Easing::linear(cursorDelayDuration, screenPos1.y, dy, cursorDelayLength);
							enemyCursor->childTransform->translate(tx, ty, 0, false);
						}else{
							// Get next glyph

							// Find next punctuation
							if(highlightedPunctuation != nullptr && glyphs.at(glyphIdx) == highlightedPunctuation){
								sweet::Event * e = new sweet::Event("miss");
								eventManager->triggerEvent(e);

								prevHighlightedPunctuation = highlightedPunctuation;
								highlightedPunctuation = findFirstPunctuation(glyphIdx+1);
							}

							if(highlightedWordEnd != nullptr && glyphs.at(glyphIdx) == highlightedWordEnd){
								highlightNextWord(glyphIdx+1);
							}

							++glyphIdx;
							cursorDelayDuration = 0;

							if(glyphIdx < glyphs.size()){
								// set cursor delay for this glyph
								cursorDelayLength = glyphs.at(glyphIdx)->getWidth() / baseGlyphWidth * (glyphs.at(glyphIdx) != highlightedPunctuation ? baseCursorDelayLength * (1.f + (sassInterjectMultiplier - 1.f) * 0.5f) : baseCursorPunctDelayLength * sassInterjectMultiplier);
								
								// play sound
								if(glyphIdx == 1 || glyphs.at(glyphIdx - 1)->character == ' '){
									auto sound = enemy->voice;
									sound->setPitch((glyphs.at(glyphIdx)->character-100.f)/100.f+1.0f);
									sound->play();
								}
							}else{
								// Enemy's insult effective!
								incrementConfidence(-damage);
								setEnemyText();
							}
						}
					}

					// Punctuation Highlight
					if(highlightedPunctuation != nullptr){
						glm::vec3 pos = highlightedPunctuation->firstParent()->getTranslationVector();
						// text label
						glm::mat4 mm = highlightedPunctuation->nodeUIParent->firstParent()->getModelMatrix();
						pos = glm::vec3(mm* glm::vec4(pos, 1));

						punctuationHighlight->childTransform->translate(pos, false);
					}

					// Word Highlight
					if(highlightedWordStart != nullptr){
						glm::vec3 pos = highlightedWordStart->firstParent()->getTranslationVector();
						// text label
						glm::mat4 mm = highlightedWordStart->nodeUIParent->firstParent()->getModelMatrix();
						pos = glm::vec3(mm* glm::vec4(pos, 1));

						wordHighlight->childTransform->translate(pos, false);
					}
				}
			}else{
				enemy->pr->talking = false;
				// update compliment bubble
				if(complimentBubble->isVisible()){
					if(complimentBubbleTimer >= complimentBubbleTimerLength){
						complimentBubble->setVisible(false);
					}else{
						complimentBubbleTimer += _step->getDeltaTime();
						float s = 0.f;
						s = complimentBubbleTimer / complimentBubbleTimerLength <= 0.7 ? Easing::easeOutElastic(complimentBubbleTimer, 0, complimentBubbleScale, complimentBubbleTimerLength * 0.7f) : Easing::easeInBack(complimentBubbleTimer - complimentBubbleTimerLength * 0.7f, complimentBubbleScale, -complimentBubbleScale, complimentBubbleTimerLength * 0.3f);
						complimentBubble->meshTransform->scale(s, s, 1, false);
					}
				}

				// INSULT
				if(playerQuestionTimer >= playerQuestionTimerLength){
					if(!playerResult){
						// Increment player answer timer
						if(playerAnswerTimer >= playerAnswerTimerLength){
							// Out of time, enemy's turn!
							countInsultAccuracy(-1);
							// Reset multipier for failed insult damage
							playerComboMultiplier = 1.f;
							incrementConfidence(-damage);
							PD_ResourceManager::scenario->getAudio(TIMER)->sound->stop();
							PD_ResourceManager::scenario->getAudio(PASSED_INSULT_TIME_LIMIT)->sound->play();
							setUIMode(false);
						}else{
							playerAnswerTimer += _step->getDeltaTime();
						}
					}else{
						// Player Insult Result
						// Increment player result timer
						if(playerResultTimer >= playerResultTimerLength){
							if (playerResultEffective){
								// Insult Success!
								// Reset enemy combo multipier if first insult was effective
								if(enemyComboMultiplier > 1.f){
									enemyComboMultiplier = 1.f;
								}
								// Get next insult
								incrementConfidence(damage);
								setPlayerText();
								playerInsultSpeedMultiplier -= (1.f - MIN_OFFENSE_SPEED_MULTIPLIER) / NUM_OFFENSE_SPEED_CHANGES;

								playerAnswerTimerLength = basePlayerAnswerTimerLength *  sassInsultMultiplier * playerInsultSpeedMultiplier;
								playerQuestionTimerLength = basePlayerQuestionTimerLength * playerInsultSpeedMultiplier;
								playerTimerSlider->setValueMax(playerAnswerTimerLength);
							}
							else{
								//Insult Failed
								// Reset multipier for failed insult
								playerComboMultiplier = 1.f;
								incrementConfidence(-damage);
								setUIMode(false);
							}
						}else{
							playerResultTimer += _step->getDeltaTime();
						}
					}
				}else{
					// Increment player question timer
					playerQuestionTimer += _step->getDeltaTime();
					if(playerQuestionTimer >= playerQuestionTimerLength){
						playerBubbleOptions->setVisible(true);
						playerTimerSlider->setVisible(true);
						PD_ResourceManager::scenario->getAudio(TIMER)->sound->play(true);
					}
				}
			}
		}else{
			gameOverDuration += _step->getDeltaTime();

			if(gameOverDuration >= gameOverLength){
				complete();
			}else{
				float p = gameOverDuration / gameOverLength;
				if(p < 0.75f){
					float size = Easing::easeOutElastic(p, 0.5f, 0.5f, gameOverLength * 0.75f);
					gameOverImage->setRationalHeight(size, gameOverContainer);
					gameOverContainer->invalidateLayout();
				}
			}
		}

		canInterject = !interjectBubble->isVisible() && !modeOffensive;
		VerticalLinearLayout::update(_step);
	}
}