diff --git a/GPN_BadgeLasertag.ino b/GPN_BadgeLasertag.ino index 3e2850fea459c9a8e88fee5575824731ed457f71..2750a43bfd12c729d22fbc6167725441bc4f6378 100644 --- a/GPN_BadgeLasertag.ino +++ b/GPN_BadgeLasertag.ino @@ -189,9 +189,9 @@ void loop() { pixels.show(); if (server) { - Serial.println("Loop - Server"); +// Serial.println("Loop - Server"); server->update(); - Serial.println("Loop - Server - Ende"); +// Serial.println("Loop - Server - Ende"); } if (client) { client->update(); @@ -201,12 +201,17 @@ void loop() { char *loadNick() { if (SPIFFS.exists("/nick.conf")) { - UrlDecode nickUrlDecode("/nick.conf"); + Serial.println("Load nick"); + File nickConf = SPIFFS.open("/nick.conf", "r"); + String configString; + while (nickConf.available()) { + configString += char(nickConf.read()); + } + nickConf.close(); + UrlDecode nickUrlDecode(configString.c_str()); char *nick = nickUrlDecode.getKey("nick"); -#ifdef DEBUG Serial.printf("loaded nickname %s!\n", nick); -#endif return nick; } return "otter"; diff --git a/GameClient.cpp b/GameClient.cpp index 7608db4c92a8d5b5327ee07b8dbfc2773cea5013..72ef36b5d9524d85318491459ba97714bbf316ac 100644 --- a/GameClient.cpp +++ b/GameClient.cpp @@ -17,22 +17,20 @@ void GameClient::createUIGameStart() { playerList->setDownAction([=]() { this->player->reload(); }); playerList->setEnterAction([=]() { this->player->shot(); }); Serial.println("GameClient::createUIGameStart - set Lambdas"); - LaserMenuItem *healthMI = new LaserMenuItem([]() {}, "/heart.bmp"); - LaserMenuItem *armorMI = new LaserMenuItem([]() {}, "/armor.bmp"); - LaserMenuItem *ammoMI = new LaserMenuItem([]() {}, "/ammo1.bmp"); - LaserMenuItem *nameMI = new LaserMenuItem([]() {}, nullptr); + MenuItem *healthMI = new MenuItem("100%", []() {}); + MenuItem *armorMI = new MenuItem("100%", []() {}); + MenuItem *ammoMI = new MenuItem("10/10", []() {}); + MenuItem *nameMI = new MenuItem(player->getNickname(), []() {}); player->setHealthMenuItem(healthMI); player->setArmorMenuItem(armorMI); player->setAmmoMenuItem(ammoMI); + playerList->addMenuItem(new MenuItem("% Otter", []() {})); playerList->addMenuItem(healthMI); - playerList->addMenuItem(armorMI); - playerList->addMenuItem(ammoMI); +// playerList->addMenuItem(armorMI); +// playerList->addMenuItem(ammoMI); playerList->addMenuItem(nameMI); Serial.println("GameClient::createUIGameStart - added Lambdas"); - nameMI->setText(player->getNickname()); - Serial.println("GameClient::createUIGameStart - set Nickname"); - playerList->setDirty(); - reopen = true; + ui->open(playerList); Serial.println("GameClient::createUIGameStart - Ende"); } @@ -60,7 +58,7 @@ void GameClient::joinGame(String ip) { //client->connect(ip.c_str(), SERVER_PORT); Serial.printf("Trying to conncet!\n"); - if (!client->connect("192.168.42.175", 4803)){ + if (!client->connect("192.168.42.175", 4803)) { Serial.printf("Connect failed!\n"); } Serial.printf("client->connect\n"); @@ -76,7 +74,7 @@ void GameClient::joinGame(String ip) { void GameClient::update() { - Serial.println("GameClient - Update"); +// Serial.println("GameClient - Update"); // String lastHitBy; // int lastDamage; @@ -88,10 +86,10 @@ void GameClient::update() { // tft.print("Hit by " + lastHitBy); // } - Serial.println("GameClient - Update - Ende"); +// Serial.println("GameClient - Update - Ende"); } -bool GameClient::wasHit(String* nick, int* damage, bool enable) { +bool GameClient::wasHit(String *nick, int *damage, bool enable) { // TODO: Write 'real' code *nick = "otter"; *damage = 10; diff --git a/GameServer.cpp b/GameServer.cpp index eecc07872c03dc6a15ff55b77eed9ee22a9024ea..d0d1d7913ef3076b3a6b0ae95e0d0ca55e52b4c8 100644 --- a/GameServer.cpp +++ b/GameServer.cpp @@ -21,20 +21,20 @@ void GameServer::secureQuestion() { #ifdef AUSGABE Serial.printf("Sicherheitsabfrage!"); #endif - secureMenu = new PlayerListMenu(4); - secureMenu->addMenuItem(new MenuItem("Start?", [=]() { this->startGame(); Serial.println("Lambda Start - Ende"); })); - secureMenu->addMenuItem(new MenuItem("Cancel?", [=]() { - ui->dispatchInput(badge->getJoystickState()); - ui->closeCurrent(); - ui->draw(); - })); - secureMenu->setRightAction([=]() { - ui->dispatchInput(badge->getJoystickState()); - ui->closeCurrent(); - ui->draw(); - }); - secureMenu->setLeftAction([=]() { this->startGame(); }); - ui->open(secureMenu); +//secureMenu = new PlayerListMenu(4); +//secureMenu->addMenuItem(new MenuItem("Start?", [=]() { this->startGame(); Serial.println("Lambda Start - Ende"); })); +//secureMenu->addMenuItem(new MenuItem("Cancel?", [=]() { +// ui->dispatchInput(badge->getJoystickState()); +// ui->closeCurrent(); +// ui->draw(); +//})); + //secureMenu->setRightAction([=]() { + // ui->dispatchInput(badge->getJoystickState()); + // ui->closeCurrent(); + // ui->draw(); + //}); + //secureMenu->setLeftAction([=]() { this->startGame(); }); + //ui->open(secureMenu); } void GameServer::kick() { @@ -54,12 +54,13 @@ void GameServer::update() { handleWelcome(&(serverClients[numConnections]), numConnections); } } else { - Serial.println("Waiting for packets"); +// Serial.println("Waiting for packets"); for (short i = 0; i < numConnections; i++) { //iterate throu the slots if (serverClients[i].connected() && serverClients[i].available()) { //skip unconnected slots String message = serverClients[i].readStringUntil('\n'); UrlDecode decode(message.c_str()); String strTyp = String(decode.getKey("typ")); + Serial.println(message); if (strTyp == "hit") { HitPacket *packet = HitPacket::read(message); sendHit(packet); @@ -133,7 +134,7 @@ void GameServer::startGame() { config.health = HEALTH; String value = config.serial() + "\n"; sendAll(value); - sendAll(this->buildPlayerList()); + sendAll(buildPlayerList()); this->gameStarted = true; if (gameStartCallback) { Serial.println("Start Game - GameServer - call Callback"); diff --git a/GameServer.hpp b/GameServer.hpp index 1c2eb3e2813a1905728c8e3d22790575ca6876b5..8a5339a4bea4b00d6bdec89f26c278613ac1557f 100644 --- a/GameServer.hpp +++ b/GameServer.hpp @@ -8,7 +8,6 @@ #include <GPNBadge.hpp> #include "BadgeUI.h" #include "HitPacket.hpp" -#include "LaserMenuItem.hpp" #include "PlayerListMenu.hpp" #include "RemotePlayer.hpp" @@ -58,11 +57,10 @@ public: Serial.printf("Opened menu\n"); #endif playerList = new PlayerListMenu(9); - LaserMenuItem *item = new LaserMenuItem([]() {}, nullptr); - item->setText("Playerlist"); + MenuItem *item = new MenuItem("Playerlist", []() {}); playerList->addMenuItem(item); playerList->setLeftAction([=]() { this->kick(); }); - playerList->setRightAction([=]() { this->secureQuestion(); }); + playerList->setRightAction([=]() { this->startGame(); }); playerList->setEnterAction([=]() { this->sendIP(); }); ui->open(playerList); ui->dispatchInput(badge->getJoystickState()); diff --git a/LaserMenuItem.cpp b/LaserMenuItem.cpp deleted file mode 100644 index c585f1e38afb47311320a47632e4030506bd3f27..0000000000000000000000000000000000000000 --- a/LaserMenuItem.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// Created by hoelshare on 21.05.17. -// -#include "LaserMenuItem.hpp" -#include <FS.h> -#include <TFT_ILI9163C.h> -#include "BadgeUI.h" - -uint32_t read32(File &f); - -uint16_t read16(File &f); - -void LaserMenuItem::bmpDraw(uint8_t x, uint16_t y, TFT_ILI9163C *tft) { - Serial.println("LaserMenuItem::bmpDraw"); - if (this->imagePath) { - File bmpFile; - uint16_t bmpWidth, bmpHeight; // W+H in pixels - uint8_t bmpDepth; // Bit depth (currently must be 24) - uint32_t bmpImageoffset; // Start of image data in file - uint32_t rowSize; // Not always = bmpWidth; may have padding - uint8_t sdbufferLen = BUFFPIXEL * 3; - uint8_t sdbuffer[sdbufferLen]; // pixel buffer (R+G+B per pixel) - uint8_t buffidx = sdbufferLen; // Current position in sdbuffer - boolean goodBmp = false; // Set to true on valid header parse - boolean flip = true; // BMP is stored bottom-to-top - uint16_t w, h, row, col; - uint8_t r, g, b; - uint32_t pos = 0; - - if ((x >= tft->width()) || (y >= tft->height())) return; - - // Open requested file on SD card - if ((bmpFile = SPIFFS.open(this->imagePath, "r")) == NULL) { - // TODO Download File - return; - } - - // Parse BMP header - if (read16(bmpFile) == 0x4D42) { // BMP signature - read32(bmpFile); - (void) read32(bmpFile); // Read & ignore creator bytes - bmpImageoffset = read32(bmpFile); // Start of image data - // Read DIB header - read32(bmpFile); - bmpWidth = read32(bmpFile); - bmpHeight = read32(bmpFile); - if (read16(bmpFile) == 1) { // # planes -- must be '1' - bmpDepth = read16(bmpFile); // bits per pixel - if ((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed - goodBmp = true; // Supported BMP format -- proceed! - rowSize = (bmpWidth * 3 + 3) & ~3;// BMP rows are padded (if needed) to 4-byte boundary - if (bmpHeight < 0) { - bmpHeight = -bmpHeight; - flip = false; - } - // Crop area to be loaded - w = bmpWidth; - h = bmpHeight; - if ((x + w - 1) >= tft->width()) w = tft->width() - x; - if ((y + h - 1) >= tft->height()) h = tft->height() - y; - //tft->startPushData(x, y, x+w-1, y+h-1); - for (row = 0; row < h; row++) { // For each scanline... - uint8_t row_data[w * 2]; - if (flip) { // Bitmap is stored bottom-to-top order (normal BMP) - pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize; - } else { // Bitmap is stored top-to-bottom - pos = bmpImageoffset + row * rowSize; - } - if (bmpFile.position() != pos) { // Need seek? - bmpFile.seek(pos, SeekSet); - buffidx = sdbufferLen; // Force buffer reload - } - for (col = 0; col < w; col++) { // For each pixel... - // Time to read more pixel data? - if (buffidx >= sdbufferLen) { // Indeed - bmpFile.read(sdbuffer, sdbufferLen); - buffidx = 0; // Set index to beginning - } - // Convert pixel from BMP to TFT format, push to display - b = sdbuffer[buffidx++]; - g = sdbuffer[buffidx++]; - r = sdbuffer[buffidx++]; - uint16_t val = tft->Color565(r, g, b); - row_data[2 * col + 1] = (uint8_t) val; - row_data[2 * col] = *(((uint8_t * ) & val) + 1); - } // end pixel - tft->writeRow(y + row, x, w, row_data); - } // end scanline - //tft->endPushData(); - } // end goodBmp - } - } - - bmpFile.close(); - if (!goodBmp) { - tft->setCursor(20, 20); - tft->print("file unrecognized!"); - } - } - Serial.println("LaserMenuItem::bmpDraw - Ende"); -} diff --git a/LaserMenuItem.hpp b/LaserMenuItem.hpp deleted file mode 100644 index a7f5c7179ce39f1966d06ca2fd037bdcc55b9b62..0000000000000000000000000000000000000000 --- a/LaserMenuItem.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// -// Created by hoelshare on 21.05.17. -// - -#ifndef GPN_LASERTAG_LASERMENUITEM_HPP -#define GPN_LASERTAG_LASERMENUITEM_HPP -#include <GPNBadge.hpp> -#include <FS.h> -#include "UIThemes.h" -#include "BadgeUI.h" -class LaserMenuItem : public MenuItem { -public: - LaserMenuItem(std::function<void(void)> trigger, const char* imagePath) : - MenuItem("100%", trigger), imagePath(imagePath) { - }; - - void setImagePath(String imagePath) { this->imagePath = imagePath.c_str(); } - -private: - const char *imagePath; - void bmpDraw(uint8_t, uint16_t, TFT_ILI9163C*); -}; - -#endif //GPN_LASERTAG_LASERMENUITEM_HPP diff --git a/Player.cpp b/Player.cpp index 0bc89d10ddea48fe8211454002714691fb281073..851ccc1c30f9650d6e914010eb30c65aa9226fdf 100644 --- a/Player.cpp +++ b/Player.cpp @@ -50,7 +50,7 @@ void Player::updateArmorMenuItem() { String percentage = buff; delete[] buff; this->armorMenuItem->setText(percentage); - this->armorMenuItem->setImagePath(String("/ammo" + String(this->weaponIndex) + ".bmp")); +// this->armorMenuItem->setImagePath(String("/ammo" + String(this->weaponIndex) + ".bmp")); } } diff --git a/Player.hpp b/Player.hpp index f0199bb18466701168ce95ab462a4abe1cf27224..2d18fd98e92df1cb3cc46240d533545c9d2df60b 100644 --- a/Player.hpp +++ b/Player.hpp @@ -5,7 +5,7 @@ #ifndef GPN_LASERTAG_PLAYER_HPP #define GPN_LASERTAG_PLAYER_HPP -#include "LaserMenuItem.hpp" +#include "BadgeUI.h" class Player { public: @@ -36,17 +36,17 @@ public: void setTeamID(unsigned short tID) { this->tID = tID; } - void setHealthMenuItem(LaserMenuItem *healthMenuItem) { + void setHealthMenuItem(MenuItem *healthMenuItem) { if (healthMenuItem) { delete healthMenuItem; } this->healthMenuItem = healthMenuItem; } - void setArmorMenuItem(LaserMenuItem *armorMenuItem) { + void setArmorMenuItem(MenuItem *armorMenuItem) { if (armorMenuItem) { delete armorMenuItem; } this->armorMenuItem = armorMenuItem; } - void setAmmoMenuItem(LaserMenuItem *ammoMenuItem) { + void setAmmoMenuItem(MenuItem *ammoMenuItem) { if (ammoMenuItem) { delete ammoMenuItem; } this->ammoMenuItem = ammoMenuItem; } @@ -91,8 +91,8 @@ protected: void updateAmmoMenuItem(); - LaserMenuItem *healthMenuItem; - LaserMenuItem *armorMenuItem; - LaserMenuItem *ammoMenuItem; + MenuItem *healthMenuItem; + MenuItem *armorMenuItem; + MenuItem *ammoMenuItem; }; #endif //GPN_LASERTAG_PLAYER_HPP diff --git a/PlayerListMenu.hpp b/PlayerListMenu.hpp index 74c5eb55f16b494f1bbc1d092eeea0a9a0b5c063..03d699c08db83d9fe0123e98a8a11c8981a11002 100644 --- a/PlayerListMenu.hpp +++ b/PlayerListMenu.hpp @@ -86,11 +86,6 @@ public: } }; - void addMenuItem(MenuItem *item) { - numItems++; - Menu::addMenuItem(item); - } - private: std::function<void(void)> leftAction; std::function<void(void)> rightAction;