#include "MiniGames.h" #include #include #include "../../Global/Variablen.h" #include #include "../../Global/Initialisierung.h" #include #include #include typedef MiniGameV* (*GetMiniGame)(); // Inhalt der MGLaden Klasse aus MiniGames.h // Konstruktor MGSuchen::MGSuchen(MiniGames* mGames) { this->mGames = mGames; start(); } // Destruktor MGSuchen::~MGSuchen() { mGames->release(); } // nicht constant void MGSuchen::thread() { KSGTDatei* dgt = new KSGTDatei("data/dg.ksgt"); dgt->laden(); bool ak = 0; int dgId = infoClient->getDateiGruppeIdVonPfad("data/Minigames"); for (int i = 0; i < dgt->getZeilenAnzahl(); i++) { if (dgt->zFeld(i, 0) && TextZuInt(dgt->zFeld(i, 0)->getText(), 10) == dgId) { int lv = dgt->zFeld(i, 2) ? TextZuInt(dgt->zFeld(i, 2)->getText(), 10) : 0; int ov = infoClient->getDateiGruppeVersion(dgId); if (lv == ov) ak = 1; break; } } dgt->release(); if (!ak) { mGames->setAktuell(0, dgId); delete this; return; } Datei* d = new Datei(); d->setDatei("data/Minigames"); if (!d->existiert()) DateiPfadErstellen("data/MiniGames/"); RCArray< Text >* list = d->getDateiListe(); if (list) { for (int i = 0; i < list->getEintragAnzahl(); i++) { MiniGame* mg = new MiniGame(list->z(i)->getText()); if (!mg->istOk()) { mg->release(); continue; } mGames->addMiniGame(mg); } list->release(); } d->release(); delete this; } // Inhalt der MGLaden Klasse aus MiniGameV.h // Konstruktor MGLaden::MGLaden(const char* name) { this->name = new Text(name); game = 0; start(); } // Destruktor MGLaden::~MGLaden() { if (game) { game->release(); Framework::getDLLRegister()->releaseDLL(name->getText()); } name->release(); } // nicht constant void MGLaden::thread() { Text* pfad = new Text("data/Minigames/"); pfad->append(name->getText()); if (!DateiExistiert(pfad->getText())) { pfad->release(); run = 0; return; } pfad->append("/mg.ini"); if (!DateiExistiert(pfad->getText())) { pfad->release(); run = 0; return; } InitDatei* mgIni = new InitDatei(pfad); if (!mgIni->laden()) { mgIni->release(); run = 0; return; } if (!mgIni->wertExistiert("DllPfad")) { mgIni->release(); run = 0; return; } Text* dllPfad = new Text("data/Minigames/"); dllPfad->append(name->getText()); dllPfad->append("/"); dllPfad->append(mgIni->zWert("DllPfad")->getText()); mgIni->release(); if (!DateiExistiert(dllPfad->getText())) { dllPfad->release(); run = 0; return; } HMODULE dll = Framework::getDLLRegister()->ladeDLL(name->getText(), dllPfad->getText()); dllPfad->release(); if (!dll) { run = 0; return; } GetMiniGame getMiniGame = (GetMiniGame)GetProcAddress(dll, "GetMiniGame"); if (!getMiniGame) { Framework::getDLLRegister()->releaseDLL(name->getText()); run = 0; return; } game = getMiniGame(); if (!game) { Framework::getDLLRegister()->releaseDLL(name->getText()); run = 0; return; } if (!minigameClient) minigameClient = mainClient->createMinigameServerClient(); if (minigameClient) game->setMinigameClientZ(dynamic_cast(minigameClient->getThis())); if (!game->laden()) { game = (MiniGameV*)game->release(); Framework::getDLLRegister()->releaseDLL(name->getText()); } run = 0; } // constant bool MGLaden::fertig() const { return !isRunning(); } MiniGameV* MGLaden::zGame() const { return game; } // Inhalt der MiniGames Klasse aus MiniGames.h // Konstruktor MiniGames::MiniGames(Fenster* zNachLoginFenster, int x) : Zeichnung() { bildschirmGröße = uiFactory.initParam.bildschirm->getBackBufferSize(); pos = Punkt(x, 67); gr = Punkt(102, 32); rahmen = new LRahmen(); rahmen->setFarbe(0xFFFFFFFF); rahmen->setSize(102, 32); alpha = 0; alpha2 = 0; animation = 0; sichtbar = 0; tickVal = 0; prozent1 = 0; prozent2 = 0; begPos = Punkt(0, 0); begGröße = Punkt(0, 0); größe1 = Punkt(102, 32); pos1 = Punkt(x, 67); größe2 = Punkt(800, 500); pos2 = bildschirmGröße / 2 - größe2 / 2; laden = (Animation2D*)ladeAnimation->dublizieren(); laden->setSichtbar(0); laden->setPosition(375, 225); games = new RCArray< MiniGame >(); suchFilter = initTextFeld(10, 10, 100, 20, TextFeld::Style::Text | TextFeld::Style::VCenter, "Suchfilter:"); TextRenderer tr(dynamic_cast(uiFactory.initParam.schrift->getThis())); tr.setSchriftSize(12); suchFilter->setSize(tr.getTextBreite(suchFilter->zText()->getText()), 20); suchName = initTextFeld(20 + suchFilter->getBreite(), 10, 200, 20, TextFeld::Style::TextFeld, ""); suchen = initKnopf(230 + suchFilter->getBreite(), 10, 100, 20, Knopf::Style::Sichtbar, "Suchen"); gefiltert = 0; getThis(); zNachLoginFenster->addMember(this); dg = 0; mgl = 0; mgInitialized = 0; fullscreen = 0; slo = 0; minAlpha = 0; getThis(); new MGSuchen(this); } // Destruktor MiniGames::~MiniGames() { rahmen->release(); suchName->release(); suchFilter->release(); suchen->release(); laden->release(); games->release(); if (mgl) mgl->release(); } // nicht constant void MiniGames::setSichtbar(bool sicht) { begPos = pos; begGröße = gr; animation |= (sicht ? 0x1 : 0x2); rend = 1; } void MiniGames::addMiniGame(MiniGame* mg) { games->add(mg); if (gefiltert) filter(); else { int i = games->getEintragAnzahl() - 1; games->z(i)->setPosition(10 + 10 * (i % 3) + 250 * (i % 3), 50 + 10 * (i / 3) + 100 * (i / 3)); } } void MiniGames::setAktuell(bool aktuell, int dg) { this->aktuell = aktuell; if (aktuell) new MGSuchen(dynamic_cast(getThis())); if (!this->dg) this->dg = dg; if (!aktuell && !updateH->hat(dg)) { nachLogin->zNachrichtenListe()->addNachricht(new SpielUpdateNachricht(new Text("Update"), new Text("Die minigames müssen aktualisiert werden."), dg, []() { if (nachLogin && nachLogin->zMGFenster()) nachLogin->zMGFenster()->setAktuell(1); })); } } void MiniGames::setFullScreenMode(bool enabled) { fullscreen = enabled; if (fullscreen) nachLogin->hideBars(); else nachLogin->showBars(); } void MiniGames::showLoadingOverlay(unsigned char minAlpha) { slo++; this->minAlpha = minAlpha; if (slo) laden->setSichtbar(1); } void MiniGames::hideLoadingOverlay() { slo--; if (!slo) laden->setSichtbar(0); } Bild* MiniGames::loadBild(const char* path) { return bilder->get(path); } void MiniGames::filter() { Text filter = suchName->zText()->getText(); bool notF = 0; if (!filter.getLength()) notF = 1; int anz = games->getEintragAnzahl(); bool* fertig = new bool[anz]; for (int i = 0; i < anz; i++) fertig[i] = 0; for (int i = 0; i < anz; i++) { int pos = -1; int p = -1; for (int j = 0; j < anz; j++) { if ((notF || (games->z(j)->zName()->hat(filter) && (pos == -1 || games->z(j)->zName()->positionVon(filter) < pos))) && !fertig[j]) { p = j; pos = games->z(j)->zName()->positionVon(filter); games->z(j)->setSichtbar(1); } } if (p < 0) break; fertig[p] = 1; games->z(p)->setPosition(10 + 10 * (i % 3) + 250 * (i % 3), 50 + 10 * (i / 3) + 100 * (i / 3)); } for (int i = 0; i < anz; i++) { if (!fertig[i]) games->z(i)->setSichtbar(0); } delete[] fertig; } void MiniGames::doPublicMausEreignis(MausEreignis& me) { if (laden->istSichtbar() || !sichtbar) return; me.mx -= pos.x; me.my -= pos.y; if (alpha2) { suchName->doPublicMausEreignis(me); bool vera = me.verarbeitet; suchen->doPublicMausEreignis(me); if (!vera && me.verarbeitet && me.id == ME_RLinks) filter(); int anz = games->getEintragAnzahl(); for (int i = 0; i < anz; i++) { bool vera = me.verarbeitet; games->z(i)->doPublicMausEreignis(me); if (!vera && me.verarbeitet && me.id == ME_RLinks) { // spiel starten laden->setSichtbar(1); if (mgl) mgl = (MGLaden*)mgl->release(); mgInitialized = 0; mgl = new MGLaden(games->z(i)->zName()->getText()); } } } if (!slo && mgl && mgl->zGame()) mgl->zGame()->doPublicMausEreignis(me); me.mx += pos.x; me.my += pos.y; } void MiniGames::doTastaturEreignis(TastaturEreignis& te) { if (laden->istSichtbar() || !sichtbar) return; if (alpha2) { bool vera = te.verarbeitet; suchName->doTastaturEreignis(te); if (!vera && te.verarbeitet && te.taste == T_Enter && te.id == TE_Release) filter(); } if (!slo && mgl && mgl->zGame()) mgl->zGame()->doTastaturEreignis(te); } bool MiniGames::tick(double z) { if (laden->istSichtbar() && mgl && mgl->fertig()) { if (!mgl->zGame()) { mgl = (MGLaden*)mgl->release(); nachLogin->zNachrichtenListe()->addNachricht(new Text("Fehler"), new Text("Das Minigame konnte nicht geladen werden."), new Text("Ok")); mgInitialized = 0; slo = 0; } else if (!mgInitialized) { mgl->zGame()->setMinigameAPI(this); mgl->zGame()->setUIFactory(uiFactory); mgInitialized = 1; } if (!slo) laden->setSichtbar(0); } if (mgl && mgl->zGame() && !alpha2) { if (sichtbar && !animation) rend |= mgl->zGame()->tick(z); if (mgl->zGame()->istEnde()) { mgl = (MGLaden*)mgl->release(); mgInitialized = 0; } } rend |= laden->tick(z); if (alpha2) { rend |= suchName->tick(z); rend |= suchen->tick(z); int anz = games->getEintragAnzahl(); for (int i = 0; i < anz; i++) rend |= games->z(i)->tick(z); } tickVal += z * 150; int val = (int)tickVal; if (val < 1) { bool ret = rend; rend = 0; return ret; } tickVal -= val; if ((animation | 0x1) == animation) // Einblenden { if (prozent1 != 100) { prozent1 += val; if (prozent1 >= 100) prozent1 = 100; pos = begPos + (Punkt)(((Vec2< double >)(pos2 - begPos) / 100.0) * prozent1); gr = begGröße + (Punkt)(((Vec2< double >)(größe2 - begGröße) / 100.0) * prozent1); } else if (alpha != 255) { alpha += val * 2; if (alpha >= 255 || (animation | 0x2) == animation) { alpha = 255; animation &= ~0x1; sichtbar = 1; prozent1 = 0; } } else { animation &= ~0x1; prozent1 = 0; pos = pos2; gr = größe2; } rend = 1; } if ((animation | 0x2) == animation) // ausblenden { if (alpha != 0) { alpha -= val * 2; if (alpha < 0) alpha = 0; } else { prozent2 += val; if (prozent2 > 100) prozent2 = 100; pos = begPos + (Punkt)(((Vec2< double >)(pos1 - begPos) / 100.0) * prozent2); gr = begGröße + (Punkt)(((Vec2< double >)(größe1 - begGröße) / 100.0) * prozent2); if (prozent2 == 100) { prozent2 = 0; animation &= ~0x2; sichtbar = 0; } } rend = 1; } if (!animation && sichtbar) { if (fullscreen) { if (pos != Punkt(0, 0)) { pos -= Punkt(val, val) * 2; if (pos.x < 0) pos.x = 0; if (pos.y < 0) pos.y = 0; } if (gr != bildschirmGröße) { gr += Punkt(val, val) * 4; if (gr.x > bildschirmGröße.x - 1) gr.x = bildschirmGröße.x - 1; if (gr.y > bildschirmGröße.y - 1) gr.y = bildschirmGröße.y - 1; } } else { if (pos != pos2 || gr != größe2) { begPos = pos; begGröße = gr; animation |= 0x1; } } if (slo && alpha != minAlpha) { alpha -= val * 2; if (alpha < minAlpha) alpha = minAlpha; } else if (!slo && alpha != 255) { alpha += val * 2; if (alpha > 255) alpha = 255; } } if (mgl && alpha2) { alpha2 -= val; if (alpha2 < 0) alpha2 = 0; rend = 1; } if (!mgl && alpha2 != 255) { alpha2 += val; if (alpha2 > 255) alpha2 = 255; rend = 1; } bool ret = rend; rend = 0; return ret; } void MiniGames::render(Bild& zRObj) { if (pos == pos1) return; rahmen->setPosition(pos); rahmen->setSize(gr); rahmen->render(zRObj); if (!zRObj.setDrawOptions(pos.x + 1, pos.y + 1, gr.x - 2, gr.y - 2)) return; int rbr = rahmen->getRBreite(); zRObj.setAlpha((unsigned char)alpha); zRObj.setAlpha((unsigned char)alpha2); suchFilter->render(zRObj); suchName->render(zRObj); suchen->render(zRObj); int anz = games->getEintragAnzahl(); for (int i = 0; i < anz; i++) games->z(i)->render(zRObj); zRObj.releaseAlpha(); if (mgl && mgl->fertig() && mgl->zGame()) mgl->zGame()->render(zRObj); zRObj.releaseAlpha(); laden->setPosition(gr.x / 2 - laden->getBreite() / 2, gr.y / 2 - laden->getHeight() / 2); laden->render(zRObj); zRObj.releaseDrawOptions(); } // constant bool MiniGames::istAnimiert() const { return animation != 0; } bool MiniGames::istSichtbar() const { return sichtbar || prozent1 != 0; }