Skip to content

Commit

Permalink
Small improvements and final tweaks for release
Browse files Browse the repository at this point in the history
Resolution for timestamp sent in gamedata increased to milliseconds
when "Do you want to quit/leave" is showed pressing Enter = yes
Register button that launches web-browser to homepage in the login box
  • Loading branch information
kroyee committed Jul 1, 2017
1 parent 5ce77c3 commit 11c0187
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 13 deletions.
22 changes: 20 additions & 2 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void UI::gameInput(sf::Event& event) {
}
else if (gamestate == GameOver) {
if (event.type == sf::Event::KeyPressed && !chatFocused) {
if (event.key.code == sf::Keyboard::Return) {
if (event.key.code == sf::Keyboard::Return && !areYouSure->isVisible()) {
if (playonline) {
game.gameover=false;
if (gameplayUI->isVisible())
Expand Down Expand Up @@ -601,13 +601,18 @@ void UI::keyEvents(sf::Event& event) {
}
}
}
else if (event.key.code == sf::Keyboard::Return)
if (areYouSure->isVisible())
areYouSure->ausY();
}
}

void UI::sendGameData() {
sf::Time tmp = game.gameclock.getElapsedTime();
if (tmp>gamedata) {
gamedata=tmp+sf::milliseconds(100);
gamedata+=sf::milliseconds(100);
if (gamedata < tmp)
gamedata=tmp+sf::milliseconds(100);
sendGameState();
}

Expand Down Expand Up @@ -670,6 +675,14 @@ void UI::sendGameWinner() {
game.winner=false;
}

void UI::iGotKicked(sf::Uint16 reason) {
if (reason == 1)
quickMsg("Kicked: game Clock out of sync");
else
quickMsg("Kicked from room for unknown reason");
setGameState(MainMenu);
}

void UI::handlePacket() {
if (net.packetid <100)
cout << "Packet id: " << (int)net.packetid << endl;
Expand All @@ -682,6 +695,7 @@ void UI::handlePacket() {
mainMenu->enable();
loginBox->hide();
challengesGameUI->hide();
replayUI->hide();
playonline=false;
performanceOutput->ping->hide();
setGameState(MainMenu);
Expand Down Expand Up @@ -898,6 +912,7 @@ void UI::handlePacket() {
sf::Uint16 clientid;
net.packet >> clientid >> pingId;
if (pingId == performanceOutput->pingIdCount) {
net.sendUDP();
sf::Time pingResult = delayClock.getElapsedTime() - performanceOutput->pingTime;
performanceOutput->setPing(pingResult.asMilliseconds());
performanceOutput->pingReturned=true;
Expand Down Expand Up @@ -1041,5 +1056,8 @@ void UI::handleSignal() {
field.drawField();
}
break;
case 17: // Got kicked from room
iGotKicked(id1);
break;
}
}
2 changes: 2 additions & 0 deletions src/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class UI {
void quickMsg(const sf::String& msg);
void receiveRecording();

void iGotKicked(sf::Uint16 reason);

void disconnect();

GameFieldDrawer gameFieldDrawer;
Expand Down
36 changes: 29 additions & 7 deletions src/gui/LoginBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,59 @@ void LoginBox::create(sf::Rect<int> _pos, UI* _gui) {

tgui::Label::Ptr LiL1 = gui->themeTG->load("Label");
LiL1->setText("Username");
LiL1->setPosition(20, 20);
LiL1->setPosition(20, 10);
panel->add(LiL1);

tgui::Label::Ptr LiL2 = gui->themeTG->load("Label");
LiL2->setText("Password");
LiL2->setPosition(220, 20);
LiL2->setPosition(220, 10);
panel->add(LiL2);

LiE1 = gui->themeTG->load("EditBox");
LiE1->setPosition(10, 60);
LiE1->setPosition(10, 40);
LiE1->setSize(180, 30);
LiE1->connect("Focused Unfocused", &UI::chatFocus, gui, std::bind(&tgui::Widget::isFocused, LiE1));
panel->add(LiE1);

tgui::EditBox::Ptr LiE2 = gui->themeTG->load("EditBox");
LiE2->setPosition(210, 60);
LiE2->setPosition(210, 40);
LiE2->setSize(180, 30);
LiE2->setPasswordCharacter('*');
LiE2->connect("ReturnKeyPressed", &LoginBox::login, this, std::bind(&tgui::EditBox::getText, LiE1), std::bind(&tgui::EditBox::getText, LiE2), 0);
LiE2->connect("Focused Unfocused", &UI::chatFocus, gui, std::bind(&tgui::Widget::isFocused, LiE2));
panel->add(LiE2);

tgui::Button::Ptr LiB1 = gui->themeBB->load("Button");
LiB1->setPosition(50, 110);
LiB1->setPosition(50, 80);
LiB1->setSize(100, 40);
LiB1->setOpacity(0.7);
LiB1->setText("Login");
LiB1->connect("pressed", &LoginBox::login, this, std::bind(&tgui::EditBox::getText, LiE1), std::bind(&tgui::EditBox::getText, LiE2), 0);
panel->add(LiB1);

tgui::Button::Ptr LiB2 = gui->themeBB->load("Button");
LiB2->setPosition(250, 110);
LiB2->setPosition(250, 80);
LiB2->setSize(100, 40);
LiB2->setOpacity(0.7);
LiB2->setText("Cancel");
LiB2->connect("Pressed", &LoginBox::closeLogin, this);
panel->add(LiB2);

tgui::Label::Ptr regLabel = gui->themeTG->load("Label");
regLabel->setPosition(40, 140);
regLabel->setText("register at ");
panel->add(regLabel);

tgui::Button::Ptr regButton = gui->themeTG->load("Button");
regButton->setPosition(140, 135);
regButton->setSize(200, 30);
regButton->setText("http://speedblocks.se");
regButton->connect("pressed", &LoginBox::regPressed, this);
panel->add(regButton);

tgui::Label::Ptr LiL3 = gui->themeTG->load("Label");
LiL3->setText("Guest name");
LiL3->setPosition(145, 175);
LiL3->setPosition(145, 180);
panel->add(LiL3);

tgui::EditBox::Ptr LiE3 = gui->themeTG->load("EditBox");
Expand Down Expand Up @@ -120,4 +132,14 @@ void LoginBox::sendLogin(const sf::String& hashorname, sf::Uint8 guest) {
gui->net.packet.clear();
gui->net.packet << packetid << gui->clientVersion << guest << hashorname;
gui->net.sendTCP();
}

void LoginBox::regPressed() {
#ifdef _WIN32
system("start https://speedblocks.se");
#elif __APPLE__
system("open https://speedblocks.se");
#else
system("xdg-open https://speedblocks.se");
#endif
}
1 change: 1 addition & 0 deletions src/gui/LoginBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LoginBox : public guiBase {
void closeLogin();
void open();
void sendLogin(const sf::String& hashorname, sf::Uint8 guest);
void regPressed();
};

#endif
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using std::cout;
using std::endl;

#define CLIENT_VERSION 4
#define CLIENT_VERSION 5

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion src/resources/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using std::cout;
using std::endl;

network::network() : serverAdd("localhost"), tcpPort(21512), udpPort(21514) {
network::network() : serverAdd("82.102.5.7"), tcpPort(21512), udpPort(21514) {
tcpSock.setBlocking(false);
udpSock.setBlocking(false);
curl_global_init(CURL_GLOBAL_ALL);
Expand Down
7 changes: 5 additions & 2 deletions src/resources/packetcompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ void PacketCompress::compress() {
tmp = game->field.text.countdown;
addBits(tmp, 2);
if (!countdown) {
tmp = game->gameclock.getElapsedTime().asMilliseconds()/100;
addBits(tmp, 8);
sf::Uint16 timevalue = game->gameclock.getElapsedTime().asMilliseconds();
sf::Uint8 smallpart = timevalue % 256;
sf::Uint8 bigpart = (timevalue - smallpart) / 256;
addBits(smallpart, 8);
addBits(bigpart, 8);
}
}

Expand Down

0 comments on commit 11c0187

Please sign in to comment.