# HG changeset patch # User jose1711 # Date 1318085696 -7200 # Node ID 5a4ea2c7b9dfb3e61c9c69ed1a78251129fd00d6 # Parent 531f64292489ad5f7c8e2f16b64dd9d3c6418310# Parent e6426c6b2882df17469b888486b79d79b49857bb merge diff -r 531f64292489 -r 5a4ea2c7b9df .hgtags --- a/.hgtags Sat Oct 08 16:45:52 2011 +0200 +++ b/.hgtags Sat Oct 08 16:54:56 2011 +0200 @@ -42,3 +42,7 @@ 0000000000000000000000000000000000000000 0.9.9 fee68e3a303998fdfcc69f74775dc84a36f587fb 0.9.9.1 0000000000000000000000000000000000000000 0.9.9.1 +718f98a9df122d73f3ba9add4d1654865199de31 Hedgewars-iOS-1.3 +cba92708277b6d0aeabfff2b878845b7d848bdcd Hedgewars-iOS-1.3.1 +74bc72746bec68806344f4ba7be0d1bc6e05d380 0.9.16-release +652a199d4f38f5becbec0839f5a1f63294dd89bf Hedgewars-iOS-1.3.2 diff -r 531f64292489 -r 5a4ea2c7b9df CMakeLists.txt --- a/CMakeLists.txt Sat Oct 08 16:45:52 2011 +0200 +++ b/CMakeLists.txt Sat Oct 08 16:54:56 2011 +0200 @@ -41,8 +41,8 @@ #versioning set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MINOR 9) -set(CPACK_PACKAGE_VERSION_PATCH 16${version_suffix}) -set(HEDGEWARS_PROTO_VER 38) +set(CPACK_PACKAGE_VERSION_PATCH 17${version_suffix}) +set(HEDGEWARS_PROTO_VER 40) set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") @@ -132,17 +132,17 @@ endif(APPLE) -#this snippet sets "Release" mode by default +#build Debug only when explicitally set if (NOT CMAKE_BUILD_TYPE) - set (CMAKE_BUILD_TYPE RELEASE CACHE STRING "Choose the type of build, options are: None Debug Release." FORCE) + set (CMAKE_BUILD_TYPE RELEASE CACHE STRING "Choose the type of build, options are: Debug Release." FORCE) endif (NOT CMAKE_BUILD_TYPE) -if(CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES "Release") +if(CMAKE_BUILD_TYPE MATCHES DEBUG OR CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "debug") + message(STATUS "Building Debug") + set(Optz false) +else() message(STATUS "Building Release") set(Optz true) -else() - message(STATUS "Building Debug") - set(Optz false) endif() @@ -262,10 +262,10 @@ "config\\\\.inc$" "hwengine\\\\.desktop$" "CMakeCache\\\\.txt$" - "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" - "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype" - "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" - "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libopenalbridge" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libfreetype" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/liblua" +# "^${CMAKE_CURRENT_SOURCE_DIR}/misc/libtremor" "^${CMAKE_CURRENT_SOURCE_DIR}/project_files/HedgewarsMobile/" "^${CMAKE_CURRENT_SOURCE_DIR}/bin/[a-z]" "^${CMAKE_CURRENT_SOURCE_DIR}/tools/templates" diff -r 531f64292489 -r 5a4ea2c7b9df CREDITS --- a/CREDITS Sat Oct 08 16:45:52 2011 +0200 +++ b/CREDITS Sat Oct 08 16:54:56 2011 +0200 @@ -48,4 +48,16 @@ ========== - Stephen Alexander +========== += SOUNDS +========== +- Mine impact sound from http://www.freesound.org/people/adcbicycle/sounds/13947/ +- Hammer sound from http://www.freesound.org/people/Syna-Max/sounds/43586/ +- Sinegun firing sound remixed from + http://beta.freesound.org/people/aust_paul/sounds/30935/ + http://www.freesound.org/people/Edgar/sounds/162/ + http://www.freesound.org/people/Ionizing/sounds/22033/ + http://www.freesound.org/people/Jovica/sounds/38317/ + + ALL OTHER CONTENT IS PROPERTY OF Andrey Korotaev UNLESS OTHERWISE SPECIFIED \ No newline at end of file diff -r 531f64292489 -r 5a4ea2c7b9df ChangeLog.txt --- a/ChangeLog.txt Sat Oct 08 16:45:52 2011 +0200 +++ b/ChangeLog.txt Sat Oct 08 16:54:56 2011 +0200 @@ -1,20 +1,34 @@ + features * bugfixes -0.9.15 -> ???: - + New modes: The Specialists, Space Invasion +0.9.15 -> 0.9.16: + + In-game chat now supports backspace-repeat and Escape to close the text input area + + Team status bars shrunk/made translucent if they take up a significant portion of the screen + + Background music change on sudden death mode + + Stereoscopic rendering + Installing content (anything under Data/ - maps, sounds, and any such stuff) to user profile allows custom adding/overriding of any Data/ content + + Screen for downloadable content + + Allow up to 8 teams in a game + + New gameplay modes/styles: Racer, The Specialists, Tumbler, Space Invasion, Balanced Random Weapon + + New single player missions: Bamboo Thicket, That Sinking Feeling, Newton and the Tree + + New Weapon/Utility: Land Spray Gun + + New Utility: Time Box + + New Game mode: Tag team + + New Game option for map bottom border + + New Theme: Golf + + Many new hats + Sudden Death art - + New Weapon/Utility: Land Spray Gun - + New Game mode: Tag team + Get away time modifier (in %) - + Allow up to 8 teams in a game + Shoppa scheme by default resets ammo + Shots are on a tenth of a second delay instead of a 1 and a quarter second delay (fast deagle/portal fire) + Defective mines explode if they take enough damage + Rope head can attach to hogs/crates/barrels again (rope still passes through them) + Control of grenade bounce + Drill Strike bombs don't explode when leaving ground, but after a (customizable!) timer + + Hammer impacts mines/barrels + + Seduction is an Area-of-Effect attack now + + Significantly altered flame behavior and damage. + + 'Throwing' weapons into hogs (e.g. grenade) no longer does max damage. + Ukranian localization of Default voice. support for localized voices + Theme cleanup, including the new theme config file change + Improvements in scoring and tracking damage @@ -22,23 +36,32 @@ + Mudball does not end turn + Indicator for height of plane when using napalm + Land smoothing (looks less pixelated on generation and damage) - + Improved lua script support (e.g. possibility to change hats) + + Improved lua script support (e.g. set per-hog ammo, place girders, spawn fake crates, switch hogs, change hats) + + The names of the ShoppaKingTournament winners are now written on the Trophies in the ShoppaKing and TrophyRace maps! + + Allow window resizes during game + + Improved fullscreen capabilities + + Additional/new sounds (mine impact, sine gun, etc) + + Victory/flawless victory sounds + * Voices don't overlap (was needed more due to faster game actions due to shortened delays) * Prevent portaling to impossible locations better * Snow accumulates more smoothly * Rope should be less sticky now + * Rope shouldn't be able to get Hogs stuck on walls anymore * Fix for last portal shot always being yellow * More accurate napalm strike drop location - * AI fixes + * AI fixes (heh, yeah right) * Fixed locales, such as korean * Code refactoring * Various bug/leak fixes Frontend/Menu and Netgame: - + Drawing straight lines in drawn map mode + + Drawing straight lines in drawn map mode (hold down the control key when clicking, then move mouse to end point and release). + + Undo clear in drawn map mode + Autokick ignored players joining your room + Improved nick sorting in lobby and rooms. (not case-sensitive, letters first, friend @ top, ignored @ bottom) + Display player count in lobby + Lobby: Player names of online players can be clicked in chat directly so that you don't have to find them in the player list + + Room names can be changed by the room admin without recreating the room * Fix invisible icons in popup menus * Various fixes and adjustments diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/AbstractPage.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/AbstractPage.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,101 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "AbstractPage.h" + +AbstractPage::AbstractPage(QWidget* parent) +{ + Q_UNUSED(parent); + + font14 = new QFont("MS Shell Dlg", 14); +} + +void AbstractPage::initPage() +{ + QGridLayout * pageLayout = new QGridLayout(this); + + // stretch grid space for body and footer + pageLayout->setColumnStretch(0,0); + pageLayout->setColumnStretch(1,1); + pageLayout->setRowStretch(0,1); + pageLayout->setRowStretch(1,0); + + // add back/exit button + btnBack = formattedButton(":/res/Exit.png", true); + pageLayout->addWidget(btnBack, 1, 0, 1, 1, Qt::AlignLeft | Qt::AlignBottom); + + // add body layout as defined by the subclass + pageLayout->addLayout(bodyLayoutDefinition(), 0, 0, 1, 2); + + // add footer layout + QLayout * fld = footerLayoutDefinition(); + if (fld != NULL) + pageLayout->addLayout(fld, 1, 1); + + // connect signals + connect(btnBack, SIGNAL(clicked()), this, SIGNAL(goBack())); + connectSignals(); +} + +QPushButton * AbstractPage::formattedButton(const QString & btname, bool hasIcon) +{ + QPushButton * btn = new QPushButton(this); + + if (hasIcon) + { + const QIcon& lp=QIcon(btname); + QSize sz = lp.actualSize(QSize(65535, 65535)); + btn->setIcon(lp); + btn->setFixedSize(sz); + btn->setIconSize(sz); + btn->setFlat(true); + btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + } + else + { + btn->setFont(*font14); + btn->setText(btname); + } + return btn; +} + +QPushButton * AbstractPage::addButton(const QString & btname, QGridLayout* grid, int wy, int wx, bool hasIcon) +{ + QPushButton * btn = formattedButton(btname, hasIcon); + grid->addWidget(btn, wy, wx); + return btn; +} + +QPushButton * AbstractPage::addButton(const QString & btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, bool hasIcon) +{ + QPushButton * btn = formattedButton(btname, hasIcon); + grid->addWidget(btn, wy, wx, rowSpan, columnSpan); + return btn; +} + +QPushButton * AbstractPage::addButton(const QString & btname, QBoxLayout* box, int where, bool hasIcon) +{ + QPushButton * btn = formattedButton(btname, hasIcon); + box->addWidget(btn, where); + return btn; +} + +void AbstractPage::setBackButtonVisible(bool visible) +{ + btnBack->setVisible(visible); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/AbstractPage.h --- a/QTfrontend/AbstractPage.h Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/AbstractPage.h Sat Oct 08 16:54:56 2011 +0200 @@ -45,78 +45,51 @@ class QAbstractItemModel; class QSettings; class QSlider; +class QGridlayout; class AbstractPage : public QWidget { Q_OBJECT - public: + signals: + void goBack(); - protected: - AbstractPage(QWidget* parent = 0) { - Q_UNUSED(parent); - - font14 = new QFont("MS Shell Dlg", 14); - //setFocusPolicy(Qt::StrongFocus); - } - virtual ~AbstractPage() {}; + protected: + // constructor and virtual destructor + AbstractPage(QWidget * parent = 0); - QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, bool iconed = false) { - QPushButton* butt = new QPushButton(this); - if (!iconed) { - butt->setFont(*font14); - butt->setText(btname); - //butt->setStyleSheet("background-color: #0d0544"); - } else { - const QIcon& lp=QIcon(btname); - QSize sz = lp.actualSize(QSize(65535, 65535)); - butt->setIcon(lp); - butt->setFixedSize(sz); - butt->setIconSize(sz); - butt->setFlat(true); - butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - grid->addWidget(butt, wy, wx); - return butt; - }; + // call this in the constructor of your subclass + void initPage(); + + // the following methods are used during page construction + + // you MUST implement this method in your subclass + // only define layout, not behavior in here + virtual QLayout * bodyLayoutDefinition() = 0; + + // you CAN implement this method in your subclass + virtual QLayout * footerLayoutDefinition() { return NULL; }; - QPushButton* addButton(QString btname, QGridLayout* grid, int wy, int wx, int rowSpan, int columnSpan, bool iconed = false) { - QPushButton* butt = new QPushButton(this); - if (!iconed) { - butt->setFont(*font14); - butt->setText(btname); - } else { - const QIcon& lp=QIcon(btname); - QSize sz = lp.actualSize(QSize(65535, 65535)); - butt->setIcon(lp); - butt->setFixedSize(sz); - butt->setIconSize(sz); - butt->setFlat(true); - butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - grid->addWidget(butt, wy, wx, rowSpan, columnSpan); - return butt; - }; + // you CAN but most likely want to implement this method in your subclass + // keep in mind not to expose twidgets as public! + // instead define a signal with a meaningful name and connect the widget + // signals to your page signals + virtual void connectSignals() {}; + + virtual ~AbstractPage() {}; - QPushButton* addButton(QString btname, QBoxLayout* box, int where, bool iconed = false) { - QPushButton* butt = new QPushButton(this); - if (!iconed) { - butt->setFont(*font14); - butt->setText(btname); - } else { - const QIcon& lp=QIcon(btname); - QSize sz = lp.actualSize(QSize(65535, 65535)); - butt->setIcon(lp); - butt->setFixedSize(sz); - butt->setIconSize(sz); - butt->setFlat(true); - butt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - box->addWidget(butt, where); - return butt; - }; + QPushButton * formattedButton(const QString & btname, bool hasIcon = false); + QPushButton * addButton(const QString & btname, QGridLayout * grid, int wy, int wx, bool hasIcon = false); + QPushButton * addButton(const QString & btname, QGridLayout * grid, int wy, int wx, int rowSpan, int columnSpan, bool hasIcon = false); + QPushButton * addButton(const QString & btname, QBoxLayout * box, int where, bool hasIcon = false); - QFont * font14; + void setBackButtonVisible(bool visible = true); + + QFont * font14; + + private: + + QPushButton * btnBack; }; #endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/CMakeLists.txt Sat Oct 08 16:54:56 2011 +0200 @@ -1,5 +1,6 @@ # Configure for Qt4 set(QT_MIN_VERSION "4.5.0") +include(CheckLibraryExists) set(QT_USE_QTCORE TRUE) set(QT_USE_QTGUI TRUE) @@ -12,11 +13,28 @@ find_package(Qt4 REQUIRED) include(${QT_USE_FILE}) +# Check if we need zlib +check_library_exists(${QT_QTCORE_LIBRARY} inflateInit2_ ${QT_LIBRARY_DIR} QT_PROVIDES_ZLIB_FUNCTIONS) + +if(NOT QT_PROVIDES_ZLIB_FUNCTIONS) + find_package(ZLIB REQUIRED) + + set(HW_LINK_LIBS ${ZLIB_LIBRARIES} ${HW_LINK_LIBS}) +endif() + + # Configure for SDL find_package(SDL REQUIRED) find_package(SDL_mixer REQUIRED) include_directories(.) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/model) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/net) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/dialog) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/page) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/widget) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util) include_directories(${SDL_INCLUDE_DIR}) include_directories(${SDLMIXER_INCLUDE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/misc/quazip) @@ -46,76 +64,30 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hwconsts.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp) +file(GLOB NetCpp net/*.cpp) +file(GLOB ModelCpp model/*.cpp) +file(GLOB_RECURSE UIcpp ui/*.cpp) +file(GLOB UtilCpp util/*.cpp) + set(hwfr_src - HWApplication.cpp + ${ModelCpp} + ${NetCpp} + ${UIcpp} + ${UtilCpp} + AbstractPage.cpp + achievements.cpp + binds.cpp + drawmapscene.cpp game.cpp + gameuiconfig.cpp + HWApplication.cpp + hwform.cpp main.cpp - hwform.cpp + mapContainer.cpp + SDLs.cpp team.cpp - namegen.cpp - teamselect.cpp - teamselhelper.cpp - frameTeam.cpp - vertScrollArea.cpp - gameuiconfig.cpp ui_hwform.cpp - gamecfgwidget.cpp - pagemain.cpp - pageeditteam.cpp - pagemultiplayer.cpp - pageoptions.cpp - pagenet.cpp - pagenetserver.cpp - pagenetgame.cpp - pageinfo.cpp - pagedata.cpp - pagesingleplayer.cpp - pagetraining.cpp - pagecampaign.cpp - pageselectweapon.cpp - pageingame.cpp - pageroomslist.cpp - pageconnecting.cpp - pagescheme.cpp - pagegamestats.cpp - pageplayrecord.cpp - pageadmin.cpp - pagenettype.cpp - pagedrawmap.cpp - SquareLabel.cpp - hats.cpp - hedgehogerWidget.cpp - hwmap.cpp - mapContainer.cpp - tcpBase.cpp - about.cpp - proto.cpp - fpsedit.cpp - netserver.cpp - newnetclient.cpp - netudpserver.cpp - netudpwidget.cpp - netregister.cpp - netserverslist.cpp - chatwidget.cpp - binds.cpp - SDLs.cpp ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp - selectWeapon.cpp - itemNum.cpp - input_ip.cpp - igbox.cpp - weaponItem.cpp - misc.cpp - ammoSchemeModel.cpp - togglebutton.cpp - bgwidget.cpp - achievements.cpp - qaspectratiolayout.cpp - drawmapwidget.cpp - drawmapscene.cpp - themesmodel.cpp - databrowser.cpp ) #xfire integration @@ -134,77 +106,35 @@ set(hwfr_src ${hwfr_src} hedgewars.rc) endif(MINGW) +file(GLOB ModelHdr model/*.h) +file(GLOB NetHdr net/*.h) +file(GLOB_RECURSE UIhdr ui/*.h) +file(GLOB UtilHdr util/*.h) + + set(hwfr_moc_hdrs - HWApplication.h - game.h - hats.h - hwform.h - teamselect.h - teamselhelper.h - frameTeam.h - vertScrollArea.h - gameuiconfig.h - gamecfgwidget.h + ${ModelHdr} + ${NetHdr} + ${UIhdr} AbstractPage.h - pagenet.h - pagemultiplayer.h - pagenetserver.h - pageingame.h - pagetraining.h - pageeditteam.h - pageoptions.h - pagemain.h - pageinfo.h - pagedata.h - pagesingleplayer.h - pagenettype.h - pageconnecting.h - pagedrawmap.h - pagecampaign.h - pagenetgame.h - pageroomslist.h - pagegamestats.h - pageadmin.h - pagescheme.h - pageselectweapon.h - pageplayrecord.h - SquareLabel.h - hedgehogerWidget.h - hwmap.h + drawmapscene.h + game.h + gameuiconfig.h + HWApplication.h + hwform.h mapContainer.h - tcpBase.h - about.h - proto.h - fpsedit.h - netserver.h - newnetclient.h - netudpserver.h - netudpwidget.h - netregister.h - netserverslist.h - chatwidget.h SDLs.h - selectWeapon.h - itemNum.h - input_ip.h - igbox.h - weaponItem.h - misc.h - ammoSchemeModel.h - togglebutton.h - bgwidget.h - qaspectratiolayout.h - drawmapwidget.h - drawmapscene.h - themesmodel.h - databrowser.h ) set(hwfr_hdrs + ${UtilHdr} + team.h + achievements.h binds.h ui_hwform.h KB.h hwconsts.h + sdlkeys.h ) set(hwfr_rez hedgewars.qrc) @@ -216,7 +146,7 @@ if(APPLE) set(hwfr_src ${hwfr_src} InstallController.cpp CocoaInitializer.mm M3Panel.mm M3InstallController.m NSWorkspace_RBAdditions.m) - set(HW_LINK_LIBS IOKit) + set(HW_LINK_LIBS IOKit ${HW_LINK_LIBS}) if(NOT NOAUTOUPDATE) find_package(Sparkle) @@ -260,7 +190,7 @@ endif() -target_link_libraries(hedgewars ${HW_LINK_LIBS}) +target_link_libraries(hedgewars ${HW_LINK_LIBS}) install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir}) diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/SquareLabel.cpp --- a/QTfrontend/SquareLabel.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include "SquareLabel.h" -#include "hwform.h" - -SquareLabel::SquareLabel(QWidget * parent) : - QWidget(parent) -{ - if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); -} - -void SquareLabel::paintEvent(QPaintEvent * event) -{ - Q_UNUSED(event); - - QPainter painter(this); - int pixsize; - if (width() > height()) { - pixsize = height(); - painter.translate((width() - pixsize) / 2, 0); - } else { - pixsize = width(); - painter.translate(0, (height() - pixsize) / 2); - } - painter.drawPixmap(0, 0, pixsize, pixsize, pixmap.scaled(pixsize, pixsize, Qt::KeepAspectRatio)); -} - -void SquareLabel::setPixmap(const QPixmap & pixmap) -{ - this->pixmap = pixmap; - repaint(); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/SquareLabel.h --- a/QTfrontend/SquareLabel.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _SQUARELABEL_H -#define _SQUARELABEL_H - -#include -#include - -class SquareLabel : public QWidget -{ - Q_OBJECT - -public: - SquareLabel(QWidget * parent = 0); - - void setPixmap(const QPixmap & pixmap); -protected: - virtual void paintEvent(QPaintEvent * event); - -private: - QPixmap pixmap; - -}; - -#endif // _SQUARELABEL_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/about.cpp --- a/QTfrontend/about.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include "about.h" -#include "hwconsts.h" - -About::About(QWidget * parent) : - QWidget(parent) -{ - QGridLayout *mainLayout = new QGridLayout(this); - - QLabel *imageLabel = new QLabel; - QImage image(":/res/Hedgehog.png"); - imageLabel->setPixmap(QPixmap::fromImage(image)); - imageLabel->setScaledContents(true); - imageLabel->setMinimumWidth(2.8); - imageLabel->setMaximumWidth(280); - imageLabel->setMinimumHeight(30); - imageLabel->setMaximumHeight(300); - - mainLayout->addWidget(imageLabel, 0, 0, 2, 1); - - QLabel *lbl1 = new QLabel(this); - lbl1->setOpenExternalLinks(true); - lbl1->setText( - "" - "

Hedgewars

" - "

" + QLabel::tr("Version") + " " + *cVersionString + "

" - "

http://www.hedgewars.org/


" + - QLabel::tr("This program is distributed under the GNU General Public License") + - "
" - ); - lbl1->setWordWrap(true); - mainLayout->addWidget(lbl1, 0, 1); - - QTextBrowser *lbl2 = new QTextBrowser(this); - - lbl2->setOpenExternalLinks(true); - lbl2->setText( - "" + - QString("

") + - QLabel::tr("Developers:") + - "

" - "Engine, frontend, net server: Andrey Korotaev <unC0Rr@gmail.com>
" - "Many frontend improvements: Igor Ulyanov <disinbox@gmail.com>
" - "Many engine and frontend improvements: Derek Pomery <nemo@m8y.org>
" - "Drill rocket, Ballgun, RC Plane weapons: Martin Boze <afffect@gmail.com>
" - "Mine number and time game settings: David A. Cuadrado <krawek@gmail.com>
" - "Frontend improvements: Martin Minarik <ttsmj@pokec.sk>
" - "Frontend improvements: Kristian Lehmann <email@thexception.net>
" - "Mac OS X/iPhone port, OpenGL-ES conversion: Vittorio Giovara <vittorio.giovara@gmail.com>
" - "Gamepad and Lua integration: Mario Liebisch <mario.liebisch@gmail.com>
" - "Many engine improvements and graphics: Carlos Vives <mail@carlosvives.es>
" - "Few engine and frontend improvements: Richard Karolyi <sheepluva@ercatec.net>
" - "Maze maps: Henning Kühn <prg@cooco.de>
" - "Engine and frontend improvements: Henrik Rostedt <henrik.rostedt@gmail.com>
" - "Lua game modes and missions: John Lambert <redgrinner@gmail.com>
" - "Frontend improvements: Mayur Pawashe <zorgiepoo@gmail.com>
" - "Android port: Richard Deurwaarder <xeli@xelification.com>
" - "

" + - - QLabel::tr("Art:") + "

" - + QString::fromUtf8( - "

John Dum <fizzy@gmail.com>" - "
" - "Joshua Frese <joshfrese@gmail.com>" - "
" - "Stanko Tadić <stanko@mfhinc.net>" - "
" - "Julien Koesten <julienkoesten@aol.com>" - "
" - "Joshua O'Sullivan <coheedftw@hotmail.co.uk>" - "
" - "Nils Lück <nils.luck.design@gmail.com>" - "
" - "Guillaume Englert <genglert@hybird.org>" - "
" - "Hats: Trey Perry <tx.perry.j@gmail.com>" - "

") + - QLabel::tr("Sounds:") + "

" - "Hedgehogs voice: Stephen Alexander <ArmagonNo1@gmail.com>" - "
" - "John Dum <fizzy@gmail.com>" - "
" - "Jonatan Nilsson <jonatanfan@gmail.com>" - "
" - "Daniel Martin <elhombresinremedio@gmail.com>" - "

" + - - QLabel::tr("Translations:") + "

" - + QString::fromUtf8( - "Brazilian Portuguese: Romulo Fernandes Machado <abra185@gmail.com>
" - "Bulgarian: Svetoslav Stefanov
" - "Czech: Petr Řezáček <rezacek@gmail.com>
" - "Chinese: Jie Luo <lililjlj@gmail.com>
" - "English: Andrey Korotaev <unC0Rr@gmail.com>
" - "Finnish: Nina Kuisma <ninnnu@gmail.com>
" - "French: Antoine Turmel <geekshadow@gmail.com>
" - "German: Peter Hüwe <PeterHuewe@gmx.de>, Mario Liebisch <mario.liebisch@gmail.com>
" - "Greek: <talos_kriti@yahoo.gr>" - "Italian: Luca Bonora <bonora.luca@gmail.com>
" - "Japanese: ADAM Etienne <etienne.adam@gmail.com>
" - "Korean: Anthony Bellew <webmaster@anthonybellew.com>
" - "Lithuanian: Lukas Urbonas <lukasu08@gmail.com>
" - "Polish: Maciej Mroziński <mynick2@o2.pl>, Wojciech Latkowski <magik17l@gmail.com>, Piotr Mitana, Maciej Górny
" - "Portuguese: Fábio Canário <inufabie@gmail.com>
" - "Russian: Andrey Korotaev <unC0Rr@gmail.com>
" - "Slovak: Jose Riha
" - "Spanish: Carlos Vives <mail@carlosvives.es>
" - "Swedish: Niklas Grahn <raewolusjoon@yaoo.com>, Henrik Rostedt <henrik.rostedt@gmail.com>
" - "Ukrainian: Eugene V. Lyubimkin <jackyf.devel@gmail.com>, Igor Paliychuk <mansonigor@gmail.com>, Eugene Sakara <eresid@gmail.com>" - "

") + - - QLabel::tr("Special thanks:") + "

" - "Aleksey Andreev <blaknayabr@gmail.com>
" - "Aleksander Rudalev <alexv@pomorsu.ru>
" - "Natasha Korotaeva <layout@pisem.net>
" - "Adam Higerd (aka ahigerd at FreeNode)" - "

" - ); - mainLayout->addWidget(lbl2, 1, 1); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/about.h --- a/QTfrontend/about.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _ABOUT_H -#define _ABOUT_H - -#include - - -class About : public QWidget -{ - Q_OBJECT - -public: - About(QWidget * parent = 0); -}; - -#endif // _ABOUT_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ammoSchemeModel.cpp --- a/QTfrontend/ammoSchemeModel.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,786 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2005-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "ammoSchemeModel.h" -#include "hwconsts.h" - -QList defaultScheme = QList() - << QVariant("Default") // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(false) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(45) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(5) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(4) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(2) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - -AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : - QAbstractTableModel(parent), - fileConfig(fileName, QSettings::IniFormat) -{ - predefSchemesNames = QStringList() - << "Default" - << "Pro Mode" - << "Shoppa" - << "Clean Slate" - << "Minefield" - << "Barrel Mayhem" - << "Tunnel Hogs" - << "Fort Mode" - << "Timeless" - << "Thinking with Portals" - << "King Mode" - ; - - numberOfDefaultSchemes = predefSchemesNames.size(); - - spNames = QStringList() - << "name" // 0 - << "fortsmode" // 1 - << "divteams" // 2 - << "solidland" // 3 - << "border" // 4 - << "lowgrav" // 5 - << "laser" // 6 - << "invulnerability" // 7 - << "resethealth" // 8 - << "vampiric" // 9 - << "karma" // 10 - << "artillery" // 11 - << "randomorder" // 12 - << "king" // 13 - << "placehog" // 14 - << "sharedammo" // 15 - << "disablegirders" // 16 - << "disablelandobjects" // 17 - << "aisurvival" // 18 - << "infattack" // 19 - << "resetweps" // 20 - << "perhogammo" // 21 - << "disablewind" // 22 - << "morewind" // 23 - << "tagteam" // 24 - << "bottomborder" // 25 - << "damagefactor" // 26 - << "turntime" // 27 - << "health" // 28 - << "suddendeath" // 29 - << "caseprobability" // 30 - << "minestime" // 31 - << "minesnum" // 32 - << "minedudpct" // 33 - << "explosives" // 34 - << "healthprobability" // 35 - << "healthcaseamount" // 36 - << "waterrise" // 37 - << "healthdecrease" // 38 - << "ropepct" // 39 - << "getawaytime" // 40 - ; - - QList proMode; - proMode - << predefSchemesNames[1] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(true) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(15) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(0) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(0) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(2) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList shoppa; - shoppa - << predefSchemesNames[2] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(true) // solid land 3 - << QVariant(true) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(true) // shared ammo 15 - << QVariant(true) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(true) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(30) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(50) // sudden death 29 - << QVariant(1) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(0) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(0) // explosives 34 - << QVariant(0) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList cleanslate; - cleanslate - << predefSchemesNames[3] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(true) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(false) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(true) // inf. attack 19 - << QVariant(true) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(45) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(5) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(4) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(2) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList minefield; - minefield - << predefSchemesNames[4] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(true) // shared ammo 15 - << QVariant(true) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(30) // turn time 27 - << QVariant(50) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(0) // case prob 30 - << QVariant(0) // mines time 31 - << QVariant(80) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(0) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList barrelmayhem; - barrelmayhem - << predefSchemesNames[5] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(true) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(30) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(0) // case prob 30 - << QVariant(0) // mines time 31 - << QVariant(0) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(80) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList tunnelhogs; - tunnelhogs - << predefSchemesNames[6] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(true) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(true) // shared ammo 15 - << QVariant(true) // disable girders 16 - << QVariant(true) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(30) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(5) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(10) // mines number 32 - << QVariant(10) // mine dud pct 33 - << QVariant(10) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList forts; - forts - << predefSchemesNames[7] // name 0 - << QVariant(true) // fortsmode 1 - << QVariant(true) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(true) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(false) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(45) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(5) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(0) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(0) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList timeless; - timeless - << predefSchemesNames[8] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(false) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(true) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(9999) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(5) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(5) // mines number 32 - << QVariant(10) // mine dud pct 33 - << QVariant(2) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(30) // health case amt 36 - << QVariant(0) // water rise amt 37 - << QVariant(0) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList thinkingportals; - thinkingportals - << predefSchemesNames[9] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(true) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(false) // king 13 - << QVariant(false) // place hog 14 - << QVariant(false) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(45) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(2) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(5) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(5) // explosives 34 - << QVariant(25) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - QList kingmode; - kingmode - << predefSchemesNames[10] // name 0 - << QVariant(false) // fortsmode 1 - << QVariant(false) // team divide 2 - << QVariant(false) // solid land 3 - << QVariant(false) // border 4 - << QVariant(false) // low gravity 5 - << QVariant(false) // laser sight 6 - << QVariant(false) // invulnerable 7 - << QVariant(false) // reset health 8 - << QVariant(false) // vampiric 9 - << QVariant(false) // karma 10 - << QVariant(false) // artillery 11 - << QVariant(true) // random order 12 - << QVariant(true) // king 13 - << QVariant(false) // place hog 14 - << QVariant(false) // shared ammo 15 - << QVariant(false) // disable girders 16 - << QVariant(false) // disable land objects 17 - << QVariant(false) // AI survival 18 - << QVariant(false) // inf. attack 19 - << QVariant(false) // reset weps 20 - << QVariant(false) // per hog ammo 21 - << QVariant(false) // no wind 22 - << QVariant(false) // more wind 23 - << QVariant(false) // tag team 24 - << QVariant(false) // bottom border 25 - << QVariant(100) // damage modfier 26 - << QVariant(45) // turn time 27 - << QVariant(100) // init health 28 - << QVariant(15) // sudden death 29 - << QVariant(5) // case prob 30 - << QVariant(3) // mines time 31 - << QVariant(4) // mines number 32 - << QVariant(0) // mine dud pct 33 - << QVariant(2) // explosives 34 - << QVariant(35) // health case pct 35 - << QVariant(25) // health case amt 36 - << QVariant(47) // water rise amt 37 - << QVariant(5) // health dec amt 38 - << QVariant(100) // rope modfier 39 - << QVariant(100) // get away time 40 - ; - - - schemes.append(defaultScheme); - schemes.append(proMode); - schemes.append(shoppa); - schemes.append(cleanslate); - schemes.append(minefield); - schemes.append(barrelmayhem); - schemes.append(tunnelhogs); - schemes.append(forts); - schemes.append(timeless); - schemes.append(thinkingportals); - schemes.append(kingmode); - - - int size = fileConfig.beginReadArray("schemes"); - for (int i = 0; i < size; ++i) { - fileConfig.setArrayIndex(i); - - if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) - { - QList scheme; - - for (int k = 0; k < spNames.size(); ++k) - scheme << fileConfig.value(spNames[k], defaultScheme[k]); - - schemes.append(scheme); - } - } - fileConfig.endArray(); -} - -QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(section); - Q_UNUSED(orientation); - Q_UNUSED(role); - - return QVariant(); -} - -int AmmoSchemeModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - else - return schemes.size(); -} - -int AmmoSchemeModel::columnCount(const QModelIndex & parent) const -{ - if (parent.isValid()) - return 0; - else - return defaultScheme.size(); -} - -Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const -{ - Q_UNUSED(index); - - return - Qt::ItemIsEnabled - | Qt::ItemIsSelectable - | Qt::ItemIsEditable; -} - -bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) -{ - if (!index.isValid() || index.row() < numberOfDefaultSchemes - || index.row() >= schemes.size() - || index.column() >= defaultScheme.size() - || role != Qt::EditRole) - return false; - - schemes[index.row()][index.column()] = value; - - emit dataChanged(index, index); - return true; -} - -bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent) -{ - Q_UNUSED(count); - - beginInsertRows(parent, schemes.size(), schemes.size()); - - if (row == -1) - { - QList newScheme = defaultScheme; - newScheme[0] = QVariant(tr("new")); - schemes.insert(schemes.size(), newScheme); - } - else - { - QList newScheme = schemes[row]; - newScheme[0] = QVariant(tr("copy of") + " " + newScheme[0].toString()); - schemes.insert(schemes.size(), newScheme); - } - - endInsertRows(); - - return true; -} - -bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent) -{ - if(count != 1 - || row < numberOfDefaultSchemes - || row >= schemes.size()) - return false; - - beginRemoveRows(parent, row, row); - - schemes.removeAt(row); - - endRemoveRows(); - - return true; -} - -QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.row() < 0 - || index.row() >= schemes.size() - || index.column() >= defaultScheme.size() - || (role != Qt::EditRole && role != Qt::DisplayRole) - ) - return QVariant(); - - return schemes[index.row()][index.column()]; -} - -void AmmoSchemeModel::Save() -{ - fileConfig.beginWriteArray("schemes", schemes.size() - numberOfDefaultSchemes); - - for (int i = 0; i < schemes.size() - numberOfDefaultSchemes; ++i) { - fileConfig.setArrayIndex(i); - - QList scheme = schemes[i + numberOfDefaultSchemes]; - - for (int k = 0; k < scheme.size(); ++k) - fileConfig.setValue(spNames[k], scheme[k]); - } - fileConfig.endArray(); -} - - -NetAmmoSchemeModel::NetAmmoSchemeModel(QObject * parent) : - QAbstractTableModel(parent) -{ - netScheme = defaultScheme; -} - -QVariant NetAmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(section); - Q_UNUSED(orientation); - Q_UNUSED(role); - - return QVariant(); -} - -int NetAmmoSchemeModel::rowCount(const QModelIndex & parent) const -{ - if (parent.isValid()) - return 0; - else - return 1; -} - -int NetAmmoSchemeModel::columnCount(const QModelIndex & parent) const -{ - if (parent.isValid()) - return 0; - else - return defaultScheme.size(); -} - -QVariant NetAmmoSchemeModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.row() < 0 - || index.row() > 1 - || index.column() >= defaultScheme.size() - || (role != Qt::EditRole && role != Qt::DisplayRole) - ) - return QVariant(); - - return netScheme[index.column()]; -} - -void NetAmmoSchemeModel::setNetSchemeConfig(QStringList & cfg) -{ - if(cfg.size() != netScheme.size()) - { - qWarning("Incorrect scheme cfg size"); - return; - } - - for(int i = 0; i < cfg.size(); ++i) - netScheme[i] = QVariant(cfg[i]); - - reset(); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ammoSchemeModel.h --- a/QTfrontend/ammoSchemeModel.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2005-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _AMMO_SCHEME_MODEL_INCLUDED -#define _AMMO_SCHEME_MODEL_INCLUDED - -#include -#include -#include -#include - -class AmmoSchemeModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - AmmoSchemeModel(QObject * parent, const QString & fileName); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - int rowCount(const QModelIndex & parent) const; - int columnCount(const QModelIndex & parent) const; - Qt::ItemFlags flags(const QModelIndex & index) const; - bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); - bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex()); - bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); - QVariant data(const QModelIndex &index, int role) const; - - int numberOfDefaultSchemes; - QStringList predefSchemesNames; - QStringList spNames; - -public slots: - void Save(); - -signals: - void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight); - -protected: - QList< QList > schemes; - -private: - QSettings fileConfig; -}; - -class NetAmmoSchemeModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - NetAmmoSchemeModel(QObject * parent); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - int rowCount(const QModelIndex & parent) const; - int columnCount(const QModelIndex & parent) const; - QVariant data(const QModelIndex &index, int role) const; - -public slots: - void setNetSchemeConfig(QStringList & cfg); - -private: - QList netScheme; -}; - -#endif // _AMMO_SCHEME_MODEL_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/bgwidget.cpp --- a/QTfrontend/bgwidget.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2009 Kristian Lehmann - * Copyright (c) 2009-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "bgwidget.h" - -SpritePosition::SpritePosition(QWidget * parent, int sh) -{ - wParent = parent; - iSpriteHeight = sh; - reset(); -} - -SpritePosition::~SpritePosition() -{ -} - -void SpritePosition::move() -{ - fX += fXMov; - fY += fYMov; - iAngle += 4; - if (iAngle >= 360) iAngle = 0; - if (fY > wParent->height()) reset(); -} - -void SpritePosition::reset() -{ - fY = -1 * iSpriteHeight; - fX = (qrand() % ((int)(wParent->width() * 1.5))) - wParent->width()/2; - fYMov = ((qrand() % 400)+300) / 100.0f; - fXMov = fYMov * 0.2f+((qrand()%100)/100.0f * 0.6f); //so between 0.2 and 0.6, or 0.5 +/- 0.3 - iAngle = qrand() % 360; -} - -QPoint SpritePosition::pos() -{ - return QPoint((int)fX,(int)fY); -} - -int SpritePosition::getAngle() -{ - return iAngle; -} - -void SpritePosition::init() -{ - fY = qrand() % (wParent->height() + 1); - fX = qrand() % (wParent->width() + 1); -} - -BGWidget::BGWidget(QWidget * parent) : QWidget(parent) -{ - setAttribute(Qt::WA_NoSystemBackground, true); - sprite.load(":/res/Star.png"); - - setAutoFillBackground(false); - - for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height()); - - for (int i = 0; i < 360; i++) - { - rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32); - rotatedSprites[i]->fill(0); - - QPoint translate(sprite.width()/2, sprite.height()/2); - - QPainter p; - p.begin(rotatedSprites[i]); - // p.setRenderHint(QPainter::Antialiasing); - p.setRenderHint(QPainter::SmoothPixmapTransform); - p.translate(translate.x(), translate.y()); - p.rotate(i); - p.translate(-1*translate.x(), -1*translate.y()); - p.drawImage(0, 0, sprite); - } - - timerAnimation = new QTimer(); - connect(timerAnimation, SIGNAL(timeout()), this, SLOT(animate())); - timerAnimation->setInterval(ANIMATION_INTERVAL); -} - -BGWidget::~BGWidget() -{ - for (int i = 0; i < SPRITE_MAX; i++) delete spritePositions[i]; - for (int i = 0; i < 360; i++) delete rotatedSprites[i]; - delete timerAnimation; -} - -void BGWidget::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - - QPainter p; - p.begin(this); - //p.setRenderHint(QPainter::Antialiasing); - for (int i = 0; i < SPRITE_MAX; i++) - { - QPoint point = spritePositions[i]->pos(); - p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()]); - } - p.end(); -} - -void BGWidget::animate() -{ - for (int i = 0; i < SPRITE_MAX; i++) - { - // bottom edge of star *seems* clipped, but in fact, if I switch to just plain old repaint()/update() it is still clipped - artifact of transform? As for 5, is arbitrary number. 4 was noticeably clipping, 5 seemed same as update() - I assume extra room is due to rotation and value really should be calculated proportional to width/height - update(spritePositions[i]->pos().x(),spritePositions[i]->pos().y(), sprite.width()+5, sprite.height()+5); - spritePositions[i]->move(); - } -} - -void BGWidget::startAnimation() -{ - timerAnimation->start(); -} - -void BGWidget::stopAnimation() -{ - timerAnimation->stop(); -} - -void BGWidget::init() -{ - for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i]->init(); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/bgwidget.h --- a/QTfrontend/bgwidget.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2009 Kristian Lehmann - * Copyright (c) 2009-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef BGWIDGET_H -#define BGWIDGET_H - -#include -//#include -#include -#include -#include -#include -#include - -#define SPRITE_MAX 12 - -#define ANIMATION_INTERVAL 40 - -class SpritePosition -{ -public: - SpritePosition(QWidget * parent, int sh); - ~SpritePosition(); -private: - float fX; - float fY; - float fXMov; - float fYMov; - int iAngle; - QWidget * wParent; - int iSpriteHeight; -public: - void move(); - void reset(); - QPoint pos(); - int getAngle(); - void init(); -}; - -class BGWidget : public QWidget -{ - Q_OBJECT -public: - BGWidget(QWidget * parent); - ~BGWidget(); - void startAnimation(); - void stopAnimation(); - void init(); -private: - QImage sprite; - QTimer * timerAnimation; - SpritePosition * spritePositions[SPRITE_MAX]; - QImage * rotatedSprites[360]; -protected: - void paintEvent(QPaintEvent * event); -private slots: - void animate(); -}; - -#endif // BGWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/binds.cpp --- a/QTfrontend/binds.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/binds.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -62,9 +62,7 @@ {"confirm", "y", QT_TRANSLATE_NOOP("binds", "confirmation"), NULL, NULL}, {"+voldown", "9", QT_TRANSLATE_NOOP("binds", "volume down"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Modify the game's volume while playing:")}, {"+volup", "0", QT_TRANSLATE_NOOP("binds", "volume up"), NULL, NULL}, -#ifndef _WIN32 {"fullscr", "f12", QT_TRANSLATE_NOOP("binds", "change mode"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Toggle fullscreen mode:")}, -#endif {"capture", "c", QT_TRANSLATE_NOOP("binds", "capture"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Take a screenshot:")}, {"rotmask", "delete", QT_TRANSLATE_NOOP("binds", "hedgehogs\ninfo"), NULL, QT_TRANSLATE_NOOP("binds (descriptions)", "Toggle labels above hedgehogs:")} }; diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/binds.h --- a/QTfrontend/binds.h Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/binds.h Sat Oct 08 16:54:56 2011 +0200 @@ -21,11 +21,7 @@ #include -#ifdef _WIN32 -#define BINDS_NUMBER 43 -#else #define BINDS_NUMBER 44 -#endif struct BindAction { diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/chatwidget.cpp --- a/QTfrontend/chatwidget.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,573 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hwconsts.h" -#include "SDLs.h" -#include "gameuiconfig.h" -#include "chatwidget.h" - -ListWidgetNickItem::ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored) : QListWidgetItem(nick) -{ - this->aFriend = isFriend; - this->isIgnored = isIgnored; -} - -void ListWidgetNickItem::setFriend(bool isFriend) -{ - this->aFriend = isFriend; -} - -void ListWidgetNickItem::setIgnored(bool isIgnored) -{ - this->isIgnored = isIgnored; -} - -bool ListWidgetNickItem::isFriend() -{ - return aFriend; -} - -bool ListWidgetNickItem::ignored() -{ - return isIgnored; -} - -bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const -{ - // case in-sensitive comparison of the associated strings - // chars that are no letters are sorted at the end of the list - - ListWidgetNickItem otherNick = const_cast(dynamic_cast(other)); - - // ignored always down - if (isIgnored != otherNick.ignored()) - return !isIgnored; - - // friends always up - if (aFriend != otherNick.isFriend()) - return aFriend; - - QString txt1 = text().toLower(); - QString txt2 = other.text().toLower(); - - bool firstIsShorter = (txt1.size() < txt2.size()); - int len = firstIsShorter?txt1.size():txt2.size(); - - for (int i = 0; i < len; i++) - { - if (txt1[i] == txt2[i]) - continue; - if (txt1[i].isLetter() != txt2[i].isLetter()) - return txt1[i].isLetter(); - return (txt1[i] < txt2[i]); - } - - return firstIsShorter; -} - -const char* HWChatWidget::STYLE = -"\ -a { color:#c8c8ff; }\ -.nick { text-decoration: none; }\ -.UserChat .nick { color:#ffec20; }\ -.FriendChat { color: #08e008; }\ -.FriendChat .nick { color: #20ff20; }\ -.UserJoin { color: #c0c0c0; }\ -.UserJoin .nick { color: #d0d0d0; }\ -.FriendJoin { color: #c0e0c0; }\ -.FriendJoin .nick { color: #d0f0d0; }\ -.UserAction { color: #ff80ff; }\ -.UserAction .nick { color: #ffa0ff; }\ -.FriendAction { color: #ff00ff; }\ -.FriendAction .nick { color: #ff30ff; }\ -"; - -HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify) : - QWidget(parent), - mainLayout(this) -{ - this->gameSettings = gameSettings; - this->sdli = sdli; - this->notify = notify; - if(notify && gameSettings->value("frontend/sound", true).toBool()) { - QFile tmpfile; - sdli->SDLMusicInit(); - for(int i=0;i<4;i++) { - tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Sounds/voices/Classic/Hello.ogg"); - if (tmpfile.exists()) sound[i] = Mix_LoadWAV(QFileInfo(tmpfile).absoluteFilePath().toLocal8Bit().constData()); - else sound[i] = Mix_LoadWAV(QString(datadir->absolutePath() + - "/Sounds/voices/Classic/Hello.ogg").toLocal8Bit().constData()); - } - } - - mainLayout.setSpacing(1); - mainLayout.setMargin(1); - mainLayout.setSizeConstraint(QLayout::SetMinimumSize); - mainLayout.setColumnStretch(0, 76); - mainLayout.setColumnStretch(1, 24); - - chatEditLine = new QLineEdit(this); - chatEditLine->setMaxLength(300); - connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed())); - - mainLayout.addWidget(chatEditLine, 2, 0); - - chatText = new QTextBrowser(this); - chatText->document()->setDefaultStyleSheet(STYLE); - chatText->setMinimumHeight(20); - chatText->setMinimumWidth(10); - chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - chatText->setOpenLinks(false); - connect(chatText, SIGNAL(anchorClicked(const QUrl&)), - this, SLOT(linkClicked(const QUrl&))); - mainLayout.addWidget(chatText, 0, 0, 2, 1); - - chatNicks = new QListWidget(this); - chatNicks->setMinimumHeight(10); - chatNicks->setMinimumWidth(10); - chatNicks->setSortingEnabled(true); - chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu); - connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)), - this, SLOT(chatNickDoubleClicked(QListWidgetItem *))); - connect(chatNicks, SIGNAL(currentRowChanged(int)), - this, SLOT(chatNickSelected(int))); - - mainLayout.addWidget(chatNicks, 0, 1, 3, 1); - - acInfo = new QAction(QAction::tr("Info"), chatNicks); - acInfo->setIcon(QIcon(":/res/info.png")); - connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo())); - acKick = new QAction(QAction::tr("Kick"), chatNicks); - acKick->setIcon(QIcon(":/res/kick.png")); - connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick())); - acBan = new QAction(QAction::tr("Ban"), chatNicks); - acBan->setIcon(QIcon(":/res/ban.png")); - connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan())); - acFollow = new QAction(QAction::tr("Follow"), chatNicks); - acFollow->setIcon(QIcon(":/res/follow.png")); - connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow())); - acIgnore = new QAction(QAction::tr("Ignore"), chatNicks); - acIgnore->setIcon(QIcon(":/res/ignore.png")); - connect(acIgnore, SIGNAL(triggered(bool)), this, SLOT(onIgnore())); - acFriend = new QAction(QAction::tr("Add friend"), chatNicks); - acFriend->setIcon(QIcon(":/res/addfriend.png")); - connect(acFriend, SIGNAL(triggered(bool)), this, SLOT(onFriend())); - - chatNicks->insertAction(0, acFriend); - chatNicks->insertAction(0, acInfo); - chatNicks->insertAction(0, acIgnore); - - showReady = false; - setShowFollow(true); -} - -void HWChatWidget::linkClicked(const QUrl & link) -{ - if (link.scheme() == "http") - QDesktopServices::openUrl(link); - if (link.scheme() == "hwnick") - { - // decode nick - const QString& nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery())); - QList items = chatNicks->findItems(nick, Qt::MatchExactly); - if (items.size() < 1) - return; - QMenu * popup = new QMenu(); - // selecting an item will automatically scroll there, so let's save old position - QScrollBar * scrollBar = chatNicks->verticalScrollBar(); - int oldScrollPos = scrollBar->sliderPosition(); - // select the nick which we want to see the actions for - chatNicks->setCurrentItem(items[0], QItemSelectionModel::Clear); - // selecting an item will automatically scroll there, so let's save old position - scrollBar->setSliderPosition(oldScrollPos); - // load actions - popup->addActions(chatNicks->actions()); - // display menu popup at mouse cursor position - popup->popup(QCursor::pos()); - } -} - -void HWChatWidget::setShowFollow(bool enabled) -{ - if (enabled) { - if (!(chatNicks->actions().contains(acFollow))) - chatNicks->insertAction(acFriend, acFollow); - } - else { - if (chatNicks->actions().contains(acFollow)) - chatNicks->removeAction(acFollow); - } -} - -void HWChatWidget::loadList(QStringList & list, const QString & file) -{ - list.clear(); - QFile txt(cfgdir->absolutePath() + "/" + file); - if(!txt.open(QIODevice::ReadOnly)) - return; - QTextStream stream(&txt); - stream.setCodec("UTF-8"); - - while(!stream.atEnd()) - { - QString str = stream.readLine(); - if(str.startsWith(";") || str.length() == 0) - continue; - list << str.trimmed(); - } - //readd once we require newer Qt than 4.4 - //list.removeDuplicates(); - txt.close(); -} - -void HWChatWidget::saveList(QStringList & list, const QString & file) -{ - QFile txt(cfgdir->absolutePath() + "/" + file); - if(!txt.open(QIODevice::WriteOnly | QIODevice::Truncate)) - return; - QTextStream stream(&txt); - stream.setCodec("UTF-8"); - - stream << "; this list is used by Hedgewars - do not edit it unless you know what you're doing!" << endl; - for(int i = 0; i < list.size(); i++) - stream << list[i] << endl; - txt.close(); -} - -void HWChatWidget::updateNickItem(QListWidgetItem *nickItem) -{ - QString nick = nickItem->text(); - ListWidgetNickItem * item = dynamic_cast(nickItem); - - item->setFriend(friendsList.contains(nick, Qt::CaseInsensitive)); - item->setIgnored(ignoreList.contains(nick, Qt::CaseInsensitive)); - - if(item->ignored()) - { - item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on.png" : ":/res/chat_ignore_off.png") : ":/res/chat_ignore.png")); - item->setForeground(Qt::gray); - } - else if(item->isFriend()) - { - item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on.png" : ":/res/chat_friend_off.png") : ":/res/chat_friend.png")); - item->setForeground(Qt::green); - } - else - { - item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on.png" : ":/res/chat_default_off.png") : ":/res/chat_default.png")); - item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00))); - } -} - -void HWChatWidget::updateNickItems() -{ - for(int i = 0; i < chatNicks->count(); i++) - updateNickItem(chatNicks->item(i)); - - chatNicks->sortItems(); -} - -void HWChatWidget::loadLists(const QString & nick) -{ - loadList(ignoreList, nick.toLower() + "_ignore.txt"); - loadList(friendsList, nick.toLower() + "_friends.txt"); - updateNickItems(); -} - -void HWChatWidget::saveLists(const QString & nick) -{ - saveList(ignoreList, nick.toLower() + "_ignore.txt"); - saveList(friendsList, nick.toLower() + "_friends.txt"); -} - -void HWChatWidget::returnPressed() -{ - emit chatLine(chatEditLine->text()); - chatEditLine->clear(); -} - - -void HWChatWidget::onChatString(const QString& str) -{ - onChatString("", str); -} - -const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http://)?(www\\.)?(hedgewars\\.org(/[^ ]*)?)"); - -void HWChatWidget::onChatString(const QString& nick, const QString& str) -{ - bool isFriend = false; - - if (!nick.isEmpty()) { - // don't show chat lines that are from ignored nicks - if (ignoreList.contains(nick, Qt::CaseInsensitive)) - return; - // friends will get special treatment, of course - isFriend = friendsList.contains(nick, Qt::CaseInsensitive); - } - - if (chatStrings.size() > 250) - chatStrings.removeFirst(); - - QString formattedStr = Qt::escape(str.mid(1)); - // make hedgewars.org urls actual links - formattedStr = formattedStr.replace(URLREGEXP, "\\3"); - - // "link" nick, but before that encode it in base64 to make sure it can't intefere with html/url syntax - // the nick is put as querystring as putting it as host would convert it to it's lower case variant - if(!nick.isEmpty()) - formattedStr.replace("|nick|",QString("%2").arg(QString(nick.toUtf8().toBase64())).arg(nick)); - - QString cssClass("UserChat"); - - // check first character for color code and set color properly - switch (str[0].toAscii()) { - case 3: - cssClass = (isFriend ? "FriendJoin" : "UserJoin"); - break; - case 2: - cssClass = (isFriend ? "FriendAction" : "UserAction"); - break; - default: - if (isFriend) - cssClass = "FriendChat"; - } - - formattedStr = QString("%1").arg(formattedStr).arg(cssClass); - - chatStrings.append(formattedStr); - - chatText->setHtml(chatStrings.join("
")); - - chatText->moveCursor(QTextCursor::End); -} - -void HWChatWidget::onServerMessage(const QString& str) -{ - if (chatStrings.size() > 250) - chatStrings.removeFirst(); - - chatStrings.append("
" + str + "
"); - - chatText->setHtml(chatStrings.join("
")); - - chatText->moveCursor(QTextCursor::End); -} - -void HWChatWidget::nickAdded(const QString& nick, bool notifyNick) -{ - QListWidgetItem * item = new ListWidgetNickItem(nick, friendsList.contains(nick, Qt::CaseInsensitive), ignoreList.contains(nick, Qt::CaseInsensitive)); - updateNickItem(item); - chatNicks->addItem(item); - - emit nickCountUpdate(chatNicks->count()); - - if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) { - Mix_PlayChannel(-1, sound[rand()%4], 0); - } -} - -void HWChatWidget::nickRemoved(const QString& nick) -{ - foreach(QListWidgetItem * item, chatNicks->findItems(nick, Qt::MatchExactly)) - chatNicks->takeItem(chatNicks->row(item)); - - emit nickCountUpdate(chatNicks->count()); -} - -void HWChatWidget::clear() -{ - chatText->clear(); - chatStrings.clear(); - chatNicks->clear(); -} - -void HWChatWidget::onKick() -{ - QListWidgetItem * curritem = chatNicks->currentItem(); - if (curritem) - emit kick(curritem->text()); -} - -void HWChatWidget::onBan() -{ - QListWidgetItem * curritem = chatNicks->currentItem(); - if (curritem) - emit ban(curritem->text()); -} - -void HWChatWidget::onInfo() -{ - QListWidgetItem * curritem = chatNicks->currentItem(); - if (curritem) - emit info(curritem->text()); -} - -void HWChatWidget::onFollow() -{ - QListWidgetItem * curritem = chatNicks->currentItem(); - if (curritem) - emit follow(curritem->text()); -} - -void HWChatWidget::onIgnore() -{ - QListWidgetItem * curritem = chatNicks->currentItem(); - if(!curritem) - return; - - if(ignoreList.contains(curritem->text(), Qt::CaseInsensitive)) // already on list - remove him - { - ignoreList.removeAll(curritem->text().toLower()); - onChatString(HWChatWidget::tr("%1 *** %2 has been removed from your ignore list").arg('\x03').arg(curritem->text())); - } - else // not on list - add - { - // don't consider ignored people friends - if(friendsList.contains(curritem->text(), Qt::CaseInsensitive)) - emit onFriend(); - - // scroll down on first ignore added so that people see where that nick went to - if (ignoreList.isEmpty()) - chatNicks->scrollToBottom(); - - ignoreList << curritem->text().toLower(); - onChatString(HWChatWidget::tr("%1 *** %2 has been added to your ignore list").arg('\x03').arg(curritem->text())); - } - updateNickItem(curritem); // update icon/sort order/etc - chatNicks->sortItems(); - chatNickSelected(0); // update context menu -} - -void HWChatWidget::onFriend() -{ - QListWidgetItem * curritem = chatNicks->currentItem(); - if(!curritem) - return; - - if(friendsList.contains(curritem->text(), Qt::CaseInsensitive)) // already on list - remove him - { - friendsList.removeAll(curritem->text().toLower()); - onChatString(HWChatWidget::tr("%1 *** %2 has been removed from your friends list").arg('\x03').arg(curritem->text())); - } - else // not on list - add - { - // don't ignore the new friend - if(ignoreList.contains(curritem->text(), Qt::CaseInsensitive)) - emit onIgnore(); - - // scroll up on first friend added so that people see where that nick went to - if (friendsList.isEmpty()) - chatNicks->scrollToTop(); - - friendsList << curritem->text().toLower(); - onChatString(HWChatWidget::tr("%1 *** %2 has been added to your friends list").arg('\x03').arg(curritem->text())); - } - updateNickItem(curritem); // update icon/sort order/etc - chatNicks->sortItems(); - chatNickSelected(0); // update context menu -} - -void HWChatWidget::chatNickDoubleClicked(QListWidgetItem * item) -{ - Q_UNUSED(item); - - QList actions = chatNicks->actions(); - actions.first()->activate(QAction::Trigger); -} - -void HWChatWidget::chatNickSelected(int index) -{ - Q_UNUSED(index); - - QListWidgetItem* item = chatNicks->currentItem(); - if (!item) - return; - - // update context menu labels according to possible action - if(ignoreList.contains(item->text(), Qt::CaseInsensitive)) - { - acIgnore->setText(QAction::tr("Unignore")); - acIgnore->setIcon(QIcon(":/res/unignore.png")); - } - else - { - acIgnore->setText(QAction::tr("Ignore")); - acIgnore->setIcon(QIcon(":/res/ignore.png")); - } - - if(friendsList.contains(item->text(), Qt::CaseInsensitive)) - { - acFriend->setText(QAction::tr("Remove friend")); - acFriend->setIcon(QIcon(":/res/remfriend.png")); - } - else - { - acFriend->setText(QAction::tr("Add friend")); - acFriend->setIcon(QIcon(":/res/addfriend.png")); - } -} - -void HWChatWidget::setShowReady(bool s) -{ - showReady = s; -} - -void HWChatWidget::setReadyStatus(const QString & nick, bool isReady) -{ - QList items = chatNicks->findItems(nick, Qt::MatchExactly); - if (items.size() != 1) - { - qWarning("Bug: cannot find user in chat"); - return; - } - - items[0]->setData(Qt::UserRole, isReady); // bulb status - updateNickItem(items[0]); - - // ensure we're still showing the status bulbs - showReady = true; -} - -void HWChatWidget::adminAccess(bool b) -{ - chatNicks->removeAction(acKick); - chatNicks->removeAction(acBan); - - if(b) - { - chatNicks->insertAction(0, acKick); -// chatNicks->insertAction(0, acBan); - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/chatwidget.h --- a/QTfrontend/chatwidget.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _CHAT_WIDGET_INCLUDED -#define _CHAT_WIDGET_INCLUDED - -#include -#include -#include -#include -#include - -#include "SDLs.h" - -class ListWidgetNickItem; -class QTextBrowser; -class QLineEdit; -class QListWidget; -class QSettings; -class SDLInteraction; - -// this class is for custom nick sorting -class ListWidgetNickItem : public QListWidgetItem -{ -public: - ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored); - bool operator<(const QListWidgetItem & other) const; - void setFriend(bool isFriend); - void setIgnored(bool isIgnored); - bool isFriend(); - bool ignored(); - -private: - bool aFriend; - bool isIgnored; -}; - -class HWChatWidget : public QWidget -{ - Q_OBJECT - - public: - HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify); - void loadLists(const QString & nick); - void saveLists(const QString & nick); - void setShowReady(bool s); - void setShowFollow(bool enabled); - static const char* STYLE; - QStringList ignoreList, friendsList; - -private: - void loadList(QStringList & list, const QString & file); - void saveList(QStringList & list, const QString & file); - void updateNickItem(QListWidgetItem *item); - void updateNickItems(); - static const QRegExp URLREGEXP; - - public slots: - void onChatString(const QString& str); - void onChatString(const QString& nick, const QString& str); - void onServerMessage(const QString& str); - void nickAdded(const QString& nick, bool notifyNick); - void nickRemoved(const QString& nick); - void clear(); - void setReadyStatus(const QString & nick, bool isReady); - void adminAccess(bool); - - signals: - void chatLine(const QString& str); - void kick(const QString & str); - void ban(const QString & str); - void info(const QString & str); - void follow(const QString &); - void nickCountUpdate(int cnt); - - private: - QGridLayout mainLayout; - QTextBrowser* chatText; - QStringList chatStrings; - QListWidget* chatNicks; - QLineEdit* chatEditLine; - QAction * acInfo; - QAction * acKick; - QAction * acBan; - QAction * acFollow; - QAction * acIgnore; - QAction * acFriend; - QSettings * gameSettings; - SDLInteraction * sdli; - Mix_Chunk *sound[4]; - bool notify; - bool showReady; - - private slots: - void returnPressed(); - void onBan(); - void onKick(); - void onInfo(); - void onFollow(); - void onIgnore(); - void onFriend(); - void chatNickDoubleClicked(QListWidgetItem * item); - void chatNickSelected(int index); - void linkClicked(const QUrl & link); -}; - -#endif // _CHAT_WIDGET_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/databrowser.cpp --- a/QTfrontend/databrowser.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -#include -#include -#include -#include -#include - -#include "databrowser.h" - -const QNetworkRequest::Attribute typeAttribute = (QNetworkRequest::Attribute)(QNetworkRequest::User + 1); -const QNetworkRequest::Attribute urlAttribute = (QNetworkRequest::Attribute)(QNetworkRequest::User + 2); - -DataBrowser::DataBrowser(QWidget *parent) : - QTextBrowser(parent) -{ - - manager = new QNetworkAccessManager(this); -} - -QVariant DataBrowser::loadResource(int type, const QUrl & name) -{ - if(type == QTextDocument::ImageResource || type == QTextDocument::StyleSheetResource) - { - if(resources.contains(name.toString())) - { - return resources.take(name.toString()); - } - else - if(!requestedResources.contains(name.toString())) - { - qDebug() << "Requesting resource" << name.toString(); - requestedResources.insert(name.toString()); - - QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + name.toString())); - newRequest.setAttribute(typeAttribute, type); - newRequest.setAttribute(urlAttribute, name); - - QNetworkReply *reply = manager->get(newRequest); - connect(reply, SIGNAL(finished()), this, SLOT(resourceDownloaded())); - } - } - - return QVariant(); -} - -void DataBrowser::resourceDownloaded() -{ - QNetworkReply * reply = qobject_cast(sender()); - - if(reply) - { - int type = reply->request().attribute(typeAttribute).toInt(); - QUrl url = reply->request().attribute(urlAttribute).toUrl(); - resources.insert(url.toString(), reply->readAll()); - document()->addResource(type, reply->request().url(), QVariant()); - update(); - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/databrowser.h --- a/QTfrontend/databrowser.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -#ifndef DATABROWSER_H -#define DATABROWSER_H - -#include -#include - -class QNetworkAccessManager; - -class DataBrowser : public QTextBrowser -{ - Q_OBJECT -public: - explicit DataBrowser(QWidget *parent = 0); - -signals: - -public slots: - -private: - QNetworkAccessManager *manager; - - // hash and set of QString instead of QUrl to support Qt versions - // older than 4.7 (those have no support for qHash(const QUrl &)) - QHash resources; - QSet requestedResources; - - QVariant loadResource(int type, const QUrl & name); - -private slots: - void resourceDownloaded(); -}; - -#endif // DATABROWSER_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/drawmapscene.cpp --- a/QTfrontend/drawmapscene.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/drawmapscene.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -108,11 +108,32 @@ emit pathChanged(); } + else if(oldItems.size()) + { + while(oldItems.size()) + addItem(oldItems.takeFirst()); + paths = oldPaths; + + emit pathChanged(); + } } void DrawMapScene::clearMap() { - clear(); + // don't clear if already cleared + if(!items().size()) + return; + + oldItems.clear(); + + // do this since clear() would _destroy_ all items + while(items().size()) { + oldItems.push_front(items().first()); + removeItem(items().first()); + } + + oldPaths = paths; + paths.clear(); emit pathChanged(); @@ -146,6 +167,8 @@ void DrawMapScene::decode(QByteArray data) { + oldItems.clear(); + oldPaths.clear(); clear(); paths.clear(); diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/drawmapscene.h --- a/QTfrontend/drawmapscene.h Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/drawmapscene.h Sat Oct 08 16:54:56 2011 +0200 @@ -48,6 +48,8 @@ QBrush m_brush; QGraphicsPathItem * m_currPath; Paths paths; + Paths oldPaths; + QList oldItems; virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent); virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent); diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/drawmapwidget.cpp --- a/QTfrontend/drawmapwidget.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "drawmapwidget.h" - -DrawMapWidget::DrawMapWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::DrawMapWidget) -{ - ui->setupUi(this); - - m_scene = 0; -} - -DrawMapWidget::~DrawMapWidget() -{ - delete ui; -} - -void DrawMapWidget::changeEvent(QEvent *e) -{ - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - -void DrawMapWidget::setScene(DrawMapScene * scene) -{ - ui->graphicsView->setScene(scene); - m_scene = scene; -} - -void DrawMapWidget::resizeEvent(QResizeEvent * event) -{ - Q_UNUSED(event); - - if(ui->graphicsView && ui->graphicsView->scene()) - ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); -} - -void DrawMapWidget::showEvent(QShowEvent * event) -{ - Q_UNUSED(event); - - resizeEvent(0); -} - -void DrawMapWidget::undo() -{ - if(m_scene) m_scene->undo(); -} - -void DrawMapWidget::clear() -{ - if(m_scene) m_scene->clearMap(); -} - -void DrawMapWidget::save(const QString & fileName) -{ - if(m_scene) - { - QFile file(fileName); - - if(!file.open(QIODevice::WriteOnly)) - QMessageBox::warning(this, tr("File error"), tr("Cannot open file '%1' for writing").arg(fileName)); - else - file.write(qCompress(m_scene->encode()).toBase64()); - } -} - -void DrawMapWidget::load(const QString & fileName) -{ - if(m_scene) - { - QFile f(fileName); - - if(!f.open(QIODevice::ReadOnly)) - QMessageBox::warning(this, tr("File error"), tr("Cannot read file '%1'").arg(fileName)); - else - m_scene->decode(qUncompress(QByteArray::fromBase64(f.readAll()))); - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/drawmapwidget.h --- a/QTfrontend/drawmapwidget.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef DRAWMAPWIDGET_H -#define DRAWMAPWIDGET_H - -#include -#include -#include -#include - -#include "qaspectratiolayout.h" -#include "drawmapscene.h" - -namespace Ui { - class Ui_DrawMapWidget - { - public: - QGraphicsView *graphicsView; - - void setupUi(QWidget *drawMapWidget) - { - QAspectRatioLayout * arLayout = new QAspectRatioLayout(drawMapWidget); - arLayout->setMargin(0); - - graphicsView = new QGraphicsView(drawMapWidget); - arLayout->addWidget(graphicsView); - - retranslateUi(drawMapWidget); - - QMetaObject::connectSlotsByName(drawMapWidget); - } // setupUi - - void retranslateUi(QWidget *drawMapWidget) - { - Q_UNUSED(drawMapWidget); - } // retranslateUi - - }; - - class DrawMapWidget: public Ui_DrawMapWidget {}; -} - -class DrawMapWidget : public QWidget -{ - Q_OBJECT - -public: - explicit DrawMapWidget(QWidget *parent = 0); - ~DrawMapWidget(); - - void setScene(DrawMapScene * scene); - -public slots: - void undo(); - void clear(); - void save(const QString & fileName); - void load(const QString & fileName); - -protected: - void changeEvent(QEvent *e); - virtual void resizeEvent(QResizeEvent * event); - virtual void showEvent(QShowEvent * event); - -private: - Ui::DrawMapWidget *ui; - - DrawMapScene * m_scene; -}; - -#endif // DRAWMAPWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/fpsedit.cpp --- a/QTfrontend/fpsedit.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "fpsedit.h" - -FPSEdit::FPSEdit(QWidget * parent) : - QSpinBox(parent) -{ - setRange(1, 34); - setValue(27); -} - -QString FPSEdit::textFromValue(int value) const -{ - return QString::number(1000 / (35 - value)); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/fpsedit.h --- a/QTfrontend/fpsedit.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _FPSEDIT_H -#define _FPSEDIT_H - -#include - -class FPSEdit : public QSpinBox -{ - Q_OBJECT - -public: - FPSEdit(QWidget * parent = 0); - -protected: - QString textFromValue (int value) const; -}; - -#endif // _FPSEDIT_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/frameTeam.cpp --- a/QTfrontend/frameTeam.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "frameTeam.h" -#include "teamselhelper.h" -#include "hwconsts.h" - -FrameTeams::FrameTeams(QWidget* parent) : - QFrame(parent), maxHedgehogsPerGame(48), overallHedgehogs(0), mainLayout(this), nonInteractive(false) -{ - QPalette newPalette = palette(); - newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); - setPalette(newPalette); - setAutoFillBackground(true); - - mainLayout.setSpacing(1); - mainLayout.setContentsMargins(4, 4, 4, 4); - - int i = 0; - while(colors[i] != 0) - availableColors.push_back(QColor(colors[i++])); - - resetColors(); -} - -void FrameTeams::setInteractivity(bool interactive) -{ - nonInteractive = !interactive; - for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ++it) { - TeamShowWidget* pts = dynamic_cast(it.value()); - if(!pts) throw; - pts->setInteractivity(interactive); - } -} - -void FrameTeams::resetColors() -{ - currentColor=availableColors.end() - 1; // ensure next color is the first one -} - -QColor FrameTeams::getNextColor() const -{ - QList::ConstIterator nextColor=currentColor; - ++nextColor; - if (nextColor==availableColors.end()) nextColor=availableColors.begin(); - return *nextColor; -} - -void FrameTeams::addTeam(HWTeam team, bool willPlay) -{ - TeamShowWidget* pTeamShowWidget = new TeamShowWidget(team, willPlay, this); - if(nonInteractive) pTeamShowWidget->setInteractivity(false); -// int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height(); - mainLayout.addWidget(pTeamShowWidget); - teamToWidget.insert(team, pTeamShowWidget); - QResizeEvent* pevent=new QResizeEvent(parentWidget()->size(), parentWidget()->size()); - QCoreApplication::postEvent(parentWidget(), pevent); -} - -void FrameTeams::removeTeam(HWTeam team) -{ - tmapTeamToWidget::iterator it=teamToWidget.find(team); - if(it==teamToWidget.end()) return; - mainLayout.removeWidget(it.value()); - it.value()->deleteLater(); - teamToWidget.erase(it); -} - -void FrameTeams::resetTeams() -{ - for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ) { - mainLayout.removeWidget(it.value()); - it.value()->deleteLater(); - teamToWidget.erase(it++); - } -} - -void FrameTeams::setHHNum(const HWTeam& team) -{ - TeamShowWidget* pTeamShowWidget = dynamic_cast(getTeamWidget(team)); - if(!pTeamShowWidget) return; - pTeamShowWidget->setHHNum(team.numHedgehogs); -} - -void FrameTeams::setTeamColor(const HWTeam& team) -{ - TeamShowWidget* pTeamShowWidget = dynamic_cast(getTeamWidget(team)); - if(!pTeamShowWidget) return; - pTeamShowWidget->changeTeamColor(team.teamColor); -} - -QWidget* FrameTeams::getTeamWidget(HWTeam team) -{ -//qDebug() << "FrameTeams::getTeamWidget getNetID() = " << team.getNetID(); - tmapTeamToWidget::iterator it=teamToWidget.find(team); - QWidget* ret = it!=teamToWidget.end() ? it.value() : 0; - return ret; -} - -bool FrameTeams::isFullTeams() const -{ - return overallHedgehogs==maxHedgehogsPerGame; -} - -void FrameTeams::emitTeamColorChanged(const HWTeam& team) -{ - emit teamColorChanged(team); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/frameTeam.h --- a/QTfrontend/frameTeam.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _FRAME_TEAM_INCLUDED -#define _FRAME_TEAM_INCLUDED - -#include -#include -#include - -#include "teamselect.h" - -class FrameTeams : public QFrame -{ - Q_OBJECT - - friend class CHedgehogerWidget; - friend class TeamShowWidget; - - public: - FrameTeams(QWidget* parent=0); - QWidget* getTeamWidget(HWTeam team); - bool isFullTeams() const; - void resetColors(); - void resetTeams(); - void setHHNum(const HWTeam& team); - void setTeamColor(const HWTeam& team); - void setInteractivity(bool interactive); - QColor getNextColor() const; - - signals: - void teamColorChanged(const HWTeam&); - - public slots: - void addTeam(HWTeam team, bool willPlay); - void removeTeam(HWTeam team); - - private: - const int maxHedgehogsPerGame; - int overallHedgehogs; - QList availableColors; - QList::Iterator currentColor; - - void emitTeamColorChanged(const HWTeam& team); - - QVBoxLayout mainLayout; - typedef QMap tmapTeamToWidget; - tmapTeamToWidget teamToWidget; - bool nonInteractive; -}; - -#endif // _FRAME_TAM_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/game.cpp --- a/QTfrontend/game.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/game.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -53,8 +53,13 @@ void HWGame::onClientDisconnect() { switch (gameType) { - case gtDemo: - if (gameState == gsInterrupted || gameState == gsHalted) emit HaveRecord(false, demo); + case gtSave: + if (gameState == gsInterrupted || gameState == gsHalted) + emit HaveRecord(false, demo); + else if (gameState == gsFinished) + emit HaveRecord(true, demo); + break; + case gtDemo: break; case gtNet: emit HaveRecord(true, demo); @@ -94,7 +99,7 @@ HWProto::addStringToBuffer(buf, QString("eammreinf %1").arg(ammostr.mid(3 * cAmmoNumber, cAmmoNumber))); if(!gamecfg->schemeData(21).toBool()) HWProto::addStringToBuffer(buf, QString("eammstore")); HWProto::addStringListToBuffer(buf, - team.TeamGameConfig(gamecfg->getInitHealth())); + team.teamGameConfig(gamecfg->getInitHealth())); ; } } @@ -115,27 +120,23 @@ .arg((themesModel->rowCount() > 0) ? themesModel->index(rand() % themesModel->rowCount()).data().toString() : "steel")); HWProto::addStringToBuffer(teamscfg, "eseed " + QUuid::createUuid().toString()); - HWNamegen namegen; - - HWTeam * team1; - team1 = new HWTeam; - team1->difficulty = 0; - team1->teamColor = QColor(colors[0]); - team1->numHedgehogs = 4; - namegen.TeamRandomNames(team1,TRUE); + HWTeam team1; + team1.setDifficulty(0); + team1.setColor(QColor(colors[0])); + team1.setNumHedgehogs(4); + HWNamegen::teamRandomNames(team1,true); HWProto::addStringListToBuffer(teamscfg, - team1->TeamGameConfig(100)); + team1.teamGameConfig(100)); - HWTeam * team2; - team2 = new HWTeam; - team2->difficulty = 4; - team2->teamColor = QColor(colors[1]); - team2->numHedgehogs = 4; - do - namegen.TeamRandomNames(team2,TRUE); - while(!team2->TeamName.compare(team1->TeamName) || !team2->Hedgehogs[0].Hat.compare(team1->Hedgehogs[0].Hat)); + HWTeam team2; + team2.setDifficulty(4); + team2.setColor(QColor(colors[1])); + team2.setNumHedgehogs(4); + do + HWNamegen::teamRandomNames(team2,true); + while(!team2.name().compare(team1.name()) || !team2.hedgehog(0).Hat.compare(team1.hedgehog(0).Hat)); HWProto::addStringListToBuffer(teamscfg, - team2->TeamGameConfig(100)); + team2.teamGameConfig(100)); HWProto::addStringToBuffer(teamscfg, QString("eammloadt %1").arg(cDefaultAmmoStore->mid(0, cAmmoNumber))); HWProto::addStringToBuffer(teamscfg, QString("eammprob %1").arg(cDefaultAmmoStore->mid(cAmmoNumber, cAmmoNumber))); @@ -188,6 +189,7 @@ SendQuickConfig(); break; } + case gtSave: case gtDemo: break; case gtNet: { SendNetConfig(); @@ -321,9 +323,9 @@ TeamCount++; } -void HWGame::PlayDemo(const QString & demofilename) +void HWGame::PlayDemo(const QString & demofilename, bool isSave) { - gameType = gtDemo; + gameType = isSave ? gtSave : gtDemo; QFile demofile(demofilename); if (!demofile.open(QIODevice::ReadOnly)) { @@ -394,7 +396,7 @@ { QByteArray buf; foreach(HWTeam team, m_pTeamSelWidget->getPlayingTeams()) - HWProto::addStringToBuffer(buf, QString("eteamgone %1").arg(team.TeamName)); + HWProto::addStringToBuffer(buf, QString("eteamgone %1").arg(team.name())); RawSendIPC(buf); } } diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/game.h --- a/QTfrontend/game.h Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/game.h Sat Oct 08 16:54:56 2011 +0200 @@ -48,7 +48,7 @@ HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget = 0); virtual ~HWGame(); void AddTeam(const QString & team); - void PlayDemo(const QString & demofilename); + void PlayDemo(const QString & demofilename, bool isSave); void StartLocal(); void StartQuick(); void StartNet(); @@ -84,6 +84,7 @@ gtNet = 4, gtTraining = 5, gtCampaign = 6, + gtSave = 7, }; char msgbuf[MAXMSGCHARS]; QString teams[5]; diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/gamecfgwidget.cpp --- a/QTfrontend/gamecfgwidget.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,575 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gamecfgwidget.h" -#include "igbox.h" -#include "hwconsts.h" -#include "ammoSchemeModel.h" -#include "proto.h" - -GameCFGWidget::GameCFGWidget(QWidget* parent) : - QGroupBox(parent) - , mainLayout(this) - , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}") -{ - mainLayout.setMargin(0); -// mainLayout.setSizeConstraint(QLayout::SetMinimumSize); - - pMapContainer = new HWMapContainer(this); - mainLayout.addWidget(pMapContainer, 0, 0); - - IconedGroupBox *GBoxOptions = new IconedGroupBox(this); - GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - mainLayout.addWidget(GBoxOptions, 1, 0); - - QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); - - QLabel *titleLabel = new QLabel(QLabel::tr("Game Options"), GBoxOptions); - titleLabel->setMargin(7); // TODO: make the text larger/richer!!!! - GBoxOptionsLayout->addWidget(titleLabel, 0, 0, 1, 0, Qt::AlignHCenter); - GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), GBoxOptions), 1, 0); - - Scripts = new QComboBox(GBoxOptions); - GBoxOptionsLayout->addWidget(Scripts, 1, 1); - - Scripts->addItem("Normal"); - Scripts->insertSeparator(1); - - for (int i = 0; i < scriptList->size(); ++i) { - QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive); - QList scriptInfo; - scriptInfo.push_back(script); - QFile scriptCfgFile; - scriptCfgFile.setFileName(QString("%1/Data/Scripts/Multiplayer/%2.cfg").arg(cfgdir->absolutePath()).arg(script)); - if (!scriptCfgFile.exists()) scriptCfgFile.setFileName(QString("%1/Scripts/Multiplayer/%2.cfg").arg(datadir->absolutePath()).arg(script)); - if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) { - QString scheme; - QString weapons; - QTextStream input(&scriptCfgFile); - input >> scheme; - input >> weapons; - if (scheme.isEmpty()) - scheme = "locked"; - scheme.replace("_", " "); - if (weapons.isEmpty()) - weapons = "locked"; - weapons.replace("_", " "); - scriptInfo.push_back(scheme); - scriptInfo.push_back(weapons); - scriptCfgFile.close(); - } - else - { - scriptInfo.push_back("locked"); - scriptInfo.push_back("locked"); - } - Scripts->addItem(script.replace("_", " "), scriptInfo); - } - - connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int))); - - QWidget *SchemeWidget = new QWidget(GBoxOptions); - GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2); - - QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget); - SchemeWidgetLayout->setMargin(0); - - GameSchemes = new QComboBox(SchemeWidget); - SchemeWidgetLayout->addWidget(GameSchemes, 0, 2); - connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int))); - - SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0); - - QPixmap pmEdit(":/res/edit.png"); - - QPushButton * goToSchemePage = new QPushButton(SchemeWidget); - goToSchemePage->setToolTip(tr("Edit schemes")); - goToSchemePage->setIconSize(pmEdit.size()); - goToSchemePage->setIcon(pmEdit); - goToSchemePage->setMaximumWidth(pmEdit.width() + 6); - SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3); - connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes())); - - SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Weapons"), SchemeWidget), 1, 0); - - WeaponsName = new QComboBox(SchemeWidget); - SchemeWidgetLayout->addWidget(WeaponsName, 1, 2); - - connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); - - QPushButton * goToWeaponPage = new QPushButton(SchemeWidget); - goToWeaponPage->setToolTip(tr("Edit weapons")); - goToWeaponPage->setIconSize(pmEdit.size()); - goToWeaponPage->setIcon(pmEdit); - goToWeaponPage->setMaximumWidth(pmEdit.width() + 6); - SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3); - connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons())); - - bindEntries = new QCheckBox(SchemeWidget); - bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon")); - bindEntries->setChecked(true); - bindEntries->setMaximumWidth(42); - bindEntries->setStyleSheet( "QCheckBox::indicator:checked { image: url(\":/res/lock.png\"); }" - "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\"); }" ); - SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter); - - connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &))); - connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &))); - connect(pMapContainer, SIGNAL(mapgenChanged(MapGenerator)), this, SLOT(mapgenChanged(MapGenerator))); - connect(pMapContainer, SIGNAL(mazeSizeChanged(int)), this, SLOT(maze_sizeChanged(int))); - connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &))); - connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); - connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap())); - connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &))); -} - -void GameCFGWidget::jumpToSchemes() -{ - emit goToSchemes(GameSchemes->currentIndex()); -} - -void GameCFGWidget::jumpToWeapons() -{ - emit goToWeapons(WeaponsName->currentIndex()); -} - -QVariant GameCFGWidget::schemeData(int column) const -{ - return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column)); -} - -quint32 GameCFGWidget::getGameFlags() const -{ - quint32 result = 0; - - if (schemeData(1).toBool()) - result |= 0x00001000; // fort - if (schemeData(2).toBool()) - result |= 0x00000010; // divide teams - if (schemeData(3).toBool()) - result |= 0x00000004; // solid land - if (schemeData(4).toBool()) - result |= 0x00000008; // border - if (schemeData(5).toBool()) - result |= 0x00000020; // low gravity - if (schemeData(6).toBool()) - result |= 0x00000040; // laser sight - if (schemeData(7).toBool()) - result |= 0x00000080; // invulnerable - if (schemeData(8).toBool()) - result |= 0x00000100; // mines - if (schemeData(9).toBool()) - result |= 0x00000200; // vampirism - if (schemeData(10).toBool()) - result |= 0x00000400; // karma - if (schemeData(11).toBool()) - result |= 0x00000800; // artillery - if (schemeData(12).toBool()) - result |= 0x00002000; // random - if (schemeData(13).toBool()) - result |= 0x00004000; // king - if (schemeData(14).toBool()) - result |= 0x00008000; // place hogs - if (schemeData(15).toBool()) - result |= 0x00010000; // shared ammo - if (schemeData(16).toBool()) - result |= 0x00020000; // disable girders - if (schemeData(17).toBool()) - result |= 0x00040000; // disable land obj - if (schemeData(18).toBool()) - result |= 0x00080000; // ai survival - if (schemeData(19).toBool()) - result |= 0x00100000; // infinite attacks - if (schemeData(20).toBool()) - result |= 0x00200000; // reset weaps - if (schemeData(21).toBool()) - result |= 0x00400000; // per hog ammo - if (schemeData(22).toBool()) - result |= 0x00800000; // no wind - if (schemeData(23).toBool()) - result |= 0x01000000; // more wind - if (schemeData(24).toBool()) - result |= 0x02000000; // tag team - if (schemeData(25).toBool()) - result |= 0x04000000; // bottom border - - return result; -} - -quint32 GameCFGWidget::getInitHealth() const -{ - return schemeData(28).toInt(); -} - -QByteArray GameCFGWidget::getFullConfig() const -{ - QList bcfg; - int mapgen = pMapContainer->get_mapgen(); - - QString currentMap = pMapContainer->getCurrentMap(); - if (currentMap.size() > 0) - { - bcfg << QString("emap " + currentMap).toUtf8(); - if(pMapContainer->getCurrentIsMission()) - bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8(); - } - bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8(); - - if (Scripts->currentIndex() > 0) - { - bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8(); - } - - bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8(); - bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8(); - bcfg << QString("e$damagepct %1").arg(schemeData(26).toInt()).toUtf8(); - bcfg << QString("e$turntime %1").arg(schemeData(27).toInt() * 1000).toUtf8(); - bcfg << QString("e$sd_turns %1").arg(schemeData(29).toInt()).toUtf8(); - bcfg << QString("e$casefreq %1").arg(schemeData(30).toInt()).toUtf8(); - bcfg << QString("e$minestime %1").arg(schemeData(31).toInt() * 1000).toUtf8(); - bcfg << QString("e$minesnum %1").arg(schemeData(32).toInt()).toUtf8(); - bcfg << QString("e$minedudpct %1").arg(schemeData(33).toInt()).toUtf8(); - bcfg << QString("e$explosives %1").arg(schemeData(34).toInt()).toUtf8(); - bcfg << QString("e$healthprob %1").arg(schemeData(35).toInt()).toUtf8(); - bcfg << QString("e$hcaseamount %1").arg(schemeData(36).toInt()).toUtf8(); - bcfg << QString("e$waterrise %1").arg(schemeData(37).toInt()).toUtf8(); - bcfg << QString("e$healthdec %1").arg(schemeData(38).toInt()).toUtf8(); - bcfg << QString("e$ropepct %1").arg(schemeData(39).toInt()).toUtf8(); - bcfg << QString("e$getawaytime %1").arg(schemeData(40).toInt()).toUtf8(); - bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8(); - bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8(); - - switch (mapgen) - { - case MAPGEN_MAZE: - bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8(); - break; - - case MAPGEN_DRAWN: - { - QByteArray data = pMapContainer->getDrawnMapData(); - while(data.size() > 0) - { - QByteArray tmp = data; - tmp.truncate(200); - tmp.prepend("edraw "); - bcfg << tmp; - data.remove(0, 200); - } - break; - } - default: ; - } - - QByteArray result; - - foreach(QByteArray ba, bcfg) - HWProto::addByteArrayToBuffer(result, ba); - - return result; -} - -void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) -{ - bool illegal = ammo.size() != cDefaultAmmoStore->size(); - if (illegal) - QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); - - int pos = WeaponsName->findText(name); - if ((pos == -1) || illegal) { // prevent from overriding schemes with bad ones - WeaponsName->addItem(name, ammo); - WeaponsName->setCurrentIndex(WeaponsName->count() - 1); - } else { - WeaponsName->setItemData(pos, ammo); - WeaponsName->setCurrentIndex(pos); - } -} - -void GameCFGWidget::fullNetConfig() -{ - ammoChanged(WeaponsName->currentIndex()); - - seedChanged(pMapContainer->getCurrentSeed()); - templateFilterChanged(pMapContainer->getTemplateFilter()); - themeChanged(pMapContainer->getCurrentTheme()); - - schemeChanged(GameSchemes->currentIndex()); - scriptChanged(Scripts->currentIndex()); - - mapgenChanged(pMapContainer->get_mapgen()); - maze_sizeChanged(pMapContainer->getMazeSize()); - - // map must be the last - QString map = pMapContainer->getCurrentMap(); - if (map.size()) - mapChanged(map); -} - -void GameCFGWidget::setParam(const QString & param, const QStringList & slValue) -{ - if (slValue.size() == 1) - { - QString value = slValue[0]; - if (param == "MAP") { - pMapContainer->setMap(value); - return; - } - if (param == "SEED") { - pMapContainer->setSeed(value); - if (!seedRegexp.exactMatch(value)) { - pMapContainer->seedEdit->setVisible(true); - } - return; - } - if (param == "THEME") { - pMapContainer->setTheme(value); - return; - } - if (param == "TEMPLATE") { - pMapContainer->setTemplateFilter(value.toUInt()); - return; - } - if (param == "MAPGEN") { - pMapContainer->setMapgen((MapGenerator)value.toUInt()); - return; - } - if (param == "MAZE_SIZE") { - pMapContainer->setMazeSize(value.toUInt()); - return; - } - if (param == "SCRIPT") { - Scripts->setCurrentIndex(Scripts->findText(value)); - return; - } - if (param == "DRAWNMAP") { - pMapContainer->setDrawnMapData(qUncompress(QByteArray::fromBase64(slValue[0].toLatin1()))); - return; - } - } - - if (slValue.size() == 2) - { - if (param == "AMMO") { - setNetAmmo(slValue[0], slValue[1]); - return; - } - } - - if (slValue.size() == 5) - { - if (param == "FULLMAPCONFIG") - { - QString seed = slValue[3]; - if (!seedRegexp.exactMatch(seed)) - pMapContainer->seedEdit->setVisible(true); - - pMapContainer->setAllMapParameters( - slValue[0], - (MapGenerator)slValue[1].toUInt(), - slValue[2].toUInt(), - seed, - slValue[4].toUInt() - ); - return; - } - } - - qWarning("Got bad config param from net"); -} - -void GameCFGWidget::ammoChanged(int index) -{ - if (index >= 0) { - emit paramChanged( - "AMMO", - QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() - ); - } -} - -void GameCFGWidget::mapChanged(const QString & value) -{ - if(isEnabled() && pMapContainer->getCurrentIsMission()) - { - Scripts->setEnabled(false); - Scripts->setCurrentIndex(0); - - if (pMapContainer->getCurrentScheme() == "locked") - { - GameSchemes->setEnabled(false); - GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); - } - else - { - GameSchemes->setEnabled(true); - int num = GameSchemes->findText(pMapContainer->getCurrentScheme()); - if (num != -1) - GameSchemes->setCurrentIndex(num); - else - GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); - } - - if (pMapContainer->getCurrentWeapons() == "locked") - { - WeaponsName->setEnabled(false); - WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); - } - else - { - WeaponsName->setEnabled(true); - int num = WeaponsName->findText(pMapContainer->getCurrentWeapons()); - if (num != -1) - WeaponsName->setCurrentIndex(num); - else - WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); - } - - if (pMapContainer->getCurrentScheme() != "locked" && pMapContainer->getCurrentWeapons() != "locked") - bindEntries->setEnabled(true); - else - bindEntries->setEnabled(false); - } - else - { - Scripts->setEnabled(true); - GameSchemes->setEnabled(true); - WeaponsName->setEnabled(true); - bindEntries->setEnabled(true); - } - emit paramChanged("MAP", QStringList(value)); -} - -void GameCFGWidget::templateFilterChanged(int value) -{ - emit paramChanged("TEMPLATE", QStringList(QString::number(value))); -} - -void GameCFGWidget::seedChanged(const QString & value) -{ - emit paramChanged("SEED", QStringList(value)); -} - -void GameCFGWidget::themeChanged(const QString & value) -{ - emit paramChanged("THEME", QStringList(value)); -} - -void GameCFGWidget::schemeChanged(int index) -{ - QStringList sl; - - int size = GameSchemes->model()->columnCount(); - for(int i = 0; i < size; ++i) - sl << schemeData(i).toString(); - - emit paramChanged("SCHEME", sl); - - if (isEnabled() && bindEntries->isEnabled() && bindEntries->isChecked()) { - QString schemeName = GameSchemes->itemText(index); - for (int i = 0; i < WeaponsName->count(); i++) { - QString weapName = WeaponsName->itemText(i); - int res = QString::compare(weapName, schemeName, Qt::CaseSensitive); - if (0 == res) { - WeaponsName->setCurrentIndex(i); - emit ammoChanged(i); - break; - } - } - } -} - -void GameCFGWidget::scriptChanged(int index) -{ - if(isEnabled() && index > 0) - { - QString scheme = Scripts->itemData(Scripts->currentIndex()).toList()[1].toString(); - QString weapons = Scripts->itemData(Scripts->currentIndex()).toList()[2].toString(); - - if (scheme == "locked") - { - GameSchemes->setEnabled(false); - GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); - } - else - { - GameSchemes->setEnabled(true); - int num = GameSchemes->findText(scheme); - if (num != -1) - GameSchemes->setCurrentIndex(num); - else - GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); - } - - if (weapons == "locked") - { - WeaponsName->setEnabled(false); - WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); - } - else - { - WeaponsName->setEnabled(true); - int num = WeaponsName->findText(weapons); - if (num != -1) - WeaponsName->setCurrentIndex(num); - else - WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); - } - - if (scheme != "locked" && weapons != "locked") - bindEntries->setEnabled(true); - else - bindEntries->setEnabled(false); - } - else - { - GameSchemes->setEnabled(true); - WeaponsName->setEnabled(true); - bindEntries->setEnabled(true); - } - emit paramChanged("SCRIPT", QStringList(Scripts->itemText(index))); -} - -void GameCFGWidget::mapgenChanged(MapGenerator m) -{ - emit paramChanged("MAPGEN", QStringList(QString::number(m))); -} - -void GameCFGWidget::maze_sizeChanged(int s) -{ - emit paramChanged("MAZE_SIZE", QStringList(QString::number(s))); -} - -void GameCFGWidget::resendSchemeData() -{ - schemeChanged(GameSchemes->currentIndex()); -} - -void GameCFGWidget::onDrawnMapChanged(const QByteArray & data) -{ - emit paramChanged("DRAWNMAP", QStringList(qCompress(data, 9).toBase64())); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/gamecfgwidget.h --- a/QTfrontend/gamecfgwidget.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef GAMECONFIGWIDGET_H -#define GAMECONFIGWIDGET_H - -#include -#include -#include -#include -#include - -#include "mapContainer.h" - -class QCheckBox; -class QVBoxLayout; -class QLabel; -class QTableView; - -class GameCFGWidget : public QGroupBox -{ - Q_OBJECT - -public: - GameCFGWidget(QWidget* parent); - quint32 getGameFlags() const; - quint32 getInitHealth() const; - QByteArray getFullConfig() const; - QComboBox * Scripts; - QComboBox * GameSchemes; - QComboBox * WeaponsName; - HWMapContainer* pMapContainer; - QTableView * tv; - QVariant schemeData(int column) const; - -public slots: - void setParam(const QString & param, const QStringList & value); - void fullNetConfig(); - void resendSchemeData(); - -signals: - void paramChanged(const QString & param, const QStringList & value); - void goToSchemes(int); - void goToWeapons(int); - void goToDrawMap(); - -private slots: - void ammoChanged(int index); - void mapChanged(const QString &); - void templateFilterChanged(int); - void seedChanged(const QString &); - void themeChanged(const QString &); - void schemeChanged(int); - void scriptChanged(int); - void jumpToSchemes(); - void jumpToWeapons(); - void mapgenChanged(MapGenerator m); - void maze_sizeChanged(int s); - void onDrawnMapChanged(const QByteArray & data); - -private: - QGridLayout mainLayout; - QCheckBox * bindEntries; - QString curNetAmmoName; - QString curNetAmmo; - QRegExp seedRegexp; - - void setNetAmmo(const QString& name, const QString& ammo); - -}; - -#endif // GAMECONFIGWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hats.cpp --- a/QTfrontend/hats.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include "hwconsts.h" -#include "hwform.h" -#include "hats.h" - -HatsModel::HatsModel(QObject* parent) : - QAbstractListModel(parent) -{ - QFile hhfile; - hhfile.setFileName(cfgdir->absolutePath() + "/Data/Graphics/Hedgehog/Idle.png"); - if (!hhfile.exists()) hhfile.setFileName(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png"); - QPixmap hhpix = QPixmap(QFileInfo(hhfile).absoluteFilePath()).copy(0, 0, 32, 32); - - QDir tmpdir; - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data"); - tmpdir.cd("Graphics"); - tmpdir.cd("Hats"); - - tmpdir.setFilter(QDir::Files); - - QStringList userhatsList = tmpdir.entryList(QStringList("*.png")); - for (QStringList::Iterator it = userhatsList.begin(); it != userhatsList.end(); ++it ) - { - QString str = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Hats/" + str + ".png"); - - QPixmap tmppix(32, 37); - tmppix.fill(QColor(Qt::transparent)); - - QPainter painter(&tmppix); - painter.drawPixmap(QPoint(0, 5), hhpix); - painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); - if(pix.width() > 32) - painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32)); - painter.end(); - - hats.append(qMakePair(str, QIcon(tmppix))); - } - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Graphics"); - tmpdir.cd("Hats"); - - QStringList hatsList = tmpdir.entryList(QStringList("*.png")); - for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) - { - if (userhatsList.contains(*it,Qt::CaseInsensitive)) continue; - QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); - - QPixmap tmppix(32, 37); - tmppix.fill(QColor(Qt::transparent)); - - QPainter painter(&tmppix); - painter.drawPixmap(QPoint(0, 5), hhpix); - painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); - if(pix.width() > 32) - painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32)); - painter.end(); - - hats.append(qMakePair(str, QIcon(tmppix))); - } - // Reserved hats - tmpdir.cd("Reserved"); - hatsList = tmpdir.entryList(QStringList(playerHash+"*.png")); - for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) - { - QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png"); - - QPixmap tmppix(32, 37); - tmppix.fill(QColor(Qt::transparent)); - - QPainter painter(&tmppix); - painter.drawPixmap(QPoint(0, 5), hhpix); - painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); - painter.end(); - - hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix))); - } -} - -QVariant HatsModel::headerData(int section, - Qt::Orientation orientation, int role) const -{ - Q_UNUSED(section); - Q_UNUSED(orientation); - Q_UNUSED(role); - - return QVariant(); -} - -int HatsModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - else - return hats.size(); -} - -/*int HatsModel::columnCount(const QModelIndex & parent) const -{ - if (parent.isValid()) - return 0; - else - return 2; -} -*/ -QVariant HatsModel::data(const QModelIndex &index, - int role) const -{ - if (!index.isValid() || index.row() < 0 - || index.row() >= hats.size() - || (role != Qt::DisplayRole && role != Qt::DecorationRole)) - return QVariant(); - - if (role == Qt::DisplayRole) - return hats.at(index.row()).first; - else // role == Qt::DecorationRole - return hats.at(index.row()).second; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hats.h --- a/QTfrontend/hats.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _HATS_INCLUDED -#define _HATS_INCLUDED - -#include -#include -#include -#include -#include - -class HatsModel : public QAbstractListModel -{ - Q_OBJECT - -public: - HatsModel(QObject *parent = 0); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - int rowCount(const QModelIndex & parent) const; - //int columnCount(const QModelIndex & parent) const; - - QVariant data(const QModelIndex &index, int role) const; -protected: - QVector > hats; -}; - -#endif // _HATS_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hedgehogerWidget.cpp --- a/QTfrontend/hedgehogerWidget.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Ulyanov Igor - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "hedgehogerWidget.h" - -#include "frameTeam.h" - -CHedgehogerWidget::CHedgehogerWidget(const QImage& im, const QImage& img, QWidget * parent) : - ItemNum(im, img, parent, 1) -{ - // TODO: maxHedgehogsPerGame doesn't reset properly and won't match map limits for now - /*if(parent) { - pOurFrameTeams = dynamic_cast(parent->parentWidget()); - } - if(pOurFrameTeams->overallHedgehogs + 4 > pOurFrameTeams->maxHedgehogsPerGame) { - numItems = pOurFrameTeams->maxHedgehogsPerGame - pOurFrameTeams->overallHedgehogs; - } else numItems = 4; - pOurFrameTeams->overallHedgehogs += numItems;*/ -} - -void CHedgehogerWidget::incItems() -{ - //if (pOurFrameTeams->overallHedgehogs < pOurFrameTeams->maxHedgehogsPerGame) { - numItems++; - //pOurFrameTeams->overallHedgehogs++; - emit hedgehogsNumChanged(); - //} -} - -void CHedgehogerWidget::decItems() -{ - numItems--; - //pOurFrameTeams->overallHedgehogs--; - emit hedgehogsNumChanged(); -} - -CHedgehogerWidget::~CHedgehogerWidget() -{ - // TODO: not called? - //pOurFrameTeams->overallHedgehogs-=numItems; -} - -void CHedgehogerWidget::setNonInteractive() -{ - nonInteractive=true; -} - -void CHedgehogerWidget::setHHNum(unsigned int num) -{ - /*unsigned int diff = num - numItems; - numItems += diff; - pOurFrameTeams->overallHedgehogs += diff;*/ - numItems = num; - repaint(); -} - -unsigned char CHedgehogerWidget::getHedgehogsNum() const -{ - return numItems; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hedgehogerWidget.h --- a/QTfrontend/hedgehogerWidget.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Ulyanov Igor - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _HEDGEHOGER_WIDGET -#define _HEDGEHOGER_WIDGET - -#include "itemNum.h" - -class FrameTeams; - -class CHedgehogerWidget : public ItemNum -{ - Q_OBJECT - - public: - CHedgehogerWidget(const QImage& im, const QImage& img, QWidget * parent); - virtual ~CHedgehogerWidget(); - unsigned char getHedgehogsNum() const; - void setHHNum (unsigned int num); - void setNonInteractive(); - - signals: - void hedgehogsNumChanged(); - - protected: - virtual void incItems(); - virtual void decItems(); - - private: - CHedgehogerWidget(); - FrameTeams* pOurFrameTeams; -}; - -#endif // _HEDGEHOGER_WIDGET diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hedgewars.qrc --- a/QTfrontend/hedgewars.qrc Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/hedgewars.qrc Sat Oct 08 16:54:56 2011 +0200 @@ -45,6 +45,7 @@ res/unchecked.png res/graphicsicon.png res/miscicon.png + res/Load.png res/Save.png res/Record.png res/weaponsicon.png @@ -57,31 +58,31 @@ res/PlaySound.png res/hh_small.png res/btnDisabled.png - res/btnForts.png - res/btnBorder.png - res/btnInvulnerable.png - res/btnLaserSight.png - res/btnLowGravity.png - res/btnResetHealth.png - res/btnTeamsDivide.png - res/btnSolid.png - res/btnVampiric.png - res/btnKarma.png - res/btnArtillery.png - res/btnRandomOrder.png - res/btnKing.png - res/btnPlaceHog.png - res/btnSharedAmmo.png - res/btnDisableGirders.png - res/btnDisableLandObjects.png - res/btnAISurvival.png - res/btnInfAttack.png - res/btnResetWeps.png - res/btnPerHogAmmo.png - res/btnNoWind.png - res/btnMoreWind.png - res/btnTagTeam.png - res/btnBottomBorder.png + res/btnForts@2x.png + res/btnBorder@2x.png + res/btnInvulnerable@2x.png + res/btnLaserSight@2x.png + res/btnLowGravity@2x.png + res/btnResetHealth@2x.png + res/btnTeamsDivide@2x.png + res/btnSolid@2x.png + res/btnVampiric@2x.png + res/btnKarma@2x.png + res/btnArtillery@2x.png + res/btnRandomOrder@2x.png + res/btnKing@2x.png + res/btnPlaceHog@2x.png + res/btnSharedAmmo@2x.png + res/btnDisableGirders@2x.png + res/btnDisableLandObjects@2x.png + res/btnAISurvival@2x.png + res/btnInfAttack@2x.png + res/btnResetWeps@2x.png + res/btnPerHogAmmo@2x.png + res/btnNoWind@2x.png + res/btnMoreWind@2x.png + res/btnTagTeam@2x.png + res/btnBottomBorder@2x.png res/iconBox.png res/iconHealth.png res/iconSuddenDeath.png diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hwconsts.h --- a/QTfrontend/hwconsts.h Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/hwconsts.h Sat Oct 08 16:54:56 2011 +0200 @@ -58,6 +58,8 @@ extern bool isDevBuild; #endif +#define HEDGEHOGS_PER_TEAM 8 + #define AMMOLINE_DEFAULT_QT "939192942219912103223511100120100000021111010101111101" #define AMMOLINE_DEFAULT_PROB "040504054160065554655446477657666666615551010111541101" #define AMMOLINE_DEFAULT_DELAY "000000000000020550000004000700400000000022000000060000" diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/hwform.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#include #include #include #include @@ -43,7 +44,6 @@ #include "hwform.h" #include "game.h" #include "team.h" -#include "namegen.h" #include "teamselect.h" #include "selectWeapon.h" #include "gameuiconfig.h" @@ -93,7 +93,7 @@ bool frontendEffects = true; QString playerHash; -HWForm::HWForm(QWidget *parent) +HWForm::HWForm(QWidget *parent, QString styleSheet) : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0) { #ifdef USE_XFIRE @@ -104,6 +104,7 @@ frontendEffects = gameSettings->value("frontend/effects", true).toBool(); playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex()); + this->setStyleSheet(styleSheet); ui.setupUi(this); setMinimumSize(760, 580); //setFocusPolicy(Qt::StrongFocus); @@ -113,7 +114,6 @@ config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); - namegen = new HWNamegen(); #ifdef __APPLE__ panel = new M3Panel; @@ -138,6 +138,12 @@ UpdateCampaignPage(0); UpdateWeapons(); + // connect all goBack signals + int nPages = ui.Pages->count(); + + for (int i = 0; i < nPages; i++) + connect(ui.Pages->widget(i), SIGNAL(goBack()), this, SLOT(GoBack())); + pageSwitchMapper = new QSignalMapper(this); connect(pageSwitchMapper, SIGNAL(mapped(int)), this, SLOT(GoToPage(int))); @@ -159,19 +165,11 @@ connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD); - connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); - connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); - - connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - connect(ui.pageDataDownload->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); + //connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed())); + //connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked())); - connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave())); - connect(ui.pageEditTeam->BtnTeamDiscard, SIGNAL(clicked()), this, SLOT(TeamDiscard())); + connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit())); - connect(ui.pageEditTeam->signalMapper, SIGNAL(mapped(const int &)), this, SLOT(RandomName(const int &))); - connect(ui.pageEditTeam->randTeamButton, SIGNAL(clicked()), this, SLOT(RandomNames())); - - connect(ui.pageMultiplayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame())); connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)), ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool))); @@ -180,18 +178,16 @@ connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToWeapons(int)), this, SLOT(GoToSelectWeaponSet(int))); connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToDrawMap()), pageSwitchMapper, SLOT(map())); pageSwitchMapper->setMapping(ui.pageMultiplayer->gameCFG, ID_PAGE_DRAWMAP); - - connect(ui.pagePlayDemo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); + connect(ui.pagePlayDemo->BtnPlayDemo, SIGNAL(clicked()), this, SLOT(PlayDemo())); connect(ui.pagePlayDemo->DemosList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(PlayDemo())); - connect(ui.pageOptions->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - connect(ui.pageOptions->BtnNewTeam, SIGNAL(clicked()), this, SLOT(NewTeam())); - connect(ui.pageOptions->BtnEditTeam, SIGNAL(clicked()), this, SLOT(EditTeam())); - connect(ui.pageOptions->BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(DeleteTeam())); - connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), config, SLOT(SaveOptions())); - connect(ui.pageOptions->BtnSaveOptions, SIGNAL(clicked()), this, SLOT(GoBack())); + connect(ui.pageOptions, SIGNAL(newTeamRequested()), this, SLOT(NewTeam())); + connect(ui.pageOptions, SIGNAL(editTeamRequested(const QString&)), this, SLOT(EditTeam(const QString&))); + connect(ui.pageOptions, SIGNAL(deleteTeamRequested(const QString&)), this, SLOT(DeleteTeam(const QString&))); + connect(ui.pageOptions->btnSave, SIGNAL(clicked()), config, SLOT(SaveOptions())); + connect(ui.pageOptions->btnSave, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageOptions->BtnAssociateFiles, SIGNAL(clicked()), this, SLOT(AssociateFiles())); connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon())); @@ -202,17 +198,14 @@ connect(ui.pageOptions->SchemeDelete, SIGNAL(clicked()), this, SLOT(DeleteScheme())); connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons())); - connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect())); connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); pageSwitchMapper->setMapping(ui.pageNet->BtnNetSvrStart, ID_PAGE_NETSERVER); connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16))); - connect(ui.pageNetServer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer())); - connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), ui.pageNetGame->BtnStart, SLOT(setEnabled(bool))); connect(ui.pageNetGame, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); @@ -221,14 +214,11 @@ connect(ui.pageNetGame->pGameCFG, SIGNAL(goToDrawMap()), pageSwitchMapper, SLOT(map())); pageSwitchMapper->setMapping(ui.pageNetGame->pGameCFG, ID_PAGE_DRAWMAP); - connect(ui.pageRoomsList->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageRoomsList->BtnAdmin, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); pageSwitchMapper->setMapping(ui.pageRoomsList->BtnAdmin, ID_PAGE_ADMIN); connect(ui.pageInfo->BtnSnapshots, SIGNAL(clicked()), this, SLOT(OpenSnapshotFolder())); - connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageGameStats, SIGNAL(saveDemoRequested()), this, SLOT(saveDemoWithCustomName())); connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame())); @@ -243,16 +233,12 @@ connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves())); connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos())); - connect(ui.pageSinglePlayer->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining())); - connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); + connect(ui.pageTraining, SIGNAL(startMission(const QString&)), this, SLOT(startTraining(const QString&))); connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign())); - connect(ui.pageCampaign->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int))); - connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first @@ -261,16 +247,10 @@ //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()), // this, SLOT(GoBack())); // executed third - connect(ui.pageScheme->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - connect(ui.pageAdmin->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - - connect(ui.pageNetType->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet())); connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer())); - connect(ui.pageDrawMap->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); - connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack())); @@ -295,26 +275,27 @@ #ifdef USE_XFIRE void HWForm::updateXfire(void) { - if(hwnet) + if(hwnet && (hwnet->clientState() != HWNewNet::Disconnected)) { xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii()); - switch(hwnet->getClientState()) + switch(hwnet->clientState()) { - case 1: // Connecting + case HWNewNet::Connecting: // Connecting + case HWNewNet::Connected: xfire_setvalue(XFIRE_STATUS, "Connecting"); xfire_setvalue(XFIRE_NICKNAME, "-"); xfire_setvalue(XFIRE_ROOM, "-"); - case 2: // In lobby + case HWNewNet::InLobby: // In lobby xfire_setvalue(XFIRE_STATUS, "Online"); xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); xfire_setvalue(XFIRE_ROOM, "In game lobby"); break; - case 3: // In room + case HWNewNet::InRoom: // In room xfire_setvalue(XFIRE_STATUS, "Online"); xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii()); break; - case 5: // In game + case HWNewNet::InGame: // In game xfire_setvalue(XFIRE_STATUS, "Online"); xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii()); xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii()); @@ -398,7 +379,7 @@ if(teamslist.empty()) { HWTeam defaultTeam(tr("DefaultTeam")); - defaultTeam.SaveToFile(); + defaultTeam.saveToFile(); teamslist.push_back(tr("DefaultTeam")); } @@ -490,11 +471,7 @@ if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) { QStringList tmNames = config->GetTeamsList(); TeamSelWidget* curTeamSelWidget; - ui.pageOptions->BtnNewTeam->setVisible(false); - ui.pageOptions->BtnEditTeam->setVisible(false); - ui.pageOptions->BtnDeleteTeam->setVisible(false); - ui.pageOptions->CBTeamName->setVisible(false); - ui.pageOptions->LblNoEditTeam->setVisible(true); + ui.pageOptions->setTeamOptionsEnabled(false); if (id == ID_PAGE_MULTIPLAYER) { curTeamSelWidget = ui.pageMultiplayer->teamsSelect; @@ -505,7 +482,7 @@ QList teamsList; for (QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++) { HWTeam team(*it); - team.LoadFromFile(); + team.loadFromFile(); teamsList.push_back(team); } @@ -525,11 +502,7 @@ } if (id == ID_PAGE_MAIN) { - ui.pageOptions->BtnNewTeam->setVisible(true); - ui.pageOptions->BtnEditTeam->setVisible(true); - ui.pageOptions->BtnDeleteTeam->setVisible(true); - ui.pageOptions->CBTeamName->setVisible(true); - ui.pageOptions->LblNoEditTeam->setVisible(false); + ui.pageOptions->setTeamOptionsEnabled(true); } // load and save ignore/friends lists @@ -560,8 +533,11 @@ void HWForm::GoBack() { + int curid = ui.Pages->currentIndex(); + if (curid == ID_PAGE_MAIN) + exit(); + int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop(); - int curid = ui.Pages->currentIndex(); ui.Pages->setCurrentIndex(id); OnPageShown(id, curid); @@ -577,7 +553,7 @@ GoBack(); if (curid == ID_PAGE_ROOMSLIST || curid == ID_PAGE_CONNECTING) NetDisconnect(); - if (curid == ID_PAGE_NETGAME && hwnet) hwnet->partRoom(); + if (curid == ID_PAGE_NETGAME && hwnet && hwnet->isInRoom()) hwnet->partRoom(); // need to work on this, can cause invalid state for admin quit trying to prevent bad state message on kick //if (curid == ID_PAGE_NETGAME && (!game || game->gameState != gsStarted)) hwnet->partRoom(); @@ -596,14 +572,15 @@ eggTimer.start(); } -void HWForm::btnExitClicked() +void HWForm::exit() { - if (eggTimer.elapsed() < 3000){ +// if (eggTimer.elapsed() < 3000){ #ifdef __APPLE__ panel->showInstallController(); #endif close(); - } +// TODO reactivate egg +/* } else { QPushButton * btn = findChild("imageButt"); @@ -611,7 +588,7 @@ { btn->setIcon(QIcon(":/res/bonus.png")); } - } + } */ } void HWForm::IntermediateSetup() @@ -628,7 +605,7 @@ QStringList tmnames; foreach(HWTeam team, curTeamSelWidget->getNotPlayingTeams()) - tmnames += team.TeamName; + tmnames += team.name(); //UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring UpdateTeamsLists(); @@ -638,61 +615,30 @@ void HWForm::NewTeam() { - editedTeam = new HWTeam("unnamed"); - editedTeam->SetToPage(this); - GoToPage(ID_PAGE_SETUP_TEAM); -} - -void HWForm::EditTeam() -{ - editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); - editedTeam->LoadFromFile(); - editedTeam->SetToPage(this); + ui.pageEditTeam->createTeam(QLineEdit::tr("unnamed"), playerHash); + UpdateTeamsLists(); GoToPage(ID_PAGE_SETUP_TEAM); } -void HWForm::DeleteTeam() +void HWForm::EditTeam(const QString & teamName) { - QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel); - - if (reallyDelete.exec() == QMessageBox::Ok) { - editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText()); - editedTeam->DeleteFile(); - - // Remove from lists - ui.pageOptions->CBTeamName->removeItem(ui.pageOptions->CBTeamName->currentIndex()); - } + ui.pageEditTeam->editTeam(teamName, playerHash); + GoToPage(ID_PAGE_SETUP_TEAM); } -void HWForm::RandomNames() -{ - editedTeam->GetFromPage(this); - namegen->TeamRandomNames(editedTeam, true); - editedTeam->SetToPage(this); -} - -void HWForm::RandomName(const int &i) +void HWForm::AfterTeamEdit() { - editedTeam->GetFromPage(this); - namegen->TeamRandomName(editedTeam,i); - editedTeam->SetToPage(this); -} - -void HWForm::TeamSave() -{ - editedTeam->GetFromPage(this); - editedTeam->SaveToFile(); - delete editedTeam; - editedTeam=0; UpdateTeamsLists(); GoBack(); } -void HWForm::TeamDiscard() + +void HWForm::DeleteTeam(const QString & teamName) { - delete editedTeam; - editedTeam=0; - GoBack(); + ui.pageEditTeam->deleteTeam(teamName); + QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel); + + UpdateTeamsLists(); } void HWForm::DeleteScheme() @@ -730,7 +676,7 @@ return; } CreateGame(0, 0, 0); - game->PlayDemo(curritem->data(Qt::UserRole).toString()); + game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave()); } void HWForm::PlayDemoQuick(const QString & demofilename) @@ -739,7 +685,7 @@ GoBack(); //needed to cleanly disconnect from netgame GoToPage(ID_PAGE_MAIN); CreateGame(0, 0, 0); - game->PlayDemo(demofilename); + game->PlayDemo(demofilename, false); } void HWForm::NetConnectServer(const QString & host, quint16 port) @@ -752,7 +698,82 @@ NetConnectServer("netserver.hedgewars.org", 46631); } -void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) +void HWForm::NetPassword(const QString & nick) +{ + bool ok = false; + int passLength = config->value("net/passwordlength", 0).toInt(); + QString hash = config->value("net/passwordhash", "").toString(); + + // If the password is blank, ask the user to enter one in + if (passLength == 0) + { + QString password = QInputDialog::getText(this, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok); + + if (!ok) { + ForcedDisconnect(tr("No password supplied.")); + return; + } + + hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex(); + config->setValue("net/passwordhash", hash); + config->setValue("net/passwordlength", password.size()); + config->setNetPasswordLength(password.size()); + } + + hwnet->SendPasswordHash(hash); +} + +void HWForm::NetNickTaken(const QString & nick) +{ + bool ok = false; + QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok); + + if (!ok || newNick.isEmpty()) { + ForcedDisconnect(tr("No nickname supplied.")); + return; + } + + hwnet->NewNick(newNick); + config->setValue("net/nick", newNick); + config->updNetNick(); +} + +void HWForm::NetAuthFailed() +{ + // Set the password blank if case the user tries to join and enter his password again + config->setValue("net/passwordlength", 0); + config->setNetPasswordLength(0); +} + +void HWForm::NetTeamAccepted(const QString & team) +{ + ui.pageNetGame->pNetTeamsWidget->changeTeamStatus(team); +} + +void HWForm::NetError(const QString & errmsg) +{ + switch (ui.Pages->currentIndex()) + { + case ID_PAGE_INGAME: + ShowErrorMessage(errmsg); + // no break + case ID_PAGE_NETGAME: + ui.pageNetGame->pChatWidget->addLine("Error",errmsg); + break; + default: + ui.pageRoomsList->chatWidget->addLine("Error",errmsg); + } +} + +void HWForm::NetWarning(const QString & wrnmsg) +{ + if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME) + ui.pageNetGame->pChatWidget->addLine("Warning",wrnmsg); + else + ui.pageRoomsList->chatWidget->addLine("Warning",wrnmsg); +} + +void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick) { if(hwnet) { hwnet->Disconnect(); @@ -762,17 +783,22 @@ ui.pageRoomsList->chatWidget->clear(); - hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); + hwnet = new HWNewNet(); GoToPage(ID_PAGE_CONNECTING); - connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); - connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); - connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected())); + connect(hwnet, SIGNAL(connected()), this, SLOT(NetConnected())); + connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&))); + connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&))); connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); - connect(hwnet, SIGNAL(LeftRoom()), this, SLOT(NetLeftRoom())); + connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&))); connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); + connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&))); + connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&))); + connect(hwnet, SIGNAL(AskForPassword(const QString&)), this, SLOT(NetPassword(const QString&))); + connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&))); + connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed())); //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); // rooms list page stuff @@ -875,11 +901,25 @@ connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &))); connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); - connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); + connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache())); // disconnect - connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); + connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection); + +// config stuff + connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); + connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); + connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); + while (nick.isEmpty()) { + nick = QInputDialog::getText(this, + QObject::tr("Nickname"), + QObject::tr("Please enter your nickname"), + QLineEdit::Normal, + QDir::home().dirName()); + config->setValue("net/nick",nick); + config->updNetNick(); + } hwnet->Connect(hostName, port, nick); } @@ -927,11 +967,6 @@ void HWForm::NetDisconnect() { - if(hwnet) { - hwnet->Disconnect(); - delete hwnet; - hwnet = 0; - } if(pnetserver) { if (pRegisterServer) { @@ -945,15 +980,12 @@ } } -void HWForm::ForcedDisconnect() +void HWForm::ForcedDisconnect(const QString & reason) { if(pnetserver) return; // we have server - let it care of all things if (hwnet) { - HWNewNet * tmp = hwnet; - hwnet = 0; - tmp->deleteLater(); QMessageBox::warning(this, QMessageBox::tr("Network"), - QMessageBox::tr("Connection to server is lost")); + QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'))); } if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack(); @@ -975,6 +1007,11 @@ ui.pageNetGame->pNetTeamsWidget->addTeam(team); } +void HWForm::RemoveNetTeam(const HWTeam& team) +{ + ui.pageNetGame->pNetTeamsWidget->removeNetTeam(team); +} + void HWForm::StartMPGame() { QString ammo; @@ -1089,11 +1126,11 @@ demofile.close(); } -void HWForm::StartTraining() +void HWForm::startTraining(const QString & scriptName) { CreateGame(0, 0, 0); - game->StartTraining(ui.pageTraining->CBSelect->itemData(ui.pageTraining->CBSelect->currentIndex()).toString()); + game->StartTraining(scriptName); } void HWForm::StartCampaign() @@ -1140,6 +1177,9 @@ void HWForm::NetGameChangeStatus(bool isMaster) { + ui.pageNetGame->pGameCFG->setEnabled(isMaster); + ui.pageNetGame->pNetTeamsWidget->setInteractivity(isMaster); + if (isMaster) NetGameMaster(); else @@ -1200,10 +1240,14 @@ ui.pageNetGame->pGameCFG->GameSchemes->setCurrentIndex(0); } -void HWForm::NetLeftRoom() +void HWForm::NetLeftRoom(const QString & reason) { if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME) + { GoBack(); + if (!reason.isEmpty()) + ui.pageRoomsList->chatWidget->addLine("Notice",reason); + } else qWarning("Left room while not in room"); } @@ -1231,7 +1275,8 @@ tmpdir.setFilter(QDir::Files); QStringList userentries = tmpdir.entryList(QStringList("*#*.lua")); //entries.sort(); - for(int i = 0; (i < userentries.count()) && (i <= team.CampaignProgress); i++) + unsigned int n = userentries.count(); + for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++) ui.pageCampaign->CBSelect->addItem(QString(userentries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(userentries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1")); tmpdir.cd(datadir->absolutePath()); @@ -1239,7 +1284,8 @@ tmpdir.setFilter(QDir::Files); QStringList entries = tmpdir.entryList(QStringList("*#*.lua")); //entries.sort(); - for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++) { + n = entries.count(); + for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++) { if (userentries.contains(entries[i])) continue; ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1")); } diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hwform.h --- a/QTfrontend/hwform.h Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/hwform.h Sat Oct 08 16:54:56 2011 +0200 @@ -52,13 +52,14 @@ Q_OBJECT public: - HWForm(QWidget *parent = 0); + HWForm(QWidget *parent = 0, QString styleSheet = ""); Ui_HWForm ui; SDLInteraction sdli; GameUIConfig * config; QSettings * gameSettings; // Same file GameUIConfig points to but without the baggage. Needs sync() calls if you want to get GameUIConfig changes though void updateXfire(); void PlayDemoQuick(const QString & demofilename); + void exit(); private slots: void GoToSaves(); @@ -76,20 +77,16 @@ QString getDemoArguments(); void AssociateFiles(); void btnExitPressed(); - void btnExitClicked(); void IntermediateSetup(); void NewTeam(); - void EditTeam(); - void DeleteTeam(); - void RandomNames(); - void RandomName(const int &i); - void TeamSave(); - void TeamDiscard(); + void EditTeam(const QString & teamName); + void AfterTeamEdit(); + void DeleteTeam(const QString & teamName); void DeleteScheme(); void DeleteWeaponSet(); void SimpleGame(); void PlayDemo(); - void StartTraining(); + void startTraining(const QString&); void StartCampaign(); void NetConnect(); void NetConnectServer(const QString & host, quint16 port); @@ -97,11 +94,18 @@ void NetStartServer(); void NetDisconnect(); void NetConnected(); + void NetError(const QString & errmsg); + void NetWarning(const QString & wrnmsg); void NetGameEnter(); + void NetPassword(const QString & nick); + void NetNickTaken(const QString & nick); + void NetAuthFailed(); + void NetTeamAccepted(const QString& team); void AddNetTeam(const HWTeam& team); + void RemoveNetTeam(const HWTeam& team); void StartMPGame(); void GameStateChanged(GameState gameState); - void ForcedDisconnect(); + void ForcedDisconnect(const QString & reason); void ShowErrorMessage(const QString &); void GetRecord(bool isDemo, const QByteArray & record); void CreateNetGame(); @@ -115,13 +119,13 @@ void NetGameSlave(); void AsyncNetServerStart(); - void NetLeftRoom(); + void NetLeftRoom(const QString & reason); void selectFirstNetScheme(); void saveDemoWithCustomName(); private: - void _NetConnect(const QString & hostName, quint16 port, const QString & nick); + void _NetConnect(const QString & hostName, quint16 port, QString nick); void UpdateTeamsLists(const QStringList* editable_teams=0); void CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo); void closeEvent(QCloseEvent *event); diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hwmap.cpp --- a/QTfrontend/hwmap.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Ulyanov Igor - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "hwconsts.h" -#include "hwmap.h" - -HWMap::HWMap() : - TCPBase(false) -{ -} - -HWMap::~HWMap() -{ -} - -void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData) -{ - m_seed = seed; - templateFilter = filter; - m_mapgen = mapgen; - m_maze_size = maze_size; - if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; - Start(); -} - -QStringList HWMap::getArguments() -{ - QStringList arguments; - arguments << cfgdir->absolutePath(); - arguments << QString("%1").arg(ipc_port); - arguments << "landpreview"; - return arguments; -} - -void HWMap::onClientDisconnect() -{ - if (readbuffer.size() == 128 * 32 + 1) - { - quint8 *buf = (quint8*) readbuffer.constData(); - QImage im(buf, 256, 128, QImage::Format_Mono); - im.setNumColors(2); - emit HHLimitReceived(buf[128 * 32]); - emit ImageReceived(im); - } -} - -void HWMap::SendToClientFirst() -{ - SendIPC(QString("eseed %1").arg(m_seed).toUtf8()); - SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8()); - SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8()); - - switch (m_mapgen) - { - case MAPGEN_MAZE: - SendIPC(QString("e$maze_size %1").arg(m_maze_size).toUtf8()); - break; - - case MAPGEN_DRAWN: - { - QByteArray data = m_drawMapData; - while(data.size() > 0) - { - QByteArray tmp = data; - tmp.truncate(200); - SendIPC("edraw " + tmp); - data.remove(0, 200); - } - break; - } - default: ; - } - - SendIPC("!"); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/hwmap.h --- a/QTfrontend/hwmap.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006 Igor Ulyanov - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _HWMAP_INCLUDED -#define _HWMAP_INCLUDED - -#include -#include -#include - -#include "tcpBase.h" - -enum MapGenerator -{ - MAPGEN_REGULAR, - MAPGEN_MAZE, - MAPGEN_DRAWN, - MAPGEN_MAP -}; - -class HWMap : public TCPBase -{ - Q_OBJECT - - public: - HWMap(); - virtual ~HWMap(); - void getImage(const QString & seed, int templateFilter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData); - - protected: - virtual QStringList getArguments(); - virtual void onClientDisconnect(); - virtual void SendToClientFirst(); - - signals: - void ImageReceived(const QImage newImage); - void HHLimitReceived(int hhLimit); - - private: - QString m_seed; - int templateFilter; - MapGenerator m_mapgen; - int m_maze_size; - QByteArray m_drawMapData; - - private slots: -}; - -#endif // _HWMAP_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/igbox.cpp --- a/QTfrontend/igbox.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include - -#include "igbox.h" - -IconedGroupBox::IconedGroupBox(QWidget * parent) - : QGroupBox(parent) -{ -// Has issues with border-radius on children -// setAttribute(Qt::WA_PaintOnScreen, true); - titleLeftPadding = 49; - contentTopPadding = 15; -} - -void IconedGroupBox::setIcon(const QIcon & icon) -{ - if (this->icon.isNull()) - setStyleSheet(QString( - "IconedGroupBox{" - "margin-top: 46px;" - "margin-left: 12px;" - "padding: %1px 2px 5px 2px;" - "}" - "IconedGroupBox::title{" - "subcontrol-origin: margin;" - "subcontrol-position: top left;" - "padding-left: %2px;" - "padding-top: %1px;" - "text-align: left;" - "}" - ).arg(contentTopPadding).arg(titleLeftPadding) - ); - - this->icon = icon; - repaint(); -} - -void IconedGroupBox::paintEvent(QPaintEvent * event) -{ - Q_UNUSED(event); - - QStylePainter painter(this); - - QStyleOptionGroupBox option; - initStyleOption(&option); - painter.drawComplexControl(QStyle::CC_GroupBox, option); - - icon.paint(&painter, QRect(QPoint(0, 0), icon.actualSize(size()))); -} - -void IconedGroupBox::setTitleTextPadding(int px) -{ - titleLeftPadding = px; -} - -void IconedGroupBox::setContentTopPadding(int px) -{ - contentTopPadding = px; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/igbox.h --- a/QTfrontend/igbox.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _IGBOX_H -#define _IGBOX_H - -#include -#include - -class IconedGroupBox : public QGroupBox -{ - Q_OBJECT - -public: - IconedGroupBox(QWidget * parent = 0); - - void setIcon(const QIcon & icon); - void setTitleTextPadding(int px); - void setContentTopPadding(int px); -protected: - virtual void paintEvent(QPaintEvent * event); - -private: - QIcon icon; - int titleLeftPadding; - int contentTopPadding; -}; - -#endif // _IGBOX_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/input_ip.cpp --- a/QTfrontend/input_ip.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include - -#include "input_ip.h" - -HWHostPortDialog::HWHostPortDialog(QWidget* parent) : QDialog(parent) -{ - QGridLayout * layout = new QGridLayout(this); - - QLabel * lbHost = new QLabel(this); - lbHost->setText(QLabel::tr("Host:")); - layout->addWidget(lbHost, 0, 0); - - QLabel * lbPort = new QLabel(this); - lbPort->setText(QLabel::tr("Port:")); - layout->addWidget(lbPort, 1, 0); - - leHost = new QLineEdit(this); - layout->addWidget(leHost, 0, 1, 1, 2); - - sbPort = new QSpinBox(this); - sbPort->setMinimum(0); - sbPort->setMaximum(65535); - layout->addWidget(sbPort, 1, 1, 1, 2); - - pbDefault = new QPushButton(this); - pbDefault->setText(QPushButton::tr("default")); - layout->addWidget(pbDefault, 1, 3); - - pbOK = new QPushButton(this); - pbOK->setText(QPushButton::tr("OK")); - pbOK->setDefault(true); - layout->addWidget(pbOK, 3, 1); - - pbCancel = new QPushButton(this); - pbCancel->setText(QPushButton::tr("Cancel")); - layout->addWidget(pbCancel, 3, 2); - - connect(pbOK, SIGNAL(clicked()), this, SLOT(accept())); - connect(pbCancel, SIGNAL(clicked()), this, SLOT(reject())); - connect(pbDefault, SIGNAL(clicked()), this, SLOT(setDefaultPort())); -} - -void HWHostPortDialog::setDefaultPort() -{ - sbPort->setValue(46631); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/input_ip.h --- a/QTfrontend/input_ip.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - - -#ifndef INPUT_IP_H -#define INPUT_IP_H - -#include -#include - -class QLineEdit; -class QSpinBox; -class QPushButton; - -class HWHostPortDialog : public QDialog -{ - Q_OBJECT -public: - HWHostPortDialog(QWidget* parent = 0); - - QLineEdit* leHost; - QSpinBox* sbPort; - -private: - QPushButton* pbOK; - QPushButton* pbCancel; - QPushButton * pbDefault; - -private slots: - void setDefaultPort(); -}; - - -#endif // INPUT_IP_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/itemNum.cpp --- a/QTfrontend/itemNum.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Igor Ulyanov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "itemNum.h" -#include "hwform.h" - -#include -#include - -ItemNum::ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min, unsigned char max) : - QFrame(parent), m_im(im), m_img(img), infinityState(false), nonInteractive(false), minItems(min), maxItems(max), - numItems(min+2 >= max ? min : min+2) -{ - enabled = true; - if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); -} - -ItemNum::~ItemNum() -{ -} - -void ItemNum::mousePressEvent ( QMouseEvent * event ) -{ - if(nonInteractive) return; - if(event->button()==Qt::LeftButton && enabled) { - event->accept(); - if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) { - incItems(); - } else { - numItems = minItems+1; - // appears there's an emit in there - decItems(); - } - } else if (event->button()==Qt::RightButton && enabled) { - event->accept(); - if(numItems > minItems) { - decItems(); - } else { - numItems = maxItems+(infinityState?0:-1); - incItems(); - } - } else { - event->ignore(); - return; - } - repaint(); -} - -QSize ItemNum::sizeHint () const -{ - return QSize((maxItems+1)*12, 32); -} - -void ItemNum::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - - QPainter painter(this); - - if (numItems==maxItems+1) { - QRect target(0, 0, 100, 32); - if (enabled) { - painter.drawImage(target, QImage(":/res/infinity.png")); - } else { - painter.drawImage(target, QImage(":/res/infinitygrey.png")); - } - } else { - for(int i=0; i - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#ifndef _ITEM_NUM_INCLUDED -#define _ITEM_NUM_INCLUDED - -class ItemNum : public QFrame -{ - Q_OBJECT - - public: - void setInfinityState(bool value); - void setEnabled(bool value); - unsigned char getItemsNum() const; - void setItemsNum(const unsigned char num); - - private: - QImage m_im; - QImage m_img; - bool infinityState; - bool enabled; - - protected: - ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min=2, unsigned char max=8); - virtual QSize sizeHint () const; - virtual ~ItemNum()=0; - - bool nonInteractive; - unsigned char minItems; - unsigned char maxItems; - unsigned char numItems; - - // from QWidget - virtual void mousePressEvent ( QMouseEvent * event ); - virtual void paintEvent(QPaintEvent* event); - - // to be implemented in child - virtual void incItems()=0; - virtual void decItems()=0; -}; - -#endif // _ITEM_NUM_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/main.cpp --- a/QTfrontend/main.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/main.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -96,8 +96,8 @@ Q_INIT_RESOURCE(hedgewars); - qApp->setStyleSheet - (QString( + QString styleSheetFromHell = + QString( "HWForm,QDialog{" "background-image: url(\":/res/Background.png\");" "background-position: bottom center;" @@ -251,6 +251,8 @@ "subcontrol-origin: margin;" "subcontrol-position: top left;" "text-align: left;" + "left: 15px;" + "top: -4px;" "}" "QCheckBox::indicator:checked{" @@ -315,8 +317,7 @@ "background-color: #ffcc00;" "width: 8px;" "}" - ) - ); + ); bindir->cd("bin"); // workaround over NSIS installer @@ -484,7 +485,7 @@ CocoaInitializer initializer; #endif - app.form = new HWForm(); + app.form = new HWForm(NULL,styleSheetFromHell); app.form->show(); return app.exec(); diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/mapContainer.cpp --- a/QTfrontend/mapContainer.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/mapContainer.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -114,6 +114,8 @@ QString scheme; QString weapons; QList mapInfo; + bool isMission = mapLuaFile.exists(); + QTextStream input(&mapCfgFile); input >> theme; input >> limit; @@ -125,16 +127,22 @@ mapInfo.push_back(limit); else mapInfo.push_back(18); - mapInfo.push_back(mapLuaFile.exists()); + + + mapInfo.push_back(isMission); + if (scheme.isEmpty()) scheme = "locked"; scheme.replace("_", " "); + if (weapons.isEmpty()) weapons = "locked"; weapons.replace("_", " "); + mapInfo.push_back(scheme); mapInfo.push_back(weapons); - if(mapLuaFile.exists()) + + if(isMission) { chooseMap->insertItem(missionindex++, // FIXME - need real icons. Disabling until then @@ -509,14 +517,14 @@ { int i = MAPGEN_MAP + 3 + numMissions + rand() % (chooseMap->count() - MAPGEN_MAP - 3 - numMissions); chooseMap->setCurrentIndex(i); - updatePreview(); + mapChanged(i); } void HWMapContainer::setRandomMission() { int i = MAPGEN_MAP + 2 + rand() % numMissions; chooseMap->setCurrentIndex(i); - updatePreview(); + mapChanged(i); } void HWMapContainer::setRandomSeed() diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/misc.cpp --- a/QTfrontend/misc.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2005-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "misc.h" diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/misc.h --- a/QTfrontend/misc.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2005-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _MISC_H -#define _MISC_H - - -#include -#include - -class FreqSpinBox : public QSpinBox -{ - Q_OBJECT - -public: - FreqSpinBox(QWidget* parent) : QSpinBox(parent) - { - - } - - QString textFromValue(int value) const - { - if (!value) - return tr("Never"); - else - return tr("Every %1 turn", "", value).arg(value); - } -}; - - -#endif // _MISC_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/ammoSchemeModel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/ammoSchemeModel.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,786 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2005-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "ammoSchemeModel.h" +#include "hwconsts.h" + +QList defaultScheme = QList() + << QVariant("Default") // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(false) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(45) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(5) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(4) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(2) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + +AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : + QAbstractTableModel(parent), + fileConfig(fileName, QSettings::IniFormat) +{ + predefSchemesNames = QStringList() + << "Default" + << "Pro Mode" + << "Shoppa" + << "Clean Slate" + << "Minefield" + << "Barrel Mayhem" + << "Tunnel Hogs" + << "Fort Mode" + << "Timeless" + << "Thinking with Portals" + << "King Mode" + ; + + numberOfDefaultSchemes = predefSchemesNames.size(); + + spNames = QStringList() + << "name" // 0 + << "fortsmode" // 1 + << "divteams" // 2 + << "solidland" // 3 + << "border" // 4 + << "lowgrav" // 5 + << "laser" // 6 + << "invulnerability" // 7 + << "resethealth" // 8 + << "vampiric" // 9 + << "karma" // 10 + << "artillery" // 11 + << "randomorder" // 12 + << "king" // 13 + << "placehog" // 14 + << "sharedammo" // 15 + << "disablegirders" // 16 + << "disablelandobjects" // 17 + << "aisurvival" // 18 + << "infattack" // 19 + << "resetweps" // 20 + << "perhogammo" // 21 + << "disablewind" // 22 + << "morewind" // 23 + << "tagteam" // 24 + << "bottomborder" // 25 + << "damagefactor" // 26 + << "turntime" // 27 + << "health" // 28 + << "suddendeath" // 29 + << "caseprobability" // 30 + << "minestime" // 31 + << "minesnum" // 32 + << "minedudpct" // 33 + << "explosives" // 34 + << "healthprobability" // 35 + << "healthcaseamount" // 36 + << "waterrise" // 37 + << "healthdecrease" // 38 + << "ropepct" // 39 + << "getawaytime" // 40 + ; + + QList proMode; + proMode + << predefSchemesNames[1] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(true) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(15) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(0) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(0) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(2) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList shoppa; + shoppa + << predefSchemesNames[2] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(true) // solid land 3 + << QVariant(true) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(true) // shared ammo 15 + << QVariant(true) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(true) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(30) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(50) // sudden death 29 + << QVariant(1) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(0) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(0) // explosives 34 + << QVariant(0) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList cleanslate; + cleanslate + << predefSchemesNames[3] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(true) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(false) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(true) // inf. attack 19 + << QVariant(true) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(45) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(5) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(4) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(2) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList minefield; + minefield + << predefSchemesNames[4] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(true) // shared ammo 15 + << QVariant(true) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(30) // turn time 27 + << QVariant(50) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(0) // case prob 30 + << QVariant(0) // mines time 31 + << QVariant(80) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(0) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList barrelmayhem; + barrelmayhem + << predefSchemesNames[5] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(true) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(30) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(0) // case prob 30 + << QVariant(0) // mines time 31 + << QVariant(0) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(80) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList tunnelhogs; + tunnelhogs + << predefSchemesNames[6] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(true) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(true) // shared ammo 15 + << QVariant(true) // disable girders 16 + << QVariant(true) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(30) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(5) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(10) // mines number 32 + << QVariant(10) // mine dud pct 33 + << QVariant(10) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList forts; + forts + << predefSchemesNames[7] // name 0 + << QVariant(true) // fortsmode 1 + << QVariant(true) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(true) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(false) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(45) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(5) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(0) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(0) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList timeless; + timeless + << predefSchemesNames[8] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(false) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(true) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(9999) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(5) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(5) // mines number 32 + << QVariant(10) // mine dud pct 33 + << QVariant(2) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(30) // health case amt 36 + << QVariant(0) // water rise amt 37 + << QVariant(0) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList thinkingportals; + thinkingportals + << predefSchemesNames[9] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(true) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(false) // king 13 + << QVariant(false) // place hog 14 + << QVariant(false) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(45) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(2) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(5) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(5) // explosives 34 + << QVariant(25) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + QList kingmode; + kingmode + << predefSchemesNames[10] // name 0 + << QVariant(false) // fortsmode 1 + << QVariant(false) // team divide 2 + << QVariant(false) // solid land 3 + << QVariant(false) // border 4 + << QVariant(false) // low gravity 5 + << QVariant(false) // laser sight 6 + << QVariant(false) // invulnerable 7 + << QVariant(false) // reset health 8 + << QVariant(false) // vampiric 9 + << QVariant(false) // karma 10 + << QVariant(false) // artillery 11 + << QVariant(true) // random order 12 + << QVariant(true) // king 13 + << QVariant(false) // place hog 14 + << QVariant(false) // shared ammo 15 + << QVariant(false) // disable girders 16 + << QVariant(false) // disable land objects 17 + << QVariant(false) // AI survival 18 + << QVariant(false) // inf. attack 19 + << QVariant(false) // reset weps 20 + << QVariant(false) // per hog ammo 21 + << QVariant(false) // no wind 22 + << QVariant(false) // more wind 23 + << QVariant(false) // tag team 24 + << QVariant(false) // bottom border 25 + << QVariant(100) // damage modfier 26 + << QVariant(45) // turn time 27 + << QVariant(100) // init health 28 + << QVariant(15) // sudden death 29 + << QVariant(5) // case prob 30 + << QVariant(3) // mines time 31 + << QVariant(4) // mines number 32 + << QVariant(0) // mine dud pct 33 + << QVariant(2) // explosives 34 + << QVariant(35) // health case pct 35 + << QVariant(25) // health case amt 36 + << QVariant(47) // water rise amt 37 + << QVariant(5) // health dec amt 38 + << QVariant(100) // rope modfier 39 + << QVariant(100) // get away time 40 + ; + + + schemes.append(defaultScheme); + schemes.append(proMode); + schemes.append(shoppa); + schemes.append(cleanslate); + schemes.append(minefield); + schemes.append(barrelmayhem); + schemes.append(tunnelhogs); + schemes.append(forts); + schemes.append(timeless); + schemes.append(thinkingportals); + schemes.append(kingmode); + + + int size = fileConfig.beginReadArray("schemes"); + for (int i = 0; i < size; ++i) { + fileConfig.setArrayIndex(i); + + if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) + { + QList scheme; + + for (int k = 0; k < spNames.size(); ++k) + scheme << fileConfig.value(spNames[k], defaultScheme[k]); + + schemes.append(scheme); + } + } + fileConfig.endArray(); +} + +QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + Q_UNUSED(section); + Q_UNUSED(orientation); + Q_UNUSED(role); + + return QVariant(); +} + +int AmmoSchemeModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + else + return schemes.size(); +} + +int AmmoSchemeModel::columnCount(const QModelIndex & parent) const +{ + if (parent.isValid()) + return 0; + else + return defaultScheme.size(); +} + +Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const +{ + Q_UNUSED(index); + + return + Qt::ItemIsEnabled + | Qt::ItemIsSelectable + | Qt::ItemIsEditable; +} + +bool AmmoSchemeModel::setData(const QModelIndex & index, const QVariant & value, int role) +{ + if (!index.isValid() || index.row() < numberOfDefaultSchemes + || index.row() >= schemes.size() + || index.column() >= defaultScheme.size() + || role != Qt::EditRole) + return false; + + schemes[index.row()][index.column()] = value; + + emit dataChanged(index, index); + return true; +} + +bool AmmoSchemeModel::insertRows(int row, int count, const QModelIndex & parent) +{ + Q_UNUSED(count); + + beginInsertRows(parent, schemes.size(), schemes.size()); + + if (row == -1) + { + QList newScheme = defaultScheme; + newScheme[0] = QVariant(tr("new")); + schemes.insert(schemes.size(), newScheme); + } + else + { + QList newScheme = schemes[row]; + newScheme[0] = QVariant(tr("copy of") + " " + newScheme[0].toString()); + schemes.insert(schemes.size(), newScheme); + } + + endInsertRows(); + + return true; +} + +bool AmmoSchemeModel::removeRows(int row, int count, const QModelIndex & parent) +{ + if(count != 1 + || row < numberOfDefaultSchemes + || row >= schemes.size()) + return false; + + beginRemoveRows(parent, row, row); + + schemes.removeAt(row); + + endRemoveRows(); + + return true; +} + +QVariant AmmoSchemeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() < 0 + || index.row() >= schemes.size() + || index.column() >= defaultScheme.size() + || (role != Qt::EditRole && role != Qt::DisplayRole) + ) + return QVariant(); + + return schemes[index.row()][index.column()]; +} + +void AmmoSchemeModel::Save() +{ + fileConfig.beginWriteArray("schemes", schemes.size() - numberOfDefaultSchemes); + + for (int i = 0; i < schemes.size() - numberOfDefaultSchemes; ++i) { + fileConfig.setArrayIndex(i); + + QList scheme = schemes[i + numberOfDefaultSchemes]; + + for (int k = 0; k < scheme.size(); ++k) + fileConfig.setValue(spNames[k], scheme[k]); + } + fileConfig.endArray(); +} + + +NetAmmoSchemeModel::NetAmmoSchemeModel(QObject * parent) : + QAbstractTableModel(parent) +{ + netScheme = defaultScheme; +} + +QVariant NetAmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + Q_UNUSED(section); + Q_UNUSED(orientation); + Q_UNUSED(role); + + return QVariant(); +} + +int NetAmmoSchemeModel::rowCount(const QModelIndex & parent) const +{ + if (parent.isValid()) + return 0; + else + return 1; +} + +int NetAmmoSchemeModel::columnCount(const QModelIndex & parent) const +{ + if (parent.isValid()) + return 0; + else + return defaultScheme.size(); +} + +QVariant NetAmmoSchemeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() < 0 + || index.row() > 1 + || index.column() >= defaultScheme.size() + || (role != Qt::EditRole && role != Qt::DisplayRole) + ) + return QVariant(); + + return netScheme[index.column()]; +} + +void NetAmmoSchemeModel::setNetSchemeConfig(QStringList & cfg) +{ + if(cfg.size() != netScheme.size()) + { + qWarning("Incorrect scheme cfg size"); + return; + } + + for(int i = 0; i < cfg.size(); ++i) + netScheme[i] = QVariant(cfg[i]); + + reset(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/ammoSchemeModel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/ammoSchemeModel.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,79 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2005-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _AMMO_SCHEME_MODEL_INCLUDED +#define _AMMO_SCHEME_MODEL_INCLUDED + +#include +#include +#include +#include + +class AmmoSchemeModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + AmmoSchemeModel(QObject * parent, const QString & fileName); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + int rowCount(const QModelIndex & parent) const; + int columnCount(const QModelIndex & parent) const; + Qt::ItemFlags flags(const QModelIndex & index) const; + bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + bool insertRows(int row, int count, const QModelIndex & parent = QModelIndex()); + bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); + QVariant data(const QModelIndex &index, int role) const; + + int numberOfDefaultSchemes; + QStringList predefSchemesNames; + QStringList spNames; + +public slots: + void Save(); + +signals: + void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight); + +protected: + QList< QList > schemes; + +private: + QSettings fileConfig; +}; + +class NetAmmoSchemeModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + NetAmmoSchemeModel(QObject * parent); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + int rowCount(const QModelIndex & parent) const; + int columnCount(const QModelIndex & parent) const; + QVariant data(const QModelIndex &index, int role) const; + +public slots: + void setNetSchemeConfig(QStringList & cfg); + +private: + QList netScheme; +}; + +#endif // _AMMO_SCHEME_MODEL_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/hats.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/hats.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,142 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include "hwconsts.h" +#include "hwform.h" +#include "hats.h" + +HatsModel::HatsModel(QObject* parent) : + QAbstractListModel(parent) +{ + QFile hhfile; + hhfile.setFileName(cfgdir->absolutePath() + "/Data/Graphics/Hedgehog/Idle.png"); + if (!hhfile.exists()) hhfile.setFileName(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png"); + QPixmap hhpix = QPixmap(QFileInfo(hhfile).absoluteFilePath()).copy(0, 0, 32, 32); + + QDir tmpdir; + tmpdir.cd(cfgdir->absolutePath()); + tmpdir.cd("Data"); + tmpdir.cd("Graphics"); + tmpdir.cd("Hats"); + + tmpdir.setFilter(QDir::Files); + + QStringList userhatsList = tmpdir.entryList(QStringList("*.png")); + for (QStringList::Iterator it = userhatsList.begin(); it != userhatsList.end(); ++it ) + { + QString str = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); + QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Hats/" + str + ".png"); + + QPixmap tmppix(32, 37); + tmppix.fill(QColor(Qt::transparent)); + + QPainter painter(&tmppix); + painter.drawPixmap(QPoint(0, 5), hhpix); + painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); + if(pix.width() > 32) + painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32)); + painter.end(); + + hats.append(qMakePair(str, QIcon(tmppix))); + } + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Graphics"); + tmpdir.cd("Hats"); + + QStringList hatsList = tmpdir.entryList(QStringList("*.png")); + for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) + { + if (userhatsList.contains(*it,Qt::CaseInsensitive)) continue; + QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); + QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); + + QPixmap tmppix(32, 37); + tmppix.fill(QColor(Qt::transparent)); + + QPainter painter(&tmppix); + painter.drawPixmap(QPoint(0, 5), hhpix); + painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); + if(pix.width() > 32) + painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32)); + painter.end(); + + hats.append(qMakePair(str, QIcon(tmppix))); + } + // Reserved hats + tmpdir.cd("Reserved"); + hatsList = tmpdir.entryList(QStringList(playerHash+"*.png")); + for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) + { + QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); + QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png"); + + QPixmap tmppix(32, 37); + tmppix.fill(QColor(Qt::transparent)); + + QPainter painter(&tmppix); + painter.drawPixmap(QPoint(0, 5), hhpix); + painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); + painter.end(); + + hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix))); + } +} + +QVariant HatsModel::headerData(int section, + Qt::Orientation orientation, int role) const +{ + Q_UNUSED(section); + Q_UNUSED(orientation); + Q_UNUSED(role); + + return QVariant(); +} + +int HatsModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + else + return hats.size(); +} + +/*int HatsModel::columnCount(const QModelIndex & parent) const +{ + if (parent.isValid()) + return 0; + else + return 2; +} +*/ +QVariant HatsModel::data(const QModelIndex &index, + int role) const +{ + if (!index.isValid() || index.row() < 0 + || index.row() >= hats.size() + || (role != Qt::DisplayRole && role != Qt::DecorationRole)) + return QVariant(); + + if (role == Qt::DisplayRole) + return hats.at(index.row()).first; + else // role == Qt::DecorationRole + return hats.at(index.row()).second; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/hats.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/hats.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,44 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _HATS_INCLUDED +#define _HATS_INCLUDED + +#include +#include +#include +#include +#include + +class HatsModel : public QAbstractListModel +{ + Q_OBJECT + +public: + HatsModel(QObject *parent = 0); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + int rowCount(const QModelIndex & parent) const; + //int columnCount(const QModelIndex & parent) const; + + QVariant data(const QModelIndex &index, int role) const; +protected: + QVector > hats; +}; + +#endif // _HATS_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/netserverslist.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/netserverslist.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,68 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "netserverslist.h" + +HWNetServersModel::HWNetServersModel(QObject* parent) : + QAbstractTableModel(parent) +{ + +} + +void HWNetServersModel::updateList() +{ + +} + +QVariant HWNetServersModel::headerData(int section, + Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + if (orientation == Qt::Horizontal) + { + switch (section) + { + case 0: return tr("Title"); + case 1: return tr("IP"); + case 2: return tr("Port"); + default: return QVariant(); + } + } else + return QString("%1").arg(section + 1); +} + +int HWNetServersModel::rowCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + else + return games.size(); +} + +int HWNetServersModel::columnCount(const QModelIndex & parent) const +{ + if (parent.isValid()) + return 0; + else + return 3; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/netserverslist.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/netserverslist.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,43 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _NET_SERVERSLIST_INCLUDED +#define _NET_SERVERSLIST_INCLUDED + +#include +#include + +class HWNetServersModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + HWNetServersModel(QObject *parent = 0); + + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + int rowCount(const QModelIndex & parent) const; + int columnCount(const QModelIndex & parent) const; + +public slots: + virtual void updateList(); + +protected: + QList games; +}; + +#endif // _NET_SERVERSLIST_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/themesmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/themesmodel.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,49 @@ + +#include "themesmodel.h" + +ThemesModel::ThemesModel(QStringList themes, QObject *parent) : + QAbstractListModel(parent) +{ +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + m_data.reserve(themes.size()); +#endif + + foreach(QString theme, themes) + { + m_data.append(QHash()); + m_data.last().insert(Qt::DisplayRole, theme); + } +} + +int ThemesModel::rowCount(const QModelIndex &parent) const +{ + if(parent.isValid()) + return 0; + else + return m_data.size(); +} + +QVariant ThemesModel::data(const QModelIndex &index, int role) const +{ + if(index.column() > 0 || index.row() >= m_data.size()) + return QVariant(); + else + return m_data.at(index.row()).value(role); +} + +bool ThemesModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if(index.column() > 0 || index.row() >= m_data.size()) + return false; + else + { + m_data[index.row()].insert(role, value); + + return true; + } + +} + + + + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/model/themesmodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/model/themesmodel.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,28 @@ +#ifndef THEMESMODEL_H +#define THEMESMODEL_H + +#include +#include +#include + +class ThemesModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit ThemesModel(QStringList themes, QObject *parent = 0); + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, + int role = Qt::EditRole); + +signals: + +public slots: + +private: + + QList > m_data; +}; + +#endif // THEMESMODEL_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/namegen.cpp --- a/QTfrontend/namegen.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,221 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2009 Martin Minarik - * Copyright (c) 2009-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include "namegen.h" -#include "hwform.h" -#include "hwconsts.h" - - -HWNamegen::HWNamegen() : - TypesAvliable(false) -{ - - TypesLoad(); -} - -HWNamegen::~HWNamegen() -{ -} - - - -void HWNamegen::TeamRandomName(HWTeam*& team, const int HedgehogNumber) -{ - RandomNameByHat(team, HedgehogNumber); -} - -void HWNamegen::TeamRandomNames(HWTeam*& team, const bool changeteamname) -{ - if ((TypesHatnames.size() > 0) && TypesAvliable){ - - int kind = (rand()%(TypesHatnames.size())); - - if (changeteamname){ - if (TypesTeamnames[kind].size() > 0){ - team->TeamName = TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())]; - } - team->Grave = GetRandomGrave(); - team->Fort = GetRandomFort(); - team->Voicepack = "Default"; - } - - //give each hedgehog a random name: - //TODO: load the dictionary only once! (right now it's loaded once for each hedgehog) - for(int i = 0; i < 8; i++) - { - if ((TypesHatnames[kind].size()) > 0){ - team->Hedgehogs[i].Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())]; - } - RandomNameByHat(team,i); - } - - } - -} - - -void HWNamegen::RandomNameByHat(HWTeam*& team, const int HedgehogNumber) -{ - QStringList Dictionaries; - HatCfgLoad(team->Hedgehogs[HedgehogNumber].Hat,Dictionaries); - - QStringList Dictionary; - DictLoad(Dictionaries[rand()%(Dictionaries.size())],Dictionary); - - team->Hedgehogs[HedgehogNumber].Name = Dictionary[rand()%(Dictionary.size())]; -} - -void HWNamegen::DictLoad(const QString filename, QStringList &list) -{ - list.clear(); - - QFile file; - file.setFileName(QString("%1/Data/Names/%2.txt").arg(cfgdir->absolutePath()).arg(filename)); - if (!file.exists()) file.setFileName(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename)); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - - QTextStream in(&file); - while (!in.atEnd()) { - QString line = in.readLine(); - if(line != QString("")) - {list.append(line);} - } - } - - if (list.size()==0) - list.append(filename); - -} - - -void HWNamegen::HatCfgLoad(const QString hatname, QStringList &list) -{ - list.clear(); - - QFile file; - file.setFileName(QString("%1/Data/Names/%2.cfg").arg(cfgdir->absolutePath()).arg(hatname)); - if (!file.exists()) file.setFileName(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname)); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - - QTextStream in(&file); - while (!in.atEnd()) { - QString line = in.readLine(); - if(line != QString("")) - {list.append(line);} - } - } - - if (list.size()==0) - list.append(QString("generic")); - -} - - -void HWNamegen::TypesLoad() -{ - QFile file; - file.setFileName(QString("%1/Data/Names/types.ini").arg(cfgdir->absolutePath())); - if (!file.exists()) file.setFileName(QString("%1/Names/types.ini").arg(datadir->absolutePath())); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) - {TypesAvliable = FALSE; return;} - - int counter = 0; //counter starts with 0 (teamnames mode) - TypesTeamnames.append(QStringList()); - TypesHatnames.append(QStringList()); - - QTextStream in(&file); - while (!in.atEnd()) { - QString line = in.readLine(); - if (line == QString("#####")){ - counter++; //toggle mode (teamnames || hats) - if ((counter%2) == 0){ - TypesTeamnames.append(QStringList()); - TypesHatnames.append(QStringList()); - } - } else if ((line == QString("*****")) || (line == QString("*END*"))){ - TypesAvliable = TRUE; return; // bye bye - } else { - if ((counter%2) == 0){ // even => teamnames mode - TypesTeamnames[(counter/2)].append(line); - } else { // odd => hats mode - TypesHatnames[((counter-1)/2)].append(line); - } - } -// Types.append(line); - } - TypesAvliable = TRUE; - return; -} - - - -QString HWNamegen::GetRandomGrave() -{ - QStringList Graves; - - //list all available Graves - QDir tmpdir; - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data/Graphics/Graves"); - tmpdir.setFilter(QDir::Files); - Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1")); - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Graphics/Graves"); - tmpdir.setFilter(QDir::Files); - QStringList tmpList = tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"); - for (QStringList::Iterator it = tmpList.begin(); it != tmpList.end(); ++it) - if (!Graves.contains(*it,Qt::CaseInsensitive)) Graves.append(*it); - - if(Graves.size()==0) - { - //do some serious error handling - return "Error"; - } - - //pick a random grave - return Graves[rand()%(Graves.size())]; -} - -QString HWNamegen::GetRandomFort() -{ - QStringList Forts; - - //list all available Forts - QDir tmpdir; - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Forts"); - tmpdir.setFilter(QDir::Files); - Forts.append(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1")); - - if(Forts.size()==0) - { - //do some serious error handling - return "Error"; - } - - //pick a random fort - return Forts[rand()%(Forts.size())]; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/namegen.h --- a/QTfrontend/namegen.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2009 Martin Minarik - * Copyright (c) 2009-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef NAMEGEN_H -#define NAMEGEN_H - -#include - -class HWForm; -class HWTeam; - -class HWNamegen -{ -public: - HWNamegen(); - ~HWNamegen(); - - void TeamRandomName(HWTeam*& team, const int HedgehogNumber); - void TeamRandomNames(HWTeam*& team, const bool changeteamname); - void RandomNameByHat(HWTeam*& team, const int HedgehogNumber); - -private: - - QList TypesTeamnames; - QList TypesHatnames; - bool TypesAvliable; - void TypesLoad(); - void DictLoad(const QString filename, QStringList &list); - void HatCfgLoad(const QString hatname, QStringList &list); - - QString GetRandomGrave(); - QString GetRandomFort(); -}; - - - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/hwmap.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/hwmap.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,91 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Ulyanov Igor + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "hwconsts.h" +#include "hwmap.h" + +HWMap::HWMap() : + TCPBase(false) +{ +} + +HWMap::~HWMap() +{ +} + +void HWMap::getImage(const QString & seed, int filter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData) +{ + m_seed = seed; + templateFilter = filter; + m_mapgen = mapgen; + m_maze_size = maze_size; + if(mapgen == MAPGEN_DRAWN) m_drawMapData = drawMapData; + Start(); +} + +QStringList HWMap::getArguments() +{ + QStringList arguments; + arguments << cfgdir->absolutePath(); + arguments << QString("%1").arg(ipc_port); + arguments << "landpreview"; + return arguments; +} + +void HWMap::onClientDisconnect() +{ + if (readbuffer.size() == 128 * 32 + 1) + { + quint8 *buf = (quint8*) readbuffer.constData(); + QImage im(buf, 256, 128, QImage::Format_Mono); + im.setNumColors(2); + emit HHLimitReceived(buf[128 * 32]); + emit ImageReceived(im); + } +} + +void HWMap::SendToClientFirst() +{ + SendIPC(QString("eseed %1").arg(m_seed).toUtf8()); + SendIPC(QString("e$template_filter %1").arg(templateFilter).toUtf8()); + SendIPC(QString("e$mapgen %1").arg(m_mapgen).toUtf8()); + + switch (m_mapgen) + { + case MAPGEN_MAZE: + SendIPC(QString("e$maze_size %1").arg(m_maze_size).toUtf8()); + break; + + case MAPGEN_DRAWN: + { + QByteArray data = m_drawMapData; + while(data.size() > 0) + { + QByteArray tmp = data; + tmp.truncate(200); + SendIPC("edraw " + tmp); + data.remove(0, 200); + } + break; + } + default: ; + } + + SendIPC("!"); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/hwmap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/hwmap.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,65 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006 Igor Ulyanov + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _HWMAP_INCLUDED +#define _HWMAP_INCLUDED + +#include +#include +#include + +#include "tcpBase.h" + +enum MapGenerator +{ + MAPGEN_REGULAR, + MAPGEN_MAZE, + MAPGEN_DRAWN, + MAPGEN_MAP +}; + +class HWMap : public TCPBase +{ + Q_OBJECT + + public: + HWMap(); + virtual ~HWMap(); + void getImage(const QString & seed, int templateFilter, MapGenerator mapgen, int maze_size, const QByteArray & drawMapData); + + protected: + virtual QStringList getArguments(); + virtual void onClientDisconnect(); + virtual void SendToClientFirst(); + + signals: + void ImageReceived(const QImage newImage); + void HHLimitReceived(int hhLimit); + + private: + QString m_seed; + int templateFilter; + MapGenerator m_mapgen; + int m_maze_size; + QByteArray m_drawMapData; + + private slots: +}; + +#endif // _HWMAP_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netregister.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netregister.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,31 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "netregister.h" + +HWNetRegisterServer::HWNetRegisterServer(QObject *parent, const QString & descr, quint16 port) : + QObject(parent) +{ + Q_UNUSED(descr); + Q_UNUSED(port); +} + +void HWNetRegisterServer::unregister() +{ + +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netregister.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netregister.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,35 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _NET_REGISTER_INCLUDED +#define _NET_REGISTER_INCLUDED + +#include + +class HWNetRegisterServer : public QObject +{ + Q_OBJECT + +public: + HWNetRegisterServer(QObject *parent, const QString & descr, quint16 port); + +public slots: + virtual void unregister(); +}; + +#endif // _NET_REGISTER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netserver.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,52 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include + +#include "hwconsts.h" +#include "netserver.h" + +HWNetServer::~HWNetServer() +{ + StopServer(); +} + +bool HWNetServer::StartServer(quint16 port) +{ + ds_port = port; + + QStringList params; + params << QString("--port=%1").arg(port); + params << "--dedicated=False"; + + process.start(bindir->absolutePath() + "/hedgewars-server", params); + + return process.waitForStarted(5000); +} + +void HWNetServer::StopServer() +{ + process.close(); +} + + +quint16 HWNetServer::getRunningPort() const +{ + return ds_port; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netserver.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,42 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _NETSERVER_INCLUDED +#define _NETSERVER_INCLUDED + +#include +#include + +class HWNetServer : public QObject +{ + Q_OBJECT + +public: + ~HWNetServer(); + bool StartServer(quint16 port); + void StopServer(); + QString getRunningHostName() const; + quint16 getRunningPort() const; + +private: + quint16 ds_port; + QProcess process; +}; + +#endif // _NETSERVER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netudpserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netudpserver.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,51 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include + +#include "netudpserver.h" + +HWNetUdpServer::HWNetUdpServer(QObject *parent, const QString & descr, quint16 port) : + HWNetRegisterServer(parent, descr, port), + m_descr(descr) +{ + pUdpSocket = new QUdpSocket(this); + pUdpSocket->bind(46631); + connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead())); +} + +void HWNetUdpServer::onClientRead() +{ + while (pUdpSocket->hasPendingDatagrams()) { + QByteArray datagram; + datagram.resize(pUdpSocket->pendingDatagramSize()); + QHostAddress clientAddr; + quint16 clientPort; + pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); + if(datagram.startsWith("hedgewars client")) { + // send answer to client + pUdpSocket->writeDatagram(QString("hedgewars server\n%1").arg(m_descr).toUtf8(), clientAddr, clientPort); + } + } +} + +void HWNetUdpServer::unregister() +{ + deleteLater(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netudpserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netudpserver.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,46 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _NET_UDPSERVER_INCLUDED +#define _NET_UDPSERVER_INCLUDED + +#include +#include "netregister.h" + +class QUdpSocket; + +class HWNetUdpServer : public HWNetRegisterServer +{ + Q_OBJECT + + public: + HWNetUdpServer(QObject *parent, const QString & descr, quint16 port); + + public slots: + void unregister(); + + private slots: + void onClientRead(); + + private: + QUdpSocket* pUdpSocket; + QString m_descr; +}; + +#endif // _NET_UDPSERVER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netudpwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netudpwidget.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,72 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include + +#include "netudpwidget.h" + +HWNetUdpModel::HWNetUdpModel(QObject* parent) : + HWNetServersModel(parent) +{ + pUdpSocket = new QUdpSocket(this); + + pUdpSocket->bind(); + connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead())); +} + +void HWNetUdpModel::updateList() +{ + games.clear(); + + reset(); + + pUdpSocket->writeDatagram("hedgewars client", QHostAddress::Broadcast, 46631); +} + +void HWNetUdpModel::onClientRead() +{ + while (pUdpSocket->hasPendingDatagrams()) { + QByteArray datagram; + datagram.resize(pUdpSocket->pendingDatagramSize()); + QHostAddress clientAddr; + quint16 clientPort; + + pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); + + QString packet = QString::fromUtf8(datagram.data()); + if(packet.startsWith("hedgewars server")) { + QStringList sl; + sl << packet.remove(0, 17) << clientAddr.toString() << "46631"; + games.append(sl); + } + } + + reset(); +} + +QVariant HWNetUdpModel::data(const QModelIndex &index, + int role) const +{ + if (!index.isValid() || index.row() < 0 + || index.row() >= games.size() + || role != Qt::DisplayRole) + return QVariant(); + + return games[index.row()][index.column()]; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/netudpwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/netudpwidget.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,46 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _NET_UDPWIDGET_INCLUDED +#define _NET_UDPWIDGET_INCLUDED + +#include "netserverslist.h" + +class QUdpSocket; + +class HWNetUdpModel : public HWNetServersModel +{ + Q_OBJECT + +public: + HWNetUdpModel(QObject *parent = 0); + + QVariant data(const QModelIndex &index, int role) const; + +public slots: + void updateList(); + +private slots: + void onClientRead(); + +private: + QUdpSocket* pUdpSocket; +}; + +#endif // _NET_UDPWIDGET_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/newnetclient.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/newnetclient.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,786 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include "hwconsts.h" +#include "newnetclient.h" +#include "proto.h" +#include "game.h" + +char delimeter='\n'; + +HWNewNet::HWNewNet() : + isChief(false), + m_game_connected(false), + loginStep(0), + netClientState(Disconnected) +{ +// socket stuff + connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); + connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); + connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); + connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, + SLOT(displayError(QAbstractSocket::SocketError))); +} + +HWNewNet::~HWNewNet() +{ + if (m_game_connected) + { + RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); + emit disconnected(tr("User quit")); + } + NetSocket.flush(); +} + +void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick) +{ + netClientState = Connecting; + mynick = nick; + myhost = hostName + QString(":%1").arg(port); + NetSocket.connectToHost(hostName, port); +} + +void HWNewNet::Disconnect() +{ + if (m_game_connected) + RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); + m_game_connected = false; + + NetSocket.disconnectFromHost(); +} + +void HWNewNet::CreateRoom(const QString & room) +{ + if(netClientState != InLobby) + { + qWarning("Illegal try to create room!"); + return; + } + + myroom = room; + + RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room)); + isChief = true; +} + +void HWNewNet::JoinRoom(const QString & room) +{ + if(netClientState != InLobby) + { + qWarning("Illegal try to join room!"); + return; + } + + myroom = room; + + RawSendNet(QString("JOIN_ROOM%1%2").arg(delimeter).arg(room)); + isChief = false; +} + +void HWNewNet::AddTeam(const HWTeam & team) +{ + QString cmd = QString("ADD_TEAM") + delimeter + + team.name() + delimeter + + team.color().name() + delimeter + + team.grave() + delimeter + + team.fort() + delimeter + + team.voicepack() + delimeter + + team.flag() + delimeter + + QString::number(team.difficulty()); + + for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i) + { + cmd.append(delimeter); + cmd.append(team.hedgehog(i).Name); + cmd.append(delimeter); + cmd.append(team.hedgehog(i).Hat); + } + RawSendNet(cmd); +} + +void HWNewNet::RemoveTeam(const HWTeam & team) +{ + RawSendNet(QString("REMOVE_TEAM") + delimeter + team.name()); +} + +void HWNewNet::NewNick(const QString & nick) +{ + RawSendNet(QString("NICK%1%2").arg(delimeter).arg(nick)); +} + +void HWNewNet::ToggleReady() +{ + RawSendNet(QString("TOGGLE_READY")); +} + +void HWNewNet::SendNet(const QByteArray & buf) +{ + QString msg = QString(buf.toBase64()); + + RawSendNet(QString("EM%1%2").arg(delimeter).arg(msg)); +} + +void HWNewNet::RawSendNet(const QString & str) +{ + RawSendNet(str.toUtf8()); +} + +void HWNewNet::RawSendNet(const QByteArray & buf) +{ + qDebug() << "Client: " << QString(buf).split("\n"); + NetSocket.write(buf); + NetSocket.write("\n\n", 2); +} + +void HWNewNet::ClientRead() +{ + while (NetSocket.canReadLine()) { + QString s = QString::fromUtf8(NetSocket.readLine()); + if (s.endsWith('\n')) s.chop(1); + + if (s.size() == 0) { + ParseCmd(cmdbuf); + cmdbuf.clear(); + } else + cmdbuf << s; + } +} + +void HWNewNet::OnConnect() +{ + netClientState = Connected; +} + +void HWNewNet::OnDisconnect() +{ + netClientState = Disconnected; + if(m_game_connected) emit disconnected(""); + m_game_connected = false; +} + +void HWNewNet::displayError(QAbstractSocket::SocketError socketError) +{ + m_game_connected = false; + + switch (socketError) { + case QAbstractSocket::RemoteHostClosedError: + break; + case QAbstractSocket::HostNotFoundError: + emit disconnected(tr("The host was not found. Please check the host name and port settings.")); + break; + case QAbstractSocket::ConnectionRefusedError: + emit disconnected(tr("Connection refused")); + break; + default: + emit disconnected(NetSocket.errorString()); + } +} + +void HWNewNet::SendPasswordHash(const QString & hash) +{ + RawSendNet(QString("PASSWORD%1%2").arg(delimeter).arg(hash)); +} + +void HWNewNet::ParseCmd(const QStringList & lst) +{ + qDebug() << "Server: " << lst; + + if(!lst.size()) + { + qWarning("Net client: Bad message"); + return; + } + + if (lst[0] == "NICK") + { + mynick = lst[1]; + return ; + } + + if (lst[0] == "PROTO") + return ; + + if (lst[0] == "ERROR") { + if (lst.size() == 2) + emit Error(lst[1]); + else + emit Error("Unknown error"); + return; + } + + if (lst[0] == "WARNING") { + if (lst.size() == 2) + emit Warning(lst[1]); + else + emit Warning("Unknown warning"); + return; + } + + if (lst[0] == "CONNECTED") { + if(lst.size() < 3 || lst[2].toInt() < cMinServerVersion) + { + // TODO: Warn user, disconnect + qWarning() << "Server too old"; + } + + RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); + RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); + netClientState = Connected; + m_game_connected = true; + emit adminAccess(false); + return; + } + + if (lst[0] == "PING") { + if (lst.size() > 1) + RawSendNet(QString("PONG%1%2").arg(delimeter).arg(lst[1])); + else + RawSendNet(QString("PONG")); + return; + } + + if (lst[0] == "ROOMS") { + QStringList tmp = lst; + tmp.removeFirst(); + emit roomsList(tmp); + return; + } + + if (lst[0] == "SERVER_MESSAGE") { + if(lst.size() < 2) + { + qWarning("Net: Empty SERVERMESSAGE message"); + return; + } + emit serverMessage(lst[1]); + return; + } + + if (lst[0] == "CHAT") { + if(lst.size() < 3) + { + qWarning("Net: Empty CHAT message"); + return; + } + if (netClientState == InLobby) + emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2])); + else + emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2])); + return; + } + + if (lst[0] == "INFO") { + if(lst.size() < 5) + { + qWarning("Net: Malformed INFO message"); + return; + } + QStringList tmp = lst; + tmp.removeFirst(); + if (netClientState == InLobby) + emit chatStringLobby(tmp.join("\n").prepend('\x01')); + else + emit chatStringFromNet(tmp.join("\n").prepend('\x01')); + return; + } + + if (lst[0] == "SERVER_VARS") { + QStringList tmp = lst; + tmp.removeFirst(); + while (tmp.size() >= 2) + { + if(tmp[0] == "MOTD_NEW") emit serverMessageNew(tmp[1]); + else if(tmp[0] == "MOTD_OLD") emit serverMessageOld(tmp[1]); + else if(tmp[0] == "LATEST_PROTO") emit latestProtocolVar(tmp[1].toInt()); + + tmp.removeFirst(); + tmp.removeFirst(); + } + return; + } + + if (lst[0] == "CLIENT_FLAGS") + { + if(lst.size() < 3 || lst[1].size() < 2) + { + qWarning("Net: Malformed CLIENT_FLAGS message"); + return; + } + + QString flags = lst[1]; + bool setFlag = flags[0] == '+'; + + while(flags.size() > 1) + { + flags.remove(0, 1); + char c = flags[0].toAscii(); + + switch(c) + { + case 'r': + { + for(int i = 2; i < lst.size(); ++i) + { + if (lst[i] == mynick) + emit setMyReadyStatus(setFlag); + emit setReadyStatus(lst[i], setFlag); + } + } + } + } + + return; + } + + if (lst[0] == "ADD_TEAM") { + if(lst.size() != 24) + { + qWarning("Net: Bad ADDTEAM message"); + return; + } + QStringList tmp = lst; + tmp.removeFirst(); + emit AddNetTeam(tmp); + return; + } + + if (lst[0] == "REMOVE_TEAM") { + if(lst.size() != 2) + { + qWarning("Net: Bad REMOVETEAM message"); + return; + } + emit RemoveNetTeam(HWTeam(lst[1])); + return; + } + + if(lst[0] == "ROOMABANDONED") { + netClientState = InLobby; + emit LeftRoom(tr("Room destroyed")); + return; + } + + if(lst[0] == "KICKED") { + netClientState = InLobby; + emit LeftRoom(tr("You got kicked")); + return; + } + + if(lst[0] == "JOINED") { + if(lst.size() < 2) + { + qWarning("Net: Bad JOINED message"); + return; + } + + for(int i = 1; i < lst.size(); ++i) + { + if (lst[i] == mynick) + { + netClientState = InRoom; + emit EnteredGame(); + emit roomMaster(isChief); + if (isChief) + emit configAsked(); + } + + emit nickAdded(lst[i], isChief && (lst[i] != mynick)); + emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); + } + return; + } + + if(lst[0] == "LOBBY:JOINED") { + if(lst.size() < 2) + { + qWarning("Net: Bad JOINED message"); + return; + } + + for(int i = 1; i < lst.size(); ++i) + { + if (lst[i] == mynick) + { + netClientState = InLobby; + RawSendNet(QString("LIST")); + emit connected(); + } + + emit nickAddedLobby(lst[i], false); + emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|")); + } + return; + } + + if(lst[0] == "LEFT") { + if(lst.size() < 2) + { + qWarning("Net: Bad LEFT message"); + return; + } + emit nickRemoved(lst[1]); + if (lst.size() < 3) + emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); + else + emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); + return; + } + + if(lst[0] == "ROOM") { + if(lst.size() < 2) + { + qWarning("Net: Bad ROOM message"); + return; + } + RawSendNet(QString("LIST")); + return; + } + + if(lst[0] == "LOBBY:LEFT") { + if(lst.size() < 2) + { + qWarning("Net: Bad LOBBY:LEFT message"); + return; + } + emit nickRemovedLobby(lst[1]); + if (lst.size() < 3) + emit chatStringLobby(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); + else + emit chatStringLobby(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); + return; + } + + if (lst[0] == "RUN_GAME") { + netClientState = InGame; + emit AskForRunGame(); + return; + } + + if (lst[0] == "ASKPASSWORD") { + emit AskForPassword(mynick); + return; + } + + if (lst[0] == "NOTICE") { + if(lst.size() < 2) + { + qWarning("Net: Bad NOTICE message"); + return; + } + + bool ok; + int n = lst[1].toInt(&ok); + if(!ok) + { + qWarning("Net: Bad NOTICE message"); + return; + } + + handleNotice(n); + + return; + } + + if (lst[0] == "TEAM_ACCEPTED") { + if (lst.size() != 2) + { + qWarning("Net: Bad TEAM_ACCEPTED message"); + return; + } + emit TeamAccepted(lst[1]); + return; + } + + + if (lst[0] == "CFG") { + if(lst.size() < 3) + { + qWarning("Net: Bad CFG message"); + return; + } + QStringList tmp = lst; + tmp.removeFirst(); + tmp.removeFirst(); + if (lst[1] == "SCHEME") + emit netSchemeConfig(tmp); + else + emit paramChanged(lst[1], tmp); + return; + } + + if (lst[0] == "HH_NUM") { + if (lst.size() != 3) + { + qWarning("Net: Bad TEAM_ACCEPTED message"); + return; + } + HWTeam tmptm(lst[1]); + tmptm.setNumHedgehogs(lst[2].toUInt()); + emit hhnumChanged(tmptm); + return; + } + + if (lst[0] == "TEAM_COLOR") { + if (lst.size() != 3) + { + qWarning("Net: Bad TEAM_COLOR message"); + return; + } + HWTeam tmptm(lst[1]); + tmptm.setColor(QColor(lst[2])); + emit teamColorChanged(tmptm); + return; + } + + if (lst[0] == "EM") { + if(lst.size() < 2) + { + qWarning("Net: Bad EM message"); + return; + } + for(int i = 1; i < lst.size(); ++i) + { + QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); + emit FromNet(em); + } + return; + } + + if (lst[0] == "BYE") { + if (lst.size() < 2) + { + qWarning("Net: Bad BYE message"); + return; + } + if (lst[1] == "Authentication failed") + { + emit AuthFailed(); + } + m_game_connected = false; + Disconnect(); + emit disconnected(lst[1]); + return; + } + + + if (lst[0] == "ADMIN_ACCESS") { + emit adminAccess(true); + return; + } + + if (lst[0] == "ROOM_CONTROL_ACCESS") { + if (lst.size() < 2) + { + qWarning("Net: Bad ROOM_CONTROL_ACCESS message"); + return; + } + isChief = (lst[1] != "0"); + emit roomMaster(isChief); + return; + } + + qWarning() << "Net: Unknown message:" << lst; +} + +void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) +{ + if (isChief) + RawSendNet(QString("HH_NUM%1%2%1%3") + .arg(delimeter) + .arg(team.name()) + .arg(team.numHedgehogs())); +} + +void HWNewNet::onTeamColorChanged(const HWTeam& team) +{ + if (isChief) + RawSendNet(QString("TEAM_COLOR%1%2%1%3") + .arg(delimeter) + .arg(team.name()) + .arg(team.color().name())); +} + +void HWNewNet::onParamChanged(const QString & param, const QStringList & value) +{ + if (isChief) + RawSendNet( + QString("CFG%1%2%1%3") + .arg(delimeter) + .arg(param) + .arg(value.join(QString(delimeter))) + ); +} + +void HWNewNet::chatLineToNet(const QString& str) +{ + if(str != "") { + RawSendNet(QString("CHAT") + delimeter + str); + emit(chatStringFromMe(HWProto::formatChatMsg(mynick, str))); + } +} + +void HWNewNet::chatLineToLobby(const QString& str) +{ + if(str != "") { + RawSendNet(QString("CHAT") + delimeter + str); + emit(chatStringFromMeLobby(HWProto::formatChatMsg(mynick, str))); + } +} + +void HWNewNet::SendTeamMessage(const QString& str) +{ + RawSendNet(QString("TEAMCHAT") + delimeter + str); +} + +void HWNewNet::askRoomsList() +{ + if(netClientState != InLobby) + { + qWarning("Illegal try to get rooms list!"); + return; + } + RawSendNet(QString("LIST")); +} + +HWNewNet::ClientState HWNewNet::clientState() +{ + return netClientState; +} + +QString HWNewNet::getNick() +{ + return mynick; +} + +QString HWNewNet::getRoom() +{ + return myroom; +} + +QString HWNewNet::getHost() +{ + return myhost; +} + +bool HWNewNet::isRoomChief() +{ + return isChief; +} + +void HWNewNet::gameFinished(bool correctly) +{ + if (netClientState == InGame) netClientState = InRoom; + RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimeter).arg(correctly ? "1" : "0")); +} + +void HWNewNet::banPlayer(const QString & nick) +{ + RawSendNet(QString("BAN%1%2").arg(delimeter).arg(nick)); +} + +void HWNewNet::kickPlayer(const QString & nick) +{ + RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick)); +} + +void HWNewNet::infoPlayer(const QString & nick) +{ + RawSendNet(QString("INFO%1%2").arg(delimeter).arg(nick)); +} + +void HWNewNet::followPlayer(const QString & nick) +{ + if (!isInRoom()) { + RawSendNet(QString("FOLLOW%1%2").arg(delimeter).arg(nick)); + isChief = false; + } +} + +void HWNewNet::startGame() +{ + RawSendNet(QString("START_GAME")); +} + +void HWNewNet::updateRoomName(const QString & name) +{ + RawSendNet(QString("ROOM_NAME%1%2").arg(delimeter).arg(name)); +} + + +void HWNewNet::toggleRestrictJoins() +{ + RawSendNet(QString("TOGGLE_RESTRICT_JOINS")); +} + +void HWNewNet::toggleRestrictTeamAdds() +{ + RawSendNet(QString("TOGGLE_RESTRICT_TEAMS")); +} + +void HWNewNet::clearAccountsCache() +{ + RawSendNet(QString("CLEAR_ACCOUNTS_CACHE")); +} + +void HWNewNet::partRoom() +{ + netClientState = InLobby; + RawSendNet(QString("PART")); +} + +bool HWNewNet::isInRoom() +{ + return netClientState >= InRoom; +} + +void HWNewNet::setServerMessageNew(const QString & msg) +{ + RawSendNet(QString("SET_SERVER_VAR%1MOTD_NEW%1%2").arg(delimeter).arg(msg)); +} + +void HWNewNet::setServerMessageOld(const QString & msg) +{ + RawSendNet(QString("SET_SERVER_VAR%1MOTD_OLD%1%2").arg(delimeter).arg(msg)); +} + +void HWNewNet::setLatestProtocolVar(int proto) +{ + RawSendNet(QString("SET_SERVER_VAR%1LATEST_PROTO%1%2").arg(delimeter).arg(proto)); +} + +void HWNewNet::askServerVars() +{ + RawSendNet(QString("GET_SERVER_VAR")); +} + +void HWNewNet::handleNotice(int n) +{ + switch(n) + { + case 0: + { + emit NickTaken(mynick); + break; + } + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/newnetclient.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/newnetclient.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,177 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _NEW_NETCLIENT_INCLUDED +#define _NEW_NETCLIENT_INCLUDED + +#include +#include +#include +#include + +#include "team.h" +#include "game.h" // for GameState + +class GameUIConfig; +class GameCFGWidget; +class TeamSelWidget; + +extern char delimeter; + +class HWNewNet : public QObject +{ + Q_OBJECT + + public: + enum ClientState { Disconnected, Connecting, Connected, InLobby, InRoom, InGame }; + + HWNewNet(); + ~HWNewNet(); + void Connect(const QString & hostName, quint16 port, const QString & nick); + void Disconnect(); + void SendPasswordHash(const QString & hash); + void NewNick(const QString & nick); + bool isRoomChief(); + bool isInRoom(); + ClientState clientState(); + QString getNick(); + QString getRoom(); + QString getHost(); + + private: + bool isChief; + QString mynick; + QString myroom; + QString myhost; + QTcpSocket NetSocket; + QString seed; + bool m_game_connected; + + template + void SendCfgStrNet(T a) { + QByteArray strmsg; + strmsg.append(a); + quint8 sz = strmsg.size(); + QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; + QString _msg = delimeter + QString(enginemsg.toBase64()); + RawSendNet(_msg); + } + + template + void SendCfgStrLoc(T a) { + QByteArray strmsg; + strmsg.append(QString(a).toUtf8()); + quint8 sz = strmsg.size(); + QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; + emit FromNet(enginemsg); + } + + QStringList cmdbuf; + + void RawSendNet(const QString & buf); + void RawSendNet(const QByteArray & buf); + void ParseCmd(const QStringList & lst); + void handleNotice(int n); + + int loginStep; + ClientState netClientState; + + signals: + void AskForRunGame(); + void connected(); + void disconnected(const QString & reason); + void Error(const QString & errmsg); + void Warning(const QString & wrnmsg); + void AskForPassword(const QString & nick); + void NickTaken(const QString & nick); + void AuthFailed(); + void EnteredGame(); + void LeftRoom(const QString & reason); + void nickAdded(const QString& nick, bool notifyNick); + void nickRemoved(const QString& nick); + void nickAddedLobby(const QString& nick, bool notifyNick); + void nickRemovedLobby(const QString& nick); + void FromNet(const QByteArray & buf); + void adminAccess(bool); + void roomMaster(bool); + + void netSchemeConfig(QStringList &); + void paramChanged(const QString & param, const QStringList & value); + void configAsked(); + + void TeamAccepted(const QString&); + void AddNetTeam(const HWTeam&); + void RemoveNetTeam(const HWTeam&); + void hhnumChanged(const HWTeam&); + void teamColorChanged(const HWTeam&); + void chatStringLobby(const QString&); + void chatStringLobby(const QString&, const QString&); + void chatStringFromNet(const QString&); + void chatStringFromMe(const QString&); + void chatStringFromMeLobby(const QString&); + + void roomsList(const QStringList&); + void serverMessage(const QString &); + void serverMessageNew(const QString &); + void serverMessageOld(const QString &); + void latestProtocolVar(int); + + void setReadyStatus(const QString & nick, bool isReady); + void setMyReadyStatus(bool isReady); + + public slots: + void ToggleReady(); + void chatLineToNet(const QString& str); + void chatLineToLobby(const QString& str); + void SendTeamMessage(const QString& str); + void SendNet(const QByteArray & buf); + void AddTeam(const HWTeam & team); + void RemoveTeam(const HWTeam& team); + void onHedgehogsNumChanged(const HWTeam& team); + void onTeamColorChanged(const HWTeam& team); + void onParamChanged(const QString & param, const QStringList & value); + + void setServerMessageNew(const QString &); + void setServerMessageOld(const QString &); + void setLatestProtocolVar(int proto); + void askServerVars(); + + void JoinRoom(const QString & room); + void CreateRoom(const QString & room); + void updateRoomName(const QString &); + void askRoomsList(); + void gameFinished(bool correcly); + void banPlayer(const QString &); + void kickPlayer(const QString &); + void infoPlayer(const QString &); + void followPlayer(const QString &); + void startGame(); + void toggleRestrictJoins(); + void toggleRestrictTeamAdds(); + void partRoom(); + void clearAccountsCache(); + + private slots: + void ClientRead(); + void OnConnect(); + void OnDisconnect(); + void displayError(QAbstractSocket::SocketError socketError); +}; + +#endif // _NEW_NETCLIENT_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/proto.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/proto.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,59 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "proto.h" + +HWProto::HWProto() +{ + +} + +QByteArray & HWProto::addByteArrayToBuffer(QByteArray & buf, const QByteArray & msg) +{ + QByteArray bmsg = msg; + bmsg = bmsg.left(250); + quint8 sz = bmsg.size(); + buf.append(QByteArray((char *)&sz, 1)); + buf.append(bmsg); + return buf; +} + +QByteArray & HWProto::addStringToBuffer(QByteArray & buf, const QString & string) +{ + return addByteArrayToBuffer(buf, string.toUtf8()); +} + +QByteArray & HWProto::addStringListToBuffer(QByteArray & buf, const QStringList & strList) +{ + for (int i = 0; i < strList.size(); i++) + addStringToBuffer(buf, strList[i]); + return buf; +} + +QString HWProto::formatChatMsgForFrontend(const QString & msg) +{ + return formatChatMsg("|nick|", msg); +} + +QString HWProto::formatChatMsg(const QString & nick, const QString & msg) +{ + if(msg.left(4) == "/me ") + return QString("\x02* %1 %2").arg(nick).arg(msg.mid(4)); + else + return QString("\x01%1: %2").arg(nick).arg(msg); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/proto.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/proto.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,40 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _PROTO_H +#define _PROTO_H + +#include +#include +#include + + +class HWProto : public QObject +{ + Q_OBJECT + +public: + HWProto(); + static QByteArray & addStringToBuffer(QByteArray & buf, const QString & string); + static QByteArray & addByteArrayToBuffer(QByteArray & buf, const QByteArray & msg); + static QByteArray & addStringListToBuffer(QByteArray & buf, const QStringList & strList); + static QString formatChatMsg(const QString & nick, const QString & msg); + static QString formatChatMsgForFrontend(const QString & msg); +}; + +#endif // _PROTO_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/tcpBase.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/tcpBase.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,166 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "tcpBase.h" + +#include +#include + +#include + +#include "hwconsts.h" + +QList srvsList; +QPointer TCPBase::IPCServer(0); + +TCPBase::~TCPBase() +{ +} + +TCPBase::TCPBase(bool demoMode) : + m_isDemoMode(demoMode), + IPCSocket(0) +{ + if(!IPCServer) { + IPCServer = new QTcpServer(0); + IPCServer->setMaxPendingConnections(1); + if (!IPCServer->listen(QHostAddress::LocalHost)) { + QMessageBox::critical(0, tr("Error"), + tr("Unable to start the server: %1.") + .arg(IPCServer->errorString())); + exit(0); // FIXME - should be graceful exit here + } + } + ipc_port=IPCServer->serverPort(); +} + +void TCPBase::NewConnection() +{ + if(IPCSocket) { + // connection should be already finished + return; + } + disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); + IPCSocket = IPCServer->nextPendingConnection(); + if(!IPCSocket) return; + connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); + connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); + SendToClientFirst(); +} + +void TCPBase::RealStart() +{ + connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); + IPCSocket = 0; + + QProcess * process; + process = new QProcess; + connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); + QStringList arguments=getArguments(); + + // redirect everything written on stdout/stderr + if(isDevBuild) + process->setProcessChannelMode(QProcess::ForwardedChannels); + process->start(bindir->absolutePath() + "/hwengine", arguments); +} + +void TCPBase::ClientDisconnect() +{ + disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); + onClientDisconnect(); + + if(srvsList.size()==1) srvsList.pop_front(); + emit isReadyNow(); + IPCSocket->deleteLater(); + deleteLater(); +} + +void TCPBase::ClientRead() +{ + QByteArray readed=IPCSocket->readAll(); + if(readed.isEmpty()) return; + readbuffer.append(readed); + onClientRead(); +} + +void TCPBase::StartProcessError(QProcess::ProcessError error) +{ + QMessageBox::critical(0, tr("Error"), + tr("Unable to run engine: %1 (") + .arg(error) + bindir->absolutePath() + "/hwengine)"); +} + +void TCPBase::tcpServerReady() +{ + disconnect(srvsList.takeFirst(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); + + RealStart(); +} + +void TCPBase::Start() +{ + if(srvsList.isEmpty()) { + srvsList.push_back(this); + } else { + connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); + srvsList.push_back(this); + return; + } + + RealStart(); +} + +void TCPBase::onClientRead() +{ +} + +void TCPBase::onClientDisconnect() +{ +} + +void TCPBase::SendToClientFirst() +{ +} + +void TCPBase::SendIPC(const QByteArray & buf) +{ + if (buf.size() > MAXMSGCHARS) return; + quint8 len = buf.size(); + RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); +} + +void TCPBase::RawSendIPC(const QByteArray & buf) +{ + if (!IPCSocket) + { + toSendBuf += buf; + } else + { + if (toSendBuf.size() > 0) + { + IPCSocket->write(toSendBuf); + if(m_isDemoMode) demo.append(toSendBuf); + toSendBuf.clear(); + } + if(!buf.isEmpty()) { + IPCSocket->write(buf); + if(m_isDemoMode) demo.append(buf); + } + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/net/tcpBase.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/net/tcpBase.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,81 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _TCPBASE_INCLUDED +#define _TCPBASE_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define MAXMSGCHARS 255 + +class TCPBase : public QObject +{ + Q_OBJECT + + public: + TCPBase(bool demoMode); + virtual ~TCPBase(); + + signals: + void isReadyNow(); + + protected: + quint16 ipc_port; + + void Start(); + + QByteArray readbuffer; + + QByteArray toSendBuf; + QByteArray demo; + + void SendIPC(const QByteArray & buf); + void RawSendIPC(const QByteArray & buf); + + virtual QStringList getArguments()=0; + virtual void onClientRead(); + virtual void onClientDisconnect(); + virtual void SendToClientFirst(); + + private: + static QPointer IPCServer; + + bool m_isDemoMode; + void RealStart(); + QPointer IPCSocket; + + private slots: + void NewConnection(); + void ClientDisconnect(); + void ClientRead(); + void StartProcessError(QProcess::ProcessError error); + + void tcpServerReady(); +}; + +#endif // _TCPBASE_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netregister.cpp --- a/QTfrontend/netregister.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "netregister.h" - -HWNetRegisterServer::HWNetRegisterServer(QObject *parent, const QString & descr, quint16 port) : - QObject(parent) -{ - Q_UNUSED(descr); - Q_UNUSED(port); -} - -void HWNetRegisterServer::unregister() -{ - -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netregister.h --- a/QTfrontend/netregister.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _NET_REGISTER_INCLUDED -#define _NET_REGISTER_INCLUDED - -#include - -class HWNetRegisterServer : public QObject -{ - Q_OBJECT - -public: - HWNetRegisterServer(QObject *parent, const QString & descr, quint16 port); - -public slots: - virtual void unregister(); -}; - -#endif // _NET_REGISTER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netserver.cpp --- a/QTfrontend/netserver.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include - -#include "hwconsts.h" -#include "netserver.h" - -HWNetServer::~HWNetServer() -{ - StopServer(); -} - -bool HWNetServer::StartServer(quint16 port) -{ - ds_port = port; - - QStringList params; - params << QString("--port=%1").arg(port); - params << "--dedicated=False"; - - process.start(bindir->absolutePath() + "/hedgewars-server", params); - - return process.waitForStarted(5000); -} - -void HWNetServer::StopServer() -{ - process.close(); -} - - -quint16 HWNetServer::getRunningPort() const -{ - return ds_port; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netserver.h --- a/QTfrontend/netserver.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _NETSERVER_INCLUDED -#define _NETSERVER_INCLUDED - -#include -#include - -class HWNetServer : public QObject -{ - Q_OBJECT - -public: - ~HWNetServer(); - bool StartServer(quint16 port); - void StopServer(); - QString getRunningHostName() const; - quint16 getRunningPort() const; - -private: - quint16 ds_port; - QProcess process; -}; - -#endif // _NETSERVER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netserverslist.cpp --- a/QTfrontend/netserverslist.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "netserverslist.h" - -HWNetServersModel::HWNetServersModel(QObject* parent) : - QAbstractTableModel(parent) -{ - -} - -void HWNetServersModel::updateList() -{ - -} - -QVariant HWNetServersModel::headerData(int section, - Qt::Orientation orientation, int role) const -{ - if (role != Qt::DisplayRole) - return QVariant(); - - if (orientation == Qt::Horizontal) - { - switch (section) - { - case 0: return tr("Title"); - case 1: return tr("IP"); - case 2: return tr("Port"); - default: return QVariant(); - } - } else - return QString("%1").arg(section + 1); -} - -int HWNetServersModel::rowCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return 0; - else - return games.size(); -} - -int HWNetServersModel::columnCount(const QModelIndex & parent) const -{ - if (parent.isValid()) - return 0; - else - return 3; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netserverslist.h --- a/QTfrontend/netserverslist.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _NET_SERVERSLIST_INCLUDED -#define _NET_SERVERSLIST_INCLUDED - -#include -#include - -class HWNetServersModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - HWNetServersModel(QObject *parent = 0); - - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - int rowCount(const QModelIndex & parent) const; - int columnCount(const QModelIndex & parent) const; - -public slots: - virtual void updateList(); - -protected: - QList games; -}; - -#endif // _NET_SERVERSLIST_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netudpserver.cpp --- a/QTfrontend/netudpserver.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include - -#include "netudpserver.h" - -HWNetUdpServer::HWNetUdpServer(QObject *parent, const QString & descr, quint16 port) : - HWNetRegisterServer(parent, descr, port), - m_descr(descr) -{ - pUdpSocket = new QUdpSocket(this); - pUdpSocket->bind(46631); - connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead())); -} - -void HWNetUdpServer::onClientRead() -{ - while (pUdpSocket->hasPendingDatagrams()) { - QByteArray datagram; - datagram.resize(pUdpSocket->pendingDatagramSize()); - QHostAddress clientAddr; - quint16 clientPort; - pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); - if(datagram.startsWith("hedgewars client")) { - // send answer to client - pUdpSocket->writeDatagram(QString("hedgewars server\n%1").arg(m_descr).toUtf8(), clientAddr, clientPort); - } - } -} - -void HWNetUdpServer::unregister() -{ - deleteLater(); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netudpserver.h --- a/QTfrontend/netudpserver.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _NET_UDPSERVER_INCLUDED -#define _NET_UDPSERVER_INCLUDED - -#include -#include "netregister.h" - -class QUdpSocket; - -class HWNetUdpServer : public HWNetRegisterServer -{ - Q_OBJECT - - public: - HWNetUdpServer(QObject *parent, const QString & descr, quint16 port); - - public slots: - void unregister(); - - private slots: - void onClientRead(); - - private: - QUdpSocket* pUdpSocket; - QString m_descr; -}; - -#endif // _NET_UDPSERVER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netudpwidget.cpp --- a/QTfrontend/netudpwidget.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include - -#include "netudpwidget.h" - -HWNetUdpModel::HWNetUdpModel(QObject* parent) : - HWNetServersModel(parent) -{ - pUdpSocket = new QUdpSocket(this); - - pUdpSocket->bind(); - connect(pUdpSocket, SIGNAL(readyRead()), this, SLOT(onClientRead())); -} - -void HWNetUdpModel::updateList() -{ - games.clear(); - - reset(); - - pUdpSocket->writeDatagram("hedgewars client", QHostAddress::Broadcast, 46631); -} - -void HWNetUdpModel::onClientRead() -{ - while (pUdpSocket->hasPendingDatagrams()) { - QByteArray datagram; - datagram.resize(pUdpSocket->pendingDatagramSize()); - QHostAddress clientAddr; - quint16 clientPort; - - pUdpSocket->readDatagram(datagram.data(), datagram.size(), &clientAddr, &clientPort); - - QString packet = QString::fromUtf8(datagram.data()); - if(packet.startsWith("hedgewars server")) { - QStringList sl; - sl << packet.remove(0, 17) << clientAddr.toString() << "46631"; - games.append(sl); - } - } - - reset(); -} - -QVariant HWNetUdpModel::data(const QModelIndex &index, - int role) const -{ - if (!index.isValid() || index.row() < 0 - || index.row() >= games.size() - || role != Qt::DisplayRole) - return QVariant(); - - return games[index.row()][index.column()]; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/netudpwidget.h --- a/QTfrontend/netudpwidget.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _NET_UDPWIDGET_INCLUDED -#define _NET_UDPWIDGET_INCLUDED - -#include "netserverslist.h" - -class QUdpSocket; - -class HWNetUdpModel : public HWNetServersModel -{ - Q_OBJECT - -public: - HWNetUdpModel(QObject *parent = 0); - - QVariant data(const QModelIndex &index, int role) const; - -public slots: - void updateList(); - -private slots: - void onClientRead(); - -private: - QUdpSocket* pUdpSocket; -}; - -#endif // _NET_UDPWIDGET_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/newnetclient.cpp --- a/QTfrontend/newnetclient.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,851 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "hwconsts.h" -#include "newnetclient.h" -#include "proto.h" -#include "gameuiconfig.h" -#include "game.h" -#include "gamecfgwidget.h" -#include "teamselect.h" -#include "misc.h" -/* only to get the ignoreList from the chat widget */ -#include "hwform.h" -#include "pageroomslist.h" -#include "chatwidget.h" - -char delimeter='\n'; - -HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) : - config(config), - m_pGameCFGWidget(pGameCFGWidget), - m_pTeamSelWidget(pTeamSelWidget), - isChief(false), - m_game_connected(false), - loginStep(0), - netClientState(0) -{ -// socket stuff - connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); - connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); - connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); - connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, - SLOT(displayError(QAbstractSocket::SocketError))); - -// config stuff - connect(this, SIGNAL(paramChanged(const QString &, const QStringList &)), pGameCFGWidget, SLOT(setParam(const QString &, const QStringList &))); - connect(pGameCFGWidget, SIGNAL(paramChanged(const QString &, const QStringList &)), this, SLOT(onParamChanged(const QString &, const QStringList &))); - connect(this, SIGNAL(configAsked()), pGameCFGWidget, SLOT(fullNetConfig())); -} - -HWNewNet::~HWNewNet() -{ - if (m_game_connected) - { - RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); - emit Disconnected(); - } - NetSocket.flush(); -} - -void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick) -{ - mynick = nick; - while (mynick.isEmpty()) { - mynick = QInputDialog::getText(m_pGameCFGWidget, - QObject::tr("Nickname"), - QObject::tr("Please enter your nickname"), - QLineEdit::Normal, - QDir::home().dirName()); - config->setValue("net/nick",mynick); - config->updNetNick(); - } - myhost = hostName + QString(":%1").arg(port); - NetSocket.connectToHost(hostName, port); -} - -void HWNewNet::Disconnect() -{ - if (m_game_connected) - RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); - m_game_connected = false; - - NetSocket.disconnectFromHost(); -} - -void HWNewNet::CreateRoom(const QString & room) -{ - if(netClientState != 2) - { - qWarning("Illegal try to create room!"); - return; - } - - myroom = room; - - RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room)); - isChief = true; -} - -void HWNewNet::JoinRoom(const QString & room) -{ - if(netClientState != 2) - { - qWarning("Illegal try to join room!"); - return; - } - - myroom = room; - - RawSendNet(QString("JOIN_ROOM%1%2").arg(delimeter).arg(room)); - isChief = false; -} - -void HWNewNet::AddTeam(const HWTeam & team) -{ - QString cmd = QString("ADD_TEAM") + delimeter + - team.TeamName + delimeter + - team.teamColor.name() + delimeter + - team.Grave + delimeter + - team.Fort + delimeter + - team.Voicepack + delimeter + - team.Flag + delimeter + - QString::number(team.difficulty); - - for(int i = 0; i < 8; ++i) - { - cmd.append(delimeter); - cmd.append(team.Hedgehogs[i].Name); - cmd.append(delimeter); - cmd.append(team.Hedgehogs[i].Hat); - } - RawSendNet(cmd); -} - -void HWNewNet::RemoveTeam(const HWTeam & team) -{ - RawSendNet(QString("REMOVE_TEAM") + delimeter + team.TeamName); -} - -void HWNewNet::ToggleReady() -{ - RawSendNet(QString("TOGGLE_READY")); -} - -void HWNewNet::SendNet(const QByteArray & buf) -{ - QString msg = QString(buf.toBase64()); - - RawSendNet(QString("EM%1%2").arg(delimeter).arg(msg)); -} - -void HWNewNet::RawSendNet(const QString & str) -{ - RawSendNet(str.toUtf8()); -} - -void HWNewNet::RawSendNet(const QByteArray & buf) -{ - qDebug() << "Client: " << QString(buf).split("\n"); - NetSocket.write(buf); - NetSocket.write("\n\n", 2); -} - -void HWNewNet::ClientRead() -{ - while (NetSocket.canReadLine()) { - QString s = QString::fromUtf8(NetSocket.readLine()); - if (s.endsWith('\n')) s.chop(1); - - if (s.size() == 0) { - ParseCmd(cmdbuf); - cmdbuf.clear(); - } else - cmdbuf << s; - } -} - -void HWNewNet::OnConnect() -{ -} - -void HWNewNet::OnDisconnect() -{ - if(m_game_connected) emit Disconnected(); - m_game_connected = false; -} - -void HWNewNet::displayError(QAbstractSocket::SocketError socketError) -{ - emit Disconnected(); - m_game_connected = false; - - switch (socketError) { - case QAbstractSocket::RemoteHostClosedError: - break; - case QAbstractSocket::HostNotFoundError: - emit showMessage(tr("The host was not found. Please check the host name and port settings.")); - break; - case QAbstractSocket::ConnectionRefusedError: - emit showMessage(tr("Connection refused")); - break; - default: - emit showMessage(NetSocket.errorString()); - } -} - -void HWNewNet::ParseCmd(const QStringList & lst) -{ - qDebug() << "Server: " << lst; - - if(!lst.size()) - { - qWarning("Net client: Bad message"); - return; - } - - if (lst[0] == "NICK") - { - mynick = lst[1]; - return ; - } - - if (lst[0] == "PROTO") - return ; - - if (lst[0] == "ERROR") { - if (lst.size() == 2) - emit showMessage("Error: " + lst[1]); - else - emit showMessage("Unknown error"); - return; - } - - if (lst[0] == "WARNING") { - if (lst.size() == 2) - emit showMessage("Warning: " + lst[1]); - else - emit showMessage("Unknown warning"); - return; - } - - if (lst[0] == "CONNECTED") { - if(lst.size() < 3 || lst[2].toInt() < cMinServerVersion) - { - // TODO: Warn user, disconnect - qWarning() << "Server too old"; - } - - RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); - RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); - netClientState = 1; - m_game_connected = true; - emit adminAccess(false); - return; - } - - if (lst[0] == "PING") { - if (lst.size() > 1) - RawSendNet(QString("PONG%1%2").arg(delimeter).arg(lst[1])); - else - RawSendNet(QString("PONG")); - return; - } - - if (lst[0] == "ROOMS") { - QStringList tmp = lst; - tmp.removeFirst(); - emit roomsList(tmp); - return; - } - - if (lst[0] == "SERVER_MESSAGE") { - if(lst.size() < 2) - { - qWarning("Net: Empty SERVERMESSAGE message"); - return; - } - emit serverMessage(lst[1]); - return; - } - - if (lst[0] == "CHAT") { - if(lst.size() < 3) - { - qWarning("Net: Empty CHAT message"); - return; - } - if (netClientState == 2) - emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2])); - else - emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2])); - return; - } - - if (lst[0] == "INFO") { - if(lst.size() < 5) - { - qWarning("Net: Malformed INFO message"); - return; - } - QStringList tmp = lst; - tmp.removeFirst(); - if (netClientState == 2) - emit chatStringLobby(tmp.join("\n").prepend('\x01')); - else - emit chatStringFromNet(tmp.join("\n").prepend('\x01')); - return; - } - - if (lst[0] == "SERVER_VARS") { - QStringList tmp = lst; - tmp.removeFirst(); - while (tmp.size() >= 2) - { - if(tmp[0] == "MOTD_NEW") emit serverMessageNew(tmp[1]); - else if(tmp[0] == "MOTD_OLD") emit serverMessageOld(tmp[1]); - else if(tmp[0] == "LATEST_PROTO") emit latestProtocolVar(tmp[1].toInt()); - - tmp.removeFirst(); - tmp.removeFirst(); - } - return; - } - - if (lst[0] == "CLIENT_FLAGS") - { - if(lst.size() < 3 || lst[1].size() < 2) - { - qWarning("Net: Malformed CLIENT_FLAGS message"); - return; - } - - QString flags = lst[1]; - bool setFlag = flags[0] == '+'; - - while(flags.size() > 1) - { - flags.remove(0, 1); - char c = flags[0].toAscii(); - - switch(c) - { - case 'r': - { - for(int i = 2; i < lst.size(); ++i) - { - if (lst[i] == mynick) - emit setMyReadyStatus(setFlag); - emit setReadyStatus(lst[i], setFlag); - } - } - } - } - - return; - } - - if (lst[0] == "ADD_TEAM") { - if(lst.size() != 24) - { - qWarning("Net: Bad ADDTEAM message"); - return; - } - QStringList tmp = lst; - tmp.removeFirst(); - emit AddNetTeam(tmp); - return; - } - - if (lst[0] == "REMOVE_TEAM") { - if(lst.size() != 2) - { - qWarning("Net: Bad REMOVETEAM message"); - return; - } - m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1])); - return; - } - - if(lst[0] == "ROOMABANDONED") { - netClientState = 2; - emit showMessage(HWNewNet::tr("Room destroyed")); - emit LeftRoom(); - return; - } - - if(lst[0] == "KICKED") { - netClientState = 2; - emit showMessage(HWNewNet::tr("You got kicked")); - emit LeftRoom(); - return; - } - - if(lst[0] == "JOINED") { - if(lst.size() < 2) - { - qWarning("Net: Bad JOINED message"); - return; - } - - for(int i = 1; i < lst.size(); ++i) - { - if (lst[i] == mynick) - { - netClientState = 3; - emit EnteredGame(); - emit roomMaster(isChief); - if (isChief) - emit configAsked(); - } - if (lst[i] != mynick && isChief && config->Form->ui.pageRoomsList->chatWidget->ignoreList.contains(lst[i], Qt::CaseInsensitive) && !config->Form->ui.pageRoomsList->chatWidget->friendsList.contains(lst[i], Qt::CaseInsensitive)) - { - kickPlayer(lst[i]); - } - else - { - emit nickAdded(lst[i], isChief && (lst[i] != mynick)); - emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); - } - } - return; - } - - if(lst[0] == "LOBBY:JOINED") { - if(lst.size() < 2) - { - qWarning("Net: Bad JOINED message"); - return; - } - - for(int i = 1; i < lst.size(); ++i) - { - if (lst[i] == mynick) - { - netClientState = 2; - RawSendNet(QString("LIST")); - emit Connected(); - } - - emit nickAddedLobby(lst[i], false); - emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|")); - } - return; - } - - if(lst[0] == "LEFT") { - if(lst.size() < 2) - { - qWarning("Net: Bad LEFT message"); - return; - } - emit nickRemoved(lst[1]); - if (lst.size() < 3) - emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); - else - emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); - return; - } - - if(lst[0] == "ROOM") { - if(lst.size() < 2) - { - qWarning("Net: Bad ROOM message"); - return; - } - RawSendNet(QString("LIST")); - return; - } - - if(lst[0] == "LOBBY:LEFT") { - if(lst.size() < 2) - { - qWarning("Net: Bad LOBBY:LEFT message"); - return; - } - emit nickRemovedLobby(lst[1]); - if (lst.size() < 3) - emit chatStringLobby(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); - else - emit chatStringLobby(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); - return; - } - - if (lst[0] == "RUN_GAME") { - netClientState = 5; - emit AskForRunGame(); - return; - } - - if (lst[0] == "BYE") { - if (lst[1] == "Authentication failed") - { - // Set the password blank if case the user tries to join and enter his password again - config->setValue("net/passwordlength", 0); - config->setNetPasswordLength(0); - } - // return early so the user won't get an unknown error message dialog (the user already gets a server connection is lost one) - return; - } - - if (lst[0] == "ASKPASSWORD") { - bool ok = false; - int passLength = config->value("net/passwordlength", 0).toInt(); - QString hash = config->value("net/passwordhash", "").toString(); - - // If the password is blank, ask the user to enter one in - if (passLength == 0) - { - QString password = QInputDialog::getText(m_pGameCFGWidget, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(mynick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok); - - if (!ok) { - Disconnect(); - emit Disconnected(); - return; - } - - hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex(); - config->setValue("net/passwordhash", hash); - config->setValue("net/passwordlength", password.size()); - config->setNetPasswordLength(password.size()); - } - - RawSendNet(QString("PASSWORD%1%2").arg(delimeter).arg(hash)); - return; - } - - if (lst[0] == "NOTICE") { - if(lst.size() < 2) - { - qWarning("Net: Bad NOTICE message"); - return; - } - - bool ok; - int n = lst[1].toInt(&ok); - if(!ok) - { - qWarning("Net: Bad NOTICE message"); - return; - } - - handleNotice(n); - - return; - } - - if (lst[0] == "TEAM_ACCEPTED") { - if (lst.size() != 2) - { - qWarning("Net: Bad TEAM_ACCEPTED message"); - return; - } - m_pTeamSelWidget->changeTeamStatus(lst[1]); - return; - } - - - if (lst[0] == "CFG") { - if(lst.size() < 3) - { - qWarning("Net: Bad CFG message"); - return; - } - QStringList tmp = lst; - tmp.removeFirst(); - tmp.removeFirst(); - if (lst[1] == "SCHEME") - emit netSchemeConfig(tmp); - else - emit paramChanged(lst[1], tmp); - return; - } - - if (lst[0] == "HH_NUM") { - if (lst.size() != 3) - { - qWarning("Net: Bad TEAM_ACCEPTED message"); - return; - } - HWTeam tmptm(lst[1]); - tmptm.numHedgehogs = lst[2].toUInt(); - emit hhnumChanged(tmptm); - return; - } - - if (lst[0] == "TEAM_COLOR") { - if (lst.size() != 3) - { - qWarning("Net: Bad TEAM_COLOR message"); - return; - } - HWTeam tmptm(lst[1]); - tmptm.teamColor = QColor(lst[2]); - emit teamColorChanged(tmptm); - return; - } - - if (lst[0] == "EM") { - if(lst.size() < 2) - { - qWarning("Net: Bad EM message"); - return; - } - for(int i = 1; i < lst.size(); ++i) - { - QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); - emit FromNet(em); - } - return; - } - - if (lst[0] == "BYE") { - if (lst.size() < 2) - { - qWarning("Net: Bad BYE message"); - return; - } - emit showMessage(HWNewNet::tr("Quit reason: ") + lst[1]); - return; - } - - - if (lst[0] == "ADMIN_ACCESS") { - emit adminAccess(true); - return; - } - - if (lst[0] == "ROOM_CONTROL_ACCESS") { - if (lst.size() < 2) - { - qWarning("Net: Bad BYE message"); - return; - } - bool b = lst[1] != "0"; - m_pGameCFGWidget->setEnabled(b); - m_pTeamSelWidget->setInteractivity(b); - isChief = b; - emit roomMaster(isChief); - - return; - } - - qWarning() << "Net: Unknown message:" << lst; -} - -void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) -{ - if (isChief) - RawSendNet(QString("HH_NUM%1%2%1%3") - .arg(delimeter) - .arg(team.TeamName) - .arg(team.numHedgehogs)); -} - -void HWNewNet::onTeamColorChanged(const HWTeam& team) -{ - if (isChief) - RawSendNet(QString("TEAM_COLOR%1%2%1%3") - .arg(delimeter) - .arg(team.TeamName) - .arg(team.teamColor.name())); -} - -void HWNewNet::onParamChanged(const QString & param, const QStringList & value) -{ - if (isChief) - RawSendNet( - QString("CFG%1%2%1%3") - .arg(delimeter) - .arg(param) - .arg(value.join(QString(delimeter))) - ); -} - -void HWNewNet::chatLineToNet(const QString& str) -{ - if(str != "") { - RawSendNet(QString("CHAT") + delimeter + str); - emit(chatStringFromMe(HWProto::formatChatMsg(mynick, str))); - } -} - -void HWNewNet::chatLineToLobby(const QString& str) -{ - if(str != "") { - RawSendNet(QString("CHAT") + delimeter + str); - emit(chatStringFromMeLobby(HWProto::formatChatMsg(mynick, str))); - } -} - -void HWNewNet::SendTeamMessage(const QString& str) -{ - RawSendNet(QString("TEAMCHAT") + delimeter + str); -} - -void HWNewNet::askRoomsList() -{ - if(netClientState != 2) - { - qWarning("Illegal try to get rooms list!"); - return; - } - RawSendNet(QString("LIST")); -} - -int HWNewNet::getClientState() -{ - return netClientState; -} - -QString HWNewNet::getNick() -{ - return mynick; -} - -QString HWNewNet::getRoom() -{ - return myroom; -} - -QString HWNewNet::getHost() -{ - return myhost; -} - -bool HWNewNet::isRoomChief() -{ - return isChief; -} - -void HWNewNet::gameFinished(bool correctly) -{ - if (netClientState == 5) netClientState = 3; - RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimeter).arg(correctly ? "1" : "0")); -} - -void HWNewNet::banPlayer(const QString & nick) -{ - RawSendNet(QString("BAN%1%2").arg(delimeter).arg(nick)); -} - -void HWNewNet::kickPlayer(const QString & nick) -{ - RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick)); -} - -void HWNewNet::infoPlayer(const QString & nick) -{ - RawSendNet(QString("INFO%1%2").arg(delimeter).arg(nick)); -} - -void HWNewNet::followPlayer(const QString & nick) -{ - if (!isInRoom()) { - RawSendNet(QString("FOLLOW%1%2").arg(delimeter).arg(nick)); - isChief = false; - } -} - -void HWNewNet::startGame() -{ - RawSendNet(QString("START_GAME")); -} - -void HWNewNet::updateRoomName(const QString & name) -{ - RawSendNet(QString("ROOM_NAME%1%2").arg(delimeter).arg(name)); -} - - -void HWNewNet::toggleRestrictJoins() -{ - RawSendNet(QString("TOGGLE_RESTRICT_JOINS")); -} - -void HWNewNet::toggleRestrictTeamAdds() -{ - RawSendNet(QString("TOGGLE_RESTRICT_TEAMS")); -} - -void HWNewNet::clearAccountsCache() -{ - RawSendNet(QString("CLEAR_ACCOUNTS_CACHE")); -} - -void HWNewNet::partRoom() -{ - netClientState = 2; - RawSendNet(QString("PART")); -} - -bool HWNewNet::isInRoom() -{ - return netClientState > 2; -} - -void HWNewNet::setServerMessageNew(const QString & msg) -{ - RawSendNet(QString("SET_SERVER_VAR%1MOTD_NEW%1%2").arg(delimeter).arg(msg)); -} - -void HWNewNet::setServerMessageOld(const QString & msg) -{ - RawSendNet(QString("SET_SERVER_VAR%1MOTD_OLD%1%2").arg(delimeter).arg(msg)); -} - -void HWNewNet::setLatestProtocolVar(int proto) -{ - RawSendNet(QString("SET_SERVER_VAR%1LATEST_PROTO%1%2").arg(delimeter).arg(proto)); -} - -void HWNewNet::askServerVars() -{ - RawSendNet(QString("GET_SERVER_VAR")); -} - -void HWNewNet::handleNotice(int n) -{ - switch(n) - { - case 0: - { - bool ok = false; - QString newNick = QInputDialog::getText(0, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(mynick), QLineEdit::Normal, mynick, &ok); - - if (!ok || newNick.isEmpty()) { - Disconnect(); - emit Disconnected(); - return; - } - - config->setValue("net/nick", newNick); - config->updNetNick(); - mynick = newNick; - - RawSendNet(QString("NICK%1%2").arg(delimeter).arg(newNick)); - - break; - } - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/newnetclient.h --- a/QTfrontend/newnetclient.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,171 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _NEW_NETCLIENT_INCLUDED -#define _NEW_NETCLIENT_INCLUDED - -#include -#include -#include -#include - -#include "team.h" -#include "game.h" // for GameState - -class GameUIConfig; -class GameCFGWidget; -class TeamSelWidget; - -extern char delimeter; - -class HWNewNet : public QObject -{ - Q_OBJECT - - public: - HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget); - ~HWNewNet(); - void Connect(const QString & hostName, quint16 port, const QString & nick); - void Disconnect(); - bool isRoomChief(); - bool isInRoom(); - int getClientState(); - QString getNick(); - QString getRoom(); - QString getHost(); - - private: - GameUIConfig* config; - GameCFGWidget* m_pGameCFGWidget; - TeamSelWidget* m_pTeamSelWidget; - - bool isChief; - QString mynick; - QString myroom; - QString myhost; - QTcpSocket NetSocket; - QString seed; - bool m_game_connected; - - template - void SendCfgStrNet(T a) { - QByteArray strmsg; - strmsg.append(a); - quint8 sz = strmsg.size(); - QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; - QString _msg = delimeter + QString(enginemsg.toBase64()); - RawSendNet(_msg); - } - - template - void SendCfgStrLoc(T a) { - QByteArray strmsg; - strmsg.append(QString(a).toUtf8()); - quint8 sz = strmsg.size(); - QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; - emit FromNet(enginemsg); - } - - QStringList cmdbuf; - - void RawSendNet(const QString & buf); - void RawSendNet(const QByteArray & buf); - void ParseCmd(const QStringList & lst); - void handleNotice(int n); - - int loginStep; - int netClientState; - - signals: - void AskForRunGame(); - void Connected(); - void Disconnected(); - void EnteredGame(); - void LeftRoom(); - void nickAdded(const QString& nick, bool notifyNick); - void nickRemoved(const QString& nick); - void nickAddedLobby(const QString& nick, bool notifyNick); - void nickRemovedLobby(const QString& nick); - void FromNet(const QByteArray & buf); - void adminAccess(bool); - void roomMaster(bool); - - void netSchemeConfig(QStringList &); - void paramChanged(const QString & param, const QStringList & value); - void configAsked(); - - void AddNetTeam(const HWTeam&); - void hhnumChanged(const HWTeam&); - void teamColorChanged(const HWTeam&); - void chatStringLobby(const QString&); - void chatStringLobby(const QString&, const QString&); - void chatStringFromNet(const QString&); - void chatStringFromMe(const QString&); - void chatStringFromMeLobby(const QString&); - - void roomsList(const QStringList&); - void serverMessage(const QString &); - void serverMessageNew(const QString &); - void serverMessageOld(const QString &); - void latestProtocolVar(int); - - void setReadyStatus(const QString & nick, bool isReady); - void setMyReadyStatus(bool isReady); - void showMessage(const QString &); - - public slots: - void ToggleReady(); - void chatLineToNet(const QString& str); - void chatLineToLobby(const QString& str); - void SendTeamMessage(const QString& str); - void SendNet(const QByteArray & buf); - void AddTeam(const HWTeam & team); - void RemoveTeam(const HWTeam& team); - void onHedgehogsNumChanged(const HWTeam& team); - void onTeamColorChanged(const HWTeam& team); - void onParamChanged(const QString & param, const QStringList & value); - - void setServerMessageNew(const QString &); - void setServerMessageOld(const QString &); - void setLatestProtocolVar(int proto); - void askServerVars(); - - void JoinRoom(const QString & room); - void CreateRoom(const QString & room); - void updateRoomName(const QString &); - void askRoomsList(); - void gameFinished(bool correcly); - void banPlayer(const QString &); - void kickPlayer(const QString &); - void infoPlayer(const QString &); - void followPlayer(const QString &); - void startGame(); - void toggleRestrictJoins(); - void toggleRestrictTeamAdds(); - void partRoom(); - void clearAccountsCache(); - - private slots: - void ClientRead(); - void OnConnect(); - void OnDisconnect(); - void displayError(QAbstractSocket::SocketError socketError); -}; - -#endif // _NEW_NETCLIENT_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageadmin.cpp --- a/QTfrontend/pageadmin.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include - -#include "pageadmin.h" -#include "chatwidget.h" - -PageAdmin::PageAdmin(QWidget* parent) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - - // 0 - pbAsk = addButton(tr("Fetch data"), pageLayout, 0, 0, 1, 3); - connect(pbAsk, SIGNAL(clicked()), this, SIGNAL(askServerVars())); - - // 1 - QLabel * lblSMN = new QLabel(this); - lblSMN->setText(tr("Server message for latest version:")); - pageLayout->addWidget(lblSMN, 1, 0); - - leServerMessageNew = new QLineEdit(this); - pageLayout->addWidget(leServerMessageNew, 1, 1); - - // 2 - QLabel * lblSMO = new QLabel(this); - lblSMO->setText(tr("Server message for previous versions:")); - pageLayout->addWidget(lblSMO, 2, 0); - - leServerMessageOld = new QLineEdit(this); - pageLayout->addWidget(leServerMessageOld, 2, 1); - - // 3 - QLabel * lblP = new QLabel(this); - lblP->setText(tr("Latest version protocol number:")); - pageLayout->addWidget(lblP, 3, 0); - - sbProtocol = new QSpinBox(this); - pageLayout->addWidget(sbProtocol, 3, 1); - - // 4 - QLabel * lblPreview = new QLabel(this); - lblPreview->setText(tr("MOTD preview:")); - pageLayout->addWidget(lblPreview, 4, 0); - - tb = new QTextBrowser(this); - tb->setOpenExternalLinks(true); - tb->document()->setDefaultStyleSheet(HWChatWidget::STYLE); - pageLayout->addWidget(tb, 4, 1, 1, 2); - connect(leServerMessageNew, SIGNAL(textEdited(const QString &)), tb, SLOT(setHtml(const QString &))); - connect(leServerMessageOld, SIGNAL(textEdited(const QString &)), tb, SLOT(setHtml(const QString &))); - - // 5 - pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), pageLayout, 5, 0); - - // 6 - pbSetSM = addButton(tr("Set data"), pageLayout, 6, 0, 1, 3); - - // 7 - BtnBack = addButton(":/res/Exit.png", pageLayout, 7, 0, true); - - connect(pbSetSM, SIGNAL(clicked()), this, SLOT(smChanged())); -} - -void PageAdmin::smChanged() -{ - emit setServerMessageNew(leServerMessageNew->text()); - emit setServerMessageOld(leServerMessageOld->text()); - emit setProtocol(sbProtocol->value()); -} - -void PageAdmin::serverMessageNew(const QString & str) -{ - leServerMessageNew->setText(str); -} - -void PageAdmin::serverMessageOld(const QString & str) -{ - leServerMessageOld->setText(str); -} -void PageAdmin::protocol(int proto) -{ - sbProtocol->setValue(proto); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageadmin.h --- a/QTfrontend/pageadmin.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_ADMIN_H -#define PAGE_ADMIN_H - -#include "AbstractPage.h" - -class PageAdmin : public AbstractPage -{ - Q_OBJECT - -public: - PageAdmin(QWidget* parent = 0); - - QPushButton * BtnBack; - QPushButton * pbClearAccountsCache; - -private: - QLineEdit * leServerMessageNew; - QLineEdit * leServerMessageOld; - QPushButton * pbSetSM; - QPushButton * pbAsk; - QSpinBox * sbProtocol; - QTextBrowser * tb; - -private slots: - void smChanged(); - -public slots: - void serverMessageNew(const QString & str); - void serverMessageOld(const QString & str); - void protocol(int proto); - -signals: - void setServerMessageNew(const QString & str); - void setServerMessageOld(const QString & str); - void setProtocol(int proto); - void askServerVars(); -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagecampaign.cpp --- a/QTfrontend/pagecampaign.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "pagecampaign.h" - -PageCampaign::PageCampaign(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 2); - pageLayout->setColumnStretch(2, 1); - pageLayout->setRowStretch(0, 1); - pageLayout->setRowStretch(3, 1); - - CBSelect = new QComboBox(this); - CBTeam = new QComboBox(this); - - pageLayout->addWidget(CBTeam, 1, 1); - pageLayout->addWidget(CBSelect, 2, 1); - - BtnStartCampaign = new QPushButton(this); - BtnStartCampaign->setFont(*font14); - BtnStartCampaign->setText(QPushButton::tr("Go!")); - pageLayout->addWidget(BtnStartCampaign, 2, 2); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 4, 0, true); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagecampaign.h --- a/QTfrontend/pagecampaign.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_CAMPAIGN_H -#define PAGE_CAMPAIGN_H - -#include "AbstractPage.h" - -class PageCampaign : public AbstractPage -{ - Q_OBJECT - -public: - PageCampaign(QWidget* parent = 0); - - QPushButton *BtnStartCampaign; - QPushButton *BtnBack; - QComboBox *CBSelect; - QComboBox *CBTeam; -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageconnecting.cpp --- a/QTfrontend/pageconnecting.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "pageconnecting.h" - -PageConnecting::PageConnecting(QWidget* parent) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - - QLabel * lblConnecting = new QLabel(this); - lblConnecting->setText(tr("Connecting...")); - pageLayout->addWidget(lblConnecting); - - QPushButton * pbCancel = new QPushButton(this); - pbCancel->setText(tr("Cancel")); - pageLayout->addWidget(pbCancel); - connect(pbCancel, SIGNAL(clicked()), this, SIGNAL(cancelConnection())); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageconnecting.h --- a/QTfrontend/pageconnecting.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_CONNECTING_H -#define PAGE_CONNECTING_H - -#include "AbstractPage.h" - -class PageConnecting : public AbstractPage -{ - Q_OBJECT - -public: - PageConnecting(QWidget* parent = 0); - -signals: - void cancelConnection(); -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagedata.cpp --- a/QTfrontend/pagedata.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,221 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pagedata.h" -#include "databrowser.h" -#include "hwconsts.h" - -#include "quazip.h" -#include "quazipfile.h" - -PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 1); - pageLayout->setColumnStretch(2, 1); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); - - web = new DataBrowser(this); - connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(request(const QUrl&))); - web->setOpenLinks(false); - pageLayout->addWidget(web, 0, 0, 1, 3); - - progressBarsLayout = new QVBoxLayout(); - pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3); - - fetchList(); -} - -void PageDataDownload::request(const QUrl &url) -{ - QUrl finalUrl; - if(url.host().isEmpty()) - finalUrl = QUrl("http://www.hedgewars.org" + url.path()); - else - finalUrl = url; - - if(url.path().endsWith(".zip")) - { - qWarning() << "Download Request" << url.toString(); - QString fileName = QFileInfo(url.toString()).fileName(); - - QNetworkRequest newRequest(finalUrl); - newRequest.setAttribute(QNetworkRequest::User, fileName); - - QNetworkAccessManager *manager = new QNetworkAccessManager(this); - QNetworkReply *reply = manager->get(newRequest); - connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded())); - connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); - - QProgressBar *progressBar = new QProgressBar(this); - progressBarsLayout->addWidget(progressBar); - progressBars.insert(reply, progressBar); - } else - { - qWarning() << "Page Request" << url.toString(); - - QNetworkRequest newRequest(finalUrl); - - QNetworkAccessManager *manager = new QNetworkAccessManager(this); - QNetworkReply *reply = manager->get(newRequest); - connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded())); - } -} - - -void PageDataDownload::pageDownloaded() -{ - QNetworkReply * reply = qobject_cast(sender()); - - if(reply) - { - QString html = QString::fromUtf8(reply->readAll()); - int begin = html.indexOf(""); - int end = html.indexOf(""); - if(begin != -1 && begin < end) - { - html.truncate(end); - html.remove(0, begin); - } - web->setHtml(html); - } -} - -void PageDataDownload::fileDownloaded() -{ - QNetworkReply * reply = qobject_cast(sender()); - - if(reply) - { - QByteArray fileContents = reply->readAll(); - QProgressBar *progressBar = progressBars.value(reply, 0); - - if(progressBar) - { - progressBars.remove(reply); - progressBar->deleteLater(); - } - - extractDataPack(&fileContents); - } -} - -void PageDataDownload::downloadProgress(qint64 bytesRecieved, qint64 bytesTotal) -{ - QNetworkReply * reply = qobject_cast(sender()); - - if(reply) - { - QProgressBar *progressBar = progressBars.value(reply, 0); - - if(progressBar) - { - progressBar->setValue(bytesRecieved); - progressBar->setMaximum(bytesTotal); - } - } -} - -void PageDataDownload::fetchList() -{ - request(QUrl("http://hedgewars.org/content.html")); -} - -bool PageDataDownload::extractDataPack(QByteArray * buf) -{ - QBuffer buffer; - buffer.setBuffer(buf); - - QuaZip zip; - zip.setIoDevice(&buffer); - if(!zip.open(QuaZip::mdUnzip)) - { - qWarning("testRead(): zip.open(): %d", zip.getZipError()); - return false; - } - - QuaZipFile file(&zip); - - QDir extractDir(*cfgdir); - extractDir.cd("Data"); - - for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) - { - if(!file.open(QIODevice::ReadOnly)) - { - qWarning("file.open(): %d", file.getZipError()); - return false; - } - - - QString fileName = file.getActualFileName(); - QString filePath = extractDir.filePath(fileName); - if (fileName.endsWith("/")) - { - QFileInfo fi(filePath); - QDir().mkpath(fi.filePath()); - } else - { - qDebug() << "Extracting" << filePath; - QFile out(filePath); - if(!out.open(QFile::WriteOnly)) - { - qWarning() << "out.open():" << out.errorString(); - return false; - } - - out.write(file.readAll()); - - out.close(); - - if(file.getZipError() != UNZ_OK) { - qWarning("file.getFileName(): %d", file.getZipError()); - return false; - } - - if(!file.atEnd()) { - qWarning("read all but not EOF"); - return false; - } - } - - file.close(); - - if(file.getZipError()!=UNZ_OK) { - qWarning("file.close(): %d", file.getZipError()); - return false; - } - } - - zip.close(); - - return true; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagedata.h --- a/QTfrontend/pagedata.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_DATA_H -#define PAGE_DATA_H - -#include -#include "AbstractPage.h" - -class DataBrowser; -class QProgressBar; -class QNetworkReply; -class QVBoxLayout; - -class PageDataDownload : public AbstractPage -{ - Q_OBJECT - -public: - PageDataDownload(QWidget* parent = 0); - - QPushButton *BtnBack; - -public slots: - void fetchList(); - -private: - DataBrowser *web; - QHash progressBars; - QVBoxLayout *progressBarsLayout; - - bool extractDataPack(QByteArray * buf); - -private slots: - void request(const QUrl &url); - - void pageDownloaded(); - void fileDownloaded(); - void downloadProgress(qint64, qint64); -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagedrawmap.cpp --- a/QTfrontend/pagedrawmap.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "pagedrawmap.h" -#include "drawmapwidget.h" - -PageDrawMap::PageDrawMap(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - - QPushButton * pbUndo = addButton(tr("Undo"), pageLayout, 0, 0); - QPushButton * pbClear = addButton(tr("Clear"), pageLayout, 1, 0); - QPushButton * pbLoad = addButton(tr("Load"), pageLayout, 2, 0); - QPushButton * pbSave = addButton(tr("Save"), pageLayout, 3, 0); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 5, 0, true); - - drawMapWidget = new DrawMapWidget(this); - pageLayout->addWidget(drawMapWidget, 0, 1, 5, 1); - - connect(pbUndo, SIGNAL(clicked()), drawMapWidget, SLOT(undo())); - connect(pbClear, SIGNAL(clicked()), drawMapWidget, SLOT(clear())); - connect(pbLoad, SIGNAL(clicked()), this, SLOT(load())); - connect(pbSave, SIGNAL(clicked()), this, SLOT(save())); -} - -void PageDrawMap::load() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Load drawn map"), ".", tr("Drawn Maps (*.hwmap);;All files (*.*)")); - - if(!fileName.isEmpty()) - drawMapWidget->load(fileName); -} - -void PageDrawMap::save() -{ - QString fileName = QFileDialog::getSaveFileName(this, tr("Save drawn map"), ".", tr("Drawn Maps (*.hwmap);;All files (*.*)")); - - if(!fileName.isEmpty()) - drawMapWidget->save(fileName); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagedrawmap.h --- a/QTfrontend/pagedrawmap.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_DRAWMAP_H -#define PAGE_DRAWMAP_H - -#include "AbstractPage.h" - -class DrawMapWidget; - -class PageDrawMap : public AbstractPage -{ - Q_OBJECT - -public: - PageDrawMap(QWidget* parent = 0); - - QPushButton * BtnBack; - - DrawMapWidget * drawMapWidget; - -private slots: - void load(); - void save(); -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageeditteam.cpp --- a/QTfrontend/pageeditteam.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,375 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pageeditteam.h" -#include "sdlkeys.h" -#include "hwconsts.h" -#include "SquareLabel.h" -#include "hats.h" -#include "HWApplication.h" - -PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) : - AbstractPage(parent) -{ - mySdli = sdli; - QGridLayout * pageLayout = new QGridLayout(this); - QTabWidget * tbw = new QTabWidget(this); - QWidget * page1 = new QWidget(this); - QWidget * page2 = new QWidget(this); - tbw->addTab(page1, tr("General")); - tbw->addTab(page2, tr("Advanced")); - pageLayout->addWidget(tbw, 0, 0, 1, 3); - BtnTeamDiscard = addButton(":/res/Exit.png", pageLayout, 1, 0, true); - BtnTeamSave = addButton(":/res/Save.png", pageLayout, 1, 2, true);; - BtnTeamSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); - BtnTeamDiscard->setFixedHeight(BtnTeamSave->height()); - BtnTeamDiscard->setStyleSheet("QPushButton{margin-top: 31px;}"); - - QHBoxLayout * page1Layout = new QHBoxLayout(page1); - page1Layout->setAlignment(Qt::AlignTop); - QGridLayout * page2Layout = new QGridLayout(page2); - -// ====== Page 1 ====== - QVBoxLayout * vbox1 = new QVBoxLayout(); - QVBoxLayout * vbox2 = new QVBoxLayout(); - page1Layout->addLayout(vbox1); - page1Layout->addLayout(vbox2); - - GBoxHedgehogs = new QGroupBox(this); - GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); - GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); - - signalMapper = new QSignalMapper(this); - - HatsModel * hatsModel = new HatsModel(GBoxHedgehogs); - for(int i = 0; i < 8; i++) - { - HHHats[i] = new QComboBox(GBoxHedgehogs); - HHHats[i]->setModel(hatsModel); - HHHats[i]->setIconSize(QSize(32, 37)); - //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); - //HHHats[i]->setModelColumn(1); - //HHHats[i]->setMinimumWidth(132); - GBHLayout->addWidget(HHHats[i], i, 0); - - HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); - HHNameEdit[i]->setMaxLength(64); - HHNameEdit[i]->setMinimumWidth(120); - GBHLayout->addWidget(HHNameEdit[i], i, 1); - - randButton[i] = addButton(":/res/dice.png", GBHLayout, i, 3, true); - - connect(randButton[i], SIGNAL(clicked()), signalMapper, SLOT(map())); - signalMapper->setMapping(randButton[i], i); - - } - - randTeamButton = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false); - - vbox1->addWidget(GBoxHedgehogs); - - - GBoxTeam = new QGroupBox(this); - GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); - GBoxTeam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - QGridLayout * GBTLayout = new QGridLayout(GBoxTeam); - QLabel * tmpLabel = new QLabel(GBoxTeam); - tmpLabel->setText(QLabel::tr("Name")); - GBTLayout->addWidget(tmpLabel, 0, 0); - tmpLabel = new QLabel(GBoxTeam); - tmpLabel->setText(QLabel::tr("Type")); - GBTLayout->addWidget(tmpLabel, 1, 0); - tmpLabel = new QLabel(GBoxTeam); - tmpLabel->setText(QLabel::tr("Grave")); - GBTLayout->addWidget(tmpLabel, 2, 0); - tmpLabel = new QLabel(GBoxTeam); - tmpLabel->setText(QLabel::tr("Flag")); - GBTLayout->addWidget(tmpLabel, 3, 0); - tmpLabel = new QLabel(GBoxTeam); - tmpLabel->setText(QLabel::tr("Voice")); - GBTLayout->addWidget(tmpLabel, 4, 0); - - - TeamNameEdit = new QLineEdit(GBoxTeam); - TeamNameEdit->setMaxLength(64); - GBTLayout->addWidget(TeamNameEdit, 0, 1); - vbox2->addWidget(GBoxTeam); - - CBTeamLvl = new QComboBox(GBoxTeam); - CBTeamLvl->setIconSize(QSize(48, 48)); - CBTeamLvl->addItem(QIcon(":/res/botlevels/0.png"), QComboBox::tr("Human")); - for(int i = 5; i > 0; i--) - CBTeamLvl->addItem( - QIcon(QString(":/res/botlevels/%1.png").arg(6 - i)), - QString("%1 %2").arg(QComboBox::tr("Level")).arg(i) - ); - GBTLayout->addWidget(CBTeamLvl, 1, 1); - - CBGrave = new QComboBox(GBoxTeam); - CBGrave->setMaxCount(65535); - CBGrave->setIconSize(QSize(32, 32)); - GBTLayout->addWidget(CBGrave, 2, 1); - - CBFlag = new QComboBox(GBoxTeam); - CBFlag->setMaxCount(65535); - CBFlag->setIconSize(QSize(22, 15)); - GBTLayout->addWidget(CBFlag, 3, 1); - - { - QHBoxLayout * hbox = new QHBoxLayout(); - CBVoicepack = new QComboBox(GBoxTeam); - { - QDir tmpdir; - QStringList list; - tmpdir.cd(cfgdir->absolutePath()); - if (tmpdir.cd("Data/Sounds/voices")) - { - list = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); - CBVoicepack->addItems(list); - } - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Sounds/voices"); - QStringList tmplist = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); - QStringList tmplist2; - for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) - if (!list.contains(*it,Qt::CaseInsensitive)) tmplist2.append(*it); - - CBVoicepack->addItems(tmplist2); - } - hbox->addWidget(CBVoicepack, 100); - BtnTestSound = addButton(":/res/PlaySound.png", hbox, 1, true); - hbox->setStretchFactor(BtnTestSound, 1); - connect(BtnTestSound, SIGNAL(clicked()), this, SLOT(testSound())); - GBTLayout->addLayout(hbox, 4, 1); - } - - GBoxFort = new QGroupBox(this); - GBoxFort->setTitle(QGroupBox::tr("Fort")); - QGridLayout * GBFLayout = new QGridLayout(GBoxFort); - CBFort = new QComboBox(GBoxFort); - CBFort->setMaxCount(65535); - GBFLayout->addWidget(CBFort, 0, 0); - FortPreview = new SquareLabel(GBoxFort); - FortPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - FortPreview->setMinimumSize(128, 128); - FortPreview->setPixmap(QPixmap()); - // perhaps due to handling its own paintevents, SquareLabel doesn't play nice with the stars - //FortPreview->setAttribute(Qt::WA_PaintOnScreen, true); - GBFLayout->addWidget(FortPreview, 1, 0); - vbox2->addWidget(GBoxFort); - - QDir tmpdir; - QStringList userforts; - tmpdir.cd(cfgdir->absolutePath()); - if (tmpdir.cd("Data/Forts")) - { - tmpdir.setFilter(QDir::Files); - userforts = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); - CBFort->addItems(userforts); - } - - tmpdir.cd("../Graphics/Graves"); - QStringList userlist = tmpdir.entryList(QStringList("*.png")); - for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) - { - QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Graves/" + *it); - QIcon icon(pix.copy(0, 0, 32, 32)); - CBGrave->addItem(icon, QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1")); - } - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Forts"); - tmpdir.setFilter(QDir::Files); - - QStringList tmplist = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); - QStringList dataforts; - for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) - if (!userforts.contains(*it,Qt::CaseInsensitive)) dataforts.append(*it); - - CBFort->addItems(dataforts); - connect(CBFort, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(CBFort_activated(const QString &))); - - tmpdir.cd("../Graphics/Graves"); - QStringList datalist = tmpdir.entryList(QStringList("*.png")); - for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) - { - if (userlist.contains(*it,Qt::CaseInsensitive)) continue; - QPixmap pix(datadir->absolutePath() + "/Graphics/Graves/" + *it); - QIcon icon(pix.copy(0, 0, 32, 32)); - CBGrave->addItem(icon, (*it).replace(QRegExp("^(.*)\\.png"), "\\1")); - } - - // add the default flag - CBFlag->addItem(QIcon(QPixmap(datadir->absolutePath() + "/Graphics/Flags/hedgewars.png").copy(0, 0, 22, 15)), "Hedgewars", "hedgewars"); - CBFlag->insertSeparator(CBFlag->count()); - - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data/Graphics/Flags"); - userlist = tmpdir.entryList(QStringList("*.png")); - - // add all country flags - for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) - { - QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it); - QIcon icon(pix.copy(0, 0, 22, 15)); - if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags - { - QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - CBFlag->addItem(icon, QString(flag).replace("_", " "), flag); - } - } - - CBFlag->insertSeparator(CBFlag->count()); - - // add all community flags - for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) - { - QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it); - QIcon icon(pix.copy(0, 0, 22, 15)); - if(it->indexOf("cm_") > -1) // skip non community flags this time - { - QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); - } - } - - CBFlag->insertSeparator(CBFlag->count()); - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Graphics/Flags"); - datalist = tmpdir.entryList(QStringList("*.png")); - - // add all country flags - for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) - { - if (userlist.contains(*it,Qt::CaseInsensitive)) continue; - QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); - QIcon icon(pix.copy(0, 0, 22, 15)); - if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags - { - QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - CBFlag->addItem(icon, QString(flag).replace("_", " "), flag); - } - } - - CBFlag->insertSeparator(CBFlag->count()); - - // add all community flags - for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) - { - if (userlist.contains(*it,Qt::CaseInsensitive)) continue; - QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); - QIcon icon(pix.copy(0, 0, 22, 15)); - if(it->indexOf("cm_") > -1) // skip non community flags this time - { - QString flag = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); - CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); - } - } - - vbox1->addStretch(); - vbox2->addStretch(); - -// ====== Page 2 ====== - GBoxBinds = new QGroupBox(this); - GBoxBinds->setTitle(QGroupBox::tr("Key binds")); - QGridLayout * GBBLayout = new QGridLayout(GBoxBinds); - BindsBox = new QToolBox(GBoxBinds); - BindsBox->setLineWidth(0); - GBBLayout->addWidget(BindsBox); - page2Layout->addWidget(GBoxBinds, 0, 0); - - quint16 i = 0; - quint16 num = 0; - QWidget * curW = NULL; - QGridLayout * pagelayout = NULL; - QLabel* l = NULL; - while (i < BINDS_NUMBER) { - if(cbinds[i].category != NULL) - { - if(curW != NULL) - { - l = new QLabel(curW); - l->setText(""); - pagelayout->addWidget(l, num++, 0, 1, 2); - } - curW = new QWidget(this); - BindsBox->addItem(curW, HWApplication::translate("binds (categories)", cbinds[i].category)); - pagelayout = new QGridLayout(curW); - num = 0; - } - if(cbinds[i].description != NULL) - { - l = new QLabel(curW); - l->setText((num > 0 ? QString("\n") : QString("")) + HWApplication::translate("binds (descriptions)", cbinds[i].description)); - pagelayout->addWidget(l, num++, 0, 1, 2); - } - - l = new QLabel(curW); - l->setText(HWApplication::translate("binds", cbinds[i].name)); - l->setAlignment(Qt::AlignRight); - pagelayout->addWidget(l, num, 0); - CBBind[i] = new QComboBox(curW); - for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) - CBBind[i]->addItem(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), sdlkeys[j][0]); - pagelayout->addWidget(CBBind[i++], num++, 1); - } -} - -void PageEditTeam::CBFort_activated(const QString & fortname) -{ - QFile tmp; - tmp.setFileName(cfgdir->absolutePath() + "/Data/Forts/" + fortname + "L.png"); - if (!tmp.exists()) tmp.setFileName(datadir->absolutePath() + "/Forts/" + fortname + "L.png"); - QPixmap pix(QFileInfo(tmp).absoluteFilePath()); - FortPreview->setPixmap(pix); -} - -void PageEditTeam::testSound() -{ - Mix_Chunk *sound; - QDir tmpdir; - mySdli->SDLMusicInit(); - - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data/Sounds/voices"); - tmpdir.cd(CBVoicepack->currentText()); - - if (!tmpdir.exists()) { - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Sounds/voices"); - tmpdir.cd(CBVoicepack->currentText()); - } - - QStringList list = tmpdir.entryList(QStringList() << "Illgetyou.ogg" << "Incoming.ogg" << "Stupid.ogg" << "Coward.ogg" << "Firstblood.ogg", QDir::Files); - if (list.size()) { - sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData()); - Mix_PlayChannel(-1, sound, 0); - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageeditteam.h --- a/QTfrontend/pageeditteam.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_EDITTEAM_H -#define PAGE_EDITTEAM_H - -#include "AbstractPage.h" -#include "binds.h" -#include "SDLs.h" - -class SquareLabel; - -class PageEditTeam : public AbstractPage -{ - Q_OBJECT - -public: - PageEditTeam(QWidget* parent, SDLInteraction * sdli); - QSignalMapper* signalMapper; - QGroupBox *GBoxHedgehogs; - QGroupBox *GBoxTeam; - QGroupBox *GBoxFort; - QComboBox *CBFort; - SquareLabel *FortPreview; - QComboBox *CBGrave; - QComboBox *CBFlag; - QComboBox *CBTeamLvl; - QComboBox *CBVoicepack; - QGroupBox *GBoxBinds; - QToolBox *BindsBox; - QPushButton *BtnTeamDiscard; - QPushButton *BtnTeamSave; - QPushButton * BtnTestSound; - QLineEdit * TeamNameEdit; - QLineEdit * HHNameEdit[8]; - QComboBox * HHHats[8]; - QPushButton * randButton[8]; - QComboBox * CBBind[BINDS_NUMBER]; - QPushButton * randTeamButton; - -private: - SDLInteraction * mySdli; - -public slots: - void CBFort_activated(const QString & gravename); - -private slots: - void testSound(); -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagegamestats.cpp --- a/QTfrontend/pagegamestats.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,257 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2010-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include - -#include "pagegamestats.h" -#include "team.h" - -FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent) -{ - -} - -void FitGraphicsView::resizeEvent(QResizeEvent * event) -{ - Q_UNUSED(event); - - fitInView(sceneRect()); -} - -PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setSpacing(20); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 1); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); - BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - - BtnSave = addButton(":/res/Save.png", pageLayout, 3, 2, true); - BtnSave->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - BtnSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); - connect(BtnSave, SIGNAL(clicked()), this, SIGNAL(saveDemoRequested())); - - QGroupBox * gb = new QGroupBox(this); - QVBoxLayout * gbl = new QVBoxLayout; - - // details - labelGameStats = new QLabel(this); - QLabel * l = new QLabel(this); - l->setTextFormat(Qt::RichText); - l->setText("

" + PageGameStats::tr("Details") + "

"); - l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - labelGameStats->setTextFormat(Qt::RichText); - labelGameStats->setAlignment(Qt::AlignTop); - labelGameStats->setWordWrap(true); - gbl->addWidget(l); - gbl->addWidget(labelGameStats); - gb->setLayout(gbl); - pageLayout->addWidget(gb, 1, 1, 1, 2); - - // graph - graphic = new FitGraphicsView(gb); - l = new QLabel(this); - l->setTextFormat(Qt::RichText); - l->setText("

" + PageGameStats::tr("Health graph") + "

"); - l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - gbl->addWidget(l); - gbl->addWidget(graphic); - graphic->scale(1.0, -1.0); - graphic->setBackgroundBrush(QBrush(Qt::black)); - - labelGameWin = new QLabel(this); - labelGameWin->setTextFormat(Qt::RichText); - pageLayout->addWidget(labelGameWin, 0, 0, 1, 2); - - // ranking box - gb = new QGroupBox(this); - gbl = new QVBoxLayout; - labelGameRank = new QLabel(gb); - l = new QLabel(this); - l->setTextFormat(Qt::RichText); - l->setText("

" + PageGameStats::tr("Ranking") + "

"); - l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - gbl->addWidget(l); - gbl->addWidget(labelGameRank); - gb->setLayout(gbl); - - labelGameRank->setTextFormat(Qt::RichText); - labelGameRank->setAlignment(Qt::AlignTop); - pageLayout->addWidget(gb, 1, 0); -} - -void PageGameStats::AddStatText(const QString & msg) -{ - labelGameStats->setText(labelGameStats->text() + msg); -} - -void PageGameStats::clear() -{ - labelGameStats->setText(""); - healthPoints.clear(); - labelGameRank->setText(""); - playerPosition = 0; - lastColor = 0; -} - -void PageGameStats::renderStats() -{ - QGraphicsScene * scene = new QGraphicsScene(); - - QMap >::const_iterator i = healthPoints.constBegin(); - while (i != healthPoints.constEnd()) - { - quint32 c = i.key(); - QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); - QVector hps = i.value(); - - QPainterPath path; - if (hps.size()) - path.moveTo(0, hps[0]); - - for(int t = 1; t < hps.size(); ++t) - path.lineTo(t, hps[t]); - - scene->addPath(path, QPen(c)); - ++i; - } - - graphic->setScene(scene); - graphic->fitInView(graphic->sceneRect()); -} - -void PageGameStats::GameStats(char type, const QString & info) -{ - switch(type) { - case 'r' : { - labelGameWin->setText(QString("

%1

").arg(info)); - break; - } - case 'D' : { - int i = info.indexOf(' '); - QString message = "

" + PageGameStats::tr("The best shot award was won by %1 with %2 pts.").arg(info.mid(i + 1), info.left(i)) + "

"; - AddStatText(message); - break; - } - case 'k' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("The best killer is %1 with %2 kills in a turn.", "", num).arg(info.mid(i + 1), info.left(i)) + "

"; - AddStatText(message); - break; - } - case 'K' : { - int num = info.toInt(); - QString message = "

" + PageGameStats::tr("A total of %1 hedgehog(s) were killed during this round.", "", num).arg(num) + "

"; - AddStatText(message); - break; - } - case 'H' : { - int i = info.indexOf(' '); - quint32 clan = info.left(i).toInt(); - quint32 hp = info.mid(i + 1).toUInt(); - healthPoints[clan].append(hp); - break; - } - case 'T': { // local team stats - //AddStatText("

local team: " + info + "

"); - QStringList infol = info.split(":"); - HWTeam team(infol[0]); - if(team.FileExists()) // do some better test to avoid influence from scripted/predefined teams? - { - team.LoadFromFile(); - team.Rounds++; - if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP! - team.Wins++; // should draws count as wins? - //team.SaveToFile(); // don't save yet - } - break; - } - - case 'P' : { - int i = info.indexOf(' '); - playerPosition++; - QString color = info.left(i); - quint32 c = color.toInt(); - QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); - - QString playerinfo = info.mid(i + 1); - - i = playerinfo.indexOf(' '); - - int kills = playerinfo.left(i).toInt(); - QString playername = playerinfo.mid(i + 1); - QString image; - - if (lastColor == c) playerPosition--; - lastColor = c; - - switch (playerPosition) - { - case 1: - image = ""; - break; - case 2: - image = ""; - break; - case 3: - image = ""; - break; - default: - image = ""; - break; - } - - QString message; - QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills); - - message = QString("

%1 %2. %3 ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "

"; - - labelGameRank->setText(labelGameRank->text() + message); - break; - } - case 's' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("%1 thought it's good to shoot his own hedgehogs with %2 pts.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; - AddStatText(message); - break; - } - case 'S' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("%1 killed %2 of his own hedgehogs.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; - AddStatText(message); - break; - } - case 'B' : { - int i = info.indexOf(' '); - int num = info.left(i).toInt(); - QString message = "

" + PageGameStats::tr("%1 was scared and skipped turn %2 times.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; - AddStatText(message); - break; - } - - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagegamestats.h --- a/QTfrontend/pagegamestats.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2010-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef STATSPAGE_H -#define STATSPAGE_H - -#include -#include -#include - -#include "AbstractPage.h" - -class FitGraphicsView : public QGraphicsView -{ - Q_OBJECT - -public: - FitGraphicsView(QWidget* parent = 0); - -protected: - void resizeEvent(QResizeEvent * event); -}; - -class PageGameStats : public AbstractPage -{ - Q_OBJECT - -public: - PageGameStats(QWidget* parent = 0); - - QPushButton *BtnBack; - QPushButton *BtnSave; - QLabel *labelGameStats; - QLabel *labelGameWin; - QLabel *labelGameRank; - FitGraphicsView * graphic; - -public slots: - void GameStats(char type, const QString & info); - void clear(); - void renderStats(); - -signals: - void saveDemoRequested(); - -private: - void AddStatText(const QString & msg); - - QMap > healthPoints; - unsigned int playerPosition; - quint32 lastColor; -}; - -#endif // STATSPAGE_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageinfo.cpp --- a/QTfrontend/pageinfo.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "pageinfo.h" -#include "about.h" - -PageInfo::PageInfo(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 1); - pageLayout->setColumnStretch(2, 1); - - BtnSnapshots = addButton(":/res/Star.png", pageLayout, 1, 2, true); - BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true); - - about = new About(this); - pageLayout->addWidget(about, 0, 0, 1, 3); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageinfo.h --- a/QTfrontend/pageinfo.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_INFO_H -#define PAGE_INFO_H - -#include "AbstractPage.h" - -class About; - -class PageInfo : public AbstractPage -{ - Q_OBJECT - -public: - PageInfo(QWidget* parent = 0); - - QPushButton *BtnSnapshots; - QPushButton *BtnBack; - About *about; -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageingame.cpp --- a/QTfrontend/pageingame.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include - -#include "pageingame.h" - -PageInGame::PageInGame(QWidget* parent) : - AbstractPage(parent) -{ - QLabel * label = new QLabel(this); - label->setText("In game..."); -} - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageingame.h --- a/QTfrontend/pageingame.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_INGAME_H -#define PAGE_INGAME_H - -#include "AbstractPage.h" - -class PageInGame : public AbstractPage -{ - Q_OBJECT - -public: - PageInGame(QWidget* parent = 0); -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagemain.cpp --- a/QTfrontend/pagemain.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,139 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include - -#include "pagemain.h" -#include "hwconsts.h" -#include "hwform.h" - -PageMain::PageMain(QWidget* parent) : - AbstractPage(parent) -{ - if(frontendEffects) setAttribute(Qt::WA_NoSystemBackground, true); - QGridLayout * pageLayout = new QGridLayout(this); - //pageLayout->setColumnStretch(0, 1); - //pageLayout->setColumnStretch(1, 2); - //pageLayout->setColumnStretch(2, 1); - - //QPushButton* btnLogo = addButton(":/res/HedgewarsTitle.png", pageLayout, 0, 0, 1, 4, true); - //pageLayout->setAlignment(btnLogo, Qt::AlignHCenter); - pageLayout->setRowStretch(0, 1); - pageLayout->setRowStretch(1, 1); - pageLayout->setRowStretch(2, 0); - pageLayout->setRowStretch(3, 1); - pageLayout->setRowStretch(4, 1); - pageLayout->setRowStretch(5, 1); - - BtnSinglePlayer = addButton(":/res/LocalPlay.png", pageLayout, 2, 0, 1, 2, true); - BtnSinglePlayer->setToolTip(tr("Local Game (Play a game on a single computer)")); - pageLayout->setAlignment(BtnSinglePlayer, Qt::AlignHCenter); - - BtnNet = addButton(":/res/NetworkPlay.png", pageLayout, 2, 2, 1, 2, true); - BtnNet->setToolTip(tr("Network Game (Play a game across a network)")); - pageLayout->setAlignment(BtnNet, Qt::AlignHCenter); - - BtnDataDownload = addButton(tr("Downloadable Content"), pageLayout, 4, 0, 1, 4, false); - pageLayout->setAlignment(BtnDataDownload, Qt::AlignHCenter); - - mainNote = new QLabel(this); - mainNote->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); - mainNote->setWordWrap(true); - mainNote->setOpenExternalLinks(true); - - if(!isDevBuild) - { - QStringList Tips; - Tips << tr("Simply pick the same color as a friend to play together as a team. Each of you will still control his or her own hedgehogs but they'll win or lose together.", "Tips"); - Tips << tr("Some weapons might do only low damage but they can be a lot more devastating in the right situation. Try to use the Desert Eagle to knock multiple hedgehogs into the water.", "Tips"); - Tips << tr("If you're unsure what to do and don't want to waste ammo, skip one round. But don't let too much time pass as there will be Sudden Death!", "Tips"); - Tips << tr("Want to save ropes? Release the rope in mid air and then shoot again. As long as you don't touch the ground you'll reuse your rope without wasting ammo!", "Tips"); - Tips << tr("If you'd like to keep others from using your preferred nickname on the official server, register an account at http://www.hedgewars.org/.", "Tips"); - Tips << tr("You're bored of default gameplay? Try one of the missions - they'll offer different gameplay depending on the one you picked.", "Tips"); - Tips << tr("By default the game will always record the last game played as a demo. Select 'Local Game' and pick the 'Demos' button on the lower right corner to play or manage them.", "Tips"); - Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. If you've got problems, ask on our forums but please don't expect 24/7 support!", "Tips"); - Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. If you like it, help us with a small donation or contribute your own work!", "Tips"); - Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. Share it with your family and friends as you like!", "Tips"); - Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. If someone sold you the game, you should try get a refund!", "Tips"); - Tips << tr("From time to time there will be official tournaments. Upcoming events will be announced at http://www.hedgewars.org/ some days in advance.", "Tips"); - Tips << tr("Hedgewars is available in many languages. If the translation in your language seems to be missing or outdated, feel free to contact us!", "Tips"); - Tips << tr("Hedgewars can be run on lots of different operating systems including Microsoft Windows, Mac OS X and Linux.", "Tips"); - Tips << tr("Always remember you're able to set up your own games in local and network/online play. You're not restricted to the 'Simple Game' option.", "Tips"); - Tips << tr("Connect one or more gamepads before starting the game to be able to assign their controls to your teams.", "Tips"); - Tips << tr("Create an account on %1 to keep others from using your most favourite nickname while playing on the official server.", "Tips").arg("http://www.hedgewars.org/"); - Tips << tr("While playing you should give yourself a short break at least once an hour.", "Tips"); - Tips << tr("If your graphics card isn't able to provide hardware accelerated OpenGL, try to enable the low quality mode to improve performance.", "Tips"); - Tips << tr("If your graphics card isn't able to provide hardware accelerated OpenGL, try to update the associated drivers.", "Tips"); - Tips << tr("We're open to suggestions and constructive feedback. If you don't like something or got a great idea, let us know!", "Tips"); - Tips << tr("Especially while playing online be polite and always remember there might be some minors playing with or against you as well!", "Tips"); - Tips << tr("Special game modes such as 'Vampirism' or 'Karma' allow you to develop completely new tactics. Try them in a custom game!", "Tips"); - Tips << tr("The Windows version of Hedgewars supports Xfire. Make sure to add Hedgewars to its game list so your friends can see you playing.", "Tips"); - Tips << tr("You should never install Hedgewars on computers you don't own (school, university, work, etc.). Please ask the responsible person instead!", "Tips"); - Tips << tr("Hedgewars can be perfect for short games during breaks. Just ensure you don't add too many hedgehogs or use an huge map. Reducing time and health might help as well.", "Tips"); - Tips << tr("No hedgehogs were harmed in making this game.", "Tips"); - Tips << tr("There are three different jumps available. Tap [high jump] twice to do a very high/backwards jump.", "Tips"); - Tips << tr("Afraid of falling off a cliff? Hold down [precise] to turn [left] or [right] without actually moving.", "Tips"); - Tips << tr("Some weapons require special strategies or just lots of training, so don't give up on a particular tool if you miss an enemy once.", "Tips"); - Tips << tr("Most weapons won't work once they touch the water. The Homing Bee as well as the Cake are exceptions to this.", "Tips"); - Tips << tr("The Old Limbuger only causes a small explosion. However the wind affected smelly cloud can poison lots of hogs at once.", "Tips"); - Tips << tr("The Piano Strike is the most damaging air strike. You'll lose the hedgehog performing it, so there's a huge downside as well.", "Tips"); - Tips << tr("The Homing Bee can be tricky to use. Its turn radius depends on its velocity, so try to not use full power.", "Tips"); - Tips << tr("Sticky Mines are a perfect tool to create small chain reactions knocking enemy hedgehogs into dire situations ... or water.", "Tips"); - Tips << tr("The Hammer is most effective when used on bridges or girders. Hit hogs will just break through the ground.", "Tips"); - Tips << tr("If you're stuck behind an enemy hedgehog, use the Hammer to free yourself without getting damaged by an explosion.", "Tips"); - Tips << tr("The Cake's maximum walking distance depends on the ground it has to pass. Use [attack] to detonate it early.", "Tips"); - Tips << tr("The Flame Thrower is a weapon but it can be used for tunnel digging as well.", "Tips"); - Tips << tr("Use the Molotov or Flame Thrower to temporary keep hedgehogs from passing terrain such as tunnels or platforms.", "Tips"); - Tips << tr("Want to know who's behind the game? Click on the Hedgewars logo in the main menu to see the credits.", "Tips"); - Tips << tr("Like Hedgewars? Become a fan on %1 or follow us on %2!", "Tips").arg("Facebook").arg("Twitter"); - Tips << tr("Feel free to draw your own graves, hats, flags or even maps and themes! But note that you'll have to share them somewhere to use them online.", "Tips"); - Tips << tr("Really want to wear a specific hat? Donate to us and receive an exclusive hat of your choice!", "Tips"); - // The following tip will require links to app store entries first. - //Tips << tr("Want to play Hedgewars any time? Grab the Mobile version for %1 and %2.", "Tips").arg("").arg(""); - // the ios version is located here: http://itunes.apple.com/us/app/hedgewars/id391234866 - Tips << tr("Keep your video card drivers up to date to avoid issues playing the game.", "Tips"); - Tips << tr("You're able to associate Hedgewars related files (savegames and demo recordings) with the game to launch them right from your favorite file or internet browser.", "Tips"); -#ifdef _WIN32 - Tips << tr("You can find your Hedgewars configuration files under \"My Documents\\Hedgewars\". Create backups or take the files with you, but don't edit them by hand.", "Tips"); -#elif defined __APPLE__ - Tips << tr("You can find your Hedgewars configuration files under \"Library/Application Support/Hedgewars\" in your home directory. Create backups or take the files with you, but don't edit them by hand.", "Tips"); -#else - Tips << tr("You can find your Hedgewars configuration files under \".hedgewars\" in your home directory. Create backups or take the files with you, but don't edit them by hand.", "Tips"); -#endif - mainNote->setText(QLabel::tr("Tip: ") + Tips[QTime(0, 0, 0).secsTo(QTime::currentTime()) % Tips.length()]); - } - else - mainNote->setText(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game. Some features might be broken or incomplete. Use at your own risk!")); - - pageLayout->addWidget(mainNote, 5, 1, 1, 2); - - BtnSetup = addButton(":/res/Settings.png", pageLayout, 5, 3, true); - - //BtnInfo = addButton(":/res/About.png", pageLayout, 3, 1, 1, 2, true); - BtnInfo = addButton(":/res/HedgewarsTitle.png", pageLayout, 0, 0, 1, 4, true); - BtnInfo->setStyleSheet("border: transparent;background: transparent;"); - pageLayout->setAlignment(BtnInfo, Qt::AlignHCenter); - //pageLayout->setAlignment(BtnInfo, Qt::AlignHCenter); - - BtnExit = addButton(":/res/Exit.png", pageLayout, 5, 0, 1, 1, true); - BtnExit->setFixedHeight(BtnSetup->height()); - BtnExit->setStyleSheet("QPushButton{margin-top: 2px;}"); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagemain.h --- a/QTfrontend/pagemain.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_MAIN_H -#define PAGE_MAIN_H - -#include "AbstractPage.h" - -class PageMain : public AbstractPage -{ - Q_OBJECT - -public: - PageMain(QWidget* parent = 0); - - QPushButton *BtnSinglePlayer; - QPushButton *BtnNet; - QPushButton *BtnSetup; - QPushButton *BtnInfo; - QPushButton *BtnExit; - QPushButton *BtnDataDownload; - QLabel *mainNote; -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagemultiplayer.cpp --- a/QTfrontend/pagemultiplayer.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "pagemultiplayer.h" -#include "gamecfgwidget.h" -#include "teamselect.h" - -PageMultiplayer::PageMultiplayer(QWidget* parent) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); - - gameCFG = new GameCFGWidget(this); - pageLayout->addWidget(gameCFG, 0, 0, 1, 2); - - QPushButton * btnSetup = new QPushButton(this); - btnSetup->setText(QPushButton::tr("Setup")); - connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked())); - pageLayout->addWidget(btnSetup, 1, 0, 1, 2); - - pageLayout->setRowStretch(2, 1); - - teamsSelect = new TeamSelWidget(this); - pageLayout->addWidget(teamsSelect, 0, 2, 3, 2); - - BtnStartMPGame = addButton(tr("Start"), pageLayout, 3, 3); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagemultiplayer.h --- a/QTfrontend/pagemultiplayer.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_MULTIPLAYER_H -#define PAGE_MULTIPLAYER_H - -#include "AbstractPage.h" - -class GameCFGWidget; -class TeamSelWidget; - -class PageMultiplayer : public AbstractPage -{ - Q_OBJECT - -public: - PageMultiplayer(QWidget* parent = 0); - - QPushButton *BtnBack; - GameCFGWidget *gameCFG; - TeamSelWidget *teamsSelect; - QPushButton *BtnStartMPGame; - -signals: - void SetupClicked(); -}; - -#endif - - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenet.cpp --- a/QTfrontend/pagenet.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include - -#include "pagenet.h" -#include "hwconsts.h" -#include "netudpwidget.h" - -PageNet::PageNet(QWidget* parent) : AbstractPage(parent) -{ - QFont * font14 = new QFont("MS Shell Dlg", 14); - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 1); - pageLayout->setColumnStretch(2, 1); - - BtnNetSvrStart = new QPushButton(this); - BtnNetSvrStart->setFont(*font14); - BtnNetSvrStart->setText(QPushButton::tr("Start server")); - BtnNetSvrStart->setVisible(haveServer); - pageLayout->addWidget(BtnNetSvrStart, 4, 2); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 4, 0, true); - - ConnGroupBox = new QGroupBox(this); - ConnGroupBox->setTitle(QGroupBox::tr("Net game")); - pageLayout->addWidget(ConnGroupBox, 2, 0, 1, 3); - GBClayout = new QGridLayout(ConnGroupBox); - GBClayout->setColumnStretch(0, 1); - GBClayout->setColumnStretch(1, 1); - GBClayout->setColumnStretch(2, 1); - - BtnNetConnect = new QPushButton(ConnGroupBox); - BtnNetConnect->setFont(*font14); - BtnNetConnect->setText(QPushButton::tr("Connect")); - GBClayout->addWidget(BtnNetConnect, 2, 2); - - tvServersList = new QTableView(ConnGroupBox); - tvServersList->setSelectionBehavior(QAbstractItemView::SelectRows); - GBClayout->addWidget(tvServersList, 1, 0, 1, 3); - - BtnUpdateSList = new QPushButton(ConnGroupBox); - BtnUpdateSList->setFont(*font14); - BtnUpdateSList->setText(QPushButton::tr("Update")); - GBClayout->addWidget(BtnUpdateSList, 2, 0); - - BtnSpecifyServer = new QPushButton(ConnGroupBox); - BtnSpecifyServer->setFont(*font14); - BtnSpecifyServer->setText(QPushButton::tr("Specify")); - GBClayout->addWidget(BtnSpecifyServer, 2, 1); - - connect(BtnNetConnect, SIGNAL(clicked()), this, SLOT(slotConnect())); -} - -void PageNet::updateServersList() -{ - tvServersList->setModel(new HWNetUdpModel(tvServersList)); - - tvServersList->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - - static_cast(tvServersList->model())->updateList(); - - connect(BtnUpdateSList, SIGNAL(clicked()), static_cast(tvServersList->model()), SLOT(updateList())); - connect(tvServersList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotConnect())); -} - -void PageNet::slotConnect() -{ - HWNetServersModel * model = static_cast(tvServersList->model()); - QModelIndex mi = tvServersList->currentIndex(); - if(!mi.isValid()) - { - QMessageBox::information(this, tr("Error"), tr("Please select server from the list above")); - return; - } - QString host = model->index(mi.row(), 1).data().toString(); - quint16 port = model->index(mi.row(), 2).data().toUInt(); - - emit connectClicked(host, port); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenet.h --- a/QTfrontend/pagenet.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_NET_H -#define PAGE_NET_H - -#include "AbstractPage.h" - -class PageNet : public AbstractPage -{ - Q_OBJECT - -public: - PageNet(QWidget* parent = 0); - - QPushButton* BtnUpdateSList; - QTableView * tvServersList; - QPushButton * BtnBack; - QPushButton * BtnNetConnect; - QPushButton * BtnNetSvrStart; - QPushButton * BtnSpecifyServer; - -private: - QGroupBox * ConnGroupBox; - QGridLayout * GBClayout; - -private slots: - void slotConnect(); - -public slots: - void updateServersList(); - -signals: - void connectClicked(const QString & host, quint16 port); -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenetgame.cpp --- a/QTfrontend/pagenetgame.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include - -#include "pagenetgame.h" -#include "gamecfgwidget.h" -#include "teamselect.h" -#include "chatwidget.h" - -PageNetGame::PageNetGame(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setSizeConstraint(QLayout::SetMinimumSize); - //pageLayout->setSpacing(1); - pageLayout->setColumnStretch(0, 50); - pageLayout->setColumnStretch(1, 50); - - // chatwidget - pChatWidget = new HWChatWidget(this, gameSettings, sdli, true); - pChatWidget->setShowReady(true); // show status bulbs by default - pChatWidget->setShowFollow(false); // don't show follow in nicks' context menus - pageLayout->addWidget(pChatWidget, 2, 0, 1, 2); - pageLayout->setRowStretch(1, 100); - - pGameCFG = new GameCFGWidget(this); - pageLayout->addWidget(pGameCFG, 0, 0); - - QPushButton * btnSetup = new QPushButton(this); - btnSetup->setText(QPushButton::tr("Setup")); - connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked())); - pageLayout->addWidget(btnSetup, 1, 0); - - pNetTeamsWidget = new TeamSelWidget(this); - pNetTeamsWidget->setAcceptOuter(true); - pageLayout->addWidget(pNetTeamsWidget, 0, 1, 2, 1); - - - QHBoxLayout * bottomLayout = new QHBoxLayout; - pageLayout->addLayout(bottomLayout, 4, 0, 1, 2); - - BtnBack = addButton(":/res/Exit.png", bottomLayout, 0, true); - - leRoomName = new QLineEdit(this); - leRoomName->setMaxLength(60); - leRoomName->setMinimumWidth(200); - leRoomName->setMaximumWidth(400); - bottomLayout->addWidget(leRoomName, 8,0); - BtnUpdate = addButton(QAction::tr("Update"), bottomLayout, 1, false); - - BtnGo = new QPushButton(this); - BtnGo->setToolTip(QPushButton::tr("Ready")); - BtnGo->setIcon(QIcon(":/res/lightbulb_off.png")); - BtnGo->setIconSize(QSize(25, 34)); - BtnGo->setMinimumWidth(50); - BtnGo->setMinimumHeight(50); - bottomLayout->addWidget(BtnGo, 4); - - - BtnMaster = addButton(tr("Control"), bottomLayout, 2); - QMenu * menu = new QMenu(BtnMaster); - restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu); - restrictJoins->setCheckable(true); - restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu); - restrictTeamAdds->setCheckable(true); - //menu->addAction(startGame); - menu->addAction(restrictJoins); - menu->addAction(restrictTeamAdds); - - BtnMaster->setMenu(menu); - - BtnStart = addButton(QAction::tr("Start"), bottomLayout, 3); - - bottomLayout->insertStretch(3, 100); - - connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick())); -} - -void PageNetGame::setReadyStatus(bool isReady) -{ - if(isReady) - BtnGo->setIcon(QIcon(":/res/lightbulb_on.png")); - else - BtnGo->setIcon(QIcon(":/res/lightbulb_off.png")); -} - -void PageNetGame::onUpdateClick() -{ - if (leRoomName->text().size()) - emit askForUpdateRoomName(leRoomName->text()); - else - QMessageBox::critical(this, - tr("Error"), - tr("Please enter room name"), - tr("OK")); -} - -void PageNetGame::setMasterMode(bool isMaster) -{ - BtnMaster->setVisible(isMaster); - BtnStart->setVisible(isMaster); - BtnUpdate->setVisible(isMaster); - leRoomName->setVisible(isMaster); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenetgame.h --- a/QTfrontend/pagenetgame.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_NETGAME_H -#define PAGE_NETGAME_H - -#include "AbstractPage.h" -#include "SDLs.h" - -class HWChatWidget; -class TeamSelWidget; -class GameCFGWidget; - -class PageNetGame : public AbstractPage -{ - Q_OBJECT - -public: - PageNetGame(QWidget* parent, QSettings * config, SDLInteraction * sdli); - - QPushButton *BtnBack; - QPushButton *BtnGo; - QPushButton *BtnMaster; - QPushButton *BtnStart; - QPushButton *BtnUpdate; - - QLineEdit * leRoomName; - - QAction * restrictJoins; - QAction * restrictTeamAdds; - - HWChatWidget* pChatWidget; - - TeamSelWidget* pNetTeamsWidget; - GameCFGWidget* pGameCFG; - -public slots: - void setReadyStatus(bool isReady); - void onUpdateClick(); - void setMasterMode(bool isMaster); - -signals: - void SetupClicked(); - void askForUpdateRoomName(const QString &); -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenetserver.cpp --- a/QTfrontend/pagenetserver.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include - -#include "pagenetserver.h" - -PageNetServer::PageNetServer(QWidget* parent) : AbstractPage(parent) -{ - QFont * font14 = new QFont("MS Shell Dlg", 14); - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 1); - pageLayout->setColumnStretch(2, 1); - - pageLayout->setRowStretch(0, 1); - pageLayout->setRowStretch(1, 0); - - BtnBack =addButton(":/res/Exit.png", pageLayout, 1, 0, true); - - BtnStart = new QPushButton(this); - BtnStart->setFont(*font14); - BtnStart->setText(QPushButton::tr("Start")); - pageLayout->addWidget(BtnStart, 1, 2); - - QWidget * wg = new QWidget(this); - pageLayout->addWidget(wg, 0, 0, 1, 3); - - QGridLayout * wgLayout = new QGridLayout(wg); - wgLayout->setColumnStretch(0, 1); - wgLayout->setColumnStretch(1, 3); - wgLayout->setColumnStretch(2, 1); - - wgLayout->setRowStretch(0, 0); - wgLayout->setRowStretch(1, 1); - - QGroupBox * gb = new QGroupBox(wg); - wgLayout->addWidget(gb, 0, 1); - - QGridLayout * gbLayout = new QGridLayout(gb); - - labelSD = new QLabel(gb); - labelSD->setText(QLabel::tr("Server name:")); - gbLayout->addWidget(labelSD, 0, 0); - - leServerDescr = new QLineEdit(gb); - gbLayout->addWidget(leServerDescr, 0, 1); - - labelPort = new QLabel(gb); - labelPort->setText(QLabel::tr("Server port:")); - gbLayout->addWidget(labelPort, 1, 0); - - sbPort = new QSpinBox(gb); - sbPort->setMinimum(0); - sbPort->setMaximum(65535); - gbLayout->addWidget(sbPort, 1, 1); - - BtnDefault = new QPushButton(gb); - BtnDefault->setText(QPushButton::tr("default")); - gbLayout->addWidget(BtnDefault, 1, 2); - - connect(BtnDefault, SIGNAL(clicked()), this, SLOT(setDefaultPort())); -} - -void PageNetServer::setDefaultPort() -{ - sbPort->setValue(46631); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenetserver.h --- a/QTfrontend/pagenetserver.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_NETSERVER_H -#define PAGE_NETSERVER_H - -#include "AbstractPage.h" - -class PageNetServer : public AbstractPage -{ - Q_OBJECT - -public: - PageNetServer(QWidget* parent = 0); - - QPushButton *BtnBack; - QPushButton *BtnStart; - QPushButton *BtnDefault; - QLabel *labelSD; - QLineEdit *leServerDescr; - QLabel *labelPort; - QSpinBox *sbPort; - -private slots: - void setDefaultPort(); -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenettype.cpp --- a/QTfrontend/pagenettype.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "pagenettype.h" - -PageNetType::PageNetType(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setRowStretch(0, 10); - pageLayout->setRowStretch(3, 10); - - pageLayout->setColumnStretch(1, 10); - pageLayout->setColumnStretch(2, 20); - pageLayout->setColumnStretch(3, 10); - - BtnLAN = addButton(tr("LAN game"), pageLayout, 1, 2); - BtnOfficialServer = addButton(tr("Official server"), pageLayout, 2, 2); - - // hack: temporary deactivated - requires server modifications that aren't backward compatible (yet) - //BtnOfficialServer->setEnabled(false); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 4, 0, true); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagenettype.h --- a/QTfrontend/pagenettype.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_NETTYPE_H -#define PAGE_NETTYPE_H - -#include "AbstractPage.h" - -class PageNetType : public AbstractPage -{ - Q_OBJECT - -public: - PageNetType(QWidget* parent = 0); - - QPushButton * BtnBack; - QPushButton * BtnLAN; - QPushButton * BtnOfficialServer; -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageoptions.cpp --- a/QTfrontend/pageoptions.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,437 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pageoptions.h" -#include "hwconsts.h" -#include "fpsedit.h" -#include "igbox.h" - -PageOptions::PageOptions(QWidget* parent) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 100); - pageLayout->setColumnStretch(1, 100); - pageLayout->setColumnStretch(2, 100); - pageLayout->setRowStretch(0, 0); - //pageLayout->setRowStretch(1, 100); - pageLayout->setRowStretch(2, 0); - pageLayout->setContentsMargins(7, 7, 7, 0); - pageLayout->setSpacing(0); - - - QGroupBox * gbTwoBoxes = new QGroupBox(this); - pageLayout->addWidget(gbTwoBoxes, 0, 0, 1, 3); - QGridLayout * gbTBLayout = new QGridLayout(gbTwoBoxes); - gbTBLayout->setMargin(0); - gbTBLayout->setSpacing(0); - gbTBLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); - - QPixmap pmNew(":/res/new.png"); - QPixmap pmEdit(":/res/edit.png"); - QPixmap pmDelete(":/res/delete.png"); - - { - teamsBox = new IconedGroupBox(this); - //teamsBox->setContentTopPadding(0); - //teamsBox->setAttribute(Qt::WA_PaintOnScreen, true); - teamsBox->setIcon(QIcon(":/res/teamicon.png")); - teamsBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - teamsBox->setTitle(QGroupBox::tr("Teams")); - - QGridLayout * GBTlayout = new QGridLayout(teamsBox); - - CBTeamName = new QComboBox(teamsBox); - GBTlayout->addWidget(CBTeamName, 0, 0); - - BtnNewTeam = new QPushButton(teamsBox); - BtnNewTeam->setToolTip(tr("New team")); - BtnNewTeam->setIconSize(pmNew.size()); - BtnNewTeam->setIcon(pmNew); - BtnNewTeam->setMaximumWidth(pmNew.width() + 6); - GBTlayout->addWidget(BtnNewTeam, 0, 1); - - BtnEditTeam = new QPushButton(teamsBox); - BtnEditTeam->setToolTip(tr("Edit team")); - BtnEditTeam->setIconSize(pmEdit.size()); - BtnEditTeam->setIcon(pmEdit); - BtnEditTeam->setMaximumWidth(pmEdit.width() + 6); - GBTlayout->addWidget(BtnEditTeam, 0, 2); - - BtnDeleteTeam = new QPushButton(teamsBox); - BtnDeleteTeam->setToolTip(tr("Delete team")); - BtnDeleteTeam->setIconSize(pmDelete.size()); - BtnDeleteTeam->setIcon(pmDelete); - BtnDeleteTeam->setMaximumWidth(pmDelete.width() + 6); - GBTlayout->addWidget(BtnDeleteTeam, 0, 3); - - LblNoEditTeam = new QLabel(teamsBox); - LblNoEditTeam->setText(tr("You can't edit teams from team selection. Go back to main menu to add, edit or delete teams.")); - LblNoEditTeam->setWordWrap(true); - LblNoEditTeam->setVisible(false); - GBTlayout->addWidget(LblNoEditTeam, 0, 0); - - gbTBLayout->addWidget(teamsBox, 0, 0); - } - - { - IconedGroupBox* groupWeapons = new IconedGroupBox(this); - - //groupWeapons->setContentTopPadding(0); - //groupWeapons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - groupWeapons->setIcon(QIcon(":/res/weaponsicon.png")); - groupWeapons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - groupWeapons->setTitle(QGroupBox::tr("Schemes and Weapons")); - QGridLayout * WeaponsLayout = new QGridLayout(groupWeapons); - - QLabel* SchemeLabel = new QLabel(groupWeapons); - SchemeLabel->setText(QLabel::tr("Game scheme")); - WeaponsLayout->addWidget(SchemeLabel, 1, 0); - - SchemesName = new QComboBox(groupWeapons); - WeaponsLayout->addWidget(SchemesName, 1, 1); - - SchemeNew = new QPushButton(groupWeapons); - SchemeNew->setToolTip(tr("New scheme")); - SchemeNew->setIconSize(pmNew.size()); - SchemeNew->setIcon(pmNew); - SchemeNew->setMaximumWidth(pmNew.width() + 6); - WeaponsLayout->addWidget(SchemeNew, 1, 2); - - SchemeEdit = new QPushButton(groupWeapons); - SchemeEdit->setToolTip(tr("Edit scheme")); - SchemeEdit->setIconSize(pmEdit.size()); - SchemeEdit->setIcon(pmEdit); - SchemeEdit->setMaximumWidth(pmEdit.width() + 6); - WeaponsLayout->addWidget(SchemeEdit, 1, 3); - - SchemeDelete = new QPushButton(groupWeapons); - SchemeDelete->setToolTip(tr("Delete scheme")); - SchemeDelete->setIconSize(pmDelete.size()); - SchemeDelete->setIcon(pmDelete); - SchemeDelete->setMaximumWidth(pmDelete.width() + 6); - WeaponsLayout->addWidget(SchemeDelete, 1, 4); - - QLabel* WeaponLabel = new QLabel(groupWeapons); - WeaponLabel->setText(QLabel::tr("Weapons")); - WeaponsLayout->addWidget(WeaponLabel, 2, 0); - - WeaponsName = new QComboBox(groupWeapons); - WeaponsLayout->addWidget(WeaponsName, 2, 1); - - WeaponNew = new QPushButton(groupWeapons); - WeaponNew->setToolTip(tr("New weapon set")); - WeaponNew->setIconSize(pmNew.size()); - WeaponNew->setIcon(pmNew); - WeaponNew->setMaximumWidth(pmNew.width() + 6); - WeaponsLayout->addWidget(WeaponNew, 2, 2); - - WeaponEdit = new QPushButton(groupWeapons); - WeaponEdit->setToolTip(tr("Edit weapon set")); - WeaponEdit->setIconSize(pmEdit.size()); - WeaponEdit->setIcon(pmEdit); - WeaponEdit->setMaximumWidth(pmEdit.width() + 6); - WeaponsLayout->addWidget(WeaponEdit, 2, 3); - - WeaponDelete = new QPushButton(groupWeapons); - WeaponDelete->setToolTip(tr("Delete weapon set")); - WeaponDelete->setIconSize(pmDelete.size()); - WeaponDelete->setIcon(pmDelete); - WeaponDelete->setMaximumWidth(pmDelete.width() + 6); - WeaponsLayout->addWidget(WeaponDelete, 2, 4); - - WeaponTooltip = new QCheckBox(this); - WeaponTooltip->setText(QCheckBox::tr("Show ammo menu tooltips")); - WeaponsLayout->addWidget(WeaponTooltip, 3, 0, 1, 4); - - gbTBLayout->addWidget(groupWeapons, 1, 0); - } - - { - IconedGroupBox* groupMisc = new IconedGroupBox(this); - //groupMisc->setContentTopPadding(0); - groupMisc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - groupMisc->setIcon(QIcon(":/res/miscicon.png")); - //groupMisc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - groupMisc->setTitle(QGroupBox::tr("Misc")); - QGridLayout * MiscLayout = new QGridLayout(groupMisc); - - labelNN = new QLabel(groupMisc); - labelNN->setText(QLabel::tr("Net nick")); - MiscLayout->addWidget(labelNN, 0, 0); - - editNetNick = new QLineEdit(groupMisc); - editNetNick->setMaxLength(20); - editNetNick->setText(QLineEdit::tr("unnamed")); - connect(editNetNick, SIGNAL(editingFinished()), this, SLOT(trimNetNick())); - MiscLayout->addWidget(editNetNick, 0, 1); - - labelNetPassword = new QLabel(groupMisc); - labelNetPassword->setText(QLabel::tr("Password")); - MiscLayout->addWidget(labelNetPassword, 1, 0); - - editNetPassword = new QLineEdit(groupMisc); - editNetPassword->setEchoMode(QLineEdit::Password); - MiscLayout->addWidget(editNetPassword, 1, 1); - - QLabel *labelLanguage = new QLabel(groupMisc); - labelLanguage->setText(QLabel::tr("Locale") + " *"); - MiscLayout->addWidget(labelLanguage, 2, 0); - - CBLanguage = new QComboBox(groupMisc); - QDir tmpdir; - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data/Locale"); - tmpdir.setFilter(QDir::Files); - QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm")); - CBLanguage->addItem(QComboBox::tr("(System default)"), QString("")); - for(int i = 0; i < locs.count(); i++) - { - QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1")); - CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); - } - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Locale"); - tmpdir.setFilter(QDir::Files); - QStringList tmplist = tmpdir.entryList(QStringList("hedgewars_*.qm")); - for(int i = 0; i < tmplist.count(); i++) - { - if (locs.contains(tmplist[i])) continue; - QLocale loc(tmplist[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1")); - CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); - } - - MiscLayout->addWidget(CBLanguage, 2, 1); - - CBAltDamage = new QCheckBox(groupMisc); - CBAltDamage->setText(QCheckBox::tr("Alternative damage show")); - MiscLayout->addWidget(CBAltDamage, 3, 0, 1, 2); - - CBNameWithDate = new QCheckBox(groupMisc); - CBNameWithDate->setText(QCheckBox::tr("Append date and time to record file name")); - MiscLayout->addWidget(CBNameWithDate, 4, 0, 1, 2); - - BtnAssociateFiles = new QPushButton(groupMisc); - BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions")); - BtnAssociateFiles->setEnabled(!custom_data && !custom_config); - MiscLayout->addWidget(BtnAssociateFiles, 5, 0, 1, 2); - -#ifdef __APPLE__ -#ifdef SPARKLE_ENABLED - CBAutoUpdate = new QCheckBox(groupMisc); - CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup")); - MiscLayout->addWidget(CBAutoUpdate, 6, 0, 1, 3); -#endif -#endif - gbTBLayout->addWidget(groupMisc, 2, 0); - } - - { - AGGroupBox = new IconedGroupBox(this); - //AGGroupBox->setContentTopPadding(0); - AGGroupBox->setIcon(QIcon(":/res/graphicsicon.png")); - //AGGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options")); - - QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox); - QHBoxLayout * GBAreslayout = new QHBoxLayout(0); - QHBoxLayout * GBAstereolayout = new QHBoxLayout(0); - QHBoxLayout * GBAqualayout = new QHBoxLayout(0); - - CBFrontendFullscreen = new QCheckBox(AGGroupBox); - CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen")); - GBAlayout->addWidget(CBFrontendFullscreen); - - CBFrontendEffects = new QCheckBox(AGGroupBox); - CBFrontendEffects->setText(QCheckBox::tr("Frontend effects") + " *"); - GBAlayout->addWidget(CBFrontendEffects); - - CBEnableFrontendSound = new QCheckBox(AGGroupBox); - CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds")); - GBAlayout->addWidget(CBEnableFrontendSound); - - CBEnableFrontendMusic = new QCheckBox(AGGroupBox); - CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music")); - GBAlayout->addWidget(CBEnableFrontendMusic); - - QFrame * hr = new QFrame(AGGroupBox); - hr->setFrameStyle(QFrame::HLine); - hr->setLineWidth(3); - hr->setFixedHeight(10); - GBAlayout->addWidget(hr); - - QLabel * resolution = new QLabel(AGGroupBox); - resolution->setText(QLabel::tr("Resolution")); - GBAreslayout->addWidget(resolution); - - CBResolution = new QComboBox(AGGroupBox); - GBAreslayout->addWidget(CBResolution); - GBAlayout->addLayout(GBAreslayout); - - CBFullscreen = new QCheckBox(AGGroupBox); - CBFullscreen->setText(QCheckBox::tr("Fullscreen")); - GBAlayout->addWidget(CBFullscreen); - connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(void))); - - QLabel * quality = new QLabel(AGGroupBox); - quality->setText(QLabel::tr("Quality")); - quality->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - GBAqualayout->addWidget(quality); - - SLQuality = new QSlider(Qt::Horizontal, AGGroupBox); - SLQuality->setTickPosition(QSlider::TicksBelow); - SLQuality->setMaximum(5); - SLQuality->setMinimum(0); - SLQuality->setFixedWidth(150); - GBAqualayout->addWidget(SLQuality); - GBAlayout->addLayout(GBAqualayout); - QLabel * stereo = new QLabel(AGGroupBox); - stereo->setText(QLabel::tr("Stereo rendering")); - GBAstereolayout->addWidget(stereo); - - CBStereoMode = new QComboBox(AGGroupBox); - CBStereoMode->addItem(QComboBox::tr("Disabled")); - CBStereoMode->addItem(QComboBox::tr("Red/Cyan")); - CBStereoMode->addItem(QComboBox::tr("Cyan/Red")); - CBStereoMode->addItem(QComboBox::tr("Red/Blue")); - CBStereoMode->addItem(QComboBox::tr("Blue/Red")); - CBStereoMode->addItem(QComboBox::tr("Red/Green")); - CBStereoMode->addItem(QComboBox::tr("Green/Red")); - CBStereoMode->addItem(QComboBox::tr("Side-by-side")); - CBStereoMode->addItem(QComboBox::tr("Top-Bottom")); - CBStereoMode->addItem(QComboBox::tr("Wiggle")); - CBStereoMode->addItem(QComboBox::tr("Red/Cyan grayscale")); - CBStereoMode->addItem(QComboBox::tr("Cyan/Red grayscale")); - CBStereoMode->addItem(QComboBox::tr("Red/Blue grayscale")); - CBStereoMode->addItem(QComboBox::tr("Blue/Red grayscale")); - CBStereoMode->addItem(QComboBox::tr("Red/Green grayscale")); - CBStereoMode->addItem(QComboBox::tr("Green/Red grayscale")); - connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int))); - - GBAstereolayout->addWidget(CBStereoMode); - GBAlayout->addLayout(GBAstereolayout); - - hr = new QFrame(AGGroupBox); - hr->setFrameStyle(QFrame::HLine); - hr->setLineWidth(3); - hr->setFixedHeight(10); - GBAlayout->addWidget(hr); - - QHBoxLayout * GBAvollayout = new QHBoxLayout(0); - QLabel * vol = new QLabel(AGGroupBox); - vol->setText(QLabel::tr("Initial sound volume")); - GBAvollayout->addWidget(vol); - GBAlayout->addLayout(GBAvollayout); - volumeBox = new QSpinBox(AGGroupBox); - volumeBox->setRange(0, 100); - volumeBox->setSingleStep(5); - GBAvollayout->addWidget(volumeBox); - - CBEnableSound = new QCheckBox(AGGroupBox); - CBEnableSound->setText(QCheckBox::tr("Enable sound")); - GBAlayout->addWidget(CBEnableSound); - - CBEnableMusic = new QCheckBox(AGGroupBox); - CBEnableMusic->setText(QCheckBox::tr("Enable music")); - GBAlayout->addWidget(CBEnableMusic); - - hr = new QFrame(AGGroupBox); - hr->setFrameStyle(QFrame::HLine); - hr->setLineWidth(3); - hr->setFixedHeight(10); - GBAlayout->addWidget(hr); - - QHBoxLayout * GBAfpslayout = new QHBoxLayout(0); - QLabel * maxfps = new QLabel(AGGroupBox); - maxfps->setText(QLabel::tr("FPS limit")); - GBAfpslayout->addWidget(maxfps); - GBAlayout->addLayout(GBAfpslayout); - fpsedit = new FPSEdit(AGGroupBox); - GBAfpslayout->addWidget(fpsedit); - - CBShowFPS = new QCheckBox(AGGroupBox); - CBShowFPS->setText(QCheckBox::tr("Show FPS")); - GBAlayout->addWidget(CBShowFPS); - - hr = new QFrame(AGGroupBox); - hr->setFrameStyle(QFrame::HLine); - hr->setLineWidth(3); - hr->setFixedHeight(10); - GBAlayout->addWidget(hr); - - QLabel *restartNote = new QLabel(this); - restartNote->setText(QString("* ") + QLabel::tr("Restart game to apply")); - restartNote->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - GBAlayout->addWidget(restartNote); - - gbTBLayout->addWidget(AGGroupBox, 0, 1, 3, 1); - } - - BtnSaveOptions = addButton(":/res/Save.png", pageLayout, 2, 2, true); - BtnSaveOptions->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); - BtnBack->setFixedHeight(BtnSaveOptions->height()); - BtnBack->setFixedWidth(BtnBack->width()+2); - BtnBack->setStyleSheet("QPushButton{margin: 22px 0 9px 2px;}"); -} - -void PageOptions::forceFullscreen(int index) -{ - if (index != 0) { - previousFullscreenValue = this->CBFullscreen->isChecked(); - this->CBFullscreen->setChecked(true); - this->CBFullscreen->setEnabled(false); - previousQuality = this->SLQuality->value(); - this->SLQuality->setValue(this->SLQuality->maximum()); - this->SLQuality->setEnabled(false); - } else { - this->CBFullscreen->setChecked(previousFullscreenValue); - this->CBFullscreen->setEnabled(true); - this->SLQuality->setValue(previousQuality); - this->SLQuality->setEnabled(true); - } -} - -void PageOptions::setFullscreen(void) -{ - int tmp = this->CBResolution->currentIndex(); - if (this->CBFullscreen->isChecked()) - this->CBResolution->setCurrentIndex(0); - else - this->CBResolution->setCurrentIndex(previousResolutionIndex); - previousResolutionIndex = tmp; -} - -void PageOptions::trimNetNick() -{ - editNetNick->setText(editNetNick->text().trimmed()); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageoptions.h --- a/QTfrontend/pageoptions.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_OPTIONS_H -#define PAGE_OPTIONS_H - -#include "AbstractPage.h" - -class FPSEdit; -class IconedGroupBox; - -class PageOptions : public AbstractPage -{ - Q_OBJECT - -public: - PageOptions(QWidget* parent = 0); - - QCheckBox *WeaponTooltip; - QPushButton *WeaponNew; - QPushButton *WeaponEdit; - QPushButton *WeaponDelete; - QComboBox *WeaponsName; - QPushButton *SchemeNew; - QPushButton *SchemeEdit; - QPushButton *SchemeDelete; - QComboBox *SchemesName; - - QComboBox *CBLanguage; - - QPushButton *BtnBack; - IconedGroupBox *teamsBox; - QPushButton *BtnNewTeam; - QPushButton *BtnEditTeam; - QPushButton *BtnDeleteTeam; - QPushButton *BtnAssociateFiles; - QLabel *LblNoEditTeam; - QComboBox *CBTeamName; - IconedGroupBox *AGGroupBox; - QComboBox *CBResolution; - QComboBox *CBStereoMode; - QCheckBox *CBEnableSound; - QCheckBox *CBEnableFrontendSound; - QCheckBox *CBEnableMusic; - QCheckBox *CBEnableFrontendMusic; - QCheckBox *CBFullscreen; - QCheckBox *CBFrontendFullscreen; - QCheckBox *CBShowFPS; - QCheckBox *CBAltDamage; - QCheckBox *CBNameWithDate; -#ifdef __APPLE__ - QCheckBox *CBAutoUpdate; -#endif - - FPSEdit *fpsedit; - QPushButton *BtnSaveOptions; - QLabel *labelNN; - QLabel *labelNetPassword; - QSpinBox * volumeBox; - QLineEdit *editNetNick; - QLineEdit *editNetPassword; - QSlider *SLQuality; - QCheckBox *CBFrontendEffects; - -private: - bool previousFullscreenValue; - int previousResolutionIndex; - int previousQuality; - -private slots: - void forceFullscreen(int index); - void setFullscreen(void); - void trimNetNick(); -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageplayrecord.cpp --- a/QTfrontend/pageplayrecord.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hwconsts.h" -#include "pageplayrecord.h" - -PagePlayDemo::PagePlayDemo(QWidget* parent) : AbstractPage(parent) -{ - QFont * font14 = new QFont("MS Shell Dlg", 14); - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 2); - pageLayout->setColumnStretch(2, 1); - pageLayout->setRowStretch(2, 100); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); - - BtnPlayDemo = new QPushButton(this); - BtnPlayDemo->setFont(*font14); - BtnPlayDemo->setText(QPushButton::tr("Play demo")); - pageLayout->addWidget(BtnPlayDemo, 3, 2); - - BtnRenameRecord = new QPushButton(this); - BtnRenameRecord->setText(QPushButton::tr("Rename")); - pageLayout->addWidget(BtnRenameRecord, 0, 2); - - BtnRemoveRecord = new QPushButton(this); - BtnRemoveRecord->setText(QPushButton::tr("Delete")); - pageLayout->addWidget(BtnRemoveRecord, 1, 2); - - DemosList = new QListWidget(this); - DemosList->setGeometry(QRect(170, 10, 311, 311)); - pageLayout->addWidget(DemosList, 0, 1, 3, 1); - - connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord())); - connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord())); -} - -void PagePlayDemo::FillFromDir(RecordType rectype) -{ - QDir dir; - QString extension; - - recType = rectype; - - dir.cd(cfgdir->absolutePath()); - if (rectype == RT_Demo) - { - dir.cd("Demos"); - extension = "hwd"; - BtnPlayDemo->setText(QPushButton::tr("Play demo")); - } else - { - dir.cd("Saves"); - extension = "hws"; - BtnPlayDemo->setText(QPushButton::tr("Load")); - } - dir.setFilter(QDir::Files); - - QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer))); - sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1"); - - DemosList->clear(); - DemosList->addItems(sl); - - for (int i = 0; i < DemosList->count(); ++i) - { - DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer))); - DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png")); - } -} - -void PagePlayDemo::renameRecord() -{ - QListWidgetItem * curritem = DemosList->currentItem(); - if (!curritem) - { - QMessageBox::critical(this, - tr("Error"), - tr("Please select record from the list"), - tr("OK")); - return ; - } - QFile rfile(curritem->data(Qt::UserRole).toString()); - - QFileInfo finfo(rfile); - - bool ok; - - QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok); - - if(ok && newname.size()) - { - QString newfullname = QString("%1/%2.%3.%4") - .arg(finfo.absolutePath()) - .arg(newname) - .arg(*cProtoVer) - .arg(finfo.suffix()); - - ok = rfile.rename(newfullname); - if(!ok) - QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname); - else - FillFromDir(recType); - } -} - -void PagePlayDemo::removeRecord() -{ - QListWidgetItem * curritem = DemosList->currentItem(); - if (!curritem) - { - QMessageBox::critical(this, - tr("Error"), - tr("Please select record from the list"), - tr("OK")); - return ; - } - QFile rfile(curritem->data(Qt::UserRole).toString()); - - bool ok; - - ok = rfile.remove(); - if(!ok) - QMessageBox::critical(this, tr("Error"), tr("Cannot delete file")); - else - FillFromDir(recType); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageplayrecord.h --- a/QTfrontend/pageplayrecord.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PLAYRECORDPAGE_H -#define PLAYRECORDPAGE_H - -#include - -#include "AbstractPage.h" - -class QPushButton; -class QListWidget; - -class PagePlayDemo : public AbstractPage -{ - Q_OBJECT - -public: - enum RecordType { - RT_Demo, - RT_Save - }; - - PagePlayDemo(QWidget* parent = 0); - - void FillFromDir(RecordType rectype); - - QPushButton *BtnBack; - QPushButton *BtnPlayDemo; - QPushButton *BtnRenameRecord; - QPushButton *BtnRemoveRecord; - QListWidget *DemosList; - -private: - RecordType recType; - -private slots: - void renameRecord(); - void removeRecord(); -}; - - -#endif // PLAYRECORDPAGE_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageroomslist.cpp --- a/QTfrontend/pageroomslist.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,396 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ammoSchemeModel.h" -#include "pageroomslist.h" -#include "hwconsts.h" -#include "chatwidget.h" - -PageRoomsList::PageRoomsList(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - - QHBoxLayout * newRoomLayout = new QHBoxLayout(); - QLabel * roomNameLabel = new QLabel(this); - roomNameLabel->setText(tr("Room Name:")); - roomName = new QLineEdit(this); - roomName->setMaxLength(60); - newRoomLayout->addWidget(roomNameLabel); - newRoomLayout->addWidget(roomName); - pageLayout->addLayout(newRoomLayout, 0, 0, 1, 2); - - roomsList = new QTableWidget(this); - roomsList->setSelectionBehavior(QAbstractItemView::SelectRows); - roomsList->verticalHeader()->setVisible(false); - roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive); - roomsList->setAlternatingRowColors(true); - roomsList->setShowGrid(false); - roomsList->setSelectionMode(QAbstractItemView::SingleSelection); - pageLayout->addWidget(roomsList, 1, 0, 3, 2); - pageLayout->setRowStretch(2, 100); - - QHBoxLayout * filterLayout = new QHBoxLayout(); - - QLabel * stateLabel = new QLabel(this); - stateLabel->setText(tr("State:")); - CBState = new QComboBox(this); - CBState->addItem(QComboBox::tr("Any")); - CBState->addItem(QComboBox::tr("In lobby")); - CBState->addItem(QComboBox::tr("In progress")); - filterLayout->addWidget(stateLabel); - filterLayout->addWidget(CBState); - filterLayout->addSpacing(30); - - QLabel * ruleLabel = new QLabel(this); - ruleLabel->setText(tr("Rules:")); - CBRules = new QComboBox(this); - CBRules->addItem(QComboBox::tr("Any")); - // not the most elegant solution but it works - ammoSchemeModel = new AmmoSchemeModel(this, NULL); - for (int i = 0; i < ammoSchemeModel->predefSchemesNames.count(); i++) - CBRules->addItem(ammoSchemeModel->predefSchemesNames.at(i).toAscii().constData()); - filterLayout->addWidget(ruleLabel); - filterLayout->addWidget(CBRules); - filterLayout->addSpacing(30); - - QLabel * weaponLabel = new QLabel(this); - weaponLabel->setText(tr("Weapons:")); - CBWeapons = new QComboBox(this); - CBWeapons->addItem(QComboBox::tr("Any")); - for (int i = 0; i < cDefaultAmmos.count(); i++) { - QPair ammo = cDefaultAmmos.at(i); - CBWeapons->addItem(ammo.first.toAscii().constData()); - } - filterLayout->addWidget(weaponLabel); - filterLayout->addWidget(CBWeapons); - filterLayout->addSpacing(30); - - QLabel * searchLabel = new QLabel(this); - searchLabel->setText(tr("Search:")); - searchText = new QLineEdit(this); - searchText->setMaxLength(60); - filterLayout->addWidget(searchLabel); - filterLayout->addWidget(searchText); - - pageLayout->addLayout(filterLayout, 4, 0, 1, 2); - - chatWidget = new HWChatWidget(this, gameSettings, sdli, false); - pageLayout->addWidget(chatWidget, 5, 0, 1, 3); - pageLayout->setRowStretch(5, 350); - - BtnCreate = addButton(tr("Create"), pageLayout, 0, 2); - BtnJoin = addButton(tr("Join"), pageLayout, 1, 2); - BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 2); - BtnClear = addButton(tr("Clear"), pageLayout, 4, 2); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 6, 0, true); - - lblCount = new QLabel(this); - pageLayout->addWidget(lblCount, 6, 1, Qt::AlignHCenter); - lblCount->setText("?"); - lblCount->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - - connect(chatWidget, SIGNAL(nickCountUpdate(const int)), this, SLOT(updateNickCounter(const int))); - - BtnAdmin = addButton(tr("Admin features"), pageLayout, 6, 2); - - connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick())); - connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick())); - connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick())); - connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick())); - connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); - connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); - connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); - connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); - connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick())); - connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); - - gameInLobby = false; -} - -void PageRoomsList::setAdmin(bool flag) -{ - BtnAdmin->setVisible(flag); -} - -void PageRoomsList::setRoomsList(const QStringList & list) -{ - QBrush red(QColor(255, 0, 0)); - QBrush orange(QColor(127, 127, 0)); - QBrush yellow(QColor(255, 255, 0)); - QBrush green(QColor(0, 255, 0)); - - listFromServer = list; - - QString selection = ""; - - if(QTableWidgetItem *item = roomsList->item(roomsList->currentRow(), 0)) - selection = item->text(); - - roomsList->clear(); - roomsList->setColumnCount(7); - roomsList->setHorizontalHeaderLabels( - QStringList() << - QTableWidget::tr("Room Name") << - QTableWidget::tr("C") << - QTableWidget::tr("T") << - QTableWidget::tr("Owner") << - QTableWidget::tr("Map") << - QTableWidget::tr("Rules") << - QTableWidget::tr("Weapons") - ); - - // set minimum sizes -// roomsList->horizontalHeader()->resizeSection(0, 200); -// roomsList->horizontalHeader()->resizeSection(1, 50); -// roomsList->horizontalHeader()->resizeSection(2, 50); -// roomsList->horizontalHeader()->resizeSection(3, 100); -// roomsList->horizontalHeader()->resizeSection(4, 100); -// roomsList->horizontalHeader()->resizeSection(5, 100); -// roomsList->horizontalHeader()->resizeSection(6, 100); - - // set resize modes -// roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive); - - bool gameCanBeJoined = true; - - if (list.size() % 8) - return; - - roomsList->setRowCount(list.size() / 8); - for(int i = 0, r = 0; i < list.size(); i += 8, r++) - { - // if we are joining a game - // TODO: Should NOT be done here - if (gameInLobby) { - if (gameInLobbyName == list[i + 1]) { - gameCanBeJoined = list[i].compare("True"); - } - } - - // check filter settings - #define NO_FILTER_MATCH roomsList->setRowCount(roomsList->rowCount() - 1); --r; continue - - if (list[i].compare("True") && CBState->currentIndex() == 2) { NO_FILTER_MATCH; } - if (list[i].compare("False") && CBState->currentIndex() == 1) { NO_FILTER_MATCH; } - if (CBRules->currentIndex() != 0 && list[i + 6].compare(CBRules->currentText())) { NO_FILTER_MATCH; } - if (CBWeapons->currentIndex() != 0 && list[i + 7].compare(CBWeapons->currentText())) { NO_FILTER_MATCH; } - bool found = list[i + 1].contains(searchText->text(), Qt::CaseInsensitive); - if (!found) { - for (int a = 4; a <= 7; ++a) { - QString compString = list[i + a]; - if (a == 5 && compString == "+rnd+") { - compString = "Random Map"; - } else if (a == 5 && compString == "+maze+") { - compString = "Random Maze"; - } else if (a == 5 && compString == "+drawn+") { - compString = "Drawn Map"; - } - if (compString.contains(searchText->text(), Qt::CaseInsensitive)) { - found = true; - break; - } - } - } - if (!searchText->text().isEmpty() && !found) { NO_FILTER_MATCH; } - - QTableWidgetItem * item; - item = new QTableWidgetItem(list[i + 1]); // room name - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - - // pick appropriate room icon and tooltip (game in progress yes/no; later maybe locked rooms etc.) - if(list[i].compare("True")) - { - item->setIcon(QIcon(":/res/iconTime.png"));// game is in lobby - item->setToolTip(tr("This game is in lobby.\nYou may join and start playing once the game starts.")); - } - else - { - item->setIcon(QIcon(":/res/iconDamage.png"));// game has started - item->setToolTip(tr("This game is in progress.\nYou may join and spectate now but you'll have to wait for the game to end to start playing.")); - } - - roomsList->setItem(r, 0, item); - - item = new QTableWidgetItem(list[i + 2]); // number of clients - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setTextAlignment(Qt::AlignCenter); - item->setToolTip(tr("There are %1 clients connected to this room.", "", list[i + 2].toInt()).arg(list[i + 2])); - roomsList->setItem(r, 1, item); - - item = new QTableWidgetItem(list[i + 3]); // number of teams - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setTextAlignment(Qt::AlignCenter); - item->setToolTip(tr("There are %1 teams participating in this room.", "", list[i + 3].toInt()).arg(list[i + 3])); - //Should we highlight "full" games? Might get misinterpreted - //if(list[i + 3].toInt() >= cMaxTeams) - // item->setForeground(red); - roomsList->setItem(r, 2, item); - - item = new QTableWidgetItem(list[i + 4].left(15)); // name of host - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setToolTip(tr("%1 is the host. He may adjust settings and start the game.").arg(list[i + 4])); - roomsList->setItem(r, 3, item); - - if(list[i + 5] == "+rnd+") - { - item = new QTableWidgetItem(tr("Random Map")); // selected map (is randomized) -// FIXME - need real icons. Disabling until then -// item->setIcon(QIcon(":/res/mapRandom.png")); - } - else if (list[i+5] == "+maze+") - { - item = new QTableWidgetItem(tr("Random Maze")); -// FIXME - need real icons. Disabling until then -// item->setIcon(QIcon(":/res/mapMaze.png")); - } - else - { - item = new QTableWidgetItem(list[i + 5]); // selected map - - // check to see if we've got this map - // not perfect but a start - if(!mapList->contains(list[i + 5])) - { - item->setForeground(red); - item->setIcon(QIcon(":/res/mapMissing.png")); - } - else - { - // todo: mission icon? -// FIXME - need real icons. Disabling until then -// item->setIcon(QIcon(":/res/mapCustom.png")); - } - } - - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setToolTip(tr("Games may be played on precreated or randomized maps.")); - roomsList->setItem(r, 4, item); - - item = new QTableWidgetItem(list[i + 6].left(24)); // selected game scheme - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setToolTip(tr("The Game Scheme defines general options and preferences like Round Time, Sudden Death or Vampirism.")); - roomsList->setItem(r, 5, item); - - item = new QTableWidgetItem(list[i + 7].left(24)); // selected weapon scheme - item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - item->setToolTip(tr("The Weapon Scheme defines available weapons and their ammunition count.")); - roomsList->setItem(r, 6, item); - - if(!list[i + 1].compare(selection) && !selection.isEmpty()) - roomsList->selectionModel()->setCurrentIndex(roomsList->model()->index(r, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); - } - - roomsList->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); - roomsList->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); - roomsList->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents); - roomsList->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents); - roomsList->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents); - roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents); - roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents); - - // TODO: Should NOT be done here - if (gameInLobby) { - gameInLobby = false; - if (gameCanBeJoined) { - emit askForJoinRoom(gameInLobbyName); - } else { - emit askJoinConfirmation(gameInLobbyName); - } - } - -// roomsList->resizeColumnsToContents(); -} - -void PageRoomsList::onCreateClick() -{ - if (roomName->text().size()) - emit askForCreateRoom(roomName->text()); - else - QMessageBox::critical(this, - tr("Error"), - tr("Please enter room name"), - tr("OK")); -} - -void PageRoomsList::onJoinClick() -{ - QTableWidgetItem * curritem = roomsList->item(roomsList->currentRow(), 0); - if (!curritem) - { - QMessageBox::critical(this, - tr("Error"), - tr("Please select room from the list"), - tr("OK")); - return; - } - - for (int i = 0; i < listFromServer.size(); i += 8) { - if (listFromServer[i + 1] == curritem->data(Qt::DisplayRole).toString()) { - gameInLobby = listFromServer[i].compare("True"); - break; - } - } - - if (gameInLobby) { - gameInLobbyName = curritem->data(Qt::DisplayRole).toString(); - emit askForRoomList(); - } else { - emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString()); - } -} - -void PageRoomsList::onRefreshClick() -{ - emit askForRoomList(); -} - -void PageRoomsList::onClearClick() -{ - CBState->setCurrentIndex(0); - CBRules->setCurrentIndex(0); - CBWeapons->setCurrentIndex(0); - searchText->clear(); -} - -void PageRoomsList::onJoinConfirmation(const QString & room) -{ - if (QMessageBox::warning(this, - tr("Warning"), - tr("The game you are trying to join has started.\nDo you still want to join the room?"), - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) - { - emit askForJoinRoom(room); - } -} - -void PageRoomsList::updateNickCounter(int cnt) -{ - lblCount->setText(tr("%1 players online", 0, cnt).arg(cnt)); -} - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageroomslist.h --- a/QTfrontend/pageroomslist.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_ROOMLIST_H -#define PAGE_ROOMLIST_H - -#include "AbstractPage.h" -#include "SDLs.h" - -class HWChatWidget; -class AmmoSchemeModel; - -class PageRoomsList : public AbstractPage -{ - Q_OBJECT - -public: - PageRoomsList(QWidget* parent, QSettings * config, SDLInteraction * sdli); - - QLineEdit * roomName; - QLineEdit * searchText; - QTableWidget * roomsList; - QPushButton * BtnBack; - QPushButton * BtnCreate; - QPushButton * BtnJoin; - QPushButton * BtnRefresh; - QPushButton * BtnAdmin; - QPushButton * BtnClear; - QComboBox * CBState; - QComboBox * CBRules; - QComboBox * CBWeapons; - HWChatWidget * chatWidget; - QLabel * lblCount; - -private: - bool gameInLobby; - QString gameInLobbyName; - QStringList listFromServer; - AmmoSchemeModel * ammoSchemeModel; - -public slots: - void setRoomsList(const QStringList & list); - void setAdmin(bool); - void updateNickCounter(int cnt); - -private slots: - void onCreateClick(); - void onJoinClick(); - void onRefreshClick(); - void onClearClick(); - void onJoinConfirmation(const QString &); - -signals: - void askForCreateRoom(const QString &); - void askForJoinRoom(const QString &); - void askForRoomList(); - void askJoinConfirmation(const QString &); -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagescheme.cpp --- a/QTfrontend/pagescheme.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,488 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ammoSchemeModel.h" -#include "pagescheme.h" -#include "misc.h" - -PageScheme::PageScheme(QWidget* parent) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - QGroupBox * gb = new QGroupBox(this); - - QGridLayout * gl = new QGridLayout(); - gb->setLayout(gl); - QSizePolicy sp; - sp.setVerticalPolicy(QSizePolicy::MinimumExpanding); - sp.setHorizontalPolicy(QSizePolicy::Expanding); - - pageLayout->addWidget(gb, 1,0,13,5); - - gbGameModes = new QGroupBox(QGroupBox::tr("Game Modifiers"), gb); - gbBasicSettings = new QGroupBox(QGroupBox::tr("Basic Settings"), gb); - - gbGameModes->setStyleSheet(".QGroupBox {" - "background-color: #130f2c; background-image:url();" - "}"); - gbBasicSettings->setStyleSheet(".QGroupBox {" - "background-color: #130f2c; background-image:url();" - "}"); - - gbGameModes->setSizePolicy(sp); - gbBasicSettings->setSizePolicy(sp); - gl->addWidget(gbGameModes,0,0,1,3,Qt::AlignTop); - gl->addWidget(gbBasicSettings,0,3,1,3,Qt::AlignTop); - - QGridLayout * glGMLayout = new QGridLayout(gbGameModes); - QGridLayout * glBSLayout = new QGridLayout(gbBasicSettings); - gbGameModes->setLayout(glGMLayout); - gbBasicSettings->setLayout(glBSLayout); - // Left - - TBW_mode_Forts = new ToggleButtonWidget(gbGameModes, ":/res/btnForts.png"); - TBW_mode_Forts->setToolTip("" + ToggleButtonWidget::tr("Fort Mode") + ":
" + tr("Defend your fort and destroy the opponents, two team colours max!")); - glGMLayout->addWidget(TBW_mode_Forts,0,0,1,1); - - TBW_teamsDivide = new ToggleButtonWidget(gbGameModes, ":/res/btnTeamsDivide.png"); - TBW_teamsDivide->setToolTip("" + ToggleButtonWidget::tr("Divide Teams") + ":
" + tr("Teams will start on opposite sides of the terrain, two team colours max!")); - glGMLayout->addWidget(TBW_teamsDivide,0,1,1,1); - - TBW_solid = new ToggleButtonWidget(gbGameModes, ":/res/btnSolid.png"); - TBW_solid->setToolTip("" + ToggleButtonWidget::tr("Solid Land") + ":
" + tr("Land can not be destroyed!")); - glGMLayout->addWidget(TBW_solid,0,2,1,1); - - TBW_border = new ToggleButtonWidget(gbGameModes, ":/res/btnBorder.png"); - TBW_border->setToolTip("" + ToggleButtonWidget::tr("Add Border") + ":
" + tr("Add an indestructible border around the terrain")); - glGMLayout->addWidget(TBW_border,0,3,1,1); - - TBW_lowGravity = new ToggleButtonWidget(gbGameModes, ":/res/btnLowGravity.png"); - TBW_lowGravity->setToolTip("" + ToggleButtonWidget::tr("Low Gravity") + ":
" + tr("Lower gravity")); - glGMLayout->addWidget(TBW_lowGravity,0,4,1,1); - - TBW_laserSight = new ToggleButtonWidget(gbGameModes, ":/res/btnLaserSight.png"); - TBW_laserSight->setToolTip("" + ToggleButtonWidget::tr("Laser Sight") + ":
" + tr("Assisted aiming with laser sight")); - glGMLayout->addWidget(TBW_laserSight,1,0,1,1); - - TBW_invulnerable = new ToggleButtonWidget(gbGameModes, ":/res/btnInvulnerable.png"); - TBW_invulnerable->setToolTip("" + ToggleButtonWidget::tr("Invulnerable") + ":
" + tr("All hogs have a personal forcefield")); - glGMLayout->addWidget(TBW_invulnerable,1,1,1,1); - - TBW_resethealth = new ToggleButtonWidget(gbGameModes, ":/res/btnResetHealth.png"); - TBW_resethealth->setToolTip("" + ToggleButtonWidget::tr("Reset Health") + ":
" + tr("All (living) hedgehogs are fully restored at the end of turn")); - glGMLayout->addWidget(TBW_resethealth,1,2,1,1); - - TBW_vampiric = new ToggleButtonWidget(gbGameModes, ":/res/btnVampiric.png"); - TBW_vampiric->setToolTip("" + ToggleButtonWidget::tr("Vampirism") + ":
" + tr("Gain 80% of the damage you do back in health")); - glGMLayout->addWidget(TBW_vampiric,1,3,1,1); - - TBW_karma = new ToggleButtonWidget(gbGameModes, ":/res/btnKarma.png"); - TBW_karma->setToolTip("" + ToggleButtonWidget::tr("Karma") + ":
" + tr("Share your opponents pain, share their damage")); - glGMLayout->addWidget(TBW_karma,1,4,1,1); - - TBW_artillery = new ToggleButtonWidget(gbGameModes, ":/res/btnArtillery.png"); - TBW_artillery->setToolTip("" + ToggleButtonWidget::tr("Artillery") + ":
" + tr("Your hogs are unable to move, put your artillery skills to the test")); - glGMLayout->addWidget(TBW_artillery,2,0,1,1); - - TBW_randomorder = new ToggleButtonWidget(gbGameModes, ":/res/btnRandomOrder.png"); - TBW_randomorder->setToolTip("" + ToggleButtonWidget::tr("Random Order") + ":
" + tr("Order of play is random instead of in room order.")); - glGMLayout->addWidget(TBW_randomorder,2,1,1,1); - - TBW_king = new ToggleButtonWidget(gbGameModes, ":/res/btnKing.png"); - TBW_king->setToolTip("" + ToggleButtonWidget::tr("King") + ":
" + tr("Play with a King. If he dies, your side dies.")); - glGMLayout->addWidget(TBW_king,2,2,1,1); - - TBW_placehog = new ToggleButtonWidget(gbGameModes, ":/res/btnPlaceHog.png"); - TBW_placehog->setToolTip("" + ToggleButtonWidget::tr("Place Hedgehogs") + ":
" + tr("Take turns placing your hedgehogs before the start of play.")); - glGMLayout->addWidget(TBW_placehog,2,3,1,1); - - TBW_sharedammo = new ToggleButtonWidget(gbGameModes, ":/res/btnSharedAmmo.png"); - TBW_sharedammo->setToolTip("" + ToggleButtonWidget::tr("Clan Shares Ammo") + ":
" + tr("Ammo is shared between all teams that share a colour.")); - glGMLayout->addWidget(TBW_sharedammo,2,4,1,1); - - TBW_disablegirders = new ToggleButtonWidget(gbGameModes, ":/res/btnDisableGirders.png"); - TBW_disablegirders->setToolTip("" + ToggleButtonWidget::tr("Disable Girders") + ":
" + tr("Disable girders when generating random maps.")); - glGMLayout->addWidget(TBW_disablegirders,3,0,1,1); - - TBW_disablelandobjects = new ToggleButtonWidget(gbGameModes, ":/res/btnDisableLandObjects.png"); - TBW_disablelandobjects->setToolTip("" + ToggleButtonWidget::tr("Disable Land Objects") + ":
" + tr("Disable land objects when generating random maps.")); - glGMLayout->addWidget(TBW_disablelandobjects,3,1,1,1); - - TBW_aisurvival = new ToggleButtonWidget(gbGameModes, ":/res/btnAISurvival.png"); - TBW_aisurvival->setToolTip("" + ToggleButtonWidget::tr("AI Survival Mode") + ":
" + tr("AI respawns on death.")); - glGMLayout->addWidget(TBW_aisurvival,3,2,1,1); - - TBW_infattack = new ToggleButtonWidget(gbGameModes, ":/res/btnInfAttack.png"); - TBW_infattack->setToolTip("" + ToggleButtonWidget::tr("Unlimited Attacks") + ":
" + tr("Attacking does not end your turn.")); - glGMLayout->addWidget(TBW_infattack,3,3,1,1); - - TBW_resetweps = new ToggleButtonWidget(gbGameModes, ":/res/btnResetWeps.png"); - TBW_resetweps->setToolTip("" + ToggleButtonWidget::tr("Reset Weapons") + ":
" + tr("Weapons are reset to starting values each turn.")); - glGMLayout->addWidget(TBW_resetweps,3,4,1,1); - - TBW_perhogammo = new ToggleButtonWidget(gbGameModes, ":/res/btnPerHogAmmo.png"); - TBW_perhogammo->setToolTip("" + ToggleButtonWidget::tr("Per Hedgehog Ammo") + ":
" + tr("Each hedgehog has its own ammo. It does not share with the team.")); - glGMLayout->addWidget(TBW_perhogammo,4,0,1,1); - - TBW_nowind = new ToggleButtonWidget(gbGameModes, ":/res/btnNoWind.png"); - TBW_nowind->setToolTip("" + ToggleButtonWidget::tr("Disable Wind") + ":
" + tr("You will not have to worry about wind anymore.")); - glGMLayout->addWidget(TBW_nowind,4,1,1,1); - - TBW_morewind = new ToggleButtonWidget(gbGameModes, ":/res/btnMoreWind.png"); - TBW_morewind->setToolTip("" + ToggleButtonWidget::tr("More Wind") + ":
" + tr("Wind will affect almost everything.")); - glGMLayout->addWidget(TBW_morewind,4,2,1,1); - - TBW_tagteam = new ToggleButtonWidget(gbGameModes, ":/res/btnTagTeam.png"); - TBW_tagteam->setToolTip("" + ToggleButtonWidget::tr("Tag Team") + ":
" + tr("Teams in each clan take successive turns sharing their turn time.")); - glGMLayout->addWidget(TBW_tagteam,4,3,1,1); - - TBW_bottomborder = new ToggleButtonWidget(gbGameModes, ":/res/btnBottomBorder.png"); - TBW_bottomborder->setToolTip("" + ToggleButtonWidget::tr("Add Bottom Border") + ":
" + tr("Add an indestructible border along the bottom")); - glGMLayout->addWidget(TBW_bottomborder,4,4,1,1); - - - // Right - QLabel * l; - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Damage Modifier")); - l->setWordWrap(true); - glBSLayout->addWidget(l,0,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconDamage.png")); - glBSLayout->addWidget(l,0,1,1,1); - SB_DamageModifier = new QSpinBox(gbBasicSettings); - SB_DamageModifier->setRange(10, 300); - SB_DamageModifier->setValue(100); - SB_DamageModifier->setSingleStep(25); - glBSLayout->addWidget(SB_DamageModifier,0,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Turn Time")); - l->setWordWrap(true); - glBSLayout->addWidget(l,1,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconTime.png")); - glBSLayout->addWidget(l,1,1,1,1); - SB_TurnTime = new QSpinBox(gbBasicSettings); - SB_TurnTime->setRange(1, 9999); - SB_TurnTime->setValue(45); - SB_TurnTime->setSingleStep(15); - glBSLayout->addWidget(SB_TurnTime,1,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Initial Health")); - l->setWordWrap(true); - glBSLayout->addWidget(l,2,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconHealth.png")); - glBSLayout->addWidget(l,2,1,1,1); - SB_InitHealth = new QSpinBox(gbBasicSettings); - SB_InitHealth->setRange(50, 200); - SB_InitHealth->setValue(100); - SB_InitHealth->setSingleStep(25); - glBSLayout->addWidget(SB_InitHealth,2,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Sudden Death Timeout")); - l->setWordWrap(true); - glBSLayout->addWidget(l,3,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconSuddenDeath.png")); - glBSLayout->addWidget(l,3,1,1,1); - SB_SuddenDeath = new QSpinBox(gbBasicSettings); - SB_SuddenDeath->setRange(0, 50); - SB_SuddenDeath->setValue(15); - SB_SuddenDeath->setSingleStep(3); - glBSLayout->addWidget(SB_SuddenDeath,3,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Sudden Death Water Rise")); - l->setWordWrap(true); - glBSLayout->addWidget(l,4,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconSuddenDeath.png")); // TODO: icon - glBSLayout->addWidget(l,4,1,1,1); - SB_WaterRise = new QSpinBox(gbBasicSettings); - SB_WaterRise->setRange(0, 100); - SB_WaterRise->setValue(47); - SB_WaterRise->setSingleStep(5); - glBSLayout->addWidget(SB_WaterRise,4,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Sudden Death Health Decrease")); - l->setWordWrap(true); - glBSLayout->addWidget(l,5,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconSuddenDeath.png")); // TODO: icon - glBSLayout->addWidget(l,5,1,1,1); - SB_HealthDecrease = new QSpinBox(gbBasicSettings); - SB_HealthDecrease->setRange(0, 100); - SB_HealthDecrease->setValue(5); - SB_HealthDecrease->setSingleStep(1); - glBSLayout->addWidget(SB_HealthDecrease,5,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("% Rope Length")); - l->setWordWrap(true); - glBSLayout->addWidget(l,6,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconRope.png")); - glBSLayout->addWidget(l,6,1,1,1); - SB_RopeModifier = new QSpinBox(gbBasicSettings); - SB_RopeModifier->setRange(25, 999); - SB_RopeModifier->setValue(100); - SB_RopeModifier->setSingleStep(25); - glBSLayout->addWidget(SB_RopeModifier,6,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Crate Drops")); - l->setWordWrap(true); - glBSLayout->addWidget(l,7,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconBox.png")); - glBSLayout->addWidget(l,7,1,1,1); - SB_CaseProb = new FreqSpinBox(gbBasicSettings); - SB_CaseProb->setRange(0, 9); - SB_CaseProb->setValue(5); - glBSLayout->addWidget(SB_CaseProb,7,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("% Health Crates")); - l->setWordWrap(true); - glBSLayout->addWidget(l,8,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconHealth.png")); // TODO: icon - glBSLayout->addWidget(l,8,1,1,1); - SB_HealthCrates = new QSpinBox(gbBasicSettings); - SB_HealthCrates->setRange(0, 100); - SB_HealthCrates->setValue(35); - SB_HealthCrates->setSingleStep(5); - glBSLayout->addWidget(SB_HealthCrates,8,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Health in Crates")); - l->setWordWrap(true); - glBSLayout->addWidget(l,9,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconHealth.png")); // TODO: icon - glBSLayout->addWidget(l,9,1,1,1); - SB_CrateHealth = new QSpinBox(gbBasicSettings); - SB_CrateHealth->setRange(0, 200); - SB_CrateHealth->setValue(25); - SB_CrateHealth->setSingleStep(5); - glBSLayout->addWidget(SB_CrateHealth,9,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Mines Time")); - l->setWordWrap(true); - glBSLayout->addWidget(l,10,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconTime.png")); // TODO: icon - glBSLayout->addWidget(l,10,1,1,1); - SB_MinesTime = new QSpinBox(gbBasicSettings); - SB_MinesTime->setRange(-1, 5); - SB_MinesTime->setValue(3); - SB_MinesTime->setSingleStep(1); - SB_MinesTime->setSpecialValueText(tr("Random")); - SB_MinesTime->setSuffix(" "+ tr("Seconds")); - glBSLayout->addWidget(SB_MinesTime,10,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Mines")); - l->setWordWrap(true); - glBSLayout->addWidget(l,11,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconMine.png")); // TODO: icon - glBSLayout->addWidget(l,11,1,1,1); - SB_Mines = new QSpinBox(gbBasicSettings); - SB_Mines->setRange(0, 80); - SB_Mines->setValue(0); - SB_Mines->setSingleStep(5); - glBSLayout->addWidget(SB_Mines,11,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("% Dud Mines")); - l->setWordWrap(true); - glBSLayout->addWidget(l,12,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconDud.png")); - glBSLayout->addWidget(l,12,1,1,1); - SB_MineDuds = new QSpinBox(gbBasicSettings); - SB_MineDuds->setRange(0, 100); - SB_MineDuds->setValue(0); - SB_MineDuds->setSingleStep(5); - glBSLayout->addWidget(SB_MineDuds,12,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Explosives")); - l->setWordWrap(true); - glBSLayout->addWidget(l,13,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconDamage.png")); - glBSLayout->addWidget(l,13,1,1,1); - SB_Explosives = new QSpinBox(gbBasicSettings); - SB_Explosives->setRange(0, 40); - SB_Explosives->setValue(0); - SB_Explosives->setSingleStep(1); - glBSLayout->addWidget(SB_Explosives,13,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("% Get Away Time")); - l->setWordWrap(true); - glBSLayout->addWidget(l,14,0,1,1); - l = new QLabel(gbBasicSettings); - l->setFixedSize(32,32); - l->setPixmap(QPixmap(":/res/iconTime.png")); - glBSLayout->addWidget(l,14,1,1,1); - SB_GetAwayTime = new QSpinBox(gbBasicSettings); - SB_GetAwayTime->setRange(0, 999); - SB_GetAwayTime->setValue(100); - SB_GetAwayTime->setSingleStep(25); - glBSLayout->addWidget(SB_GetAwayTime,14,2,1,1); - - l = new QLabel(gbBasicSettings); - l->setText(QLabel::tr("Scheme Name:")); - - LE_name = new QLineEdit(this); - - gl->addWidget(LE_name,15,1,1,5); - gl->addWidget(l,15,0,1,1); - - mapper = new QDataWidgetMapper(this); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 16, 0, true); - BtnCopy = addButton(tr("Copy"), pageLayout, 16, 2); - BtnNew = addButton(tr("New"), pageLayout, 16, 3); - BtnDelete = addButton(tr("Delete"), pageLayout, 16, 4); - - selectScheme = new QComboBox(this); - pageLayout->addWidget(selectScheme, 16, 1); - - connect(BtnCopy, SIGNAL(clicked()), this, SLOT(copyRow())); - connect(BtnNew, SIGNAL(clicked()), this, SLOT(newRow())); - connect(BtnDelete, SIGNAL(clicked()), this, SLOT(deleteRow())); - connect(selectScheme, SIGNAL(currentIndexChanged(int)), mapper, SLOT(setCurrentIndex(int))); - connect(selectScheme, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeSelected(int))); -} - -void PageScheme::setModel(QAbstractItemModel * model) -{ - mapper->setModel(model); - selectScheme->setModel(model); - - mapper->addMapping(LE_name, 0); - mapper->addMapping(TBW_mode_Forts, 1); - mapper->addMapping(TBW_teamsDivide, 2); - mapper->addMapping(TBW_solid, 3); - mapper->addMapping(TBW_border, 4); - mapper->addMapping(TBW_lowGravity, 5); - mapper->addMapping(TBW_laserSight, 6); - mapper->addMapping(TBW_invulnerable, 7); - mapper->addMapping(TBW_resethealth, 8); - mapper->addMapping(TBW_vampiric, 9); - mapper->addMapping(TBW_karma, 10); - mapper->addMapping(TBW_artillery, 11); - mapper->addMapping(TBW_randomorder, 12); - mapper->addMapping(TBW_king, 13); - mapper->addMapping(TBW_placehog, 14); - mapper->addMapping(TBW_sharedammo, 15); - mapper->addMapping(TBW_disablegirders, 16); - mapper->addMapping(TBW_disablelandobjects, 17); - mapper->addMapping(TBW_aisurvival, 18); - mapper->addMapping(TBW_infattack, 19); - mapper->addMapping(TBW_resetweps, 20); - mapper->addMapping(TBW_perhogammo, 21); - mapper->addMapping(TBW_nowind, 22); - mapper->addMapping(TBW_morewind, 23); - mapper->addMapping(TBW_tagteam, 24); - mapper->addMapping(TBW_bottomborder, 25); - mapper->addMapping(SB_DamageModifier, 26); - mapper->addMapping(SB_TurnTime, 27); - mapper->addMapping(SB_InitHealth, 28); - mapper->addMapping(SB_SuddenDeath, 29); - mapper->addMapping(SB_CaseProb, 30); - mapper->addMapping(SB_MinesTime, 31); - mapper->addMapping(SB_Mines, 32); - mapper->addMapping(SB_MineDuds, 33); - mapper->addMapping(SB_Explosives, 34); - mapper->addMapping(SB_HealthCrates, 35); - mapper->addMapping(SB_CrateHealth, 36); - mapper->addMapping(SB_WaterRise, 37); - mapper->addMapping(SB_HealthDecrease, 38); - mapper->addMapping(SB_RopeModifier, 39); - mapper->addMapping(SB_GetAwayTime, 40); - - mapper->toFirst(); -} - -void PageScheme::newRow() -{ - QAbstractItemModel * model = mapper->model(); - model->insertRow(-1); - selectScheme->setCurrentIndex(model->rowCount() - 1); -} - -void PageScheme::copyRow() -{ - QAbstractItemModel * model = mapper->model(); - model->insertRow(selectScheme->currentIndex()); - selectScheme->setCurrentIndex(model->rowCount() - 1); -} - -void PageScheme::deleteRow() -{ - QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Schemes"), QMessageBox::tr("Really delete this game scheme?"), QMessageBox::Ok | QMessageBox::Cancel); - - if (reallyDelete.exec() == QMessageBox::Ok) { - QAbstractItemModel * model = mapper->model(); - model->removeRow(selectScheme->currentIndex()); - } -} - -void PageScheme::schemeSelected(int n) -{ - int c = ((AmmoSchemeModel*)mapper->model())->numberOfDefaultSchemes; - gbGameModes->setEnabled(n >= c); - gbBasicSettings->setEnabled(n >= c); - LE_name->setEnabled(n >= c); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagescheme.h --- a/QTfrontend/pagescheme.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_SCHEME_H -#define PAGE_SCHEME_H - -#include "AbstractPage.h" -#include "togglebutton.h" - -class FreqSpinBox; - -class PageScheme : public AbstractPage -{ - Q_OBJECT - -public: - PageScheme(QWidget* parent = 0); - - QPushButton * BtnBack; - QPushButton * BtnCopy; - QPushButton * BtnNew; - QPushButton * BtnDelete; - QPushButton * BtnSave; - QComboBox * selectScheme; - - void setModel(QAbstractItemModel * model); - -public slots: - void newRow(); - void copyRow(); - void deleteRow(); - -private: - QDataWidgetMapper * mapper; - ToggleButtonWidget * TBW_mode_Forts; - ToggleButtonWidget * TBW_teamsDivide; - ToggleButtonWidget * TBW_solid; - ToggleButtonWidget * TBW_border; - ToggleButtonWidget * TBW_lowGravity; - ToggleButtonWidget * TBW_laserSight; - ToggleButtonWidget * TBW_invulnerable; - ToggleButtonWidget * TBW_resethealth; - ToggleButtonWidget * TBW_vampiric; - ToggleButtonWidget * TBW_karma; - ToggleButtonWidget * TBW_artillery; - ToggleButtonWidget * TBW_randomorder; - ToggleButtonWidget * TBW_king; - ToggleButtonWidget * TBW_placehog; - ToggleButtonWidget * TBW_sharedammo; - ToggleButtonWidget * TBW_disablegirders; - ToggleButtonWidget * TBW_disablelandobjects; - ToggleButtonWidget * TBW_aisurvival; - ToggleButtonWidget * TBW_infattack; - ToggleButtonWidget * TBW_resetweps; - ToggleButtonWidget * TBW_perhogammo; - ToggleButtonWidget * TBW_nowind; - ToggleButtonWidget * TBW_morewind; - ToggleButtonWidget * TBW_tagteam; - ToggleButtonWidget * TBW_bottomborder; - - QSpinBox * SB_DamageModifier; - QSpinBox * SB_TurnTime; - QSpinBox * SB_InitHealth; - QSpinBox * SB_SuddenDeath; - QSpinBox * SB_WaterRise; - QSpinBox * SB_HealthDecrease; - FreqSpinBox * SB_CaseProb; - QSpinBox * SB_HealthCrates; - QSpinBox * SB_CrateHealth; - QSpinBox * SB_MinesTime; - QSpinBox * SB_Mines; - QSpinBox * SB_MineDuds; - QSpinBox * SB_Explosives; - QSpinBox * SB_RopeModifier; - QSpinBox * SB_GetAwayTime; - QLineEdit * LE_name; - - QGroupBox * gbGameModes; - QGroupBox * gbBasicSettings; - -private slots: - void schemeSelected(int); - -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageselectweapon.cpp --- a/QTfrontend/pageselectweapon.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "pageselectweapon.h" -#include "hwconsts.h" -#include "selectWeapon.h" - -PageSelectWeapon::PageSelectWeapon(QWidget* parent) : - AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - - pWeapons = new SelWeaponWidget(cAmmoNumber, this); - pageLayout->addWidget(pWeapons, 0, 0, 1, 5); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, 2, 1, true); - BtnDefault = addButton(tr("Default"), pageLayout, 1, 3); - BtnNew = addButton(tr("New"), pageLayout, 1, 2); - BtnCopy = addButton(tr("Copy"), pageLayout, 2, 2); - BtnDelete = addButton(tr("Delete"), pageLayout, 2, 3); - BtnSave = addButton(":/res/Save.png", pageLayout, 1, 4, 2, 1, true); - BtnSave->setStyleSheet("QPushButton{margin: 24px 0px 0px 0px;}"); - BtnBack->setFixedHeight(BtnSave->height()); - BtnBack->setStyleSheet("QPushButton{margin-top: 31px;}"); - - selectWeaponSet = new QComboBox(this); - pageLayout->addWidget(selectWeaponSet, 1, 1, 2, 1); - - connect(BtnDefault, SIGNAL(clicked()), pWeapons, SLOT(setDefault())); - connect(BtnSave, SIGNAL(clicked()), pWeapons, SLOT(save())); - connect(BtnNew, SIGNAL(clicked()), pWeapons, SLOT(newWeaponsName())); - connect(BtnCopy, SIGNAL(clicked()), pWeapons, SLOT(copy())); - connect(selectWeaponSet, SIGNAL(currentIndexChanged(const QString&)), pWeapons, SLOT(setWeaponsName(const QString&))); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pageselectweapon.h --- a/QTfrontend/pageselectweapon.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_SELECTWEAPON_H -#define PAGE_SELECTWEAPON_H - -#include "AbstractPage.h" - -class SelWeaponWidget; - -class PageSelectWeapon : public AbstractPage -{ - Q_OBJECT - -public: - PageSelectWeapon(QWidget* parent = 0); - - QPushButton *BtnSave; - QPushButton *BtnDefault; - QPushButton *BtnDelete; - QPushButton *BtnNew; - QPushButton *BtnCopy; - QPushButton *BtnBack; - SelWeaponWidget* pWeapons; - QComboBox* selectWeaponSet; -}; - -#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagesingleplayer.cpp --- a/QTfrontend/pagesingleplayer.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include - -#include "pagesingleplayer.h" -#include "gamecfgwidget.h" - -PageSinglePlayer::PageSinglePlayer(QWidget* parent) : AbstractPage(parent) -{ - QVBoxLayout * vLayout = new QVBoxLayout(this); - QHBoxLayout * topLine = new QHBoxLayout(); - QHBoxLayout * middleLine = new QHBoxLayout(); - QHBoxLayout * bottomLine = new QHBoxLayout(); - vLayout->addStretch(); - vLayout->addLayout(topLine); - vLayout->addSpacing(30); - vLayout->addLayout(middleLine); - vLayout->addStretch(); - vLayout->addLayout(bottomLine); - - topLine->addStretch(); - BtnSimpleGamePage = addButton(":/res/SimpleGame.png", topLine, 0, true); - BtnSimpleGamePage->setToolTip(tr("Simple Game (a quick game against the computer, settings are chosen for you)")); - topLine->addSpacing(60); - BtnMultiplayer = addButton(":/res/Multiplayer.png", topLine, 1, true); - BtnMultiplayer->setToolTip(tr("Multiplayer (play a hotseat game against your friends, or AI teams)")); - topLine->addStretch(); - - - BtnCampaignPage = addButton(":/res/Campaign.png", middleLine, 0, true); - BtnCampaignPage->setToolTip(tr("Campaign Mode (...). IN DEVELOPMENT")); - BtnCampaignPage->setVisible(false); - - BtnTrainPage = addButton(":/res/Trainings.png", middleLine, 1, true); - BtnTrainPage->setToolTip(tr("Training Mode (Practice your skills in a range of training missions). IN DEVELOPMENT")); - - BtnBack = addButton(":/res/Exit.png", bottomLine, 0, true); - bottomLine->addStretch(); - - BtnDemos = addButton(":/res/Record.png", bottomLine, 1, true); - BtnDemos->setToolTip(tr("Demos (Watch recorded demos)")); - BtnLoad = addButton(":/res/Save.png", bottomLine, 2, true); - BtnLoad->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); - BtnLoad->setToolTip(tr("Load (Load a previously saved game)")); - BtnBack->setFixedHeight(BtnLoad->height()); - BtnBack->setStyleSheet("QPushButton{margin-top: 31px;}"); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagesingleplayer.h --- a/QTfrontend/pagesingleplayer.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_SINGLE_PLAYER_H -#define PAGE_SINGLE_PLAYER_H - -#include "AbstractPage.h" - -class GameCFGWidget; - -class PageSinglePlayer : public AbstractPage -{ - Q_OBJECT - -public: - PageSinglePlayer(QWidget* parent = 0); - - QPushButton *BtnSimpleGamePage; - QPushButton *BtnTrainPage; - QPushButton *BtnCampaignPage; - QPushButton *BtnMultiplayer; - QPushButton *BtnLoad; - QPushButton *BtnDemos; - QPushButton *BtnBack; - GameCFGWidget *gameCFG; -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagetraining.cpp --- a/QTfrontend/pagetraining.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include "pagetraining.h" -#include "hwconsts.h" - -PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent) -{ - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->setColumnStretch(0, 1); - pageLayout->setColumnStretch(1, 2); - pageLayout->setColumnStretch(2, 1); - pageLayout->setRowStretch(0, 1); - pageLayout->setRowStretch(2, 1); - - CBSelect = new QComboBox(this); - - QDir tmpdir; - tmpdir.cd(cfgdir->absolutePath()); - tmpdir.cd("Data/Missions/Training"); - tmpdir.setFilter(QDir::Files); - QStringList userlist = tmpdir.entryList(QStringList("*.lua")).replaceInStrings(QRegExp("^(.*)\\.lua"), "\\1"); - CBSelect->addItems(userlist); - - tmpdir.cd(datadir->absolutePath()); - tmpdir.cd("Missions/Training"); - tmpdir.setFilter(QDir::Files); - QStringList tmplist = tmpdir.entryList(QStringList("*.lua")).replaceInStrings(QRegExp("^(.*)\\.lua"), "\\1"); - QStringList datalist; - for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) - if (!userlist.contains(*it,Qt::CaseInsensitive)) datalist.append(*it); - CBSelect->addItems(datalist); - - for(int i = 0; i < CBSelect->count(); i++) - { - CBSelect->setItemData(i, CBSelect->itemText(i)); - CBSelect->setItemText(i, CBSelect->itemText(i).replace("_", " ")); - } - - pageLayout->addWidget(CBSelect, 1, 1); - - BtnStartTrain = new QPushButton(this); - BtnStartTrain->setFont(*font14); - BtnStartTrain->setText(QPushButton::tr("Go!")); - pageLayout->addWidget(BtnStartTrain, 1, 2); - - BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/pagetraining.h --- a/QTfrontend/pagetraining.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef PAGE_TRAINING_H -#define PAGE_TRAINING_H - -#include "AbstractPage.h" - -class PageTraining : public AbstractPage -{ - Q_OBJECT - -public: - PageTraining(QWidget* parent = 0); - - QPushButton *BtnStartTrain; - QPushButton *BtnBack; - QComboBox *CBSelect; -}; - -#endif - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/proto.cpp --- a/QTfrontend/proto.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "proto.h" - -HWProto::HWProto() -{ - -} - -QByteArray & HWProto::addByteArrayToBuffer(QByteArray & buf, const QByteArray & msg) -{ - QByteArray bmsg = msg; - bmsg = bmsg.left(250); - quint8 sz = bmsg.size(); - buf.append(QByteArray((char *)&sz, 1)); - buf.append(bmsg); - return buf; -} - -QByteArray & HWProto::addStringToBuffer(QByteArray & buf, const QString & string) -{ - return addByteArrayToBuffer(buf, string.toUtf8()); -} - -QByteArray & HWProto::addStringListToBuffer(QByteArray & buf, const QStringList & strList) -{ - for (int i = 0; i < strList.size(); i++) - addStringToBuffer(buf, strList[i]); - return buf; -} - -QString HWProto::formatChatMsgForFrontend(const QString & msg) -{ - return formatChatMsg("|nick|", msg); -} - -QString HWProto::formatChatMsg(const QString & nick, const QString & msg) -{ - if(msg.left(4) == "/me ") - return QString("\x02* %1 %2").arg(nick).arg(msg.mid(4)); - else - return QString("\x01%1: %2").arg(nick).arg(msg); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/proto.h --- a/QTfrontend/proto.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _PROTO_H -#define _PROTO_H - -#include -#include -#include - - -class HWProto : public QObject -{ - Q_OBJECT - -public: - HWProto(); - static QByteArray & addStringToBuffer(QByteArray & buf, const QString & string); - static QByteArray & addByteArrayToBuffer(QByteArray & buf, const QByteArray & msg); - static QByteArray & addStringListToBuffer(QByteArray & buf, const QStringList & strList); - static QString formatChatMsg(const QString & nick, const QString & msg); - static QString formatChatMsgForFrontend(const QString & msg); -}; - -#endif // _PROTO_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/qaspectratiolayout.cpp --- a/QTfrontend/qaspectratiolayout.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2009 Nokia Corporation. - */ - -#include "qaspectratiolayout.h" - -QAspectRatioLayout::QAspectRatioLayout(QWidget* parent, int spacing) : QLayout(parent) { - init(spacing); -} - -QAspectRatioLayout::QAspectRatioLayout(int spacing) { - init(spacing); -} - -QAspectRatioLayout::~QAspectRatioLayout() { - delete item; - delete lastReceivedRect; - delete _geometry; -} - -void QAspectRatioLayout::init(int spacing) { - item = 0; - lastReceivedRect = new QRect(0, 0, 0, 0); - _geometry = new QRect(0, 0, 0, 0); - setSpacing(spacing); -} - - -/* Adds item if place isn't already taken. */ -void QAspectRatioLayout::add(QLayoutItem* item) { - if(!hasItem()) { - replaceItem(item); - } -} - -/* Adds item if place isn't already taken. */ -void QAspectRatioLayout::addItem(QLayoutItem* item) { - if(!hasItem()) { - replaceItem(item); - } -} - -/* Adds widget if place isn't already taken. */ -void QAspectRatioLayout::addWidget(QWidget* widget) { - if(!hasItem()) { - replaceItem(new QWidgetItem(widget)); - } -} - -/* Returns the item pointer and dereferences it here. */ -QLayoutItem* QAspectRatioLayout::take() { - QLayoutItem* item = 0; - if(this->hasItem()) { - item = this->item; - this->item = 0; - } - return item; -} - -/* Returns the item pointer and dereferences it here. */ -QLayoutItem* QAspectRatioLayout::takeAt(int index) { - if(index != 0) { - return 0; - } - return this->take(); -} - -/* Returns the item pointer. */ -QLayoutItem* QAspectRatioLayout::itemAt(int index) const { - if(index != 0) { - return 0; - } - if(hasItem()) { - return this->item; - } - return 0; -} - -/* Checks if we have an item. */ -bool QAspectRatioLayout::hasItem() const { - return this->item != 0; -} - -/* Returns the count of items which can be either 0 or 1. */ -int QAspectRatioLayout::count() const { - int returnValue = 0; - if(hasItem()) { - returnValue = 1; - } - return returnValue; -} - -/* Replaces the item with the new and returns the old. */ -QLayoutItem* QAspectRatioLayout::replaceItem(QLayoutItem* item) { - QLayoutItem* old = 0; - if(this->hasItem()) { - old = this->item; - } - this->item = item; - setGeometry(*this->_geometry); - return old; -} - -/* Tells which way layout expands. */ -Qt::Orientations QAspectRatioLayout::expandingDirections() const { - return Qt::Horizontal | Qt::Vertical; -} - -/* Tells which size is preferred. */ -QSize QAspectRatioLayout::sizeHint() const { - return this->item->minimumSize(); -} - -/* Tells minimum size. */ -QSize QAspectRatioLayout::minimumSize() const { - return this->item->minimumSize(); -} - -/* - * Tells if heightForWidth calculations is handled. - * It isn't since width isn't enough to calculate - * proper size. - */ -bool QAspectRatioLayout::hasHeightForWidth() const { - return false; -} - -/* Replaces lastReceivedRect. */ -void QAspectRatioLayout::setLastReceivedRect(const QRect& rect) { - QRect* oldRect = this->lastReceivedRect; - this->lastReceivedRect = new QRect(rect.topLeft(), rect.size()); - delete oldRect; -} - -/* Returns geometry */ -QRect QAspectRatioLayout::geometry() { - return QRect(*this->_geometry); -} - -/* Sets geometry to given size. */ -void QAspectRatioLayout::setGeometry(const QRect& rect) { - /* - * We check if the item is set and - * if size is the same previously received. - * If either is false nothing is done. - */ - if(!this->hasItem() || - areRectsEqual(*this->lastReceivedRect, rect)) { - return; - } - /* Replace the last received rectangle. */ - setLastReceivedRect(rect); - /* Calculate proper size for the item relative to the received size. */ - QSize properSize = calculateProperSize(rect.size()); - /* Calculate center location in the rect and with item size. */ - QPoint properLocation = calculateCenterLocation(rect.size(), properSize); - /* Set items geometry */ - this->item->setGeometry(QRect(properLocation, properSize)); - QRect* oldRect = this->_geometry; - /* Cache the calculated geometry. */ - this->_geometry = new QRect(properLocation, properSize); - delete oldRect; - /* Super classes setGeometry */ - QLayout::setGeometry(*this->_geometry); -} - -/* Takes the shortest side and creates QSize - * with the shortest side as width and height. */ -QSize QAspectRatioLayout::calculateProperSize(QSize from) const { - QSize properSize; - if(from.height() * 2 < from.width()) { - properSize.setHeight(from.height() - this->margin()); - properSize.setWidth(from.height() * 2 - this->margin()); - } - else { - properSize.setWidth(from.width() - this->margin()); - properSize.setHeight(from.width() / 2 - this->margin()); - } - return properSize; -} - -/* Calculates center location from the given height and width for item size. */ -QPoint QAspectRatioLayout::calculateCenterLocation(QSize from, - QSize itemSize) const { - QPoint centerLocation; - if((from.width() - itemSize.width()) > 0) { - centerLocation.setX((from.width() - itemSize.width())/2); - } - if((from.height() - itemSize.height()) > 0) { - centerLocation.setY((from.height() - itemSize.height())/2); - } - return centerLocation; -} - -/* Compares if two QRects are equal. */ -bool QAspectRatioLayout::areRectsEqual(const QRect& a, - const QRect& b) const { - bool result = false; - if(a.x() == b.x() && - a.y() == b.y() && - a.height() == b.height() && - a.width() == b.width()) { - result = true; - } - return result; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/qaspectratiolayout.h --- a/QTfrontend/qaspectratiolayout.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2009 Nokia Corporation. - */ - -#ifndef QASPECTRATIOLAYOUT_H_ -#define QASPECTRATIOLAYOUT_H_ - -#include -#include -#include -#include -#include - - -class QAspectRatioLayout : public QLayout -{ - Q_OBJECT - -public: - QAspectRatioLayout(QWidget* parent, int spacing =-1); - QAspectRatioLayout(int spacing = -1); - ~QAspectRatioLayout(); - - /* Convenience method */ - virtual void add(QLayoutItem* item); - -/* http://doc.trolltech.com/qlayout.html#addItem */ - virtual void addItem(QLayoutItem* item); - /* http://doc.trolltech.com/qlayout.html#addWidget */ - virtual void addWidget(QWidget* widget); - /* http://doc.trolltech.com/qlayout.html#takeAt */ - virtual QLayoutItem* takeAt(int index); - /* http://doc.trolltech.com/qlayout.html#itemAt */ - virtual QLayoutItem* itemAt(int index) const; - /* http://doc.trolltech.com/qlayout.html#count */ - virtual int count() const; - - /* - * These are ours since we do have only one item. - */ - virtual QLayoutItem* replaceItem(QLayoutItem* item); - virtual QLayoutItem* take(); - virtual bool hasItem() const; - -/* http://doc.trolltech.com/qlayout.html#expandingDirections */ - virtual Qt::Orientations expandingDirections() const; - - /* - * This method contains most of the juice of this article. - * http://doc.trolltech.com/qlayoutitem.html#setGeometry - */ - virtual void setGeometry(const QRect& rect); - /* http://doc.trolltech.com/qlayoutitem.html#geometry */ - virtual QRect geometry(); - - /* http://doc.trolltech.com/qlayoutitem.html#sizeHint */ - virtual QSize sizeHint() const; - /* http://doc.trolltech.com/qlayout.html#minimumSize */ - virtual QSize minimumSize() const; - /* http://doc.trolltech.com/qlayoutitem.html#hasHeightForWidth */ - virtual bool hasHeightForWidth() const; - -private: - /* Saves the last received rect. */ - void setLastReceivedRect(const QRect& rect); - /* Used to initialize the object. */ - void init(int spacing); - /* Calculates the maximum size for the item from the assigned size. */ - QSize calculateProperSize(QSize from) const; - /* Calculates the center location from the assigned size and - * the items size. */ - QPoint calculateCenterLocation(QSize from, QSize itemSize) const; - /* Check if two QRects are equal */ - bool areRectsEqual(const QRect& a, const QRect& b) const; - /* Contains item reference */ - QLayoutItem* item; - /* - * Used for caching so we won't do calculations every time - * setGeometry is called. - */ - QRect* lastReceivedRect; - /* Contains geometry */ - QRect* _geometry; - -}; - -#endif /* QASPECTRATIOLAYOUT_H_ */ diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/Load.png Binary file QTfrontend/res/Load.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/StatsMedal1@2x.png Binary file QTfrontend/res/StatsMedal1@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/StatsMedal2@2x.png Binary file QTfrontend/res/StatsMedal2@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/StatsMedal3@2x.png Binary file QTfrontend/res/StatsMedal3@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/StatsMedal4@2x.png Binary file QTfrontend/res/StatsMedal4@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/ammopic@2x.png Binary file QTfrontend/res/ammopic@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnAISurvival.png Binary file QTfrontend/res/btnAISurvival.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnAISurvival@2x.png Binary file QTfrontend/res/btnAISurvival@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnArtillery.png Binary file QTfrontend/res/btnArtillery.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnArtillery@2x.png Binary file QTfrontend/res/btnArtillery@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnBorder.png Binary file QTfrontend/res/btnBorder.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnBorder@2x.png Binary file QTfrontend/res/btnBorder@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnBottomBorder.png Binary file QTfrontend/res/btnBottomBorder.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnBottomBorder@2x.png Binary file QTfrontend/res/btnBottomBorder@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnDisableGirders.png Binary file QTfrontend/res/btnDisableGirders.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnDisableGirders@2x.png Binary file QTfrontend/res/btnDisableGirders@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnDisableLandObjects.png Binary file QTfrontend/res/btnDisableLandObjects.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnDisableLandObjects@2x.png Binary file QTfrontend/res/btnDisableLandObjects@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnDisabled.png diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnForts.png Binary file QTfrontend/res/btnForts.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnForts@2x.png Binary file QTfrontend/res/btnForts@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnInfAttack.png Binary file QTfrontend/res/btnInfAttack.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnInfAttack@2x.png Binary file QTfrontend/res/btnInfAttack@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnInvulnerable.png Binary file QTfrontend/res/btnInvulnerable.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnInvulnerable@2x.png Binary file QTfrontend/res/btnInvulnerable@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnKarma.png Binary file QTfrontend/res/btnKarma.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnKarma@2x.png Binary file QTfrontend/res/btnKarma@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnKing.png Binary file QTfrontend/res/btnKing.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnKing@2x.png Binary file QTfrontend/res/btnKing@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnLaserSight.png Binary file QTfrontend/res/btnLaserSight.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnLaserSight@2x.png Binary file QTfrontend/res/btnLaserSight@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnLowGravity.png Binary file QTfrontend/res/btnLowGravity.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnLowGravity@2x.png Binary file QTfrontend/res/btnLowGravity@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnMoreWind.png Binary file QTfrontend/res/btnMoreWind.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnMoreWind@2x.png Binary file QTfrontend/res/btnMoreWind@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnNoWind.png Binary file QTfrontend/res/btnNoWind.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnNoWind@2x.png Binary file QTfrontend/res/btnNoWind@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnOverlay.png Binary file QTfrontend/res/btnOverlay.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnOverlay@2x.png Binary file QTfrontend/res/btnOverlay@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnPerHogAmmo.png Binary file QTfrontend/res/btnPerHogAmmo.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnPerHogAmmo@2x.png Binary file QTfrontend/res/btnPerHogAmmo@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnPlaceHog.png Binary file QTfrontend/res/btnPlaceHog.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnPlaceHog@2x.png Binary file QTfrontend/res/btnPlaceHog@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnRandomOrder.png Binary file QTfrontend/res/btnRandomOrder.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnRandomOrder@2x.png Binary file QTfrontend/res/btnRandomOrder@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnResetHealth.png Binary file QTfrontend/res/btnResetHealth.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnResetHealth@2x.png Binary file QTfrontend/res/btnResetHealth@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnResetWeps.png Binary file QTfrontend/res/btnResetWeps.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnResetWeps@2x.png Binary file QTfrontend/res/btnResetWeps@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnSharedAmmo.png Binary file QTfrontend/res/btnSharedAmmo.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnSharedAmmo@2x.png Binary file QTfrontend/res/btnSharedAmmo@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnSolid.png Binary file QTfrontend/res/btnSolid.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnSolid@2x.png Binary file QTfrontend/res/btnSolid@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnTagTeam.png Binary file QTfrontend/res/btnTagTeam.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnTagTeam@2x.png Binary file QTfrontend/res/btnTagTeam@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnTeamsDivide.png Binary file QTfrontend/res/btnTeamsDivide.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnTeamsDivide@2x.png Binary file QTfrontend/res/btnTeamsDivide@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnVampiric.png Binary file QTfrontend/res/btnVampiric.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/btnVampiric@2x.png Binary file QTfrontend/res/btnVampiric@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconBox@2x.png Binary file QTfrontend/res/iconBox@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconDamage.png Binary file QTfrontend/res/iconDamage.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconDamage@2x.png Binary file QTfrontend/res/iconDamage@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconDud@2x.png Binary file QTfrontend/res/iconDud@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconHealth.png Binary file QTfrontend/res/iconHealth.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconHealth@2x.png Binary file QTfrontend/res/iconHealth@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconMine@2x.png Binary file QTfrontend/res/iconMine@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconRope@2x.png Binary file QTfrontend/res/iconRope@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconSuddenDeath.png Binary file QTfrontend/res/iconSuddenDeath.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconSuddenDeath@2x.png Binary file QTfrontend/res/iconSuddenDeath@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/res/iconTime@2x.png Binary file QTfrontend/res/iconTime@2x.png has changed diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/selectWeapon.cpp --- a/QTfrontend/selectWeapon.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,294 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "selectWeapon.h" -#include "weaponItem.h" -#include "hwconsts.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QImage getAmmoImage(int num) -{ - static QImage ammo(":Ammos.png"); - int x = num/(ammo.height()/32); - int y = (num-((ammo.height()/32)*x))*32; - x*=32; - return ammo.copy(x, y, 32, 32); -} - -SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent) : - QWidget(parent) -{ - QHBoxLayout* hbLayout = new QHBoxLayout(this); - hbLayout->setSpacing(1); - hbLayout->setMargin(1); - - QLabel* lbl = new QLabel(this); - lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum))); - lbl->setMaximumWidth(30); - lbl->setGeometry(0, 0, 30, 30); - hbLayout->addWidget(lbl); - - item = new WeaponItem(image, imagegrey, this); - item->setItemsNum(wNum); - item->setInfinityState(allowInfinite); - hbLayout->addWidget(item); - - hbLayout->setStretchFactor(lbl, 1); - hbLayout->setStretchFactor(item, 99); - hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter); - hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter); -} - -void SelWeaponItem::setItemsNum(const unsigned char num) -{ - item->setItemsNum(num); -} - -unsigned char SelWeaponItem::getItemsNum() const -{ - return item->getItemsNum(); -} - -void SelWeaponItem::setEnabled(bool value) -{ - item->setEnabled(value); -} - -SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) : - QFrame(parent), - m_numItems(numItems) -{ - wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this); - - for(int i = 0; i < cDefaultAmmos.size(); ++i) - wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second); - - QStringList keys = wconf->allKeys(); - for(int i = 0; i < keys.size(); i++) - { - if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size()) - wconf->remove(keys[i]); - } - - QString currentState = *cDefaultAmmoStore; - - QTabWidget * tbw = new QTabWidget(this); - QWidget * page1 = new QWidget(this); - p1Layout = new QGridLayout(page1); - p1Layout->setSpacing(1); - p1Layout->setMargin(1); - QWidget * page2 = new QWidget(this); - p2Layout = new QGridLayout(page2); - p2Layout->setSpacing(1); - p2Layout->setMargin(1); - QWidget * page3 = new QWidget(this); - p3Layout = new QGridLayout(page3); - p3Layout->setSpacing(1); - p3Layout->setMargin(1); - QWidget * page4 = new QWidget(this); - p4Layout = new QGridLayout(page4); - p4Layout->setSpacing(1); - p4Layout->setMargin(1); - - tbw->addTab(page1, tr("Weapon set")); - tbw->addTab(page2, tr("Probabilities")); - tbw->addTab(page4, tr("Ammo in boxes")); - tbw->addTab(page3, tr("Delays")); - - QGridLayout * pageLayout = new QGridLayout(this); - pageLayout->addWidget(tbw); - - - int j = -1; - int i = 0, k = 0; - for(; i < m_numItems; ++i) { - if (i == 6) continue; - if (i == 52) continue; // Disable structures for now - if (k % 4 == 0) ++j; - SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this); - weaponItems[i].append(swi); - p1Layout->addWidget(swi, j, k % 4); - - SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), QImage(":/res/ammopicbox.png"), QImage(":/res/ammopicboxgrey.png"), this); - weaponItems[i].append(pwi); - p2Layout->addWidget(pwi, j, k % 4); - - SelWeaponItem * dwi = new SelWeaponItem(false, i, currentState[numItems*2 + i].digitValue(), QImage(":/res/ammopicdelay.png"), QImage(":/res/ammopicdelaygrey.png"), this); - weaponItems[i].append(dwi); - p3Layout->addWidget(dwi, j, k % 4); - - SelWeaponItem * awi = new SelWeaponItem(false, i, currentState[numItems*3 + i].digitValue(), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this); - weaponItems[i].append(awi); - p4Layout->addWidget(awi, j, k % 4); - - ++k; - } - - //pLayout->setRowStretch(5, 100); - m_name = new QLineEdit(this); - pageLayout->addWidget(m_name, i, 0, 1, 5); -} - -void SelWeaponWidget::setWeapons(const QString& ammo) -{ - bool enable = true; - for(int i = 0; i < cDefaultAmmos.size(); i++) - if (!cDefaultAmmos[i].first.compare(m_name->text())) { - enable = false; - } - for(int i = 0; i < m_numItems; ++i) { - twi::iterator it = weaponItems.find(i); - if (it == weaponItems.end()) continue; - it.value()[0]->setItemsNum(ammo[i].digitValue()); - it.value()[1]->setItemsNum(ammo[m_numItems + i].digitValue()); - it.value()[2]->setItemsNum(ammo[m_numItems*2 + i].digitValue()); - it.value()[3]->setItemsNum(ammo[m_numItems*3 + i].digitValue()); - it.value()[0]->setEnabled(enable); - it.value()[1]->setEnabled(enable); - it.value()[2]->setEnabled(enable); - it.value()[3]->setEnabled(enable); - } - m_name->setEnabled(enable); -} - -void SelWeaponWidget::setDefault() -{ - for(int i = 0; i < cDefaultAmmos.size(); i++) - if (!cDefaultAmmos[i].first.compare(m_name->text())) { - return; - } - setWeapons(*cDefaultAmmoStore); -} - -void SelWeaponWidget::save() -{ - for(int i = 0; i < cDefaultAmmos.size(); i++) - if (!cDefaultAmmos[i].first.compare(m_name->text())) { - QMessageBox::warning(0, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not overwrite default weapon set '%1'!").arg(cDefaultAmmos[i].first)); - return; - } - - if (m_name->text() == "") return; - - QString state1; - QString state2; - QString state3; - QString state4; - - for(int i = 0; i < m_numItems; ++i) { - twi::const_iterator it = weaponItems.find(i); - int num = it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum(); // 9 is for 'skip turn' - state1.append(QString::number(num)); - int prob = it == weaponItems.end() ? 0 : it.value()[1]->getItemsNum(); - state2.append(QString::number(prob)); - int del = it == weaponItems.end() ? 0 : it.value()[2]->getItemsNum(); - state3.append(QString::number(del)); - int am = it == weaponItems.end() ? 0 : it.value()[3]->getItemsNum(); - state4.append(QString::number(am)); - } - if (curWeaponsName != "") { - // remove old entry - wconf->remove(curWeaponsName); - } - wconf->setValue(m_name->text(), state1 + state2 + state3 + state4); - emit weaponsChanged(); -} - -int SelWeaponWidget::operator [] (unsigned int weaponIndex) const -{ - twi::const_iterator it = weaponItems.find(weaponIndex); - return it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum(); -} - -QString SelWeaponWidget::getWeaponsString(const QString& name) const -{ - return wconf->value(name).toString(); -} - -void SelWeaponWidget::deleteWeaponsName() -{ - if (curWeaponsName == "") return; - - for(int i = 0; i < cDefaultAmmos.size(); i++) - if (!cDefaultAmmos[i].first.compare(m_name->text())) { - QMessageBox::warning(0, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not delete default weapon set '%1'!").arg(cDefaultAmmos[i].first)); - return; - } - - QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Weapons"), QMessageBox::tr("Really delete this weapon set?"), QMessageBox::Ok | QMessageBox::Cancel); - - if (reallyDelete.exec() == QMessageBox::Ok) { - wconf->remove(curWeaponsName); - emit weaponsDeleted(); - } -} - -void SelWeaponWidget::newWeaponsName() -{ - QString newName = tr("new"); - if(wconf->contains(newName)) { - //name already used -> look for an appropriate name: - int i=2; - while(wconf->contains(newName = tr("new")+QString::number(i++))); - } - setWeaponsName(newName); -} - -void SelWeaponWidget::setWeaponsName(const QString& name) -{ - m_name->setText(name); - - curWeaponsName = name; - - if(name != "" && wconf->contains(name)) { - setWeapons(wconf->value(name).toString()); - } else { - setWeapons(*cDefaultAmmoStore); - } -} - -QStringList SelWeaponWidget::getWeaponNames() const -{ - return wconf->allKeys(); -} - -void SelWeaponWidget::copy() -{ - if(wconf->contains(curWeaponsName)) { - QString ammo = getWeaponsString(curWeaponsName); - QString newName = tr("copy of") + " " + curWeaponsName; - if(wconf->contains(newName)) { - //name already used -> look for an appropriate name: - int i=2; - while(wconf->contains(newName = tr("copy of") + " " + curWeaponsName+QString::number(i++))); - } - setWeaponsName(newName); - setWeapons(ammo); - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/selectWeapon.h --- a/QTfrontend/selectWeapon.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _SELECT_WEAPON_INCLUDED -#define _SELECT_WEAPON_INCLUDED - -#include -#include -#include - -class QGridLayout; -class WeaponItem; -class QLineEdit; -class QSettings; - -class SelWeaponItem : public QWidget -{ - Q_OBJECT - -public: - SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent=0); - - unsigned char getItemsNum() const; - void setItemsNum(const unsigned char num); - void setEnabled(bool value); - - private: - WeaponItem* item; -}; - -class SelWeaponWidget : public QFrame -{ - Q_OBJECT - - public: - SelWeaponWidget(int numItems, QWidget* parent=0); - QString getWeaponsString(const QString& name) const; - QStringList getWeaponNames() const; - - public slots: - void setDefault(); - void setWeapons(const QString& ammo); - //sets the name of the current set - void setWeaponsName(const QString& name); - void deleteWeaponsName(); - void newWeaponsName(); - void save(); - void copy(); - - signals: - void weaponsChanged(); - void weaponsDeleted(); - - private: - //the name of the current weapon set - QString curWeaponsName; - - QLineEdit* m_name; - - //storage for all the weapons sets - QSettings* wconf; - - const int m_numItems; - int operator [] (unsigned int weaponIndex) const; - - typedef QList ItemsList; - typedef QMap twi; - twi weaponItems; - //layout element for each tab: - QGridLayout* p1Layout; - QGridLayout* p2Layout; - QGridLayout* p3Layout; - QGridLayout* p4Layout; -}; - -#endif // _SELECT_WEAPON_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/tcpBase.cpp --- a/QTfrontend/tcpBase.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "tcpBase.h" - -#include -#include - -#include - -#include "hwconsts.h" - -QList srvsList; -QPointer TCPBase::IPCServer(0); - -TCPBase::~TCPBase() -{ -} - -TCPBase::TCPBase(bool demoMode) : - m_isDemoMode(demoMode), - IPCSocket(0) -{ - if(!IPCServer) { - IPCServer = new QTcpServer(0); - IPCServer->setMaxPendingConnections(1); - if (!IPCServer->listen(QHostAddress::LocalHost)) { - QMessageBox::critical(0, tr("Error"), - tr("Unable to start the server: %1.") - .arg(IPCServer->errorString())); - exit(0); // FIXME - should be graceful exit here - } - } - ipc_port=IPCServer->serverPort(); -} - -void TCPBase::NewConnection() -{ - if(IPCSocket) { - // connection should be already finished - return; - } - disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); - IPCSocket = IPCServer->nextPendingConnection(); - if(!IPCSocket) return; - connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); - connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); - SendToClientFirst(); -} - -void TCPBase::RealStart() -{ - connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); - IPCSocket = 0; - - QProcess * process; - process = new QProcess; - connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); - QStringList arguments=getArguments(); - - // redirect everything written on stdout/stderr - if(isDevBuild) - process->setProcessChannelMode(QProcess::ForwardedChannels); - process->start(bindir->absolutePath() + "/hwengine", arguments); -} - -void TCPBase::ClientDisconnect() -{ - disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); - onClientDisconnect(); - - if(srvsList.size()==1) srvsList.pop_front(); - emit isReadyNow(); - IPCSocket->deleteLater(); - deleteLater(); -} - -void TCPBase::ClientRead() -{ - QByteArray readed=IPCSocket->readAll(); - if(readed.isEmpty()) return; - readbuffer.append(readed); - onClientRead(); -} - -void TCPBase::StartProcessError(QProcess::ProcessError error) -{ - QMessageBox::critical(0, tr("Error"), - tr("Unable to run engine: %1 (") - .arg(error) + bindir->absolutePath() + "/hwengine)"); -} - -void TCPBase::tcpServerReady() -{ - disconnect(srvsList.takeFirst(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); - - RealStart(); -} - -void TCPBase::Start() -{ - if(srvsList.isEmpty()) { - srvsList.push_back(this); - } else { - connect(srvsList.back(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); - srvsList.push_back(this); - return; - } - - RealStart(); -} - -void TCPBase::onClientRead() -{ -} - -void TCPBase::onClientDisconnect() -{ -} - -void TCPBase::SendToClientFirst() -{ -} - -void TCPBase::SendIPC(const QByteArray & buf) -{ - if (buf.size() > MAXMSGCHARS) return; - quint8 len = buf.size(); - RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); -} - -void TCPBase::RawSendIPC(const QByteArray & buf) -{ - if (!IPCSocket) - { - toSendBuf += buf; - } else - { - if (toSendBuf.size() > 0) - { - IPCSocket->write(toSendBuf); - if(m_isDemoMode) demo.append(toSendBuf); - toSendBuf.clear(); - } - if(!buf.isEmpty()) { - IPCSocket->write(buf); - if(m_isDemoMode) demo.append(buf); - } - } -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/tcpBase.h --- a/QTfrontend/tcpBase.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _TCPBASE_INCLUDED -#define _TCPBASE_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define MAXMSGCHARS 255 - -class TCPBase : public QObject -{ - Q_OBJECT - - public: - TCPBase(bool demoMode); - virtual ~TCPBase(); - - signals: - void isReadyNow(); - - protected: - quint16 ipc_port; - - void Start(); - - QByteArray readbuffer; - - QByteArray toSendBuf; - QByteArray demo; - - void SendIPC(const QByteArray & buf); - void RawSendIPC(const QByteArray & buf); - - virtual QStringList getArguments()=0; - virtual void onClientRead(); - virtual void onClientDisconnect(); - virtual void SendToClientFirst(); - - private: - static QPointer IPCServer; - - bool m_isDemoMode; - void RealStart(); - QPointer IPCSocket; - - private slots: - void NewConnection(); - void ClientDisconnect(); - void ClientRead(); - void StartProcessError(QProcess::ProcessError error); - - void tcpServerReady(); -}; - -#endif // _TCPBASE_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/team.cpp --- a/QTfrontend/team.cpp Sat Oct 08 16:45:52 2011 +0200 +++ b/QTfrontend/team.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -25,115 +25,113 @@ #include "team.h" #include "hwform.h" -#include "pageeditteam.h" -#include "hwconsts.h" #include "hats.h" HWTeam::HWTeam(const QString & teamname) : - difficulty(0), - numHedgehogs(4), + m_difficulty(0), + m_numHedgehogs(4), m_isNetTeam(false) { - TeamName = teamname; - OldTeamName = TeamName; - for (int i = 0; i < 8; i++) + m_name = teamname; + OldTeamName = m_name; + for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - Hedgehogs[i].Name.sprintf("hedgehog %d", i); - Hedgehogs[i].Hat = "NoHat"; + m_hedgehogs[i].Name = (QLineEdit::tr("hedgehog %1").arg(i+1)); + m_hedgehogs[i].Hat = "NoHat"; } - Grave = "Statue"; - Fort = "Plane"; - Voicepack = "Default"; - Flag = "hedgewars"; + m_grave = "Statue"; + m_fort = "Plane"; + m_voicepack = "Default"; + m_flag = "hedgewars"; for(int i = 0; i < BINDS_NUMBER; i++) { - binds[i].action = cbinds[i].action; - binds[i].strbind = cbinds[i].strbind; + m_binds[i].action = cbinds[i].action; + m_binds[i].strbind = cbinds[i].strbind; } - Rounds = 0; - Wins = 0; - CampaignProgress = 0; + m_rounds = 0; + m_wins = 0; + m_campaignProgress = 0; } HWTeam::HWTeam(const QStringList& strLst) : - numHedgehogs(4), + m_numHedgehogs(4), m_isNetTeam(true) { // net teams are configured from QStringList if(strLst.size() != 23) throw HWTeamConstructException(); - TeamName = strLst[0]; - Grave = strLst[1]; - Fort = strLst[2]; - Voicepack = strLst[3]; - Flag = strLst[4]; - Owner = strLst[5]; - difficulty = strLst[6].toUInt(); - for(int i = 0; i < 8; i++) + m_name = strLst[0]; + m_grave = strLst[1]; + m_fort = strLst[2]; + m_voicepack = strLst[3]; + m_flag = strLst[4]; + m_owner = strLst[5]; + m_difficulty = strLst[6].toUInt(); + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - Hedgehogs[i].Name=strLst[i * 2 + 7]; - Hedgehogs[i].Hat=strLst[i * 2 + 8]; + m_hedgehogs[i].Name=strLst[i * 2 + 7]; + m_hedgehogs[i].Hat=strLst[i * 2 + 8]; // Somehow claymore managed an empty hat. Until we figure out how, this should avoid a repeat // Checking net teams is probably pointless, but can't hurt. - if (Hedgehogs[i].Hat.isEmpty()) Hedgehogs[i].Hat = "NoHat"; + if (m_hedgehogs[i].Hat.isEmpty()) m_hedgehogs[i].Hat = "NoHat"; } - Rounds = 0; - Wins = 0; - CampaignProgress = 0; + m_rounds = 0; + m_wins = 0; + m_campaignProgress = 0; } HWTeam::HWTeam() : - difficulty(0), - numHedgehogs(4), + m_difficulty(0), + m_numHedgehogs(4), m_isNetTeam(false) { - TeamName = QString("Team"); - for (int i = 0; i < 8; i++) + m_name = QString("Team"); + for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { - Hedgehogs[i].Name.sprintf("hedgehog %d", i); - Hedgehogs[i].Hat = "NoHat"; + m_hedgehogs[i].Name.sprintf("hedgehog %d", i); + m_hedgehogs[i].Hat = "NoHat"; } - Grave = QString("Simple"); // default - Fort = QString("Island"); // default - Voicepack = "Default"; - Flag = "hedgewars"; + m_grave = QString("Simple"); // default + m_fort = QString("Island"); // default + m_voicepack = "Default"; + m_flag = "hedgewars"; for(int i = 0; i < BINDS_NUMBER; i++) { - binds[i].action = cbinds[i].action; - binds[i].strbind = cbinds[i].strbind; + m_binds[i].action = cbinds[i].action; + m_binds[i].strbind = cbinds[i].strbind; } - Rounds = 0; - Wins = 0; - CampaignProgress = 0; + m_rounds = 0; + m_wins = 0; + m_campaignProgress = 0; } -bool HWTeam::LoadFromFile() +bool HWTeam::loadFromFile() { - QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt", QSettings::IniFormat, 0); + QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0); teamfile.setIniCodec("UTF-8"); - TeamName = teamfile.value("Team/Name", TeamName).toString(); - Grave = teamfile.value("Team/Grave", "Statue").toString(); - Fort = teamfile.value("Team/Fort", "Plane").toString(); - Voicepack = teamfile.value("Team/Voicepack", "Default").toString(); - Flag = teamfile.value("Team/Flag", "hedgewars").toString(); - difficulty = teamfile.value("Team/Difficulty", 0).toInt(); - Rounds = teamfile.value("Team/Rounds", 0).toInt(); - Wins = teamfile.value("Team/Wins", 0).toInt(); - CampaignProgress = teamfile.value("Team/CampaignProgress", 0).toInt(); - for(int i = 0; i < 8; i++) + m_name = teamfile.value("Team/Name", m_name).toString(); + m_grave = teamfile.value("Team/Grave", "Statue").toString(); + m_fort = teamfile.value("Team/Fort", "Plane").toString(); + m_voicepack = teamfile.value("Team/Voicepack", "Default").toString(); + m_flag = teamfile.value("Team/Flag", "hedgewars").toString(); + m_difficulty = teamfile.value("Team/Difficulty", 0).toInt(); + m_rounds = teamfile.value("Team/Rounds", 0).toInt(); + m_wins = teamfile.value("Team/Wins", 0).toInt(); + m_campaignProgress = teamfile.value("Team/CampaignProgress", 0).toInt(); + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { QString hh = QString("Hedgehog%1/").arg(i); - Hedgehogs[i].Name = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i)).toString(); - Hedgehogs[i].Hat = teamfile.value(hh + "Hat", "NoHat").toString(); - Hedgehogs[i].Rounds = teamfile.value(hh + "Rounds", 0).toInt(); - Hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt(); - Hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt(); - Hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt(); + m_hedgehogs[i].Name = teamfile.value(hh + "Name", QString("hedgehog %1").arg(i+1)).toString(); + m_hedgehogs[i].Hat = teamfile.value(hh + "Hat", "NoHat").toString(); + m_hedgehogs[i].Rounds = teamfile.value(hh + "Rounds", 0).toInt(); + m_hedgehogs[i].Kills = teamfile.value(hh + "Kills", 0).toInt(); + m_hedgehogs[i].Deaths = teamfile.value(hh + "Deaths", 0).toInt(); + m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt(); } for(int i = 0; i < BINDS_NUMBER; i++) - binds[i].strbind = teamfile.value(QString("Binds/%1").arg(binds[i].action), cbinds[i].strbind).toString(); + m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString(); for(int i = 0; i < MAX_ACHIEVEMENTS; i++) if(achievements[i][0][0]) AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt(); @@ -142,52 +140,52 @@ return true; } -bool HWTeam::FileExists() +bool HWTeam::fileExists() { - QFile f(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt"); + QFile f(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt"); return f.exists(); } -bool HWTeam::DeleteFile() +bool HWTeam::deleteFile() { if(m_isNetTeam) return false; - QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt"); + QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt"); cfgfile.remove(); return true; } -bool HWTeam::SaveToFile() +bool HWTeam::saveToFile() { - if (OldTeamName != TeamName) + if (OldTeamName != m_name) { QFile cfgfile(cfgdir->absolutePath() + "/Teams/" + OldTeamName + ".hwt"); cfgfile.remove(); - OldTeamName = TeamName; + OldTeamName = m_name; } - QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + TeamName + ".hwt", QSettings::IniFormat, 0); + QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + m_name + ".hwt", QSettings::IniFormat, 0); teamfile.setIniCodec("UTF-8"); - teamfile.setValue("Team/Name", TeamName); - teamfile.setValue("Team/Grave", Grave); - teamfile.setValue("Team/Fort", Fort); - teamfile.setValue("Team/Voicepack", Voicepack); - teamfile.setValue("Team/Flag", Flag); - teamfile.setValue("Team/Difficulty", difficulty); - teamfile.setValue("Team/Rounds", Rounds); - teamfile.setValue("Team/Wins", Wins); - teamfile.setValue("Team/CampaignProgress", CampaignProgress); - for(int i = 0; i < 8; i++) + teamfile.setValue("Team/Name", m_name); + teamfile.setValue("Team/Grave", m_grave); + teamfile.setValue("Team/Fort", m_fort); + teamfile.setValue("Team/Voicepack", m_voicepack); + teamfile.setValue("Team/Flag", m_flag); + teamfile.setValue("Team/Difficulty", m_difficulty); + teamfile.setValue("Team/Rounds", m_rounds); + teamfile.setValue("Team/Wins", m_wins); + teamfile.setValue("Team/CampaignProgress", m_campaignProgress); + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) { QString hh = QString("Hedgehog%1/").arg(i); - teamfile.setValue(hh + "Name", Hedgehogs[i].Name); - teamfile.setValue(hh + "Hat", Hedgehogs[i].Hat); - teamfile.setValue(hh + "Rounds", Hedgehogs[i].Rounds); - teamfile.setValue(hh + "Kills", Hedgehogs[i].Kills); - teamfile.setValue(hh + "Deaths", Hedgehogs[i].Deaths); - teamfile.setValue(hh + "Suicides", Hedgehogs[i].Suicides); + teamfile.setValue(hh + "Name", m_hedgehogs[i].Name); + teamfile.setValue(hh + "Hat", m_hedgehogs[i].Hat); + teamfile.setValue(hh + "Rounds", m_hedgehogs[i].Rounds); + teamfile.setValue(hh + "Kills", m_hedgehogs[i].Kills); + teamfile.setValue(hh + "Deaths", m_hedgehogs[i].Deaths); + teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides); } for(int i = 0; i < BINDS_NUMBER; i++) - teamfile.setValue(QString("Binds/%1").arg(binds[i].action), binds[i].strbind); + teamfile.setValue(QString("Binds/%1").arg(m_binds[i].action), m_binds[i].strbind); for(int i = 0; i < MAX_ACHIEVEMENTS; i++) if(achievements[i][0][0]) teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]); @@ -196,82 +194,34 @@ return true; } -void HWTeam::SetToPage(HWForm * hwform) -{ - hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName); - hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(difficulty); - for(int i = 0; i < 8; i++) - { - hwform->ui.pageEditTeam->HHNameEdit[i]->setText(Hedgehogs[i].Name); - if (Hedgehogs[i].Hat.startsWith("Reserved")) - hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+Hedgehogs[i].Hat.remove(0,40), Qt::DisplayRole)); - else - hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(Hedgehogs[i].Hat, Qt::DisplayRole)); - } - hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave)); - hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findData(Flag)); - - hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(Fort)); - hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(Voicepack)); - //hwform->ui.pageEditTeam->CBFort_activated(Fort); - - for(int i = 0; i < BINDS_NUMBER; i++) - { - hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findData(binds[i].strbind)); - } -} - -void HWTeam::GetFromPage(HWForm * hwform) -{ - TeamName = hwform->ui.pageEditTeam->TeamNameEdit->text(); - difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex(); - for(int i = 0; i < 8; i++) - { - Hedgehogs[i].Name = hwform->ui.pageEditTeam->HHNameEdit[i]->text(); - if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved")) - Hedgehogs[i].Hat = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9); - else - Hedgehogs[i].Hat = hwform->ui.pageEditTeam->HHHats[i]->currentText(); - } - - Grave = hwform->ui.pageEditTeam->CBGrave->currentText(); - Fort = hwform->ui.pageEditTeam->CBFort->currentText(); - Voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText(); - Flag = hwform->ui.pageEditTeam->CBFlag->itemData(hwform->ui.pageEditTeam->CBFlag->currentIndex()).toString(); - for(int i = 0; i < BINDS_NUMBER; i++) - { - binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->itemData(hwform->ui.pageEditTeam->CBBind[i]->currentIndex()).toString(); - } -} - -QStringList HWTeam::TeamGameConfig(quint32 InitHealth) const +QStringList HWTeam::teamGameConfig(quint32 InitHealth) const { QStringList sl; if (m_isNetTeam) { - sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(QString(QCryptographicHash::hash(Owner.toLatin1(), QCryptographicHash::Md5).toHex()))); + sl.push_back(QString("eaddteam %3 %1 %2").arg(m_color.rgb() & 0xffffff).arg(m_name).arg(QString(QCryptographicHash::hash(m_owner.toLatin1(), QCryptographicHash::Md5).toHex()))); sl.push_back("erdriven"); } - else sl.push_back(QString("eaddteam %3 %1 %2").arg(teamColor.rgb() & 0xffffff).arg(TeamName).arg(playerHash)); + else sl.push_back(QString("eaddteam %3 %1 %2").arg(m_color.rgb() & 0xffffff).arg(m_name).arg(playerHash)); - sl.push_back(QString("egrave " + Grave)); - sl.push_back(QString("efort " + Fort)); - sl.push_back(QString("evoicepack " + Voicepack)); - sl.push_back(QString("eflag " + Flag)); + sl.push_back(QString("egrave " + m_grave)); + sl.push_back(QString("efort " + m_fort)); + sl.push_back(QString("evoicepack " + m_voicepack)); + sl.push_back(QString("eflag " + m_flag)); if (!m_isNetTeam) for(int i = 0; i < BINDS_NUMBER; i++) - if(!binds[i].strbind.isEmpty()) - sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action)); + if(!m_binds[i].strbind.isEmpty()) + sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action)); - for (int t = 0; t < numHedgehogs; t++) + for (int t = 0; t < m_numHedgehogs; t++) { sl.push_back(QString("eaddhh %1 %2 %3") - .arg(QString::number(difficulty), + .arg(QString::number(m_difficulty), QString::number(InitHealth), - Hedgehogs[t].Name)); + m_hedgehogs[t].Name)); sl.push_back(QString("ehat %1") - .arg(Hedgehogs[t].Hat)); + .arg(m_hedgehogs[t].Hat)); } return sl; } @@ -283,11 +233,70 @@ bool HWTeam::operator==(const HWTeam& t1) const { - return TeamName==t1.TeamName; + return m_name==t1.m_name; } bool HWTeam::operator<(const HWTeam& t1) const { - return TeamName #include "binds.h" #include "achievements.h" +#include "hwconsts.h" class HWForm; class GameUIConfig; @@ -32,6 +33,7 @@ { }; +// structure for customization and statistics of a single hedgehog struct HWHog { QString Name; @@ -39,45 +41,89 @@ int Rounds, Kills, Deaths, Suicides; }; +// class representing a team class HWTeam { public: + + // constructors HWTeam(const QString & teamname); HWTeam(const QStringList& strLst); HWTeam(); - bool isNetTeam() const; + // file operations + static HWTeam loadFromFile(const QString & teamName); + bool loadFromFile(); + bool deleteFile(); + bool saveToFile(); + bool fileExists(); - QString TeamName; - QString Grave; - QString Fort; - QString Flag; - QString Voicepack; - QString Owner; - int Rounds; - int Wins; - int CampaignProgress; - HWHog Hedgehogs[8]; - unsigned int AchievementProgress[MAX_ACHIEVEMENTS]; - unsigned int difficulty; - BindAction binds[BINDS_NUMBER]; + // attribute getters + unsigned int campaignProgress() const; + QColor color() const; + unsigned int difficulty() const; + QString flag() const; + QString fort() const; + QString grave() const; + const HWHog & hedgehog(unsigned int idx) const; + bool isNetTeam() const; + QString keyBind(unsigned int idx) const; + QString name() const; + unsigned char numHedgehogs() const; + QString owner() const; + QString voicepack() const; - unsigned char numHedgehogs; - QColor teamColor; + // attribute setters + void bindKey(unsigned int idx, const QString & key); + void setColor(const QColor & color); + void setDifficulty(unsigned int level); + void setFlag(const QString & flag); + void setFort(const QString & fort); + void setGrave(const QString & grave); + void setHedgehog(unsigned int idx, HWHog hh); + void setName(const QString & name); + void setNumHedgehogs(unsigned char num); + void setVoicepack(const QString & voicepack); - bool LoadFromFile(); - bool DeleteFile(); - bool SaveToFile(); - bool FileExists(); - void SetToPage(HWForm * hwform); - void GetFromPage(HWForm * hwform); - QStringList TeamGameConfig(quint32 InitHealth) const; + // increments for statistical info + void incRounds(); + void incWins(); + // convert team info into strings for further computation + QStringList teamGameConfig(quint32 InitHealth) const; + + // comparison operators bool operator==(const HWTeam& t1) const; bool operator<(const HWTeam& t1) const; + + + private: + + QString OldTeamName; + + // class members that contain the general team info and settings + QString m_name; + QString m_grave; + QString m_fort; + QString m_flag; + QString m_voicepack; + HWHog m_hedgehogs[HEDGEHOGS_PER_TEAM]; + unsigned int m_difficulty; + BindAction m_binds[BINDS_NUMBER]; + + // class members that contain info for the current game setup + unsigned char m_numHedgehogs; + QColor m_color; bool m_isNetTeam; - QString OldTeamName; + QString m_owner; + + // class members that contain statistics, etc. + unsigned int m_campaignProgress; + unsigned int m_rounds; + unsigned int m_wins; + unsigned int AchievementProgress[MAX_ACHIEVEMENTS]; + }; diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/teamselect.cpp --- a/QTfrontend/teamselect.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,281 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include - -#include -#include -#include -#include -#include - -#include "vertScrollArea.h" -#include "teamselect.h" -#include "teamselhelper.h" -#include "frameTeam.h" - -void TeamSelWidget::addTeam(HWTeam team) -{ - if(team.isNetTeam()) { - framePlaying->addTeam(team, true); - curPlayingTeams.push_back(team); - connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), - this, SLOT(netTeamStatusChanged(const HWTeam&))); - connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), - this, SLOT(hhNumChanged(const HWTeam&))); - dynamic_cast(framePlaying->getTeamWidget(team))->hhNumChanged(); - connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), - this, SLOT(proxyTeamColorChanged(const HWTeam&))); - } else { - frameDontPlaying->addTeam(team, false); - m_curNotPlayingTeams.push_back(team); - if(m_acceptOuter) { - connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), - this, SLOT(pre_changeTeamStatus(HWTeam))); - } else { - connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), - this, SLOT(changeTeamStatus(HWTeam))); - } - } - emit setEnabledGameStart(curPlayingTeams.size()>1); -} - -void TeamSelWidget::setInteractivity(bool interactive) -{ - framePlaying->setInteractivity(interactive); -} - -void TeamSelWidget::hhNumChanged(const HWTeam& team) -{ - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - if(itPlay==curPlayingTeams.end()) - { - qWarning() << QString("hhNumChanged: team '%1' not found").arg(team.TeamName); - return; - } - itPlay->numHedgehogs=team.numHedgehogs; - emit hhogsNumChanged(team); -} - -void TeamSelWidget::proxyTeamColorChanged(const HWTeam& team) -{ - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - if(itPlay==curPlayingTeams.end()) - { - qWarning() << QString("proxyTeamColorChanged: team '%1' not found").arg(team.TeamName); - return; - } - itPlay->teamColor=team.teamColor; - emit teamColorChanged(team); -} - -void TeamSelWidget::changeHHNum(const HWTeam& team) -{ - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - if(itPlay==curPlayingTeams.end()) - { - qWarning() << QString("changeHHNum: team '%1' not found").arg(team.TeamName); - return; - } - itPlay->numHedgehogs=team.numHedgehogs; - - framePlaying->setHHNum(team); -} - -void TeamSelWidget::changeTeamColor(const HWTeam& team) -{ - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - if(itPlay==curPlayingTeams.end()) - { - qWarning() << QString("changeTeamColor: team '%1' not found").arg(team.TeamName); - return; - } - itPlay->teamColor=team.teamColor; - - framePlaying->setTeamColor(team); -} - -void TeamSelWidget::removeNetTeam(const HWTeam& team) -{ - //qDebug() << QString("removeNetTeam: removing team '%1'").arg(team.TeamName); - for(;;) { - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - if(itPlay==curPlayingTeams.end()) - { - qWarning() << QString("removeNetTeam: team '%1' not found").arg(team.TeamName); - break; - } - if(itPlay->isNetTeam()) { - QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); - framePlaying->removeTeam(team); - curPlayingTeams.erase(itPlay); - break; - } - } - emit setEnabledGameStart(curPlayingTeams.size()>1); -} - -void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) -{ - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - -} - -//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) -//{ - //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); -//} - -void TeamSelWidget::changeTeamStatus(HWTeam team) -{ - QList::iterator itDontPlay=std::find(m_curNotPlayingTeams.begin(), m_curNotPlayingTeams.end(), team); - QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); - - bool willBePlaying=itDontPlay!=m_curNotPlayingTeams.end(); - - if(!willBePlaying) { - // playing team => dont playing - m_curNotPlayingTeams.push_back(*itPlay); - emit teamNotPlaying(*itPlay); - curPlayingTeams.erase(itPlay); - } else { - // return if max playing teams reached - if(framePlaying->isFullTeams()) return; - // dont playing team => playing - team=*itDontPlay; // for net team info saving in framePlaying (we have only name with netID from network) - itDontPlay->teamColor=framePlaying->getNextColor(); - curPlayingTeams.push_back(*itDontPlay); - if(!m_acceptOuter) emit teamWillPlay(*itDontPlay); - m_curNotPlayingTeams.erase(itDontPlay); - } - - FrameTeams* pRemoveTeams; - FrameTeams* pAddTeams; - if(!willBePlaying) { - pRemoveTeams=framePlaying; - pAddTeams=frameDontPlaying; - } else { - pRemoveTeams=frameDontPlaying; - pAddTeams=framePlaying; - } - - pAddTeams->addTeam(team, willBePlaying); - pRemoveTeams->removeTeam(team); - if(!team.isNetTeam() && m_acceptOuter && !willBePlaying) { - connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), - this, SLOT(pre_changeTeamStatus(HWTeam))); - } else { - connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), - this, SLOT(changeTeamStatus(HWTeam))); - } - if(willBePlaying) { - connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), - this, SLOT(hhNumChanged(const HWTeam&))); - dynamic_cast(framePlaying->getTeamWidget(team))->hhNumChanged(); - connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), - this, SLOT(proxyTeamColorChanged(const HWTeam&))); - emit teamColorChanged(((TeamShowWidget*)framePlaying->getTeamWidget(team))->getTeam()); - } - - QSize szh=pAddTeams->sizeHint(); - QSize szh1=pRemoveTeams->sizeHint(); - if(szh.isValid() && szh1.isValid()) { - pAddTeams->resize(pAddTeams->size().width(), szh.height()); - pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); - } - - emit setEnabledGameStart(curPlayingTeams.size()>1); -} - -void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int fixedHeight) -{ - VertScrArea* area = new VertScrArea(color); - area->setWidget(pfteams); - mainLayout.addWidget(area, 30); - if (fixedHeight > 0) - { - area->setMinimumHeight(fixedHeight); - area->setMaximumHeight(fixedHeight); - area->setStyleSheet( - "FrameTeams{" - "border: solid;" - "border-width: 1px;" - "border-radius: 16px;" - "border-color: #ffcc00;" - "}" - ); - } -} - -TeamSelWidget::TeamSelWidget(QWidget* parent) : - QGroupBox(parent), mainLayout(this), m_acceptOuter(false) -{ - setTitle(QGroupBox::tr("Playing teams")); - framePlaying = new FrameTeams(); - frameDontPlaying = new FrameTeams(); - - QPalette p; - p.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); - addScrArea(framePlaying, p.color(QPalette::Window).light(105), 250); - addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); -} - -void TeamSelWidget::setAcceptOuter(bool acceptOuter) -{ - m_acceptOuter=acceptOuter; -} - -void TeamSelWidget::resetPlayingTeams(const QList& teamslist) -{ - //for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { - //framePlaying->removeTeam(*it); - //} - framePlaying->resetTeams(); - framePlaying->resetColors(); - curPlayingTeams.clear(); - //for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { - //frameDontPlaying->removeTeam(*it); - //} - frameDontPlaying->resetTeams(); - m_curNotPlayingTeams.clear(); - - foreach(HWTeam team, teamslist) - addTeam(team); -} - -bool TeamSelWidget::isPlaying(HWTeam team) const -{ - return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); -} - -QList TeamSelWidget::getPlayingTeams() const -{ - return curPlayingTeams; -} - -QList TeamSelWidget::getNotPlayingTeams() const -{ - return m_curNotPlayingTeams; -} - -void TeamSelWidget::pre_changeTeamStatus(HWTeam team) -{ - team.teamColor=framePlaying->getNextColor(); - emit acceptRequested(team); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/teamselect.h --- a/QTfrontend/teamselect.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _TEAM_SELECT_INCLUDED -#define _TEAM_SELECT_INCLUDED - -#include -#include -#include -#include - -#include "team.h" - -class TeamSelWidget; -class FrameTeams; -class QFrame; -class QPushButton; - -using namespace std; - -class TeamSelWidget : public QGroupBox -{ - Q_OBJECT - - public: - TeamSelWidget(QWidget* parent); - void setAcceptOuter(bool acceptOuter); - void removeNetTeam(const HWTeam& team); - void resetPlayingTeams(const QList& teamslist); - bool isPlaying(HWTeam team) const; - QList getPlayingTeams() const; - QList getNotPlayingTeams() const; - void setInteractivity(bool interactive); - - public slots: - void addTeam(HWTeam team); - void netTeamStatusChanged(const HWTeam& team); - void changeHHNum(const HWTeam&); - void changeTeamColor(const HWTeam&); - void changeTeamStatus(HWTeam team); - - signals: - void setEnabledGameStart(bool); - void teamWillPlay(HWTeam team); - void teamNotPlaying(const HWTeam& team); - void hhogsNumChanged(const HWTeam&); - void teamColorChanged(const HWTeam&); - void acceptRequested(HWTeam team); - - private slots: - void pre_changeTeamStatus(HWTeam); - void hhNumChanged(const HWTeam& team); - void proxyTeamColorChanged(const HWTeam& team); - - private: - void addScrArea(FrameTeams* pfteams, QColor color, int maxHeight); - FrameTeams* frameDontPlaying; - FrameTeams* framePlaying; - - QVBoxLayout mainLayout; - bool m_acceptOuter; - - QList curPlayingTeams; - QList m_curNotPlayingTeams; -}; - -#endif // _TEAM_SELECT_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/teamselhelper.cpp --- a/QTfrontend/teamselhelper.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include -#include -#include - -#include - -#include "teamselhelper.h" -#include "hwconsts.h" -#include "frameTeam.h" - -void TeamLabel::teamButtonClicked() -{ - emit teamActivated(text()); -} - -TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) : - QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0), - colorButt(0) -{ - QPalette newPalette = palette(); - newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); - setPalette(newPalette); - setAutoFillBackground(true); - - mainLayout.setSpacing(3); - mainLayout.setMargin(0); - this->setMaximumHeight(38); - this->setMinimumHeight(38); - QIcon difficultyIcon=team.isNetTeam() ? - QIcon(QString(":/res/botlevels/net%1.png").arg(m_team.difficulty)) - : QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty)); - - butt = new QPushButton(difficultyIcon, team.TeamName.replace("&","&&"), this); - butt->setFlat(true); - butt->setToolTip(team.Owner); - mainLayout.addWidget(butt); - butt->setStyleSheet("QPushButton{" - "icon-size: 48px;" - "text-align: left;" - "background-color: #0d0544;" - "color: orange;" - "font: bold;" - "border-width: 2px;" - "margin: 6px 0px 6px 0px;" - "}"); - - if(m_isPlaying) { - // team color - colorButt = new QPushButton(this); - colorButt->setMaximumWidth(26); - colorButt->setMinimumHeight(26); - colorButt->setGeometry(0, 0, 26, 26); - - changeTeamColor(); - connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor())); - mainLayout.addWidget(colorButt); - - phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), QImage(":/res/hh25x25grey.png"), this); - connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged())); - phhoger->setHHNum(team.numHedgehogs); - mainLayout.addWidget(phhoger); - } else { - } - - QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam())); - //QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam())); -} - -void TeamShowWidget::setInteractivity(bool interactive) -{ - if(m_team.isNetTeam()) { - butt->setEnabled(interactive); - } - - colorButt->setEnabled(interactive); - phhoger->setEnabled(interactive); -} - -void TeamShowWidget::setHHNum(unsigned int num) -{ - phhoger->setHHNum(num); -} - -void TeamShowWidget::hhNumChanged() -{ - m_team.numHedgehogs=phhoger->getHedgehogsNum(); - emit hhNmChanged(m_team); -} - -void TeamShowWidget::activateTeam() -{ - emit teamStatusChanged(m_team); -} - -/*HWTeamTempParams TeamShowWidget::getTeamParams() const -{ - if(!phhoger) throw; - HWTeamTempParams params; - params.numHedgehogs=phhoger->getHedgehogsNum(); - params.teamColor=colorButt->palette().color(QPalette::Button); - return params; -}*/ - -void TeamShowWidget::changeTeamColor(QColor color) -{ - FrameTeams* pOurFrameTeams=dynamic_cast(parentWidget()); - if(!color.isValid()) { - if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { - pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); - } - color=*pOurFrameTeams->currentColor; - } else { - // set according color iterator - pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(), - pOurFrameTeams->availableColors.end(), color); - if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { - // error condition - pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); - } - } - - colorButt->setStyleSheet(QString("QPushButton{" - "background-color: %1;" - "border-width: 1px;" - "border-radius: 2px;" - "}").arg(pOurFrameTeams->currentColor->name())); - - m_team.teamColor=color; - emit teamColorChanged(m_team); -} - -HWTeam TeamShowWidget::getTeam() const -{ - return m_team; -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/teamselhelper.h --- a/QTfrontend/teamselhelper.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2007 Igor Ulyanov - * Copyright (c) 2007-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _TEAMSEL_HELPER_INCLUDED -#define _TEAMSEL_HELPER_INCLUDED - -#include -#include -#include -#include - -#include "teamselect.h" -#include "hedgehogerWidget.h" - -class TeamLabel : public QLabel -{ - Q_OBJECT - - public: - TeamLabel(const QString& inp_str) : QLabel(inp_str) {}; - - signals: - void teamActivated(QString team_name); - - public slots: - void teamButtonClicked(); - -}; - -class TeamShowWidget : public QWidget -{ - Q_OBJECT - - public slots: - void changeTeamColor(QColor color=QColor()); - void hhNumChanged(); - - private slots: - void activateTeam(); - - public: - TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent); - void setPlaying(bool isPlaying); - void setHHNum(unsigned int num); - void setInteractivity(bool interactive); - HWTeam getTeam() const; - - private: - TeamShowWidget(); - QHBoxLayout mainLayout; - HWTeam m_team; - bool m_isPlaying; - CHedgehogerWidget* phhoger; - QPushButton* colorButt; - QPushButton* butt; -// QPushButton* bText; - - signals: - void teamStatusChanged(HWTeam team); - void hhNmChanged(const HWTeam&); - void teamColorChanged(const HWTeam&); -}; - -#endif // _TEAMSEL_HELPER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/themesmodel.cpp --- a/QTfrontend/themesmodel.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ - -#include "themesmodel.h" - -ThemesModel::ThemesModel(QStringList themes, QObject *parent) : - QAbstractListModel(parent) -{ -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - m_data.reserve(themes.size()); -#endif - - foreach(QString theme, themes) - { - m_data.append(QHash()); - m_data.last().insert(Qt::DisplayRole, theme); - } -} - -int ThemesModel::rowCount(const QModelIndex &parent) const -{ - if(parent.isValid()) - return 0; - else - return m_data.size(); -} - -QVariant ThemesModel::data(const QModelIndex &index, int role) const -{ - if(index.column() > 0 || index.row() >= m_data.size()) - return QVariant(); - else - return m_data.at(index.row()).value(role); -} - -bool ThemesModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if(index.column() > 0 || index.row() >= m_data.size()) - return false; - else - { - m_data[index.row()].insert(role, value); - - return true; - } - -} - - - - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/themesmodel.h --- a/QTfrontend/themesmodel.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#ifndef THEMESMODEL_H -#define THEMESMODEL_H - -#include -#include -#include - -class ThemesModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit ThemesModel(QStringList themes, QObject *parent = 0); - - int rowCount(const QModelIndex &parent = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role) const; - bool setData(const QModelIndex &index, const QVariant &value, - int role = Qt::EditRole); - -signals: - -public slots: - -private: - - QList > m_data; -}; - -#endif // THEMESMODEL_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/togglebutton.cpp --- a/QTfrontend/togglebutton.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2009 Kristian Lehmann - * Copyright (c) 2009-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "togglebutton.h" - -ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img) - : QPushButton(parent) -{ - setCheckable(true); - - QPixmap pm(":/res/btnDisabled.png"); - QPainter * painter = new QPainter(); - - pmChecked.load(img); - pmDisabled.load(img); - - setMaximumWidth(pmChecked.width() + 6); - - painter->begin(&pmDisabled); - painter->drawPixmap(pmDisabled.rect(), pm); - painter->end(); - - setIconSize(pmDisabled.size()); - setIcon(pmDisabled); - - connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool))); -} - -ToggleButtonWidget::~ToggleButtonWidget() -{ -} - -void ToggleButtonWidget::eventToggled(bool checked) -{ - setIcon(checked ? pmChecked : pmDisabled); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/togglebutton.h --- a/QTfrontend/togglebutton.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2009 Kristian Lehmann - * Copyright (c) 2009-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef TOGGLEBUTTONWIDGET_H -#define TOGGLEBUTTONWIDGET_H - -#include -#include -#include -#include -#include - -class ToggleButtonWidget : public QPushButton -{ - Q_OBJECT -public: - ToggleButtonWidget(QWidget * parent, QString img); - ~ToggleButtonWidget(); -private: - QPixmap pmChecked; - QPixmap pmDisabled; -private slots: - void eventToggled(bool checked); -}; - -#endif // TOGGLEBUTTONWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/dialog/input_ip.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/dialog/input_ip.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,68 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "input_ip.h" + +HWHostPortDialog::HWHostPortDialog(QWidget* parent) : QDialog(parent) +{ + QGridLayout * layout = new QGridLayout(this); + + QLabel * lbHost = new QLabel(this); + lbHost->setText(QLabel::tr("Host:")); + layout->addWidget(lbHost, 0, 0); + + QLabel * lbPort = new QLabel(this); + lbPort->setText(QLabel::tr("Port:")); + layout->addWidget(lbPort, 1, 0); + + leHost = new QLineEdit(this); + layout->addWidget(leHost, 0, 1, 1, 2); + + sbPort = new QSpinBox(this); + sbPort->setMinimum(0); + sbPort->setMaximum(65535); + layout->addWidget(sbPort, 1, 1, 1, 2); + + pbDefault = new QPushButton(this); + pbDefault->setText(QPushButton::tr("default")); + layout->addWidget(pbDefault, 1, 3); + + pbOK = new QPushButton(this); + pbOK->setText(QPushButton::tr("OK")); + pbOK->setDefault(true); + layout->addWidget(pbOK, 3, 1); + + pbCancel = new QPushButton(this); + pbCancel->setText(QPushButton::tr("Cancel")); + layout->addWidget(pbCancel, 3, 2); + + connect(pbOK, SIGNAL(clicked()), this, SLOT(accept())); + connect(pbCancel, SIGNAL(clicked()), this, SLOT(reject())); + connect(pbDefault, SIGNAL(clicked()), this, SLOT(setDefaultPort())); +} + +void HWHostPortDialog::setDefaultPort() +{ + sbPort->setValue(46631); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/dialog/input_ip.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/dialog/input_ip.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,49 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + + +#ifndef INPUT_IP_H +#define INPUT_IP_H + +#include +#include + +class QLineEdit; +class QSpinBox; +class QPushButton; + +class HWHostPortDialog : public QDialog +{ + Q_OBJECT +public: + HWHostPortDialog(QWidget* parent = 0); + + QLineEdit* leHost; + QSpinBox* sbPort; + +private: + QPushButton* pbOK; + QPushButton* pbCancel; + QPushButton * pbDefault; + +private slots: + void setDefaultPort(); +}; + + +#endif // INPUT_IP_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageadmin.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageadmin.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,112 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "pageadmin.h" +#include "chatwidget.h" + +QLayout * PageAdmin::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + // 0 + pbAsk = addButton(tr("Fetch data"), pageLayout, 0, 0, 1, 3); + + // 1 + QLabel * lblSMN = new QLabel(this); + lblSMN->setText(tr("Server message for latest version:")); + pageLayout->addWidget(lblSMN, 1, 0); + + leServerMessageNew = new QLineEdit(this); + pageLayout->addWidget(leServerMessageNew, 1, 1); + + // 2 + QLabel * lblSMO = new QLabel(this); + lblSMO->setText(tr("Server message for previous versions:")); + pageLayout->addWidget(lblSMO, 2, 0); + + leServerMessageOld = new QLineEdit(this); + pageLayout->addWidget(leServerMessageOld, 2, 1); + + // 3 + QLabel * lblP = new QLabel(this); + lblP->setText(tr("Latest version protocol number:")); + pageLayout->addWidget(lblP, 3, 0); + + sbProtocol = new QSpinBox(this); + pageLayout->addWidget(sbProtocol, 3, 1); + + // 4 + QLabel * lblPreview = new QLabel(this); + lblPreview->setText(tr("MOTD preview:")); + pageLayout->addWidget(lblPreview, 4, 0); + + tb = new QTextBrowser(this); + tb->setOpenExternalLinks(true); + tb->document()->setDefaultStyleSheet(HWChatWidget::STYLE); + pageLayout->addWidget(tb, 4, 1, 1, 2); + + // 5 + pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), pageLayout, 5, 0); + + // 6 + pbSetSM = addButton(tr("Set data"), pageLayout, 6, 0, 1, 3); + + return pageLayout; +} + +void PageAdmin::connectSignals() +{ + connect(pbAsk, SIGNAL(clicked()), this, SIGNAL(askServerVars())); + connect(leServerMessageNew, SIGNAL(textEdited(const QString &)), tb, SLOT(setHtml(const QString &))); + connect(leServerMessageOld, SIGNAL(textEdited(const QString &)), tb, SLOT(setHtml(const QString &))); + connect(pbClearAccountsCache, SIGNAL(clicked()), this, SIGNAL(clearAccountsCache())); + connect(pbSetSM, SIGNAL(clicked()), this, SLOT(smChanged())); +} + +PageAdmin::PageAdmin(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageAdmin::smChanged() +{ + emit setServerMessageNew(leServerMessageNew->text()); + emit setServerMessageOld(leServerMessageOld->text()); + emit setProtocol(sbProtocol->value()); +} + +void PageAdmin::serverMessageNew(const QString & str) +{ + leServerMessageNew->setText(str); +} + +void PageAdmin::serverMessageOld(const QString & str) +{ + leServerMessageOld->setText(str); +} +void PageAdmin::protocol(int proto) +{ + sbProtocol->setValue(proto); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageadmin.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageadmin.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,60 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_ADMIN_H +#define PAGE_ADMIN_H + +#include "AbstractPage.h" + +class PageAdmin : public AbstractPage +{ + Q_OBJECT + +public: + PageAdmin(QWidget* parent = 0); + +public slots: + void serverMessageNew(const QString & str); + void serverMessageOld(const QString & str); + void protocol(int proto); + +signals: + void setServerMessageNew(const QString & str); + void setServerMessageOld(const QString & str); + void setProtocol(int proto); + void askServerVars(); + void clearAccountsCache(); + +protected: + QLayout * bodyLayoutDefinition(); + void connectSignals(); + +private: + QLineEdit * leServerMessageNew; + QLineEdit * leServerMessageOld; + QPushButton * pbSetSM; + QPushButton * pbAsk; + QSpinBox * sbProtocol; + QTextBrowser * tb; + QPushButton * pbClearAccountsCache; + +private slots: + void smChanged(); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagecampaign.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagecampaign.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,53 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include "pagecampaign.h" + +QLayout * PageCampaign::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 2); + pageLayout->setColumnStretch(2, 1); + pageLayout->setRowStretch(0, 1); + pageLayout->setRowStretch(3, 1); + + CBSelect = new QComboBox(this); + CBTeam = new QComboBox(this); + + pageLayout->addWidget(CBTeam, 1, 1); + pageLayout->addWidget(CBSelect, 2, 1); + + BtnStartCampaign = new QPushButton(this); + BtnStartCampaign->setFont(*font14); + BtnStartCampaign->setText(QPushButton::tr("Go!")); + pageLayout->addWidget(BtnStartCampaign, 2, 2); + + return pageLayout; +} + +PageCampaign::PageCampaign(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagecampaign.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagecampaign.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,39 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_CAMPAIGN_H +#define PAGE_CAMPAIGN_H + +#include "AbstractPage.h" + +class PageCampaign : public AbstractPage +{ + Q_OBJECT + +public: + PageCampaign(QWidget* parent = 0); + + QPushButton *BtnStartCampaign; + QComboBox *CBSelect; + QComboBox *CBTeam; + +protected: + QLayout * bodyLayoutDefinition(); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageconnecting.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageconnecting.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,43 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "pageconnecting.h" + +QLayout * PageConnecting::bodyLayoutDefinition() +{ + QVBoxLayout * pageLayout = new QVBoxLayout(); + + QLabel * lblConnecting = new QLabel(this); + lblConnecting->setText(tr("Connecting...")); + pageLayout->addWidget(lblConnecting); + + return pageLayout; +} + +void PageConnecting::connectSignals() +{ + connect(this, SIGNAL(goBack()), this, SIGNAL(cancelConnection())); +} + +PageConnecting::PageConnecting(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageconnecting.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageconnecting.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,39 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_CONNECTING_H +#define PAGE_CONNECTING_H + +#include "AbstractPage.h" + +class PageConnecting : public AbstractPage +{ + Q_OBJECT + +public: + PageConnecting(QWidget* parent = 0); + +signals: + void cancelConnection(); + +protected: + QLayout * bodyLayoutDefinition(); + void connectSignals(); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagedata.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagedata.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,229 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pagedata.h" +#include "databrowser.h" +#include "hwconsts.h" + +#include "quazip.h" +#include "quazipfile.h" + +QLayout * PageDataDownload::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 1); + pageLayout->setColumnStretch(2, 1); + + web = new DataBrowser(this); + pageLayout->addWidget(web, 0, 0, 1, 3); + + progressBarsLayout = new QVBoxLayout(); + pageLayout->addLayout(progressBarsLayout, 1, 0, 1, 3); + return pageLayout; +} + +void PageDataDownload::connectSignals() +{ + connect(web, SIGNAL(anchorClicked(QUrl)), this, SLOT(request(const QUrl&))); +} + +PageDataDownload::PageDataDownload(QWidget* parent) : AbstractPage(parent) +{ + initPage(); + + web->setOpenLinks(false); + fetchList(); +} + +void PageDataDownload::request(const QUrl &url) +{ + QUrl finalUrl; + if(url.host().isEmpty()) + finalUrl = QUrl("http://www.hedgewars.org" + url.path()); + else + finalUrl = url; + + if(url.path().endsWith(".zip")) + { + qWarning() << "Download Request" << url.toString(); + QString fileName = QFileInfo(url.toString()).fileName(); + + QNetworkRequest newRequest(finalUrl); + newRequest.setAttribute(QNetworkRequest::User, fileName); + + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QNetworkReply *reply = manager->get(newRequest); + connect(reply, SIGNAL(finished()), this, SLOT(fileDownloaded())); + connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); + + QProgressBar *progressBar = new QProgressBar(this); + progressBarsLayout->addWidget(progressBar); + progressBars.insert(reply, progressBar); + } else + { + qWarning() << "Page Request" << url.toString(); + + QNetworkRequest newRequest(finalUrl); + + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QNetworkReply *reply = manager->get(newRequest); + connect(reply, SIGNAL(finished()), this, SLOT(pageDownloaded())); + } +} + + +void PageDataDownload::pageDownloaded() +{ + QNetworkReply * reply = qobject_cast(sender()); + + if(reply) + { + QString html = QString::fromUtf8(reply->readAll()); + int begin = html.indexOf(""); + int end = html.indexOf(""); + if(begin != -1 && begin < end) + { + html.truncate(end); + html.remove(0, begin); + } + web->setHtml(html); + } +} + +void PageDataDownload::fileDownloaded() +{ + QNetworkReply * reply = qobject_cast(sender()); + + if(reply) + { + QByteArray fileContents = reply->readAll(); + QProgressBar *progressBar = progressBars.value(reply, 0); + + if(progressBar) + { + progressBars.remove(reply); + progressBar->deleteLater(); + } + + extractDataPack(&fileContents); + } +} + +void PageDataDownload::downloadProgress(qint64 bytesRecieved, qint64 bytesTotal) +{ + QNetworkReply * reply = qobject_cast(sender()); + + if(reply) + { + QProgressBar *progressBar = progressBars.value(reply, 0); + + if(progressBar) + { + progressBar->setValue(bytesRecieved); + progressBar->setMaximum(bytesTotal); + } + } +} + +void PageDataDownload::fetchList() +{ + request(QUrl("http://hedgewars.org/content.html")); +} + +bool PageDataDownload::extractDataPack(QByteArray * buf) +{ + QBuffer buffer; + buffer.setBuffer(buf); + + QuaZip zip; + zip.setIoDevice(&buffer); + if(!zip.open(QuaZip::mdUnzip)) + { + qWarning("testRead(): zip.open(): %d", zip.getZipError()); + return false; + } + + QuaZipFile file(&zip); + + QDir extractDir(*cfgdir); + extractDir.cd("Data"); + + for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) + { + if(!file.open(QIODevice::ReadOnly)) + { + qWarning("file.open(): %d", file.getZipError()); + return false; + } + + + QString fileName = file.getActualFileName(); + QString filePath = extractDir.filePath(fileName); + if (fileName.endsWith("/")) + { + QFileInfo fi(filePath); + QDir().mkpath(fi.filePath()); + } else + { + qDebug() << "Extracting" << filePath; + QFile out(filePath); + if(!out.open(QFile::WriteOnly)) + { + qWarning() << "out.open():" << out.errorString(); + return false; + } + + out.write(file.readAll()); + + out.close(); + + if(file.getZipError() != UNZ_OK) { + qWarning("file.getFileName(): %d", file.getZipError()); + return false; + } + + if(!file.atEnd()) { + qWarning("read all but not EOF"); + return false; + } + } + + file.close(); + + if(file.getZipError()!=UNZ_OK) { + qWarning("file.close(): %d", file.getZipError()); + return false; + } + } + + zip.close(); + + return true; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagedata.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagedata.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,59 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_DATA_H +#define PAGE_DATA_H + +#include +#include "AbstractPage.h" + +class DataBrowser; +class QProgressBar; +class QNetworkReply; +class QVBoxLayout; + +class PageDataDownload : public AbstractPage +{ + Q_OBJECT + +public: + PageDataDownload(QWidget* parent = 0); + +public slots: + void fetchList(); + +protected: + QLayout * bodyLayoutDefinition(); + void connectSignals(); + +private: + DataBrowser *web; + QHash progressBars; + QVBoxLayout *progressBarsLayout; + + bool extractDataPack(QByteArray * buf); + +private slots: + void request(const QUrl &url); + + void pageDownloaded(); + void fileDownloaded(); + void downloadProgress(qint64, qint64); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagedrawmap.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagedrawmap.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,69 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include "pagedrawmap.h" +#include "drawmapwidget.h" + + +QLayout * PageDrawMap::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + pbUndo = addButton(tr("Undo"), pageLayout, 0, 0); + pbClear = addButton(tr("Clear"), pageLayout, 1, 0); + pbLoad = addButton(tr("Load"), pageLayout, 2, 0); + pbSave = addButton(tr("Save"), pageLayout, 3, 0); + + drawMapWidget = new DrawMapWidget(this); + pageLayout->addWidget(drawMapWidget, 0, 1, 5, 1); + + return pageLayout; +} + +void PageDrawMap::connectSignals() +{ + connect(pbUndo, SIGNAL(clicked()), drawMapWidget, SLOT(undo())); + connect(pbClear, SIGNAL(clicked()), drawMapWidget, SLOT(clear())); + connect(pbLoad, SIGNAL(clicked()), this, SLOT(load())); + connect(pbSave, SIGNAL(clicked()), this, SLOT(save())); +} + +PageDrawMap::PageDrawMap(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageDrawMap::load() +{ + QString fileName = QFileDialog::getOpenFileName(NULL, tr("Load drawn map"), ".", tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)"); + + if(!fileName.isEmpty()) + drawMapWidget->load(fileName); +} + +void PageDrawMap::save() +{ + QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save drawn map"), ".", tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)"); + + if(!fileName.isEmpty()) + drawMapWidget->save(fileName); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagedrawmap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagedrawmap.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,51 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_DRAWMAP_H +#define PAGE_DRAWMAP_H + +#include "AbstractPage.h" + +class DrawMapWidget; + +class PageDrawMap : public AbstractPage +{ + Q_OBJECT + +public: + PageDrawMap(QWidget* parent = 0); + + DrawMapWidget * drawMapWidget; + +protected: + QLayout * bodyLayoutDefinition(); + void connectSignals(); + +private: + QPushButton * pbUndo; + QPushButton * pbClear; + QPushButton * pbLoad; + QPushButton * pbSave; + +private slots: + void load(); + void save(); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageeditteam.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageeditteam.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,523 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pageeditteam.h" +#include "sdlkeys.h" +#include "SquareLabel.h" +#include "hats.h" +#include "HWApplication.h" + +QLayout * PageEditTeam::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + QTabWidget * tbw = new QTabWidget(); + QWidget * page1 = new QWidget(this); + QWidget * page2 = new QWidget(this); + tbw->addTab(page1, tr("General")); + tbw->addTab(page2, tr("Advanced")); + pageLayout->addWidget(tbw, 0, 0, 1, 3); + + QHBoxLayout * page1Layout = new QHBoxLayout(page1); + page1Layout->setAlignment(Qt::AlignTop); + QGridLayout * page2Layout = new QGridLayout(page2); + +// ====== Page 1 ====== + QVBoxLayout * vbox1 = new QVBoxLayout(); + QVBoxLayout * vbox2 = new QVBoxLayout(); + page1Layout->addLayout(vbox1); + page1Layout->addLayout(vbox2); + + GBoxHedgehogs = new QGroupBox(this); + GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); + GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); + + HatsModel * hatsModel = new HatsModel(GBoxHedgehogs); + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) + { + HHHats[i] = new QComboBox(GBoxHedgehogs); + HHHats[i]->setModel(hatsModel); + HHHats[i]->setIconSize(QSize(32, 37)); + //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); + //HHHats[i]->setModelColumn(1); + //HHHats[i]->setMinimumWidth(132); + GBHLayout->addWidget(HHHats[i], i, 0); + + HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); + HHNameEdit[i]->setMaxLength(64); + HHNameEdit[i]->setMinimumWidth(120); + GBHLayout->addWidget(HHNameEdit[i], i, 1); + + btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i, 3, true); + } + + btnRandomTeam = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false); + + vbox1->addWidget(GBoxHedgehogs); + + GBoxTeam = new QGroupBox(this); + GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); + GBoxTeam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + QGridLayout * GBTLayout = new QGridLayout(GBoxTeam); + QLabel * tmpLabel = new QLabel(GBoxTeam); + tmpLabel->setText(QLabel::tr("Name")); + GBTLayout->addWidget(tmpLabel, 0, 0); + tmpLabel = new QLabel(GBoxTeam); + tmpLabel->setText(QLabel::tr("Type")); + GBTLayout->addWidget(tmpLabel, 1, 0); + tmpLabel = new QLabel(GBoxTeam); + tmpLabel->setText(QLabel::tr("Grave")); + GBTLayout->addWidget(tmpLabel, 2, 0); + tmpLabel = new QLabel(GBoxTeam); + tmpLabel->setText(QLabel::tr("Flag")); + GBTLayout->addWidget(tmpLabel, 3, 0); + tmpLabel = new QLabel(GBoxTeam); + tmpLabel->setText(QLabel::tr("Voice")); + GBTLayout->addWidget(tmpLabel, 4, 0); + + TeamNameEdit = new QLineEdit(GBoxTeam); + TeamNameEdit->setMaxLength(64); + GBTLayout->addWidget(TeamNameEdit, 0, 1); + vbox2->addWidget(GBoxTeam); + + CBTeamLvl = new QComboBox(GBoxTeam); + CBTeamLvl->setIconSize(QSize(48, 48)); + CBTeamLvl->addItem(QIcon(":/res/botlevels/0.png"), QComboBox::tr("Human")); + for(int i = 5; i > 0; i--) + CBTeamLvl->addItem( + QIcon(QString(":/res/botlevels/%1.png").arg(6 - i)), + QString("%1 %2").arg(QComboBox::tr("Level")).arg(i) + ); + GBTLayout->addWidget(CBTeamLvl, 1, 1); + + CBGrave = new QComboBox(GBoxTeam); + CBGrave->setMaxCount(65535); + CBGrave->setIconSize(QSize(32, 32)); + GBTLayout->addWidget(CBGrave, 2, 1); + + CBFlag = new QComboBox(GBoxTeam); + CBFlag->setMaxCount(65535); + CBFlag->setIconSize(QSize(22, 15)); + GBTLayout->addWidget(CBFlag, 3, 1); + + QHBoxLayout * hbox = new QHBoxLayout(); + CBVoicepack = new QComboBox(GBoxTeam); + + hbox->addWidget(CBVoicepack, 100); + btnTestSound = addButton(":/res/PlaySound.png", hbox, 1, true); + hbox->setStretchFactor(btnTestSound, 1); + + GBTLayout->addLayout(hbox, 4, 1); + + GBoxFort = new QGroupBox(this); + GBoxFort->setTitle(QGroupBox::tr("Fort")); + QGridLayout * GBFLayout = new QGridLayout(GBoxFort); + CBFort = new QComboBox(GBoxFort); + CBFort->setMaxCount(65535); + GBFLayout->addWidget(CBFort, 0, 0); + FortPreview = new SquareLabel(GBoxFort); + FortPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + FortPreview->setMinimumSize(128, 128); + FortPreview->setPixmap(QPixmap()); + // perhaps due to handling its own paintevents, SquareLabel doesn't play nice with the stars + //FortPreview->setAttribute(Qt::WA_PaintOnScreen, true); + GBFLayout->addWidget(FortPreview, 1, 0); + vbox2->addWidget(GBoxFort); + + vbox1->addStretch(); + vbox2->addStretch(); + +// ====== Page 2 ====== + GBoxBinds = new QGroupBox(this); + GBoxBinds->setTitle(QGroupBox::tr("Key binds")); + QGridLayout * GBBLayout = new QGridLayout(GBoxBinds); + BindsBox = new QToolBox(GBoxBinds); + BindsBox->setLineWidth(0); + GBBLayout->addWidget(BindsBox); + page2Layout->addWidget(GBoxBinds, 0, 0); + + quint16 i = 0; + quint16 num = 0; + QWidget * curW = NULL; + QGridLayout * pagelayout = NULL; + QLabel* l = NULL; + while (i < BINDS_NUMBER) { + if(cbinds[i].category != NULL) + { + if(curW != NULL) + { + l = new QLabel(curW); + l->setText(""); + pagelayout->addWidget(l, num++, 0, 1, 2); + } + curW = new QWidget(this); + BindsBox->addItem(curW, HWApplication::translate("binds (categories)", cbinds[i].category)); + pagelayout = new QGridLayout(curW); + num = 0; + } + if(cbinds[i].description != NULL) + { + l = new QLabel(curW); + l->setText((num > 0 ? QString("\n") : QString("")) + HWApplication::translate("binds (descriptions)", cbinds[i].description)); + pagelayout->addWidget(l, num++, 0, 1, 2); + } + + l = new QLabel(curW); + l->setText(HWApplication::translate("binds", cbinds[i].name)); + l->setAlignment(Qt::AlignRight); + pagelayout->addWidget(l, num, 0); + CBBind[i] = new QComboBox(curW); + for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) + CBBind[i]->addItem(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), sdlkeys[j][0]); + pagelayout->addWidget(CBBind[i++], num++, 1); + } + + return pageLayout; +} + +QLayout * PageEditTeam::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout(); + + btnSave = addButton(":/res/Save.png", bottomLayout, 0, true);; + btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}"); + bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom); + + return bottomLayout; +} + +void PageEditTeam::connectSignals() +{ + connect(btnSave, SIGNAL(clicked()), this, SLOT(saveTeam())); + + signalMapper1 = new QSignalMapper(this); + signalMapper2 = new QSignalMapper(this); + + connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int))); + connect(signalMapper2, SIGNAL(mapped(int)), this, SLOT(setRandomName(int))); + + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) + { + connect(HHNameEdit[i], SIGNAL(editingFinished()), signalMapper1, SLOT(map())); + signalMapper1->setMapping(HHNameEdit[i], i); + + connect(btnRandomHogName[i], SIGNAL(clicked()), signalMapper2, SLOT(map())); + signalMapper2->setMapping(btnRandomHogName[i], i); + } + + connect(btnRandomTeam, SIGNAL(clicked()), this, SLOT(setRandomNames())); + + connect(btnTestSound, SIGNAL(clicked()), this, SLOT(testSound())); + + connect(CBFort, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(CBFort_activated(const QString &))); +} + +PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) : + AbstractPage(parent) +{ + initPage(); + + m_playerHash = "0000000000000000000000000000000000000000"; + mySdli = sdli; + + QDir tmpdir; + QStringList list; + tmpdir.cd(cfgdir->absolutePath()); + if (tmpdir.cd("Data/Sounds/voices")) + { + list = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); + CBVoicepack->addItems(list); + } + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Sounds/voices"); + QStringList tmplist = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); + QStringList tmplist2; + foreach (const QString & line, tmplist) + { + if (!list.contains(line,Qt::CaseInsensitive)) + tmplist2.append(line); + } + + CBVoicepack->addItems(tmplist2); + + QStringList userforts; + tmpdir.cd(cfgdir->absolutePath()); + if (tmpdir.cd("Data/Forts")) + { + tmpdir.setFilter(QDir::Files); + userforts = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); + CBFort->addItems(userforts); + } + + tmpdir.cd("../Graphics/Graves"); + QStringList userlist = tmpdir.entryList(QStringList("*.png")); + for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) + { + QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Graves/" + *it); + QIcon icon(pix.copy(0, 0, 32, 32)); + CBGrave->addItem(icon, QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1")); + } + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Forts"); + tmpdir.setFilter(QDir::Files); + + tmplist = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); + QStringList dataforts; + foreach (const QString & line, tmplist) + { + if (!userforts.contains(line,Qt::CaseInsensitive)) + dataforts.append(line); + } + + CBFort->addItems(dataforts); + + tmpdir.cd("../Graphics/Graves"); + QStringList datalist = tmpdir.entryList(QStringList("*.png")); + foreach (const QString & line, datalist) + { + if (userlist.contains(line,Qt::CaseInsensitive)) continue; + QPixmap pix(datadir->absolutePath() + "/Graphics/Graves/" + line); + QIcon icon(pix.copy(0, 0, 32, 32)); + QString grave = line; + grave = grave.replace(QRegExp("^(.*)\\.png"), "\\1"); + CBGrave->addItem(icon, grave); + } + + // add the default flag + CBFlag->addItem(QIcon(QPixmap(datadir->absolutePath() + "/Graphics/Flags/hedgewars.png").copy(0, 0, 22, 15)), "Hedgewars", "hedgewars"); + CBFlag->insertSeparator(CBFlag->count()); + + tmpdir.cd(cfgdir->absolutePath()); + tmpdir.cd("Data/Graphics/Flags"); + userlist = tmpdir.entryList(QStringList("*.png")); + + // add all country flags + foreach (const QString & line, userlist) + { + QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + line); + QIcon icon(pix.copy(0, 0, 22, 15)); + // TODO improve readablility + if(line.compare("cpu.png") && line.compare("hedgewars.png") && (line.indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags + { + QString flag = line; + flag = flag.replace(QRegExp("^(.*)\\.png"), "\\1"); + CBFlag->addItem(icon, flag.replace("_", " "), flag); + } + } + + CBFlag->insertSeparator(CBFlag->count()); + + // add all community flags + for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) + { + QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it); + QIcon icon(pix.copy(0, 0, 22, 15)); + if(it->indexOf("cm_") > -1) // skip non community flags this time + { + QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); + CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); + } + } + + CBFlag->insertSeparator(CBFlag->count()); + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Graphics/Flags"); + datalist = tmpdir.entryList(QStringList("*.png")); + + // add all country flags + for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) + { + if (userlist.contains(*it,Qt::CaseInsensitive)) continue; + QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); + QIcon icon(pix.copy(0, 0, 22, 15)); + if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags + { + QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); + CBFlag->addItem(icon, QString(flag).replace("_", " "), flag); + } + } + + CBFlag->insertSeparator(CBFlag->count()); + + // add all community flags + for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) + { + if (userlist.contains(*it,Qt::CaseInsensitive)) continue; + QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); + QIcon icon(pix.copy(0, 0, 22, 15)); + if(it->indexOf("cm_") > -1) // skip non community flags this time + { + QString flag = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); + CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); + } + } +} + +void PageEditTeam::fixHHname(int idx) +{ + HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed()); + + if (HHNameEdit[idx]->text().isEmpty()) + HHNameEdit[idx]->setText(QLineEdit::tr("hedgehog %1").arg(idx+1)); +} + +void PageEditTeam::CBFort_activated(const QString & fortname) +{ + QFile tmp; + tmp.setFileName(cfgdir->absolutePath() + "/Data/Forts/" + fortname + "L.png"); + if (!tmp.exists()) tmp.setFileName(datadir->absolutePath() + "/Forts/" + fortname + "L.png"); + QPixmap pix(QFileInfo(tmp).absoluteFilePath()); + FortPreview->setPixmap(pix); +} + +void PageEditTeam::testSound() +{ + Mix_Chunk *sound; + QDir tmpdir; + mySdli->SDLMusicInit(); + + tmpdir.cd(cfgdir->absolutePath()); + if (!tmpdir.cd("Data/Sounds/voices/"+CBVoicepack->currentText())) + { + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Sounds/voices"); + tmpdir.cd(CBVoicepack->currentText()); + } + + QStringList list = tmpdir.entryList(QStringList() << "Illgetyou.ogg" << "Incoming.ogg" << "Stupid.ogg" << "Coward.ogg" << "Firstblood.ogg", QDir::Files); + if (list.size()) { + sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData()); + Mix_PlayChannel(-1, sound, 0); + } +} + +void PageEditTeam::createTeam(const QString & name, const QString & playerHash) +{ + m_playerHash = playerHash; + HWTeam newTeam(name); + loadTeam(newTeam); +} + +void PageEditTeam::editTeam(const QString & name, const QString & playerHash) +{ + m_playerHash = playerHash; + HWTeam team(name); + team.loadFromFile(); + loadTeam(team); +} + +void PageEditTeam::deleteTeam(const QString & name) +{ + QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel, this); + + if (reallyDelete.exec() == QMessageBox::Ok) + HWTeam(name).deleteFile(); +} + +void PageEditTeam::setRandomNames() +{ + HWTeam team = data(); + HWNamegen::teamRandomNames(team, true); + loadTeam(team); +} + +void PageEditTeam::setRandomName(int hh_index) +{ + HWTeam team = data(); + HWNamegen::teamRandomName(team,hh_index); + loadTeam(team); +} + +void PageEditTeam::loadTeam(const HWTeam & team) +{ + TeamNameEdit->setText(team.name()); + CBTeamLvl->setCurrentIndex(team.difficulty()); + + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) + { + HWHog hh = team.hedgehog(i); + + HHNameEdit[i]->setText(hh.Name); + + if (hh.Hat.startsWith("Reserved")) + hh.Hat = hh.Hat.remove(0,40); + + HHHats[i]->setCurrentIndex(HHHats[i]->findData(hh.Hat, Qt::DisplayRole)); + } + + CBGrave->setCurrentIndex(CBGrave->findText(team.grave())); + CBFlag->setCurrentIndex(CBFlag->findData(team.flag())); + + CBFort->setCurrentIndex(CBFort->findText(team.fort())); + CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack())); + + for(int i = 0; i < BINDS_NUMBER; i++) + { + CBBind[i]->setCurrentIndex(CBBind[i]->findData(team.keyBind(i))); + } +} + +HWTeam PageEditTeam::data() +{ + HWTeam team(TeamNameEdit->text()); + team.setDifficulty(CBTeamLvl->currentIndex()); + + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) + { + HWHog hh; + hh.Name = HHNameEdit[i]->text(); + hh.Hat = HHHats[i]->currentText(); + + if (hh.Hat.startsWith("Reserved")) + hh.Hat = "Reserved"+m_playerHash+hh.Hat.remove(0,9); + + team.setHedgehog(i,hh); + } + + team.setGrave(CBGrave->currentText()); + team.setFort(CBFort->currentText()); + team.setVoicepack(CBVoicepack->currentText()); + team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString()); + + for(int i = 0; i < BINDS_NUMBER; i++) + { + team.bindKey(i,CBBind[i]->itemData(CBBind[i]->currentIndex()).toString()); + } + + return team; +} + +void PageEditTeam::saveTeam() +{ + data().saveToFile(); + emit teamEdited(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageeditteam.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageeditteam.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,94 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_EDITTEAM_H +#define PAGE_EDITTEAM_H + +#include "AbstractPage.h" +#include "binds.h" +#include "hwconsts.h" +#include "namegen.h" +#include "SDLs.h" + +#include "team.h" + +class SquareLabel; + +class PageEditTeam : public AbstractPage +{ + Q_OBJECT + +public: + PageEditTeam(QWidget* parent, SDLInteraction * sdli); + + void createTeam(const QString & name, const QString & playerHash); + void editTeam(const QString & name, const QString & playerHash); + void deleteTeam(const QString & name); + +signals: + void teamEdited(); + +public slots: + void CBFort_activated(const QString & gravename); + +private: + QSignalMapper* signalMapper1; + QSignalMapper* signalMapper2; + QGroupBox *GBoxHedgehogs; + QGroupBox *GBoxTeam; + QGroupBox *GBoxFort; + QComboBox *CBFort; + SquareLabel *FortPreview; + QComboBox *CBGrave; + QComboBox *CBFlag; + QComboBox *CBTeamLvl; + QComboBox *CBVoicepack; + QGroupBox *GBoxBinds; + QToolBox *BindsBox; + QLineEdit * TeamNameEdit; + QLineEdit * HHNameEdit[HEDGEHOGS_PER_TEAM]; + QComboBox * HHHats[HEDGEHOGS_PER_TEAM]; + QComboBox * CBBind[BINDS_NUMBER]; + SDLInteraction * mySdli; + HWTeam data(); + QString m_playerHash; + + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + + void loadTeam(const HWTeam & team); + + // page 1 + QPushButton * btnRandomHogName[HEDGEHOGS_PER_TEAM]; + QPushButton * btnRandomTeam; + QPushButton * btnTestSound; + + // footer + QPushButton * btnSave; + +private slots: + void saveTeam(); + void setRandomNames(); + void setRandomName(int hh_index); + void testSound(); + void fixHHname(int idx); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagegamestats.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagegamestats.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,274 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2010-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "pagegamestats.h" +#include "team.h" + +FitGraphicsView::FitGraphicsView(QWidget* parent) : QGraphicsView(parent) +{ + +} + +void FitGraphicsView::resizeEvent(QResizeEvent * event) +{ + Q_UNUSED(event); + + fitInView(sceneRect()); +} + +QLayout * PageGameStats::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + pageLayout->setSpacing(20); + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 1); + pageLayout->setContentsMargins(7, 7, 7, 0); + + QGroupBox * gb = new QGroupBox(this); + QVBoxLayout * gbl = new QVBoxLayout; + + // details + labelGameStats = new QLabel(this); + QLabel * l = new QLabel(this); + l->setTextFormat(Qt::RichText); + l->setText("

" + PageGameStats::tr("Details") + "

"); + l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + labelGameStats->setTextFormat(Qt::RichText); + labelGameStats->setAlignment(Qt::AlignTop); + labelGameStats->setWordWrap(true); + gbl->addWidget(l); + gbl->addWidget(labelGameStats); + gb->setLayout(gbl); + pageLayout->addWidget(gb, 1, 1, 1, 2); + + // graph + graphic = new FitGraphicsView(gb); + l = new QLabel(this); + l->setTextFormat(Qt::RichText); + l->setText("

" + PageGameStats::tr("Health graph") + "

"); + l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + gbl->addWidget(l); + gbl->addWidget(graphic); + graphic->scale(1.0, -1.0); + graphic->setBackgroundBrush(QBrush(Qt::black)); + + labelGameWin = new QLabel(this); + labelGameWin->setTextFormat(Qt::RichText); + pageLayout->addWidget(labelGameWin, 0, 0, 1, 2); + + // ranking box + gb = new QGroupBox(this); + gbl = new QVBoxLayout; + labelGameRank = new QLabel(gb); + l = new QLabel(this); + l->setTextFormat(Qt::RichText); + l->setText("

" + PageGameStats::tr("Ranking") + "

"); + l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + gbl->addWidget(l); + gbl->addWidget(labelGameRank); + gb->setLayout(gbl); + + labelGameRank->setTextFormat(Qt::RichText); + labelGameRank->setAlignment(Qt::AlignTop); + pageLayout->addWidget(gb, 1, 0); + + return pageLayout; +} + +QLayout * PageGameStats::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout(); + + btnSave = addButton(":/res/Save.png", bottomLayout, 0, true); + btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}"); + bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom); + + return bottomLayout; +} + +void PageGameStats::connectSignals() +{ + connect(btnSave, SIGNAL(clicked()), this, SIGNAL(saveDemoRequested())); +} + +PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageGameStats::AddStatText(const QString & msg) +{ + labelGameStats->setText(labelGameStats->text() + msg); +} + +void PageGameStats::clear() +{ + labelGameStats->setText(""); + healthPoints.clear(); + labelGameRank->setText(""); + playerPosition = 0; + lastColor = 0; +} + +void PageGameStats::renderStats() +{ + QGraphicsScene * scene = new QGraphicsScene(); + + QMap >::const_iterator i = healthPoints.constBegin(); + while (i != healthPoints.constEnd()) + { + quint32 c = i.key(); + QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); + QVector hps = i.value(); + + QPainterPath path; + if (hps.size()) + path.moveTo(0, hps[0]); + + for(int t = 1; t < hps.size(); ++t) + path.lineTo(t, hps[t]); + + scene->addPath(path, QPen(c)); + ++i; + } + + graphic->setScene(scene); + graphic->fitInView(graphic->sceneRect()); +} + +void PageGameStats::GameStats(char type, const QString & info) +{ + switch(type) { + case 'r' : { + labelGameWin->setText(QString("

%1

").arg(info)); + break; + } + case 'D' : { + int i = info.indexOf(' '); + QString message = "

" + PageGameStats::tr("The best shot award was won by %1 with %2 pts.").arg(info.mid(i + 1), info.left(i)) + "

"; + AddStatText(message); + break; + } + case 'k' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("The best killer is %1 with %2 kills in a turn.", "", num).arg(info.mid(i + 1), info.left(i)) + "

"; + AddStatText(message); + break; + } + case 'K' : { + int num = info.toInt(); + QString message = "

" + PageGameStats::tr("A total of %1 hedgehog(s) were killed during this round.", "", num).arg(num) + "

"; + AddStatText(message); + break; + } + case 'H' : { + int i = info.indexOf(' '); + quint32 clan = info.left(i).toInt(); + quint32 hp = info.mid(i + 1).toUInt(); + healthPoints[clan].append(hp); + break; + } + case 'T': { // local team stats + //AddStatText("

local team: " + info + "

"); + QStringList infol = info.split(":"); + HWTeam team(infol[0]); + if(team.fileExists()) // do some better test to avoid influence from scripted/predefined teams? + { + team.loadFromFile(); + team.incRounds(); + if(infol[1].toInt() > 0) // might require some better test for winning condition (or changed flag) ... WIP! + team.incWins(); // should draws count as wins? + //team.SaveToFile(); // don't save yet + } + break; + } + + case 'P' : { + int i = info.indexOf(' '); + playerPosition++; + QString color = info.left(i); + quint32 c = color.toInt(); + QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); + + QString playerinfo = info.mid(i + 1); + + i = playerinfo.indexOf(' '); + + int kills = playerinfo.left(i).toInt(); + QString playername = playerinfo.mid(i + 1); + QString image; + + if (lastColor == c) playerPosition--; + lastColor = c; + + switch (playerPosition) + { + case 1: + image = ""; + break; + case 2: + image = ""; + break; + case 3: + image = ""; + break; + default: + image = ""; + break; + } + + QString message; + QString killstring = PageGameStats::tr("(%1 kill)", "", kills).arg(kills); + + message = QString("

%1 %2. %3 ").arg(image, QString::number(playerPosition), playername, clanColor.name()) + killstring + "

"; + + labelGameRank->setText(labelGameRank->text() + message); + break; + } + case 's' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("%1 thought it's good to shoot his own hedgehogs with %2 pts.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; + AddStatText(message); + break; + } + case 'S' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("%1 killed %2 of his own hedgehogs.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; + AddStatText(message); + break; + } + case 'B' : { + int i = info.indexOf(' '); + int num = info.left(i).toInt(); + QString message = "

" + PageGameStats::tr("%1 was scared and skipped turn %2 times.", "", num).arg(info.mid(i + 1)).arg(num) + "

"; + AddStatText(message); + break; + } + + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagegamestats.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagegamestats.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,73 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2010-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef STATSPAGE_H +#define STATSPAGE_H + +#include +#include +#include + +#include "AbstractPage.h" + +class FitGraphicsView : public QGraphicsView +{ + Q_OBJECT + +public: + FitGraphicsView(QWidget* parent = 0); + +protected: + void resizeEvent(QResizeEvent * event); +}; + +class PageGameStats : public AbstractPage +{ + Q_OBJECT + +public: + PageGameStats(QWidget* parent = 0); + + QPushButton *btnSave; + QLabel *labelGameStats; + QLabel *labelGameWin; + QLabel *labelGameRank; + FitGraphicsView * graphic; + +public slots: + void GameStats(char type, const QString & info); + void clear(); + void renderStats(); + +signals: + void saveDemoRequested(); + +private: + void AddStatText(const QString & msg); + + QMap > healthPoints; + unsigned int playerPosition; + quint32 lastColor; + +protected: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); +}; + +#endif // STATSPAGE_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageinfo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageinfo.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,56 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "pageinfo.h" +#include "about.h" + +QLayout * PageInfo::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 1); + pageLayout->setColumnStretch(2, 1); + + about = new About(); + pageLayout->addWidget(about, 0, 0, 1, 3); + + return pageLayout; +} + +QLayout * PageInfo::footerLayoutDefinition() +{ + QGridLayout * bottomLayout = new QGridLayout(); + BtnSnapshots = addButton(":/res/Star.png", bottomLayout, 1, 1, true); + bottomLayout->setAlignment(BtnSnapshots, Qt::AlignRight | Qt::AlignVCenter); + return bottomLayout; +} + +void PageInfo::connectSignals() +{ + //TODO +} + +PageInfo::PageInfo(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageinfo.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageinfo.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,43 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_INFO_H +#define PAGE_INFO_H + +#include "AbstractPage.h" + +class About; + +class PageInfo : public AbstractPage +{ + Q_OBJECT + +public: + PageInfo(QWidget* parent = 0); + + QPushButton *BtnSnapshots; + About *about; + +private: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageingame.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageingame.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,40 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "pageingame.h" + +QLayout * PageInGame::bodyLayoutDefinition() +{ + QHBoxLayout * pageLayout = new QHBoxLayout(); + + QLabel * label = new QLabel(this); + label->setText(tr("In game...")); + pageLayout->addWidget(label); + + setBackButtonVisible(false); + + return pageLayout; +} + +PageInGame::PageInGame(QWidget * parent) : AbstractPage(parent) +{ + initPage(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageingame.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageingame.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,35 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_INGAME_H +#define PAGE_INGAME_H + +#include "AbstractPage.h" + +class PageInGame : public AbstractPage +{ + Q_OBJECT + + public: + PageInGame(QWidget * parent = 0); + + QLayout * bodyLayoutDefinition(); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagemain.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagemain.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,162 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "pagemain.h" +#include "hwconsts.h" +#include "hwform.h" + +QLayout * PageMain::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + //pageLayout->setColumnStretch(0, 1); + //pageLayout->setColumnStretch(1, 2); + //pageLayout->setColumnStretch(2, 1); + + //QPushButton* btnLogo = addButton(":/res/HedgewarsTitle.png", pageLayout, 0, 0, 1, 4, true); + //pageLayout->setAlignment(btnLogo, Qt::AlignHCenter); + pageLayout->setRowStretch(0, 1); + pageLayout->setRowStretch(1, 1); + pageLayout->setRowStretch(2, 0); + pageLayout->setRowStretch(3, 1); + pageLayout->setRowStretch(4, 1); + + //BtnInfo = addButton(":/res/About.png", pageLayout, 3, 1, 1, 2, true); + BtnInfo = addButton(":/res/HedgewarsTitle.png", pageLayout, 0, 0, 1, 4, true); + BtnInfo->setStyleSheet("border: transparent;background: transparent;"); + pageLayout->setAlignment(BtnInfo, Qt::AlignHCenter); + + BtnSinglePlayer = addButton(":/res/LocalPlay.png", pageLayout, 2, 0, 1, 2, true); + BtnSinglePlayer->setToolTip(tr("Local Game (Play a game on a single computer)")); + pageLayout->setAlignment(BtnSinglePlayer, Qt::AlignHCenter); + + BtnNet = addButton(":/res/NetworkPlay.png", pageLayout, 2, 2, 1, 2, true); + BtnNet->setToolTip(tr("Network Game (Play a game across a network)")); + pageLayout->setAlignment(BtnNet, Qt::AlignHCenter); + + BtnDataDownload = addButton(tr("Downloadable Content"), pageLayout, 4, 0, 1, 4, false); + pageLayout->setAlignment(BtnDataDownload, Qt::AlignHCenter); + + return pageLayout; +} + +QLayout * PageMain::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout(); + + mainNote = new QLabel(this); + mainNote->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + mainNote->setWordWrap(true); + + bottomLayout->addWidget(mainNote, 0); + bottomLayout->setStretch(0,1); + + BtnSetup = addButton(":/res/Settings.png", bottomLayout, 1, true); + bottomLayout->setStretch(1,0); + + return bottomLayout; +} + +void PageMain::connectSignals() +{ + //TODO +} + +PageMain::PageMain(QWidget* parent) : AbstractPage(parent) +{ + initPage(); + + if(frontendEffects) setAttribute(Qt::WA_NoSystemBackground, true); + mainNote->setOpenExternalLinks(true); + + if(!isDevBuild) + { + mainNote->setText(QLabel::tr("Tip: ") + randomTip()); + } + else + mainNote->setText(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game. Some features might be broken or incomplete. Use at your own risk!")); + +} + +QString PageMain::randomTip() const +{ + QStringList Tips; + Tips << tr("Simply pick the same color as a friend to play together as a team. Each of you will still control his or her own hedgehogs but they'll win or lose together.", "Tips"); + Tips << tr("Some weapons might do only low damage but they can be a lot more devastating in the right situation. Try to use the Desert Eagle to knock multiple hedgehogs into the water.", "Tips"); + Tips << tr("If you're unsure what to do and don't want to waste ammo, skip one round. But don't let too much time pass as there will be Sudden Death!", "Tips"); + Tips << tr("Want to save ropes? Release the rope in mid air and then shoot again. As long as you don't touch the ground you'll reuse your rope without wasting ammo!", "Tips"); + Tips << tr("If you'd like to keep others from using your preferred nickname on the official server, register an account at http://www.hedgewars.org/.", "Tips"); + Tips << tr("You're bored of default gameplay? Try one of the missions - they'll offer different gameplay depending on the one you picked.", "Tips"); + Tips << tr("By default the game will always record the last game played as a demo. Select 'Local Game' and pick the 'Demos' button on the lower right corner to play or manage them.", "Tips"); + Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. If you've got problems, ask on our forums but please don't expect 24/7 support!", "Tips"); + Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. If you like it, help us with a small donation or contribute your own work!", "Tips"); + Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. Share it with your family and friends as you like!", "Tips"); + Tips << tr("Hedgewars is Open Source and Freeware we create in our spare time. If someone sold you the game, you should try get a refund!", "Tips"); + Tips << tr("From time to time there will be official tournaments. Upcoming events will be announced at http://www.hedgewars.org/ some days in advance.", "Tips"); + Tips << tr("Hedgewars is available in many languages. If the translation in your language seems to be missing or outdated, feel free to contact us!", "Tips"); + Tips << tr("Hedgewars can be run on lots of different operating systems including Microsoft Windows, Mac OS X and Linux.", "Tips"); + Tips << tr("Always remember you're able to set up your own games in local and network/online play. You're not restricted to the 'Simple Game' option.", "Tips"); + Tips << tr("Connect one or more gamepads before starting the game to be able to assign their controls to your teams.", "Tips"); + Tips << tr("Create an account on %1 to keep others from using your most favourite nickname while playing on the official server.", "Tips").arg("http://www.hedgewars.org/"); + Tips << tr("While playing you should give yourself a short break at least once an hour.", "Tips"); + Tips << tr("If your graphics card isn't able to provide hardware accelerated OpenGL, try to enable the low quality mode to improve performance.", "Tips"); + Tips << tr("If your graphics card isn't able to provide hardware accelerated OpenGL, try to update the associated drivers.", "Tips"); + Tips << tr("We're open to suggestions and constructive feedback. If you don't like something or got a great idea, let us know!", "Tips"); + Tips << tr("Especially while playing online be polite and always remember there might be some minors playing with or against you as well!", "Tips"); + Tips << tr("Special game modes such as 'Vampirism' or 'Karma' allow you to develop completely new tactics. Try them in a custom game!", "Tips"); + Tips << tr("The Windows version of Hedgewars supports Xfire. Make sure to add Hedgewars to its game list so your friends can see you playing.", "Tips"); + Tips << tr("You should never install Hedgewars on computers you don't own (school, university, work, etc.). Please ask the responsible person instead!", "Tips"); + Tips << tr("Hedgewars can be perfect for short games during breaks. Just ensure you don't add too many hedgehogs or use an huge map. Reducing time and health might help as well.", "Tips"); + Tips << tr("No hedgehogs were harmed in making this game.", "Tips"); + Tips << tr("There are three different jumps available. Tap [high jump] twice to do a very high/backwards jump.", "Tips"); + Tips << tr("Afraid of falling off a cliff? Hold down [precise] to turn [left] or [right] without actually moving.", "Tips"); + Tips << tr("Some weapons require special strategies or just lots of training, so don't give up on a particular tool if you miss an enemy once.", "Tips"); + Tips << tr("Most weapons won't work once they touch the water. The Homing Bee as well as the Cake are exceptions to this.", "Tips"); + Tips << tr("The Old Limbuger only causes a small explosion. However the wind affected smelly cloud can poison lots of hogs at once.", "Tips"); + Tips << tr("The Piano Strike is the most damaging air strike. You'll lose the hedgehog performing it, so there's a huge downside as well.", "Tips"); + Tips << tr("The Homing Bee can be tricky to use. Its turn radius depends on its velocity, so try to not use full power.", "Tips"); + Tips << tr("Sticky Mines are a perfect tool to create small chain reactions knocking enemy hedgehogs into dire situations ... or water.", "Tips"); + Tips << tr("The Hammer is most effective when used on bridges or girders. Hit hogs will just break through the ground.", "Tips"); + Tips << tr("If you're stuck behind an enemy hedgehog, use the Hammer to free yourself without getting damaged by an explosion.", "Tips"); + Tips << tr("The Cake's maximum walking distance depends on the ground it has to pass. Use [attack] to detonate it early.", "Tips"); + Tips << tr("The Flame Thrower is a weapon but it can be used for tunnel digging as well.", "Tips"); + Tips << tr("Use the Molotov or Flame Thrower to temporary keep hedgehogs from passing terrain such as tunnels or platforms.", "Tips"); + Tips << tr("Want to know who's behind the game? Click on the Hedgewars logo in the main menu to see the credits.", "Tips"); + Tips << tr("Like Hedgewars? Become a fan on %1 or follow us on %2!", "Tips").arg("Facebook").arg("Twitter"); + Tips << tr("Feel free to draw your own graves, hats, flags or even maps and themes! But note that you'll have to share them somewhere to use them online.", "Tips"); + Tips << tr("Really want to wear a specific hat? Donate to us and receive an exclusive hat of your choice!", "Tips"); + // The following tip will require links to app store entries first. + //Tips << tr("Want to play Hedgewars any time? Grab the Mobile version for %1 and %2.", "Tips").arg("").arg(""); + // the ios version is located here: http://itunes.apple.com/us/app/hedgewars/id391234866 + Tips << tr("Keep your video card drivers up to date to avoid issues playing the game.", "Tips"); + Tips << tr("You're able to associate Hedgewars related files (savegames and demo recordings) with the game to launch them right from your favorite file or internet browser.", "Tips"); +#ifdef _WIN32 + Tips << tr("You can find your Hedgewars configuration files under \"My Documents\\Hedgewars\". Create backups or take the files with you, but don't edit them by hand.", "Tips"); +#elif defined __APPLE__ + Tips << tr("You can find your Hedgewars configuration files under \"Library/Application Support/Hedgewars\" in your home directory. Create backups or take the files with you, but don't edit them by hand.", "Tips"); +#else + Tips << tr("You can find your Hedgewars configuration files under \".hedgewars\" in your home directory. Create backups or take the files with you, but don't edit them by hand.", "Tips"); +#endif + + return Tips[QTime(0, 0, 0).secsTo(QTime::currentTime()) % Tips.length()]; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagemain.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagemain.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,47 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_MAIN_H +#define PAGE_MAIN_H + +#include "AbstractPage.h" + +class PageMain : public AbstractPage +{ + Q_OBJECT + +public: + PageMain(QWidget * parent = 0); + + QPushButton * BtnSinglePlayer; + QPushButton * BtnNet; + QPushButton * BtnSetup; + QPushButton * BtnInfo; + QPushButton * BtnDataDownload; + QLabel * mainNote; + +private: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + + QString randomTip() const; +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagemultiplayer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagemultiplayer.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,55 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "pagemultiplayer.h" +#include "gamecfgwidget.h" +#include "teamselect.h" + +QLayout * PageMultiplayer::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + gameCFG = new GameCFGWidget(this); + pageLayout->addWidget(gameCFG, 0, 0, 1, 2); + + btnSetup = new QPushButton(this); + btnSetup->setText(QPushButton::tr("Setup")); + pageLayout->addWidget(btnSetup, 1, 0, 1, 2); + + pageLayout->setRowStretch(2, 1); + + teamsSelect = new TeamSelWidget(this); + pageLayout->addWidget(teamsSelect, 0, 2, 3, 2); + + BtnStartMPGame = addButton(tr("Start"), pageLayout, 3, 3); + + return pageLayout; +} + +void PageMultiplayer::connectSignals() +{ + PageMultiplayer::connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked())); +} + +PageMultiplayer::PageMultiplayer(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagemultiplayer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagemultiplayer.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,50 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_MULTIPLAYER_H +#define PAGE_MULTIPLAYER_H + +#include "AbstractPage.h" + +class GameCFGWidget; +class TeamSelWidget; + +class PageMultiplayer : public AbstractPage +{ + Q_OBJECT + +public: + PageMultiplayer(QWidget* parent = 0); + + GameCFGWidget *gameCFG; + TeamSelWidget *teamsSelect; + QPushButton *BtnStartMPGame; + +signals: + void SetupClicked(); + +private: + QLayout * bodyLayoutDefinition(); + void connectSignals(); + + QPushButton * btnSetup; +}; + +#endif + + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenet.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenet.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,109 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include "pagenet.h" +#include "hwconsts.h" +#include "netudpwidget.h" + +QLayout * PageNet::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 1); + pageLayout->setColumnStretch(2, 1); + + BtnNetSvrStart = new QPushButton(this); + BtnNetSvrStart->setFont(*font14); + BtnNetSvrStart->setText(QPushButton::tr("Start server")); + BtnNetSvrStart->setVisible(haveServer); + pageLayout->addWidget(BtnNetSvrStart, 4, 2); + + ConnGroupBox = new QGroupBox(this); + ConnGroupBox->setTitle(QGroupBox::tr("Net game")); + pageLayout->addWidget(ConnGroupBox, 2, 0, 1, 3); + GBClayout = new QGridLayout(ConnGroupBox); + GBClayout->setColumnStretch(0, 1); + GBClayout->setColumnStretch(1, 1); + GBClayout->setColumnStretch(2, 1); + + BtnNetConnect = new QPushButton(ConnGroupBox); + BtnNetConnect->setFont(*font14); + BtnNetConnect->setText(QPushButton::tr("Connect")); + GBClayout->addWidget(BtnNetConnect, 2, 2); + + tvServersList = new QTableView(ConnGroupBox); + tvServersList->setSelectionBehavior(QAbstractItemView::SelectRows); + GBClayout->addWidget(tvServersList, 1, 0, 1, 3); + + BtnUpdateSList = new QPushButton(ConnGroupBox); + BtnUpdateSList->setFont(*font14); + BtnUpdateSList->setText(QPushButton::tr("Update")); + GBClayout->addWidget(BtnUpdateSList, 2, 0); + + BtnSpecifyServer = new QPushButton(ConnGroupBox); + BtnSpecifyServer->setFont(*font14); + BtnSpecifyServer->setText(QPushButton::tr("Specify")); + GBClayout->addWidget(BtnSpecifyServer, 2, 1); + + return pageLayout; +} + +void PageNet::connectSignals() +{ + connect(BtnNetConnect, SIGNAL(clicked()), this, SLOT(slotConnect())); +} + +PageNet::PageNet(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageNet::updateServersList() +{ + tvServersList->setModel(new HWNetUdpModel(tvServersList)); + + tvServersList->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + + static_cast(tvServersList->model())->updateList(); + + connect(BtnUpdateSList, SIGNAL(clicked()), static_cast(tvServersList->model()), SLOT(updateList())); + connect(tvServersList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(slotConnect())); +} + +void PageNet::slotConnect() +{ + HWNetServersModel * model = static_cast(tvServersList->model()); + QModelIndex mi = tvServersList->currentIndex(); + if(!mi.isValid()) + { + QMessageBox::information(this, tr("Error"), tr("Please select server from the list above")); + return; + } + QString host = model->index(mi.row(), 1).data().toString(); + quint16 port = model->index(mi.row(), 2).data().toUInt(); + + emit connectClicked(host, port); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenet.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenet.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,55 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_NET_H +#define PAGE_NET_H + +#include "AbstractPage.h" + +class PageNet : public AbstractPage +{ + Q_OBJECT + +public: + PageNet(QWidget* parent = 0); + + QPushButton* BtnUpdateSList; + QTableView * tvServersList; + QPushButton * BtnNetConnect; + QPushButton * BtnNetSvrStart; + QPushButton * BtnSpecifyServer; + +public slots: + void updateServersList(); + +signals: + void connectClicked(const QString & host, quint16 port); + +private: + QLayout * bodyLayoutDefinition(); + void connectSignals(); + + QGroupBox * ConnGroupBox; + QGridLayout * GBClayout; + +private slots: + void slotConnect(); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenetgame.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenetgame.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,142 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include + +#include "pagenetgame.h" +#include "gamecfgwidget.h" +#include "teamselect.h" +#include "chatwidget.h" + +QLayout * PageNetGame::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + pageLayout->setSizeConstraint(QLayout::SetMinimumSize); + //pageLayout->setSpacing(1); + pageLayout->setColumnStretch(0, 50); + pageLayout->setColumnStretch(1, 50); + + // chatwidget + pChatWidget = new HWChatWidget(this, m_gameSettings, m_sdli, true); + pChatWidget->setShowReady(true); // show status bulbs by default + pChatWidget->setShowFollow(false); // don't show follow in nicks' context menus + pageLayout->addWidget(pChatWidget, 2, 0, 1, 2); + pageLayout->setRowStretch(1, 100); + pageLayout->setRowStretch(2, 100); + + pGameCFG = new GameCFGWidget(this); + pageLayout->addWidget(pGameCFG, 0, 0); + + btnSetup = new QPushButton(this); + btnSetup->setText(QPushButton::tr("Setup")); + pageLayout->addWidget(btnSetup, 1, 0); + + pNetTeamsWidget = new TeamSelWidget(this); + pNetTeamsWidget->setAcceptOuter(true); + pageLayout->addWidget(pNetTeamsWidget, 0, 1, 2, 1); + + return pageLayout; +} + +QLayout * PageNetGame::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout; + + leRoomName = new QLineEdit(this); + leRoomName->setMaxLength(60); + leRoomName->setMinimumWidth(200); + leRoomName->setMaximumWidth(400); + + BtnGo = new QPushButton(this); + BtnGo->setToolTip(QPushButton::tr("Ready")); + BtnGo->setIcon(QIcon(":/res/lightbulb_off.png")); + BtnGo->setIconSize(QSize(25, 34)); + BtnGo->setMinimumWidth(50); + BtnGo->setMinimumHeight(50); + + + bottomLayout->addWidget(leRoomName); + BtnUpdate = addButton(QAction::tr("Update"), bottomLayout, 1, false); + bottomLayout->addWidget(BtnGo); + + BtnMaster = addButton(tr("Control"), bottomLayout, 3); + bottomLayout->insertStretch(3, 100); + + BtnStart = addButton(QAction::tr("Start"), bottomLayout, 3); + + return bottomLayout; +} + +void PageNetGame::connectSignals() +{ + connect(btnSetup, SIGNAL(clicked()), this, SIGNAL(SetupClicked())); + + connect(BtnUpdate, SIGNAL(clicked()), this, SLOT(onUpdateClick())); +} + +PageNetGame::PageNetGame(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) : AbstractPage(parent) +{ + m_gameSettings = gameSettings; + m_sdli = sdli; + + initPage(); + + QMenu * menu = new QMenu(BtnMaster); + + restrictJoins = new QAction(QAction::tr("Restrict Joins"), menu); + restrictJoins->setCheckable(true); + restrictTeamAdds = new QAction(QAction::tr("Restrict Team Additions"), menu); + restrictTeamAdds->setCheckable(true); + //menu->addAction(startGame); + menu->addAction(restrictJoins); + menu->addAction(restrictTeamAdds); + + BtnMaster->setMenu(menu); + +} + +void PageNetGame::setReadyStatus(bool isReady) +{ + if(isReady) + BtnGo->setIcon(QIcon(":/res/lightbulb_on.png")); + else + BtnGo->setIcon(QIcon(":/res/lightbulb_off.png")); +} + +void PageNetGame::onUpdateClick() +{ + if (leRoomName->text().size()) + emit askForUpdateRoomName(leRoomName->text()); + else + QMessageBox::critical(this, + tr("Error"), + tr("Please enter room name"), + tr("OK")); +} + +void PageNetGame::setMasterMode(bool isMaster) +{ + BtnMaster->setVisible(isMaster); + BtnStart->setVisible(isMaster); + BtnUpdate->setVisible(isMaster); + leRoomName->setVisible(isMaster); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenetgame.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenetgame.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,71 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_NETGAME_H +#define PAGE_NETGAME_H + +#include "AbstractPage.h" +#include "SDLs.h" + +class HWChatWidget; +class TeamSelWidget; +class GameCFGWidget; + +class PageNetGame : public AbstractPage +{ + Q_OBJECT + +public: + PageNetGame(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli); + + QPushButton *BtnGo; + QPushButton *BtnMaster; + QPushButton *BtnStart; + QPushButton *BtnUpdate; + + QLineEdit * leRoomName; + + QAction * restrictJoins; + QAction * restrictTeamAdds; + + HWChatWidget* pChatWidget; + + TeamSelWidget* pNetTeamsWidget; + GameCFGWidget* pGameCFG; + +public slots: + void setReadyStatus(bool isReady); + void onUpdateClick(); + void setMasterMode(bool isMaster); + +signals: + void SetupClicked(); + void askForUpdateRoomName(const QString &); + +private: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + + QSettings * m_gameSettings; + SDLInteraction * m_sdli; + + QPushButton * btnSetup; +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenetserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenetserver.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,100 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pagenetserver.h" + +QLayout * PageNetServer::bodyLayoutDefinition() +{ + QVBoxLayout * pageLayout = new QVBoxLayout(); + + QWidget * wg = new QWidget(this); + pageLayout->addWidget(wg); + + QGridLayout * wgLayout = new QGridLayout(wg); + wgLayout->setColumnStretch(0, 1); + wgLayout->setColumnStretch(1, 3); + wgLayout->setColumnStretch(2, 1); + + wgLayout->setRowStretch(0, 0); + wgLayout->setRowStretch(1, 1); + + QGroupBox * gb = new QGroupBox(wg); + wgLayout->addWidget(gb, 0, 1); + + QGridLayout * gbLayout = new QGridLayout(gb); + + labelSD = new QLabel(gb); + labelSD->setText(QLabel::tr("Server name:")); + gbLayout->addWidget(labelSD, 0, 0); + + leServerDescr = new QLineEdit(gb); + gbLayout->addWidget(leServerDescr, 0, 1); + + labelPort = new QLabel(gb); + labelPort->setText(QLabel::tr("Server port:")); + gbLayout->addWidget(labelPort, 1, 0); + + sbPort = new QSpinBox(gb); + sbPort->setMinimum(0); + sbPort->setMaximum(65535); + gbLayout->addWidget(sbPort, 1, 1); + + BtnDefault = new QPushButton(gb); + BtnDefault->setText(QPushButton::tr("default")); + gbLayout->addWidget(BtnDefault, 1, 2); + + return pageLayout; +} + +QLayout * PageNetServer::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout(); + + BtnStart = new QPushButton(this); + BtnStart->setFont(*font14); + BtnStart->setText(QPushButton::tr("Start")); + + bottomLayout->addStretch(); + bottomLayout->addWidget(BtnStart); + + return bottomLayout; +} + +void PageNetServer::connectSignals() +{ + connect(BtnDefault, SIGNAL(clicked()), this, SLOT(setDefaultPort())); +} + +PageNetServer::PageNetServer(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageNetServer::setDefaultPort() +{ + sbPort->setValue(46631); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenetserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenetserver.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,47 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_NETSERVER_H +#define PAGE_NETSERVER_H + +#include "AbstractPage.h" + +class PageNetServer : public AbstractPage +{ + Q_OBJECT + +public: + PageNetServer(QWidget* parent = 0); + + QPushButton *BtnStart; + QPushButton *BtnDefault; + QLabel *labelSD; + QLineEdit *leServerDescr; + QLabel *labelPort; + QSpinBox *sbPort; + +protected: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + +private slots: + void setDefaultPort(); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenettype.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenettype.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,47 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "pagenettype.h" + + +QLayout * PageNetType::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + pageLayout->setRowStretch(0, 10); + pageLayout->setRowStretch(3, 10); + + pageLayout->setColumnStretch(1, 10); + pageLayout->setColumnStretch(2, 20); + pageLayout->setColumnStretch(3, 10); + + BtnLAN = addButton(tr("LAN game"), pageLayout, 1, 2); + BtnOfficialServer = addButton(tr("Official server"), pageLayout, 2, 2); + + // hack: temporary deactivated - requires server modifications that aren't backward compatible (yet) + //BtnOfficialServer->setEnabled(false); + + return pageLayout; +} + +PageNetType::PageNetType(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagenettype.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagenettype.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,38 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_NETTYPE_H +#define PAGE_NETTYPE_H + +#include "AbstractPage.h" + +class PageNetType : public AbstractPage +{ + Q_OBJECT + +public: + PageNetType(QWidget* parent = 0); + + QPushButton * BtnLAN; + QPushButton * BtnOfficialServer; + +protected: + QLayout * bodyLayoutDefinition(); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageoptions.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageoptions.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,492 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pageoptions.h" +#include "hwconsts.h" +#include "fpsedit.h" +#include "igbox.h" + +// TODO cleanup +QLayout * PageOptions::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + pageLayout->setColumnStretch(0, 100); + pageLayout->setColumnStretch(1, 100); + pageLayout->setColumnStretch(2, 100); + pageLayout->setRowStretch(0, 0); + //pageLayout->setRowStretch(1, 100); + pageLayout->setRowStretch(2, 0); + pageLayout->setContentsMargins(7, 7, 7, 0); + pageLayout->setSpacing(0); + + + QGroupBox * gbTwoBoxes = new QGroupBox(this); + pageLayout->addWidget(gbTwoBoxes, 0, 0, 1, 3); + QGridLayout * gbTBLayout = new QGridLayout(gbTwoBoxes); + gbTBLayout->setMargin(0); + gbTBLayout->setSpacing(0); + gbTBLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); + + QPixmap pmNew(":/res/new.png"); + QPixmap pmEdit(":/res/edit.png"); + QPixmap pmDelete(":/res/delete.png"); + + { + teamsBox = new IconedGroupBox(this); + //teamsBox->setContentTopPadding(0); + //teamsBox->setAttribute(Qt::WA_PaintOnScreen, true); + teamsBox->setIcon(QIcon(":/res/teamicon.png")); + teamsBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + teamsBox->setTitle(QGroupBox::tr("Teams")); + + QGridLayout * GBTlayout = new QGridLayout(teamsBox); + + CBTeamName = new QComboBox(teamsBox); + GBTlayout->addWidget(CBTeamName, 0, 0); + + BtnNewTeam = new QPushButton(teamsBox); + BtnNewTeam->setToolTip(tr("New team")); + BtnNewTeam->setIconSize(pmNew.size()); + BtnNewTeam->setIcon(pmNew); + BtnNewTeam->setMaximumWidth(pmNew.width() + 6); + connect(BtnNewTeam, SIGNAL(clicked()), this, SIGNAL(newTeamRequested())); + GBTlayout->addWidget(BtnNewTeam, 0, 1); + + BtnEditTeam = new QPushButton(teamsBox); + BtnEditTeam->setToolTip(tr("Edit team")); + BtnEditTeam->setIconSize(pmEdit.size()); + BtnEditTeam->setIcon(pmEdit); + BtnEditTeam->setMaximumWidth(pmEdit.width() + 6); + connect(BtnEditTeam, SIGNAL(clicked()), this, SLOT(requestEditSelectedTeam())); + GBTlayout->addWidget(BtnEditTeam, 0, 2); + + BtnDeleteTeam = new QPushButton(teamsBox); + BtnDeleteTeam->setToolTip(tr("Delete team")); + BtnDeleteTeam->setIconSize(pmDelete.size()); + BtnDeleteTeam->setIcon(pmDelete); + BtnDeleteTeam->setMaximumWidth(pmDelete.width() + 6); + connect(BtnDeleteTeam, SIGNAL(clicked()), this, SLOT(requestDeleteSelectedTeam())); + GBTlayout->addWidget(BtnDeleteTeam, 0, 3); + + LblNoEditTeam = new QLabel(teamsBox); + LblNoEditTeam->setText(tr("You can't edit teams from team selection. Go back to main menu to add, edit or delete teams.")); + LblNoEditTeam->setWordWrap(true); + LblNoEditTeam->setVisible(false); + GBTlayout->addWidget(LblNoEditTeam, 0, 0); + + gbTBLayout->addWidget(teamsBox, 0, 0); + } + + { + IconedGroupBox* groupWeapons = new IconedGroupBox(this); + + //groupWeapons->setContentTopPadding(0); + //groupWeapons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + groupWeapons->setIcon(QIcon(":/res/weaponsicon.png")); + groupWeapons->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + groupWeapons->setTitle(QGroupBox::tr("Schemes and Weapons")); + QGridLayout * WeaponsLayout = new QGridLayout(groupWeapons); + + QLabel* SchemeLabel = new QLabel(groupWeapons); + SchemeLabel->setText(QLabel::tr("Game scheme")); + WeaponsLayout->addWidget(SchemeLabel, 1, 0); + + SchemesName = new QComboBox(groupWeapons); + WeaponsLayout->addWidget(SchemesName, 1, 1); + + SchemeNew = new QPushButton(groupWeapons); + SchemeNew->setToolTip(tr("New scheme")); + SchemeNew->setIconSize(pmNew.size()); + SchemeNew->setIcon(pmNew); + SchemeNew->setMaximumWidth(pmNew.width() + 6); + WeaponsLayout->addWidget(SchemeNew, 1, 2); + + SchemeEdit = new QPushButton(groupWeapons); + SchemeEdit->setToolTip(tr("Edit scheme")); + SchemeEdit->setIconSize(pmEdit.size()); + SchemeEdit->setIcon(pmEdit); + SchemeEdit->setMaximumWidth(pmEdit.width() + 6); + WeaponsLayout->addWidget(SchemeEdit, 1, 3); + + SchemeDelete = new QPushButton(groupWeapons); + SchemeDelete->setToolTip(tr("Delete scheme")); + SchemeDelete->setIconSize(pmDelete.size()); + SchemeDelete->setIcon(pmDelete); + SchemeDelete->setMaximumWidth(pmDelete.width() + 6); + WeaponsLayout->addWidget(SchemeDelete, 1, 4); + + QLabel* WeaponLabel = new QLabel(groupWeapons); + WeaponLabel->setText(QLabel::tr("Weapons")); + WeaponsLayout->addWidget(WeaponLabel, 2, 0); + + WeaponsName = new QComboBox(groupWeapons); + WeaponsLayout->addWidget(WeaponsName, 2, 1); + + WeaponNew = new QPushButton(groupWeapons); + WeaponNew->setToolTip(tr("New weapon set")); + WeaponNew->setIconSize(pmNew.size()); + WeaponNew->setIcon(pmNew); + WeaponNew->setMaximumWidth(pmNew.width() + 6); + WeaponsLayout->addWidget(WeaponNew, 2, 2); + + WeaponEdit = new QPushButton(groupWeapons); + WeaponEdit->setToolTip(tr("Edit weapon set")); + WeaponEdit->setIconSize(pmEdit.size()); + WeaponEdit->setIcon(pmEdit); + WeaponEdit->setMaximumWidth(pmEdit.width() + 6); + WeaponsLayout->addWidget(WeaponEdit, 2, 3); + + WeaponDelete = new QPushButton(groupWeapons); + WeaponDelete->setToolTip(tr("Delete weapon set")); + WeaponDelete->setIconSize(pmDelete.size()); + WeaponDelete->setIcon(pmDelete); + WeaponDelete->setMaximumWidth(pmDelete.width() + 6); + WeaponsLayout->addWidget(WeaponDelete, 2, 4); + + WeaponTooltip = new QCheckBox(this); + WeaponTooltip->setText(QCheckBox::tr("Show ammo menu tooltips")); + WeaponsLayout->addWidget(WeaponTooltip, 3, 0, 1, 4); + + gbTBLayout->addWidget(groupWeapons, 1, 0); + } + + { + IconedGroupBox* groupMisc = new IconedGroupBox(this); + //groupMisc->setContentTopPadding(0); + groupMisc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + groupMisc->setIcon(QIcon(":/res/miscicon.png")); + //groupMisc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + groupMisc->setTitle(QGroupBox::tr("Misc")); + QGridLayout * MiscLayout = new QGridLayout(groupMisc); + + labelNN = new QLabel(groupMisc); + labelNN->setText(QLabel::tr("Net nick")); + MiscLayout->addWidget(labelNN, 0, 0); + + editNetNick = new QLineEdit(groupMisc); + editNetNick->setMaxLength(20); + editNetNick->setText(QLineEdit::tr("unnamed")); + connect(editNetNick, SIGNAL(editingFinished()), this, SLOT(trimNetNick())); + MiscLayout->addWidget(editNetNick, 0, 1); + + labelNetPassword = new QLabel(groupMisc); + labelNetPassword->setText(QLabel::tr("Password")); + MiscLayout->addWidget(labelNetPassword, 1, 0); + + editNetPassword = new QLineEdit(groupMisc); + editNetPassword->setEchoMode(QLineEdit::Password); + MiscLayout->addWidget(editNetPassword, 1, 1); + + QLabel *labelLanguage = new QLabel(groupMisc); + labelLanguage->setText(QLabel::tr("Locale") + " *"); + MiscLayout->addWidget(labelLanguage, 2, 0); + + CBLanguage = new QComboBox(groupMisc); + QDir tmpdir; + tmpdir.cd(cfgdir->absolutePath()); + tmpdir.cd("Data/Locale"); + tmpdir.setFilter(QDir::Files); + QStringList locs = tmpdir.entryList(QStringList("hedgewars_*.qm")); + CBLanguage->addItem(QComboBox::tr("(System default)"), QString("")); + for(int i = 0; i < locs.count(); i++) + { + QLocale loc(locs[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1")); + CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); + } + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Locale"); + tmpdir.setFilter(QDir::Files); + QStringList tmplist = tmpdir.entryList(QStringList("hedgewars_*.qm")); + for(int i = 0; i < tmplist.count(); i++) + { + if (locs.contains(tmplist[i])) continue; + QLocale loc(tmplist[i].replace(QRegExp("hedgewars_(.*)\\.qm"), "\\1")); + CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); + } + + MiscLayout->addWidget(CBLanguage, 2, 1); + + CBAltDamage = new QCheckBox(groupMisc); + CBAltDamage->setText(QCheckBox::tr("Alternative damage show")); + MiscLayout->addWidget(CBAltDamage, 3, 0, 1, 2); + + CBNameWithDate = new QCheckBox(groupMisc); + CBNameWithDate->setText(QCheckBox::tr("Append date and time to record file name")); + MiscLayout->addWidget(CBNameWithDate, 4, 0, 1, 2); + + BtnAssociateFiles = new QPushButton(groupMisc); + BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions")); + BtnAssociateFiles->setEnabled(!custom_data && !custom_config); + MiscLayout->addWidget(BtnAssociateFiles, 5, 0, 1, 2); + +#ifdef __APPLE__ +#ifdef SPARKLE_ENABLED + CBAutoUpdate = new QCheckBox(groupMisc); + CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup")); + MiscLayout->addWidget(CBAutoUpdate, 6, 0, 1, 3); +#endif +#endif + gbTBLayout->addWidget(groupMisc, 2, 0); + } + + { + AGGroupBox = new IconedGroupBox(this); + //AGGroupBox->setContentTopPadding(0); + AGGroupBox->setIcon(QIcon(":/res/graphicsicon.png")); + //AGGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + AGGroupBox->setTitle(QGroupBox::tr("Audio/Graphic options")); + + QVBoxLayout * GBAlayout = new QVBoxLayout(AGGroupBox); + QHBoxLayout * GBAreslayout = new QHBoxLayout(0); + QHBoxLayout * GBAstereolayout = new QHBoxLayout(0); + QHBoxLayout * GBAqualayout = new QHBoxLayout(0); + + CBFrontendFullscreen = new QCheckBox(AGGroupBox); + CBFrontendFullscreen->setText(QCheckBox::tr("Frontend fullscreen")); + GBAlayout->addWidget(CBFrontendFullscreen); + + CBFrontendEffects = new QCheckBox(AGGroupBox); + CBFrontendEffects->setText(QCheckBox::tr("Frontend effects") + " *"); + GBAlayout->addWidget(CBFrontendEffects); + + CBEnableFrontendSound = new QCheckBox(AGGroupBox); + CBEnableFrontendSound->setText(QCheckBox::tr("Enable frontend sounds")); + GBAlayout->addWidget(CBEnableFrontendSound); + + CBEnableFrontendMusic = new QCheckBox(AGGroupBox); + CBEnableFrontendMusic->setText(QCheckBox::tr("Enable frontend music")); + GBAlayout->addWidget(CBEnableFrontendMusic); + + QFrame * hr = new QFrame(AGGroupBox); + hr->setFrameStyle(QFrame::HLine); + hr->setLineWidth(3); + hr->setFixedHeight(10); + GBAlayout->addWidget(hr); + + QLabel * resolution = new QLabel(AGGroupBox); + resolution->setText(QLabel::tr("Resolution")); + GBAreslayout->addWidget(resolution); + + CBResolution = new QComboBox(AGGroupBox); + GBAreslayout->addWidget(CBResolution); + GBAlayout->addLayout(GBAreslayout); + + CBFullscreen = new QCheckBox(AGGroupBox); + CBFullscreen->setText(QCheckBox::tr("Fullscreen")); + GBAlayout->addWidget(CBFullscreen); + + QLabel * quality = new QLabel(AGGroupBox); + quality->setText(QLabel::tr("Quality")); + quality->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + GBAqualayout->addWidget(quality); + + SLQuality = new QSlider(Qt::Horizontal, AGGroupBox); + SLQuality->setTickPosition(QSlider::TicksBelow); + SLQuality->setMaximum(5); + SLQuality->setMinimum(0); + SLQuality->setFixedWidth(150); + GBAqualayout->addWidget(SLQuality); + GBAlayout->addLayout(GBAqualayout); + + QLabel * stereo = new QLabel(AGGroupBox); + stereo->setText(QLabel::tr("Stereo rendering")); + GBAstereolayout->addWidget(stereo); + + CBStereoMode = new QComboBox(AGGroupBox); + CBStereoMode->addItem(QComboBox::tr("Disabled")); + CBStereoMode->addItem(QComboBox::tr("Red/Cyan")); + CBStereoMode->addItem(QComboBox::tr("Cyan/Red")); + CBStereoMode->addItem(QComboBox::tr("Red/Blue")); + CBStereoMode->addItem(QComboBox::tr("Blue/Red")); + CBStereoMode->addItem(QComboBox::tr("Red/Green")); + CBStereoMode->addItem(QComboBox::tr("Green/Red")); + CBStereoMode->addItem(QComboBox::tr("Side-by-side")); + CBStereoMode->addItem(QComboBox::tr("Top-Bottom")); + CBStereoMode->addItem(QComboBox::tr("Wiggle")); + CBStereoMode->addItem(QComboBox::tr("Red/Cyan grayscale")); + CBStereoMode->addItem(QComboBox::tr("Cyan/Red grayscale")); + CBStereoMode->addItem(QComboBox::tr("Red/Blue grayscale")); + CBStereoMode->addItem(QComboBox::tr("Blue/Red grayscale")); + CBStereoMode->addItem(QComboBox::tr("Red/Green grayscale")); + CBStereoMode->addItem(QComboBox::tr("Green/Red grayscale")); + connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int))); + + GBAstereolayout->addWidget(CBStereoMode); + GBAlayout->addLayout(GBAstereolayout); + + hr = new QFrame(AGGroupBox); + hr->setFrameStyle(QFrame::HLine); + hr->setLineWidth(3); + hr->setFixedHeight(10); + GBAlayout->addWidget(hr); + + QHBoxLayout * GBAvollayout = new QHBoxLayout(0); + QLabel * vol = new QLabel(AGGroupBox); + vol->setText(QLabel::tr("Initial sound volume")); + GBAvollayout->addWidget(vol); + GBAlayout->addLayout(GBAvollayout); + volumeBox = new QSpinBox(AGGroupBox); + volumeBox->setRange(0, 100); + volumeBox->setSingleStep(5); + GBAvollayout->addWidget(volumeBox); + + CBEnableSound = new QCheckBox(AGGroupBox); + CBEnableSound->setText(QCheckBox::tr("Enable sound")); + GBAlayout->addWidget(CBEnableSound); + + CBEnableMusic = new QCheckBox(AGGroupBox); + CBEnableMusic->setText(QCheckBox::tr("Enable music")); + GBAlayout->addWidget(CBEnableMusic); + + hr = new QFrame(AGGroupBox); + hr->setFrameStyle(QFrame::HLine); + hr->setLineWidth(3); + hr->setFixedHeight(10); + GBAlayout->addWidget(hr); + + QHBoxLayout * GBAfpslayout = new QHBoxLayout(0); + QLabel * maxfps = new QLabel(AGGroupBox); + maxfps->setText(QLabel::tr("FPS limit")); + GBAfpslayout->addWidget(maxfps); + GBAlayout->addLayout(GBAfpslayout); + fpsedit = new FPSEdit(AGGroupBox); + GBAfpslayout->addWidget(fpsedit); + + CBShowFPS = new QCheckBox(AGGroupBox); + CBShowFPS->setText(QCheckBox::tr("Show FPS")); + GBAlayout->addWidget(CBShowFPS); + + hr = new QFrame(AGGroupBox); + hr->setFrameStyle(QFrame::HLine); + hr->setLineWidth(3); + hr->setFixedHeight(10); + GBAlayout->addWidget(hr); + + QLabel *restartNote = new QLabel(this); + restartNote->setText(QString("* ") + QLabel::tr("Restart game to apply")); + restartNote->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + GBAlayout->addWidget(restartNote); + + gbTBLayout->addWidget(AGGroupBox, 0, 1, 3, 1); + } + + previousQuality = this->SLQuality->value(); + previousResolutionIndex = this->CBResolution->currentIndex(); + previousFullscreenValue = this->CBFullscreen->isChecked(); + + return pageLayout; +} + +QLayout * PageOptions::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout(); + btnSave = addButton(":/res/Save.png", bottomLayout, 0, true); + btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}"); + bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom); + return bottomLayout; +} + +void PageOptions::connectSignals() +{ + connect(CBResolution, SIGNAL(currentIndexChanged(int)), this, SLOT(setResolution(int))); + connect(CBFullscreen, SIGNAL(stateChanged(int)), this, SLOT(setFullscreen(int))); + connect(SLQuality, SIGNAL(valueChanged(int)), this, SLOT(setQuality(int))); +} + +PageOptions::PageOptions(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageOptions::forceFullscreen(int index) +{ + bool forced = (index == 7 || index == 8 || index == 9); + + if (index != 0) { + this->SLQuality->setValue(this->SLQuality->maximum()); + this->SLQuality->setEnabled(false); + this->CBFullscreen->setEnabled(!forced); + this->CBFullscreen->setChecked(forced ? true : previousFullscreenValue); + this->CBResolution->setCurrentIndex(forced ? 0 : previousResolutionIndex); + } else { + this->SLQuality->setEnabled(true); + this->CBFullscreen->setEnabled(true); + this->SLQuality->setValue(previousQuality); + this->CBFullscreen->setChecked(previousFullscreenValue); + this->CBResolution->setCurrentIndex(previousResolutionIndex); + } +} + +void PageOptions::setQuality(int value) +{ + int index = this->CBStereoMode->currentIndex(); + if (index == 0) + previousQuality = this->SLQuality->value(); +} + +void PageOptions::setFullscreen(int state) +{ + int index = this->CBStereoMode->currentIndex(); + if (index != 7 && index != 8 && index != 9) + previousFullscreenValue = this->CBFullscreen->isChecked(); +} + +void PageOptions::setResolution(int state) +{ + int index = this->CBStereoMode->currentIndex(); + if (index != 7 && index != 8 && index != 9) + previousResolutionIndex = this->CBResolution->currentIndex(); +} + +void PageOptions::trimNetNick() +{ + editNetNick->setText(editNetNick->text().trimmed()); +} + +void PageOptions::requestEditSelectedTeam() +{ + emit editTeamRequested(CBTeamName->currentText()); +} + +void PageOptions::requestDeleteSelectedTeam() +{ + emit deleteTeamRequested(CBTeamName->currentText()); +} + +void PageOptions::setTeamOptionsEnabled(bool enabled) +{ + BtnNewTeam->setVisible(enabled); + BtnEditTeam->setVisible(enabled); + BtnDeleteTeam->setVisible(enabled); + CBTeamName->setVisible(enabled); + LblNoEditTeam->setVisible(!enabled); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageoptions.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageoptions.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,107 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_OPTIONS_H +#define PAGE_OPTIONS_H + +#include "AbstractPage.h" + +class FPSEdit; +class IconedGroupBox; + +class PageOptions : public AbstractPage +{ + Q_OBJECT + +public: + PageOptions(QWidget* parent = 0); + + QCheckBox *WeaponTooltip; + QPushButton *WeaponNew; + QPushButton *WeaponEdit; + QPushButton *WeaponDelete; + QComboBox *WeaponsName; + QPushButton *SchemeNew; + QPushButton *SchemeEdit; + QPushButton *SchemeDelete; + QComboBox *SchemesName; + + QComboBox *CBLanguage; + + IconedGroupBox *teamsBox;; + QPushButton *BtnAssociateFiles; + QComboBox *CBTeamName; + IconedGroupBox *AGGroupBox; + QComboBox *CBResolution; + QComboBox *CBStereoMode; + QCheckBox *CBEnableSound; + QCheckBox *CBEnableFrontendSound; + QCheckBox *CBEnableMusic; + QCheckBox *CBEnableFrontendMusic; + QCheckBox *CBFullscreen; + QCheckBox *CBFrontendFullscreen; + QCheckBox *CBShowFPS; + QCheckBox *CBAltDamage; + QCheckBox *CBNameWithDate; +#ifdef __APPLE__ + QCheckBox *CBAutoUpdate; +#endif + + FPSEdit *fpsedit; + QPushButton *btnSave; + QLabel *labelNN; + QLabel *labelNetPassword; + QSpinBox * volumeBox; + QLineEdit *editNetNick; + QLineEdit *editNetPassword; + QSlider *SLQuality; + QCheckBox *CBFrontendEffects; + + void setTeamOptionsEnabled(bool enabled); + +signals: + void newTeamRequested(); + void editTeamRequested(const QString & teamName); + void deleteTeamRequested(const QString & teamName); + + +private: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + + bool previousFullscreenValue; + int previousResolutionIndex; + int previousQuality; + QLabel *LblNoEditTeam; + QPushButton *BtnNewTeam; + QPushButton *BtnEditTeam; + QPushButton *BtnDeleteTeam; + +private slots: + void forceFullscreen(int index); + void setFullscreen(int state); + void setResolution(int state); + void setQuality(int value); + void trimNetNick(); + void requestEditSelectedTeam(); + void requestDeleteSelectedTeam(); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageplayrecord.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageplayrecord.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,165 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hwconsts.h" +#include "pageplayrecord.h" + +QLayout * PagePlayDemo::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + pageLayout->setColumnStretch(0, 1); + pageLayout->setColumnStretch(1, 2); + pageLayout->setColumnStretch(2, 1); + pageLayout->setRowStretch(2, 100); + + BtnPlayDemo = new QPushButton(this); + BtnPlayDemo->setFont(*font14); + BtnPlayDemo->setText(QPushButton::tr("Play demo")); + pageLayout->addWidget(BtnPlayDemo, 3, 2); + + BtnRenameRecord = new QPushButton(this); + BtnRenameRecord->setText(QPushButton::tr("Rename")); + pageLayout->addWidget(BtnRenameRecord, 0, 2); + + BtnRemoveRecord = new QPushButton(this); + BtnRemoveRecord->setText(QPushButton::tr("Delete")); + pageLayout->addWidget(BtnRemoveRecord, 1, 2); + + DemosList = new QListWidget(this); + DemosList->setGeometry(QRect(170, 10, 311, 311)); + pageLayout->addWidget(DemosList, 0, 1, 3, 1); + + return pageLayout; +} + +void PagePlayDemo::connectSignals() +{ + connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord())); + connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord())); +} + +PagePlayDemo::PagePlayDemo(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PagePlayDemo::FillFromDir(RecordType rectype) +{ + QDir dir; + QString extension; + + recType = rectype; + + dir.cd(cfgdir->absolutePath()); + if (rectype == RT_Demo) + { + dir.cd("Demos"); + extension = "hwd"; + BtnPlayDemo->setText(QPushButton::tr("Play demo")); + } else + { + dir.cd("Saves"); + extension = "hws"; + BtnPlayDemo->setText(QPushButton::tr("Load")); + } + dir.setFilter(QDir::Files); + + QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer))); + sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1"); + + DemosList->clear(); + DemosList->addItems(sl); + + for (int i = 0; i < DemosList->count(); ++i) + { + DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer))); + DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png")); + } +} + +void PagePlayDemo::renameRecord() +{ + QListWidgetItem * curritem = DemosList->currentItem(); + if (!curritem) + { + QMessageBox::critical(this, + tr("Error"), + tr("Please select record from the list"), + tr("OK")); + return ; + } + QFile rfile(curritem->data(Qt::UserRole).toString()); + + QFileInfo finfo(rfile); + + bool ok; + + QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok); + + if(ok && newname.size()) + { + QString newfullname = QString("%1/%2.%3.%4") + .arg(finfo.absolutePath()) + .arg(newname) + .arg(*cProtoVer) + .arg(finfo.suffix()); + + ok = rfile.rename(newfullname); + if(!ok) + QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname); + else + FillFromDir(recType); + } +} + +void PagePlayDemo::removeRecord() +{ + QListWidgetItem * curritem = DemosList->currentItem(); + if (!curritem) + { + QMessageBox::critical(this, + tr("Error"), + tr("Please select record from the list"), + tr("OK")); + return ; + } + QFile rfile(curritem->data(Qt::UserRole).toString()); + + bool ok; + + ok = rfile.remove(); + if(!ok) + QMessageBox::critical(this, tr("Error"), tr("Cannot delete file")); + else + FillFromDir(recType); +} + +bool PagePlayDemo::isSave() +{ + return recType == RT_Save; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageplayrecord.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageplayrecord.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,61 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PLAYRECORDPAGE_H +#define PLAYRECORDPAGE_H + +#include + +#include "AbstractPage.h" + +class QPushButton; +class QListWidget; + +class PagePlayDemo : public AbstractPage +{ + Q_OBJECT + +public: + enum RecordType { + RT_Demo, + RT_Save + }; + + PagePlayDemo(QWidget* parent = 0); + + void FillFromDir(RecordType rectype); + bool isSave(); + + QPushButton *BtnPlayDemo; + QPushButton *BtnRenameRecord; + QPushButton *BtnRemoveRecord; + QListWidget *DemosList; + +private: + QLayout * bodyLayoutDefinition(); + void connectSignals(); + + RecordType recType; + +private slots: + void renameRecord(); + void removeRecord(); +}; + + +#endif // PLAYRECORDPAGE_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageroomslist.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageroomslist.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,419 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ammoSchemeModel.h" +#include "pageroomslist.h" +#include "hwconsts.h" +#include "chatwidget.h" + +QLayout * PageRoomsList::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + QHBoxLayout * newRoomLayout = new QHBoxLayout(); + QLabel * roomNameLabel = new QLabel(this); + roomNameLabel->setText(tr("Room Name:")); + roomName = new QLineEdit(this); + roomName->setMaxLength(60); + newRoomLayout->addWidget(roomNameLabel); + newRoomLayout->addWidget(roomName); + pageLayout->addLayout(newRoomLayout, 0, 0, 1, 2); + + roomsList = new QTableWidget(this); + roomsList->setSelectionBehavior(QAbstractItemView::SelectRows); + roomsList->verticalHeader()->setVisible(false); + roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive); + roomsList->setAlternatingRowColors(true); + roomsList->setShowGrid(false); + roomsList->setSelectionMode(QAbstractItemView::SingleSelection); + pageLayout->addWidget(roomsList, 1, 0, 3, 2); + pageLayout->setRowStretch(2, 100); + + QHBoxLayout * filterLayout = new QHBoxLayout(); + + QLabel * stateLabel = new QLabel(this); + CBState = new QComboBox(this); + + filterLayout->addWidget(stateLabel); + filterLayout->addWidget(CBState); + filterLayout->addSpacing(30); + + QLabel * ruleLabel = new QLabel(this); + ruleLabel->setText(tr("Rules:")); + CBRules = new QComboBox(this); + + filterLayout->addWidget(ruleLabel); + filterLayout->addWidget(CBRules); + filterLayout->addSpacing(30); + + QLabel * weaponLabel = new QLabel(this); + weaponLabel->setText(tr("Weapons:")); + CBWeapons = new QComboBox(this); + + filterLayout->addWidget(weaponLabel); + filterLayout->addWidget(CBWeapons); + filterLayout->addSpacing(30); + + QLabel * searchLabel = new QLabel(this); + searchLabel->setText(tr("Search:")); + searchText = new QLineEdit(this); + searchText->setMaxLength(60); + filterLayout->addWidget(searchLabel); + filterLayout->addWidget(searchText); + + pageLayout->addLayout(filterLayout, 4, 0, 1, 2); + + chatWidget = new HWChatWidget(this, m_gameSettings, m_sdli, false); + pageLayout->addWidget(chatWidget, 5, 0, 1, 3); + pageLayout->setRowStretch(5, 350); + + BtnCreate = addButton(tr("Create"), pageLayout, 0, 2); + BtnJoin = addButton(tr("Join"), pageLayout, 1, 2); + BtnRefresh = addButton(tr("Refresh"), pageLayout, 3, 2); + BtnClear = addButton(tr("Clear"), pageLayout, 4, 2); + + CBRules->addItem(QComboBox::tr("Any")); + CBState->addItem(QComboBox::tr("Any")); + CBState->addItem(QComboBox::tr("In lobby")); + CBState->addItem(QComboBox::tr("In progress")); + + return pageLayout; +} + +QLayout * PageRoomsList::footerLayoutDefinition() +{ + QGridLayout * bottomLayout = new QGridLayout(); + + lblCount = new QLabel(this); + bottomLayout->addWidget(lblCount, 0, 0, Qt::AlignHCenter); + lblCount->setText("?"); + lblCount->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + BtnAdmin = addButton(tr("Admin features"), bottomLayout, 6, 2); + + return bottomLayout; +} + +void PageRoomsList::connectSignals() +{ + connect(chatWidget, SIGNAL(nickCountUpdate(const int)), this, SLOT(updateNickCounter(const int))); + + connect(BtnCreate, SIGNAL(clicked()), this, SLOT(onCreateClick())); + connect(BtnJoin, SIGNAL(clicked()), this, SLOT(onJoinClick())); + connect(BtnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClick())); + connect(BtnClear, SIGNAL(clicked()), this, SLOT(onClearClick())); + connect(roomsList, SIGNAL(doubleClicked (const QModelIndex &)), this, SLOT(onJoinClick())); + connect(CBState, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); + connect(CBRules, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); + connect(CBWeapons, SIGNAL(currentIndexChanged (int)), this, SLOT(onRefreshClick())); + connect(searchText, SIGNAL(textChanged (const QString &)), this, SLOT(onRefreshClick())); + connect(this, SIGNAL(askJoinConfirmation (const QString &)), this, SLOT(onJoinConfirmation(const QString &)), Qt::QueuedConnection); +} + + +PageRoomsList::PageRoomsList(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli) : + AbstractPage(parent) +{ + m_gameSettings = gameSettings; + m_sdli = sdli; + + initPage(); + + // not the most elegant solution but it works + ammoSchemeModel = new AmmoSchemeModel(this, NULL); + for (int i = 0; i < ammoSchemeModel->predefSchemesNames.count(); i++) + CBRules->addItem(ammoSchemeModel->predefSchemesNames.at(i).toAscii().constData()); + + CBWeapons->addItem(QComboBox::tr("Any")); + for (int i = 0; i < cDefaultAmmos.count(); i++) { + QPair ammo = cDefaultAmmos.at(i); + CBWeapons->addItem(ammo.first.toAscii().constData()); + } + + gameInLobby = false; +} + +void PageRoomsList::setAdmin(bool flag) +{ + BtnAdmin->setVisible(flag); +} + +void PageRoomsList::setRoomsList(const QStringList & list) +{ + QBrush red(QColor(255, 0, 0)); + QBrush orange(QColor(127, 127, 0)); + QBrush yellow(QColor(255, 255, 0)); + QBrush green(QColor(0, 255, 0)); + + listFromServer = list; + + QString selection = ""; + + if(QTableWidgetItem *item = roomsList->item(roomsList->currentRow(), 0)) + selection = item->text(); + + roomsList->clear(); + roomsList->setColumnCount(7); + roomsList->setHorizontalHeaderLabels( + QStringList() << + QTableWidget::tr("Room Name") << + QTableWidget::tr("C") << + QTableWidget::tr("T") << + QTableWidget::tr("Owner") << + QTableWidget::tr("Map") << + QTableWidget::tr("Rules") << + QTableWidget::tr("Weapons") + ); + + // set minimum sizes +// roomsList->horizontalHeader()->resizeSection(0, 200); +// roomsList->horizontalHeader()->resizeSection(1, 50); +// roomsList->horizontalHeader()->resizeSection(2, 50); +// roomsList->horizontalHeader()->resizeSection(3, 100); +// roomsList->horizontalHeader()->resizeSection(4, 100); +// roomsList->horizontalHeader()->resizeSection(5, 100); +// roomsList->horizontalHeader()->resizeSection(6, 100); + + // set resize modes +// roomsList->horizontalHeader()->setResizeMode(QHeaderView::Interactive); + + bool gameCanBeJoined = true; + + if (list.size() % 8) + return; + + roomsList->setRowCount(list.size() / 8); + for(int i = 0, r = 0; i < list.size(); i += 8, r++) + { + // if we are joining a game + // TODO: Should NOT be done here + if (gameInLobby) { + if (gameInLobbyName == list[i + 1]) { + gameCanBeJoined = list[i].compare("True"); + } + } + + // check filter settings + #define NO_FILTER_MATCH roomsList->setRowCount(roomsList->rowCount() - 1); --r; continue + + if (list[i].compare("True") && CBState->currentIndex() == 2) { NO_FILTER_MATCH; } + if (list[i].compare("False") && CBState->currentIndex() == 1) { NO_FILTER_MATCH; } + if (CBRules->currentIndex() != 0 && list[i + 6].compare(CBRules->currentText())) { NO_FILTER_MATCH; } + if (CBWeapons->currentIndex() != 0 && list[i + 7].compare(CBWeapons->currentText())) { NO_FILTER_MATCH; } + bool found = list[i + 1].contains(searchText->text(), Qt::CaseInsensitive); + if (!found) { + for (int a = 4; a <= 7; ++a) { + QString compString = list[i + a]; + if (a == 5 && compString == "+rnd+") { + compString = "Random Map"; + } else if (a == 5 && compString == "+maze+") { + compString = "Random Maze"; + } else if (a == 5 && compString == "+drawn+") { + compString = "Drawn Map"; + } + if (compString.contains(searchText->text(), Qt::CaseInsensitive)) { + found = true; + break; + } + } + } + if (!searchText->text().isEmpty() && !found) { NO_FILTER_MATCH; } + + QTableWidgetItem * item; + item = new QTableWidgetItem(list[i + 1]); // room name + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + + // pick appropriate room icon and tooltip (game in progress yes/no; later maybe locked rooms etc.) + if(list[i].compare("True")) + { + item->setIcon(QIcon(":/res/iconTime.png"));// game is in lobby + item->setToolTip(tr("This game is in lobby.\nYou may join and start playing once the game starts.")); + } + else + { + item->setIcon(QIcon(":/res/iconDamage.png"));// game has started + item->setToolTip(tr("This game is in progress.\nYou may join and spectate now but you'll have to wait for the game to end to start playing.")); + } + + roomsList->setItem(r, 0, item); + + item = new QTableWidgetItem(list[i + 2]); // number of clients + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + item->setTextAlignment(Qt::AlignCenter); + item->setToolTip(tr("There are %1 clients connected to this room.", "", list[i + 2].toInt()).arg(list[i + 2])); + roomsList->setItem(r, 1, item); + + item = new QTableWidgetItem(list[i + 3]); // number of teams + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + item->setTextAlignment(Qt::AlignCenter); + item->setToolTip(tr("There are %1 teams participating in this room.", "", list[i + 3].toInt()).arg(list[i + 3])); + //Should we highlight "full" games? Might get misinterpreted + //if(list[i + 3].toInt() >= cMaxTeams) + // item->setForeground(red); + roomsList->setItem(r, 2, item); + + item = new QTableWidgetItem(list[i + 4].left(15)); // name of host + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + item->setToolTip(tr("%1 is the host. He may adjust settings and start the game.").arg(list[i + 4])); + roomsList->setItem(r, 3, item); + + if(list[i + 5] == "+rnd+") + { + item = new QTableWidgetItem(tr("Random Map")); // selected map (is randomized) +// FIXME - need real icons. Disabling until then +// item->setIcon(QIcon(":/res/mapRandom.png")); + } + else if (list[i+5] == "+maze+") + { + item = new QTableWidgetItem(tr("Random Maze")); +// FIXME - need real icons. Disabling until then +// item->setIcon(QIcon(":/res/mapMaze.png")); + } + else + { + item = new QTableWidgetItem(list[i + 5]); // selected map + + // check to see if we've got this map + // not perfect but a start + if(!mapList->contains(list[i + 5])) + { + item->setForeground(red); + item->setIcon(QIcon(":/res/mapMissing.png")); + } + else + { + // todo: mission icon? +// FIXME - need real icons. Disabling until then +// item->setIcon(QIcon(":/res/mapCustom.png")); + } + } + + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + item->setToolTip(tr("Games may be played on precreated or randomized maps.")); + roomsList->setItem(r, 4, item); + + item = new QTableWidgetItem(list[i + 6].left(24)); // selected game scheme + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + item->setToolTip(tr("The Game Scheme defines general options and preferences like Round Time, Sudden Death or Vampirism.")); + roomsList->setItem(r, 5, item); + + item = new QTableWidgetItem(list[i + 7].left(24)); // selected weapon scheme + item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); + item->setToolTip(tr("The Weapon Scheme defines available weapons and their ammunition count.")); + roomsList->setItem(r, 6, item); + + if(!list[i + 1].compare(selection) && !selection.isEmpty()) + roomsList->selectionModel()->setCurrentIndex(roomsList->model()->index(r, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + } + + roomsList->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); + roomsList->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents); + roomsList->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents); + roomsList->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents); + roomsList->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents); + roomsList->horizontalHeader()->setResizeMode(5, QHeaderView::ResizeToContents); + roomsList->horizontalHeader()->setResizeMode(6, QHeaderView::ResizeToContents); + + // TODO: Should NOT be done here + if (gameInLobby) { + gameInLobby = false; + if (gameCanBeJoined) { + emit askForJoinRoom(gameInLobbyName); + } else { + emit askJoinConfirmation(gameInLobbyName); + } + } + +// roomsList->resizeColumnsToContents(); +} + +void PageRoomsList::onCreateClick() +{ + if (roomName->text().size()) + emit askForCreateRoom(roomName->text()); + else + QMessageBox::critical(this, + tr("Error"), + tr("Please enter room name"), + tr("OK")); +} + +void PageRoomsList::onJoinClick() +{ + QTableWidgetItem * curritem = roomsList->item(roomsList->currentRow(), 0); + if (!curritem) + { + QMessageBox::critical(this, + tr("Error"), + tr("Please select room from the list"), + tr("OK")); + return; + } + + for (int i = 0; i < listFromServer.size(); i += 8) { + if (listFromServer[i + 1] == curritem->data(Qt::DisplayRole).toString()) { + gameInLobby = listFromServer[i].compare("True"); + break; + } + } + + if (gameInLobby) { + gameInLobbyName = curritem->data(Qt::DisplayRole).toString(); + emit askForRoomList(); + } else { + emit askForJoinRoom(curritem->data(Qt::DisplayRole).toString()); + } +} + +void PageRoomsList::onRefreshClick() +{ + emit askForRoomList(); +} + +void PageRoomsList::onClearClick() +{ + CBState->setCurrentIndex(0); + CBRules->setCurrentIndex(0); + CBWeapons->setCurrentIndex(0); + searchText->clear(); +} + +void PageRoomsList::onJoinConfirmation(const QString & room) +{ + if (QMessageBox::warning(this, + tr("Warning"), + tr("The game you are trying to join has started.\nDo you still want to join the room?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) + { + emit askForJoinRoom(room); + } +} + +void PageRoomsList::updateNickCounter(int cnt) +{ + lblCount->setText(tr("%1 players online", 0, cnt).arg(cnt)); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageroomslist.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageroomslist.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,83 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_ROOMLIST_H +#define PAGE_ROOMLIST_H + +#include "AbstractPage.h" +#include "SDLs.h" + +class HWChatWidget; +class AmmoSchemeModel; + +class PageRoomsList : public AbstractPage +{ + Q_OBJECT + +public: + PageRoomsList(QWidget* parent, QSettings * config, SDLInteraction * sdli); + + QLineEdit * roomName; + QLineEdit * searchText; + QTableWidget * roomsList; + QPushButton * BtnCreate; + QPushButton * BtnJoin; + QPushButton * BtnRefresh; + QPushButton * BtnAdmin; + QPushButton * BtnClear; + QComboBox * CBState; + QComboBox * CBRules; + QComboBox * CBWeapons; + HWChatWidget * chatWidget; + QLabel * lblCount; + +public slots: + void setRoomsList(const QStringList & list); + void setAdmin(bool); + void updateNickCounter(int cnt); + +signals: + void askForCreateRoom(const QString &); + void askForJoinRoom(const QString &); + void askForRoomList(); + void askJoinConfirmation(const QString &); + +protected: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + +private slots: + void onCreateClick(); + void onJoinClick(); + void onRefreshClick(); + void onClearClick(); + void onJoinConfirmation(const QString &); + +private: + QSettings * m_gameSettings; + SDLInteraction * m_sdli; + + bool gameInLobby; + QString gameInLobbyName; + QStringList listFromServer; + AmmoSchemeModel * ammoSchemeModel; + +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagescheme.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagescheme.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,510 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ammoSchemeModel.h" +#include "pagescheme.h" +#include "FreqSpinBox.h" + + +QLayout * PageScheme::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + QGroupBox * gb = new QGroupBox(this); + + QGridLayout * gl = new QGridLayout(); + gb->setLayout(gl); + QSizePolicy sp; + sp.setVerticalPolicy(QSizePolicy::MinimumExpanding); + sp.setHorizontalPolicy(QSizePolicy::Expanding); + + pageLayout->addWidget(gb, 1,0,13,5); + + gbGameModes = new QGroupBox(QGroupBox::tr("Game Modifiers"), gb); + gbBasicSettings = new QGroupBox(QGroupBox::tr("Basic Settings"), gb); + + // TODO name stuff and put CSS into main style sheet + gbGameModes->setStyleSheet(".QGroupBox {" + "background-color: #130f2c; background-image:url();" + "}"); + gbBasicSettings->setStyleSheet(".QGroupBox {" + "background-color: #130f2c; background-image:url();" + "}"); + + gbGameModes->setSizePolicy(sp); + gbBasicSettings->setSizePolicy(sp); + gl->addWidget(gbGameModes,0,0,1,3,Qt::AlignTop); + gl->addWidget(gbBasicSettings,0,3,1,3,Qt::AlignTop); + + QGridLayout * glGMLayout = new QGridLayout(gbGameModes); + QGridLayout * glBSLayout = new QGridLayout(gbBasicSettings); + gbGameModes->setLayout(glGMLayout); + gbBasicSettings->setLayout(glBSLayout); + // Left + + TBW_mode_Forts = new ToggleButtonWidget(gbGameModes, ":/res/btnForts@2x.png"); + TBW_mode_Forts->setToolTip("" + ToggleButtonWidget::tr("Fort Mode") + ":
" + tr("Defend your fort and destroy the opponents, two team colours max!")); + glGMLayout->addWidget(TBW_mode_Forts,0,0,1,1); + + TBW_teamsDivide = new ToggleButtonWidget(gbGameModes, ":/res/btnTeamsDivide@2x.png"); + TBW_teamsDivide->setToolTip("" + ToggleButtonWidget::tr("Divide Teams") + ":
" + tr("Teams will start on opposite sides of the terrain, two team colours max!")); + glGMLayout->addWidget(TBW_teamsDivide,0,1,1,1); + + TBW_solid = new ToggleButtonWidget(gbGameModes, ":/res/btnSolid@2x.png"); + TBW_solid->setToolTip("" + ToggleButtonWidget::tr("Solid Land") + ":
" + tr("Land can not be destroyed!")); + glGMLayout->addWidget(TBW_solid,0,2,1,1); + + TBW_border = new ToggleButtonWidget(gbGameModes, ":/res/btnBorder@2x.png"); + TBW_border->setToolTip("" + ToggleButtonWidget::tr("Add Border") + ":
" + tr("Add an indestructible border around the terrain")); + glGMLayout->addWidget(TBW_border,0,3,1,1); + + TBW_lowGravity = new ToggleButtonWidget(gbGameModes, ":/res/btnLowGravity@2x.png"); + TBW_lowGravity->setToolTip("" + ToggleButtonWidget::tr("Low Gravity") + ":
" + tr("Lower gravity")); + glGMLayout->addWidget(TBW_lowGravity,0,4,1,1); + + TBW_laserSight = new ToggleButtonWidget(gbGameModes, ":/res/btnLaserSight@2x.png"); + TBW_laserSight->setToolTip("" + ToggleButtonWidget::tr("Laser Sight") + ":
" + tr("Assisted aiming with laser sight")); + glGMLayout->addWidget(TBW_laserSight,1,0,1,1); + + TBW_invulnerable = new ToggleButtonWidget(gbGameModes, ":/res/btnInvulnerable@2x.png"); + TBW_invulnerable->setToolTip("" + ToggleButtonWidget::tr("Invulnerable") + ":
" + tr("All hogs have a personal forcefield")); + glGMLayout->addWidget(TBW_invulnerable,1,1,1,1); + + TBW_resethealth = new ToggleButtonWidget(gbGameModes, ":/res/btnResetHealth@2x.png"); + TBW_resethealth->setToolTip("" + ToggleButtonWidget::tr("Reset Health") + ":
" + tr("All (living) hedgehogs are fully restored at the end of turn")); + glGMLayout->addWidget(TBW_resethealth,1,2,1,1); + + TBW_vampiric = new ToggleButtonWidget(gbGameModes, ":/res/btnVampiric@2x.png"); + TBW_vampiric->setToolTip("" + ToggleButtonWidget::tr("Vampirism") + ":
" + tr("Gain 80% of the damage you do back in health")); + glGMLayout->addWidget(TBW_vampiric,1,3,1,1); + + TBW_karma = new ToggleButtonWidget(gbGameModes, ":/res/btnKarma@2x.png"); + TBW_karma->setToolTip("" + ToggleButtonWidget::tr("Karma") + ":
" + tr("Share your opponents pain, share their damage")); + glGMLayout->addWidget(TBW_karma,1,4,1,1); + + TBW_artillery = new ToggleButtonWidget(gbGameModes, ":/res/btnArtillery@2x.png"); + TBW_artillery->setToolTip("" + ToggleButtonWidget::tr("Artillery") + ":
" + tr("Your hogs are unable to move, put your artillery skills to the test")); + glGMLayout->addWidget(TBW_artillery,2,0,1,1); + + TBW_randomorder = new ToggleButtonWidget(gbGameModes, ":/res/btnRandomOrder@2x.png"); + TBW_randomorder->setToolTip("" + ToggleButtonWidget::tr("Random Order") + ":
" + tr("Order of play is random instead of in room order.")); + glGMLayout->addWidget(TBW_randomorder,2,1,1,1); + + TBW_king = new ToggleButtonWidget(gbGameModes, ":/res/btnKing@2x.png"); + TBW_king->setToolTip("" + ToggleButtonWidget::tr("King") + ":
" + tr("Play with a King. If he dies, your side dies.")); + glGMLayout->addWidget(TBW_king,2,2,1,1); + + TBW_placehog = new ToggleButtonWidget(gbGameModes, ":/res/btnPlaceHog@2x.png"); + TBW_placehog->setToolTip("" + ToggleButtonWidget::tr("Place Hedgehogs") + ":
" + tr("Take turns placing your hedgehogs before the start of play.")); + glGMLayout->addWidget(TBW_placehog,2,3,1,1); + + TBW_sharedammo = new ToggleButtonWidget(gbGameModes, ":/res/btnSharedAmmo@2x.png"); + TBW_sharedammo->setToolTip("" + ToggleButtonWidget::tr("Clan Shares Ammo") + ":
" + tr("Ammo is shared between all teams that share a colour.")); + glGMLayout->addWidget(TBW_sharedammo,2,4,1,1); + + TBW_disablegirders = new ToggleButtonWidget(gbGameModes, ":/res/btnDisableGirders@2x.png"); + TBW_disablegirders->setToolTip("" + ToggleButtonWidget::tr("Disable Girders") + ":
" + tr("Disable girders when generating random maps.")); + glGMLayout->addWidget(TBW_disablegirders,3,0,1,1); + + TBW_disablelandobjects = new ToggleButtonWidget(gbGameModes, ":/res/btnDisableLandObjects@2x.png"); + TBW_disablelandobjects->setToolTip("" + ToggleButtonWidget::tr("Disable Land Objects") + ":
" + tr("Disable land objects when generating random maps.")); + glGMLayout->addWidget(TBW_disablelandobjects,3,1,1,1); + + TBW_aisurvival = new ToggleButtonWidget(gbGameModes, ":/res/btnAISurvival@2x.png"); + TBW_aisurvival->setToolTip("" + ToggleButtonWidget::tr("AI Survival Mode") + ":
" + tr("AI respawns on death.")); + glGMLayout->addWidget(TBW_aisurvival,3,2,1,1); + + TBW_infattack = new ToggleButtonWidget(gbGameModes, ":/res/btnInfAttack@2x.png"); + TBW_infattack->setToolTip("" + ToggleButtonWidget::tr("Unlimited Attacks") + ":
" + tr("Attacking does not end your turn.")); + glGMLayout->addWidget(TBW_infattack,3,3,1,1); + + TBW_resetweps = new ToggleButtonWidget(gbGameModes, ":/res/btnResetWeps@2x.png"); + TBW_resetweps->setToolTip("" + ToggleButtonWidget::tr("Reset Weapons") + ":
" + tr("Weapons are reset to starting values each turn.")); + glGMLayout->addWidget(TBW_resetweps,3,4,1,1); + + TBW_perhogammo = new ToggleButtonWidget(gbGameModes, ":/res/btnPerHogAmmo@2x.png"); + TBW_perhogammo->setToolTip("" + ToggleButtonWidget::tr("Per Hedgehog Ammo") + ":
" + tr("Each hedgehog has its own ammo. It does not share with the team.")); + glGMLayout->addWidget(TBW_perhogammo,4,0,1,1); + + TBW_nowind = new ToggleButtonWidget(gbGameModes, ":/res/btnNoWind@2x.png"); + TBW_nowind->setToolTip("" + ToggleButtonWidget::tr("Disable Wind") + ":
" + tr("You will not have to worry about wind anymore.")); + glGMLayout->addWidget(TBW_nowind,4,1,1,1); + + TBW_morewind = new ToggleButtonWidget(gbGameModes, ":/res/btnMoreWind@2x.png"); + TBW_morewind->setToolTip("" + ToggleButtonWidget::tr("More Wind") + ":
" + tr("Wind will affect almost everything.")); + glGMLayout->addWidget(TBW_morewind,4,2,1,1); + + TBW_tagteam = new ToggleButtonWidget(gbGameModes, ":/res/btnTagTeam@2x.png"); + TBW_tagteam->setToolTip("" + ToggleButtonWidget::tr("Tag Team") + ":
" + tr("Teams in each clan take successive turns sharing their turn time.")); + glGMLayout->addWidget(TBW_tagteam,4,3,1,1); + + TBW_bottomborder = new ToggleButtonWidget(gbGameModes, ":/res/btnBottomBorder@2x.png"); + TBW_bottomborder->setToolTip("" + ToggleButtonWidget::tr("Add Bottom Border") + ":
" + tr("Add an indestructible border along the bottom")); + glGMLayout->addWidget(TBW_bottomborder,4,4,1,1); + + + // Right + QLabel * l; + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Damage Modifier")); + l->setWordWrap(true); + glBSLayout->addWidget(l,0,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconDamage.png")); + glBSLayout->addWidget(l,0,1,1,1); + SB_DamageModifier = new QSpinBox(gbBasicSettings); + SB_DamageModifier->setRange(10, 300); + SB_DamageModifier->setValue(100); + SB_DamageModifier->setSingleStep(25); + glBSLayout->addWidget(SB_DamageModifier,0,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Turn Time")); + l->setWordWrap(true); + glBSLayout->addWidget(l,1,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconTime.png")); + glBSLayout->addWidget(l,1,1,1,1); + SB_TurnTime = new QSpinBox(gbBasicSettings); + SB_TurnTime->setRange(1, 9999); + SB_TurnTime->setValue(45); + SB_TurnTime->setSingleStep(15); + glBSLayout->addWidget(SB_TurnTime,1,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Initial Health")); + l->setWordWrap(true); + glBSLayout->addWidget(l,2,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconHealth.png")); + glBSLayout->addWidget(l,2,1,1,1); + SB_InitHealth = new QSpinBox(gbBasicSettings); + SB_InitHealth->setRange(50, 200); + SB_InitHealth->setValue(100); + SB_InitHealth->setSingleStep(25); + glBSLayout->addWidget(SB_InitHealth,2,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Sudden Death Timeout")); + l->setWordWrap(true); + glBSLayout->addWidget(l,3,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconSuddenDeath.png")); + glBSLayout->addWidget(l,3,1,1,1); + SB_SuddenDeath = new QSpinBox(gbBasicSettings); + SB_SuddenDeath->setRange(0, 50); + SB_SuddenDeath->setValue(15); + SB_SuddenDeath->setSingleStep(3); + glBSLayout->addWidget(SB_SuddenDeath,3,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Sudden Death Water Rise")); + l->setWordWrap(true); + glBSLayout->addWidget(l,4,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconSuddenDeath.png")); // TODO: icon + glBSLayout->addWidget(l,4,1,1,1); + SB_WaterRise = new QSpinBox(gbBasicSettings); + SB_WaterRise->setRange(0, 100); + SB_WaterRise->setValue(47); + SB_WaterRise->setSingleStep(5); + glBSLayout->addWidget(SB_WaterRise,4,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Sudden Death Health Decrease")); + l->setWordWrap(true); + glBSLayout->addWidget(l,5,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconSuddenDeath.png")); // TODO: icon + glBSLayout->addWidget(l,5,1,1,1); + SB_HealthDecrease = new QSpinBox(gbBasicSettings); + SB_HealthDecrease->setRange(0, 100); + SB_HealthDecrease->setValue(5); + SB_HealthDecrease->setSingleStep(1); + glBSLayout->addWidget(SB_HealthDecrease,5,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("% Rope Length")); + l->setWordWrap(true); + glBSLayout->addWidget(l,6,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconRope.png")); + glBSLayout->addWidget(l,6,1,1,1); + SB_RopeModifier = new QSpinBox(gbBasicSettings); + SB_RopeModifier->setRange(25, 999); + SB_RopeModifier->setValue(100); + SB_RopeModifier->setSingleStep(25); + glBSLayout->addWidget(SB_RopeModifier,6,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Crate Drops")); + l->setWordWrap(true); + glBSLayout->addWidget(l,7,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconBox.png")); + glBSLayout->addWidget(l,7,1,1,1); + SB_CaseProb = new FreqSpinBox(gbBasicSettings); + SB_CaseProb->setRange(0, 9); + SB_CaseProb->setValue(5); + glBSLayout->addWidget(SB_CaseProb,7,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("% Health Crates")); + l->setWordWrap(true); + glBSLayout->addWidget(l,8,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconHealth.png")); // TODO: icon + glBSLayout->addWidget(l,8,1,1,1); + SB_HealthCrates = new QSpinBox(gbBasicSettings); + SB_HealthCrates->setRange(0, 100); + SB_HealthCrates->setValue(35); + SB_HealthCrates->setSingleStep(5); + glBSLayout->addWidget(SB_HealthCrates,8,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Health in Crates")); + l->setWordWrap(true); + glBSLayout->addWidget(l,9,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconHealth.png")); // TODO: icon + glBSLayout->addWidget(l,9,1,1,1); + SB_CrateHealth = new QSpinBox(gbBasicSettings); + SB_CrateHealth->setRange(0, 200); + SB_CrateHealth->setValue(25); + SB_CrateHealth->setSingleStep(5); + glBSLayout->addWidget(SB_CrateHealth,9,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Mines Time")); + l->setWordWrap(true); + glBSLayout->addWidget(l,10,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconTime.png")); // TODO: icon + glBSLayout->addWidget(l,10,1,1,1); + SB_MinesTime = new QSpinBox(gbBasicSettings); + SB_MinesTime->setRange(-1, 5); + SB_MinesTime->setValue(3); + SB_MinesTime->setSingleStep(1); + SB_MinesTime->setSpecialValueText(tr("Random")); + SB_MinesTime->setSuffix(" "+ tr("Seconds")); + glBSLayout->addWidget(SB_MinesTime,10,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Mines")); + l->setWordWrap(true); + glBSLayout->addWidget(l,11,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconMine.png")); // TODO: icon + glBSLayout->addWidget(l,11,1,1,1); + SB_Mines = new QSpinBox(gbBasicSettings); + SB_Mines->setRange(0, 80); + SB_Mines->setValue(0); + SB_Mines->setSingleStep(5); + glBSLayout->addWidget(SB_Mines,11,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("% Dud Mines")); + l->setWordWrap(true); + glBSLayout->addWidget(l,12,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconDud.png")); + glBSLayout->addWidget(l,12,1,1,1); + SB_MineDuds = new QSpinBox(gbBasicSettings); + SB_MineDuds->setRange(0, 100); + SB_MineDuds->setValue(0); + SB_MineDuds->setSingleStep(5); + glBSLayout->addWidget(SB_MineDuds,12,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Explosives")); + l->setWordWrap(true); + glBSLayout->addWidget(l,13,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconDamage.png")); + glBSLayout->addWidget(l,13,1,1,1); + SB_Explosives = new QSpinBox(gbBasicSettings); + SB_Explosives->setRange(0, 40); + SB_Explosives->setValue(0); + SB_Explosives->setSingleStep(1); + glBSLayout->addWidget(SB_Explosives,13,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("% Get Away Time")); + l->setWordWrap(true); + glBSLayout->addWidget(l,14,0,1,1); + l = new QLabel(gbBasicSettings); + l->setFixedSize(32,32); + l->setPixmap(QPixmap(":/res/iconTime.png")); + glBSLayout->addWidget(l,14,1,1,1); + SB_GetAwayTime = new QSpinBox(gbBasicSettings); + SB_GetAwayTime->setRange(0, 999); + SB_GetAwayTime->setValue(100); + SB_GetAwayTime->setSingleStep(25); + glBSLayout->addWidget(SB_GetAwayTime,14,2,1,1); + + l = new QLabel(gbBasicSettings); + l->setText(QLabel::tr("Scheme Name:")); + + LE_name = new QLineEdit(this); + + gl->addWidget(LE_name,15,1,1,5); + gl->addWidget(l,15,0,1,1); + + return pageLayout; +} + +QLayout * PageScheme::footerLayoutDefinition() +{ + QHBoxLayout * bottomLayout = new QHBoxLayout(); + selectScheme = new QComboBox(this); + + bottomLayout->addWidget(selectScheme, 0); + BtnCopy = addButton(tr("Copy"), bottomLayout, 1); + BtnNew = addButton(tr("New"), bottomLayout, 2); + BtnDelete = addButton(tr("Delete"), bottomLayout, 3); + + bottomLayout->setStretch(1,1); + bottomLayout->setStretch(2,1); + bottomLayout->setStretch(3,1); + + return bottomLayout; +} + +void PageScheme::connectSignals() +{ + connect(BtnCopy, SIGNAL(clicked()), this, SLOT(copyRow())); + connect(BtnNew, SIGNAL(clicked()), this, SLOT(newRow())); + connect(BtnDelete, SIGNAL(clicked()), this, SLOT(deleteRow())); + mapper = new QDataWidgetMapper(this); + connect(selectScheme, SIGNAL(currentIndexChanged(int)), mapper, SLOT(setCurrentIndex(int))); + connect(selectScheme, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeSelected(int))); +} + +PageScheme::PageScheme(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} + +void PageScheme::setModel(QAbstractItemModel * model) +{ + mapper->setModel(model); + selectScheme->setModel(model); + + mapper->addMapping(LE_name, 0); + mapper->addMapping(TBW_mode_Forts, 1); + mapper->addMapping(TBW_teamsDivide, 2); + mapper->addMapping(TBW_solid, 3); + mapper->addMapping(TBW_border, 4); + mapper->addMapping(TBW_lowGravity, 5); + mapper->addMapping(TBW_laserSight, 6); + mapper->addMapping(TBW_invulnerable, 7); + mapper->addMapping(TBW_resethealth, 8); + mapper->addMapping(TBW_vampiric, 9); + mapper->addMapping(TBW_karma, 10); + mapper->addMapping(TBW_artillery, 11); + mapper->addMapping(TBW_randomorder, 12); + mapper->addMapping(TBW_king, 13); + mapper->addMapping(TBW_placehog, 14); + mapper->addMapping(TBW_sharedammo, 15); + mapper->addMapping(TBW_disablegirders, 16); + mapper->addMapping(TBW_disablelandobjects, 17); + mapper->addMapping(TBW_aisurvival, 18); + mapper->addMapping(TBW_infattack, 19); + mapper->addMapping(TBW_resetweps, 20); + mapper->addMapping(TBW_perhogammo, 21); + mapper->addMapping(TBW_nowind, 22); + mapper->addMapping(TBW_morewind, 23); + mapper->addMapping(TBW_tagteam, 24); + mapper->addMapping(TBW_bottomborder, 25); + mapper->addMapping(SB_DamageModifier, 26); + mapper->addMapping(SB_TurnTime, 27); + mapper->addMapping(SB_InitHealth, 28); + mapper->addMapping(SB_SuddenDeath, 29); + mapper->addMapping(SB_CaseProb, 30); + mapper->addMapping(SB_MinesTime, 31); + mapper->addMapping(SB_Mines, 32); + mapper->addMapping(SB_MineDuds, 33); + mapper->addMapping(SB_Explosives, 34); + mapper->addMapping(SB_HealthCrates, 35); + mapper->addMapping(SB_CrateHealth, 36); + mapper->addMapping(SB_WaterRise, 37); + mapper->addMapping(SB_HealthDecrease, 38); + mapper->addMapping(SB_RopeModifier, 39); + mapper->addMapping(SB_GetAwayTime, 40); + + mapper->toFirst(); +} + +void PageScheme::newRow() +{ + QAbstractItemModel * model = mapper->model(); + model->insertRow(-1); + selectScheme->setCurrentIndex(model->rowCount() - 1); +} + +void PageScheme::copyRow() +{ + QAbstractItemModel * model = mapper->model(); + model->insertRow(selectScheme->currentIndex()); + selectScheme->setCurrentIndex(model->rowCount() - 1); +} + +void PageScheme::deleteRow() +{ + QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Schemes"), QMessageBox::tr("Really delete this game scheme?"), QMessageBox::Ok | QMessageBox::Cancel); + + if (reallyDelete.exec() == QMessageBox::Ok) { + QAbstractItemModel * model = mapper->model(); + model->removeRow(selectScheme->currentIndex()); + } +} + +void PageScheme::schemeSelected(int n) +{ + int c = ((AmmoSchemeModel*)mapper->model())->numberOfDefaultSchemes; + gbGameModes->setEnabled(n >= c); + gbBasicSettings->setEnabled(n >= c); + LE_name->setEnabled(n >= c); +} + + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagescheme.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagescheme.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,104 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_SCHEME_H +#define PAGE_SCHEME_H + +#include "AbstractPage.h" +#include "togglebutton.h" + +class FreqSpinBox; + +class PageScheme : public AbstractPage +{ + Q_OBJECT + +public: + PageScheme(QWidget* parent = 0); + + QPushButton * BtnCopy; + QPushButton * BtnNew; + QPushButton * BtnDelete; + QPushButton * btnSave; + QComboBox * selectScheme; + + void setModel(QAbstractItemModel * model); + +public slots: + void newRow(); + void copyRow(); + void deleteRow(); + +protected: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + +private: + QDataWidgetMapper * mapper; + ToggleButtonWidget * TBW_mode_Forts; + ToggleButtonWidget * TBW_teamsDivide; + ToggleButtonWidget * TBW_solid; + ToggleButtonWidget * TBW_border; + ToggleButtonWidget * TBW_lowGravity; + ToggleButtonWidget * TBW_laserSight; + ToggleButtonWidget * TBW_invulnerable; + ToggleButtonWidget * TBW_resethealth; + ToggleButtonWidget * TBW_vampiric; + ToggleButtonWidget * TBW_karma; + ToggleButtonWidget * TBW_artillery; + ToggleButtonWidget * TBW_randomorder; + ToggleButtonWidget * TBW_king; + ToggleButtonWidget * TBW_placehog; + ToggleButtonWidget * TBW_sharedammo; + ToggleButtonWidget * TBW_disablegirders; + ToggleButtonWidget * TBW_disablelandobjects; + ToggleButtonWidget * TBW_aisurvival; + ToggleButtonWidget * TBW_infattack; + ToggleButtonWidget * TBW_resetweps; + ToggleButtonWidget * TBW_perhogammo; + ToggleButtonWidget * TBW_nowind; + ToggleButtonWidget * TBW_morewind; + ToggleButtonWidget * TBW_tagteam; + ToggleButtonWidget * TBW_bottomborder; + + QSpinBox * SB_DamageModifier; + QSpinBox * SB_TurnTime; + QSpinBox * SB_InitHealth; + QSpinBox * SB_SuddenDeath; + QSpinBox * SB_WaterRise; + QSpinBox * SB_HealthDecrease; + FreqSpinBox * SB_CaseProb; + QSpinBox * SB_HealthCrates; + QSpinBox * SB_CrateHealth; + QSpinBox * SB_MinesTime; + QSpinBox * SB_Mines; + QSpinBox * SB_MineDuds; + QSpinBox * SB_Explosives; + QSpinBox * SB_RopeModifier; + QSpinBox * SB_GetAwayTime; + QLineEdit * LE_name; + + QGroupBox * gbGameModes; + QGroupBox * gbBasicSettings; + +private slots: + void schemeSelected(int); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageselectweapon.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageselectweapon.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,75 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "pageselectweapon.h" +#include "hwconsts.h" +#include "selectWeapon.h" + +QLayout * PageSelectWeapon::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + + pWeapons = new SelWeaponWidget(cAmmoNumber, this); + pageLayout->addWidget(pWeapons); + + return pageLayout; +} + +QLayout * PageSelectWeapon::footerLayoutDefinition() +{ + QGridLayout * bottomLayout = new QGridLayout(); + + selectWeaponSet = new QComboBox(this); + bottomLayout->addWidget(selectWeaponSet, 0, 0, 2, 1); + + // first row + BtnNew = addButton(tr("New"), bottomLayout, 0, 1); + BtnDefault = addButton(tr("Default"), bottomLayout, 0, 2); + + // second row + BtnCopy = addButton(tr("Copy"), bottomLayout, 1, 1); + BtnDelete = addButton(tr("Delete"), bottomLayout, 1, 2); + + bottomLayout->setColumnStretch(1,1); + bottomLayout->setColumnStretch(2,1); + + btnSave = addButton(":/res/Save.png", bottomLayout, 0, 3, 2, 1, true); + btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}"); + bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom); + + return bottomLayout; +} + +void PageSelectWeapon::connectSignals() +{ + connect(BtnDefault, SIGNAL(clicked()), pWeapons, SLOT(setDefault())); + connect(btnSave, SIGNAL(clicked()), pWeapons, SLOT(save())); + connect(BtnNew, SIGNAL(clicked()), pWeapons, SLOT(newWeaponsName())); + connect(BtnCopy, SIGNAL(clicked()), pWeapons, SLOT(copy())); + connect(selectWeaponSet, SIGNAL(currentIndexChanged(const QString&)), pWeapons, SLOT(setWeaponsName(const QString&))); +} + +PageSelectWeapon::PageSelectWeapon(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pageselectweapon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pageselectweapon.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,47 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_SELECTWEAPON_H +#define PAGE_SELECTWEAPON_H + +#include "AbstractPage.h" + +class SelWeaponWidget; + +class PageSelectWeapon : public AbstractPage +{ + Q_OBJECT + +public: + PageSelectWeapon(QWidget* parent = 0); + + QPushButton *btnSave; + QPushButton *BtnDefault; + QPushButton *BtnDelete; + QPushButton *BtnNew; + QPushButton *BtnCopy; + SelWeaponWidget* pWeapons; + QComboBox* selectWeaponSet; + +protected: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); +}; + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagesingleplayer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagesingleplayer.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,83 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#include "pagesingleplayer.h" +#include "gamecfgwidget.h" + +QLayout * PageSinglePlayer::bodyLayoutDefinition() +{ + QVBoxLayout * vLayout = new QVBoxLayout(); + + QHBoxLayout * topLine = new QHBoxLayout(); + QHBoxLayout * middleLine = new QHBoxLayout(); + vLayout->addStretch(); + vLayout->addLayout(topLine); + vLayout->addSpacing(30); + vLayout->addLayout(middleLine); + vLayout->addStretch(); + + topLine->addStretch(); + BtnSimpleGamePage = addButton(":/res/SimpleGame.png", topLine, 0, true); + BtnSimpleGamePage->setToolTip(tr("Simple Game (a quick game against the computer, settings are chosen for you)")); + topLine->addSpacing(60); + BtnMultiplayer = addButton(":/res/Multiplayer.png", topLine, 1, true); + BtnMultiplayer->setToolTip(tr("Multiplayer (play a hotseat game against your friends, or AI teams)")); + topLine->addStretch(); + + + BtnCampaignPage = addButton(":/res/Campaign.png", middleLine, 0, true); + BtnCampaignPage->setToolTip(tr("Campaign Mode (...). IN DEVELOPMENT")); + BtnCampaignPage->setVisible(false); + + BtnTrainPage = addButton(":/res/Trainings.png", middleLine, 1, true); + BtnTrainPage->setToolTip(tr("Training Mode (Practice your skills in a range of training missions). IN DEVELOPMENT")); + + return vLayout; +} + +QLayout * PageSinglePlayer::footerLayoutDefinition() +{ + QHBoxLayout * bottomLine = new QHBoxLayout(); + bottomLine->addStretch(); + + BtnDemos = addButton(":/res/Record.png", bottomLine, 1, true); + BtnDemos->setToolTip(tr("Demos (Watch recorded demos)")); + BtnLoad = addButton(":/res/Load.png", bottomLine, 2, true); + BtnLoad->setStyleSheet("QPushButton{margin: 24px 0 0 0;}"); + BtnLoad->setToolTip(tr("Load (Load a previously saved game)")); + + bottomLine->setStretch(1,0); + bottomLine->setStretch(2,0); + bottomLine->setAlignment(BtnDemos, Qt::AlignRight | Qt::AlignBottom); + bottomLine->setAlignment(BtnLoad, Qt::AlignRight | Qt::AlignBottom); + + return bottomLine; +} + +void PageSinglePlayer::connectSignals() +{ + //TODO +} + +PageSinglePlayer::PageSinglePlayer(QWidget* parent) : AbstractPage(parent) +{ + initPage(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagesingleplayer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagesingleplayer.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,48 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_SINGLE_PLAYER_H +#define PAGE_SINGLE_PLAYER_H + +#include "AbstractPage.h" + +class GameCFGWidget; + +class PageSinglePlayer : public AbstractPage +{ + Q_OBJECT + +public: + PageSinglePlayer(QWidget* parent = 0); + + QPushButton *BtnSimpleGamePage; + QPushButton *BtnTrainPage; + QPushButton *BtnCampaignPage; + QPushButton *BtnMultiplayer; + QPushButton *BtnLoad; + QPushButton *BtnDemos; + GameCFGWidget *gameCFG; + +private: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagetraining.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagetraining.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,234 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "pagetraining.h" +#include "hwconsts.h" + +QLayout * PageTraining::bodyLayoutDefinition() +{ + QGridLayout * pageLayout = new QGridLayout(); + +// left column + + // declare start button, caption and description + btnPreview = formattedButton(":/res/Trainings.png", true); + btnPreview->setToolTip(QPushButton::tr("Go!")); + + // make both rows equal height + pageLayout->setRowStretch(0, 1); + pageLayout->setRowStretch(1, 1); + + // add start button, caption and description to 3 different rows + pageLayout->addWidget(btnPreview, 0, 0); + + // center preview + pageLayout->setAlignment(btnPreview, Qt::AlignRight | Qt::AlignVCenter); + + +// right column + + // info area (caption on top, description below) + QVBoxLayout * infoLayout = new QVBoxLayout(); + + lblCaption = new QLabel(); + lblCaption->setMinimumWidth(360); + lblCaption->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); + lblCaption->setWordWrap(true); + lblDescription = new QLabel(); + lblDescription->setMinimumWidth(360); + lblDescription->setAlignment(Qt::AlignHCenter | Qt::AlignTop); + lblDescription->setWordWrap(true); + + infoLayout->addWidget(lblCaption); + infoLayout->addWidget(lblDescription); + + pageLayout->addLayout(infoLayout, 0, 1); + pageLayout->setAlignment(infoLayout, Qt::AlignLeft); + + + // mission list + lstMissions = new QListWidget(this); + pageLayout->addWidget(lstMissions, 1, 0, 1, 2); // span 2 columns + + // let's not make the list use more space than needed + lstMissions->setFixedWidth(360); + pageLayout->setAlignment(lstMissions, Qt::AlignHCenter); + + return pageLayout; +} + +QLayout * PageTraining::footerLayoutDefinition() +{ + QBoxLayout * bottomLayout = new QVBoxLayout(); + + btnStart = formattedButton(QPushButton::tr("Go!")); + btnStart->setFixedWidth(140); + + bottomLayout->addWidget(btnStart); + + bottomLayout->setAlignment(btnStart, Qt::AlignRight | Qt::AlignVCenter); + + return bottomLayout; +} + + +void PageTraining::connectSignals() +{ + connect(lstMissions, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateInfo())); + connect(lstMissions, SIGNAL(clicked()), this, SLOT(updateInfo())); + connect(lstMissions, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(startSelected())); + connect(btnPreview, SIGNAL(clicked()), this, SLOT(startSelected())); + connect(btnStart, SIGNAL(clicked()), this, SLOT(startSelected())); +} + + +PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent) +{ + initPage(); + + // get locale + QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", + QSettings::IniFormat); + + QString loc = settings.value("misc/locale", "").toString(); + if (loc.isEmpty()) + loc = QLocale::system().name(); + + QString infoFile = + datadir->absolutePath() + "/Locale/missions_" + loc + ".txt"; + + // if file is non-existant try with language only + if (!QFile::exists(infoFile)) + infoFile = datadir->absolutePath() + "/Locale/missions_" + + loc.replace(QRegExp("_.*$"),"") + ".txt"; + + // fallback if file for current locale is non-existant + if (!QFile::exists(infoFile)) + infoFile = datadir->absolutePath() + "/Locale/missions_en.txt"; + + // preload mission info for current locale + m_info = new QSettings(infoFile, QSettings::IniFormat, this); + +// TODO -> this should be done in a tool "DataDir" class + QDir tmpdir; + tmpdir.cd(cfgdir->absolutePath()); + tmpdir.cd("Data/Missions/Training"); + QStringList missionList = scriptList(tmpdir); + missionList.sort(); + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Missions/Training"); + QStringList defaultList = scriptList(tmpdir); + defaultList.sort(); + + // add non-duplicate default scripts to the list + foreach (const QString & mission, defaultList) + { + if (!missionList.contains(mission)) + missionList.append(mission); + } + + // add default scripts that have names different from detected user scripts + foreach (const QString & mission, missionList) + { + QListWidgetItem * item = new QListWidgetItem(mission); + + // fallback name: replace underscores in mission name with spaces + QString name = item->text().replace("_", " "); + + // see if we can get a prettier/translated name + name = m_info->value(mission + ".name", name).toString(); + + item->setText(name); + + // store original name in data + item->setData(Qt::UserRole, mission); + + lstMissions->addItem(item); + } + + updateInfo(); + + // pre-select first mission + if (lstMissions->count() > 0) + lstMissions->setCurrentRow(0); +} + +QStringList PageTraining::scriptList(const QDir & scriptDir) const +{ + QDir dir = scriptDir; + dir.setFilter(QDir::Files); + return dir.entryList(QStringList("*.lua")).replaceInStrings(QRegExp("^(.*)\\.lua"), "\\1"); +} + + +void PageTraining::startSelected() +{ + QListWidgetItem * curItem = lstMissions->currentItem(); + + if (curItem != NULL) + emit startMission(curItem->data(Qt::UserRole).toString()); +} + + +void PageTraining::updateInfo() +{ + if (lstMissions->currentItem()) + { + // TODO also use .pngs in userdata folder + QString thumbFile = datadir->absolutePath() + + "/Graphics/Missions/Training/" + + lstMissions->currentItem()->data(Qt::UserRole).toString() + + "@2x.png"; + + if (QFile::exists(thumbFile)) + btnPreview->setIcon(QIcon(thumbFile)); + else + btnPreview->setIcon(QIcon(":/res/Trainings.png")); + + QString realName = lstMissions->currentItem()->data( + Qt::UserRole).toString(); + + QString caption = m_info->value(realName + ".name", + lstMissions->currentItem()->text()).toString(); + + QString description = m_info->value(realName + ".desc", + tr("No description available")).toString(); + + lblCaption->setText("

" + caption +"

"); + lblDescription->setText(description); + } + else + { + btnPreview->setIcon(QIcon(":/res/Trainings.png")); + lblCaption->setText(tr("Select a mission!")); + // TODO better text and tr() + lblDescription->setText(""); + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/page/pagetraining.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/page/pagetraining.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,62 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PAGE_TRAINING_H +#define PAGE_TRAINING_H + +#include + +#include "AbstractPage.h" + +class PageTraining : public AbstractPage +{ + Q_OBJECT + +public: + PageTraining(QWidget* parent = 0); + + +signals: + void startMission(const QString & scriptName); + + +protected: + QLayout * bodyLayoutDefinition(); + QLayout * footerLayoutDefinition(); + void connectSignals(); + + +private: + QPushButton * btnPreview; + QPushButton * btnStart; + QLabel * lblCaption; + QLabel * lblDescription; + QListWidget * lstMissions; + QSettings * m_info; + + QStringList scriptList(const QDir & scriptDir) const; + + +private slots: + void startSelected(); + void updateInfo(); + +}; + +#endif + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/qaspectratiolayout.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/qaspectratiolayout.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2009 Nokia Corporation. + */ + +#include "qaspectratiolayout.h" + +QAspectRatioLayout::QAspectRatioLayout(QWidget* parent, int spacing) : QLayout(parent) { + init(spacing); +} + +QAspectRatioLayout::QAspectRatioLayout(int spacing) { + init(spacing); +} + +QAspectRatioLayout::~QAspectRatioLayout() { + delete item; + delete lastReceivedRect; + delete _geometry; +} + +void QAspectRatioLayout::init(int spacing) { + item = 0; + lastReceivedRect = new QRect(0, 0, 0, 0); + _geometry = new QRect(0, 0, 0, 0); + setSpacing(spacing); +} + + +/* Adds item if place isn't already taken. */ +void QAspectRatioLayout::add(QLayoutItem* item) { + if(!hasItem()) { + replaceItem(item); + } +} + +/* Adds item if place isn't already taken. */ +void QAspectRatioLayout::addItem(QLayoutItem* item) { + if(!hasItem()) { + replaceItem(item); + } +} + +/* Adds widget if place isn't already taken. */ +void QAspectRatioLayout::addWidget(QWidget* widget) { + if(!hasItem()) { + replaceItem(new QWidgetItem(widget)); + } +} + +/* Returns the item pointer and dereferences it here. */ +QLayoutItem* QAspectRatioLayout::take() { + QLayoutItem* item = 0; + if(this->hasItem()) { + item = this->item; + this->item = 0; + } + return item; +} + +/* Returns the item pointer and dereferences it here. */ +QLayoutItem* QAspectRatioLayout::takeAt(int index) { + if(index != 0) { + return 0; + } + return this->take(); +} + +/* Returns the item pointer. */ +QLayoutItem* QAspectRatioLayout::itemAt(int index) const { + if(index != 0) { + return 0; + } + if(hasItem()) { + return this->item; + } + return 0; +} + +/* Checks if we have an item. */ +bool QAspectRatioLayout::hasItem() const { + return this->item != 0; +} + +/* Returns the count of items which can be either 0 or 1. */ +int QAspectRatioLayout::count() const { + int returnValue = 0; + if(hasItem()) { + returnValue = 1; + } + return returnValue; +} + +/* Replaces the item with the new and returns the old. */ +QLayoutItem* QAspectRatioLayout::replaceItem(QLayoutItem* item) { + QLayoutItem* old = 0; + if(this->hasItem()) { + old = this->item; + } + this->item = item; + setGeometry(*this->_geometry); + return old; +} + +/* Tells which way layout expands. */ +Qt::Orientations QAspectRatioLayout::expandingDirections() const { + return Qt::Horizontal | Qt::Vertical; +} + +/* Tells which size is preferred. */ +QSize QAspectRatioLayout::sizeHint() const { + return this->item->minimumSize(); +} + +/* Tells minimum size. */ +QSize QAspectRatioLayout::minimumSize() const { + return this->item->minimumSize(); +} + +/* + * Tells if heightForWidth calculations is handled. + * It isn't since width isn't enough to calculate + * proper size. + */ +bool QAspectRatioLayout::hasHeightForWidth() const { + return false; +} + +/* Replaces lastReceivedRect. */ +void QAspectRatioLayout::setLastReceivedRect(const QRect& rect) { + QRect* oldRect = this->lastReceivedRect; + this->lastReceivedRect = new QRect(rect.topLeft(), rect.size()); + delete oldRect; +} + +/* Returns geometry */ +QRect QAspectRatioLayout::geometry() { + return QRect(*this->_geometry); +} + +/* Sets geometry to given size. */ +void QAspectRatioLayout::setGeometry(const QRect& rect) { + /* + * We check if the item is set and + * if size is the same previously received. + * If either is false nothing is done. + */ + if(!this->hasItem() || + areRectsEqual(*this->lastReceivedRect, rect)) { + return; + } + /* Replace the last received rectangle. */ + setLastReceivedRect(rect); + /* Calculate proper size for the item relative to the received size. */ + QSize properSize = calculateProperSize(rect.size()); + /* Calculate center location in the rect and with item size. */ + QPoint properLocation = calculateCenterLocation(rect.size(), properSize); + /* Set items geometry */ + this->item->setGeometry(QRect(properLocation, properSize)); + QRect* oldRect = this->_geometry; + /* Cache the calculated geometry. */ + this->_geometry = new QRect(properLocation, properSize); + delete oldRect; + /* Super classes setGeometry */ + QLayout::setGeometry(*this->_geometry); +} + +/* Takes the shortest side and creates QSize + * with the shortest side as width and height. */ +QSize QAspectRatioLayout::calculateProperSize(QSize from) const { + QSize properSize; + if(from.height() * 2 < from.width()) { + properSize.setHeight(from.height() - this->margin()); + properSize.setWidth(from.height() * 2 - this->margin()); + } + else { + properSize.setWidth(from.width() - this->margin()); + properSize.setHeight(from.width() / 2 - this->margin()); + } + return properSize; +} + +/* Calculates center location from the given height and width for item size. */ +QPoint QAspectRatioLayout::calculateCenterLocation(QSize from, + QSize itemSize) const { + QPoint centerLocation; + if((from.width() - itemSize.width()) > 0) { + centerLocation.setX((from.width() - itemSize.width())/2); + } + if((from.height() - itemSize.height()) > 0) { + centerLocation.setY((from.height() - itemSize.height())/2); + } + return centerLocation; +} + +/* Compares if two QRects are equal. */ +bool QAspectRatioLayout::areRectsEqual(const QRect& a, + const QRect& b) const { + bool result = false; + if(a.x() == b.x() && + a.y() == b.y() && + a.height() == b.height() && + a.width() == b.width()) { + result = true; + } + return result; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/qaspectratiolayout.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/qaspectratiolayout.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2009 Nokia Corporation. + */ + +#ifndef QASPECTRATIOLAYOUT_H_ +#define QASPECTRATIOLAYOUT_H_ + +#include +#include +#include +#include +#include + + +class QAspectRatioLayout : public QLayout +{ + Q_OBJECT + +public: + QAspectRatioLayout(QWidget* parent, int spacing =-1); + QAspectRatioLayout(int spacing = -1); + ~QAspectRatioLayout(); + + /* Convenience method */ + virtual void add(QLayoutItem* item); + +/* http://doc.trolltech.com/qlayout.html#addItem */ + virtual void addItem(QLayoutItem* item); + /* http://doc.trolltech.com/qlayout.html#addWidget */ + virtual void addWidget(QWidget* widget); + /* http://doc.trolltech.com/qlayout.html#takeAt */ + virtual QLayoutItem* takeAt(int index); + /* http://doc.trolltech.com/qlayout.html#itemAt */ + virtual QLayoutItem* itemAt(int index) const; + /* http://doc.trolltech.com/qlayout.html#count */ + virtual int count() const; + + /* + * These are ours since we do have only one item. + */ + virtual QLayoutItem* replaceItem(QLayoutItem* item); + virtual QLayoutItem* take(); + virtual bool hasItem() const; + +/* http://doc.trolltech.com/qlayout.html#expandingDirections */ + virtual Qt::Orientations expandingDirections() const; + + /* + * This method contains most of the juice of this article. + * http://doc.trolltech.com/qlayoutitem.html#setGeometry + */ + virtual void setGeometry(const QRect& rect); + /* http://doc.trolltech.com/qlayoutitem.html#geometry */ + virtual QRect geometry(); + + /* http://doc.trolltech.com/qlayoutitem.html#sizeHint */ + virtual QSize sizeHint() const; + /* http://doc.trolltech.com/qlayout.html#minimumSize */ + virtual QSize minimumSize() const; + /* http://doc.trolltech.com/qlayoutitem.html#hasHeightForWidth */ + virtual bool hasHeightForWidth() const; + +private: + /* Saves the last received rect. */ + void setLastReceivedRect(const QRect& rect); + /* Used to initialize the object. */ + void init(int spacing); + /* Calculates the maximum size for the item from the assigned size. */ + QSize calculateProperSize(QSize from) const; + /* Calculates the center location from the assigned size and + * the items size. */ + QPoint calculateCenterLocation(QSize from, QSize itemSize) const; + /* Check if two QRects are equal */ + bool areRectsEqual(const QRect& a, const QRect& b) const; + /* Contains item reference */ + QLayoutItem* item; + /* + * Used for caching so we won't do calculations every time + * setGeometry is called. + */ + QRect* lastReceivedRect; + /* Contains geometry */ + QRect* _geometry; + +}; + +#endif /* QASPECTRATIOLAYOUT_H_ */ diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/FreqSpinBox.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/FreqSpinBox.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,33 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2005-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "FreqSpinBox.h" + +/** + * Returns it's value as localized frequency. + * 'Never', 'Every Turn', 'Every 2 Turns', etc. + * @param value integer value to be representing as string + * @return the turn frequence-like string representation + */ +QString FreqSpinBox::textFromValue(int value) const +{ + if (value == 0) + return tr("Never"); + else + return tr("Every %1 turn", "", value).arg(value); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/FreqSpinBox.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/FreqSpinBox.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,44 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2005-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef FREQSPINBOX_H +#define FREQSPINBOX_H + + +#include +#include + +/** + * A SpinBox that returns it's value as localized turn frequency. + * 'Never', 'Every Turn', 'Every 2 Turns', etc. + * @author unc0rr + * @since 0.9.12 + */ +class FreqSpinBox : public QSpinBox +{ + Q_OBJECT + +public: + FreqSpinBox(QWidget* parent) : QSpinBox(parent) {}; + +protected: + QString textFromValue(int value) const; +}; + + +#endif // FREQSPINBOX_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/SquareLabel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/SquareLabel.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,50 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include "SquareLabel.h" +#include "hwform.h" + +SquareLabel::SquareLabel(QWidget * parent) : + QWidget(parent) +{ + if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); +} + +void SquareLabel::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + + QPainter painter(this); + int pixsize; + if (width() > height()) { + pixsize = height(); + painter.translate((width() - pixsize) / 2, 0); + } else { + pixsize = width(); + painter.translate(0, (height() - pixsize) / 2); + } + painter.drawPixmap(0, 0, pixsize, pixsize, pixmap.scaled(pixsize, pixsize, Qt::KeepAspectRatio)); +} + +void SquareLabel::setPixmap(const QPixmap & pixmap) +{ + this->pixmap = pixmap; + repaint(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/SquareLabel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/SquareLabel.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,41 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _SQUARELABEL_H +#define _SQUARELABEL_H + +#include +#include + +class SquareLabel : public QWidget +{ + Q_OBJECT + +public: + SquareLabel(QWidget * parent = 0); + + void setPixmap(const QPixmap & pixmap); +protected: + virtual void paintEvent(QPaintEvent * event); + +private: + QPixmap pixmap; + +}; + +#endif // _SQUARELABEL_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/about.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/about.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,146 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include "about.h" +#include "hwconsts.h" + +About::About(QWidget * parent) : + QWidget(parent) +{ + QGridLayout *mainLayout = new QGridLayout(this); + + QLabel *imageLabel = new QLabel; + QImage image(":/res/Hedgehog.png"); + imageLabel->setPixmap(QPixmap::fromImage(image)); + imageLabel->setScaledContents(true); + imageLabel->setMinimumWidth(2.8); + imageLabel->setMaximumWidth(280); + imageLabel->setMinimumHeight(30); + imageLabel->setMaximumHeight(300); + + mainLayout->addWidget(imageLabel, 0, 0, 2, 1); + + QLabel *lbl1 = new QLabel(this); + lbl1->setOpenExternalLinks(true); + lbl1->setText( + "" + "

Hedgewars

" + "

" + QLabel::tr("Version") + " " + *cVersionString + "

" + "

http://www.hedgewars.org/


" + + QLabel::tr("This program is distributed under the GNU General Public License v2") + + "
" + ); + lbl1->setWordWrap(true); + mainLayout->addWidget(lbl1, 0, 1); + + QTextBrowser *lbl2 = new QTextBrowser(this); + + lbl2->setOpenExternalLinks(true); + lbl2->setText( + "" + + QString("

") + + QLabel::tr("Developers:") + + "

" + "Engine, frontend, net server: Andrey Korotaev <unC0Rr@gmail.com>
" + "Many frontend improvements: Igor Ulyanov <disinbox@gmail.com>
" + "Many engine and frontend improvements: Derek Pomery <nemo@m8y.org>
" + "Drill rocket, Ballgun, RC Plane weapons: Martin Boze <afffect@gmail.com>
" + "Mine number and time game settings: David A. Cuadrado <krawek@gmail.com>
" + "Frontend improvements: Martin Minarik <ttsmj@pokec.sk>
" + "Frontend improvements: Kristian Lehmann <email@thexception.net>
" + "Mac OS X/iPhone port, OpenGL-ES conversion: Vittorio Giovara <vittorio.giovara@gmail.com>
" + "Many engine and frontend improvements (and bugs): Richard Karolyi <sheepluva@" "ercatec.net>
" + "Gamepad and Lua integration: Mario Liebisch <mario.liebisch@gmail.com>
" + "Many engine improvements and graphics: Carlos Vives <mail@carlosvives.es>
" + "Maze maps: Henning Kühn <prg@cooco.de>
" + "Engine and frontend improvements: Henrik Rostedt <henrik.rostedt@gmail.com>
" + "Lua game modes and missions: John Lambert <redgrinner@gmail.com>
" + "Frontend improvements: Mayur Pawashe <zorgiepoo@gmail.com>
" + "Android port: Richard Deurwaarder <xeli@xelification.com>
" + "

" + + + QLabel::tr("Art:") + "

" + + QString::fromUtf8( + "

John Dum <fizzy@gmail.com>" + "
" + "Joshua Frese <joshfrese@gmail.com>" + "
" + "Stanko Tadić <stanko@mfhinc.net>" + "
" + "Julien Koesten <julienkoesten@aol.com>" + "
" + "Joshua O'Sullivan <coheedftw@hotmail.co.uk>" + "
" + "Nils Lück <nils.luck.design@gmail.com>" + "
" + "Guillaume Englert <genglert@hybird.org>" + "
" + "Hats: Trey Perry <tx.perry.j@gmail.com>" + "

") + + QLabel::tr("Sounds:") + "

" + "Hedgehogs voice: Stephen Alexander <ArmagonNo1@gmail.com>" + "
" + "John Dum <fizzy@gmail.com>" + "
" + "Jonatan Nilsson <jonatanfan@gmail.com>" + "
" + "Daniel Martin <elhombresinremedio@gmail.com>" + "

" + + + QLabel::tr("Translations:") + "

" + + QString::fromUtf8( + "Brazilian Portuguese: Romulo Fernandes Machado <abra185@gmail.com>
" + "Bulgarian: Svetoslav Stefanov
" + "Czech: Petr Řezáček <rezacek@gmail.com>
" + "Chinese: Jie Luo <lililjlj@gmail.com>
" + "English: Andrey Korotaev <unC0Rr@gmail.com>
" + "Finnish: Nina Kuisma <ninnnu@gmail.com>
" + "French: Antoine Turmel <geekshadow@gmail.com>
" + "German: Peter Hüwe <PeterHuewe@gmx.de>, Mario Liebisch <mario.liebisch@gmail.com>, Richard Karolyi <sheepluva@" "ercatec.net>
" + "Greek: <talos_kriti@yahoo.gr>
" + "Italian: Luca Bonora <bonora.luca@gmail.com>, Marco Bresciani
" + "Japanese: ADAM Etienne <etienne.adam@gmail.com>
" + "Korean: Anthony Bellew <webmaster@anthonybellew.com>
" + "Lithuanian: Lukas Urbonas <lukasu08@gmail.com>
" + "Polish: Maciej Mroziński <mynick2@o2.pl>, Wojciech Latkowski <magik17l@gmail.com>, Piotr Mitana, Maciej Górny
" + "Portuguese: Fábio Canário <inufabie@gmail.com>
" + "Russian: Andrey Korotaev <unC0Rr@gmail.com>
" + "Slovak: Jose Riha
" + "Spanish: Carlos Vives <mail@carlosvives.es>
" + "Swedish: Niklas Grahn <raewolusjoon@yaoo.com>, Henrik Rostedt <henrik.rostedt@gmail.com>
" + "Ukrainian: Eugene V. Lyubimkin <jackyf.devel@gmail.com>, Igor Paliychuk <mansonigor@gmail.com>, Eugene Sakara <eresid@gmail.com>" + "

") + + + QLabel::tr("Special thanks:") + "

" + "Aleksey Andreev <blaknayabr@gmail.com>
" + "Aleksander Rudalev <alexv@pomorsu.ru>
" + "Natasha Korotaeva <layout@pisem.net>
" + "Adam Higerd (aka ahigerd at FreeNode)" + "

" + ); + mainLayout->addWidget(lbl2, 1, 1); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/about.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/about.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,33 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _ABOUT_H +#define _ABOUT_H + +#include + + +class About : public QWidget +{ + Q_OBJECT + +public: + About(QWidget * parent = 0); +}; + +#endif // _ABOUT_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/bgwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/bgwidget.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,143 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2009 Kristian Lehmann + * Copyright (c) 2009-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "bgwidget.h" + +SpritePosition::SpritePosition(QWidget * parent, int sh) +{ + wParent = parent; + iSpriteHeight = sh; + reset(); +} + +SpritePosition::~SpritePosition() +{ +} + +void SpritePosition::move() +{ + fX += fXMov; + fY += fYMov; + iAngle += 4; + if (iAngle >= 360) iAngle = 0; + if (fY > wParent->height()) reset(); +} + +void SpritePosition::reset() +{ + fY = -1 * iSpriteHeight; + fX = (qrand() % ((int)(wParent->width() * 1.5))) - wParent->width()/2; + fYMov = ((qrand() % 400)+300) / 100.0f; + fXMov = fYMov * 0.2f+((qrand()%100)/100.0f * 0.6f); //so between 0.2 and 0.6, or 0.5 +/- 0.3 + iAngle = qrand() % 360; +} + +QPoint SpritePosition::pos() +{ + return QPoint((int)fX,(int)fY); +} + +int SpritePosition::getAngle() +{ + return iAngle; +} + +void SpritePosition::init() +{ + fY = qrand() % (wParent->height() + 1); + fX = qrand() % (wParent->width() + 1); +} + +BGWidget::BGWidget(QWidget * parent) : QWidget(parent) +{ + setAttribute(Qt::WA_NoSystemBackground, true); + sprite.load(":/res/Star.png"); + + setAutoFillBackground(false); + + for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height()); + + for (int i = 0; i < 360; i++) + { + rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32); + rotatedSprites[i]->fill(0); + + QPoint translate(sprite.width()/2, sprite.height()/2); + + QPainter p; + p.begin(rotatedSprites[i]); + // p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.translate(translate.x(), translate.y()); + p.rotate(i); + p.translate(-1*translate.x(), -1*translate.y()); + p.drawImage(0, 0, sprite); + } + + timerAnimation = new QTimer(); + connect(timerAnimation, SIGNAL(timeout()), this, SLOT(animate())); + timerAnimation->setInterval(ANIMATION_INTERVAL); +} + +BGWidget::~BGWidget() +{ + for (int i = 0; i < SPRITE_MAX; i++) delete spritePositions[i]; + for (int i = 0; i < 360; i++) delete rotatedSprites[i]; + delete timerAnimation; +} + +void BGWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter p; + p.begin(this); + //p.setRenderHint(QPainter::Antialiasing); + for (int i = 0; i < SPRITE_MAX; i++) + { + QPoint point = spritePositions[i]->pos(); + p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()]); + } + p.end(); +} + +void BGWidget::animate() +{ + for (int i = 0; i < SPRITE_MAX; i++) + { + // bottom edge of star *seems* clipped, but in fact, if I switch to just plain old repaint()/update() it is still clipped - artifact of transform? As for 5, is arbitrary number. 4 was noticeably clipping, 5 seemed same as update() - I assume extra room is due to rotation and value really should be calculated proportional to width/height + update(spritePositions[i]->pos().x(),spritePositions[i]->pos().y(), sprite.width()+5, sprite.height()+5); + spritePositions[i]->move(); + } +} + +void BGWidget::startAnimation() +{ + timerAnimation->start(); +} + +void BGWidget::stopAnimation() +{ + timerAnimation->stop(); +} + +void BGWidget::init() +{ + for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i]->init(); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/bgwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/bgwidget.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,76 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2009 Kristian Lehmann + * Copyright (c) 2009-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef BGWIDGET_H +#define BGWIDGET_H + +#include +//#include +#include +#include +#include +#include +#include + +#define SPRITE_MAX 12 + +#define ANIMATION_INTERVAL 40 + +class SpritePosition +{ +public: + SpritePosition(QWidget * parent, int sh); + ~SpritePosition(); +private: + float fX; + float fY; + float fXMov; + float fYMov; + int iAngle; + QWidget * wParent; + int iSpriteHeight; +public: + void move(); + void reset(); + QPoint pos(); + int getAngle(); + void init(); +}; + +class BGWidget : public QWidget +{ + Q_OBJECT +public: + BGWidget(QWidget * parent); + ~BGWidget(); + void startAnimation(); + void stopAnimation(); + void init(); +private: + QImage sprite; + QTimer * timerAnimation; + SpritePosition * spritePositions[SPRITE_MAX]; + QImage * rotatedSprites[360]; +protected: + void paintEvent(QPaintEvent * event); +private slots: + void animate(); +}; + +#endif // BGWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/chatwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/chatwidget.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,584 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hwconsts.h" +#include "SDLs.h" +#include "gameuiconfig.h" +#include "chatwidget.h" + +ListWidgetNickItem::ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored) : QListWidgetItem(nick) +{ + this->aFriend = isFriend; + this->isIgnored = isIgnored; +} + +void ListWidgetNickItem::setFriend(bool isFriend) +{ + this->aFriend = isFriend; +} + +void ListWidgetNickItem::setIgnored(bool isIgnored) +{ + this->isIgnored = isIgnored; +} + +bool ListWidgetNickItem::isFriend() +{ + return aFriend; +} + +bool ListWidgetNickItem::ignored() +{ + return isIgnored; +} + +bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const +{ + // case in-sensitive comparison of the associated strings + // chars that are no letters are sorted at the end of the list + + ListWidgetNickItem otherNick = const_cast(dynamic_cast(other)); + + // ignored always down + if (isIgnored != otherNick.ignored()) + return !isIgnored; + + // friends always up + if (aFriend != otherNick.isFriend()) + return aFriend; + + QString txt1 = text().toLower(); + QString txt2 = other.text().toLower(); + + bool firstIsShorter = (txt1.size() < txt2.size()); + int len = firstIsShorter?txt1.size():txt2.size(); + + for (int i = 0; i < len; i++) + { + if (txt1[i] == txt2[i]) + continue; + if (txt1[i].isLetter() != txt2[i].isLetter()) + return txt1[i].isLetter(); + return (txt1[i] < txt2[i]); + } + + return firstIsShorter; +} + +const char* HWChatWidget::STYLE = +"\ +a { color:#c8c8ff; }\ +.nick { text-decoration: none; }\ +.UserChat .nick { color:#ffec20; }\ +.FriendChat { color: #08e008; }\ +.FriendChat .nick { color: #20ff20; }\ +.UserJoin { color: #c0c0c0; }\ +.UserJoin .nick { color: #d0d0d0; }\ +.FriendJoin { color: #c0e0c0; }\ +.FriendJoin .nick { color: #d0f0d0; }\ +.UserAction { color: #ff80ff; }\ +.UserAction .nick { color: #ffa0ff; }\ +.FriendAction { color: #ff00ff; }\ +.FriendAction .nick { color: #ff30ff; }\ +.Error { color: #ff0000 }\ +.Warning { color: #ff8000 }\ +.Notice { color: #fefefe }\ +"; + +HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify) : + QWidget(parent), + mainLayout(this) +{ + this->gameSettings = gameSettings; + this->sdli = sdli; + this->notify = notify; + if(notify && gameSettings->value("frontend/sound", true).toBool()) { + QFile tmpfile; + sdli->SDLMusicInit(); + for(int i=0;i<4;i++) { + tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Sounds/voices/Classic/Hello.ogg"); + if (tmpfile.exists()) sound[i] = Mix_LoadWAV(QFileInfo(tmpfile).absoluteFilePath().toLocal8Bit().constData()); + else sound[i] = Mix_LoadWAV(QString(datadir->absolutePath() + + "/Sounds/voices/Classic/Hello.ogg").toLocal8Bit().constData()); + } + } + + mainLayout.setSpacing(1); + mainLayout.setMargin(1); + mainLayout.setSizeConstraint(QLayout::SetMinimumSize); + mainLayout.setColumnStretch(0, 76); + mainLayout.setColumnStretch(1, 24); + + chatEditLine = new QLineEdit(this); + chatEditLine->setMaxLength(300); + connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed())); + + mainLayout.addWidget(chatEditLine, 2, 0); + + chatText = new QTextBrowser(this); + chatText->document()->setDefaultStyleSheet(STYLE); + chatText->setMinimumHeight(20); + chatText->setMinimumWidth(10); + chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + chatText->setOpenLinks(false); + connect(chatText, SIGNAL(anchorClicked(const QUrl&)), + this, SLOT(linkClicked(const QUrl&))); + mainLayout.addWidget(chatText, 0, 0, 2, 1); + + chatNicks = new QListWidget(this); + chatNicks->setMinimumHeight(10); + chatNicks->setMinimumWidth(10); + chatNicks->setSortingEnabled(true); + chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu); + connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this, SLOT(chatNickDoubleClicked(QListWidgetItem *))); + connect(chatNicks, SIGNAL(currentRowChanged(int)), + this, SLOT(chatNickSelected(int))); + + mainLayout.addWidget(chatNicks, 0, 1, 3, 1); + + acInfo = new QAction(QAction::tr("Info"), chatNicks); + acInfo->setIcon(QIcon(":/res/info.png")); + connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo())); + acKick = new QAction(QAction::tr("Kick"), chatNicks); + acKick->setIcon(QIcon(":/res/kick.png")); + connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick())); + acBan = new QAction(QAction::tr("Ban"), chatNicks); + acBan->setIcon(QIcon(":/res/ban.png")); + connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan())); + acFollow = new QAction(QAction::tr("Follow"), chatNicks); + acFollow->setIcon(QIcon(":/res/follow.png")); + connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow())); + acIgnore = new QAction(QAction::tr("Ignore"), chatNicks); + acIgnore->setIcon(QIcon(":/res/ignore.png")); + connect(acIgnore, SIGNAL(triggered(bool)), this, SLOT(onIgnore())); + acFriend = new QAction(QAction::tr("Add friend"), chatNicks); + acFriend->setIcon(QIcon(":/res/addfriend.png")); + connect(acFriend, SIGNAL(triggered(bool)), this, SLOT(onFriend())); + + chatNicks->insertAction(0, acFriend); + chatNicks->insertAction(0, acInfo); + chatNicks->insertAction(0, acIgnore); + + showReady = false; + setShowFollow(true); +} + +void HWChatWidget::linkClicked(const QUrl & link) +{ + if (link.scheme() == "http") + QDesktopServices::openUrl(link); + if (link.scheme() == "hwnick") + { + // decode nick + const QString& nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery())); + QList items = chatNicks->findItems(nick, Qt::MatchExactly); + if (items.size() < 1) + return; + QMenu * popup = new QMenu(this); + // selecting an item will automatically scroll there, so let's save old position + QScrollBar * scrollBar = chatNicks->verticalScrollBar(); + int oldScrollPos = scrollBar->sliderPosition(); + // select the nick which we want to see the actions for + chatNicks->setCurrentItem(items[0], QItemSelectionModel::Clear); + // selecting an item will automatically scroll there, so let's save old position + scrollBar->setSliderPosition(oldScrollPos); + // load actions + popup->addActions(chatNicks->actions()); + // display menu popup at mouse cursor position + popup->popup(QCursor::pos()); + } +} + +void HWChatWidget::setShowFollow(bool enabled) +{ + if (enabled) { + if (!(chatNicks->actions().contains(acFollow))) + chatNicks->insertAction(acFriend, acFollow); + } + else { + if (chatNicks->actions().contains(acFollow)) + chatNicks->removeAction(acFollow); + } +} + +void HWChatWidget::loadList(QStringList & list, const QString & file) +{ + list.clear(); + QFile txt(cfgdir->absolutePath() + "/" + file); + if(!txt.open(QIODevice::ReadOnly)) + return; + QTextStream stream(&txt); + stream.setCodec("UTF-8"); + + while(!stream.atEnd()) + { + QString str = stream.readLine(); + if(str.startsWith(";") || str.length() == 0) + continue; + list << str.trimmed(); + } + //readd once we require newer Qt than 4.4 + //list.removeDuplicates(); + txt.close(); +} + +void HWChatWidget::saveList(QStringList & list, const QString & file) +{ + QFile txt(cfgdir->absolutePath() + "/" + file); + if(!txt.open(QIODevice::WriteOnly | QIODevice::Truncate)) + return; + QTextStream stream(&txt); + stream.setCodec("UTF-8"); + + stream << "; this list is used by Hedgewars - do not edit it unless you know what you're doing!" << endl; + for(int i = 0; i < list.size(); i++) + stream << list[i] << endl; + txt.close(); +} + +void HWChatWidget::updateNickItem(QListWidgetItem *nickItem) +{ + QString nick = nickItem->text(); + ListWidgetNickItem * item = dynamic_cast(nickItem); + + item->setFriend(friendsList.contains(nick, Qt::CaseInsensitive)); + item->setIgnored(ignoreList.contains(nick, Qt::CaseInsensitive)); + + if(item->ignored()) + { + item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on.png" : ":/res/chat_ignore_off.png") : ":/res/chat_ignore.png")); + item->setForeground(Qt::gray); + } + else if(item->isFriend()) + { + item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on.png" : ":/res/chat_friend_off.png") : ":/res/chat_friend.png")); + item->setForeground(Qt::green); + } + else + { + item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on.png" : ":/res/chat_default_off.png") : ":/res/chat_default.png")); + item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00))); + } +} + +void HWChatWidget::updateNickItems() +{ + for(int i = 0; i < chatNicks->count(); i++) + updateNickItem(chatNicks->item(i)); + + chatNicks->sortItems(); +} + +void HWChatWidget::loadLists(const QString & nick) +{ + loadList(ignoreList, nick.toLower() + "_ignore.txt"); + loadList(friendsList, nick.toLower() + "_friends.txt"); + updateNickItems(); +} + +void HWChatWidget::saveLists(const QString & nick) +{ + saveList(ignoreList, nick.toLower() + "_ignore.txt"); + saveList(friendsList, nick.toLower() + "_friends.txt"); +} + +void HWChatWidget::returnPressed() +{ + QStringList lines = chatEditLine->text().split('\n'); + chatEditLine->clear(); + foreach (const QString &line, lines) + emit chatLine(line); +} + + +void HWChatWidget::onChatString(const QString& str) +{ + onChatString("", str); +} + +const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http://)?(www\\.)?(hedgewars\\.org(/[^ ]*)?)"); + +void HWChatWidget::onChatString(const QString& nick, const QString& str) +{ + bool isFriend = false; + + if (!nick.isEmpty()) { + // don't show chat lines that are from ignored nicks + if (ignoreList.contains(nick, Qt::CaseInsensitive)) + return; + // friends will get special treatment, of course + isFriend = friendsList.contains(nick, Qt::CaseInsensitive); + } + + QString formattedStr = Qt::escape(str.mid(1)); + // make hedgewars.org urls actual links + formattedStr = formattedStr.replace(URLREGEXP, "\\3"); + + // "link" nick, but before that encode it in base64 to make sure it can't intefere with html/url syntax + // the nick is put as querystring as putting it as host would convert it to it's lower case variant + if(!nick.isEmpty()) + formattedStr.replace("|nick|",QString("%2").arg(QString(nick.toUtf8().toBase64())).arg(nick)); + + QString cssClass("UserChat"); + + // check first character for color code and set color properly + switch (str[0].toAscii()) { + case 3: + cssClass = (isFriend ? "FriendJoin" : "UserJoin"); + break; + case 2: + cssClass = (isFriend ? "FriendAction" : "UserAction"); + break; + default: + if (isFriend) + cssClass = "FriendChat"; + } + + addLine(cssClass,formattedStr); +} + +void HWChatWidget::addLine(const QString& cssClass, QString line) +{ + if (chatStrings.size() > 250) + chatStrings.removeFirst(); + + line = QString("%1").arg(line).arg(cssClass); + + chatStrings.append(line); + + chatText->setHtml(chatStrings.join("
")); + + chatText->moveCursor(QTextCursor::End); +} + +void HWChatWidget::onServerMessage(const QString& str) +{ + if (chatStrings.size() > 250) + chatStrings.removeFirst(); + + chatStrings.append("
" + str + "
"); + + chatText->setHtml(chatStrings.join("
")); + + chatText->moveCursor(QTextCursor::End); +} + +void HWChatWidget::nickAdded(const QString& nick, bool notifyNick) +{ + QListWidgetItem * item = new ListWidgetNickItem(nick, friendsList.contains(nick, Qt::CaseInsensitive), ignoreList.contains(nick, Qt::CaseInsensitive)); + updateNickItem(item); + chatNicks->addItem(item); + + emit nickCountUpdate(chatNicks->count()); + + if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) { + Mix_PlayChannel(-1, sound[rand()%4], 0); + } +} + +void HWChatWidget::nickRemoved(const QString& nick) +{ + foreach(QListWidgetItem * item, chatNicks->findItems(nick, Qt::MatchExactly)) + chatNicks->takeItem(chatNicks->row(item)); + + emit nickCountUpdate(chatNicks->count()); +} + +void HWChatWidget::clear() +{ + chatText->clear(); + chatStrings.clear(); + chatNicks->clear(); +} + +void HWChatWidget::onKick() +{ + QListWidgetItem * curritem = chatNicks->currentItem(); + if (curritem) + emit kick(curritem->text()); +} + +void HWChatWidget::onBan() +{ + QListWidgetItem * curritem = chatNicks->currentItem(); + if (curritem) + emit ban(curritem->text()); +} + +void HWChatWidget::onInfo() +{ + QListWidgetItem * curritem = chatNicks->currentItem(); + if (curritem) + emit info(curritem->text()); +} + +void HWChatWidget::onFollow() +{ + QListWidgetItem * curritem = chatNicks->currentItem(); + if (curritem) + emit follow(curritem->text()); +} + +void HWChatWidget::onIgnore() +{ + QListWidgetItem * curritem = chatNicks->currentItem(); + if(!curritem) + return; + + if(ignoreList.contains(curritem->text(), Qt::CaseInsensitive)) // already on list - remove him + { + ignoreList.removeAll(curritem->text().toLower()); + onChatString(HWChatWidget::tr("%1 *** %2 has been removed from your ignore list").arg('\x03').arg(curritem->text())); + } + else // not on list - add + { + // don't consider ignored people friends + if(friendsList.contains(curritem->text(), Qt::CaseInsensitive)) + emit onFriend(); + + // scroll down on first ignore added so that people see where that nick went to + if (ignoreList.isEmpty()) + chatNicks->scrollToBottom(); + + ignoreList << curritem->text().toLower(); + onChatString(HWChatWidget::tr("%1 *** %2 has been added to your ignore list").arg('\x03').arg(curritem->text())); + } + updateNickItem(curritem); // update icon/sort order/etc + chatNicks->sortItems(); + chatNickSelected(0); // update context menu +} + +void HWChatWidget::onFriend() +{ + QListWidgetItem * curritem = chatNicks->currentItem(); + if(!curritem) + return; + + if(friendsList.contains(curritem->text(), Qt::CaseInsensitive)) // already on list - remove him + { + friendsList.removeAll(curritem->text().toLower()); + onChatString(HWChatWidget::tr("%1 *** %2 has been removed from your friends list").arg('\x03').arg(curritem->text())); + } + else // not on list - add + { + // don't ignore the new friend + if(ignoreList.contains(curritem->text(), Qt::CaseInsensitive)) + emit onIgnore(); + + // scroll up on first friend added so that people see where that nick went to + if (friendsList.isEmpty()) + chatNicks->scrollToTop(); + + friendsList << curritem->text().toLower(); + onChatString(HWChatWidget::tr("%1 *** %2 has been added to your friends list").arg('\x03').arg(curritem->text())); + } + updateNickItem(curritem); // update icon/sort order/etc + chatNicks->sortItems(); + chatNickSelected(0); // update context menu +} + +void HWChatWidget::chatNickDoubleClicked(QListWidgetItem * item) +{ + Q_UNUSED(item); + + QList actions = chatNicks->actions(); + actions.first()->activate(QAction::Trigger); +} + +void HWChatWidget::chatNickSelected(int index) +{ + Q_UNUSED(index); + + QListWidgetItem* item = chatNicks->currentItem(); + if (!item) + return; + + // update context menu labels according to possible action + if(ignoreList.contains(item->text(), Qt::CaseInsensitive)) + { + acIgnore->setText(QAction::tr("Unignore")); + acIgnore->setIcon(QIcon(":/res/unignore.png")); + } + else + { + acIgnore->setText(QAction::tr("Ignore")); + acIgnore->setIcon(QIcon(":/res/ignore.png")); + } + + if(friendsList.contains(item->text(), Qt::CaseInsensitive)) + { + acFriend->setText(QAction::tr("Remove friend")); + acFriend->setIcon(QIcon(":/res/remfriend.png")); + } + else + { + acFriend->setText(QAction::tr("Add friend")); + acFriend->setIcon(QIcon(":/res/addfriend.png")); + } +} + +void HWChatWidget::setShowReady(bool s) +{ + showReady = s; +} + +void HWChatWidget::setReadyStatus(const QString & nick, bool isReady) +{ + QList items = chatNicks->findItems(nick, Qt::MatchExactly); + if (items.size() != 1) + { + qWarning("Bug: cannot find user in chat"); + return; + } + + items[0]->setData(Qt::UserRole, isReady); // bulb status + updateNickItem(items[0]); + + // ensure we're still showing the status bulbs + showReady = true; +} + +void HWChatWidget::adminAccess(bool b) +{ + chatNicks->removeAction(acKick); + chatNicks->removeAction(acBan); + + if(b) + { + chatNicks->insertAction(0, acKick); +// chatNicks->insertAction(0, acBan); + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/chatwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/chatwidget.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,124 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _CHAT_WIDGET_INCLUDED +#define _CHAT_WIDGET_INCLUDED + +#include +#include +#include +#include +#include + +#include "SDLs.h" + +class ListWidgetNickItem; +class QTextBrowser; +class QLineEdit; +class QListWidget; +class QSettings; +class SDLInteraction; + +// this class is for custom nick sorting +class ListWidgetNickItem : public QListWidgetItem +{ +public: + ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored); + bool operator<(const QListWidgetItem & other) const; + void setFriend(bool isFriend); + void setIgnored(bool isIgnored); + bool isFriend(); + bool ignored(); + +private: + bool aFriend; + bool isIgnored; +}; + +class HWChatWidget : public QWidget +{ + Q_OBJECT + + public: + HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify); + void loadLists(const QString & nick); + void saveLists(const QString & nick); + void setShowReady(bool s); + void setShowFollow(bool enabled); + void addLine(const QString & cssClass, QString line); + static const char* STYLE; + QStringList ignoreList, friendsList; + +private: + void loadList(QStringList & list, const QString & file); + void saveList(QStringList & list, const QString & file); + void updateNickItem(QListWidgetItem *item); + void updateNickItems(); + static const QRegExp URLREGEXP; + + public slots: + void onChatString(const QString& str); + void onChatString(const QString& nick, const QString& str); + void onServerMessage(const QString& str); + void nickAdded(const QString& nick, bool notifyNick); + void nickRemoved(const QString& nick); + void clear(); + void setReadyStatus(const QString & nick, bool isReady); + void adminAccess(bool); + + signals: + void chatLine(const QString& str); + void kick(const QString & str); + void ban(const QString & str); + void info(const QString & str); + void follow(const QString &); + void nickCountUpdate(int cnt); + + private: + QGridLayout mainLayout; + QTextBrowser* chatText; + QStringList chatStrings; + QListWidget* chatNicks; + QLineEdit* chatEditLine; + QAction * acInfo; + QAction * acKick; + QAction * acBan; + QAction * acFollow; + QAction * acIgnore; + QAction * acFriend; + QSettings * gameSettings; + SDLInteraction * sdli; + Mix_Chunk *sound[4]; + bool notify; + bool showReady; + + private slots: + void returnPressed(); + void onBan(); + void onKick(); + void onInfo(); + void onFollow(); + void onIgnore(); + void onFriend(); + void chatNickDoubleClicked(QListWidgetItem * item); + void chatNickSelected(int index); + void linkClicked(const QUrl & link); +}; + +#endif // _CHAT_WIDGET_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/databrowser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/databrowser.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include + +#include "databrowser.h" + +const QNetworkRequest::Attribute typeAttribute = (QNetworkRequest::Attribute)(QNetworkRequest::User + 1); +const QNetworkRequest::Attribute urlAttribute = (QNetworkRequest::Attribute)(QNetworkRequest::User + 2); + +DataBrowser::DataBrowser(QWidget *parent) : + QTextBrowser(parent) +{ + + manager = new QNetworkAccessManager(this); +} + +QVariant DataBrowser::loadResource(int type, const QUrl & name) +{ + if(type == QTextDocument::ImageResource || type == QTextDocument::StyleSheetResource) + { + if(resources.contains(name.toString())) + { + return resources.take(name.toString()); + } + else + if(!requestedResources.contains(name.toString())) + { + qDebug() << "Requesting resource" << name.toString(); + requestedResources.insert(name.toString()); + + QNetworkRequest newRequest(QUrl("http://www.hedgewars.org" + name.toString())); + newRequest.setAttribute(typeAttribute, type); + newRequest.setAttribute(urlAttribute, name); + + QNetworkReply *reply = manager->get(newRequest); + connect(reply, SIGNAL(finished()), this, SLOT(resourceDownloaded())); + } + } + + return QVariant(); +} + +void DataBrowser::resourceDownloaded() +{ + QNetworkReply * reply = qobject_cast(sender()); + + if(reply) + { + int type = reply->request().attribute(typeAttribute).toInt(); + QUrl url = reply->request().attribute(urlAttribute).toUrl(); + resources.insert(url.toString(), reply->readAll()); + document()->addResource(type, reply->request().url(), QVariant()); + update(); + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/databrowser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/databrowser.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,33 @@ +#ifndef DATABROWSER_H +#define DATABROWSER_H + +#include +#include + +class QNetworkAccessManager; + +class DataBrowser : public QTextBrowser +{ + Q_OBJECT +public: + explicit DataBrowser(QWidget *parent = 0); + +signals: + +public slots: + +private: + QNetworkAccessManager *manager; + + // hash and set of QString instead of QUrl to support Qt versions + // older than 4.7 (those have no support for qHash(const QUrl &)) + QHash resources; + QSet requestedResources; + + QVariant loadResource(int type, const QUrl & name); + +private slots: + void resourceDownloaded(); +}; + +#endif // DATABROWSER_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/drawmapwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/drawmapwidget.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,106 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include "drawmapwidget.h" + +DrawMapWidget::DrawMapWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::DrawMapWidget) +{ + ui->setupUi(this); + + m_scene = 0; +} + +DrawMapWidget::~DrawMapWidget() +{ + delete ui; +} + +void DrawMapWidget::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void DrawMapWidget::setScene(DrawMapScene * scene) +{ + ui->graphicsView->setScene(scene); + m_scene = scene; +} + +void DrawMapWidget::resizeEvent(QResizeEvent * event) +{ + Q_UNUSED(event); + + if(ui->graphicsView && ui->graphicsView->scene()) + ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); +} + +void DrawMapWidget::showEvent(QShowEvent * event) +{ + Q_UNUSED(event); + + resizeEvent(0); +} + +void DrawMapWidget::undo() +{ + if(m_scene) m_scene->undo(); +} + +void DrawMapWidget::clear() +{ + if(m_scene) m_scene->clearMap(); +} + +void DrawMapWidget::save(const QString & fileName) +{ + if(m_scene) + { + QFile file(fileName); + + if(!file.open(QIODevice::WriteOnly)) + QMessageBox::warning(this, tr("File error"), tr("Cannot open file '%1' for writing").arg(fileName)); + else + file.write(qCompress(m_scene->encode()).toBase64()); + } +} + +void DrawMapWidget::load(const QString & fileName) +{ + if(m_scene) + { + QFile f(fileName); + + if(!f.open(QIODevice::ReadOnly)) + QMessageBox::warning(this, tr("File error"), tr("Cannot read file '%1'").arg(fileName)); + else + m_scene->decode(qUncompress(QByteArray::fromBase64(f.readAll()))); + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/drawmapwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/drawmapwidget.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,86 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef DRAWMAPWIDGET_H +#define DRAWMAPWIDGET_H + +#include +#include +#include +#include + +#include "qaspectratiolayout.h" +#include "drawmapscene.h" + +namespace Ui { + class Ui_DrawMapWidget + { + public: + QGraphicsView *graphicsView; + + void setupUi(QWidget *drawMapWidget) + { + QAspectRatioLayout * arLayout = new QAspectRatioLayout(drawMapWidget); + arLayout->setMargin(0); + + graphicsView = new QGraphicsView(drawMapWidget); + arLayout->addWidget(graphicsView); + + retranslateUi(drawMapWidget); + + QMetaObject::connectSlotsByName(drawMapWidget); + } // setupUi + + void retranslateUi(QWidget *drawMapWidget) + { + Q_UNUSED(drawMapWidget); + } // retranslateUi + + }; + + class DrawMapWidget: public Ui_DrawMapWidget {}; +} + +class DrawMapWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DrawMapWidget(QWidget *parent = 0); + ~DrawMapWidget(); + + void setScene(DrawMapScene * scene); + +public slots: + void undo(); + void clear(); + void save(const QString & fileName); + void load(const QString & fileName); + +protected: + void changeEvent(QEvent *e); + virtual void resizeEvent(QResizeEvent * event); + virtual void showEvent(QShowEvent * event); + +private: + Ui::DrawMapWidget *ui; + + DrawMapScene * m_scene; +}; + +#endif // DRAWMAPWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/fpsedit.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/fpsedit.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,31 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "fpsedit.h" + +FPSEdit::FPSEdit(QWidget * parent) : + QSpinBox(parent) +{ + setRange(1, 34); + setValue(27); +} + +QString FPSEdit::textFromValue(int value) const +{ + return QString::number(1000 / (35 - value)); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/fpsedit.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/fpsedit.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,35 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _FPSEDIT_H +#define _FPSEDIT_H + +#include + +class FPSEdit : public QSpinBox +{ + Q_OBJECT + +public: + FPSEdit(QWidget * parent = 0); + +protected: + QString textFromValue (int value) const; +}; + +#endif // _FPSEDIT_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/frameTeam.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/frameTeam.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,128 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include "frameTeam.h" +#include "teamselhelper.h" +#include "hwconsts.h" + +FrameTeams::FrameTeams(QWidget* parent) : + QFrame(parent), maxHedgehogsPerGame(48), overallHedgehogs(0), mainLayout(this), nonInteractive(false) +{ + QPalette newPalette = palette(); + newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); + setPalette(newPalette); + setAutoFillBackground(true); + + mainLayout.setSpacing(1); + mainLayout.setContentsMargins(4, 4, 4, 4); + + int i = 0; + while(colors[i] != 0) + availableColors.push_back(QColor(colors[i++])); + + resetColors(); +} + +void FrameTeams::setInteractivity(bool interactive) +{ + nonInteractive = !interactive; + for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ++it) { + TeamShowWidget* pts = dynamic_cast(it.value()); + if(!pts) throw; + pts->setInteractivity(interactive); + } +} + +void FrameTeams::resetColors() +{ + currentColor=availableColors.end() - 1; // ensure next color is the first one +} + +QColor FrameTeams::getNextColor() const +{ + QList::ConstIterator nextColor=currentColor; + ++nextColor; + if (nextColor==availableColors.end()) nextColor=availableColors.begin(); + return *nextColor; +} + +void FrameTeams::addTeam(HWTeam team, bool willPlay) +{ + TeamShowWidget* pTeamShowWidget = new TeamShowWidget(team, willPlay, this); + if(nonInteractive) pTeamShowWidget->setInteractivity(false); +// int hght=teamToWidget.empty() ? 0 : teamToWidget.begin()->second->size().height(); + mainLayout.addWidget(pTeamShowWidget); + teamToWidget.insert(team, pTeamShowWidget); + QResizeEvent* pevent=new QResizeEvent(parentWidget()->size(), parentWidget()->size()); + QCoreApplication::postEvent(parentWidget(), pevent); +} + +void FrameTeams::removeTeam(HWTeam team) +{ + tmapTeamToWidget::iterator it=teamToWidget.find(team); + if(it==teamToWidget.end()) return; + mainLayout.removeWidget(it.value()); + it.value()->deleteLater(); + teamToWidget.erase(it); +} + +void FrameTeams::resetTeams() +{ + for(tmapTeamToWidget::iterator it=teamToWidget.begin(); it!=teamToWidget.end(); ) { + mainLayout.removeWidget(it.value()); + it.value()->deleteLater(); + teamToWidget.erase(it++); + } +} + +void FrameTeams::setHHNum(const HWTeam& team) +{ + TeamShowWidget* pTeamShowWidget = dynamic_cast(getTeamWidget(team)); + if(!pTeamShowWidget) return; + pTeamShowWidget->setHHNum(team.numHedgehogs()); +} + +void FrameTeams::setTeamColor(const HWTeam& team) +{ + TeamShowWidget* pTeamShowWidget = dynamic_cast(getTeamWidget(team)); + if(!pTeamShowWidget) return; + pTeamShowWidget->changeTeamColor(team.color()); +} + +QWidget* FrameTeams::getTeamWidget(HWTeam team) +{ +//qDebug() << "FrameTeams::getTeamWidget getNetID() = " << team.getNetID(); + tmapTeamToWidget::iterator it=teamToWidget.find(team); + QWidget* ret = it!=teamToWidget.end() ? it.value() : 0; + return ret; +} + +bool FrameTeams::isFullTeams() const +{ + return overallHedgehogs==maxHedgehogsPerGame; +} + +void FrameTeams::emitTeamColorChanged(const HWTeam& team) +{ + emit teamColorChanged(team); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/frameTeam.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/frameTeam.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,68 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _FRAME_TEAM_INCLUDED +#define _FRAME_TEAM_INCLUDED + +#include +#include +#include + +#include "teamselect.h" + +class FrameTeams : public QFrame +{ + Q_OBJECT + + friend class CHedgehogerWidget; + friend class TeamShowWidget; + + public: + FrameTeams(QWidget* parent=0); + QWidget* getTeamWidget(HWTeam team); + bool isFullTeams() const; + void resetColors(); + void resetTeams(); + void setHHNum(const HWTeam& team); + void setTeamColor(const HWTeam& team); + void setInteractivity(bool interactive); + QColor getNextColor() const; + + signals: + void teamColorChanged(const HWTeam&); + + public slots: + void addTeam(HWTeam team, bool willPlay); + void removeTeam(HWTeam team); + + private: + const int maxHedgehogsPerGame; + int overallHedgehogs; + QList availableColors; + QList::Iterator currentColor; + + void emitTeamColorChanged(const HWTeam& team); + + QVBoxLayout mainLayout; + typedef QMap tmapTeamToWidget; + tmapTeamToWidget teamToWidget; + bool nonInteractive; +}; + +#endif // _FRAME_TAM_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/gamecfgwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/gamecfgwidget.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,575 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gamecfgwidget.h" +#include "igbox.h" +#include "hwconsts.h" +#include "ammoSchemeModel.h" +#include "proto.h" + +GameCFGWidget::GameCFGWidget(QWidget* parent) : + QGroupBox(parent) + , mainLayout(this) + , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}") +{ + mainLayout.setMargin(0); +// mainLayout.setSizeConstraint(QLayout::SetMinimumSize); + + pMapContainer = new HWMapContainer(this); + mainLayout.addWidget(pMapContainer, 0, 0); + + IconedGroupBox *GBoxOptions = new IconedGroupBox(this); + GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + mainLayout.addWidget(GBoxOptions, 1, 0); + + QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); + + GBoxOptions->setTitle(tr("Game Options")); + GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), GBoxOptions), 1, 0); + + Scripts = new QComboBox(GBoxOptions); + GBoxOptionsLayout->addWidget(Scripts, 1, 1); + + Scripts->addItem("Normal"); + Scripts->insertSeparator(1); + + for (int i = 0; i < scriptList->size(); ++i) { + QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive); + QList scriptInfo; + scriptInfo.push_back(script); + QFile scriptCfgFile; + scriptCfgFile.setFileName(QString("%1/Data/Scripts/Multiplayer/%2.cfg").arg(cfgdir->absolutePath()).arg(script)); + if (!scriptCfgFile.exists()) scriptCfgFile.setFileName(QString("%1/Scripts/Multiplayer/%2.cfg").arg(datadir->absolutePath()).arg(script)); + if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) { + QString scheme; + QString weapons; + QTextStream input(&scriptCfgFile); + input >> scheme; + input >> weapons; + if (scheme.isEmpty()) + scheme = "locked"; + scheme.replace("_", " "); + if (weapons.isEmpty()) + weapons = "locked"; + weapons.replace("_", " "); + scriptInfo.push_back(scheme); + scriptInfo.push_back(weapons); + scriptCfgFile.close(); + } + else + { + scriptInfo.push_back("locked"); + scriptInfo.push_back("locked"); + } + Scripts->addItem(script.replace("_", " "), scriptInfo); + } + + connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int))); + + QWidget *SchemeWidget = new QWidget(GBoxOptions); + GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2); + + QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget); + SchemeWidgetLayout->setMargin(0); + + GameSchemes = new QComboBox(SchemeWidget); + SchemeWidgetLayout->addWidget(GameSchemes, 0, 2); + connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int))); + + SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0); + + QPixmap pmEdit(":/res/edit.png"); + + QPushButton * goToSchemePage = new QPushButton(SchemeWidget); + goToSchemePage->setToolTip(tr("Edit schemes")); + goToSchemePage->setIconSize(pmEdit.size()); + goToSchemePage->setIcon(pmEdit); + goToSchemePage->setMaximumWidth(pmEdit.width() + 6); + SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3); + connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes())); + + SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Weapons"), SchemeWidget), 1, 0); + + WeaponsName = new QComboBox(SchemeWidget); + SchemeWidgetLayout->addWidget(WeaponsName, 1, 2); + + connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); + + QPushButton * goToWeaponPage = new QPushButton(SchemeWidget); + goToWeaponPage->setToolTip(tr("Edit weapons")); + goToWeaponPage->setIconSize(pmEdit.size()); + goToWeaponPage->setIcon(pmEdit); + goToWeaponPage->setMaximumWidth(pmEdit.width() + 6); + SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3); + connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons())); + + bindEntries = new QCheckBox(SchemeWidget); + bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon")); + bindEntries->setChecked(true); + bindEntries->setMaximumWidth(42); + bindEntries->setStyleSheet( "QCheckBox::indicator:checked { image: url(\":/res/lock.png\"); }" + "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\"); }" ); + SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter); + + connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &))); + connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &))); + connect(pMapContainer, SIGNAL(mapgenChanged(MapGenerator)), this, SLOT(mapgenChanged(MapGenerator))); + connect(pMapContainer, SIGNAL(mazeSizeChanged(int)), this, SLOT(maze_sizeChanged(int))); + connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &))); + connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); + connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap())); + connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &))); +} + +void GameCFGWidget::jumpToSchemes() +{ + emit goToSchemes(GameSchemes->currentIndex()); +} + +void GameCFGWidget::jumpToWeapons() +{ + emit goToWeapons(WeaponsName->currentIndex()); +} + +QVariant GameCFGWidget::schemeData(int column) const +{ + return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column)); +} + +quint32 GameCFGWidget::getGameFlags() const +{ + quint32 result = 0; + + if (schemeData(1).toBool()) + result |= 0x00001000; // fort + if (schemeData(2).toBool()) + result |= 0x00000010; // divide teams + if (schemeData(3).toBool()) + result |= 0x00000004; // solid land + if (schemeData(4).toBool()) + result |= 0x00000008; // border + if (schemeData(5).toBool()) + result |= 0x00000020; // low gravity + if (schemeData(6).toBool()) + result |= 0x00000040; // laser sight + if (schemeData(7).toBool()) + result |= 0x00000080; // invulnerable + if (schemeData(8).toBool()) + result |= 0x00000100; // mines + if (schemeData(9).toBool()) + result |= 0x00000200; // vampirism + if (schemeData(10).toBool()) + result |= 0x00000400; // karma + if (schemeData(11).toBool()) + result |= 0x00000800; // artillery + if (schemeData(12).toBool()) + result |= 0x00002000; // random + if (schemeData(13).toBool()) + result |= 0x00004000; // king + if (schemeData(14).toBool()) + result |= 0x00008000; // place hogs + if (schemeData(15).toBool()) + result |= 0x00010000; // shared ammo + if (schemeData(16).toBool()) + result |= 0x00020000; // disable girders + if (schemeData(17).toBool()) + result |= 0x00040000; // disable land obj + if (schemeData(18).toBool()) + result |= 0x00080000; // ai survival + if (schemeData(19).toBool()) + result |= 0x00100000; // infinite attacks + if (schemeData(20).toBool()) + result |= 0x00200000; // reset weaps + if (schemeData(21).toBool()) + result |= 0x00400000; // per hog ammo + if (schemeData(22).toBool()) + result |= 0x00800000; // no wind + if (schemeData(23).toBool()) + result |= 0x01000000; // more wind + if (schemeData(24).toBool()) + result |= 0x02000000; // tag team + if (schemeData(25).toBool()) + result |= 0x04000000; // bottom border + + return result; +} + +quint32 GameCFGWidget::getInitHealth() const +{ + return schemeData(28).toInt(); +} + +QByteArray GameCFGWidget::getFullConfig() const +{ + QList bcfg; + int mapgen = pMapContainer->get_mapgen(); + + QString currentMap = pMapContainer->getCurrentMap(); + if (currentMap.size() > 0) + { + bcfg << QString("emap " + currentMap).toUtf8(); + +// engine should figure it out on its own +// if(pMapContainer->getCurrentIsMission()) +// bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8(); + } + bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8(); + + if (Scripts->currentIndex() > 0) + { + bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8(); + } + + bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8(); + bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8(); + bcfg << QString("e$damagepct %1").arg(schemeData(26).toInt()).toUtf8(); + bcfg << QString("e$turntime %1").arg(schemeData(27).toInt() * 1000).toUtf8(); + bcfg << QString("e$sd_turns %1").arg(schemeData(29).toInt()).toUtf8(); + bcfg << QString("e$casefreq %1").arg(schemeData(30).toInt()).toUtf8(); + bcfg << QString("e$minestime %1").arg(schemeData(31).toInt() * 1000).toUtf8(); + bcfg << QString("e$minesnum %1").arg(schemeData(32).toInt()).toUtf8(); + bcfg << QString("e$minedudpct %1").arg(schemeData(33).toInt()).toUtf8(); + bcfg << QString("e$explosives %1").arg(schemeData(34).toInt()).toUtf8(); + bcfg << QString("e$healthprob %1").arg(schemeData(35).toInt()).toUtf8(); + bcfg << QString("e$hcaseamount %1").arg(schemeData(36).toInt()).toUtf8(); + bcfg << QString("e$waterrise %1").arg(schemeData(37).toInt()).toUtf8(); + bcfg << QString("e$healthdec %1").arg(schemeData(38).toInt()).toUtf8(); + bcfg << QString("e$ropepct %1").arg(schemeData(39).toInt()).toUtf8(); + bcfg << QString("e$getawaytime %1").arg(schemeData(40).toInt()).toUtf8(); + bcfg << QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()).toUtf8(); + bcfg << QString("e$mapgen %1").arg(mapgen).toUtf8(); + + switch (mapgen) + { + case MAPGEN_MAZE: + bcfg << QString("e$maze_size %1").arg(pMapContainer->getMazeSize()).toUtf8(); + break; + + case MAPGEN_DRAWN: + { + QByteArray data = pMapContainer->getDrawnMapData(); + while(data.size() > 0) + { + QByteArray tmp = data; + tmp.truncate(200); + tmp.prepend("edraw "); + bcfg << tmp; + data.remove(0, 200); + } + break; + } + default: ; + } + + QByteArray result; + + foreach(QByteArray ba, bcfg) + HWProto::addByteArrayToBuffer(result, ba); + + return result; +} + +void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) +{ + bool illegal = ammo.size() != cDefaultAmmoStore->size(); + if (illegal) + QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); + + int pos = WeaponsName->findText(name); + if ((pos == -1) || illegal) { // prevent from overriding schemes with bad ones + WeaponsName->addItem(name, ammo); + WeaponsName->setCurrentIndex(WeaponsName->count() - 1); + } else { + WeaponsName->setItemData(pos, ammo); + WeaponsName->setCurrentIndex(pos); + } +} + +void GameCFGWidget::fullNetConfig() +{ + ammoChanged(WeaponsName->currentIndex()); + + seedChanged(pMapContainer->getCurrentSeed()); + templateFilterChanged(pMapContainer->getTemplateFilter()); + themeChanged(pMapContainer->getCurrentTheme()); + + schemeChanged(GameSchemes->currentIndex()); + scriptChanged(Scripts->currentIndex()); + + mapgenChanged(pMapContainer->get_mapgen()); + maze_sizeChanged(pMapContainer->getMazeSize()); + + // map must be the last + QString map = pMapContainer->getCurrentMap(); + if (map.size()) + mapChanged(map); +} + +void GameCFGWidget::setParam(const QString & param, const QStringList & slValue) +{ + if (slValue.size() == 1) + { + QString value = slValue[0]; + if (param == "MAP") { + pMapContainer->setMap(value); + return; + } + if (param == "SEED") { + pMapContainer->setSeed(value); + if (!seedRegexp.exactMatch(value)) { + pMapContainer->seedEdit->setVisible(true); + } + return; + } + if (param == "THEME") { + pMapContainer->setTheme(value); + return; + } + if (param == "TEMPLATE") { + pMapContainer->setTemplateFilter(value.toUInt()); + return; + } + if (param == "MAPGEN") { + pMapContainer->setMapgen((MapGenerator)value.toUInt()); + return; + } + if (param == "MAZE_SIZE") { + pMapContainer->setMazeSize(value.toUInt()); + return; + } + if (param == "SCRIPT") { + Scripts->setCurrentIndex(Scripts->findText(value)); + return; + } + if (param == "DRAWNMAP") { + pMapContainer->setDrawnMapData(qUncompress(QByteArray::fromBase64(slValue[0].toLatin1()))); + return; + } + } + + if (slValue.size() == 2) + { + if (param == "AMMO") { + setNetAmmo(slValue[0], slValue[1]); + return; + } + } + + if (slValue.size() == 5) + { + if (param == "FULLMAPCONFIG") + { + QString seed = slValue[3]; + if (!seedRegexp.exactMatch(seed)) + pMapContainer->seedEdit->setVisible(true); + + pMapContainer->setAllMapParameters( + slValue[0], + (MapGenerator)slValue[1].toUInt(), + slValue[2].toUInt(), + seed, + slValue[4].toUInt() + ); + return; + } + } + + qWarning("Got bad config param from net"); +} + +void GameCFGWidget::ammoChanged(int index) +{ + if (index >= 0) { + emit paramChanged( + "AMMO", + QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() + ); + } +} + +void GameCFGWidget::mapChanged(const QString & value) +{ + if(isEnabled() && pMapContainer->getCurrentIsMission()) + { + Scripts->setEnabled(false); + Scripts->setCurrentIndex(0); + + if (pMapContainer->getCurrentScheme() == "locked") + { + GameSchemes->setEnabled(false); + GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); + } + else + { + GameSchemes->setEnabled(true); + int num = GameSchemes->findText(pMapContainer->getCurrentScheme()); + if (num != -1) + GameSchemes->setCurrentIndex(num); + else + GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); + } + + if (pMapContainer->getCurrentWeapons() == "locked") + { + WeaponsName->setEnabled(false); + WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); + } + else + { + WeaponsName->setEnabled(true); + int num = WeaponsName->findText(pMapContainer->getCurrentWeapons()); + if (num != -1) + WeaponsName->setCurrentIndex(num); + else + WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); + } + + if (pMapContainer->getCurrentScheme() != "locked" && pMapContainer->getCurrentWeapons() != "locked") + bindEntries->setEnabled(true); + else + bindEntries->setEnabled(false); + } + else + { + Scripts->setEnabled(true); + GameSchemes->setEnabled(true); + WeaponsName->setEnabled(true); + bindEntries->setEnabled(true); + } + emit paramChanged("MAP", QStringList(value)); +} + +void GameCFGWidget::templateFilterChanged(int value) +{ + emit paramChanged("TEMPLATE", QStringList(QString::number(value))); +} + +void GameCFGWidget::seedChanged(const QString & value) +{ + emit paramChanged("SEED", QStringList(value)); +} + +void GameCFGWidget::themeChanged(const QString & value) +{ + emit paramChanged("THEME", QStringList(value)); +} + +void GameCFGWidget::schemeChanged(int index) +{ + QStringList sl; + + int size = GameSchemes->model()->columnCount(); + for(int i = 0; i < size; ++i) + sl << schemeData(i).toString(); + + emit paramChanged("SCHEME", sl); + + if (isEnabled() && bindEntries->isEnabled() && bindEntries->isChecked()) { + QString schemeName = GameSchemes->itemText(index); + for (int i = 0; i < WeaponsName->count(); i++) { + QString weapName = WeaponsName->itemText(i); + int res = QString::compare(weapName, schemeName, Qt::CaseSensitive); + if (0 == res) { + WeaponsName->setCurrentIndex(i); + emit ammoChanged(i); + break; + } + } + } +} + +void GameCFGWidget::scriptChanged(int index) +{ + if(isEnabled() && index > 0) + { + QString scheme = Scripts->itemData(Scripts->currentIndex()).toList()[1].toString(); + QString weapons = Scripts->itemData(Scripts->currentIndex()).toList()[2].toString(); + + if (scheme == "locked") + { + GameSchemes->setEnabled(false); + GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); + } + else + { + GameSchemes->setEnabled(true); + int num = GameSchemes->findText(scheme); + if (num != -1) + GameSchemes->setCurrentIndex(num); + else + GameSchemes->setCurrentIndex(GameSchemes->findText("Default")); + } + + if (weapons == "locked") + { + WeaponsName->setEnabled(false); + WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); + } + else + { + WeaponsName->setEnabled(true); + int num = WeaponsName->findText(weapons); + if (num != -1) + WeaponsName->setCurrentIndex(num); + else + WeaponsName->setCurrentIndex(WeaponsName->findText("Default")); + } + + if (scheme != "locked" && weapons != "locked") + bindEntries->setEnabled(true); + else + bindEntries->setEnabled(false); + } + else + { + GameSchemes->setEnabled(true); + WeaponsName->setEnabled(true); + bindEntries->setEnabled(true); + } + emit paramChanged("SCRIPT", QStringList(Scripts->itemText(index))); +} + +void GameCFGWidget::mapgenChanged(MapGenerator m) +{ + emit paramChanged("MAPGEN", QStringList(QString::number(m))); +} + +void GameCFGWidget::maze_sizeChanged(int s) +{ + emit paramChanged("MAZE_SIZE", QStringList(QString::number(s))); +} + +void GameCFGWidget::resendSchemeData() +{ + schemeChanged(GameSchemes->currentIndex()); +} + +void GameCFGWidget::onDrawnMapChanged(const QByteArray & data) +{ + emit paramChanged("DRAWNMAP", QStringList(qCompress(data, 9).toBase64())); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/gamecfgwidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/gamecfgwidget.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,87 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef GAMECONFIGWIDGET_H +#define GAMECONFIGWIDGET_H + +#include +#include +#include +#include +#include + +#include "mapContainer.h" + +class QCheckBox; +class QVBoxLayout; +class QLabel; +class QTableView; + +class GameCFGWidget : public QGroupBox +{ + Q_OBJECT + +public: + GameCFGWidget(QWidget* parent); + quint32 getGameFlags() const; + quint32 getInitHealth() const; + QByteArray getFullConfig() const; + QComboBox * Scripts; + QComboBox * GameSchemes; + QComboBox * WeaponsName; + HWMapContainer* pMapContainer; + QTableView * tv; + QVariant schemeData(int column) const; + +public slots: + void setParam(const QString & param, const QStringList & value); + void fullNetConfig(); + void resendSchemeData(); + +signals: + void paramChanged(const QString & param, const QStringList & value); + void goToSchemes(int); + void goToWeapons(int); + void goToDrawMap(); + +private slots: + void ammoChanged(int index); + void mapChanged(const QString &); + void templateFilterChanged(int); + void seedChanged(const QString &); + void themeChanged(const QString &); + void schemeChanged(int); + void scriptChanged(int); + void jumpToSchemes(); + void jumpToWeapons(); + void mapgenChanged(MapGenerator m); + void maze_sizeChanged(int s); + void onDrawnMapChanged(const QByteArray & data); + +private: + QGridLayout mainLayout; + QCheckBox * bindEntries; + QString curNetAmmoName; + QString curNetAmmo; + QRegExp seedRegexp; + + void setNetAmmo(const QString& name, const QString& ammo); + +}; + +#endif // GAMECONFIGWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/hedgehogerWidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/hedgehogerWidget.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,76 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Ulyanov Igor + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "hedgehogerWidget.h" + +#include "frameTeam.h" + +CHedgehogerWidget::CHedgehogerWidget(const QImage& im, const QImage& img, QWidget * parent) : + ItemNum(im, img, parent, 1) +{ + // TODO: maxHedgehogsPerGame doesn't reset properly and won't match map limits for now + /*if(parent) { + pOurFrameTeams = dynamic_cast(parent->parentWidget()); + } + if(pOurFrameTeams->overallHedgehogs + 4 > pOurFrameTeams->maxHedgehogsPerGame) { + numItems = pOurFrameTeams->maxHedgehogsPerGame - pOurFrameTeams->overallHedgehogs; + } else numItems = 4; + pOurFrameTeams->overallHedgehogs += numItems;*/ +} + +void CHedgehogerWidget::incItems() +{ + //if (pOurFrameTeams->overallHedgehogs < pOurFrameTeams->maxHedgehogsPerGame) { + numItems++; + //pOurFrameTeams->overallHedgehogs++; + emit hedgehogsNumChanged(); + //} +} + +void CHedgehogerWidget::decItems() +{ + numItems--; + //pOurFrameTeams->overallHedgehogs--; + emit hedgehogsNumChanged(); +} + +CHedgehogerWidget::~CHedgehogerWidget() +{ + // TODO: not called? + //pOurFrameTeams->overallHedgehogs-=numItems; +} + +void CHedgehogerWidget::setNonInteractive() +{ + nonInteractive=true; +} + +void CHedgehogerWidget::setHHNum(unsigned int num) +{ + /*unsigned int diff = num - numItems; + numItems += diff; + pOurFrameTeams->overallHedgehogs += diff;*/ + numItems = num; + repaint(); +} + +unsigned char CHedgehogerWidget::getHedgehogsNum() const +{ + return numItems; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/hedgehogerWidget.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/hedgehogerWidget.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,50 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Ulyanov Igor + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _HEDGEHOGER_WIDGET +#define _HEDGEHOGER_WIDGET + +#include "itemNum.h" + +class FrameTeams; + +class CHedgehogerWidget : public ItemNum +{ + Q_OBJECT + + public: + CHedgehogerWidget(const QImage& im, const QImage& img, QWidget * parent); + virtual ~CHedgehogerWidget(); + unsigned char getHedgehogsNum() const; + void setHHNum (unsigned int num); + void setNonInteractive(); + + signals: + void hedgehogsNumChanged(); + + protected: + virtual void incItems(); + virtual void decItems(); + + private: + CHedgehogerWidget(); + FrameTeams* pOurFrameTeams; +}; + +#endif // _HEDGEHOGER_WIDGET diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/igbox.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/igbox.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,79 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include + +#include "igbox.h" + +IconedGroupBox::IconedGroupBox(QWidget * parent) + : QGroupBox(parent) +{ +// Has issues with border-radius on children +// setAttribute(Qt::WA_PaintOnScreen, true); + titleLeftPadding = 49; + contentTopPadding = 15; +} + +void IconedGroupBox::setIcon(const QIcon & icon) +{ + if (this->icon.isNull()) + setStyleSheet(QString( + "IconedGroupBox{" + "margin-top: 46px;" + "margin-left: 12px;" + "padding: %1px 2px 5px 2px;" + "}" + "IconedGroupBox::title{" + "subcontrol-origin: margin;" + "subcontrol-position: top left;" + "padding-left: %2px;" + "padding-top: %1px;" + "text-align: left;" + "}" + ).arg(contentTopPadding).arg(titleLeftPadding) + ); + + this->icon = icon; + repaint(); +} + +void IconedGroupBox::paintEvent(QPaintEvent * event) +{ + Q_UNUSED(event); + + QStylePainter painter(this); + + QStyleOptionGroupBox option; + initStyleOption(&option); + painter.drawComplexControl(QStyle::CC_GroupBox, option); + + icon.paint(&painter, QRect(QPoint(0, 0), icon.actualSize(size()))); +} + +void IconedGroupBox::setTitleTextPadding(int px) +{ + titleLeftPadding = px; +} + +void IconedGroupBox::setContentTopPadding(int px) +{ + contentTopPadding = px; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/igbox.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/igbox.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,44 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _IGBOX_H +#define _IGBOX_H + +#include +#include + +class IconedGroupBox : public QGroupBox +{ + Q_OBJECT + +public: + IconedGroupBox(QWidget * parent = 0); + + void setIcon(const QIcon & icon); + void setTitleTextPadding(int px); + void setContentTopPadding(int px); +protected: + virtual void paintEvent(QPaintEvent * event); + +private: + QIcon icon; + int titleLeftPadding; + int contentTopPadding; +}; + +#endif // _IGBOX_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/itemNum.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/itemNum.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,114 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2011 Igor Ulyanov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "itemNum.h" +#include "hwform.h" + +#include +#include + +ItemNum::ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min, unsigned char max) : + QFrame(parent), m_im(im), m_img(img), infinityState(false), nonInteractive(false), minItems(min), maxItems(max), + numItems(min+2 >= max ? min : min+2) +{ + enabled = true; + if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); +} + +ItemNum::~ItemNum() +{ +} + +void ItemNum::mousePressEvent ( QMouseEvent * event ) +{ + if(nonInteractive) return; + if(event->button()==Qt::LeftButton && enabled) { + event->accept(); + if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) { + incItems(); + } else { + numItems = minItems+1; + // appears there's an emit in there + decItems(); + } + } else if (event->button()==Qt::RightButton && enabled) { + event->accept(); + if(numItems > minItems) { + decItems(); + } else { + numItems = maxItems+(infinityState?0:-1); + incItems(); + } + } else { + event->ignore(); + return; + } + repaint(); +} + +QSize ItemNum::sizeHint () const +{ + return QSize((maxItems+1)*12, 32); +} + +void ItemNum::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + + QPainter painter(this); + + if (numItems==maxItems+1) { + QRect target(0, 0, 100, 32); + if (enabled) { + painter.drawImage(target, QImage(":/res/infinity.png")); + } else { + painter.drawImage(target, QImage(":/res/infinitygrey.png")); + } + } else { + for(int i=0; i + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include + +#ifndef _ITEM_NUM_INCLUDED +#define _ITEM_NUM_INCLUDED + +class ItemNum : public QFrame +{ + Q_OBJECT + + public: + void setInfinityState(bool value); + void setEnabled(bool value); + unsigned char getItemsNum() const; + void setItemsNum(const unsigned char num); + + private: + QImage m_im; + QImage m_img; + bool infinityState; + bool enabled; + + protected: + ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min=2, unsigned char max=8); + virtual QSize sizeHint () const; + virtual ~ItemNum()=0; + + bool nonInteractive; + unsigned char minItems; + unsigned char maxItems; + unsigned char numItems; + + // from QWidget + virtual void mousePressEvent ( QMouseEvent * event ); + virtual void paintEvent(QPaintEvent* event); + + // to be implemented in child + virtual void incItems()=0; + virtual void decItems()=0; +}; + +#endif // _ITEM_NUM_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/selectWeapon.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/selectWeapon.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,294 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "selectWeapon.h" +#include "weaponItem.h" +#include "hwconsts.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QImage getAmmoImage(int num) +{ + static QImage ammo(":Ammos.png"); + int x = num/(ammo.height()/32); + int y = (num-((ammo.height()/32)*x))*32; + x*=32; + return ammo.copy(x, y, 32, 32); +} + +SelWeaponItem::SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent) : + QWidget(parent) +{ + QHBoxLayout* hbLayout = new QHBoxLayout(this); + hbLayout->setSpacing(1); + hbLayout->setMargin(1); + + QLabel* lbl = new QLabel(this); + lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum))); + lbl->setMaximumWidth(30); + lbl->setGeometry(0, 0, 30, 30); + hbLayout->addWidget(lbl); + + item = new WeaponItem(image, imagegrey, this); + item->setItemsNum(wNum); + item->setInfinityState(allowInfinite); + hbLayout->addWidget(item); + + hbLayout->setStretchFactor(lbl, 1); + hbLayout->setStretchFactor(item, 99); + hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter); + hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter); +} + +void SelWeaponItem::setItemsNum(const unsigned char num) +{ + item->setItemsNum(num); +} + +unsigned char SelWeaponItem::getItemsNum() const +{ + return item->getItemsNum(); +} + +void SelWeaponItem::setEnabled(bool value) +{ + item->setEnabled(value); +} + +SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) : + QFrame(parent), + m_numItems(numItems) +{ + wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this); + + for(int i = 0; i < cDefaultAmmos.size(); ++i) + wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second); + + QStringList keys = wconf->allKeys(); + for(int i = 0; i < keys.size(); i++) + { + if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size()) + wconf->remove(keys[i]); + } + + QString currentState = *cDefaultAmmoStore; + + QTabWidget * tbw = new QTabWidget(this); + QWidget * page1 = new QWidget(this); + p1Layout = new QGridLayout(page1); + p1Layout->setSpacing(1); + p1Layout->setMargin(1); + QWidget * page2 = new QWidget(this); + p2Layout = new QGridLayout(page2); + p2Layout->setSpacing(1); + p2Layout->setMargin(1); + QWidget * page3 = new QWidget(this); + p3Layout = new QGridLayout(page3); + p3Layout->setSpacing(1); + p3Layout->setMargin(1); + QWidget * page4 = new QWidget(this); + p4Layout = new QGridLayout(page4); + p4Layout->setSpacing(1); + p4Layout->setMargin(1); + + tbw->addTab(page1, tr("Weapon set")); + tbw->addTab(page2, tr("Probabilities")); + tbw->addTab(page4, tr("Ammo in boxes")); + tbw->addTab(page3, tr("Delays")); + + QGridLayout * pageLayout = new QGridLayout(this); + pageLayout->addWidget(tbw); + + + int j = -1; + int i = 0, k = 0; + for(; i < m_numItems; ++i) { + if (i == 6) continue; + if (i == 52) continue; // Disable structures for now + if (k % 4 == 0) ++j; + SelWeaponItem * swi = new SelWeaponItem(true, i, currentState[i].digitValue(), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this); + weaponItems[i].append(swi); + p1Layout->addWidget(swi, j, k % 4); + + SelWeaponItem * pwi = new SelWeaponItem(false, i, currentState[numItems + i].digitValue(), QImage(":/res/ammopicbox.png"), QImage(":/res/ammopicboxgrey.png"), this); + weaponItems[i].append(pwi); + p2Layout->addWidget(pwi, j, k % 4); + + SelWeaponItem * dwi = new SelWeaponItem(false, i, currentState[numItems*2 + i].digitValue(), QImage(":/res/ammopicdelay.png"), QImage(":/res/ammopicdelaygrey.png"), this); + weaponItems[i].append(dwi); + p3Layout->addWidget(dwi, j, k % 4); + + SelWeaponItem * awi = new SelWeaponItem(false, i, currentState[numItems*3 + i].digitValue(), QImage(":/res/ammopic.png"), QImage(":/res/ammopicgrey.png"), this); + weaponItems[i].append(awi); + p4Layout->addWidget(awi, j, k % 4); + + ++k; + } + + //pLayout->setRowStretch(5, 100); + m_name = new QLineEdit(this); + pageLayout->addWidget(m_name, i, 0, 1, 5); +} + +void SelWeaponWidget::setWeapons(const QString& ammo) +{ + bool enable = true; + for(int i = 0; i < cDefaultAmmos.size(); i++) + if (!cDefaultAmmos[i].first.compare(m_name->text())) { + enable = false; + } + for(int i = 0; i < m_numItems; ++i) { + twi::iterator it = weaponItems.find(i); + if (it == weaponItems.end()) continue; + it.value()[0]->setItemsNum(ammo[i].digitValue()); + it.value()[1]->setItemsNum(ammo[m_numItems + i].digitValue()); + it.value()[2]->setItemsNum(ammo[m_numItems*2 + i].digitValue()); + it.value()[3]->setItemsNum(ammo[m_numItems*3 + i].digitValue()); + it.value()[0]->setEnabled(enable); + it.value()[1]->setEnabled(enable); + it.value()[2]->setEnabled(enable); + it.value()[3]->setEnabled(enable); + } + m_name->setEnabled(enable); +} + +void SelWeaponWidget::setDefault() +{ + for(int i = 0; i < cDefaultAmmos.size(); i++) + if (!cDefaultAmmos[i].first.compare(m_name->text())) { + return; + } + setWeapons(*cDefaultAmmoStore); +} + +void SelWeaponWidget::save() +{ + for(int i = 0; i < cDefaultAmmos.size(); i++) + if (!cDefaultAmmos[i].first.compare(m_name->text())) { + QMessageBox::warning(0, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not overwrite default weapon set '%1'!").arg(cDefaultAmmos[i].first)); + return; + } + + if (m_name->text() == "") return; + + QString state1; + QString state2; + QString state3; + QString state4; + + for(int i = 0; i < m_numItems; ++i) { + twi::const_iterator it = weaponItems.find(i); + int num = it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum(); // 9 is for 'skip turn' + state1.append(QString::number(num)); + int prob = it == weaponItems.end() ? 0 : it.value()[1]->getItemsNum(); + state2.append(QString::number(prob)); + int del = it == weaponItems.end() ? 0 : it.value()[2]->getItemsNum(); + state3.append(QString::number(del)); + int am = it == weaponItems.end() ? 0 : it.value()[3]->getItemsNum(); + state4.append(QString::number(am)); + } + if (curWeaponsName != "") { + // remove old entry + wconf->remove(curWeaponsName); + } + wconf->setValue(m_name->text(), state1 + state2 + state3 + state4); + emit weaponsChanged(); +} + +int SelWeaponWidget::operator [] (unsigned int weaponIndex) const +{ + twi::const_iterator it = weaponItems.find(weaponIndex); + return it == weaponItems.end() ? 9 : it.value()[0]->getItemsNum(); +} + +QString SelWeaponWidget::getWeaponsString(const QString& name) const +{ + return wconf->value(name).toString(); +} + +void SelWeaponWidget::deleteWeaponsName() +{ + if (curWeaponsName == "") return; + + for(int i = 0; i < cDefaultAmmos.size(); i++) + if (!cDefaultAmmos[i].first.compare(m_name->text())) { + QMessageBox::warning(0, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not delete default weapon set '%1'!").arg(cDefaultAmmos[i].first)); + return; + } + + QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Weapons"), QMessageBox::tr("Really delete this weapon set?"), QMessageBox::Ok | QMessageBox::Cancel); + + if (reallyDelete.exec() == QMessageBox::Ok) { + wconf->remove(curWeaponsName); + emit weaponsDeleted(); + } +} + +void SelWeaponWidget::newWeaponsName() +{ + QString newName = tr("new"); + if(wconf->contains(newName)) { + //name already used -> look for an appropriate name: + int i=2; + while(wconf->contains(newName = tr("new")+QString::number(i++))); + } + setWeaponsName(newName); +} + +void SelWeaponWidget::setWeaponsName(const QString& name) +{ + m_name->setText(name); + + curWeaponsName = name; + + if(name != "" && wconf->contains(name)) { + setWeapons(wconf->value(name).toString()); + } else { + setWeapons(*cDefaultAmmoStore); + } +} + +QStringList SelWeaponWidget::getWeaponNames() const +{ + return wconf->allKeys(); +} + +void SelWeaponWidget::copy() +{ + if(wconf->contains(curWeaponsName)) { + QString ammo = getWeaponsString(curWeaponsName); + QString newName = tr("copy of") + " " + curWeaponsName; + if(wconf->contains(newName)) { + //name already used -> look for an appropriate name: + int i=2; + while(wconf->contains(newName = tr("copy of") + " " + curWeaponsName+QString::number(i++))); + } + setWeaponsName(newName); + setWeapons(ammo); + } +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/selectWeapon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/selectWeapon.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,92 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _SELECT_WEAPON_INCLUDED +#define _SELECT_WEAPON_INCLUDED + +#include +#include +#include + +class QGridLayout; +class WeaponItem; +class QLineEdit; +class QSettings; + +class SelWeaponItem : public QWidget +{ + Q_OBJECT + +public: + SelWeaponItem(bool allowInfinite, int iconNum, int wNum, QImage image, QImage imagegrey, QWidget* parent=0); + + unsigned char getItemsNum() const; + void setItemsNum(const unsigned char num); + void setEnabled(bool value); + + private: + WeaponItem* item; +}; + +class SelWeaponWidget : public QFrame +{ + Q_OBJECT + + public: + SelWeaponWidget(int numItems, QWidget* parent=0); + QString getWeaponsString(const QString& name) const; + QStringList getWeaponNames() const; + + public slots: + void setDefault(); + void setWeapons(const QString& ammo); + //sets the name of the current set + void setWeaponsName(const QString& name); + void deleteWeaponsName(); + void newWeaponsName(); + void save(); + void copy(); + + signals: + void weaponsChanged(); + void weaponsDeleted(); + + private: + //the name of the current weapon set + QString curWeaponsName; + + QLineEdit* m_name; + + //storage for all the weapons sets + QSettings* wconf; + + const int m_numItems; + int operator [] (unsigned int weaponIndex) const; + + typedef QList ItemsList; + typedef QMap twi; + twi weaponItems; + //layout element for each tab: + QGridLayout* p1Layout; + QGridLayout* p2Layout; + QGridLayout* p3Layout; + QGridLayout* p4Layout; +}; + +#endif // _SELECT_WEAPON_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/teamselect.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/teamselect.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,281 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include + +#include +#include +#include +#include +#include + +#include "vertScrollArea.h" +#include "teamselect.h" +#include "teamselhelper.h" +#include "frameTeam.h" + +void TeamSelWidget::addTeam(HWTeam team) +{ + if(team.isNetTeam()) { + framePlaying->addTeam(team, true); + curPlayingTeams.push_back(team); + connect(framePlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), + this, SLOT(netTeamStatusChanged(const HWTeam&))); + connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), + this, SLOT(hhNumChanged(const HWTeam&))); + dynamic_cast(framePlaying->getTeamWidget(team))->hhNumChanged(); + connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), + this, SLOT(proxyTeamColorChanged(const HWTeam&))); + } else { + frameDontPlaying->addTeam(team, false); + m_curNotPlayingTeams.push_back(team); + if(m_acceptOuter) { + connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), + this, SLOT(pre_changeTeamStatus(HWTeam))); + } else { + connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), + this, SLOT(changeTeamStatus(HWTeam))); + } + } + emit setEnabledGameStart(curPlayingTeams.size()>1); +} + +void TeamSelWidget::setInteractivity(bool interactive) +{ + framePlaying->setInteractivity(interactive); +} + +void TeamSelWidget::hhNumChanged(const HWTeam& team) +{ + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + if(itPlay==curPlayingTeams.end()) + { + qWarning() << QString("hhNumChanged: team '%1' not found").arg(team.name()); + return; + } + itPlay->setNumHedgehogs(team.numHedgehogs()); + emit hhogsNumChanged(team); +} + +void TeamSelWidget::proxyTeamColorChanged(const HWTeam& team) +{ + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + if(itPlay==curPlayingTeams.end()) + { + qWarning() << QString("proxyTeamColorChanged: team '%1' not found").arg(team.name()); + return; + } + itPlay->setColor(team.color()); + emit teamColorChanged(team); +} + +void TeamSelWidget::changeHHNum(const HWTeam& team) +{ + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + if(itPlay==curPlayingTeams.end()) + { + qWarning() << QString("changeHHNum: team '%1' not found").arg(team.name()); + return; + } + itPlay->setNumHedgehogs(team.numHedgehogs()); + + framePlaying->setHHNum(team); +} + +void TeamSelWidget::changeTeamColor(const HWTeam& team) +{ + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + if(itPlay==curPlayingTeams.end()) + { + qWarning() << QString("changeTeamColor: team '%1' not found").arg(team.name()); + return; + } + itPlay->setColor(team.color()); + + framePlaying->setTeamColor(team); +} + +void TeamSelWidget::removeNetTeam(const HWTeam& team) +{ + //qDebug() << QString("removeNetTeam: removing team '%1'").arg(team.TeamName); + for(;;) { + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + if(itPlay==curPlayingTeams.end()) + { + qWarning() << QString("removeNetTeam: team '%1' not found").arg(team.name()); + break; + } + if(itPlay->isNetTeam()) { + QObject::disconnect(framePlaying->getTeamWidget(*itPlay), SIGNAL(teamStatusChanged(HWTeam))); + framePlaying->removeTeam(team); + curPlayingTeams.erase(itPlay); + break; + } + } + emit setEnabledGameStart(curPlayingTeams.size()>1); +} + +void TeamSelWidget::netTeamStatusChanged(const HWTeam& team) +{ + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + +} + +//void TeamSelWidget::removeTeam(__attribute__ ((unused)) HWTeam team) +//{ + //curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team)); +//} + +void TeamSelWidget::changeTeamStatus(HWTeam team) +{ + QList::iterator itDontPlay=std::find(m_curNotPlayingTeams.begin(), m_curNotPlayingTeams.end(), team); + QList::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team); + + bool willBePlaying=itDontPlay!=m_curNotPlayingTeams.end(); + + if(!willBePlaying) { + // playing team => dont playing + m_curNotPlayingTeams.push_back(*itPlay); + emit teamNotPlaying(*itPlay); + curPlayingTeams.erase(itPlay); + } else { + // return if max playing teams reached + if(framePlaying->isFullTeams()) return; + // dont playing team => playing + team=*itDontPlay; // for net team info saving in framePlaying (we have only name with netID from network) + itDontPlay->setColor(framePlaying->getNextColor()); + curPlayingTeams.push_back(*itDontPlay); + if(!m_acceptOuter) emit teamWillPlay(*itDontPlay); + m_curNotPlayingTeams.erase(itDontPlay); + } + + FrameTeams* pRemoveTeams; + FrameTeams* pAddTeams; + if(!willBePlaying) { + pRemoveTeams=framePlaying; + pAddTeams=frameDontPlaying; + } else { + pRemoveTeams=frameDontPlaying; + pAddTeams=framePlaying; + } + + pAddTeams->addTeam(team, willBePlaying); + pRemoveTeams->removeTeam(team); + if(!team.isNetTeam() && m_acceptOuter && !willBePlaying) { + connect(frameDontPlaying->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), + this, SLOT(pre_changeTeamStatus(HWTeam))); + } else { + connect(pAddTeams->getTeamWidget(team), SIGNAL(teamStatusChanged(HWTeam)), + this, SLOT(changeTeamStatus(HWTeam))); + } + if(willBePlaying) { + connect(framePlaying->getTeamWidget(team), SIGNAL(hhNmChanged(const HWTeam&)), + this, SLOT(hhNumChanged(const HWTeam&))); + dynamic_cast(framePlaying->getTeamWidget(team))->hhNumChanged(); + connect(framePlaying->getTeamWidget(team), SIGNAL(teamColorChanged(const HWTeam&)), + this, SLOT(proxyTeamColorChanged(const HWTeam&))); + emit teamColorChanged(((TeamShowWidget*)framePlaying->getTeamWidget(team))->getTeam()); + } + + QSize szh=pAddTeams->sizeHint(); + QSize szh1=pRemoveTeams->sizeHint(); + if(szh.isValid() && szh1.isValid()) { + pAddTeams->resize(pAddTeams->size().width(), szh.height()); + pRemoveTeams->resize(pRemoveTeams->size().width(), szh1.height()); + } + + emit setEnabledGameStart(curPlayingTeams.size()>1); +} + +void TeamSelWidget::addScrArea(FrameTeams* pfteams, QColor color, int fixedHeight) +{ + VertScrArea* area = new VertScrArea(color); + area->setWidget(pfteams); + mainLayout.addWidget(area, 30); + if (fixedHeight > 0) + { + area->setMinimumHeight(fixedHeight); + area->setMaximumHeight(fixedHeight); + area->setStyleSheet( + "FrameTeams{" + "border: solid;" + "border-width: 1px;" + "border-radius: 16px;" + "border-color: #ffcc00;" + "}" + ); + } +} + +TeamSelWidget::TeamSelWidget(QWidget* parent) : + QGroupBox(parent), mainLayout(this), m_acceptOuter(false) +{ + setTitle(QGroupBox::tr("Playing teams")); + framePlaying = new FrameTeams(); + frameDontPlaying = new FrameTeams(); + + QPalette p; + p.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); + addScrArea(framePlaying, p.color(QPalette::Window).light(105), 250); + addScrArea(frameDontPlaying, p.color(QPalette::Window).dark(105), 0); +} + +void TeamSelWidget::setAcceptOuter(bool acceptOuter) +{ + m_acceptOuter=acceptOuter; +} + +void TeamSelWidget::resetPlayingTeams(const QList& teamslist) +{ + //for(it=curPlayingTeams.begin(); it!=curPlayingTeams.end(); it++) { + //framePlaying->removeTeam(*it); + //} + framePlaying->resetTeams(); + framePlaying->resetColors(); + curPlayingTeams.clear(); + //for(it=curDontPlayingTeams.begin(); it!=curDontPlayingTeams.end(); it++) { + //frameDontPlaying->removeTeam(*it); + //} + frameDontPlaying->resetTeams(); + m_curNotPlayingTeams.clear(); + + foreach(HWTeam team, teamslist) + addTeam(team); +} + +bool TeamSelWidget::isPlaying(HWTeam team) const +{ + return std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team)!=curPlayingTeams.end(); +} + +QList TeamSelWidget::getPlayingTeams() const +{ + return curPlayingTeams; +} + +QList TeamSelWidget::getNotPlayingTeams() const +{ + return m_curNotPlayingTeams; +} + +void TeamSelWidget::pre_changeTeamStatus(HWTeam team) +{ + team.setColor(framePlaying->getNextColor()); + emit acceptRequested(team); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/teamselect.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/teamselect.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,83 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _TEAM_SELECT_INCLUDED +#define _TEAM_SELECT_INCLUDED + +#include +#include +#include +#include + +#include "team.h" + +class TeamSelWidget; +class FrameTeams; +class QFrame; +class QPushButton; + +using namespace std; + +class TeamSelWidget : public QGroupBox +{ + Q_OBJECT + + public: + TeamSelWidget(QWidget* parent); + void setAcceptOuter(bool acceptOuter); + void removeNetTeam(const HWTeam& team); + void resetPlayingTeams(const QList& teamslist); + bool isPlaying(HWTeam team) const; + QList getPlayingTeams() const; + QList getNotPlayingTeams() const; + void setInteractivity(bool interactive); + + public slots: + void addTeam(HWTeam team); + void netTeamStatusChanged(const HWTeam& team); + void changeHHNum(const HWTeam&); + void changeTeamColor(const HWTeam&); + void changeTeamStatus(HWTeam team); + + signals: + void setEnabledGameStart(bool); + void teamWillPlay(HWTeam team); + void teamNotPlaying(const HWTeam& team); + void hhogsNumChanged(const HWTeam&); + void teamColorChanged(const HWTeam&); + void acceptRequested(HWTeam team); + + private slots: + void pre_changeTeamStatus(HWTeam); + void hhNumChanged(const HWTeam& team); + void proxyTeamColorChanged(const HWTeam& team); + + private: + void addScrArea(FrameTeams* pfteams, QColor color, int maxHeight); + FrameTeams* frameDontPlaying; + FrameTeams* framePlaying; + + QVBoxLayout mainLayout; + bool m_acceptOuter; + + QList curPlayingTeams; + QList m_curNotPlayingTeams; +}; + +#endif // _TEAM_SELECT_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/teamselhelper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/teamselhelper.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,154 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include + +#include + +#include "teamselhelper.h" +#include "hwconsts.h" +#include "frameTeam.h" + +void TeamLabel::teamButtonClicked() +{ + emit teamActivated(text()); +} + +TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) : + QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0), + colorButt(0) +{ + QPalette newPalette = palette(); + newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); + setPalette(newPalette); + setAutoFillBackground(true); + + mainLayout.setSpacing(3); + mainLayout.setMargin(0); + this->setMaximumHeight(38); + this->setMinimumHeight(38); + QIcon difficultyIcon=team.isNetTeam() ? + QIcon(QString(":/res/botlevels/net%1.png").arg(m_team.difficulty())) + : QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty())); + + butt = new QPushButton(difficultyIcon, team.name().replace("&","&&"), this); + butt->setFlat(true); + butt->setToolTip(team.owner()); + mainLayout.addWidget(butt); + butt->setStyleSheet("QPushButton{" + "icon-size: 48px;" + "text-align: left;" + "background-color: #0d0544;" + "color: orange;" + "font: bold;" + "border-width: 2px;" + "margin: 6px 0px 6px 0px;" + "}"); + + if(m_isPlaying) { + // team color + colorButt = new QPushButton(this); + colorButt->setMaximumWidth(26); + colorButt->setMinimumHeight(26); + colorButt->setGeometry(0, 0, 26, 26); + + changeTeamColor(); + connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor())); + mainLayout.addWidget(colorButt); + + phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), QImage(":/res/hh25x25grey.png"), this); + connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged())); + phhoger->setHHNum(team.numHedgehogs()); + mainLayout.addWidget(phhoger); + } else { + } + + QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam())); + //QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam())); +} + +void TeamShowWidget::setInteractivity(bool interactive) +{ + if(m_team.isNetTeam()) { + butt->setEnabled(interactive); + } + + colorButt->setEnabled(interactive); + phhoger->setEnabled(interactive); +} + +void TeamShowWidget::setHHNum(unsigned int num) +{ + phhoger->setHHNum(num); +} + +void TeamShowWidget::hhNumChanged() +{ + m_team.setNumHedgehogs(phhoger->getHedgehogsNum()); + emit hhNmChanged(m_team); +} + +void TeamShowWidget::activateTeam() +{ + emit teamStatusChanged(m_team); +} + +/*HWTeamTempParams TeamShowWidget::getTeamParams() const +{ + if(!phhoger) throw; + HWTeamTempParams params; + params.numHedgehogs=phhoger->getHedgehogsNum(); + params.teamColor=colorButt->palette().color(QPalette::Button); + return params; +}*/ + +void TeamShowWidget::changeTeamColor(QColor color) +{ + FrameTeams* pOurFrameTeams=dynamic_cast(parentWidget()); + if(!color.isValid()) { + if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { + pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); + } + color=*pOurFrameTeams->currentColor; + } else { + // set according color iterator + pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(), + pOurFrameTeams->availableColors.end(), color); + if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) { + // error condition + pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin(); + } + } + + colorButt->setStyleSheet(QString("QPushButton{" + "background-color: %1;" + "border-width: 1px;" + "border-radius: 2px;" + "}").arg(pOurFrameTeams->currentColor->name())); + + m_team.setColor(color); + emit teamColorChanged(m_team); +} + +HWTeam TeamShowWidget::getTeam() const +{ + return m_team; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/teamselhelper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/teamselhelper.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,80 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2007 Igor Ulyanov + * Copyright (c) 2007-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _TEAMSEL_HELPER_INCLUDED +#define _TEAMSEL_HELPER_INCLUDED + +#include +#include +#include +#include + +#include "teamselect.h" +#include "hedgehogerWidget.h" + +class TeamLabel : public QLabel +{ + Q_OBJECT + + public: + TeamLabel(const QString& inp_str) : QLabel(inp_str) {}; + + signals: + void teamActivated(QString team_name); + + public slots: + void teamButtonClicked(); + +}; + +class TeamShowWidget : public QWidget +{ + Q_OBJECT + + public slots: + void changeTeamColor(QColor color=QColor()); + void hhNumChanged(); + + private slots: + void activateTeam(); + + public: + TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent); + void setPlaying(bool isPlaying); + void setHHNum(unsigned int num); + void setInteractivity(bool interactive); + HWTeam getTeam() const; + + private: + TeamShowWidget(); + QHBoxLayout mainLayout; + HWTeam m_team; + bool m_isPlaying; + CHedgehogerWidget* phhoger; + QPushButton* colorButt; + QPushButton* butt; +// QPushButton* bText; + + signals: + void teamStatusChanged(HWTeam team); + void hhNmChanged(const HWTeam&); + void teamColorChanged(const HWTeam&); +}; + +#endif // _TEAMSEL_HELPER_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/togglebutton.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/togglebutton.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,52 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2009 Kristian Lehmann + * Copyright (c) 2009-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "togglebutton.h" + +ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img) + : QPushButton(parent) +{ + setCheckable(true); + + QPixmap pm(":/res/btnDisabled.png"); + QPainter * painter = new QPainter(); + + pmChecked.load(img); + pmDisabled.load(img); + + setMaximumWidth(pmChecked.width() + 6); + + painter->begin(&pmDisabled); + painter->drawPixmap(pmDisabled.rect(), pm); + painter->end(); + + setIconSize(pmDisabled.size()); + setIcon(pmDisabled); + + connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool))); +} + +ToggleButtonWidget::~ToggleButtonWidget() +{ +} + +void ToggleButtonWidget::eventToggled(bool checked) +{ + setIcon(checked ? pmChecked : pmDisabled); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/togglebutton.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/togglebutton.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,42 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2009 Kristian Lehmann + * Copyright (c) 2009-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef TOGGLEBUTTONWIDGET_H +#define TOGGLEBUTTONWIDGET_H + +#include +#include +#include +#include +#include + +class ToggleButtonWidget : public QPushButton +{ + Q_OBJECT +public: + ToggleButtonWidget(QWidget * parent, QString img); + ~ToggleButtonWidget(); +private: + QPixmap pmChecked; + QPixmap pmDisabled; +private slots: + void eventToggled(bool checked); +}; + +#endif // TOGGLEBUTTONWIDGET_H diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/vertScrollArea.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/vertScrollArea.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,35 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006 Igor Ulyanov + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "vertScrollArea.h" + +#include + +VertScrArea::VertScrArea(QColor frameColor, QWidget * parent) : + QScrollArea(parent) +{ + QPalette newPalette = palette(); + newPalette.setColor(QPalette::Background, frameColor); + setPalette(newPalette); +} + +void VertScrArea::resizeEvent(QResizeEvent * event) +{ + widget()->resize(event->size().width(), widget()->sizeHint().height()); +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/vertScrollArea.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/vertScrollArea.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,36 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006 Igor Ulyanov + * Copyright (c) 2006-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _VERT_SCROLL_AREA_INCLUDED +#define _VERT_SCROLL_AREA_INCLUDED + +#include + +class VertScrArea : public QScrollArea +{ + Q_OBJECT + +public: + VertScrArea(QColor frameColor, QWidget * parent = 0); + +protected: + virtual void resizeEvent(QResizeEvent * event); +}; + +#endif // _VERT_SCROLL_AREA_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/weaponItem.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/weaponItem.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,40 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "weaponItem.h" + +WeaponItem::WeaponItem(const QImage& im, const QImage& img, QWidget * parent) : + ItemNum(im, img, parent, 0) +{ +} + +WeaponItem::~WeaponItem() +{ +} + +void WeaponItem::incItems() +{ + ++numItems; +} + +void WeaponItem::decItems() +{ + --numItems; +} + diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/ui/widget/weaponItem.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/ui/widget/weaponItem.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,44 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2006-2008 Igor Ulyanov + * Copyright (c) 2008-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef _WEAPON_ITEM +#define _WEAPON_ITEM + +#include "itemNum.h" + +class WeaponItem : public ItemNum +{ + Q_OBJECT + + public: + WeaponItem(const QImage& im, const QImage& img, QWidget * parent); + virtual ~WeaponItem(); + + signals: + void hedgehogsNumChanged(); + + protected: + virtual void incItems(); + virtual void decItems(); + + private: + WeaponItem(); +}; + +#endif // _WEAPON_ITEM diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/util/namegen.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/util/namegen.cpp Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,285 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2009 Martin Minarik + * Copyright (c) 2009-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include +#include +#include +#include +#include "namegen.h" +#include "hwform.h" +#include "hwconsts.h" + + +HWNamegen::HWNamegen() {} + +QList HWNamegen::TypesTeamnames; +QList HWNamegen::TypesHatnames; +bool HWNamegen::typesAvailable = false; + + +void HWNamegen::teamRandomNames(HWTeam & team, const bool changeteamname) +{ + // load types if not already loaded + if (!typesAvailable) + if (!loadTypes()) + return; // abort if loading failed + + // abort if there are no hat types + if (TypesHatnames.size() <= 0) + return; + + // the hat will influence which names the hogs get + int kind = (rand()%(TypesHatnames.size())); + + // pick team name based on hat + if (changeteamname) + { + if (TypesTeamnames[kind].size() > 0) + team.setName(TypesTeamnames[kind][rand()%(TypesTeamnames[kind].size())]); + + team.setGrave(getRandomGrave()); + team.setFort(getRandomFort()); + team.setVoicepack("Default"); + } + + QStringList dicts; + QStringList dict; + + if ((TypesHatnames[kind].size()) <= 0) + { + dicts = dictsForHat(team.hedgehog(0).Hat); + dict = dictContents(dicts[rand()%(dicts.size())]); + } + + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) + { + if ((TypesHatnames[kind].size()) > 0) + { + HWHog hh = team.hedgehog(i); + hh.Hat = TypesHatnames[kind][rand()%(TypesHatnames[kind].size())]; + team.setHedgehog(i,hh); + } + + // there is a chance that this hog has the same hat as the previous one + // let's reuse the hat-specific dict in this case + if ((i == 0) or (team.hedgehog(i).Hat != team.hedgehog(i-1).Hat)) + { + dicts = dictsForHat(team.hedgehog(i).Hat); + dict = dictContents(dicts[rand()%(dicts.size())]); + } + + // give each hedgehog a random name + HWNamegen::teamRandomName(team,i,dict); + } + +} + +void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber) +{ + QStringList dicts = dictsForHat(team.hedgehog(HedgehogNumber).Hat); + + QStringList dict = dictContents(dicts[rand()%(dicts.size())]); + + teamRandomName(team, HedgehogNumber, dict); +} + +void HWNamegen::teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict) +{ + QStringList namesDict = dict; + + for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) + { + namesDict.removeOne(team.hedgehog(i).Name); + } + + // if our dict doesn't have any new names we'll have to use duplicates + if (namesDict.size() < 1) + namesDict = dict; + + HWHog hh = team.hedgehog(HedgehogNumber); + + hh.Name = namesDict[rand()%(namesDict.size())]; + + team.setHedgehog(HedgehogNumber, hh); +} + +QStringList HWNamegen::dictContents(const QString filename) +{ + QStringList list; + + QFile file; + + // find .cfg to load the names from + file.setFileName(QString("%1/Data/Names/%2.txt").arg(cfgdir->absolutePath()).arg(filename)); + if (!file.exists()) + file.setFileName(QString("%1/Names/%2.txt").arg(datadir->absolutePath()).arg(filename)); + + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + + QTextStream in(&file); + while (!in.atEnd()) + { + QString line = in.readLine(); + if(!line.isEmpty()) + list.append(line); + } + } + + if (list.size() == 0) + list.append(filename); + + return list; +} + + +QStringList HWNamegen::dictsForHat(const QString hatname) +{ + QStringList list; + + QFile file; + + // find .cfg to load the names from + file.setFileName(QString("%1/Data/Names/%2.cfg").arg(cfgdir->absolutePath()).arg(hatname)); + if (!file.exists()) + file.setFileName(QString("%1/Names/%2.cfg").arg(datadir->absolutePath()).arg(hatname)); + + + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&file); + while (!in.atEnd()) + { + QString line = in.readLine(); + if(!line.isEmpty()) + list.append(line); + } + } + + if (list.size() == 0) + list.append(QString("generic")); + + return list; +} + +// loades types from ini files. returns true on success. +bool HWNamegen::loadTypes() +{ + QFile file; + + // find .cfg to load the names from + file.setFileName(QString("%1/Data/Names/types.ini").arg(cfgdir->absolutePath())); + if (!file.exists()) + file.setFileName(QString("%1/Names/types.ini").arg(datadir->absolutePath())); + + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return false; + + int counter = 0; //counter starts with 0 (teamnames mode) + TypesTeamnames.append(QStringList()); + TypesHatnames.append(QStringList()); + + QTextStream in(&file); + while (!in.atEnd()) + { + QString line = in.readLine(); + if (line == QString("#####")) + { + counter++; //toggle mode (teamnames || hats) + if ((counter%2) == 0) + { + TypesTeamnames.append(QStringList()); + TypesHatnames.append(QStringList()); + } + } + else if ((line == QString("*****")) || (line == QString("*END*"))) + { + typesAvailable = true; + return true; // bye bye + } + else + { + if ((counter%2) == 0) + { + // even => teamnames mode + TypesTeamnames[(counter/2)].append(line); + } + else + { + // odd => hats mode + TypesHatnames[((counter-1)/2)].append(line); + } + } + } + + typesAvailable = true; + return true; +} + + + +QString HWNamegen::getRandomGrave() +{ + QStringList Graves; + + //list all available Graves + QDir tmpdir; + tmpdir.cd(cfgdir->absolutePath()); + tmpdir.cd("Data/Graphics/Graves"); + tmpdir.setFilter(QDir::Files); + Graves.append(tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1")); + + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Graphics/Graves"); + tmpdir.setFilter(QDir::Files); + QStringList tmpList = tmpdir.entryList(QStringList("*.png")).replaceInStrings(QRegExp("^(.*)\\.png"), "\\1"); + for (QStringList::Iterator it = tmpList.begin(); it != tmpList.end(); ++it) + if (!Graves.contains(*it,Qt::CaseInsensitive)) Graves.append(*it); + + if(Graves.size()==0) + { + //do some serious error handling + return "Error"; + } + + //pick a random grave + return Graves[rand()%(Graves.size())]; +} + +QString HWNamegen::getRandomFort() +{ + QStringList Forts; + + //list all available Forts + QDir tmpdir; + tmpdir.cd(datadir->absolutePath()); + tmpdir.cd("Forts"); + tmpdir.setFilter(QDir::Files); + Forts.append(tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1")); + + if(Forts.size()==0) + { + //do some serious error handling + return "Error"; + } + + //pick a random fort + return Forts[rand()%(Forts.size())]; +} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/util/namegen.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/util/namegen.h Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,53 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2009 Martin Minarik + * Copyright (c) 2009-2011 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef NAMEGEN_H +#define NAMEGEN_H + +#include + +class HWForm; +class HWTeam; + +class HWNamegen +{ +public: + + static void teamRandomName(HWTeam & team, const int HedgehogNumber); + static void teamRandomNames(HWTeam & team, const bool changeteamname); + +private: + HWNamegen(); + + static QList TypesTeamnames; + static QList TypesHatnames; + static bool typesAvailable; + + static bool loadTypes(); + static QStringList dictContents(const QString filename); + static QStringList dictsForHat(const QString hatname); + + static QString getRandomGrave(); + static QString getRandomFort(); + static void teamRandomName(HWTeam & team, const int HedgehogNumber, const QStringList & dict); +}; + + + +#endif diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/vertScrollArea.cpp --- a/QTfrontend/vertScrollArea.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006 Igor Ulyanov - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "vertScrollArea.h" - -#include - -VertScrArea::VertScrArea(QColor frameColor, QWidget * parent) : - QScrollArea(parent) -{ - QPalette newPalette = palette(); - newPalette.setColor(QPalette::Background, frameColor); - setPalette(newPalette); -} - -void VertScrArea::resizeEvent(QResizeEvent * event) -{ - widget()->resize(event->size().width(), widget()->sizeHint().height()); -} diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/vertScrollArea.h --- a/QTfrontend/vertScrollArea.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006 Igor Ulyanov - * Copyright (c) 2006-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _VERT_SCROLL_AREA_INCLUDED -#define _VERT_SCROLL_AREA_INCLUDED - -#include - -class VertScrArea : public QScrollArea -{ - Q_OBJECT - -public: - VertScrArea(QColor frameColor, QWidget * parent = 0); - -protected: - virtual void resizeEvent(QResizeEvent * event); -}; - -#endif // _VERT_SCROLL_AREA_INCLUDED diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/weaponItem.cpp --- a/QTfrontend/weaponItem.cpp Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include "weaponItem.h" - -WeaponItem::WeaponItem(const QImage& im, const QImage& img, QWidget * parent) : - ItemNum(im, img, parent, 0) -{ -} - -WeaponItem::~WeaponItem() -{ -} - -void WeaponItem::incItems() -{ - ++numItems; -} - -void WeaponItem::decItems() -{ - --numItems; -} - diff -r 531f64292489 -r 5a4ea2c7b9df QTfrontend/weaponItem.h --- a/QTfrontend/weaponItem.h Sat Oct 08 16:45:52 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Hedgewars, a free turn based strategy game - * Copyright (c) 2006-2008 Igor Ulyanov - * Copyright (c) 2008-2011 Andrey Korotaev - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#ifndef _WEAPON_ITEM -#define _WEAPON_ITEM - -#include "itemNum.h" - -class WeaponItem : public ItemNum -{ - Q_OBJECT - - public: - WeaponItem(const QImage& im, const QImage& img, QWidget * parent); - virtual ~WeaponItem(); - - signals: - void hedgehogsNumChanged(); - - protected: - virtual void incItems(); - virtual void decItems(); - - private: - WeaponItem(); -}; - -#endif // _WEAPON_ITEM diff -r 531f64292489 -r 5a4ea2c7b9df README --- a/README Sat Oct 08 16:45:52 2011 +0200 +++ b/README Sat Oct 08 16:54:56 2011 +0200 @@ -3,5 +3,5 @@ Images and sounds are distributed under the terms of the GNU FDL licence. Source: -Copyright 2004-2010 Andrey Korotaev +Copyright 2004-2011 Andrey Korotaev Portions copyright 2006-2008 Igor Ulyanov aka Displacer diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/Actions.hs --- a/gameServer/Actions.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/Actions.hs Sat Oct 08 16:54:56 2011 +0200 @@ -1,4 +1,4 @@ -{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP, OverloadedStrings #-} module Actions where import Control.Concurrent @@ -17,16 +17,17 @@ import Data.Unique import Control.Arrow import Control.Exception -import OfficialServer.GameReplayStore import System.Process import Network.Socket ----------------------------- +import OfficialServer.GameReplayStore import CoreTypes import Utils import ClientIO import ServerState import Consts import ConfigFile +import EngineInteraction data Action = AnswerClients ![ClientChan] ![B.ByteString] @@ -206,7 +207,7 @@ (Just ci) <- gets clientIndex ri <- clientRoomA rnc <- gets roomsClients - (gameProgress, playersNum) <- io $ room'sM rnc (gameinprogress &&& playersIn) ri + (gameProgress, playersNum) <- io $ room'sM rnc ((isJust . gameInfo) &&& playersIn) ri ready <- client's isReady master <- client's isMaster -- client <- client's id @@ -298,7 +299,7 @@ processAction (RemoveTeam teamName) = do rnc <- gets roomsClients ri <- clientRoomA - inGame <- io $ room'sM rnc gameinprogress ri + inGame <- io $ room'sM rnc (isJust . gameInfo) ri chans <- othersChans if not $ inGame then mapM_ processAction [ @@ -310,8 +311,10 @@ AnswerClients chans ["EM", rmTeamMsg], ModifyRoom (\r -> r{ teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r, - leftTeams = teamName : leftTeams r, - roundMsgs = roundMsgs r Seq.|> rmTeamMsg + gameInfo = liftM (\g -> g{ + leftTeams = teamName : leftTeams g, + roundMsgs = roundMsgs g Seq.|> rmTeamMsg + }) $ gameInfo r }) ] where @@ -505,9 +508,13 @@ return () processAction $ ModifyServerInfo (\s -> s{shutdownPending = True}) +#if defined(OFFICIAL_SERVER) processAction SaveReplay = do ri <- clientRoomA rnc <- gets roomsClients io $ do r <- room'sM rnc id ri saveReplay r +#else +processAction SaveReplay = return () +#endif diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/ClientIO.hs --- a/gameServer/ClientIO.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/ClientIO.hs Sat Oct 08 16:54:56 2011 +0200 @@ -58,6 +58,10 @@ clientSendLoop :: Socket -> ThreadId -> Chan [B.ByteString] -> ClientIndex -> IO () clientSendLoop s tId chan ci = do answer <- readChan chan + + when (isQuit answer) $ + killReciever . B.unpack $ quitMessage answer + Exception.handle (\(e :: Exception.IOException) -> unless (isQuit answer) . killReciever $ show e) $ sendAll s $ B.unlines answer `B.snoc` '\n' @@ -65,7 +69,6 @@ if isQuit answer then do Exception.handle (\(_ :: Exception.IOException) -> putStrLn "error on sClose") $ sClose s - killReciever . B.unpack $ quitMessage answer else clientSendLoop s tId chan ci diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/CoreTypes.hs --- a/gameServer/CoreTypes.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/CoreTypes.hs Sat Oct 08 16:54:56 2011 +0200 @@ -62,6 +62,24 @@ hedgehogs :: [HedgehogInfo] } deriving (Show, Read) + +data GameInfo = + GameInfo + { + roundMsgs :: Seq B.ByteString, + leftTeams :: [B.ByteString], + teamsAtStart :: [TeamInfo], + allPlayersHaveRegisteredAccounts :: Bool, + giMapParams :: Map.Map B.ByteString B.ByteString, + giParams :: Map.Map B.ByteString [B.ByteString] + } deriving (Show, Read) + +--newGameInfo :: -> GameInfo +newGameInfo = + GameInfo + Data.Sequence.empty + [] + [] data RoomInfo = RoomInfo @@ -71,14 +89,11 @@ password :: B.ByteString, roomProto :: Word16, teams :: [TeamInfo], - gameinprogress :: Bool, + gameInfo :: Maybe GameInfo, playersIn :: !Int, readyPlayers :: !Int, isRestrictedJoins :: Bool, isRestrictedTeams :: Bool, - roundMsgs :: Seq B.ByteString, - leftTeams :: [B.ByteString], - teamsAtStart :: [TeamInfo], mapParams :: Map.Map B.ByteString B.ByteString, params :: Map.Map B.ByteString [B.ByteString] } @@ -91,14 +106,11 @@ "" 0 [] - False + Nothing 0 0 False False - Data.Sequence.empty - [] - [] ( Map.fromList $ Prelude.zipWith (,) ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"] diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/EngineInteraction.hs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gameServer/EngineInteraction.hs Sat Oct 08 16:54:56 2011 +0200 @@ -0,0 +1,38 @@ +module EngineInteraction where + +import qualified Data.Set as Set +import qualified Data.List as List +import Control.Monad +import qualified Codec.Binary.Base64 as Base64 +import qualified Data.ByteString.Char8 as B +import qualified Data.ByteString as BW +------------- +import CoreTypes + + +toEngineMsg :: B.ByteString -> B.ByteString +toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg) + + +fromEngineMsg :: B.ByteString -> Maybe B.ByteString +fromEngineMsg msg = liftM BW.pack (Base64.decode (B.unpack msg) >>= removeLength) + where + removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing + removeLength _ = Nothing + + +checkNetCmd :: B.ByteString -> (Bool, Bool) +checkNetCmd msg = check decoded + where + decoded = fromEngineMsg msg + check Nothing = (False, False) + check (Just ms) | B.length ms > 0 = let m = B.head ms in (m `Set.member` legalMessages, m == '+') + | otherwise = (False, False) + legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghbc12345" ++ slotMessages + slotMessages = "\128\129\130\131\132\133\134\135\136\137\138" + +gameInfo2Replay :: GameInfo -> B.ByteString +gameInfo2Replay GameInfo{roundMsgs = rm, + teamsAtStart = teams, + giMapParams = params1, + giParams = params2} = undefined diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/HWProtoCore.hs --- a/gameServer/HWProtoCore.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/HWProtoCore.hs Sat Oct 08 16:54:56 2011 +0200 @@ -52,7 +52,7 @@ let roomMasterSign = if isMaster cl then "@" else "" let adminSign = if isAdministrator cl then "@" else "" let roomInfo = if roomId /= lobbyId then B.concat [roomMasterSign, "room ", name clRoom] else adminSign `B.append` "lobby" - let roomStatus = if gameinprogress clRoom then + let roomStatus = if isJust $ gameInfo clRoom then if teamsInGame cl > 0 then "(playing)" else "(spectating)" else "" diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/HWProtoInRoomState.hs --- a/gameServer/HWProtoInRoomState.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/HWProtoInRoomState.hs Sat Oct 08 16:54:56 2011 +0200 @@ -14,6 +14,7 @@ import Utils import HandlerUtils import RoomsAndClients +import EngineInteraction handleCmd_inRoom :: CmdHandler @@ -52,13 +53,13 @@ clChan <- thisClientChans othChans <- roomOthersChans return $ - if not . null . drop 5 $ teams rm then + if not . null . drop (maxTeams rm - 1) $ teams rm then [Warning "too many teams"] else if canAddNumber rm <= 0 then [Warning "too many hedgehogs"] else if isJust $ findTeam rm then [Warning "There's already a team with same name in the list"] - else if gameinprogress rm then + else if isJust $ gameInfo rm then [Warning "round in progress"] else if isRestrictedTeams rm then [Warning "restricted"] @@ -78,6 +79,10 @@ hhsList [_] = error "Hedgehogs list with odd elements number" hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs newTeamHHNum r = min 4 (canAddNumber r) + maxTeams r + | roomProto r < 38 = 6 + | otherwise = 8 + handleCmd_inRoom ["REMOVE_TEAM", tName] = do (ci, _) <- ask @@ -162,19 +167,20 @@ ] handleCmd_inRoom ["START_GAME"] = do + (ci, rnc) <- ask cl <- thisClient rm <- thisRoom chans <- roomClientsChans + + let allPlayersRegistered = all ((<) 0 . B.length . webPassword . client rnc . teamownerId) $ teams rm - if isMaster cl && playersIn rm == readyPlayers rm && not (gameinprogress rm) then + if isMaster cl && playersIn rm == readyPlayers rm && not (isJust $ gameInfo rm) then if enoughClans rm then return [ ModifyRoom (\r -> r{ - gameinprogress = True, - roundMsgs = empty, - leftTeams = [], - teamsAtStart = teams r} + gameInfo = Just $ newGameInfo allPlayersRegistered (mapParams rm) (params rm) + } ), AnswerClients chans ["RUN_GAME"] ] @@ -191,35 +197,35 @@ rm <- thisRoom chans <- roomOthersChans - if teamsInGame cl > 0 && gameinprogress rm && isLegal then - return $ AnswerClients chans ["EM", msg] : [ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}) | not isKeepAlive] + if teamsInGame cl > 0 && (isJust $ gameInfo rm) && isLegal then + return $ AnswerClients chans ["EM", msg] : [ModifyRoom (\r -> r{gameInfo = liftM (\g -> g{roundMsgs = roundMsgs g |> msg}) $ gameInfo r}) | not isKeepAlive] else return [] where (isLegal, isKeepAlive) = checkNetCmd msg -handleCmd_inRoom ["ROUNDFINISHED", _] = do +handleCmd_inRoom ["ROUNDFINISHED", correctly] = do cl <- thisClient rm <- thisRoom chans <- roomClientsChans - if isMaster cl && gameinprogress rm then - return $ - ModifyRoom + if isMaster cl && (isJust $ gameInfo rm) then + return $ + SaveReplay + : ModifyRoom (\r -> r{ - gameinprogress = False, - readyPlayers = 0, - roundMsgs = empty, - leftTeams = [], - teamsAtStart = []} + gameInfo = Nothing, + readyPlayers = 0 + } ) : UnreadyRoomClients : answerRemovedTeams chans rm else return [] where - answerRemovedTeams chans = map (\t -> AnswerClients chans ["REMOVE_TEAM", t]) . leftTeams + answerRemovedTeams chans = map (\t -> AnswerClients chans ["REMOVE_TEAM", t]) . leftTeams . fromJust . gameInfo + isCorrect = correctly == "1" -- compatibility with clients with protocol < 38 handleCmd_inRoom ["ROUNDFINISHED"] = diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/HWProtoLobbyState.hs --- a/gameServer/HWProtoLobbyState.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/HWProtoLobbyState.hs Sat Oct 08 16:54:56 2011 +0200 @@ -12,6 +12,7 @@ import Utils import HandlerUtils import RoomsAndClients +import EngineInteraction answerAllTeams :: ClientInfo -> [TeamInfo] -> [Action] @@ -34,7 +35,7 @@ return [AnswerClients [sendChan cl] ("ROOMS" : roomsInfoList rooms)] where roomInfo irnc r = [ - showB $ gameinprogress r, + showB $ isJust $ gameInfo r, name r, showB $ playersIn r, showB $ length $ teams r, @@ -75,11 +76,12 @@ let maybeRI = find (\ri -> roomName == name (irnc `room` ri)) ris let jRI = fromJust maybeRI let jRoom = irnc `room` jRI + let sameProto = clientProto cl == roomProto jRoom let jRoomClients = map (client irnc) $ roomClients irnc jRI let nicks = map nick jRoomClients let chans = map sendChan (cl : jRoomClients) return $ - if isNothing maybeRI then + if isNothing maybeRI || not sameProto then [Warning "No such rooms"] else if isRestrictedJoins jRoom then [Warning "Joining restricted"] @@ -116,13 +118,13 @@ : ("SCHEME", pr Map.! "SCHEME") : (filter (\(p, _) -> p /= "SCHEME") $ Map.toList pr) - answerTeams cl jRoom = let f = if gameinprogress jRoom then teamsAtStart else teams in answerAllTeams cl $ f jRoom + answerTeams cl jRoom = let f = if isJust $ gameInfo jRoom then teamsAtStart . fromJust . gameInfo else teams in answerAllTeams cl $ f jRoom - watchRound cl jRoom = if not $ gameinprogress jRoom then + watchRound cl jRoom = if isNothing $ gameInfo jRoom then [] else [AnswerClients [sendChan cl] ["RUN_GAME"], - AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : Foldable.toList (roundMsgs jRoom)] + AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : Foldable.toList (roundMsgs . fromJust . gameInfo $ jRoom)] handleCmd_lobby ["JOIN_ROOM", roomName] = @@ -135,7 +137,7 @@ cl <- thisClient let ri = clientRoom rnc $ fromJust ci let clRoom = room rnc ri - if isNothing ci || ri == lobbyId || clientProto cl /= roomProto clRoom then + if isNothing ci || ri == lobbyId then return [] else handleCmd_lobby ["JOIN_ROOM", name clRoom] diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/OfficialServer/GameReplayStore.hs --- a/gameServer/OfficialServer/GameReplayStore.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/OfficialServer/GameReplayStore.hs Sat Oct 08 16:54:56 2011 +0200 @@ -1,18 +1,25 @@ {-# LANGUAGE ScopedTypeVariables #-} module OfficialServer.GameReplayStore where -import CoreTypes import Data.Time import Control.Exception as E import qualified Data.Map as Map import Data.Sequence() import System.Log.Logger +import Data.Maybe +import Data.Unique +import Control.Monad +--------------- +import CoreTypes + saveReplay :: RoomInfo -> IO () saveReplay r = do time <- getCurrentTime - let fileName = "replays/" ++ show time - let replayInfo = (teamsAtStart r, Map.toList $ mapParams r, Map.toList $ params r, roundMsgs r) + u <- liftM hashUnique newUnique + let fileName = "replays/" ++ show time ++ "-" ++ show u + let gi = fromJust $ gameInfo r + let replayInfo = (teamsAtStart gi, Map.toList $ mapParams r, Map.toList $ params r, roundMsgs gi) E.catch (writeFile fileName (show replayInfo)) (\(e :: IOException) -> warningM "REPLAYS" $ "Couldn't write to " ++ fileName ++ ": " ++ show e) diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/OfficialServer/extdbinterface.hs --- a/gameServer/OfficialServer/extdbinterface.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/OfficialServer/extdbinterface.hs Sat Oct 08 16:54:56 2011 +0200 @@ -17,7 +17,7 @@ "SELECT users.pass, users_roles.rid FROM users LEFT JOIN users_roles ON users.uid = users_roles.uid WHERE users.name = ?" dbQueryStats = - "UPDATE gameserver_stats SET players = ?, rooms = ?, last_update = UNIX_TIMESTAMP()" + "INSERT INTO gameserver_stats (players, rooms, last_update) VALUES (?, ?, UNIX_TIMESTAMP())" dbInteractionLoop dbConn = forever $ do q <- liftM read getLine diff -r 531f64292489 -r 5a4ea2c7b9df gameServer/Utils.hs --- a/gameServer/Utils.hs Sat Oct 08 16:45:52 2011 +0200 +++ b/gameServer/Utils.hs Sat Oct 08 16:54:56 2011 +0200 @@ -26,25 +26,6 @@ $ List.intersperse (':':) $ concatMap (\n -> (\(a0, a1) -> [showHex a0, showHex a1]) $ divMod n 65536) [a, b, c, d]) [] -toEngineMsg :: B.ByteString -> B.ByteString -toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg) - -fromEngineMsg :: B.ByteString -> Maybe B.ByteString -fromEngineMsg msg = liftM BW.pack (Base64.decode (B.unpack msg) >>= removeLength) - where - removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing - removeLength _ = Nothing - -checkNetCmd :: B.ByteString -> (Bool, Bool) -checkNetCmd msg = check decoded - where - decoded = fromEngineMsg msg - check Nothing = (False, False) - check (Just ms) | B.length ms > 0 = let m = B.head ms in (m `Set.member` legalMessages, m == '+') - | otherwise = (False, False) - legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghbc12345" ++ slotMessages - slotMessages = "\128\129\130\131\132\133\134\135\136\137\138" - maybeRead :: Read a => String -> Maybe a maybeRead s = case reads s of [(x, rest)] | all isSpace rest -> Just x @@ -103,6 +84,8 @@ , (35, "0.9.14.1") , (37, "0.9.15") , (38, "0.9.16-dev") + , (39, "0.9.16") + , (40, "0.9.17-dev") ] askFromConsole :: B.ByteString -> IO B.ByteString diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/CMakeLists.txt Sat Oct 08 16:54:56 2011 +0200 @@ -183,6 +183,10 @@ add_custom_target(${engine_output_name} ALL DEPENDS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}") +IF(NOT APPLE) +add_custom_target(ENGINECLEAN COMMAND ${CMAKE_BUILD_TOOL} "clean" "${PROJECT_BINARY_DIR}" "${hedgewars_SOURCE_DIR}/hedgewars") +add_dependencies(${engine_output_name} ENGINECLEAN) +ENDIF() install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/${engine_output_name}${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir}) diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/GSHandlers.inc Sat Oct 08 16:54:56 2011 +0200 @@ -103,6 +103,35 @@ end; end; +procedure HideHog(HH: PHedgehog); +begin +ScriptCall('onHogHide', HH^.Gear^.Uid); +DeleteCI(HH^.Gear); +if FollowGear = HH^.Gear then FollowGear:= nil; +if lastGearByUID = HH^.Gear then lastGearByUID := nil; +RemoveGearFromList(HH^.Gear); +with HH^.Gear^ do + begin + Z := cHHZ; + Active := false; + State:= State and not (gstHHDriven or gstAttacking or gstAttacked); + Message := Message and not gmAttack; + end; +HH^.GearHidden:= HH^.Gear; +HH^.Gear:= nil +end; + +procedure RestoreHog(HH: PHedgehog); +begin +HH^.Gear:=HH^.GearHidden; +HH^.GearHidden:= nil; +InsertGearToList(HH^.Gear); +HH^.Gear^.State:= (HH^.Gear^.State and not (gstHHDriven or gstInvisible or gstAttacking)) or gstAttacked; +AddGearCI(HH^.Gear); +HH^.Gear^.Active:= true; +ScriptCall('onHogRestore', HH^.Gear^.Uid) +end; + //////////////////////////////////////////////////////////////////////////////// procedure doStepDrowningGear(Gear: PGear); forward; @@ -190,8 +219,7 @@ procedure CheckCollision(Gear: PGear); inline; begin - if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) or TestCollisionYwithGear(Gear, hwSign(Gear^.dY) - ) + if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then Gear^.State := Gear^.State or gstCollision else Gear^.State := Gear^.State and not gstCollision end; @@ -274,6 +302,7 @@ //tmp: QWord; tdX, tdY: hwFloat; collV, collH: LongInt; + land: word; begin // clip velocity at 1.9 - over 1 per pixel, but really shouldn't cause many actual problems. if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862; @@ -291,28 +320,37 @@ if Gear^.dY.isNegative then begin isFalling := true; - if TestCollisionYwithGear(Gear, -1) then + land:= TestCollisionYwithGear(Gear, -1); + if land <> 0 then begin collV := -1; - Gear^.dX := Gear^.dX * Gear^.Friction; + if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_1 - (_1 - Gear^.Friction) / _10) + else Gear^.dX := Gear^.dX * Gear^.Friction; + Gear^.dY := - Gear^.dY * Gear^.Elasticity; Gear^.State := Gear^.State or gstCollision end - else if (Gear^.AdvBounce=1) and TestCollisionYwithGear(Gear, 1) then collV := 1; + else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then collV := 1; end - else if TestCollisionYwithGear(Gear, 1) then + else begin - collV := 1; - isFalling := false; - Gear^.dX := Gear^.dX * Gear^.Friction; - Gear^.dY := - Gear^.dY * Gear^.Elasticity; - Gear^.State := Gear^.State or gstCollision - end - else - begin - isFalling := true; - if (Gear^.AdvBounce=1) and not Gear^.dY.isNegative and TestCollisionYwithGear(Gear, -1) then - collV := -1; + land:= TestCollisionYwithGear(Gear, 1); + if land <> 0 then + begin + collV := 1; + isFalling := false; + if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_1 - (_1 - Gear^.Friction) / _10) + else Gear^.dX := Gear^.dX * Gear^.Friction; + + Gear^.dY := - Gear^.dY * Gear^.Elasticity; + Gear^.State := Gear^.State or gstCollision + end + else + begin + isFalling := true; + if (Gear^.AdvBounce=1) and not Gear^.dY.isNegative and (TestCollisionYwithGear(Gear, -1) <> 0) then + collV := -1 + end end; @@ -480,21 +518,56 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepMolotov(Gear: PGear); var + s: Longword; i, gX, gY: LongInt; dX, dY: hwFloat; Fire: PGear; + smoke, glass: PVisualGear; begin AllInactive := false; doStepFallingGear(Gear); CalcRotationDirAngle(Gear); + // let's add some smoke depending on speed + s:= max(32,152 - hwRound(Distance(Gear^.dX,Gear^.dY)*120))+random(10); + if (GameTicks mod s) = 0 then + begin + // adjust angle to match the texture + if Gear^.dX.isNegative then i:= 130 else i:= 50; + smoke:= AddVisualGear(hwRound(Gear^.X)-round(cos((Gear^.DirAngle+i) * pi / 180)*20), hwRound(Gear^.Y)-round(sin((Gear^.DirAngle+i) * pi / 180)*20), vgtSmoke); + if smoke <> nil then smoke^.Scale:= 0.75; + end; + if (Gear^.State and gstCollision) <> 0 then begin PlaySound(sndMolotov); gX := hwRound(Gear^.X); gY := hwRound(Gear^.Y); - //doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 5, EXPLAutoSound); + for i:= 0 to 4 do + begin + (*glass:= AddVisualGear(gx+random(7)-3, gy+random(5)-2, vgtEgg); + if glass <> nil then + begin + glass^.Frame:= 2; + glass^.Tint:= $41B83ED0 - i * $10081000; + glass^.dX:= 1/(10*(random(11)-5)); + glass^.dY:= -1/(random(4)+5); + end;*) + glass:= AddVisualGear(gx+random(7)-3, gy+random(7)-3, vgtStraightShot); + if glass <> nil then + with glass^ do + begin + Frame:= 2; + Tint:= $41B83ED0 - i * $10081000; + Angle:= random * 360; + dx:= 0.0000001; + dy:= 0; + if random(2) = 0 then dx := -dx; + FrameTicks:= 750; + State:= ord(sprEgg) + end; + end; for i:= 0 to 24 do begin dX := AngleCos(i * 2) * ((_0_15*(i div 5))) * (GetRandom + _1); @@ -930,6 +1003,44 @@ end; //////////////////////////////////////////////////////////////////////////////// +procedure spawnBulletTrail(Bullet: PGear); +var oX, oY: hwFloat; + VGear: PVisualGear; +begin + if Bullet^.PortalCounter = 0 then + begin + ox:= CurrentHedgehog^.Gear^.X + Int2hwFloat(GetLaunchX(CurrentHedgehog^.CurAmmoType, hwSign(CurrentHedgehog^.Gear^.dX), CurrentHedgehog^.Gear^.Angle)); + oy:= CurrentHedgehog^.Gear^.Y + Int2hwFloat(GetLaunchY(CurrentHedgehog^.CurAmmoType, CurrentHedgehog^.Gear^.Angle)); + end + else + begin + ox:= Bullet^.Elasticity; + oy:= Bullet^.Friction; + end; + + // Bullet trail + VGear := AddVisualGear(hwRound(ox), hwRound(oy), vgtLineTrail); + if VGear <> nil then + begin + VGear^.X:= hwFloat2Float(ox); + VGear^.Y:= hwFloat2Float(oy); + VGear^.dX:= hwFloat2Float(Bullet^.X); + VGear^.dY:= hwFloat2Float(Bullet^.Y); + + // reached edge of land. assume infinite beam. Extend it way out past camera + if (hwRound(Bullet^.X) and LAND_WIDTH_MASK <> 0) + or (hwRound(Bullet^.Y) and LAND_HEIGHT_MASK <> 0) then + // only extend if not under water + if hwRound(Bullet^.Y) < cWaterLine then + begin + VGear^.dX := VGear^.dX + LAND_WIDTH * (VGear^.dX - VGear^.X); + VGear^.dY := VGear^.dY + LAND_WIDTH * (VGear^.dY - VGear^.Y); + end; + + VGear^.Timer := 200; + end; +end; + procedure doStepBulletWork(Gear: PGear); var i, x, y: LongWord; @@ -948,6 +1059,19 @@ y := hwRound(Gear^.Y); if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then inc(Gear^.Damage); + // let's interrupt before a collision to give portals a chance to catch the bullet + if (Gear^.Damage = 1) and (Gear^.Tag = 0) and (Land[y, x] > 255) then + begin + Gear^.Tag := 1; + Gear^.Damage := 0; + Gear^.X := Gear^.X - Gear^.dX; + Gear^.Y := Gear^.Y - Gear^.dY; + CheckGearDrowning(Gear); + break; + end + else + Gear^.Tag := 0; + if Gear^.Damage > 5 then if Gear^.AmmoType = amDEagle then AmmoShove(Gear, 7, 20) @@ -993,31 +1117,7 @@ end; end; - if Gear^.PortalCounter = 0 then - begin - // Bullet trail - VGear := AddVisualGear( - hwround(CurrentHedgehog^.Gear^.X) + GetLaunchX(CurrentHedgehog^.CurAmmoType, hwSign(CurrentHedgehog^.Gear^.dX), CurrentHedgehog^.Gear^.Angle), - hwround(CurrentHedgehog^.Gear^.Y) + GetLaunchY(CurrentHedgehog^.CurAmmoType, CurrentHedgehog^.Gear^.Angle), - vgtLineTrail - ); - if VGear <> nil then - begin - // http://mantis.freepascal.org/view.php?id=17714 hits again - VGear^.dX := Gear^.X.QWordValue / SignAs(_1,_1).QWordValue; - VGear^.dY := Gear^.Y.QWordValue / SignAs(_1,_1).QWordValue; - - // reached edge of land. assume infinite beam. Extend it way out past camera - if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) - or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then - begin - VGear^.dX := VGear^.dX + (CurrentHedgehog^.Gear^.dX * LAND_WIDTH).QWordValue / SignAs(_1,_1).QWordValue; - VGear^.dY := VGear^.dY + (CurrentHedgehog^.Gear^.dY * LAND_WIDTH).QWordValue / SignAs(_1,_1).QWordValue; - end; - - VGear^.Timer := 200; - end - end; + spawnBulletTrail(Gear); Gear^.doStep := @doStepShotIdle end; end; @@ -1025,9 +1125,9 @@ procedure doStepDEagleShot(Gear: PGear); begin PlaySound(sndGun); - // add 2 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths - Gear^.X := Gear^.X + Gear^.dX * 2; - Gear^.Y := Gear^.Y + Gear^.dY * 2; + // add 3 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths, and also just plain old weird angles + Gear^.X := Gear^.X + Gear^.dX * 3; + Gear^.Y := Gear^.Y + Gear^.dY * 3; Gear^.doStep := @doStepBulletWork end; @@ -1061,9 +1161,9 @@ Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX) * _0_5; Gear^.dY := -AngleCos(HHGear^.Angle) * _0_5; PlaySound(sndGun); - // add an initial step to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths - Gear^.X := Gear^.X + Gear^.dX; - Gear^.Y := Gear^.Y + Gear^.dY; + // add 3 initial steps to avoid problem with ammoshove related to calculation of radius + 1 radius as gear widths, and also just weird angles + Gear^.X := Gear^.X + Gear^.dX * 3; + Gear^.Y := Gear^.Y + Gear^.dY * 3; Gear^.doStep := @doStepBulletWork; end else @@ -1169,7 +1269,7 @@ end; SetAllHHToActive; end; - if TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) <> 0 then begin Gear^.dY := _0; SetLittle(HHGear^.dX); @@ -1338,7 +1438,7 @@ HHGear := Gear^.Hedgehog^.Gear; if ((HHGear^.State and gstHHDriven) = 0) or (CheckGearDrowning(HHGear)) - or TestCollisionYwithGear(HHGear, 1) then + or (TestCollisionYwithGear(HHGear, 1) <> 0) then begin DeleteGear(Gear); isCursorVisible := false; @@ -1350,7 +1450,7 @@ if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX); - if HHGear^.dY.isNegative and TestCollisionYwithGear(HHGear, -1) then HHGear^.dY := _0; + if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then HHGear^.dY := _0; HHGear^.X := HHGear^.X + HHGear^.dX; HHGear^.Y := HHGear^.Y + HHGear^.dY; HHGear^.dY := HHGear^.dY + cGravity; @@ -1376,7 +1476,7 @@ var HHGear: PGear; len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat; - lx, ly: LongInt; + lx, ly, cd: LongInt; haveCollision, haveDivided: boolean; @@ -1413,20 +1513,36 @@ exit end; - if (Gear^.Message and gmLeft <> 0) then HHGear^.dX := HHGear^.dX - _0_0002 - else - if (Gear^.Message and gmRight <> 0) then HHGear^.dX := HHGear^.dX + _0_0002; - - if not TestCollisionYwithGear(HHGear, 1) then - begin - HHGear^.dY := HHGear^.dY + cGravity; - if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; - end; + if (Gear^.Message and gmLeft <> 0) and not TestCollisionXwithGear(HHGear, -1) then + HHGear^.dX := HHGear^.dX - _0_0002; + + if (Gear^.Message and gmRight <> 0) and not TestCollisionXwithGear(HHGear, 1) then + HHGear^.dX := HHGear^.dX + _0_0002; // vector between hedgehog and rope attaching point ropeDx := HHGear^.X - Gear^.X; ropeDy := HHGear^.Y - Gear^.Y; + if TestCollisionYwithGear(HHGear, 1) = 0 then + begin + + // depending on the rope vector we know which X-side to check for collision + // in order to find out if the hog can still be moved by gravity + if ropeDx.isNegative = RopeDy.IsNegative then + cd:= -1 + else + cd:= 1; + + // apply gravity if there is no obstacle + if not TestCollisionXwithGear(HHGear, cd) then + HHGear^.dY := HHGear^.dY + cGravity; + + if (GameFlags and gfMoreWind) <> 0 then + // apply wind if there's no obstacle + if not TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) then + HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; + end; + mdX := ropeDx + HHGear^.dX; mdY := ropeDy + HHGear^.dY; len := _1 / Distance(mdX, mdY); @@ -1444,12 +1560,12 @@ if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx)) - or TestCollisionYwithGear(HHGear, hwSign(ropeDy))) then + or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then Gear^.Elasticity := Gear^.Elasticity + _0_3; if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx)) - or TestCollisionYwithGear(HHGear, -hwSign(ropeDy))) then + or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then Gear^.Elasticity := Gear^.Elasticity - _0_3; HHGear^.X := Gear^.X + mdX * Gear^.Elasticity; @@ -1541,7 +1657,7 @@ HHGear^.dX := -_0_6 * HHGear^.dX; haveCollision := true end; - if TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) then + if TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0 then begin HHGear^.dY := -_0_6 * HHGear^.dY; haveCollision := true @@ -1643,12 +1759,12 @@ if (HHGear^.State and gstMoving) <> 0 then begin if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX); - if HHGear^.dY.isNegative and TestCollisionYwithGear(HHGear, -1) then HHGear^.dY := _0; + if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then HHGear^.dY := _0; HHGear^.X := HHGear^.X + HHGear^.dX; Gear^.X := Gear^.X + HHGear^.dX; - if TestCollisionYwithGear(HHGear, 1) then + if TestCollisionYwithGear(HHGear, 1) <> 0 then begin CheckHHDamage(HHGear); HHGear^.dY := _0 @@ -1756,11 +1872,11 @@ doStepFallingGear(Gear); if (Gear^.Health = 0) then begin - if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and TestCollisionYwithGear(Gear, 1) then + if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then inc(Gear^.Damage, hwRound(Gear^.dY * _70)) else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then inc(Gear^.Damage, hwRound(Gear^.dX * _70)) - else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and TestCollisionYwithGear(Gear, -1) then + else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then inc(Gear^.Damage, hwRound(Gear^.dX * -_70)); @@ -1820,7 +1936,7 @@ procedure doStepSMine(Gear: PGear); begin // TODO: do real calculation? - if TestCollisionXwithGear(Gear, 2) or TestCollisionYwithGear(Gear, -2) or TestCollisionXwithGear(Gear, -2) or TestCollisionYwithGear(Gear, 2) then + if TestCollisionXwithGear(Gear, 2) or (TestCollisionYwithGear(Gear, -2) <> 0) or TestCollisionXwithGear(Gear, -2) or (TestCollisionYwithGear(Gear, 2) <> 0) then begin if (hwAbs(Gear^.dX) > _0) or (hwAbs(Gear^.dY) > _0) then begin @@ -1892,13 +2008,13 @@ i: LongInt; particle: PVisualGear; begin - if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and not TestCollisionYwithGear(Gear, 1) then SetLittle(Gear^.dY); + if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then SetLittle(Gear^.dY); Gear^.State := Gear^.State or gstAnimation; if ((Gear^.dX.QWordValue <> 0) or (Gear^.dY.QWordValue <> 0)) then begin DeleteCI(Gear); AllInactive := false; - if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and TestCollisionYwithGear(Gear, 1) then + if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then begin Gear^.State := Gear^.State or gsttmpFlag; inc(Gear^.Damage, hwRound(Gear^.dY * _70)); @@ -1912,7 +2028,7 @@ else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then inc(Gear^.Damage, hwRound(Gear^.dX * _70)) - else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and TestCollisionYwithGear(Gear, -1) + else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then inc(Gear^.Damage, hwRound(Gear^.dY * -_70)) else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) @@ -1945,7 +2061,7 @@ if Gear^.dX.QWordValue = 0 then AddGearCI(Gear) end; *) - if not Gear^.dY.isNegative and (Gear^.dY < _0_001) and TestCollisionYwithGear(Gear, 1) then Gear + if not Gear^.dY.isNegative and (Gear^.dY < _0_001) and (TestCollisionYwithGear(Gear, 1) <> 0) then Gear ^.dY := _0; if hwAbs(Gear^.dX) < _0_001 then Gear^.dX := _0; @@ -2029,14 +2145,14 @@ exit end; - if (Gear^.dY.QWordValue <> 0) or (not TestCollisionYwithGear(Gear, 1)) then + if (Gear^.dY.QWordValue <> 0) or (TestCollisionYwithGear(Gear, 1) = 0) then begin AllInactive := false; Gear^.dY := Gear^.dY + cGravity; Gear^.Y := Gear^.Y + Gear^.dY; if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then SetAllHHToActive; - if (Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, -1) then Gear^.dY := _0; - if (not Gear^.dY.isNegative) and TestCollisionYwithGear(Gear, 1) then + if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY := _0; + if (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, 1) <> 0) then begin if (Gear^.dY > _0_2) and (k = gtExplosives) then inc(Gear^.Damage, hwRound(Gear^.dY * _70)); @@ -2142,7 +2258,7 @@ sticky:= (Gear^.State and gsttmpFlag) <> 0; if not sticky then AllInactive := false; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin AllInactive := false; @@ -2340,7 +2456,7 @@ inc(Gear^.Timer); - if TestCollisionYwithGear(HHGear, 1) + if (TestCollisionYwithGear(HHGear, 1) <> 0) or ((HHGear^.State and gstHHDriven) = 0) or CheckGearDrowning(HHGear) or ((Gear^.Message and gmAttack) <> 0) then @@ -2526,7 +2642,7 @@ HHGear^.X := HHGear^.X + HHGear^.dX; // hedgehog falling to collect cases HHGear^.dY := HHGear^.dY + cGravity; - if TestCollisionYwithGear(HHGear, 1) + if (TestCollisionYwithGear(HHGear, 1) <> 0) or CheckGearDrowning(HHGear) then begin DeleteGear(Gear); @@ -2622,7 +2738,7 @@ repeat CurrentTeam^.CurrHedgehog := Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^. HedgehogsNumber); - until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil); + until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.Damage = 0); CurrentHedgehog := @CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]; @@ -2693,8 +2809,12 @@ var i: LongWord; HHGear: PGear; + sparkles: PVisualGear; + hasWishes: boolean; begin AllInactive := false; + hasWishes:= ((Gear^.Message and (gmPrecise or gmSwitch)) = (gmPrecise or gmSwitch)); + if hasWishes then Gear^.AdvBounce:= 1; HHGear := Gear^.Hedgehog^.Gear; HHGear^.State := HHGear^.State or gstNoDamage; @@ -2702,9 +2822,19 @@ Gear^.X := HHGear^.X; Gear^.Y := HHGear^.Y; + if (GameTicks mod 2 = 0) and hasWishes then + begin + sparkles:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtDust, 1); + if sparkles <> nil then + begin + sparkles^.Tint:= ((random(210)+45) shl 24) or ((random(210)+45) shl 16) or ((random(210)+45) shl 8) or $FF; + sparkles^.Angle:= random * 360; + end + end; i := 2; repeat + Gear^.X := Gear^.X + HHGear^.dX; Gear^.Y := Gear^.Y + HHGear^.dY; HHGear^.X := Gear^.X; @@ -2721,7 +2851,13 @@ inc(upd); if upd > 3 then begin - if Gear^.Health < 1500 then Gear^.Pos := 2; + if Gear^.Health < 1500 then + begin + if Gear^.AdvBounce <> 0 then + Gear^.Pos := 3 + else + Gear^.Pos := 2; + end; AmmoShove(Gear, 30, 40); @@ -2738,6 +2874,21 @@ if Gear^.Health < Gear^.Damage then begin doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound); + for i:= 0 to 31 do + begin + sparkles:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot); + if sparkles <> nil then + with sparkles^ do + begin + Tint:= ((random(210)+45) shl 24) or ((random(210)+45) shl 16) or ((random(210)+45) shl 8) or $FF; + Angle:= random * 360; + dx:= 0.001 * (random(200)); + dy:= 0.001 * (random(200)); + if random(2) = 0 then dx := -dx; + if random(2) = 0 then dy := -dy; + FrameTicks:= random(400) + 250 + end; + end; AfterAttack; DeleteGear(Gear); DeleteGear(HHGear); @@ -2754,11 +2905,11 @@ AllInactive := false; dec(Gear^.Timer); if Gear^.Timer = 0 then - begin + begin Gear^.Pos := 1; PlaySound(sndKamikaze, Gear^.Hedgehog^.Team^.voicepack); Gear^.doStep := @doStepKamikazeWork - end + end end; procedure doStepKamikaze(Gear: PGear); @@ -2864,7 +3015,7 @@ yyn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].y; if (xx = 0) then - if TestCollisionYwithGear(Gear, yy) then + if TestCollisionYwithGear(Gear, yy) <> 0 then PrevAngle else begin @@ -2941,13 +3092,12 @@ AllInactive := false; Gear^.dY := Gear^.dY + cGravity; - if TestCollisionYwithGear(Gear, 1) then - Gear^.doStep := @doStepCakeUp + if TestCollisionYwithGear(Gear, 1) <> 0 then Gear^.doStep := @doStepCakeUp else - begin + begin Gear^.Y := Gear^.Y + Gear^.dY; if CheckGearDrowning(Gear) then AfterAttack - end + end end; procedure doStepCake(Gear: PGear); @@ -3112,11 +3262,10 @@ t := CheckGearsCollision(Gear); //fixes drill not exploding when touching HH bug - if (Gear^.Timer = 0) - or (t^.Count <> 0) - or (not TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) - and not TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) - and ((Gear^.State and gsttmpFlag) = 0)) + if (Gear^.Timer = 0) or (t^.Count <> 0) or + ( ((Gear^.State and gsttmpFlag) = 0) and + (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) + and not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))) // CheckLandValue returns true if the type isn't matched or not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible) then begin @@ -3129,7 +3278,7 @@ DeleteGear(Gear); exit end - else if not TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) and not TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) then + else if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and not TestCollisionXWithGear(Gear, hwSign(Gear^.dX)) then begin StopSound(Gear^.SoundChannel); Gear^.Tag := 1; @@ -3483,8 +3632,7 @@ or (cWaterLine + 512 < hwRound(HHGear^.Y)) or (TurnTimeLeft = 0) // allow brief ground touches - to be fair on this, might need another counter - or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and TestCollisionYwithGear( - HHGear, 1)) + or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0)) or ((Gear^.Message and gmAttack) <> 0) then begin with HHGear^ do @@ -3608,8 +3756,7 @@ or CheckGearDrowning(HHGear) or (TurnTimeLeft = 0) // allow brief ground touches - to be fair on this, might need another counter - or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and TestCollisionYwithGear( - HHGear, 1)) + or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0)) or ((Gear^.Message and gmAttack) <> 0) then begin with HHGear^ do @@ -3883,12 +4030,20 @@ continue; end; + // draw bullet trail + if isbullet then + spawnBulletTrail(iterator); + // calc gear offset in portal vector direction ox := (iterator^.X - Gear^.X); oy := (iterator^.Y - Gear^.Y); poffs:= (Gear^.dX * ox + Gear^.dY * oy); - if poffs < _0 then + if not isBullet and poffs.isNegative then + continue; + + // only port bullets close to the portal + if isBullet and not (hwAbs(poffs) < _3) then continue; // @@ -3916,8 +4071,11 @@ // calc gear offset in portal normal vector direction noffs:= (nx * ox + ny * oy); + if isBullet and (hwRound(hwAbs(noffs)) >= Gear^.Radius) then + continue; + // avoid gravity related loops of not really moving gear - if not iscake and (Gear^.dY.isNegative) and (conPortal^.dY.isNegative) + if not (iscake or isbullet) and (Gear^.dY.isNegative) and (conPortal^.dY.isNegative) and ((iterator^.dX.QWordValue + iterator^.dY.QWordValue) < _0_08.QWordValue) and (iterator^.PortalCounter > 0) then continue; @@ -4027,16 +4185,28 @@ // Until loops are reliably broken if iscake then iterator^.PortalCounter:= 33 - else inc(iterator^.PortalCounter); + else + begin + inc(iterator^.PortalCounter); + iterator^.State:= iterator^.State and not gstHHHJump + end; if not isbullet and (iterator^.Kind <> gtFlake) then FollowGear := iterator; + // store X/Y values of exit for net bullet trail + if isbullet then + begin + iterator^.Elasticity:= iterator^.X; + iterator^.Friction := iterator^.Y; + end; + // This jiggles gears, to ensure a portal connection just placed under a gear takes effect. iterator:= GearsList; while iterator <> nil do begin - if iterator^.Kind <> gtPortal then + if (iterator^.Kind <> gtPortal) and + ((iterator^.Hedgehog <> CurrentHedgehog) or ((iterator^.Message and gmAllStoppable) = 0)) then begin iterator^.Active:= true; if iterator^.dY.QWordValue = _0.QWordValue then iterator^.dY.isNegative:= false; @@ -4093,7 +4263,7 @@ begin Gear^.State := Gear^.State or gstCollision; Gear^.State := Gear^.State and not gstMoving; - if not calcSlopeTangent(Gear, x, y, tx, ty, 255) + if not CalcSlopeTangent(Gear, x, y, tx, ty, 255) or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain begin loadNewPortalBall(Gear, true); @@ -4646,7 +4816,7 @@ i := hwRound(Gear^.X) - HitGear^.Radius + 2; ei := hwRound(Gear^.X) + HitGear^.Radius - 2; for j := 1 to 4 do DrawExplosion(i - GetRandom(5), hwRound(Gear^.Y) + 6*j, 3); - for j := 1 to 4 do DrawExplosion(ei + GetRandom(5), hwRound(Gear^.Y) + 6*j, 3); + for j := 1 to 4 do DrawExplosion(ei + LongInt(GetRandom(5)), hwRound(Gear^.Y) + 6*j, 3); while i <= ei do begin for j := 1 to 11 do DrawExplosion(i, hwRound(Gear^.Y) + 3*j, 3); @@ -4660,7 +4830,7 @@ Gear^.Y := Gear^.Y + _1_9; end; end; - if TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) <> 0 then begin Gear^.dY := _0; SetLittle(HitGear^.dX); @@ -4735,7 +4905,7 @@ if Gear^.Power < 45 then begin inc(Gear^.Power); - if not TestCollisionYwithGear(hh^.Gear, -1) then hh^.Gear^.Y := hh^.Gear^.Y - _1; + if TestCollisionYwithGear(hh^.Gear, -1) = 0 then hh^.Gear^.Y := hh^.Gear^.Y - _1; end; graves := GearsNear(Gear^.X, Gear^.Y, gtGrave, Gear^.Radius); @@ -4936,7 +5106,6 @@ var HH: PHedgehog; i,j,cnt: LongWord; begin - HH:= Gear^.Hedgehog; if Gear^.Pos = 2 then begin @@ -4945,30 +5114,15 @@ begin if (HH^.Gear <> nil) and (HH^.Gear^.State and gstInvisible = 0) then begin - AfterAttack; + AfterAttack; if Gear = CurAmmoGear then CurAmmoGear := nil; - DeleteCI(HH^.Gear); - RemoveGearFromList(HH^.Gear); - with HH^.Gear^ do - begin - Z := cHHZ; - Active := false; - State:= State and not (gstHHDriven or gstAttacking or gstAttacked); - Message := Message and not gmAttack; - end; - HH^.GearHidden:= HH^.Gear; - HH^.Gear:= nil + if (HH^.Gear^.Damage = 0) and (HH^.Gear^.Health > 0) and + ((Gear^.State and (gstMoving or gstHHDeath or gstHHGone)) = 0) then + HideHog(HH) end //else if (HH^.Gear <> nil) and (HH^.Gear^.State and gstInvisible <> 0) then else if (HH^.GearHidden <> nil) then// and (HH^.Gear^.State and gstInvisible <> 0) then - begin - HH^.Gear:=HH^.GearHidden; - HH^.GearHidden:= nil; - InsertGearToList(HH^.Gear); - HH^.Gear^.State:= (HH^.Gear^.State and not (gstHHDriven or gstInvisible or gstAttacking)) or gstAttacked; - AddGearCI(HH^.Gear); - HH^.Gear^.Active:= true - end; + RestoreHog(HH) end; inc(Gear^.Timer); @@ -4979,7 +5133,20 @@ end end; -if (Gear^.Pos = 1) and (GameTicks and $1F = 0) and (Gear^.Power < 255) then inc(Gear^.Power); +if (Gear^.Pos = 1) and (GameTicks and $1F = 0) and (Gear^.Power < 255) then + begin + inc(Gear^.Power); + if (Gear^.Power = 172) and (HH^.Gear <> nil) and + (HH^.Gear^.Damage = 0) and (HH^.Gear^.Health > 0) and + ((HH^.Gear^.State and (gstMoving or gstHHDeath or gstHHGone)) = 0) then + with HH^.Gear^ do + begin + State:= State or gstAnimation; + Tag:= 2; + Timer:= 0; + Pos:= 0 + end + end; if (Gear^.Pos = 3) and (GameTicks and $1F = 0) and (Gear^.Power > 0) then dec(Gear^.Power); if (Gear^.Pos = 1) and (Gear^.Power = 255) and ((GameTicks mod 2000) = 1000) then Gear^.Pos:= 2; if (Gear^.Pos = 3) and (Gear^.Power = 0) then @@ -5036,13 +5203,14 @@ 3. Hog is a king *) HH:= Gear^.Hedgehog; + if HH^.Gear <> nil then if (HH^.Gear = nil) or (HH^.King) or (SuddenDeathDmg) then begin - if HH^.Gear <> nil then - begin - HH^.Gear^.Message := HH^.Gear^.Message and not gmAttack; - HH^.Gear^.State:= HH^.Gear^.State and not gstAttacking; - end; + if HH^.Gear <> nil then + begin + HH^.Gear^.Message := HH^.Gear^.Message and not gmAttack; + HH^.Gear^.State:= HH^.Gear^.State and not gstAttacking; + end; PlaySound(sndDenied); DeleteGear(gear); exit @@ -5056,14 +5224,14 @@ HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt); if cnt < 2 then begin - if HH^.Gear <> nil then - begin - HH^.Gear^.Message := HH^.Gear^.Message and not gmAttack; - HH^.Gear^.State:= HH^.Gear^.State and not gstAttacking; - end; - PlaySound(sndDenied); - DeleteGear(gear); - exit + if HH^.Gear <> nil then + begin + HH^.Gear^.Message := HH^.Gear^.Message and not gmAttack; + HH^.Gear^.State:= HH^.Gear^.State and not gstAttacking; + end; + PlaySound(sndDenied); + DeleteGear(gear); + exit end; Gear^.SoundChannel := LoopSound(sndTardis); Gear^.doStep:= @doStepTardisWarp diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/HHHandlers.inc Sat Oct 08 16:54:56 2011 +0200 @@ -53,7 +53,6 @@ HHGear^.Message:= HHGear^.Message and not gmSlot; ammoidx:= 0; if ((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) or - (TargetPoint.X <> NoPointX) or ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or ((HHGear^.State and gstHHDriven) = 0) then exit; ChangeAmmo:= true; @@ -483,15 +482,16 @@ AllInactive:= false; dec(Gear^.Timer); if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos) - end else -if Gear^.Timer = 1 then + end +else if Gear^.Timer = 1 then begin Gear^.State:= Gear^.State or gstNoDamage; doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, CurrentHedgehog, EXPLAutoSound); AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog; DeleteGear(Gear); SetAllToActive - end else // Gear^.Timer = 0 + end +else // Gear^.Timer = 0 begin AllInactive:= false; Gear^.Z:= cCurrHHZ; @@ -638,11 +638,11 @@ begin Gear^.Message:= Gear^.Message and not gmLJump; DeleteCI(Gear); - if not TestCollisionYwithGear(Gear, -1) then + if TestCollisionYwithGear(Gear, -1) = 0 then if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _2 else if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then + or (TestCollisionYwithGear(Gear, -1) <> 0)) then begin Gear^.dY:= -_0_15; if not cArtillery then Gear^.dX:= SignAs(_0_15, Gear^.dX); @@ -685,17 +685,17 @@ if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then begin if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; end; if (not cArtillery) and ((Gear^.Message and gmPrecise) = 0) and (not TestCollisionXwithGear(Gear, hwSign(Gear^.dX))) then @@ -703,25 +703,25 @@ SetAllHHToActive; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y - _6; Gear^.dY:= _0; @@ -758,7 +758,9 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepHedgehogMoving(Gear: PGear); var isFalling, isUnderwater: boolean; + land: Word; begin +land:= 0; isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius; if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862; if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862; @@ -775,6 +777,11 @@ begin if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0; Gear^.State:= Gear^.State or gstMoving; + if (CurrentHedgehog^.Gear = Gear) + and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > _0_003) then + begin + FollowGear:= Gear; + end; if isUnderwater then Gear^.dY:= Gear^.dY + cGravity / _2 else begin @@ -791,7 +798,8 @@ end else begin - if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) + land:= TestCollisionYwithGear(Gear, 1); + if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0) and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX); if not Gear^.dY.isNegative then @@ -805,7 +813,11 @@ Gear^.dY:= _0; end else Gear^.dY:= Gear^.dY + cGravity; - if ((Gear^.State and gstMoving) <> 0) then Gear^.dX:= Gear^.dX * Gear^.Friction + if ((Gear^.State and gstMoving) <> 0) then + begin + if land and lfIce <> 0 then Gear^.dX:= Gear^.dX * (_1 - (_1 - Gear^.Friction) / _2) + else Gear^.dX:= Gear^.dX * Gear^.Friction; + end end; if (Gear^.State <> 0) then DeleteCI(Gear); @@ -868,7 +880,7 @@ if (hwAbs(Gear^.dY) > _0) and (Gear^.FlightTime > 0) and ((GameFlags and gfLowGravity) = 0) then begin - inc(Gear^.FlightTime, 1); + inc(Gear^.FlightTime); if Gear^.FlightTime = 3000 then begin AddCaption(GetEventString(eidHomerun), cWhiteColor, capgrpMessage); @@ -877,6 +889,7 @@ end else begin + uStats.hedgehogFlight(Gear, Gear^.FlightTime); Gear^.FlightTime:= 0; end; @@ -888,11 +901,13 @@ Hedgehog: PHedgehog; begin Hedgehog:= HHGear^.Hedgehog; -if not isInMultiShoot then - AllInactive:= false -else +if isInMultiShoot then HHGear^.Message:= 0; +if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Utility) <> 0) and isInMultiShoot then + AllInactive:= true +else if not isInMultiShoot then AllInactive:= false; + if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then begin if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft; @@ -1034,22 +1049,24 @@ PrvInactive:= false; AllInactive:= false; - if not Gear^.Hedgehog^.Team^.hasGone then + if (Gear^.State and gstHHGone) = 0 then begin Gear^.Hedgehog^.Effects[hePoisoned] := false; if Gear^.Hedgehog^.Effects[heResurrectable] then begin ResurrectHedgehog(Gear); - end else begin - Gear^.State:= Gear^.State or gstHHDeath; + end else + begin + Gear^.State:= (Gear^.State or gstHHDeath) and not gstAnimation; Gear^.doStep:= @doStepHedgehogDead; // Death message AddCaption(Format(GetEventString(eidDied), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); - end; + end; end else begin - Gear^.State:= Gear^.State or gstHHGone; + Gear^.State:= Gear^.State and not gstAnimation; Gear^.doStep:= @doStepHedgehogGone; + // Gone message AddCaption(Format(GetEventString(eidGone), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); end @@ -1060,13 +1077,13 @@ if ((Gear^.State and gstWait) = 0) and (prevState <> Gear^.State) then begin - Gear^.State:= gstWait; + Gear^.State:= Gear^.State or gstWait; Gear^.Timer:= 150 end else begin if Gear^.Timer = 0 then begin - Gear^.State:= 0; + Gear^.State:= Gear^.State and not (gstWait or gstLoser or gstWinner or gstAttacked); Gear^.Active:= false; AddGearCI(Gear); exit @@ -1090,7 +1107,9 @@ else begin with Gear^.Hedgehog^ do - if Team^.hasGone then TeamGoneEffect(Team^); - doStepHedgehogDriven(Gear) + if Team^.hasGone then + TeamGoneEffect(Team^) + else + doStepHedgehogDriven(Gear) end; end; diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/PascalExports.pas diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/SDLh.pas Sat Oct 08 16:54:56 2011 +0200 @@ -228,6 +228,8 @@ SDL_HWPALETTE = $20000000; SDL_DOUBLEBUF = $40000000; SDL_FULLSCREEN = $80000000; + + SDL_ALLEVENTS = $FFFFFFFF; {$ENDIF} {$IFDEF ENDIAN_LITTLE} @@ -279,9 +281,6 @@ IMG_INIT_TIF = $00000004; {* SDL_EventMask type definition *} -{$IFNDEF SDL13} - SDL_ALLEVENTS = $FFFFFFFF; -{$ENDIF} ///////////////////////////////////////////////////////////////// /////////////////////// TYPE DEFINITIONS /////////////////////// @@ -776,6 +775,7 @@ function SDL_CreateRenderer(window: PSDL_Window; index, flags: LongInt): PSDL_Renderer; cdecl; external SDLLibName; function SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName; function SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName; +procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName; function SDL_GL_CreateContext(window: PSDL_Window): PSDL_GLContext; cdecl; external SDLLibName; procedure SDL_GL_DeleteContext(context: PSDL_GLContext); cdecl; external SDLLibName; @@ -804,7 +804,7 @@ function SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: SDL_eventaction; minType, maxType: LongInt): LongInt; cdecl; external SDLLibName; {$ELSE} -function SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: SDL_eventaction; mask: LongInt): LongInt; cdecl; external SDLLibName; +function SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: SDL_eventaction; mask: Longword): LongInt; cdecl; external SDLLibName; {$ENDIF} function SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName; @@ -871,8 +871,8 @@ procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName; (* SDL_mixer *) -function Mix_Init(flags: LongInt): LongInt; cdecl; external SDL_MixerLibName; -procedure Mix_Quit; cdecl; external SDL_MixerLibName; +function Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF} +procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF} function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; @@ -903,8 +903,8 @@ function Mix_FadeOutChannel(channel: LongInt; fadems: LongInt): LongInt; cdecl; external SDL_MixerLibName; (* SDL_image *) -function IMG_Init(flags: LongInt): LongInt; cdecl; external SDL_ImageLibName; -procedure IMG_Quit; cdecl; external SDL_ImageLibName; +function IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF} +procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF} function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; function IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongInt): PSDL_Surface; cdecl; external SDL_ImageLibName; @@ -963,13 +963,36 @@ function SDL_MustLock(Surface: PSDL_Surface): Boolean; begin + SDL_MustLock:= {$IFDEF SDL13} - SDL_MustLock:= ((surface^.flags and SDL_RLEACCEL) <> 0) + ((surface^.flags and SDL_RLEACCEL) <> 0) {$ELSE} - SDL_MustLock:= ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) + ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) {$ENDIF} end; +{$IFNDEF SDL_MIXER_NEWER} +function Mix_Init(flags: LongInt): LongInt; +begin + exit(flags); +end; + +procedure Mix_Quit; +begin +end; +{$ENDIF} + +{$IFNDEF SDL_IMAGE_NEWER} +function IMG_Init(flags: LongInt): LongInt; +begin + exit(flags); +end; + +procedure IMG_Quit; +begin +end; +{$ENDIF} + procedure SDLNet_Write16(value: Word; buf: pointer); begin PByteArray(buf)^[1]:= value; diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/VGSHandlers.inc --- a/hedgewars/VGSHandlers.inc Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/VGSHandlers.inc Sat Oct 08 16:54:56 2011 +0200 @@ -174,7 +174,10 @@ if Gear^.FrameTicks <= Steps then DeleteVisualGear(Gear) else - dec(Gear^.FrameTicks, Steps) + dec(Gear^.FrameTicks, Steps); + +if Gear^.FrameTicks < $FF then + Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or Gear^.FrameTicks end; //////////////////////////////////////////////////////////////////////////////// @@ -587,22 +590,16 @@ //////////////////////////////////////////////////////////////////////////////// procedure doStepBigExplosionWork(Gear: PVisualGear; Steps: Longword); -//var maxMovement: LongInt; +var maxMovement: LongInt; begin inc(Gear^.Timer, Steps); -(* -FIXME - This block desyncs due to the way WorldDx is important for various things network related. -One possible solution is, instead of using WorldDx, to use straight gl/SDL calls to jitter the screen a bit. - -// a comment by unC0Rr: instead of changing WorldDx shake cursor coordinates, that should be safe - if (Gear^.Timer and 5) = 0 then begin maxMovement := max(1, 13 - ((Gear^.Timer * 15) div 250)); ShakeCamera(maxMovement); end; -*) + if Gear^.Timer > 250 then DeleteVisualGear(Gear); end; @@ -611,6 +608,9 @@ gX,gY: LongInt; vg: PVisualGear; begin +//ScreenFade:= sfFromWhite; +//ScreenFadeValue:= round(60 * zoom * zoom); +//ScreenFadeSpeed:= 5; gX:= round(Gear^.X); gY:= round(Gear^.Y); AddVisualGear(gX, gY, vgtSmokeRing); diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/hwengine.pas Sat Oct 08 16:54:56 2011 +0200 @@ -100,6 +100,7 @@ gsExit: begin isTerminated:= true; end; + gsSuspend: exit; end; {$IFDEF SDL13} @@ -112,9 +113,17 @@ begin flagMakeCapture:= false; s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks); - WriteLnToConsole('Saving ' + s + '...'); + playSound(sndShutter); - {$IFNDEF IPHONEOS}MakeScreenshot(s);{$ENDIF} +{$IFNDEF IPHONEOS} + if not MakeScreenshot(s) then + begin + WriteLnToConsole('Screenshot failed.'); + AddChatString(#5 + 'screen capture failed (lack of memory or write permissions)'); + end + else +{$ENDIF} + WriteLnToConsole('Screenshot saved: ' + s); end; end; @@ -144,21 +153,21 @@ const event: TSDL_Event = (); {$WARNINGS ON} var PrevTime, CurrTime: Longword; +{$IFDEF SDL13} + previousGameState: TGameState; +{$ELSE} prevFocusState: boolean; +{$ENDIF} begin PrevTime:= SDL_GetTicks; while isTerminated = false do begin SDL_PumpEvents(); - {$IFDEF SDL13} - while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do - {$ELSE} - while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0 do - {$ENDIF} + while SDL_PeepEvents(@event, 1, SDL_GETEVENT, {$IFDEF SDL13}SDL_FIRSTEVENT, SDL_LASTEVENT{$ELSE}SDL_ALLEVENTS{$ENDIF}) > 0 do begin case event.type_ of +{$IFDEF SDL13} SDL_KEYDOWN: if GameState = gsChat then -{$IFDEF SDL13} // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3 KeyPressChat(event.key.keysym.sym); SDL_WINDOWEVENT: @@ -166,8 +175,24 @@ begin cHasFocus:= true; onFocusStateChanged() + end + else if event.window.event = SDL_WINDOWEVENT_MINIMIZED then + begin + previousGameState:= GameState; + GameState:= gsSuspend; + end + else if event.window.event = SDL_WINDOWEVENT_RESTORED then + begin + GameState:= previousGameState; + end + else if event.window.event = SDL_WINDOWEVENT_RESIZED then + begin + cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth); + cNewScreenHeight:= max(2 * (event.window.data2 div 2), cMinScreenHeight); + cScreenResizeDelay:= RealTicks+500; end; {$ELSE} + SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode); SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true; SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true; @@ -180,9 +205,12 @@ onFocusStateChanged() end; SDL_VIDEORESIZE: begin - // using lower values causes widget overlap and video issues - cNewScreenWidth:= max(event.resize.w, cMinScreenWidth); - cNewScreenHeight:= max(event.resize.h, cMinScreenHeight); + // using lower values than cMinScreenWidth or cMinScreenHeight causes widget overlap and off-screen widget parts + // Change by sheepluva: + // Let's only use even numbers for custom width/height since I ran into scaling issues with odd width values. + // Maybe just fixes the symptom not the actual cause(?), I'm too tired to find out :P + cNewScreenWidth:= max(2 * (event.resize.w div 2), cMinScreenWidth); + cNewScreenHeight:= max(2 * (event.resize.h div 2), cMinScreenHeight); cScreenResizeDelay:= RealTicks+500; end; {$ENDIF} @@ -193,6 +221,7 @@ SDL_QUITEV: isTerminated:= true end; //end case event.type_ of end; //end while SDL_PollEvent(@event) <> 0 do + if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then begin cScreenResizeDelay:= 0; @@ -200,30 +229,27 @@ cScreenHeight:= cNewScreenHeight; ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true); - WriteLnToConsole('window resize'); + WriteLnToConsole('window resize: ' + IntToStr(cScreenWidth) + ' x ' + IntToStr(cScreenHeight)); + ScriptOnScreenResize(); InitCameraBorders() end; if isTerminated = false then - begin + begin CurrTime:= SDL_GetTicks; if PrevTime + longword(cTimerInterval) <= CurrTime then - begin + begin DoTimer(CurrTime - PrevTime); PrevTime:= CurrTime - end + end else SDL_Delay(1); IPCCheckSock(); - end; + end; end; end; /////////////// -{$IFDEF HWLIBRARY} -procedure Game(gameArgs: PPChar); cdecl; export; -{$ELSE} -procedure Game; -{$ENDIF} +procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF}; var p: TPathType; s: shortstring; i: LongInt; @@ -250,8 +276,8 @@ recordFileName:= gameArgs[10]; cStereoMode:= smNone; {$ENDIF} - cMinScreenWidth:= min(cScreenWidth, 480); - cMinScreenHeight:= min(cScreenHeight, 320); + cMinScreenWidth:= min(cScreenWidth, cMinScreenWidth); + cMinScreenHeight:= min(cScreenHeight, cMinScreenHeight); cOrigScreenWidth:= cScreenWidth; cOrigScreenHeight:= cScreenHeight; diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uAIAmmoTests.pas --- a/hedgewars/uAIAmmoTests.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uAIAmmoTests.pas Sat Oct 08 16:54:56 2011 +0200 @@ -105,7 +105,7 @@ (proc: @TestHammer; flags: 0), // amHammer (proc: nil; flags: 0), // amResurrector (proc: nil; flags: 0), // amDrillStrike - (proc: @TestSnowball; flags: 0), // amSnowball + (proc: nil; flags: 0), // amSnowball (proc: nil; flags: 0), // amTardis (proc: nil; flags: 0), // amStructure (proc: nil; flags: 0) // amLandGun diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uAIMisc.pas Sat Oct 08 16:54:56 2011 +0200 @@ -80,7 +80,7 @@ procedure FillTargets; var i, t: Longword; - f, e: Longword; + f, e: LongInt; begin Targets.Count:= 0; f:= 0; @@ -112,7 +112,7 @@ end; if e > f then friendlyfactor:= 300 + (e - f) * 30 -else friendlyfactor:= max(30, 300 - f * 80 div e) +else friendlyfactor:= max(30, 300 - f * 80 div max(1,e)) end; procedure FillBonuses(isAfterAttack: boolean; filter: TGearsType); @@ -233,7 +233,7 @@ with Targets.ar[i] do begin dmg:= hwRound(_0_01 * cDamageModifier - * min((r + cHHRadius div 2 - DistanceI(Point.x - x, Point.y - y).Round) div 2, r) * cDamagePercent); + * min((r + cHHRadius div 2 - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent); if dmg > 0 then begin @@ -332,18 +332,18 @@ bY:= hwRound(Gear^.Y); case JumpType of jmpNone: exit(bRes); - jmpHJump: if not TestCollisionYwithGear(Gear, -1) then + jmpHJump: if TestCollisionYwithGear(Gear, -1) = 0 then begin Gear^.dY:= -_0_2; SetLittle(Gear^.dX); Gear^.State:= Gear^.State or gstMoving or gstHHJumping; end else exit(bRes); jmpLJump: begin - if not TestCollisionYwithGear(Gear, -1) then + if TestCollisionYwithGear(Gear, -1) <> 0 then if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then + or (TestCollisionYwithGear(Gear, -1) <> 0)) then begin Gear^.dY:= -_0_15; Gear^.dX:= SignAs(_0_15, Gear^.dX); @@ -367,9 +367,9 @@ inc(GoInfo.Ticks); Gear^.dY:= Gear^.dY + cGravity; if Gear^.dY > _0_4 then exit(bRes); - if (Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, -1) then Gear^.dY:= _0; + if (Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY:= _0; Gear^.Y:= Gear^.Y + Gear^.dY; - if (not Gear^.dY.isNegative)and TestCollisionYwithGear(Gear, 1) then + if (not Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, 1) <> 0) then begin Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); Gear^.dY:= _0; @@ -417,7 +417,7 @@ end; Gear^.Y:= Gear^.Y + Gear^.dY; if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix); - if TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) <> 0 then begin inc(GoInfo.Ticks, 410); Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping); @@ -432,17 +432,17 @@ if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then begin if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; end; if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then @@ -450,25 +450,25 @@ Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX)); inc(GoInfo.Ticks, cHHStepTicks) end; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y + _1; - if not TestCollisionYwithGear(Gear, 1) then + if TestCollisionYwithGear(Gear, 1) = 0 then begin Gear^.Y:= Gear^.Y - _6; Gear^.dY:= _0; diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uAmmos.pas Sat Oct 08 16:54:56 2011 +0200 @@ -339,7 +339,8 @@ CurWeapon:= GetAmmoEntry(Hedgehog); if (CurWeapon^.Count = 0) then - SwitchToFirstLegalAmmo(Hedgehog); + SwitchToFirstLegalAmmo(Hedgehog) + else if CurWeapon^.AmmoType = amNothing then Hedgehog.CurAmmoType:= amNothing; CurWeapon:= GetAmmoEntry(Hedgehog); diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uCollisions.pas --- a/hedgewars/uCollisions.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uCollisions.pas Sat Oct 08 16:54:56 2011 +0200 @@ -39,7 +39,7 @@ function CheckGearsCollision(Gear: PGear): PGearArray; function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean; -function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean; +function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean; function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; @@ -50,7 +50,8 @@ function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; -function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean; +function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; +function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean; implementation uses uConsts, uLandGraphics, uVariables, uDebug, uGears; @@ -156,7 +157,7 @@ TestCollisionXwithGear:= false end; -function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean; +function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word; var x, y, i: LongInt; TestWord: LongWord; begin @@ -180,11 +181,11 @@ i:= x + Gear^.Radius * 2 - 2; repeat if (x and LAND_WIDTH_MASK) = 0 then - if Land[y, x] > TestWord then exit(true); + if Land[y, x] > TestWord then exit(Land[y, x]); inc(x) until (x > i); end; -TestCollisionYwithGear:= false +TestCollisionYwithGear:= 0 end; function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean; @@ -343,14 +344,48 @@ begin Gear^.X:= Gear^.X + int2hwFloat(ShiftX); Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); -if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) +if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0 else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); Gear^.X:= Gear^.X - int2hwFloat(ShiftX); Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) end; +function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; +var x, y: LongInt; + TestWord: LongWord; +begin +if landOnly then + TestWord:= 255 +else + TestWord:= 0; -function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; +if x1 > x2 then +begin + x := x1; + x1 := x2; + x2 := x; +end; + +if y1 > y2 then +begin + y := y1; + y1 := y2; + y2 := y; +end; + +if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then + exit(true); + +for y := y1 to y2 do + for x := x1 to x2 do + if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) + and (Land[y, x] > TestWord) then + exit(true); + +TestRectancleForObstacle:= false +end; + +function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; var ldx, ldy, rdx, rdy: LongInt; i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt; tmpx, tmpy: LongWord; diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uCommandHandlers.pas --- a/hedgewars/uCommandHandlers.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uCommandHandlers.pas Sat Oct 08 16:54:56 2011 +0200 @@ -451,11 +451,13 @@ procedure chSetMap(var s: shortstring); begin if isDeveloperMode then -begin -UserPathz[ptMapCurrent]:= UserPathz[ptMaps] + '/' + s; -Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s; -InitStepsFlags:= InitStepsFlags or cifMap -end + begin + UserPathz[ptMapCurrent]:= UserPathz[ptMaps] + '/' + s; + Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s; + InitStepsFlags:= InitStepsFlags or cifMap + end; + +ScriptLoad(s) end; procedure chSetTheme(var s: shortstring); diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uConsts.pas Sat Oct 08 16:54:56 2011 +0200 @@ -89,10 +89,12 @@ // To allow these to layer, going to treat them as masks. The bottom byte is reserved for objects // TODO - set lfBasic for all solid land, ensure all uses of the flags can handle multiple flag bits +// lfObject and lfBasic are only to be different *graphically* in all other ways they should be treated the same lfBasic = $8000; // white lfIndestructible = $4000; // red - lfObject = $2000; // no idea - lfDamaged = $1000; // no idea + lfObject = $2000; + lfDamaged = $1000; // + lfIce = $0800; // blue cMaxPower = 1500; cMaxAngle = 2048; diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uFloat.pas diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uGame.pas --- a/hedgewars/uGame.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uGame.pas Sat Oct 08 16:54:56 2011 +0200 @@ -72,7 +72,7 @@ SetBinds(CurrentTeam^.Binds); //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos isSoundEnabled:= isSEBackup; - if isSoundEnabled then playMusic; + PlayMusic; GameType:= gmtLocal; AddVisualGear(0, 0, vgtTeamHealthSorter); AddVisualGear(0, 0, vgtSmoothWindBar); diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uGears.pas --- a/hedgewars/uGears.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uGears.pas Sat Oct 08 16:54:56 2011 +0200 @@ -43,6 +43,8 @@ function GetAmmo: TAmmoType; function GetUtility: TAmmoType; procedure ResurrectHedgehog(gear: PGear); +procedure HideHog(HH: PHedgehog); +procedure RestoreHog(HH: PHedgehog); procedure ProcessGears; procedure EndTurnCleanup; procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource); @@ -222,6 +224,7 @@ gear^.SoundChannel:= -1; gear^.ImpactSound:= sndNone; gear^.nImpactSounds:= 0; +gear^.Density:= _1; // Define ammo association, if any. gear^.AmmoType:= GearKindAmmoTypeMap[Kind]; if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then gear^.Z:= cHHZ+1 @@ -599,13 +602,16 @@ Gear^.IntersectGear^.IntersectGear:= nil; end else if Gear^.Kind = gtHedgehog then - if (CurAmmoGear <> nil) and (CurrentHedgehog^.Gear = Gear) then + (* + This behaviour dates back to revision 4, and I accidentally encountered it with TARDIS. I don't think it must apply to any modern weapon, since if it was actually hit, the best the gear could do would be to destroy itself immediately, and you'd still end up with two graves. I believe it should be removed + if (CurAmmoGear <> nil) and (CurrentHedgehog^.Gear = Gear) then begin + AttackBar:= 0; Gear^.Message:= gmDestroy; CurAmmoGear^.Message:= gmDestroy; exit end - else + else*) begin if (hwRound(Gear^.Y) >= cWaterLine) then begin @@ -618,6 +624,7 @@ team:= Gear^.Hedgehog^.Team; if CurrentHedgehog^.Gear = Gear then begin + AttackBar:= 0; FreeActionsList; // to avoid ThinkThread on drawned gear if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (CurrentHedgehog^.MultiShootAttacks > 0) then OnUsedAmmo(CurrentHedgehog^); end; @@ -991,7 +998,10 @@ if ((GameTicks and $FFFF) = $FFFF) then begin if (not CurrentTeam^.ExtDriven) then - SendIPCTimeInc; + begin + SendIPC('#'); + AddFileLog('hiTicks increment message sent') + end; if (not CurrentTeam^.ExtDriven) or CurrentTeam^.hasGone then inc(hiTicks) // we do not recieve a message for this @@ -1231,11 +1241,8 @@ cArtillery:= true; if not hasBorder and ((Theme = 'Snow') or (Theme = 'Christmas')) then - begin for i:= 0 to Pred(vobCount*2) do AddGear(GetRandom(LAND_WIDTH+1024)-512, LAND_HEIGHT - GetRandom(LAND_HEIGHT div 2), gtFlake, 0, _0, _0, 0); - //disableLandBack:= true - end end; procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord); @@ -1480,11 +1487,11 @@ if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then begin if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) - or TestCollisionYwithGear(Gear, -1)) then Gear^.Y:= Gear^.Y - _1; + or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1; end; if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then FollowGear:= Gear @@ -1650,6 +1657,7 @@ procedure ResurrectHedgehog(gear: PGear); var tempTeam : PTeam; begin + AttackBar:= 0; gear^.dX := _0; gear^.dY := _0; gear^.Damage := 0; @@ -1747,7 +1755,6 @@ if (t > 0) then begin t:= GetRandom(t); - AddFileLog(inttostr(t)+' --------------'); while t >= 0 do begin inc(i); diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uGearsRender.pas --- a/hedgewars/uGearsRender.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uGearsRender.pas Sat Oct 08 16:54:56 2011 +0200 @@ -328,7 +328,7 @@ hx:= ox + 8 * sign; hy:= oy - 2; aangle:= Gear^.Angle * 180 / cMaxAngle - 90; - if CurAmmoGear <> nil then + if (CurAmmoGear <> nil) and (CurAmmoGear^.Kind <> gtTardis) then begin case CurAmmoGear^.Kind of gtShotgunShot: begin @@ -886,7 +886,10 @@ gtGrenade: DrawRotated(sprBomb, x, y, 0, Gear^.DirAngle); gtSnowball: DrawRotated(sprSnowball, x, y, 0, Gear^.DirAngle); gtGasBomb: DrawRotated(sprCheese, x, y, 0, Gear^.DirAngle); - gtMolotov: DrawRotated(sprMolotov, x, y, 0, Gear^.DirAngle); + + gtMolotov: if (Gear^.State and gstDrowning) = 0 then + DrawRotatedF(sprMolotov, x, y, (RealTicks div 125) mod 8, hwSign(Gear^.dX), Gear^.DirAngle * hwSign(Gear^.dX)) + else DrawSprite(sprMolotov, x, y, 8); gtRCPlane: begin if (Gear^.Tag = -1) then diff -r 531f64292489 -r 5a4ea2c7b9df hedgewars/uIO.pas --- a/hedgewars/uIO.pas Sat Oct 08 16:45:52 2011 +0200 +++ b/hedgewars/uIO.pas Sat Oct 08 16:54:56 2011 +0200 @@ -29,7 +29,6 @@ procedure SendIPCXY(cmd: char; X, Y: SmallInt); procedure SendIPCRaw(p: pointer; len: Longword); procedure SendIPCAndWaitReply(s: shortstring); -procedure SendIPCTimeInc; procedure SendKeepAliveMessage(Lag: Longword); procedure LoadRecordFromFile(fileName: shortstring); procedure SendStat(sit: TStatInfoType; s: shortstring); @@ -246,13 +245,6 @@ SendIPC(s) end; -procedure SendIPCTimeInc; -const timeinc: shortstring = '#'; -begin -AddFileLog('[IPC out]