From 24aba77413bc291786ba1bce5d7590a1bd3c4e57 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Sat, 5 Jun 2004 17:44:19 +0000 Subject: [PATCH] Beginnings of a setup menu git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1370 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/Makeinfo | 2 +- sc2/src/sc2code/restart.c | 63 +++++++++++------- sc2/src/sc2code/setupmenu.c | 126 ++++++++++++++++++++++++++++++++++++ sc2/src/sc2code/setupmenu.h | 24 +++++++ 4 files changed, 190 insertions(+), 25 deletions(-) create mode 100644 sc2/src/sc2code/setupmenu.c create mode 100644 sc2/src/sc2code/setupmenu.h diff --git a/sc2/src/sc2code/Makeinfo b/sc2/src/sc2code/Makeinfo index 420065d87..4a3d6d7d5 100644 --- a/sc2/src/sc2code/Makeinfo +++ b/sc2/src/sc2code/Makeinfo @@ -6,7 +6,7 @@ uqm_CFILES="battle.c border.c build.c cleanup.c clock.c collide.c comm.c hyper.c init.c intel.c intro.c ipdisp.c load.c loadship.c master.c melee.c menu.c misc.c oscill.c outfit.c pickmele.c pickship.c plandata.c process.c restart.c save.c settings.c - setup.c ship.c shipstat.c shipyard.c sis.c starbase.c + setup.c setupmenu.c ship.c shipstat.c shipyard.c sis.c starbase.c starcon.c starmap.c state.c status.c tactrans.c trans.c util.c velocity.c weapon.c" diff --git a/sc2/src/sc2code/restart.c b/sc2/src/sc2code/restart.c index 10cfaac8a..b2defec32 100644 --- a/sc2/src/sc2code/restart.c +++ b/sc2/src/sc2code/restart.c @@ -20,6 +20,8 @@ #include "uqmversion.h" #include "controls.h" #include "credits.h" +#include "libs/graphics/gfx_common.h" +#include "setupmenu.h" //Added by Chris @@ -46,6 +48,30 @@ enum QUIT_GAME }; +static void +DrawRestartMenuGraphic (PMENU_STATE pMS) +{ + RECT r; + STAMP s; + + s.frame = CaptureDrawable ( + LoadGraphic (RESTART_PMAP_ANIM) + ); + pMS->CurFrame = s.frame; + GetFrameRect (s.frame, &r); + s.origin.x = (SCREEN_WIDTH - r.extent.width) >> 1; + s.origin.y = (SCREEN_HEIGHT - r.extent.height) >> 1; + + SetContextBackGroundColor (BLACK_COLOR); + BatchGraphics (); + ClearDrawable (); + FlushColorXForms (); + LockMutex (GraphicsLock); + DrawStamp (&s); + UnlockMutex (GraphicsLock); + UnbatchGraphics (); +} + static void DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f) { @@ -140,11 +166,19 @@ else if (InputState & DEVICE_EXIT) return (FALSE); GLOBAL (CurrentActivity) = SUPER_MELEE; break; case SETUP_GAME: - PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 2), - 0, NotPositional (), NULL, GAME_SOUND_PRIORITY); + LockMutex (GraphicsLock); + SetFlashRect (NULL_PTR, (FRAME)0); + UnlockMutex (GraphicsLock); + SetupMenu (); + SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, MENU_SOUND_SELECT); InTime = GetTimeCounter (); + SetTransitionSource (NULL); + BatchGraphics (); + DrawRestartMenuGraphic (pMS); + DrawRestartMenu ((BYTE)~0, pMS->CurState, pMS->CurFrame); + ScreenTransition (3, NULL); + UnbatchGraphics (); return TRUE; - break; case QUIT_GAME: PlaySoundEffect (SetAbsSoundIndex (MenuSounds, 1), 0, NotPositional (), NULL, GAME_SOUND_PRIORITY); @@ -264,29 +298,10 @@ LastActivity = WON_LAST_BATTLE; LastActivity = NextActivity = 0; { - RECT r; - STAMP s; - - s.frame = CaptureDrawable ( - LoadGraphic (RESTART_PMAP_ANIM) - ); - MenuState.CurFrame = s.frame; - GetFrameRect (s.frame, &r); - s.origin.x = (SCREEN_WIDTH - r.extent.width) >> 1; - s.origin.y = (SCREEN_HEIGHT - r.extent.height) >> 1; SleepThreadUntil (XFormColorMap ((COLORMAPPTR)black_buf, TimeOut)); if (TimeOut == ONE_SECOND / 8) SleepThread (ONE_SECOND * 3); - - SetContextBackGroundColor (BLACK_COLOR); - BatchGraphics (); - ClearDrawable (); - FlushColorXForms (); - LockMutex (GraphicsLock); - DrawStamp (&s); - UnlockMutex (GraphicsLock); - UnbatchGraphics (); - + DrawRestartMenuGraphic (&MenuState); FlushInput (); GLOBAL (CurrentActivity) &= ~CHECK_ABORT; SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, MENU_SOUND_SELECT); @@ -295,7 +310,7 @@ LastActivity = WON_LAST_BATTLE; LockMutex (GraphicsLock); SetFlashRect ((PRECT)0, (FRAME)0); UnlockMutex (GraphicsLock); - DestroyDrawable (ReleaseDrawable (s.frame)); + DestroyDrawable (ReleaseDrawable (MenuState.CurFrame)); if (GLOBAL (CurrentActivity) == (ACTIVITY)~0) goto TimedOut; diff --git a/sc2/src/sc2code/setupmenu.c b/sc2/src/sc2code/setupmenu.c new file mode 100644 index 000000000..ab4225d13 --- /dev/null +++ b/sc2/src/sc2code/setupmenu.c @@ -0,0 +1,126 @@ +// Copyright Michael Martin, 2004. + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "starcon.h" +#include "setupmenu.h" +#include "controls.h" +#include "libs/graphics/widgets.h" + +typedef struct setup_menu_state { + BOOLEAN (*InputFunc) (struct setup_menu_state *pInputState); + COUNT MenuRepeatDelay; + BOOLEAN initialized; + int anim_frame_count; + DWORD NextTime; +} SETUP_MENU_STATE; + +typedef SETUP_MENU_STATE *PSETUP_MENU_STATE; + +#define NUM_STEPS 20 +#define X_STEP (SCREEN_WIDTH / NUM_STEPS) +#define Y_STEP (SCREEN_HEIGHT / NUM_STEPS) +#define MENU_FRAME_RATE (ONE_SECOND / 60) + +BOOLEAN +DoSetupMenu (PSETUP_MENU_STATE pInputState) +{ + if (!pInputState->initialized) + { + SetDefaultMenuRepeatDelay (); + pInputState->anim_frame_count = NUM_STEPS; + pInputState->initialized = TRUE; + pInputState->NextTime = GetTimeCounter (); + } + + BatchGraphics (); + if (pInputState->anim_frame_count) + { + RECT r; + COLOR bg, dark, medium; + int frame = --pInputState->anim_frame_count; + + r.corner.x = ((frame * X_STEP) >> 1) + 2; + r.corner.y = ((frame * Y_STEP) >> 1) + 2; + r.extent.width = X_STEP * (NUM_STEPS - frame) - 4; + r.extent.height = Y_STEP * (NUM_STEPS - frame) - 4; + + dark = BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x08), 0x01); + medium = BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x10), 0x01); + bg = BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x1A), 0x09); + + DrawShadowedBox(&r, bg, dark, medium); + } + else + { + RECT r; + COLOR bg, dark, medium, text, oldtext; + FONT oldfont = SetContextFont (StarConFont); + FONTEFFECT oldFontEffect = SetContextFontEffect (0, 0, 0); + TEXT t; + + r.corner.x = 2; + r.corner.y = 2; + r.extent.width = SCREEN_WIDTH - 4; + r.extent.height = SCREEN_HEIGHT - 4; + + dark = BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x08), 0x01); + medium = BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x10), 0x01); + bg = BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x1A), 0x09); + text = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x00), 0x0E); + + DrawShadowedBox(&r, bg, dark, medium); + + oldtext = SetContextForeGroundColor (text); + t.baseline.x = r.corner.x + (r.extent.width >> 1); + t.baseline.y = r.corner.y + 8; + t.pStr = "Sorry!"; + t.align = ALIGN_CENTER; + t.valign = VALIGN_BOTTOM; + t.CharCount = ~0; + font_DrawText (&t); + + t.baseline.y += 100; + t.pStr = "The Setup menu has not yet been implemented."; + font_DrawText (&t); + + t.baseline.y += 8; + t.pStr = "Please press Select or Cancel to return."; + font_DrawText (&t); + + SetContextFontEffect (oldFontEffect.type, oldFontEffect.from, oldFontEffect.to); + SetContextFont (oldfont); + SetContextForeGroundColor (oldtext); + } + + UnbatchGraphics (); + SleepThreadUntil (pInputState->NextTime + MENU_FRAME_RATE); + pInputState->NextTime = GetTimeCounter (); + return !(PulsedInputState.key[KEY_MENU_CANCEL] || + PulsedInputState.key[KEY_MENU_SELECT]); +} + +void +SetupMenu (void) +{ + SETUP_MENU_STATE s; + + s.InputFunc = DoSetupMenu; + s.initialized = FALSE; + SetMenuSounds (0, MENU_SOUND_SELECT | MENU_SOUND_CANCEL); + DoInput ((PVOID)&s, TRUE); +} diff --git a/sc2/src/sc2code/setupmenu.h b/sc2/src/sc2code/setupmenu.h new file mode 100644 index 000000000..adc67f6b1 --- /dev/null +++ b/sc2/src/sc2code/setupmenu.h @@ -0,0 +1,24 @@ +// Copyright Michael Martin, 2004. + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef _SETUPMENU_H +#define _SETUPMENU_H + +void SetupMenu (void); + +#endif // _SETUPMENU_H