22
22
Functions for the in-game console.
23
23
*/
24
24
25
- #include < QtCore/QString>
26
- #include < QtGui/QPixmap>
27
- #include < QtGui/QPainter>
28
- #include " lib/framework/wzapp.h"
29
- // **NOTE: Qt headers must be before platform specific headers!
30
-
31
25
#include " lib/framework/frame.h"
32
26
#include " lib/framework/input.h"
33
27
#include " lib/gamelib/gtime.h"
@@ -61,11 +55,11 @@ struct CONSOLE
61
55
/* Definition of a message */
62
56
struct CONSOLE_MESSAGE
63
57
{
64
- QPixmap *cache; // Text of the message
65
- QString text; // Text of the message
58
+ char text[MAX_CONSOLE_STRING_LENGTH]; // Text of the message
66
59
UDWORD timeAdded; // When was it added to our list?
67
- int id;
68
- int player; // Player who sent this message or SYSTEM_MESSAGE
60
+ UDWORD JustifyType;
61
+ UDWORD id;
62
+ SDWORD player; // Player who sent this message or SYSTEM_MESSAGE
69
63
CONSOLE_MESSAGE * psNext;
70
64
};
71
65
@@ -122,12 +116,14 @@ static UDWORD consoleVisibleLines;
122
116
/* * Whether new messages are allowed to be added */
123
117
static int allowNewMessages;
124
118
119
+ /* * What's the default justification? */
120
+ static CONSOLE_TEXT_JUSTIFICATION defJustification;
121
+
125
122
static UDWORD messageId; // unique ID
126
123
127
124
// / Global string for new console messages.
128
125
char ConsoleString[MAX_CONSOLE_TMP_STRING_LENGTH];
129
126
130
- static PIELIGHT getConsoleTextColor (SDWORD player);
131
127
132
128
/* *
133
129
Specify how long messages will stay on screen.
@@ -137,28 +133,12 @@ static void setConsoleMessageDuration(UDWORD time)
137
133
messageDuration = time ;
138
134
}
139
135
140
- void consoleInit ()
141
- {
142
- int i;
143
-
144
- for (i = 0 ; i < MAX_CONSOLE_MESSAGES; i++)
145
- {
146
- consoleStorage[i].cache = NULL ;
147
- }
148
- }
149
-
150
136
/* * Sets the system up */
151
137
void initConsoleMessages ( void )
152
138
{
153
- int i, TextLineSize = iV_GetTextLineSize ();
139
+ int TextLineSize = iV_GetTextLineSize ();
154
140
messageIndex = 0 ;
155
141
156
- for (i = 0 ; i < MAX_CONSOLE_MESSAGES; i++)
157
- {
158
- delete consoleStorage[i].cache ;
159
- consoleStorage[i].cache = NULL ;
160
- }
161
-
162
142
/* Console can extend to half screen height */
163
143
if (TextLineSize)
164
144
{
@@ -195,6 +175,9 @@ void initConsoleMessages( void )
195
175
/* Turn on the console display */
196
176
enableConsoleDisplay (true );
197
177
178
+ /* Set left justification as default */
179
+ setDefaultConsoleJust (LEFT_JUSTIFY);
180
+
198
181
/* Set up the console size and postion
199
182
x,y,width */
200
183
setConsoleSizePos (16 , 16 , pie_GetVideoBufferWidth ()-32 );
@@ -232,6 +215,7 @@ void toggleConsoleDrop( void )
232
215
bool addConsoleMessage (const char *messageText, CONSOLE_TEXT_JUSTIFICATION jusType,
233
216
SDWORD player)
234
217
{
218
+ int textLength;
235
219
CONSOLE_MESSAGE *psMessage;
236
220
237
221
/* Just don't add it if there's too many already */
@@ -246,34 +230,49 @@ bool addConsoleMessage(const char *messageText, CONSOLE_TEXT_JUSTIFICATION jusTy
246
230
return false ;
247
231
}
248
232
233
+ /* Is the string too long? */
234
+ textLength = strlen (messageText);
235
+
236
+ ASSERT ( textLength<MAX_CONSOLE_STRING_LENGTH,
237
+ " Attempt to add a message to the console that exceeds MAX_CONSOLE_STRING_LENGTH" );
238
+
239
+ /* Are we using a defualt justification? */
240
+ if (jusType == DEFAULT_JUSTIFY)
241
+ {
242
+ /* Then set it */
243
+ jusType = defJustification;
244
+ }
245
+
249
246
debug (LOG_CONSOLE, " (to player %d): %s" , (int )player, messageText);
250
247
251
248
consoleStorage[messageIndex].player = player;
252
249
253
- /* Draw the text of the message */
254
- PIELIGHT color (getConsoleTextColor (player));
255
- delete consoleStorage[messageIndex].cache ;
256
- consoleStorage[messageIndex].cache = new QPixmap (mainConsole.width , iV_GetTextLineSize ());
257
- consoleStorage[messageIndex].cache ->fill (QColor (16 , 16 , 128 , 128 )); // FIXME, and fix pie_TransBoxFill, to not use hardcoded numbers
258
- consoleStorage[messageIndex].text = QString::fromUtf8 (messageText);
259
- QPainter painter (consoleStorage[messageIndex].cache );
260
- painter.setPen (QColor (color.byte .r , color.byte .g , color.byte .b , color.byte .a ));
261
250
/* Precalculate and store (quicker!) the indent for justified text */
262
- QTextOption opts;
263
251
switch (jusType)
264
252
{
265
- case DEFAULT_JUSTIFY:
253
+ /* Allign to left edge of screen */
266
254
case LEFT_JUSTIFY:
267
- opts. setAlignment (Qt::AlignLeft) ;
255
+ consoleStorage[messageIndex]. JustifyType = FTEXT_LEFTJUSTIFY ;
268
256
break ;
257
+
258
+ /* Allign to right edge of screen */
269
259
case RIGHT_JUSTIFY:
270
- opts. setAlignment (Qt::AlignRight) ;
260
+ consoleStorage[messageIndex]. JustifyType = FTEXT_RIGHTJUSTIFY ;
271
261
break ;
262
+
263
+ /* Allign to centre of the screen,NOT TO CENTRE OF CONSOLE!!!!!! */
272
264
case CENTRE_JUSTIFY:
273
- opts.setAlignment (Qt::AlignHCenter);
265
+ consoleStorage[messageIndex].JustifyType = FTEXT_CENTRE;
266
+ break ;
267
+ /* Gone tits up by the looks of it */
268
+ default :
269
+ debug ( LOG_FATAL, " Weirdy type of text justification for console print" );
270
+ abort ();
274
271
break ;
275
272
}
276
- painter.drawText (QRect (0 , 0 , mainConsole.width , iV_GetTextLineSize ()), consoleStorage[messageIndex].text , opts);
273
+
274
+ /* Copy over the text of the message */
275
+ sstrcpy (consoleStorage[messageIndex].text , messageText);
277
276
278
277
/* Set the time when it was added - this might not be needed */
279
278
consoleStorage[messageIndex].timeAdded = gameTime2;
@@ -417,35 +416,35 @@ void flushConsoleMessages( void )
417
416
}
418
417
419
418
/* * Sets console text color depending on message type */
420
- static PIELIGHT getConsoleTextColor (SDWORD player)
419
+ static void setConsoleTextColor (SDWORD player)
421
420
{
422
421
// System messages
423
- if (player == SYSTEM_MESSAGE)
422
+ if (player == SYSTEM_MESSAGE)
424
423
{
425
- return WZCOL_CONS_TEXT_SYSTEM;
424
+ iV_SetTextColour ( WZCOL_CONS_TEXT_SYSTEM) ;
426
425
}
427
426
else if (player == NOTIFY_MESSAGE)
428
427
{
429
- return WZCOL_YELLOW;
428
+ iV_SetTextColour ( WZCOL_YELLOW) ;
430
429
}
431
430
else
432
431
{
433
432
// Don't use friend-foe colors in the lobby
434
- if (bEnemyAllyRadarColor && (GetGameMode () == GS_NORMAL))
433
+ if (bEnemyAllyRadarColor && (GetGameMode () == GS_NORMAL))
435
434
{
436
- if (aiCheckAlliances (player,selectedPlayer))
435
+ if (aiCheckAlliances (player,selectedPlayer))
437
436
{
438
- return WZCOL_CONS_TEXT_USER_ALLY;
437
+ iV_SetTextColour ( WZCOL_CONS_TEXT_USER_ALLY) ;
439
438
}
440
439
else
441
440
{
442
- return WZCOL_CONS_TEXT_USER_ENEMY;
441
+ iV_SetTextColour ( WZCOL_CONS_TEXT_USER_ENEMY) ;
443
442
}
444
443
}
445
444
else
446
445
{
447
446
// Friend-foe is off
448
- return WZCOL_CONS_TEXT_USER;
447
+ iV_SetTextColour ( WZCOL_CONS_TEXT_USER) ;
449
448
}
450
449
}
451
450
}
@@ -515,18 +514,47 @@ static int displayOldMessages(void)
515
514
{
516
515
/* Get the line pitch */
517
516
linePitch = iV_GetTextLineSize ();
517
+
518
+ /* How big a box is necessary? */
519
+ /* GET RID OF THE MAGIC NUMBERS BELOW */
520
+ iV_TransBoxFill (mainConsole.topX - CON_BORDER_WIDTH,mainConsole.topY -mainConsole.textDepth -CON_BORDER_HEIGHT,
521
+ mainConsole.topX +mainConsole.width ,mainConsole.topY +((count)*linePitch)+CON_BORDER_HEIGHT-linePitch);
522
+ }
523
+ /*
524
+ if(count)
525
+ {
526
+ sprintf(buildData,"%s,%s",__TIME__,__DATE__);
527
+
528
+ buildWidth = iV_GetTextWidth(buildData);
529
+
530
+ iV_DrawText(buildData,((mainConsole.topX+mainConsole.width) - buildWidth - 16),
531
+ mainConsole.topY);
518
532
}
533
+ */
519
534
MesY = mainConsole.topY ;
520
535
/* Render what we found */
521
536
for (i=count-1 ; i>0 ; i--)
522
537
{
538
+ /* Set text color depending on message type */
539
+ setConsoleTextColor (consoleStorage[history[i]].player );
540
+
523
541
/* Draw the text string */
524
- WzMainWindow::instance ()->drawPixmap (mainConsole.topX , MesY, consoleStorage[history[i]].cache );
525
- MesY += iV_GetTextLineSize ();
542
+ MesY = iV_DrawFormattedText (consoleStorage[history[i]].text ,
543
+ mainConsole.topX ,
544
+ MesY,
545
+ mainConsole.width ,
546
+ consoleStorage[history[i]].JustifyType );
526
547
}
527
548
549
+ /* Set text color depending on message type */
550
+ setConsoleTextColor (consoleStorage[history[0 ]].player );
551
+
528
552
/* Draw the top one */
529
- WzMainWindow::instance ()->drawPixmap (mainConsole.topX , MesY, consoleStorage[history[0 ]].cache );
553
+ iV_DrawFormattedText (consoleStorage[history[0 ]].text ,
554
+ mainConsole.topX ,
555
+ MesY,
556
+ mainConsole.width ,
557
+ consoleStorage[history[0 ]].JustifyType );
530
558
531
559
/* Return how much to drop the existing console by... Fix this for lines>screenWIDTH */
532
560
if (count)
@@ -587,7 +615,7 @@ void displayConsoleMessages( void )
587
615
psMessage && consoleVisibleLines > 0 && exceed < 4 ; // ho ho ho!!!
588
616
psMessage = psMessage->psNext )
589
617
{
590
- if (iV_GetTextWidth (psMessage->text . toAscii (). constData () ) > mainConsole.width )
618
+ if (iV_GetTextWidth (psMessage->text ) > mainConsole.width )
591
619
{
592
620
++exceed;
593
621
}
@@ -605,6 +633,9 @@ void displayConsoleMessages( void )
605
633
{
606
634
clipDepth = (pie_GetVideoBufferHeight () - linePitch);
607
635
}
636
+
637
+ iV_TransBoxFill (mainConsole.topX - CON_BORDER_WIDTH,mainConsole.topY -mainConsole.textDepth -CON_BORDER_HEIGHT+drop+1 ,
638
+ mainConsole.topX +mainConsole.width ,clipDepth);
608
639
}
609
640
610
641
/* Stop when we've drawn enough or we're at the end */
@@ -614,9 +645,13 @@ void displayConsoleMessages( void )
614
645
psMessage && numProcessed < consoleVisibleLines && MesY < pie_GetVideoBufferHeight () - linePitch;
615
646
psMessage = psMessage->psNext )
616
647
{
648
+
649
+ /* Set text color depending on message type */
650
+ setConsoleTextColor (psMessage->player );
651
+
617
652
/* Draw the text string */
618
- WzMainWindow::instance ()-> drawPixmap ( mainConsole.topX , MesY, psMessage-> cache );
619
- MesY += iV_GetTextLineSize ( );
653
+ MesY = iV_DrawFormattedText (psMessage-> text , mainConsole.topX , MesY,
654
+ mainConsole. width , psMessage-> JustifyType );
620
655
621
656
/* Move on */
622
657
++numProcessed;
@@ -640,6 +675,23 @@ void enableConsoleDisplay(bool state)
640
675
bConsoleDisplayEnabled = state;
641
676
}
642
677
678
+ /* * Sets the default justification for text */
679
+ void setDefaultConsoleJust (CONSOLE_TEXT_JUSTIFICATION defJ)
680
+ {
681
+ switch (defJ)
682
+ {
683
+ case LEFT_JUSTIFY:
684
+ case RIGHT_JUSTIFY:
685
+ case CENTRE_JUSTIFY:
686
+ defJustification = defJ;
687
+ break ;
688
+ default :
689
+ debug ( LOG_FATAL, " Weird default text justification for console" );
690
+ abort ();
691
+ break ;
692
+ }
693
+ }
694
+
643
695
/* * Allows positioning of the console on screen */
644
696
void setConsoleSizePos (UDWORD x, UDWORD y, UDWORD width)
645
697
{
0 commit comments