Diffstat (limited to 'noncore/games/wordgame/wordgame.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/wordgame/wordgame.cpp | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index ca4352d..16d37b3 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -56,12 +56,19 @@ | |||
56 | enum RuleEffects { | 56 | enum RuleEffects { |
57 | Multiplier=15, | 57 | Multiplier=15, |
58 | MultiplyAll=64, | 58 | MultiplyAll=64, |
59 | Start=128 | 59 | Start=128 |
60 | }; | 60 | }; |
61 | 61 | ||
62 | static int tile_smallw = 16; | ||
63 | static int tile_smallh = 16; | ||
64 | static int tile_bigw = 22; | ||
65 | static int tile_bigh = 22; | ||
66 | static int tile_stweak = -2; | ||
67 | static int tile_btweak = -1; | ||
68 | |||
62 | static const int rack_tiles=7; | 69 | static const int rack_tiles=7; |
63 | 70 | ||
64 | const char* sampleWGR= | 71 | const char* sampleWGR= |
65 | "wordgame_shapes\n" | 72 | "wordgame_shapes\n" |
66 | "15 15\n" | 73 | "15 15\n" |
67 | "400001040100004\n" | 74 | "400001040100004\n" |
@@ -108,12 +115,21 @@ const char* sampleWGR= | |||
108 | "11 e 1\n" | 115 | "11 e 1\n" |
109 | "0\n"; | 116 | "0\n"; |
110 | 117 | ||
111 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : | 118 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : |
112 | QMainWindow(parent, name, fl) | 119 | QMainWindow(parent, name, fl) |
113 | { | 120 | { |
121 | if ( qApp->desktop()->width() < 240 ) { | ||
122 | tile_smallw = 10; | ||
123 | tile_smallh = 10; | ||
124 | tile_bigw = 16; | ||
125 | tile_bigh = 16; | ||
126 | tile_stweak = 0; | ||
127 | tile_btweak = 0; | ||
128 | } | ||
129 | |||
114 | setIcon( Resource::loadPixmap( "wordgame" ) ); | 130 | setIcon( Resource::loadPixmap( "wordgame" ) ); |
115 | setCaption( tr("Word Game") ); | 131 | setCaption( tr("Word Game") ); |
116 | 132 | ||
117 | setToolBarsMovable( FALSE ); | 133 | setToolBarsMovable( FALSE ); |
118 | vbox = new QVBox(this); | 134 | vbox = new QVBox(this); |
119 | 135 | ||
@@ -244,12 +260,13 @@ void WordGame::startGame() | |||
244 | } | 260 | } |
245 | 261 | ||
246 | void WordGame::startGame(const QStringList& playerlist) | 262 | void WordGame::startGame(const QStringList& playerlist) |
247 | { | 263 | { |
248 | toolbar->show(); | 264 | toolbar->show(); |
249 | racks = new QWidgetStack(vbox); | 265 | racks = new QWidgetStack(vbox); |
266 | racks->setFixedHeight(TileItem::bigHeight()+2); | ||
250 | namelist.clear(); | 267 | namelist.clear(); |
251 | nplayers=0; | 268 | nplayers=0; |
252 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) | 269 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) |
253 | addPlayer(*it); | 270 | addPlayer(*it); |
254 | scoreinfo->init(namelist); | 271 | scoreinfo->init(namelist); |
255 | 272 | ||
@@ -280,13 +297,12 @@ bool WordGame::loadRules(const QString &name) | |||
280 | int htiles,vtiles; | 297 | int htiles,vtiles; |
281 | ts >> htiles >> vtiles; | 298 | ts >> htiles >> vtiles; |
282 | 299 | ||
283 | if ( htiles < 3 || vtiles < 3 ) | 300 | if ( htiles < 3 || vtiles < 3 ) |
284 | return FALSE; | 301 | return FALSE; |
285 | 302 | ||
286 | QPixmap bgshapes = Resource::loadPixmap(shapepixmap); | ||
287 | QString rule_shapes; | 303 | QString rule_shapes; |
288 | for (int i=0; i<vtiles; i++) { | 304 | for (int i=0; i<vtiles; i++) { |
289 | QString line; | 305 | QString line; |
290 | ts >> line; | 306 | ts >> line; |
291 | rule_shapes += line; | 307 | rule_shapes += line; |
292 | } | 308 | } |
@@ -294,12 +310,18 @@ bool WordGame::loadRules(const QString &name) | |||
294 | int re=0,e; | 310 | int re=0,e; |
295 | ts >> e; | 311 | ts >> e; |
296 | while ( e && re < 10 ) { | 312 | while ( e && re < 10 ) { |
297 | rule_effects[re] = e; | 313 | rule_effects[re] = e; |
298 | if ( re++ < 10 ) ts >> e; | 314 | if ( re++ < 10 ) ts >> e; |
299 | } | 315 | } |
316 | |||
317 | QImage shim = Resource::loadImage(shapepixmap); | ||
318 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); | ||
319 | QPixmap bgshapes; | ||
320 | bgshapes.convertFromImage(shim); | ||
321 | |||
300 | rule_effects[re++] = 100; // default bonus | 322 | rule_effects[re++] = 100; // default bonus |
301 | board = new Board(bgshapes, htiles, vtiles, vbox); | 323 | board = new Board(bgshapes, htiles, vtiles, vbox); |
302 | board->setRules(rule_shapes, rule_effects); | 324 | board->setRules(rule_shapes, rule_effects); |
303 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); | 325 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); |
304 | 326 | ||
305 | bag = new Bag; | 327 | bag = new Bag; |
@@ -678,28 +700,28 @@ qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); | |||
678 | best_start = current; | 700 | best_start = current; |
679 | } | 701 | } |
680 | } | 702 | } |
681 | 703 | ||
682 | int TileItem::smallWidth() | 704 | int TileItem::smallWidth() |
683 | { | 705 | { |
684 | return 16; | 706 | return tile_smallw; |
685 | } | 707 | } |
686 | 708 | ||
687 | int TileItem::smallHeight() | 709 | int TileItem::smallHeight() |
688 | { | 710 | { |
689 | return 16; | 711 | return tile_smallh; |
690 | } | 712 | } |
691 | 713 | ||
692 | int TileItem::bigWidth() | 714 | int TileItem::bigWidth() |
693 | { | 715 | { |
694 | return 22; | 716 | return tile_bigw; |
695 | } | 717 | } |
696 | 718 | ||
697 | int TileItem::bigHeight() | 719 | int TileItem::bigHeight() |
698 | { | 720 | { |
699 | return 22; | 721 | return tile_bigh; |
700 | } | 722 | } |
701 | 723 | ||
702 | void TileItem::setState( State state ) | 724 | void TileItem::setState( State state ) |
703 | { | 725 | { |
704 | hide(); | 726 | hide(); |
705 | s = state; | 727 | s = state; |
@@ -717,42 +739,53 @@ void TileItem::setBig(bool b) | |||
717 | { | 739 | { |
718 | big = b; | 740 | big = b; |
719 | } | 741 | } |
720 | 742 | ||
721 | void TileItem::drawShape(QPainter& p) | 743 | void TileItem::drawShape(QPainter& p) |
722 | { | 744 | { |
723 | static QFont value_font("heletica",8); | 745 | static QFont *value_font=0; |
724 | static QFont big_font("smoothtimes",17); | 746 | static QFont *big_font=0; |
725 | static QFont small_font("smoothtimes",10); | 747 | static QFont *small_font=0; |
748 | if ( !value_font ) { | ||
749 | value_font = new QFont("helvetica",8); | ||
750 | if ( TileItem::bigWidth() < 20 ) { | ||
751 | big_font = new QFont("helvetica",12); | ||
752 | small_font = new QFont("helvetica",8); | ||
753 | } else { | ||
754 | big_font = new QFont("smoothtimes",17); | ||
755 | small_font = new QFont("smoothtimes",10); | ||
756 | } | ||
757 | } | ||
726 | 758 | ||
727 | QRect area(x(),y(),width(),height()); | 759 | QRect area(x(),y(),width(),height()); |
728 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); | 760 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); |
729 | p.drawRect(area); | 761 | p.drawRect(area); |
730 | if ( big ) { | 762 | if ( big ) { |
731 | p.setFont(value_font); | 763 | p.setFont(*value_font); |
732 | QString n = QString::number(t.value()); | 764 | QString n = QString::number(t.value()); |
733 | int w = p.fontMetrics().width('1'); | 765 | int w = p.fontMetrics().width('1'); |
734 | int h = p.fontMetrics().height(); | 766 | int h = p.fontMetrics().height(); |
735 | w *= n.length(); | 767 | w *= n.length(); |
736 | QRect valuearea(x()+width()-w-2,y()+height()-h+1,w,h); | 768 | QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); |
737 | p.drawText(valuearea,AlignCenter,n); | 769 | p.drawText(valuearea,AlignCenter,n); |
738 | p.setFont(big_font); | 770 | p.setFont(*big_font); |
739 | area = QRect(x(),y(),width()-2,height()-1); | 771 | area = QRect(x(),y()+tile_btweak,width()-4,height()-1); |
740 | } else { | 772 | } else { |
741 | p.setFont(small_font); | 773 | p.setFont(*small_font); |
742 | area = QRect(x(),y()+2,width(),height()-2); | 774 | area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); |
743 | } | 775 | } |
744 | if ( t.value() == 0 ) | 776 | if ( t.value() == 0 ) |
745 | p.setPen(darkGray); | 777 | p.setPen(darkGray); |
746 | p.drawText(area,AlignCenter,t.text().upper()); | 778 | p.drawText(area,AlignCenter,t.text().upper()); |
747 | } | 779 | } |
748 | 780 | ||
749 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : | 781 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : |
750 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), | 782 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), |
751 | parent) | 783 | parent) |
752 | { | 784 | { |
785 | setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); | ||
753 | grid = new TileItem*[w*h]; | 786 | grid = new TileItem*[w*h]; |
754 | memset(grid,0,w*h*sizeof(TileItem*)); | 787 | memset(grid,0,w*h*sizeof(TileItem*)); |
755 | setFrameStyle(0); | 788 | setFrameStyle(0); |
756 | setHScrollBarMode(AlwaysOff); | 789 | setHScrollBarMode(AlwaysOff); |
757 | setVScrollBarMode(AlwaysOff); | 790 | setVScrollBarMode(AlwaysOff); |
758 | current_rack = 0; | 791 | current_rack = 0; |
@@ -761,12 +794,17 @@ Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : | |||
761 | 794 | ||
762 | Board::~Board() | 795 | Board::~Board() |
763 | { | 796 | { |
764 | delete canvas(); | 797 | delete canvas(); |
765 | } | 798 | } |
766 | 799 | ||
800 | QSize Board::sizeHint() const | ||
801 | { | ||
802 | return QSize(canvas()->width(),canvas()->height()); | ||
803 | } | ||
804 | |||
767 | void Board::writeConfig(Config& cfg) | 805 | void Board::writeConfig(Config& cfg) |
768 | { | 806 | { |
769 | QStringList t; | 807 | QStringList t; |
770 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); | 808 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); |
771 | for (int i=0; i<n; i++) | 809 | for (int i=0; i<n; i++) |
772 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); | 810 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); |
@@ -1178,12 +1216,17 @@ Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( | |||
1178 | Rack::~Rack() | 1216 | Rack::~Rack() |
1179 | { | 1217 | { |
1180 | clear(); | 1218 | clear(); |
1181 | delete canvas(); | 1219 | delete canvas(); |
1182 | } | 1220 | } |
1183 | 1221 | ||
1222 | QSize Rack::sizeHint() const | ||
1223 | { | ||
1224 | return QSize(-1,TileItem::bigHeight()+2); | ||
1225 | } | ||
1226 | |||
1184 | void Rack::clear() | 1227 | void Rack::clear() |
1185 | { | 1228 | { |
1186 | for (int i=0; i<n; i++) | 1229 | for (int i=0; i<n; i++) |
1187 | delete item[i]; | 1230 | delete item[i]; |
1188 | n=0; | 1231 | n=0; |
1189 | } | 1232 | } |