123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- #include "MiniGames.h"
- #include <Datei.h>
- #include <Globals.h>
- #include <InitDatei.h>
- #include <KSGTDatei.h>
- #include <Punkt.h>
- #include <Rahmen.h>
- #include "../../Global/Initialisierung.h"
- #include "../../Global/Variablen.h"
- 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<KSGClient::MinigameServerClient*>(
- 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<Schrift*>(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<MiniGames*>(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.virtualKey == 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;
- }
|