Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
optmenu.c
Go to the documentation of this file.
1/*
2 * Text input and modal text panels.
3 *
4 * Retail object 0x459160-0x45A00F (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
8unsigned char g_abTaggedAllocationPrefix[8] = {
9 'j', 'e', 'f', 'f', 0, 0, 0, 0
10}; /* 0x0049ca40 */
11ShortRect g_stModalBounds = {0x18, 0x28, 0x128, 0x3c}; /* 0x0049ca48 */
12ModalTextPanel *g_pModalTextPanel = 0; /* 0x0049ca50 */
13unsigned char *g_pCampaignChalkboardShape = 0; /* 0x0049ca54 */
14short g_bDisableChalkboardReplay = 0; /* 0x0049ca58 */
15
16/* Function start: 0x459160 */
18{
19 short pixelWidth;
20 Viewport clearArea;
21 char *text;
22 short characterWidth;
23 short length;
24
26 pixelWidth = MeasureTextPixelWidthClamped(text);
27 length = DosStrlen(text);
28 if (length != 0) {
29 characterWidth = (short)GetFontCharWidth(text[length - 1]);
31 clearArea.left += pixelWidth - characterWidth;
32 clearArea.right = (short)(clearArea.left + characterWidth - 1);
34 clearArea.bottom = (short)(clearArea.top +
35 ReadWord((unsigned short *)
37 ClearViewport(&clearArea,
40 g_29_pCurrentTextContext->cursorX - characterWidth);
41 }
42}
43
44/* Function start: 0x45924D */
46{
47 short colour;
48
49 colour = context->backgroundColour;
50 if (colour == 0xff)
52 ClearViewport(context->viewport, colour);
53}
54
55/* Function start: 0x459294 */
56void DrawTextInputCursor(char character)
57{
58 unsigned char savedBackground =
60 unsigned char ink = g_29_pCurrentTextContext->colour;
61 short savedX;
62 char glyph[2] = { character, 0 };
63
67 DrawFormattedText(glyph);
70}
71
72/* Function start: 0x45930A */
74{
75 short savedX;
76
79 ClearTextInputCharacter(character);
81}
82
83/* Function start: 0x459348 */
84void ClearTextInputCharacter(char character)
85{
86 Viewport clearArea;
87 short characterWidth;
88
89 characterWidth = (short)GetFontCharWidth(character);
92 clearArea.right = (short)(clearArea.left + characterWidth - 1);
94 clearArea.bottom = (short)(clearArea.top +
95 (short)ReadWord((unsigned short *)g_29_pCurrentTextContext->font) - 1);
96 ClearViewport(&clearArea,
98}
99
100/* Function start: 0x4593D6 */
101short InitializeModalTextPanel(ModalTextPanel *panel, short fontIndex,
102 ModalPanelBounds bounds, short clearColour,
103 short backgroundColour, short borderColour)
104{
105 *(ShortRect *)&panel->left = bounds;
109 if (fontIndex == -1)
110 fontIndex = 1;
111 InitializeTextContextFromFont(&panel->context, fontIndex,
112 (unsigned char)clearColour,
113 (signed char)backgroundColour);
115 /* The panel and its viewports keep their bounds as four loose shorts;
116 * the rectangle is copied between them as one 8-byte record. */
117 *(ShortRect *)&panel->savedBackground.left = *(ShortRect *)&panel->left;
118 *(ShortRect *)&panel->viewport.left = *(ShortRect *)&panel->left;
119 if (AllocateViewport(&panel->savedBackground, clearColour, 0) == 0)
120 return 0;
122 panel->context.viewport = &panel->viewport;
126 DrawViewportBorder(&panel->viewport, panel->left, panel->top,
127 panel->right, panel->bottom, borderColour);
128 return 1;
129}
130
131#pragma function(strcat)
132/* Function start: 0x459527 */
133void DrawModalTextPanel(ModalTextPanel *panel, short x, short y,
134 unsigned char alignment,
135 const char *format, ...)
136{
137 va_list argList;
138 char text[84];
139
140 va_start(argList, format);
141 vsprintf(text, format, argList);
142 va_end(argList);
143 SetTextCursor((unsigned short)(panel->left + x),
144 (unsigned short)(panel->top + y));
145 panel->context.alignment = alignment;
146 strcat(text, "%P");
148 MarkDibDirty();
149 DIBslamReal();
150}
151
152/* Function start: 0x4595AA */
161
162/* Function start: 0x4595EF */
163short ShowModalTextPanel(short fontIndex, const char *format, ...)
164{
165 ShortRect bounds;
166 short halfWidth;
167 va_list argList;
168 char text[52];
169
170 va_start(argList, format);
171 vsprintf(text, format, argList);
172 va_end(argList);
173 bounds = g_stModalBounds;
174 if (g_pModalTextPanel == 0) {
176 }
177 if (g_pModalTextPanel == 0)
178 return 0;
186 return 0;
187 }
188 halfWidth = MeasureTextPixelWidthClamped(text) * 8 / 16;
190 bounds.left = 159 - halfWidth;
191 bounds.right = 161 + halfWidth;
193 bounds,
196 g_cRedColour) == 0) {
199 return 0;
200 }
202 MarkDibDirty();
203 DIBslamReal();
204 return 1;
205}
206
207/* Function start: 0x45979B */
218
219/* This callee declaration preserves CL 4.1's comparison operand order below. */
220void DrawTextInputCursor(char character);
221
222/* Function start: 0x4597E3 */
223short ReadTextInput(char *destination, short maximumLength,
224 volatile short mode,
225 volatile short allowPathSeparators)
226{
227 Viewport textArea;
228 Viewport *oldViewport;
229 char *oldText;
230 short textX;
231 short textY;
232 short done;
233 short keyHandled;
234 unsigned char backgroundInk;
235 short inputCode;
236 char textBuffer[40];
237 short characterCount;
238
239 done = 0;
243 else
246 oldViewport = g_29_pCurrentTextContext->viewport;
247 g_29_pCurrentTextContext->text = textBuffer;
252 DosStrcpy(textBuffer, destination);
253 characterCount = DosStrlen(textBuffer);
254
255 textArea.left = textX;
256 textArea.top = textY;
257 textArea.bottom = (short)(
258 (short)ReadWord((unsigned short *)g_29_pCurrentTextContext->font) +
259 textY);
260 textArea.right = (short)(textArea.left +
261 MeasureTextPixelWidthClamped(textBuffer));
262 ClearViewport(&textArea,
264 DrawFormattedText(textBuffer);
266
267 MarkDibDirty();
268 DIBslamReal();
269 while (done == 0) {
270 keyHandled = 0;
271 while (keyHandled == 0) {
273 inputCode = WaitForQueuedInputPress();
274 switch (inputCode) {
275 case 27:
276 keyHandled++;
277 if (textBuffer[0] != 0)
280 g_29_pCurrentTextContext->viewport = oldViewport;
281 return 0;
282 case 13:
283 keyHandled++;
284 if (textBuffer[0] == 0)
285 break;
287 done++;
288 break;
289 default:
290 if (inputCode == 8 && characterCount != 0) {
294 characterCount--;
295 textBuffer[characterCount] = 0;
296 } else if (characterCount < maximumLength &&
297 ((allowPathSeparators != 0 &&
298 (inputCode == ':' || inputCode == '\\')) ||
299 isalnum(inputCode) ||
300 (inputCode == ' ' && characterCount != 0))) {
301 switch (mode) {
302 case 1:
303 inputCode = (short)toupper(inputCode);
304 break;
305 case 2:
306 if (inputCode < '0' || inputCode > '9')
307 inputCode = 0;
308 break;
309 }
310 if (inputCode == 0)
311 break;
313 textBuffer[characterCount] = (char)inputCode;
314 characterCount++;
315 textBuffer[characterCount] = 0;
316 SetTextCursor((unsigned short)textX,
317 (unsigned short)textY);
318 DrawFormattedText(textBuffer);
320 }
321 keyHandled++;
322 break;
323 }
324 }
325 MarkDibDirty();
326 DIBslamReal();
327 }
328
329 DosStrcpy(destination, textBuffer);
331 g_29_pCurrentTextContext->viewport = oldViewport;
333 return 1;
334}
335
336/* Function start: 0x459BC8 */
337short ReadPersonnelTextField(unsigned int x, unsigned int y,
338 int font, const char *prompt,
339 char *destination, int maximumLength,
340 int mode, int required)
341{
342 short result;
343
344 result = 0;
347 SetTextCursor((unsigned short)x, (unsigned short)y);
348 DrawFormattedText("%s", prompt);
349 MarkDibDirty();
350 DIBslamReal();
351 if (ReadTextInput(destination, (short)maximumLength, (short)mode,
352 (short)required) != 0) {
353 result = 1;
354 }
357 return result;
358}
359
360#pragma function(strcmp)
361/* Function start: 0x459C4D */
362short PollCampaignChalkboardMenu(unsigned char *scene)
363{
364 short selection;
365 short done;
366
367 selection = 0;
368 done = 0;
371 while ((selection = PollSceneHotspotInput(scene, 0, 0, 0, 0)) == 0) {
374 58, 175,
381 if (g_pszPersonnelFooter != 0) {
383 (unsigned short)((320 -
385 g_pszPersonnelFooter)) >> 1),
386 180);
387 if (strcmp(g_pszPersonnelFooter,
388 "Exit to DOS") != 0) {
391 } else {
392 DrawFormattedText("%S", "Exit the Game");
393 }
394 }
399 }
400 return selection;
401}
402
403#pragma function(strcpy)
404/* Function start: 0x459D74 */
405short RunCampaignChalkboardMenu(short campaignSlot)
406{
407 short again;
408 short result;
409 short selection;
410
411 selection = 0;
412 result = 1;
413 again = 1;
414 PreloadMusicTrack(0x35);
415 spacetrack(0x35, 2, 1);
417 while (selection == 0) {
419 (short)(g_pCampaignGlobals->field_0a == 0);
420 selection = PollCampaignChalkboardMenu(
422 switch (selection) {
423 case 1:
429 ReleaseMusicTrack(0x35);
432 RunCampaignScript(campaignSlot);
434 result = 0;
435 break;
436 case 4:
437 exit_squadron(0);
438 break;
439 case 3:
443 if (g_nOriginDevUnlock != 0)
445 "CHEATER");
448 (short)(g_pCampaignGlobals->field_0e & 0xff));
449 result = 1;
450 break;
451 case 5:
453 result = 1;
454 break;
455 case 2:
461 ReleaseMusicTrack(0x35);
463 while (again != 0) {
464 RunCampaignScript(campaignSlot);
465 again = 0;
466 if (g_pCampaignGlobals->field_16 != 0) {
467 again++;
469 }
471 }
475 (short)(g_pCampaignGlobals->field_0e & 0xff));
476 result = 1;
477 break;
478 }
479 }
480 return result;
481}
short ReadPersonnelTextField(unsigned int x, unsigned int y, int font, const char *prompt, char *destination, int maximumLength, int mode, int required)
Definition optmenu.c:337
short ReadWord(unsigned short *p)
Definition eventmgr.c:210
void RefreshCampaignChalkboardScreen(short cockpitVariant)
Definition personnel.c:180
void FormatTextBufferFromStart(const char *format,...)
Definition textfmt.c:123
void SetInputViewport(Viewport *viewport)
Definition eventmgr.c:2093
void RestoreModalTextPanel(ModalTextPanel *panel)
Definition optmenu.c:153
void InitializeTextContextFromFont(TextContext *context, short fontIndex, unsigned char colour, signed char background)
Definition disk.c:254
short AllocateViewport(Viewport *viewport, short clearColour, short flags)
Definition vpalloc.c:32
void ClearTextInputCharacter(char character)
Definition optmenu.c:84
short DosStrlen(const char *s)
Definition eventmgr.c:479
void free_viewport(Viewport *viewport)
Definition vpfree.c:10
void RefreshMemoryStatusOverlay(void)
Definition main.c:283
short MeasureTextPixelWidthClamped(const char *text)
Definition strwidth.c:10
void DrawModalTextPanel(ModalTextPanel *panel, short x, short y, unsigned char alignment, const char *format,...)
Definition optmenu.c:133
void EraseCharacterAfterTextCursor(char character)
Definition optmenu.c:73
void DrawSpriteDefault(Viewport *viewport, short x, short y, unsigned char *shape, short frame)
Definition gr.c:682
void StopMusicUnlessSuppressed(void)
Definition music.c:160
void FlushInputEvents(void)
Definition eventmgr.c:1014
void DIBslamReal(void)
Definition dib.cpp:562
void ReleaseMusicTrack(int track)
Definition fltsetup.c:976
void InitializeCampaignChalkboardScreen(short cockpitVariant)
Definition personnel.c:115
void spacetrack(int track, int mode, int enabled)
Definition music.c:152
short PollCampaignChalkboardMenu(unsigned char *scene)
Definition optmenu.c:362
short WaitForQueuedInputPress(void)
Definition waitkey.c:9
void * AllocateTaggedMemory(unsigned int size, short flags)
Definition memapi.c:92
void ServiceSoundSystem(void)
Definition sound.c:389
short InitializeModalTextPanel(ModalTextPanel *panel, short fontIndex, ModalPanelBounds bounds, short clearColour, short backgroundColour, short borderColour)
Definition optmenu.c:101
short RunCampaignChalkboardMenu(short campaignSlot)
Definition optmenu.c:405
short PollSceneHotspotInput(void *scenePacket, short offsetX, short offsetY, short dismissOnBackground, short maximumSelection)
Definition hotspot.c:170
void RunPilotSaveLoadMenu(void)
Definition personnel.c:827
void RunCampaignScript(short campaignSlot)
Definition campglob.c:126
char * DosStrcpy(char *dst, const char *src)
Definition eventmgr.c:465
void DisableMouseCursorDrawing(void)
Definition eventmgr.c:1327
void ResetStringBuilder(TextContext *context)
Definition pload.c:9
void DrawViewportBorder(Viewport *viewport, short left, short top, short right, short bottom, short colour)
Definition gr.c:1360
void ClearViewport(Viewport *viewport, short colour)
Definition gr.c:1027
void EnableMouseCursorDrawing(void)
Definition eventmgr.c:1254
short ReadTextInput(char *destination, short maximumLength, volatile short mode, volatile short allowPathSeparators)
Definition optmenu.c:223
void DrawTextInputCursor(char character)
Definition optmenu.c:56
void SetMenuInputPump(void)
Definition eventmgr.c:2106
void ReleasePacketHandle(void *handle)
Definition memapi.c:108
void SetTextCursor(unsigned short a, unsigned short b)
Definition eventmgr.c:172
void EraseLastTextInputCharacter(void)
Definition optmenu.c:17
void exit_squadron(const char *msg,...)
Definition message.c:44
void ReleaseModalTextPanel(void)
Definition optmenu.c:208
void FreePacketAndClear(void *slot, unsigned short releaseFlags)
Definition disk.c:45
ShortRect ModalPanelBounds
Definition functions.h:694
void EraseTextContextBackground(TextContext *context)
Definition optmenu.c:45
void DrawFormattedText(const char *format,...)
Definition textfmt.c:103
void MarkDibDirty(void)
Definition dib.cpp:532
void PreloadMusicTrack(int track)
Definition fltsetup.c:961
void CopyViewportContents(Viewport *source, Viewport *destination)
Definition gr.c:995
short GetFontCharWidth(char i)
Definition eventmgr.c:216
short ShowModalTextPanel(short fontIndex, const char *format,...)
Definition optmenu.c:163
Shared Win32 declarations, types and library interfaces.
CampaignGlobals * g_pCampaignGlobals
Definition gameflow.c:3707
unsigned char * g_pCampaignChalkboardShape
Definition optmenu.c:13
TextContext * g_29_pCurrentTextContext
Definition eventmgr.c:2563
unsigned char g_cBlueColour
Definition startup.c:546
char * g_pszPersonnelFooter
Definition hotspot.c:243
unsigned char g_cSecondaryViewBufferColour
Definition startup.c:544
short g_bRewritePacketExtensions
Definition startup.c:543
unsigned char g_cRedColour
Definition startup.c:548
short g_bDisableChalkboardReplay
Definition optmenu.c:14
unsigned char g_bPrimaryViewBufferColour
Definition startup.c:545
Viewport g_2_stModalSourceWindow
Definition message.c:231
char g_16_szTextBufferBuffer[256]
Definition cockpt.c:3793
Viewport g_101_stScrViewInfo
Definition cockpt.c:3831
Viewport g_stSecondaryViewBufferBlock
Definition message.c:234
short g_nOriginDevUnlock
Definition main.c:1944
PilotProfile g_stCurrentPilotProfile
Definition viewrect.c:73
unsigned char g_abTaggedAllocationPrefix[8]
Definition optmenu.c:8
TextContext g_3_stDefaultStringContext
Definition message.c:239
ModalTextPanel * g_pModalTextPanel
Definition optmenu.c:12
ShortRect g_stModalBounds
Definition optmenu.c:11
TextContext context
Definition game.h:308
short top
Definition game.h:313
TextContext * previousContext
Definition game.h:311
short left
Definition game.h:312
Viewport viewport
Definition game.h:310
short bottom
Definition game.h:315
short right
Definition game.h:314
Viewport savedBackground
Definition game.h:309
char callsign[13]
Definition game_data.h:1115
short left
Definition game_data.h:479
short right
Definition game_data.h:481
unsigned char colour
Definition game.h:288
short cursorY
Definition game.h:286
unsigned char * font
Definition game.h:287
char * text
Definition game.h:290
unsigned char backgroundColour
Definition game.h:289
signed char alignment
Definition game.h:292
short cursorX
Definition game.h:285
Viewport * viewport
Definition game.h:284
short right
Definition game.h:154
short bottom
Definition game.h:155
short left
Definition game.h:152
short top
Definition game.h:153