26 #include <QTextStream>
27 #include <QGridLayout>
28 #include <QVBoxLayout>
29 #include <QSpacerItem>
30 #include <QHeaderView>
32 #include <QPushButton>
33 #include <QButtonGroup>
34 #include <QRadioButton>
40 #include <QApplication>
41 #include <QDesktopWidget>
43 #include <KGlobalSettings>
44 #include <KConfigGroup>
45 #include <KIntNumInput>
58 myGameList (gameList),
59 defaultGame (gameIndex),
60 defaultLevel (requestedLevel),
61 systemDir (pSystemDir),
74 selectedGame = defaultGame;
78 while (exec() == QDialog::Accepted) {
79 selectedGame = slGameIndex;
81 if (myGameList.
at (selectedGame)->owner ==
SYSTEM) {
87 i18n (
"Sorry, you can only save or move "
88 "into one of your own games."));
93 i18n (
"Sorry, you can only delete a level "
94 "from one of your own games."));
99 i18n (
"Sorry, you can only edit the game "
100 "information on your own games."));
108 selectedLevel = number->
value();
109 if ((selectedLevel > myGameList.
at (selectedGame)->nLevels) &&
113 i18n (
"There is no level %1 in \"%2\", "
114 "so you cannot play or edit it.",
116 myGameList.
at (selectedGame)->name));
122 return (selectedLevel > 0);
125 void KGrSLDialog::setupWidgets()
127 int margin = marginHint();
128 int spacing = spacingHint();
131 setCaption (i18n (
"Select Game"));
132 setButtons (KDialog::Ok | KDialog::Cancel | KDialog::Help);
133 setDefaultButton (KDialog::Ok);
140 (i18n (
"<html><b>Please select a game:</b></html>"), dad);
147 i18n (
"Name of Game") <<
157 gameN =
new QLabel (
"", dad);
164 (21, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
165 hboxLayout1->
addItem (spacerItem1);
167 gameD =
new QLabel (
"", dad);
180 dad-> setWindowTitle (i18n (
"Select Game"));
182 (
"<b>" + i18n (
"Level 1 of the selected game is:") +
"</b>", dad);
186 dad-> setWindowTitle (i18n (
"Select Game/Level"));
188 (
"<b>" + i18n (
"Please select a level:") +
"</b>", dad);
206 grid->
addWidget (numberPair, 1, 1, 1, 3);
207 numberL =
new QLabel (i18n (
"Level number:"), numberPair);
208 display =
new KIntSpinBox (numberPair);
209 display->setRange (1, 150);
213 levelNH =
new QPushButton (i18n (
"Edit Level Name && Hint"), dad);
216 slName =
new QLabel (
"", dad);
223 cellSize = (cellSize < 4) ? 4 : cellSize;
224 thumbNail-> setFixedWidth ((
FIELDWIDTH * cellSize) + 2);
225 thumbNail-> setFixedHeight ((
FIELDHEIGHT * cellSize) + 2);
239 number-> setTracking (
true);
242 slSetGames (defaultGame);
248 OKText = i18n (
"Start Game");
251 display->setEnabled (
false);
257 OKText = i18n (
"Play Level");
260 OKText = i18n (
"Replay Level");
263 OKText = i18n (
"Show Solution");
266 OKText = i18n (
"Edit Level");
269 OKText = i18n (
"Save New");
272 OKText = i18n (
"Save Change");
275 OKText = i18n (
"Delete Level");
278 OKText = i18n (
"Move To...");
281 OKText = i18n (
"Edit Game Info");
284 display->setEnabled (
false);
293 setButtonGuiItem (KDialog::Ok, KGuiItem (OKText));
297 slShowLevel (number->
value());
299 if (display->isEnabled()) {
301 display->selectAll();
310 connect (games, SIGNAL (itemSelectionChanged()),
this, SLOT (slGame()));
312 connect (display, SIGNAL (valueChanged(
QString)),
313 this, SLOT (slUpdate(
QString)));
315 connect (number, SIGNAL(valueChanged(
int)),
this, SLOT(slShowLevel(
int)));
321 connect (levelNH, SIGNAL (clicked()),
329 connect (games, SIGNAL(itemSelectionChanged()),
this, SLOT(slPaintLevel()));
330 connect (number, SIGNAL (sliderReleased()),
this, SLOT (slPaintLevel()));
332 connect (
this, SIGNAL (helpClicked()),
this, SLOT (slotHelp()));
339 void KGrSLDialog::slSetGames (
int cIndex)
342 int imax = myGameList.
count();
350 sortOrder1 <<
'N' <<
'C' <<
'T';
351 sortOrder2 <<
'T' <<
'K';
353 foreach (
char sortItem1, sortOrder1) {
354 foreach (
char sortItem2, sortOrder2) {
355 for (i = 0; i < imax; i++) {
356 if ((myGameList.
at (i)->skill == sortItem1) &&
357 (myGameList.
at (i)->rules == sortItem2)) {
360 << myGameList.
at (i)->name
361 << ((myGameList.
at (i)->rules ==
'K') ?
362 i18nc (
"Rules",
"KGoldrunner") :
363 i18nc (
"Rules",
"Traditional"))
365 << ((myGameList.
at (i)->skill ==
'T') ?
366 i18nc (
"Skill Level",
"Tutorial") :
367 ((myGameList.
at (i)->skill ==
'N') ?
368 i18nc (
"Skill Level",
"Normal") :
369 i18nc (
"Skill Level",
"Championship")));
373 if (slGameIndex < 0) {
385 if (slGameIndex < 0) {
402 void KGrSLDialog::slGame()
405 if (slGameIndex < 0) {
418 if (myGameList.
at (n)->nLevels > 0) {
420 display->setMaximum (myGameList.
at (n)->nLevels);
424 display->setMaximum (1);
427 KConfigGroup gameGroup (KGlobal::config(),
"KDEGame");
444 lev = gameGroup.readEntry (
"Level_" + myGameList.
at (n)->prefix, 1);
451 if ((n == N) && (slAction !=
SL_CREATE)) {
458 display->setMaximum (myGameList.
at (n)->nLevels + 1);
467 slShowLevel (number->
value());
469 int levCnt = myGameList.
at (n)->nLevels;
470 if (myGameList.
at (n)->rules ==
'K')
471 gameD->
setText (i18np (
"1 level, uses KGoldrunner rules.",
472 "%1 levels, uses KGoldrunner rules.", levCnt));
474 gameD->
setText (i18np (
"1 level, uses Traditional rules.",
475 "%1 levels, uses Traditional rules.", levCnt));
476 gameN->
setText (myGameList.
at (n)->name);
478 if (myGameList.
at (n)->about.isEmpty()) {
479 s = i18n (
"Sorry, there is no further information about this game.");
482 s = (i18n (myGameList.
at (n)->about.constData()));
487 void KGrSLDialog::slShowLevel (
int i)
490 display->setValue (i);
493 void KGrSLDialog::slUpdate (
const QString & text)
498 int n = s.
toInt (&ok);
505 i18n (
"This level number is not valid. It can not be used."));
508 void KGrSLDialog::slPaintLevel()
511 if (slGameIndex < 0) {
517 thumbNail->
setLevelData (dir, myGameList.
at (slGameIndex)->prefix,
518 number->
value(), slName);
522 void KGrSLDialog::slotHelp()
526 i18n (
"The main button at the bottom echoes the "
527 "menu action you selected. Click it after choosing "
528 "a game and level - or use \"Cancel\".");
531 s += i18n (
"\n\nIf this is your first time in KGoldrunner, select the "
532 "tutorial game, which gives you hints as you go.\n\n"
533 "Otherwise, just click on the name of a game in the table, "
534 "then, to start at level 001, click on the main button at the "
535 "bottom. Play begins when you move the mouse or press a key.");
540 s += i18n (
"\n\nYou can select System levels for editing (or "
541 "copying), but you must save the result in a game you have "
542 "created. Use the left mouse-button as a paintbrush and the "
543 "editor toolbar buttons as a palette. Use the 'Erase' button "
544 "or the right mouse-button to erase. You can drag the mouse "
545 "with a button held down and paint or erase multiple squares.");
548 s += i18n(
"\n\nYou can add a name and hint to your new level here, "
549 "but you must save the level you have created into one of "
550 "your own games. By default your new level will go at the "
551 "end of your game, but you can also select a level number and "
552 "save into the middle of your game.");
555 s += i18n(
"\n\nYou can create or edit a name and hint here, before "
556 "saving. If you change the game or level, you can do a copy "
557 "or \"Save As\", but you must always save into one of your "
558 "own games. If you save a level into the middle of a series, "
559 "the other levels are automatically re-numbered.");
562 s += i18n (
"\n\nYou can only delete levels from one of your own "
563 "games. If you delete a level from the middle of a series, "
564 "the other levels are automatically re-numbered.");
567 s += i18n (
"\n\nTo move (re-number) a level, you must first select "
568 "it by using \"Edit Any Level...\", then you can use "
569 "\"Move Level...\" to move it to a new number or even a "
570 "different game. Other levels are automatically re-numbered as "
571 "required. You can only move levels within your own games.");
574 s += i18n (
"\n\nWhen editing game info you only need to choose a "
575 "game, then you can go to a dialog where you edit the "
576 "details of the game.");
581 s += i18n (
"\n\nClick on the table to choose a game. "
582 "In the table and below it you can see more information about the "
583 "selected game, including how many levels there are, how difficult "
584 "the game is and what "
585 "rules the enemies follow (see the KGoldrunner Handbook).\n\n"
587 "a level number by typing it or using the spin box or scroll bar. "
588 "As you vary the game or level, the thumbnail area shows a "
589 "preview of your choice.");
600 const int internalId)
603 mInternalId = internalId;
613 mInternalId = internalId;
685 obj = levelLayout.
at (j*FIELDWIDTH + i);
708 p.
drawLine (i*n+fw, j*n+fw, i*n+(n-1)+fw, j*n+fw);
714 for (
int k = 1; k < n; k++) {
715 p.
drawLine (i*n+fw, j*n+k+fw, i*n+(n-1)+fw, j*n+k+fw);
723 p.
drawLine (i*n+k, j*n+k, i*n+k, j*n+(n-1)+fw);
724 p.
drawLine (i*n+k+1, j*n+k, i*n+k+1, j*n+(n-1)+fw);
734 #include "kgrselector.moc"
The KGrGameIO class handles I/O for text-files containing KGoldrunner games and levels.
KGrThumbNail(QWidget *parent=0)
void setRange(int min, int max)
void setFrameShape(Shape)
const T & at(int i) const
KGrGameListItem(const QStringList &data, const int internalId=-1)
QByteArray layout
Codes for the level layout (mandatory).
void setFrameStyle(int style)
void drawLine(const QLineF &line)
IOStatus fetchLevelData(const QString &dir, const QString &prefix, const int level, KGrLevelData &d, QString &filePath)
Find and read data for a level of a game, into a KGrLevelData structure.
void setNamedColor(const QString &name)
void setBold(bool enable)
void drawRect(const QRectF &rectangle)
int count(const T &value) const
void setPen(const QColor &color)
int toInt(bool *ok, int base) const
virtual void addItem(QLayoutItem *item)
static QColor ladderColor
KGrSLDialog(int action, int requestedLevel, int gameIndex, QList< KGrGameData * > &gameList, const QString &pSystemDir, const QString &pUserDir, QWidget *parent=0)
static void information(QWidget *parent, const QString &caption, const QString &text, const QString &dontShowAgain=QString())
KGrLevelData structure: contains attributes of a KGoldrunner level.
void setLevelData(const QString &dir, const QString &prefix, int level, QLabel *sln)
void setText(const QString &)
void setColor(const QColor &color)
void setMargin(int margin)
void paintEvent(QPaintEvent *event)
IOStatus
Return values from I/O operations.
static QColor backgroundColor
QDesktopWidget * desktop()
QString & setNum(short n, int base)
bool selectLevel(int &selectedGame, int &selectedLevel)
void setReadOnly(bool ro)
void setRootIsDecorated(bool show)
void setText(const QString &text)
void setId(const int internalId)
void setSpacing(int spacing)
void addLayout(QLayout *layout, int stretch)
QByteArray name
Level name (optional).