From: <av...@us...> - 2009-12-12 07:50:51
|
Revision: 3427 http://sc2.svn.sourceforge.net/sc2/?rev=3427&view=rev Author: avolkov Date: 2009-12-12 07:50:45 +0000 (Sat, 12 Dec 2009) Log Message: ----------- Cargo menu cleanup: MENU_STATE.CurState is now 0-based; split drawing into functions; added symbolic positioning constants; moved colors to colors.h; not relying on MENU_STATE.Initialized Modified Paths: -------------- trunk/sc2/src/uqm/colors.h trunk/sc2/src/uqm/planets/cargo.c Modified: trunk/sc2/src/uqm/colors.h =================================================================== --- trunk/sc2/src/uqm/colors.h 2009-12-12 04:45:15 UTC (rev 3426) +++ trunk/sc2/src/uqm/colors.h 2009-12-12 07:50:45 UTC (rev 3427) @@ -342,10 +342,34 @@ #define THREEDOMENU_TEXT_COLOR \ BUILD_COLOR (MAKE_RGB15 (0x00, 0x1F, 0x00), 0x00) + // === Credits === + #define CREDITS_TEXT_COLOR \ WHITE_COLOR + +// === Cargo === + +#define CARGO_BACK_COLOR \ + BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01) + +#define CARGO_WORTH_COLOR \ + BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09) + +#define CARGO_AMOUNT_COLOR \ + BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03) + +#define CARGO_SELECTED_BACK_COLOR \ + BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09) + +#define CARGO_SELECTED_WORTH_COLOR \ + BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03) + +#define CARGO_SELECTED_AMOUNT_COLOR \ + BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B) + + // Temporary, until we can use C'99 features: #define BLACK_COLOR_INIT \ BUILD_COLOR (MAKE_RGB15_INIT (0x00, 0x00, 0x00), 0x00) Modified: trunk/sc2/src/uqm/planets/cargo.c =================================================================== --- trunk/sc2/src/uqm/planets/cargo.c 2009-12-12 04:45:15 UTC (rev 3426) +++ trunk/sc2/src/uqm/planets/cargo.c 2009-12-12 07:50:45 UTC (rev 3427) @@ -26,263 +26,240 @@ #include "../sis.h" // for ClearSISRect(), DrawStatusMessage() #include "planets.h" +#include "libs/graphics/drawable.h" + // for GetFrameBounds() +#define ELEMENT_ORG_Y 35 +#define FREE_ORG_Y (ELEMENT_ORG_Y + (NUM_ELEMENT_CATEGORIES \ + * ELEMENT_SPACING_Y)) +#define BIO_ORG_Y 119 +#define ELEMENT_SPACING_Y 9 + +#define ELEMENT_COL_0 7 +#define ELEMENT_COL_1 32 +#define ELEMENT_COL_2 58 + +#define ELEMENT_SEL_ORG_X (ELEMENT_COL_0 + 7 + 5) +#define ELEMENT_SEL_WIDTH (ELEMENT_COL_2 - ELEMENT_SEL_ORG_X + 1) + +#define TEXT_BASELINE 6 + + void ShowRemainingCapacity (void) { RECT r; - TEXT rt; + TEXT t; CONTEXT OldContext; - UNICODE rt_amount_buf[40]; + UNICODE buf[40]; OldContext = SetContext (StatusContext); SetContextFont (TinyFont); - sprintf (rt_amount_buf, "%u", + r.corner.x = 40; + r.corner.y = FREE_ORG_Y; + + snprintf (buf, sizeof buf, "%u", GetStorageBayCapacity () - GLOBAL_SIS (TotalElementMass)); - rt.baseline.x = 59; - rt.baseline.y = 113; - rt.align = ALIGN_RIGHT; - rt.pStr = rt_amount_buf; - rt.CharCount = (COUNT)~0; + t.baseline.x = ELEMENT_COL_2 + 1; + t.baseline.y = r.corner.y + TEXT_BASELINE; + t.align = ALIGN_RIGHT; + t.pStr = buf; + t.CharCount = (COUNT)~0; - r.corner.x = 40; - r.corner.y = rt.baseline.y - 6; - r.extent.width = rt.baseline.x - r.corner.x + 1; - r.extent.height = 7; + r.extent.width = t.baseline.x - r.corner.x + 1; + r.extent.height = ELEMENT_SPACING_Y - 2; BatchGraphics (); - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); + // erase previous free amount + SetContextForeGroundColor (CARGO_BACK_COLOR); DrawFilledRectangle (&r); - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)); - font_DrawText (&rt); + // print the new free amount + SetContextForeGroundColor (CARGO_WORTH_COLOR); + font_DrawText (&t); UnbatchGraphics (); SetContext (OldContext); } -void -DrawCargoStrings (BYTE OldElement, BYTE NewElement) +static void +DrawElementAmount (COUNT element, bool selected) { - COORD y, cy; - TEXT rt; RECT r; - CONTEXT OldContext; - UNICODE rt_amount_buf[40]; + TEXT t; + UNICODE buf[40]; - LockMutex (GraphicsLock); + r.corner.x = ELEMENT_SEL_ORG_X; + r.extent.width = ELEMENT_SEL_WIDTH; + r.extent.height = ELEMENT_SPACING_Y - 2; - OldContext = SetContext (StatusContext); - SetContextFont (TinyFont); + if (element == NUM_ELEMENT_CATEGORIES) + r.corner.y = BIO_ORG_Y; + else + r.corner.y = ELEMENT_ORG_Y + (element * ELEMENT_SPACING_Y); + + // draw line background + SetContextForeGroundColor (selected ? + CARGO_SELECTED_BACK_COLOR : CARGO_BACK_COLOR); + DrawFilledRectangle (&r); - BatchGraphics (); + t.pStr = buf; + t.baseline.y = r.corner.y + TEXT_BASELINE; - y = 41; - rt.align = ALIGN_RIGHT; - rt.pStr = rt_amount_buf; + if (element == NUM_ELEMENT_CATEGORIES) + { // Bio + snprintf (buf, sizeof buf, "%u", GLOBAL_SIS (TotalBioMass)); + } + else + { // Element + // print element's worth + SetContextForeGroundColor (selected ? + CARGO_SELECTED_WORTH_COLOR : CARGO_WORTH_COLOR); + t.baseline.x = ELEMENT_COL_1; + snprintf (buf, sizeof buf, "%u", GLOBAL (ElementWorth[element])); + t.CharCount = (COUNT)~0; + font_DrawText (&t); + + snprintf (buf, sizeof buf, "%u", GLOBAL_SIS (ElementAmounts[element])); + } - if (OldElement > NUM_ELEMENT_CATEGORIES) - { - STAMP s; + // print the element/bio amount + SetContextForeGroundColor (selected ? + CARGO_SELECTED_AMOUNT_COLOR : CARGO_AMOUNT_COLOR); + t.baseline.x = ELEMENT_COL_2; + t.CharCount = (COUNT)~0; + font_DrawText (&t); +} - r.corner.x = 2; - r.extent.width = FIELD_WIDTH + 1; +static void +DrawCargoDisplay (void) +{ + STAMP s; + TEXT t; + RECT r; + COORD cy; + COUNT i; - { - TEXT ct; + r.corner.x = 2; + r.extent.width = FIELD_WIDTH + 1; - r.corner.y = 20; - r.extent.height = 109; - DrawStarConBox (&r, 1, - BUILD_COLOR (MAKE_RGB15 (0x10, 0x10, 0x10), 0x19), - BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F), - TRUE, - BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); + r.corner.y = 20; + r.extent.height = 109; + DrawStarConBox (&r, 1, + SHADOWBOX_MEDIUM_COLOR, SHADOWBOX_DARK_COLOR, + TRUE, CARGO_BACK_COLOR); - SetContextFont (StarConFont); - ct.baseline.x = (STATUS_WIDTH >> 1) - 1; - ct.baseline.y = 27; - ct.align = ALIGN_CENTER; - ct.pStr = GAME_STRING (CARGO_STRING_BASE); - ct.CharCount = (COUNT)~0; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B)); - font_DrawText (&ct); + // draw the "CARGO" title + SetContextFont (StarConFont); + t.baseline.x = (STATUS_WIDTH >> 1) - 1; + t.baseline.y = 27; + t.align = ALIGN_CENTER; + t.pStr = GAME_STRING (CARGO_STRING_BASE); + t.CharCount = (COUNT)~0; + SetContextForeGroundColor (CARGO_SELECTED_AMOUNT_COLOR); + font_DrawText (&t); - SetContextFont (TinyFont); - } + SetContextFont (TinyFont); - r.corner.x = 7; - r.extent.width = 7; - r.extent.height = 7; + s.frame = SetAbsFrameIndex (MiscDataFrame, + (NUM_SCANDOT_TRANSITIONS * 2) + 3); + r.corner.x = ELEMENT_COL_0; + r.extent = GetFrameBounds (s.frame); + s.origin.x = r.corner.x + (r.extent.width >> 1); - s.origin.x = r.corner.x + (r.extent.width >> 1); - s.frame = SetAbsFrameIndex ( - MiscDataFrame, - (NUM_SCANDOT_TRANSITIONS << 1) + 3 - ); - cy = y; + cy = ELEMENT_ORG_Y; - rt.baseline.y = cy - 7; - rt.CharCount = 1; + // print element column headings + t.align = ALIGN_RIGHT; + t.baseline.y = cy - 1; + t.CharCount = (COUNT)~0; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)); - rt.baseline.x = 32; - rt_amount_buf[0] = '$'; - font_DrawText (&rt); + SetContextForeGroundColor (CARGO_WORTH_COLOR); + t.baseline.x = ELEMENT_COL_1; + t.pStr = "$"; + font_DrawText (&t); - rt.baseline.x = 58; - rt_amount_buf[0] = '#'; - font_DrawText (&rt); + t.baseline.x = ELEMENT_COL_2; + t.pStr = "#"; + font_DrawText (&t); - for (OldElement = 0; - OldElement < NUM_ELEMENT_CATEGORIES; ++OldElement) - { - SetContextForeGroundColor (BLACK_COLOR); - r.corner.y = cy - 6; - DrawFilledRectangle (&r); + // draw element icons and print amounts + for (i = 0; i < NUM_ELEMENT_CATEGORIES; ++i, cy += ELEMENT_SPACING_Y) + { + // erase background under an element icon + SetContextForeGroundColor (BLACK_COLOR); + r.corner.y = cy; + DrawFilledRectangle (&r); - s.origin.y = r.corner.y + (r.extent.height >> 1); - DrawStamp (&s); - s.frame = SetRelFrameIndex (s.frame, 5); + // draw an element icon + s.origin.y = r.corner.y + (r.extent.height >> 1); + DrawStamp (&s); + s.frame = SetRelFrameIndex (s.frame, 5); - if (OldElement != NewElement) - { - rt.baseline.y = cy; + DrawElementAmount (i, false); + } - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)); - rt.baseline.x = 32; - sprintf (rt_amount_buf, "%u", - GLOBAL (ElementWorth[OldElement])); - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); + // erase background under the Bio icon + SetContextForeGroundColor (BLACK_COLOR); + r.corner.y = BIO_ORG_Y; + DrawFilledRectangle (&r); - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); - rt.baseline.x = 58; - sprintf (rt_amount_buf, "%u", - GLOBAL_SIS (ElementAmounts[OldElement])); - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); - } + // draw the Bio icon + s.origin.y = r.corner.y + (r.extent.height >> 1); + s.frame = SetAbsFrameIndex (s.frame, 68); + DrawStamp (&s); - cy += 9; - } + // print the Bio amount + DrawElementAmount (NUM_ELEMENT_CATEGORIES, false); - OldElement = NewElement; + // draw the line over the Bio amount + r.corner.x = 4; + r.corner.y = BIO_ORG_Y - 2; + r.extent.width = FIELD_WIDTH - 3; + r.extent.height = 1; + SetContextForeGroundColor (CARGO_SELECTED_BACK_COLOR); + DrawFilledRectangle (&r); - rt.baseline.y = 125; + // print "Free" + t.baseline.x = 5; + t.baseline.y = FREE_ORG_Y + TEXT_BASELINE; + t.align = ALIGN_LEFT; + t.pStr = GAME_STRING (CARGO_STRING_BASE + 1); + t.CharCount = (COUNT)~0; + font_DrawText (&t); - SetContextForeGroundColor (BLACK_COLOR); - r.corner.y = rt.baseline.y - 6; - DrawFilledRectangle (&r); + ShowRemainingCapacity (); +} - s.origin.y = r.corner.y + (r.extent.height >> 1); - s.frame = SetAbsFrameIndex (s.frame, 68); - DrawStamp (&s); +void +DrawCargoStrings (BYTE OldElement, BYTE NewElement) +{ + CONTEXT OldContext; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); - rt.baseline.x = 58; - sprintf (rt_amount_buf, "%u", GLOBAL_SIS (TotalBioMass)); - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); + LockMutex (GraphicsLock); - r.corner.x = 4; - r.corner.y = 117; - r.extent.width = 56; - r.extent.height = 1; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)); - DrawFilledRectangle (&r); + OldContext = SetContext (StatusContext); + SetContextFont (TinyFont); - { - TEXT lt; - - lt.baseline.x = 5; - lt.baseline.y = 113; - lt.align = ALIGN_LEFT; - lt.pStr = GAME_STRING (CARGO_STRING_BASE + 1); - lt.CharCount = (COUNT)~0; - font_DrawText (<); - } + BatchGraphics (); - ShowRemainingCapacity (); + if (OldElement > NUM_ELEMENT_CATEGORIES) + { // Asked for the initial display + DrawCargoDisplay (); + + // do not draw unselected again this time + OldElement = NewElement; } - r.corner.x = 19; - r.extent.width = 40; - r.extent.height = 7; - if (OldElement != NewElement) - { - if (OldElement == NUM_ELEMENT_CATEGORIES) - cy = 125; - else - cy = y + (OldElement * 9); - r.corner.y = cy - 6; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); - DrawFilledRectangle (&r); - - rt.baseline.y = cy; - - if (OldElement == NUM_ELEMENT_CATEGORIES) - sprintf (rt_amount_buf, "%u", GLOBAL_SIS (TotalBioMass)); - else - { - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)); - rt.baseline.x = 32; - sprintf (rt_amount_buf, "%u", GLOBAL (ElementWorth[OldElement])); - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); - sprintf (rt_amount_buf, "%u", GLOBAL_SIS (ElementAmounts[OldElement])); - } - - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); - rt.baseline.x = 58; - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); + { // unselect the previous element + DrawElementAmount (OldElement, false); } if (NewElement != (BYTE)~0) - { - if (NewElement == NUM_ELEMENT_CATEGORIES) - cy = 125; - else - cy = y + (NewElement * 9); - r.corner.y = cy - 6; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)); - DrawFilledRectangle (&r); - - rt.baseline.y = cy; - - if (NewElement == NUM_ELEMENT_CATEGORIES) - sprintf (rt_amount_buf, "%u", GLOBAL_SIS (TotalBioMass)); - else - { - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); - rt.baseline.x = 32; - sprintf (rt_amount_buf, "%u", GLOBAL (ElementWorth[NewElement])); - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); - sprintf (rt_amount_buf, "%u", GLOBAL_SIS (ElementAmounts[NewElement])); - } - - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B)); - rt.baseline.x = 58; - rt.CharCount = (COUNT)~0; - font_DrawText (&rt); + { // select the new element + DrawElementAmount (NewElement, true); } UnbatchGraphics (); @@ -290,42 +267,38 @@ UnlockMutex (GraphicsLock); } +static void +DrawElementDescription (COUNT element) +{ + LockMutex (GraphicsLock); + DrawStatusMessage (GAME_STRING (element + (CARGO_STRING_BASE + 2))); + UnlockMutex (GraphicsLock); +} + static BOOLEAN DoDiscardCargo (MENU_STATE *pMS) { BYTE NewState; BOOLEAN select, cancel, back, forward; + select = PulsedInputState.menu[KEY_MENU_SELECT]; cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; back = PulsedInputState.menu[KEY_MENU_UP] || PulsedInputState.menu[KEY_MENU_LEFT]; forward = PulsedInputState.menu[KEY_MENU_DOWN] || PulsedInputState.menu[KEY_MENU_RIGHT]; if (GLOBAL (CurrentActivity) & CHECK_ABORT) - return (FALSE); + return FALSE; - if (!pMS->Initialized) + if (cancel) { - pMS->InputFunc = DoDiscardCargo; - pMS->Initialized = TRUE; - - NewState = pMS->CurState; - pMS->CurState = (BYTE)~0; - goto SelectCargo; + return FALSE; } - else if (cancel) - { - LockMutex (GraphicsLock); - ClearSISRect (DRAW_SIS_DISPLAY); - UnlockMutex (GraphicsLock); - - return (FALSE); - } else if (select) { - if (GLOBAL_SIS (ElementAmounts[pMS->CurState - 1])) + if (GLOBAL_SIS (ElementAmounts[pMS->CurState])) { - --GLOBAL_SIS (ElementAmounts[pMS->CurState - 1]); - DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(pMS->CurState - 1)); + --GLOBAL_SIS (ElementAmounts[pMS->CurState]); + DrawCargoStrings (pMS->CurState, pMS->CurState); LockMutex (GraphicsLock); --GLOBAL_SIS (TotalElementMass); @@ -339,7 +312,7 @@ } else { - NewState = pMS->CurState - 1; + NewState = pMS->CurState; if (back) { if (NewState == 0) @@ -353,15 +326,10 @@ NewState = 0; } - ++NewState; if (NewState != pMS->CurState) { -SelectCargo: - DrawCargoStrings ((BYTE)(pMS->CurState - 1), (BYTE)(NewState - 1)); - LockMutex (GraphicsLock); - DrawStatusMessage (GAME_STRING (NewState - 1 + (CARGO_STRING_BASE + 2))); - UnlockMutex (GraphicsLock); - + DrawCargoStrings (pMS->CurState, NewState); + DrawElementDescription (NewState); pMS->CurState = NewState; } } @@ -374,16 +342,22 @@ void CargoMenu (void) { - // XXX: Should get an own STATE struct MENU_STATE MenuState; - MenuState.InputFunc = DoDiscardCargo; - MenuState.Initialized = FALSE; - // XXX: 1-based index because this had to work around the - // pSolarSysState->MenuState.CurState abuse. Should be changed. - MenuState.CurState = 1; + memset (&MenuState, 0, sizeof MenuState); + // draw the initial cargo display + DrawCargoStrings ((BYTE)~0, MenuState.CurState); + DrawElementDescription (MenuState.CurState); + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); + + MenuState.InputFunc = DoDiscardCargo; DoInput (&MenuState, TRUE); + + // erase the cargo display + LockMutex (GraphicsLock); + ClearSISRect (DRAW_SIS_DISPLAY); + UnlockMutex (GraphicsLock); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |