static void DrawNameMenu( menu_t *menu, GraphicsDevice *g, Vec2i pos, Vec2i size, void *data) { PlayerSelectMenuData *d = data; #define ENTRY_COLS 8 #define ENTRY_SPACING 7 int x = pos.x; int y = CENTER_Y( pos, size, FontH() * ((strlen(letters) - 1) / ENTRY_COLS)); UNUSED(menu); UNUSED(g); int i; for (i = 0; i < (int)strlen(letters); i++) { Vec2i menuPos = Vec2iNew( x + (i % ENTRY_COLS) * ENTRY_SPACING, y + (i / ENTRY_COLS) * FontH()); FontChMask( letters[i], menuPos, i == d->nameMenuSelection ? colorRed : colorWhite); } DisplayMenuItem( Vec2iNew( x + (i % ENTRY_COLS) * ENTRY_SPACING, y + (i / ENTRY_COLS) * FontH()), "(End)", i == d->nameMenuSelection, 0, colorBlack); }
void DisplayFlag( const struct vec2i pos, const char *s, const bool isOn, const bool isHighlighted) { color_t labelMask = isHighlighted ? colorRed : colorWhite; struct vec2i p = FontStrMask(s, pos, labelMask); p = FontChMask(':', p, labelMask); FontStrMask(isOn ? "On" : "Off", p, isOn ? colorPurple : colorWhite); }
static void VictoryDraw(void *data) { const VictoryData *vd = data; const int w = gGraphicsDevice.cachedConfig.Res.x; FontOpts opts = FontOptsNew(); opts.HAlign = ALIGN_CENTER; opts.Area = gGraphicsDevice.cachedConfig.Res; int y = 30; // Congratulations text #define CONGRATULATIONS "Congratulations, you have completed " FontStrOpt(CONGRATULATIONS, svec2i(0, y), opts); y += 15; opts.Mask = colorRed; FontStrOpt(vd->Campaign->Setting.Title, svec2i(0, y), opts); y += 15; // Final words struct vec2i pos = svec2i((w - FontStrW(vd->FinalWords)) / 2, y); pos = FontChMask('"', pos, colorDarker); pos = FontStrMask(vd->FinalWords, pos, colorPurple); FontChMask('"', pos, colorDarker); }
static void VictoryDraw(void *data) { // This will only draw once const CampaignOptions *c = data; GraphicsBlitBkg(&gGraphicsDevice); const int w = gGraphicsDevice.cachedConfig.Res.x; const int h = gGraphicsDevice.cachedConfig.Res.y; FontOpts opts = FontOptsNew(); opts.HAlign = ALIGN_CENTER; opts.Area = gGraphicsDevice.cachedConfig.Res; int y = 100; // Congratulations text #define CONGRATULATIONS "Congratulations, you have completed " FontStrOpt(CONGRATULATIONS, Vec2iNew(0, y), opts); y += 15; opts.Mask = colorRed; FontStrOpt(c->Setting.Title, Vec2iNew(0, y), opts); // Display players switch (gPlayerDatas.size) { case 1: { const PlayerData *p = CArrayGet(&gPlayerDatas, 0); DisplayCharacterAndName(Vec2iNew(w / 4, h / 4), &p->Char, p->name); } break; case 2: { // side by side const PlayerData *p1 = CArrayGet(&gPlayerDatas, 0); DisplayCharacterAndName( Vec2iNew(w / 8, h / 4), &p1->Char, p1->name); const PlayerData *p2 = CArrayGet(&gPlayerDatas, 1); DisplayCharacterAndName( Vec2iNew(w / 8 + w / 2, h / 4), &p2->Char, p2->name); } break; case 3: // fallthrough case 4: { // 2x2 const PlayerData *p1 = CArrayGet(&gPlayerDatas, 0); DisplayCharacterAndName( Vec2iNew(w / 8, h / 8), &p1->Char, p1->name); const PlayerData *p2 = CArrayGet(&gPlayerDatas, 1); DisplayCharacterAndName( Vec2iNew(w / 8 + w / 2, h / 8), &p2->Char, p2->name); const PlayerData *p3 = CArrayGet(&gPlayerDatas, 2); DisplayCharacterAndName( Vec2iNew(w / 8, h / 8 + h / 4), &p3->Char, p3->name); if (gPlayerDatas.size == 4) { const PlayerData *p4 = CArrayGet(&gPlayerDatas, 3); DisplayCharacterAndName( Vec2iNew(w / 8 + w / 2, h / 8 + h / 4), &p4->Char, p4->name); } } break; default: CASSERT(false, "not implemented"); break; } // Final words const char *finalWordsSingle[] = { "Ha, next time I'll use my good hand", "Over already? I was just warming up...", "There's just no good opposition to be found these days!", "Well, maybe I'll just do my monthly reload then", "Woof woof", "I'll just bury the bones in the back yard, he-he", "I just wish they'd let me try bare-handed", "Rambo? Who's Rambo?", "<in Austrian accent:> I'll be back", "Gee, my trigger finger is sore", "I need more practice. I think I missed a few shots at times" }; const char *finalWordsMulti[] = { "United we stand, divided we conquer", "Nothing like good teamwork, is there?", "Which way is the camera?", "We eat bullets for breakfast and have grenades as dessert", "We're so cool we have to wear mittens", }; const char *finalWords; if (gPlayerDatas.size == 1) { const int numWords = sizeof finalWordsSingle / sizeof(char *); finalWords = finalWordsSingle[rand() % numWords]; } else { const int numWords = sizeof finalWordsMulti / sizeof(char *); finalWords = finalWordsMulti[rand() % numWords]; } Vec2i pos = Vec2iNew((w - FontStrW(finalWords)) / 2, h / 2 + 20); pos = FontChMask('"', pos, colorDarker); pos = FontStrMask(finalWords, pos, colorPurple); FontChMask('"', pos, colorDarker); }
static void UIObjectDrawAndAddChildren( UIObject *o, GraphicsDevice *g, Vec2i pos, Vec2i mouse, CArray *objs) { if (!o) { return; } if (o->CheckVisible) { o->CheckVisible(o, o->Data); } if (!o->IsVisible) { return; } int isHighlighted = UIObjectIsHighlighted(o); Vec2i oPos = Vec2iAdd(pos, o->Pos); switch (o->Type) { case UITYPE_LABEL: { const char *text = LabelGetText(o); if (!text) { break; } color_t textMask = isHighlighted ? colorRed : colorWhite; FontStrMaskWrap(text, oPos, textMask, o->Size.x); } break; case UITYPE_TEXTBOX: { int isText = !!o->u.Textbox.TextLinkFunc; const char *text = isText ? o->u.Textbox.TextLinkFunc(o, o->Data) : NULL; int isEmptyText = !isText || !text || strlen(text) == 0; color_t bracketMask = isHighlighted ? colorRed : colorWhite; color_t textMask = isEmptyText ? colorGray : colorWhite; int oPosX = oPos.x; if (isEmptyText) { text = o->u.Textbox.Hint; } if (!o->u.Textbox.IsEditable) { textMask = bracketMask; } if (o->u.Textbox.IsEditable) { oPos = FontChMask('>', oPos, bracketMask); } oPos = FontStrMaskWrap( text, oPos, textMask, o->Pos.x + o->Size.x - oPosX); if (o->u.Textbox.IsEditable) { oPos = FontChMask('<', oPos, bracketMask); } oPos.x = oPosX; } break; case UITYPE_TAB: if (o->Children.size > 0) { color_t textMask = isHighlighted ? colorRed : colorWhite; char **labelp = CArrayGet(&o->u.Tab.Labels, o->u.Tab.Index); UIObject **objp = CArrayGet(&o->Children, o->u.Tab.Index); FontStrMaskWrap( *labelp, Vec2iAdd(pos, o->Pos), textMask, o->Size.x); if (!((*objp)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) { UIObjectDrawAndAddChildren(*objp, g, oPos, mouse, objs); } } break; case UITYPE_BUTTON: { int isDown = o->u.Button.IsDownFunc && o->u.Button.IsDownFunc(o->Data); BlitMasked( g, o->u.Button.Pic, oPos, isDown ? colorGray : colorWhite, 1); } break; case UITYPE_CONTEXT_MENU: { // Draw background DrawRectangle( g, Vec2iAdd(oPos, Vec2iScale(Vec2iUnit(), -TOOLTIP_PADDING)), Vec2iAdd(o->Size, Vec2iScale(Vec2iUnit(), 2 * TOOLTIP_PADDING)), menuBGColor, 0); // Find if mouse over any children, and draw highlight for (int i = 0; i < (int)o->Children.size; i++) { UIObject *child = *(UIObject **)CArrayGet(&o->Children, i); if (IsInside(mouse, Vec2iAdd(oPos, child->Pos), child->Size)) { DrawRectangle( g, Vec2iAdd(oPos, child->Pos), child->Size, hiliteColor, 0); } } } break; case UITYPE_CUSTOM: o->u.CustomDrawFunc(o, g, pos, o->Data); break; default: // do nothing break; } // add children // Note: tab type draws its own children (one) if (o->Type != UITYPE_TAB && objs != NULL) { size_t i; UIObject **childPtr = o->Children.data; for (i = 0; i < o->Children.size; i++, childPtr++) { if (!((*childPtr)->Flags & UI_ENABLED_WHEN_PARENT_HIGHLIGHTED_ONLY) || isHighlighted) { UIObjectDrawContext c; c.obj = *childPtr; c.pos = oPos; CArrayPushBack(objs, &c); } } } }