Beispiel #1
0
void
TestTextSplit(Text string, Text delims, int empty, long expect)
{
	int i;
	Text s;
	Vector v;

	printf("string=[%s] delims=[%s] return-empty-tokens=%d\n",TextString(string),TextString(delims), empty);
	v = TextSplitOn(string, delims, empty);

	if (v == NULL) {
		printf("vector is null\n");
		return;
	}

	printf("  length=%ld expected=%ld", VectorLength(v), expect);
	for (i = 0; i < VectorLength(v); i++) {
		s = VectorGet(v, i);
		printf("[%s]", s == NULL ? "" : s->string(s));
	}

	printf(" ...%s\n", VectorLength(v) == expect ? "OK" : "FAIL");
	VectorDestroy(v);

	string->destroy(string);
	delims->destroy(delims);
}
Beispiel #2
0
void
TestFunction(long (*cmp)(Text, Text), Text a, Text b, long expect)
{
	long result = (*cmp)(a, b);

	printf("a=[%s] b=[%s] expect=%ld, result=%ld %s\n", TextString(a), TextString(b), expect, result, expect == result ? "OK" : "FAIL");

	a->destroy(a);
	b->destroy(b);
}
Beispiel #3
0
static int TemplateSelection(int loadFlag, int x, int index,
			     struct PlayerData *data, int cmd)
{
	int i;
	int y;
	static int selection[2] = { 0, 0 };

	if (cmd & CMD_BUTTON1) {
		if (loadFlag)
			UseTemplate(index, data,
				    &templates[selection[index]]);
		else
			SaveTemplate(data, &templates[selection[index]]);
		PlaySound(rand() % SND_COUNT, 0, 255);
		return 0;
	} else if (cmd & CMD_BUTTON2) {
		PlaySound(rand() % SND_COUNT, 0, 255);
		return 0;
	} else if (cmd & (CMD_LEFT | CMD_UP)) {
		if (selection[index] > 0) {
			selection[index]--;
			PlaySound(SND_SWITCH, 0, 255);
		} else if (selection[index] == 0) {
			selection[index] = MAX_TEMPLATE - 1;
			PlaySound(SND_SWITCH, 0, 255);
		}
	} else if (cmd & (CMD_RIGHT | CMD_DOWN)) {
		if (selection[index] < MAX_TEMPLATE - 1) {
			selection[index]++;
			PlaySound(SND_SWITCH, 0, 255);
		} else if (selection[index] == MAX_TEMPLATE - 1) {
			selection[index] = 0;
			PlaySound(SND_SWITCH, 0, 255);
		}
	}

	y = CenterY((TextHeight() * MAX_TEMPLATE));

	if (!loadFlag) {
		TextStringAt(x, y - 4 - TextHeight(), "Save ");
		TextString(data->name);
		TextString("...");
	}

	for (i = 0; i < MAX_TEMPLATE; i++)
		DisplayMenuItem(x, y + i * TextHeight(),
				templates[i].name, i == selection[index]);

	return 1;
}
Beispiel #4
0
void DisplayFlag(int x, int y, const char *s, int on, int hilite)
{
	TextGoto(x, y);
	if (hilite) {
		TextStringWithTable(s, tableFlamed);
		TextCharWithTable(':', tableFlamed);
	} else {
		TextString(s);
		TextChar(':');
	}
	if (on)
		TextStringWithTable("On", tablePurple);
	else
		TextString("Off");
}
Beispiel #5
0
static void HelpScreen(void)
{
	Vec2i pos = Vec2iNew(20, 20);
	const char *helpText =
		"Help\n"
		"====\n"
		"Use mouse to select controls; keyboard to type text\n"
		"Open files by dragging them over the editor shortcut\n"
		"\n"
		"Common commands\n"
		"===============\n"
		"left/right click, page up/down: Increase/decrease value\n"
		"shift + left/right click:       Increase/decrease number of items\n"
		"insert:                         Add new item\n"
		"delete:                         Delete selected item\n"
		"arrow keys:                     Move camera\n"
		"\n"
		"Other commands\n"
		"==============\n"
		"Escape:                         Back or quit\n"
		"Ctrl+E:                         Go to character editor\n"
		"Ctrl+N:                         New mission or character\n"
		"Ctrl+O:                         Open file\n"
		"Ctrl+S:                         Save file\n"
		"Ctrl+X, C, V:                   Cut/copy/paste\n"
		"Ctrl+M:                         Preview automap\n"
		"F1:                             This screen\n";
	ClearScreen(&gGraphicsDevice);
	TextString(&gTextManager, helpText, &gGraphicsDevice, pos);
	BlitFlip(&gGraphicsDevice, &gConfig.Graphics);
	GetKey(&gEventHandlers);
}
Beispiel #6
0
void DisplayCharacter(int x, int y, int character, int hilite)
{
	struct CharacterDescription *cd;
	TOffsetPic body, head;

	cd = &characterDesc[character];

	body.dx = cBodyOffset[cd->unarmedBodyPic][DIRECTION_DOWN].dx;
	body.dy = cBodyOffset[cd->unarmedBodyPic][DIRECTION_DOWN].dy;
	body.picIndex =
	    cBodyPic[cd->unarmedBodyPic][DIRECTION_DOWN][STATE_IDLE];

	head.dx =
	    cNeckOffset[cd->unarmedBodyPic][DIRECTION_DOWN].dx +
	    cHeadOffset[cd->facePic][DIRECTION_DOWN].dx;
	head.dy =
	    cNeckOffset[cd->unarmedBodyPic][DIRECTION_DOWN].dy +
	    cHeadOffset[cd->facePic][DIRECTION_DOWN].dy;
	head.picIndex = cHeadPic[cd->facePic][DIRECTION_DOWN][STATE_IDLE];

	DrawTTPic(x + body.dx, y + body.dy, gPics[body.picIndex],
		  cd->table, NULL);
	DrawTTPic(x + head.dx, y + head.dy, gPics[head.picIndex],
		  cd->table, NULL);

	if (hilite) {
		TextGoto(x - 8, y - 16);
		TextChar('\020');
		TextGoto(x - 8, y + 8);
		TextString(gunDesc[cd->defaultGun].gunName);
	}
}
Beispiel #7
0
bool ConfirmScreen(const char *info, const char *msg)
{
	int w = gGraphicsDevice.cachedConfig.Res.x;
	int h = gGraphicsDevice.cachedConfig.Res.y;
	ClearScreen(&gGraphicsDevice);
	TextString(&gTextManager,
		info,
		&gGraphicsDevice,
		Vec2iNew((w - TextGetStringWidth(info)) / 2, (h - CDogsTextHeight()) / 2));
	TextString(&gTextManager,
		msg,
		&gGraphicsDevice,
		Vec2iNew((w - TextGetStringWidth(msg)) / 2, (h + CDogsTextHeight()) / 2));
	BlitFlip(&gGraphicsDevice, &gConfig.Graphics);

	int c = GetKey(&gEventHandlers);
	return (c == 'Y' || c == 'y');
}
Beispiel #8
0
void
TestCompareFunction(int (*cmp)(void *, void *), Text a, Text b, int expect)
{
	int result;

	result = (*cmp)(a, b);
	if (result < 0)
		result = -1;
	else if (0 < result)
		result = 1;
	else
		result = 0;

	printf("a=[%s] b=[%s] expect=%d, result=%d %s\n", TextString(a), TextString(b), expect, result, expect == result ? "OK" : "FAIL");

	a->destroy(a);
	b->destroy(b);
}
Beispiel #9
0
static void Save(int asCode)
{
	char filename[128];
//      char drive[_MAX_DRIVE];
	char dir[96];
	char name[32];
//      char ext[_MAX_EXT];
	char c;
	int i;

	strcpy(filename, lastFile);
	while (1) {
		memset(GetDstScreen(), 58, 64000);
		TextStringAt(125, 50, "Save as:");
		TextGoto(125, 50 + TextHeight());
		TextChar('\020');
		TextString(filename);
		TextChar('\021');
		vsync();
		CopyToScreen();

		c = GetKey();
		switch (c) {
		case ENTER:
			if (!filename[0])
				break;
			if (asCode) {
				SaveCampaignAsC(filename, name, &campaign);
			} else {
				SaveCampaign(filename, &campaign);
			}
			fileChanged = 0;
			return;

		case ESCAPE:
			return;

		case BACKSPACE:
			if (filename[0])
				filename[strlen(filename) - 1] = 0;
			break;

		default:
			if (strlen(filename) == sizeof(filename) - 1)
				break;
			c = toupper(c);
			if ((c >= 'A' && c <= 'Z') ||
			    c == '-' || c == '_' || c == '\\') {
				i = strlen(filename);
				filename[i + 1] = 0;
				filename[i] = c;
			}
		}
	}
}
Beispiel #10
0
void UITooltipDraw(GraphicsDevice *device, Vec2i pos, const char *s)
{
	Vec2i bgSize = TextGetSize(s);
	pos = Vec2iAdd(pos, Vec2iNew(10, 10));	// add offset
	DrawRectangle(
		device,
		Vec2iAdd(pos, Vec2iScale(Vec2iUnit(), -TOOLTIP_PADDING)),
		Vec2iAdd(bgSize, Vec2iScale(Vec2iUnit(), 2 * TOOLTIP_PADDING)),
		bgColor,
		0);
	TextString(&gTextManager, s, device, pos);
}
static void SaveTemplateDisplayTitle(
	menu_t *menu, GraphicsDevice *g, Vec2i pos, Vec2i size, void *data)
{
	PlayerSelectMenuData *d = data;
	char buf[256];

	UNUSED(menu);
	UNUSED(size);

	// Display "Save <template>..." title
	sprintf(buf, "Save %s...", d->display.pData->name);
	TextString(&gTextManager, buf, g, Vec2iAdd(pos, Vec2iNew(0, 0)));
}
Beispiel #12
0
void DisplayMapItem(int x, int y, TMapObject * mo, int density, int hilite)
{
	char s[10];

	TOffsetPic *pic = &cGeneralPics[mo->pic];
	DrawTPic(x + pic->dx, y + pic->dy, gPics[pic->picIndex], NULL);

	if (hilite) {
		TextGoto(x - 8, y - 4);
		TextChar('\020');
	}
	sprintf(s, "%d", density);
	TextGoto(x - 8, y + 5);
	TextString(s);

	SetSecondaryMouseRects(localMapItemClicks);
}
Beispiel #13
0
static void DrawAIChatter(const DrawBuffer *b, const Vec2i offset)
{
	Vec2i pos;
	const Tile *tile = &b->tiles[0][0];
	pos.y = b->dy + cWallOffset.dy + offset.y;
	for (int y = 0; y < Y_TILES; y++, pos.y += TILE_HEIGHT)
	{
		pos.x = b->dx + cWallOffset.dx + offset.x;
		for (int x = 0; x < b->Size.x; x++, tile++, pos.x += TILE_WIDTH)
		{
			if (!(tile->flags & MAPTILE_OUT_OF_SIGHT))
			{
				// Draw the items that are in LOS
				for (int i = 0; i < (int)tile->things.size; i++)
				{
					const ThingId *tid = CArrayGet(&tile->things, i);
					if (tid->Kind != KIND_CHARACTER)
					{
						continue;
					}
					const TActor *a = CArrayGet(&gActors, tid->Id);
					if (!a->aiContext)
					{
						continue;
					}
					const char *text =
						AIStateGetChatterText(a->aiContext->State);
					Vec2i textPos = Vec2iNew(
						a->tileItem.x - b->xTop + offset.x -
							TextGetStringWidth(text) / 2,
						a->tileItem.y - b->yTop + offset.y - ACTOR_HEIGHT);
					TextString(
						&gTextManager,
						AIStateGetChatterText(a->aiContext->State),
						b->g,
						textPos);
				}
			}
		}
		tile += X_TILES - b->Size.x;
	}
}
Beispiel #14
0
void DisplayText(int x, int y, const char *text, int hilite, int editable)
{
	TextGoto(x, y);
	if (editable) {
		if (hilite)
			TextCharWithTable('\020', tableFlamed);
		else
			TextChar('\020');
	}

	if (hilite && !editable)
		TextStringWithTable(text, tableFlamed);
	else
		TextString(text);

	if (editable) {
		if (hilite)
			TextCharWithTable('\021', tableFlamed);
		else
			TextChar('\021');
	}
}
Beispiel #15
0
//---------------------------------------------------------------------------
TextString ParErrorText(int Error)
{
    char text[TextLen];
    Par_ErrorText(Error, text, TextLen);
    return TextString(text);
}
Beispiel #16
0
long
TextStartsWithIgnoreCase(Text self, Text prefix)
{
	return TextStartsWithIgnoreCaseC(self, TextString(prefix));
}
Beispiel #17
0
Text
TextNextToken(Text self, Text delims, int returnEmptyToken)
{
	return TextNextTokenC(self, (const char *) TextString(delims), returnEmptyToken);
}
Beispiel #18
0
Vector
TextSplitOn(Text self, Text delims, int returnEmptyToken)
{
	return TextSplitOnC(self, (const char *) TextString(delims), returnEmptyToken);
}
Beispiel #19
0
void TextStringAt(int x, int y, const char *s)
{
    TextGoto(x, y);
    TextString(s);
}
Beispiel #20
0
static void Display(GraphicsDevice *g, int yc, HandleInputResult result)
{
	char s[128];
	int y = 5;
	int i;
	int w = g->cachedConfig.Res.x;
	int h = g->cachedConfig.Res.y;
	Mission *mission = CampaignGetCurrentMission(&gCampaign);

	if (mission)
	{
		// Re-make the background if the resolution has changed
		if (gEventHandlers.HasResolutionChanged)
		{
			MakeBackground(g, 0);
		}
		if (result.RemakeBg || brush.IsGuideImageNew)
		{
			// Clear background first
			for (i = 0; i < GraphicsGetScreenSize(&g->cachedConfig); i++)
			{
				g->buf[i] = PixelFromColor(g, colorBlack);
			}
			brush.IsGuideImageNew = false;
			GrafxDrawExtra extra;
			extra.guideImage = brush.GuideImageSurface;
			extra.guideImageAlpha = brush.GuideImageAlpha;
			GrafxDrawBackground(g, &sDrawBuffer, tintNone, camera, &extra);
		}
		GraphicsBlitBkg(g);

		// Draw brush highlight tiles
		if (brush.IsActive && IsBrushPosValid(brush.Pos, mission))
		{
			EditorBrushSetHighlightedTiles(&brush);
		}
		for (i = 0; i < (int)brush.HighlightedTiles.size; i++)
		{
			Vec2i *pos = CArrayGet(&brush.HighlightedTiles, i);
			Vec2i screenPos = GetScreenPos(*pos);
			if (screenPos.x >= 0 && screenPos.x < w &&
				screenPos.y >= 0 && screenPos.y < h)
			{
				DrawRectangle(
					g,
					screenPos, Vec2iNew(TILE_WIDTH, TILE_HEIGHT),
					colorWhite, DRAW_FLAG_LINE);
			}
		}

		sprintf(
			s, "Mission %d/%d",
			gCampaign.MissionIndex + 1, (int)gCampaign.Setting.Missions.size);
		TextStringMasked(&gTextManager, 
			s, g, Vec2iNew(270, y),
			yc == YC_MISSIONINDEX ? colorRed : colorWhite);
		if (brush.LastPos.x)
		{
			sprintf(s, "(%d, %d)", brush.Pos.x, brush.Pos.y);
			TextString(&gTextManager, s, g, Vec2iNew(w - 40, h - 16));
		}
	}
	else
	{
		ClearScreen(g);
		if (gCampaign.Setting.Missions.size)
		{
			sprintf(s, "End/%d", (int)gCampaign.Setting.Missions.size);
			TextStringMasked(&gTextManager, 
				s, g, Vec2iNew(270, y),
				yc == YC_MISSIONINDEX ? colorRed : colorWhite);
		}
	}

	if (fileChanged)
	{
		DrawTPic(10, y, PicManagerGetOldPic(&gPicManager, 221));
	}

	TextString(&gTextManager, 
		"Press F1 for help", g, Vec2iNew(20, h - 20 - CDogsTextHeight()));

	y = 150;

	UIObjectDraw(
		sObjs, g, Vec2iZero(), gEventHandlers.mouse.currentPos, &sDrawObjs);

	if (result.WillDisplayAutomap && mission)
	{
		AutomapDraw(AUTOMAP_FLAGS_SHOWALL, true);
	}
	else
	{
		if (sTooltipObj && sTooltipObj->Tooltip)
		{
			UITooltipDraw(
				g, gEventHandlers.mouse.currentPos, sTooltipObj->Tooltip);
		}
		MouseDraw(&gEventHandlers.mouse);
	}
	BlitFlip(g, &gConfig.Graphics);
}
Beispiel #21
0
//==============================================================================
// Text routines
//==============================================================================
TextString CliErrorText(int Error)
{
    char text[TextLen];
    Cli_ErrorText(Error, text, TextLen);
    return TextString(text);
}
Beispiel #22
0
//---------------------------------------------------------------------------
TextString SrvEventText(TSrvEvent *Event)
{
    char text[TextLen];
    Srv_EventText(Event, text, TextLen);
    return TextString(text);
}
Beispiel #23
0
//---------------------------------------------------------------------------
TextString SrvErrorText(int Error)
{
    char text[TextLen];
    Srv_ErrorText(Error, text, TextLen);
    return TextString(text);
}