From: <av...@us...> - 2009-11-17 08:49:34
|
Revision: 3309 http://sc2.svn.sourceforge.net/sc2/?rev=3309&view=rev Author: avolkov Date: 2009-11-17 08:49:22 +0000 (Tue, 17 Nov 2009) Log Message: ----------- Naming code cleanup: some abuses of MENU_STATE removed; load savegame info while fading music; some dead code removed Modified Paths: -------------- trunk/sc2/src/uqm/gameopt.c trunk/sc2/src/uqm/gameopt.h trunk/sc2/src/uqm/outfit.c trunk/sc2/src/uqm/sis.c trunk/sc2/src/uqm/state.h Modified: trunk/sc2/src/uqm/gameopt.c =================================================================== --- trunk/sc2/src/uqm/gameopt.c 2009-11-16 23:32:01 UTC (rev 3308) +++ trunk/sc2/src/uqm/gameopt.c 2009-11-17 08:49:22 UTC (rev 3309) @@ -44,12 +44,15 @@ #define SUMMARY_SIDE_OFFS 7 #define SAVES_PER_PAGE 5 +#define MAX_NAME_SIZE SIS_NAME_SIZE + static BOOLEAN DoSettings (MENU_STATE *pMS); static BOOLEAN DoNaming (MENU_STATE *pMS); static MENU_STATE *pLocMenuState; static BYTE prev_save; //keeps track of the last slot that was saved or loaded +static NamingCallback *namingCB; void ConfirmSaveLoad (STAMP *MsgStamp) @@ -188,9 +191,9 @@ #define DDSHS_BLOCKCUR 2 static BOOLEAN -DrawDescriptionString (MENU_STATE *pMS, COUNT which_string, COUNT state) +DrawDescriptionString (MENU_STATE *pMS, UNICODE *Str, COUNT CursorPos, + COUNT state) { - COUNT rel_index; RECT r; TEXT lf; COLOR BackGround, ForeGround; @@ -198,8 +201,6 @@ LockMutex (GraphicsLock); - rel_index = (COUNT)(which_string - pMS->first_item.y); - { r.corner.x = 2; r.extent.width = SHIP_NAME_WIDTH; @@ -207,7 +208,7 @@ SetContext (StatusContext); if (pMS->CurState == CHANGE_CAPTAIN_SETTING) - { + { // Naming the captain Font = TinyFont; r.corner.y = 10; ++r.corner.x; @@ -218,7 +219,7 @@ ForeGround = BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B); } else - { + { // Naming the flagship Font = StarConFont; r.corner.y = 20; lf.baseline.x = r.corner.x + (r.extent.width >> 1); @@ -232,44 +233,23 @@ } SetContextFont (Font); - lf.pStr = ((GAME_DESC *)pMS->Extra)[rel_index]; + lf.pStr = Str; lf.CharCount = (COUNT)~0; if (!(state & DDSHS_EDIT)) { // normal state SetFlashRect (SFR_MENU_3DO); - if (pMS->InputFunc == DoNaming) - { - if (pMS->CurState == CHANGE_CAPTAIN_SETTING) - DrawCaptainsName (); - else - { - DrawFlagshipName (TRUE); - if (pMenuState && pMenuState->InputFunc == DoOutfit) - DrawFlagshipName (FALSE); - } - } + if (pMS->CurState == CHANGE_CAPTAIN_SETTING) + DrawCaptainsName (); else - { // XXX: remnants of DOS? this function is never actually - // called outside DoNaming nowadays, which makes this - // code utterly dead - if (state == 0) - { - COLOR OldColor; - - OldColor = SetContextForeGroundColor (BLACK_COLOR); - DrawFilledRectangle (&r); - SetContextForeGroundColor (OldColor); - } - font_DrawText (&lf); - } + DrawFlagshipName (TRUE); } else { // editing state COUNT i; RECT text_r; - BYTE char_deltas[MAX_DESC_CHARS]; + BYTE char_deltas[MAX_NAME_SIZE]; BYTE *pchar_deltas; TextRect (&lf, &text_r, char_deltas); @@ -285,18 +265,18 @@ DrawFilledRectangle (&r); pchar_deltas = char_deltas; - for (i = pMS->first_item.x; i > 0; --i) - text_r.corner.x += (SIZE)*pchar_deltas++; - if ((COUNT)pMS->first_item.x < lf.CharCount) /* end of line */ + for (i = CursorPos; i > 0; --i) + text_r.corner.x += *pchar_deltas++; + if (CursorPos < lf.CharCount) /* end of line */ --text_r.corner.x; if (state & DDSHS_BLOCKCUR) { // Use block cursor for keyboardless systems - if ((COUNT)pMS->first_item.x == lf.CharCount) + if (CursorPos == lf.CharCount) { // cursor at end-line -- use insertion point text_r.extent.width = 1; } - else if ((COUNT)pMS->first_item.x + 1 == lf.CharCount) + else if (CursorPos + 1 == lf.CharCount) { // extra pixel for last char margin text_r.extent.width = (SIZE)*pchar_deltas + 2; } @@ -331,34 +311,23 @@ MENU_STATE *pMS = (MENU_STATE*) pTES->CbParam; COUNT hl = DDSHS_EDIT; - pMS->first_item.x = pTES->CursorPos; if (pTES->JoystickMode) hl |= DDSHS_BLOCKCUR; - return DrawDescriptionString (pMS, 0, hl); + return DrawDescriptionString (pMS, pTES->BaseStr, pTES->CursorPos, hl); } static BOOLEAN DoNaming (MENU_STATE *pMS) { - GAME_DESC buf; + UNICODE buf[MAX_NAME_SIZE] = ""; TEXTENTRY_STATE tes; UNICODE *Setting; pMS->Initialized = TRUE; pMS->InputFunc = DoNaming; - buf[0] = '\0'; - // XXX: this code abuses MENU_STATE struct members to store - // some values: - // first_item.x - current cursor position - // first_item.y - must be set to 0; DrawDescriptionString() - // treats it as base index into array of strings - // supplied in Extra - pMS->first_item.x = 0; - pMS->first_item.y = 0; - pMS->Extra = buf; - DrawDescriptionString (pMS, 0, DDSHS_EDIT); + DrawDescriptionString (pMS, buf, 0, DDSHS_EDIT); LockMutex (GraphicsLock); DrawStatusMessage (GAME_STRING (NAMING_STRING_BASE + 0)); @@ -388,8 +357,11 @@ utf8StringCopy (Setting, tes.MaxSize, buf); else utf8StringCopy (buf, sizeof (buf), Setting); - DrawDescriptionString (pMS, 0, DDSHS_NORMAL); + DrawDescriptionString (pMS, buf, 0, DDSHS_NORMAL); + if (namingCB) + namingCB (); + SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); pMS->InputFunc = DoSettings; @@ -399,6 +371,12 @@ return (TRUE); } +void +SetNamingCallback (NamingCallback *callback) +{ + namingCB = callback; +} + static BOOLEAN DoSettings (MENU_STATE *pMS) { @@ -867,11 +845,6 @@ pMS->delta_item = (SIZE)pMS->CurState; pMS->CurState = NewState = prev_save; pMS->InputFunc = DoPickGame; - SleepThreadUntil ((DWORD)pMS->CurFrame); - pMS->CurFrame = 0; - PauseMusic (); - StopSound (); - FadeMusic (NORMAL_VOLUME, 0); { extern FRAME PlayFrame; @@ -884,7 +857,6 @@ BatchGraphics (); Restart: SetContext (SpaceContext); - LoadGameDescriptions ((SUMMARY_DESC *)pMS->Extra); DrawCargo (1); pMS->Initialized = TRUE; goto ChangeGameSelection; @@ -941,6 +913,7 @@ SaveProblem (); pMS->Initialized = FALSE; + LoadGameDescriptions ((SUMMARY_DESC *)pMS->Extra); NewState = pMS->CurState; LockMutex (GraphicsLock); BatchGraphics (); @@ -1139,7 +1112,10 @@ SUMMARY_DESC desc_array[MAX_SAVED_GAMES]; RECT DlgRect; STAMP DlgStamp; + TimeCount TimeOut; + TimeOut = FadeMusic (0, ONE_SECOND / 2); + if (pSolarSysState) { ++pSolarSysState->MenuState.Initialized; @@ -1147,6 +1123,8 @@ TaskSwitch (); } + LoadGameDescriptions (desc_array); + LockMutex (GraphicsLock); OldContext = SetContext (SpaceContext); @@ -1164,6 +1142,11 @@ pMS->Extra = desc_array; UnlockMutex (GraphicsLock); + SleepThreadUntil (TimeOut); + PauseMusic (); + StopSound (); + FadeMusic (NORMAL_VOLUME, 0); + DoInput (pMS, TRUE); LockMutex (GraphicsLock); pMS->Initialized = -1; @@ -1179,7 +1162,7 @@ } if (!(GLOBAL (CurrentActivity) & (CHECK_ABORT | CHECK_LOAD))) - { + { // Restore previous screen if necessary // TODO: Need a better test for in-encounter if (CommData.ConversationPhrasesRes || !(pSolarSysState Modified: trunk/sc2/src/uqm/gameopt.h =================================================================== --- trunk/sc2/src/uqm/gameopt.h 2009-11-16 23:32:01 UTC (rev 3308) +++ trunk/sc2/src/uqm/gameopt.h 2009-11-17 08:49:22 UTC (rev 3309) @@ -22,5 +22,8 @@ extern void ConfirmSaveLoad (STAMP *MsgStamp); extern BOOLEAN GameOptions (void); +typedef void (NamingCallback) (void); +extern void SetNamingCallback (NamingCallback *); + #endif /* _GAMEOPT_H */ Modified: trunk/sc2/src/uqm/outfit.c =================================================================== --- trunk/sc2/src/uqm/outfit.c 2009-11-16 23:32:01 UTC (rev 3308) +++ trunk/sc2/src/uqm/outfit.c 2009-11-17 08:49:22 UTC (rev 3309) @@ -609,6 +609,15 @@ } } +static void +onNamingDone (void) +{ + // In case player just named a ship, redraw it + LockMutex (GraphicsLock); + DrawFlagshipName (FALSE); + UnlockMutex (GraphicsLock); +} + BOOLEAN DoOutfit (MENU_STATE *pMS) { @@ -620,6 +629,8 @@ pMS->InputFunc = DoOutfit; pMS->Initialized = TRUE; + SetNamingCallback (onNamingDone); + { COUNT num_frames; STAMP s; @@ -747,6 +758,8 @@ DestroyDrawable (ReleaseDrawable (pMS->ModuleFrame)); pMS->ModuleFrame = 0; + SetNamingCallback (NULL); + return (FALSE); } } Modified: trunk/sc2/src/uqm/sis.c =================================================================== --- trunk/sc2/src/uqm/sis.c 2009-11-16 23:32:01 UTC (rev 3308) +++ trunk/sc2/src/uqm/sis.c 2009-11-17 08:49:22 UTC (rev 3309) @@ -237,7 +237,9 @@ { // editing state int i; RECT text_r; - BYTE char_deltas[MAX_DESC_CHARS]; + // XXX: 128 is currently safe, but it would be better to specify + // the size to TextRect() + BYTE char_deltas[128]; BYTE *pchar_deltas; t.baseline.x = 3; Modified: trunk/sc2/src/uqm/state.h =================================================================== --- trunk/sc2/src/uqm/state.h 2009-11-16 23:32:01 UTC (rev 3308) +++ trunk/sc2/src/uqm/state.h 2009-11-17 08:49:22 UTC (rev 3309) @@ -46,9 +46,6 @@ // (GROUP_LIST) in one of the state files extern void BuildGroups (void); -#define MAX_DESC_CHARS 60 -typedef UNICODE GAME_DESC[MAX_DESC_CHARS + 1]; - typedef struct GAME_STATE_FILE GAME_STATE_FILE; #define STARINFO_FILE 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |