2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/shock/shkmenu.cpp,v 1.27 2000/02/19 13:25:39 toml Exp $
47 #include <dbmem.h> // must be last header!
49 ////////////////////////////////////////////////////////////
50 // DARK METAGAME MENUS
56 // Some day, I expect this will
57 // deal with levers and other festoonery
60 class cMenuBase
: public cDarkPanel
, public cUiAnim
63 cMenuBase(const sDarkPanelDesc
* desc
)
64 : cDarkPanel(desc
), cUiAnim(desc
->panel_name
,INTERFACE_PATH
)
83 void OnLoopMsg(eLoopMessage msg
, tLoopMessageData data
)
85 cUiAnim::OnLoopMsg(msg
,data
);
86 cDarkPanel::OnLoopMsg(msg
,data
);
90 //------------------------------------------------------------
94 // Avoid name conflicts
96 typedef cShockMainMenu cMainMenu
;
98 EXTERN
void SwitchToShockNewGameMode(BOOL push
);
101 class cShockMainMenu
: public cMenuBase
103 static sDarkPanelDesc gDesc
;
106 cMainMenu() : cMenuBase(&gDesc
)
110 cMainMenu(const sDarkPanelDesc
* pdesc
) : cMenuBase(pdesc
)
130 void OnButtonList(ushort action
, int button
)
132 if (!(action
& BUTTONGADG_LCLICK
))
135 //SchemaPlay((Label *)"menubutt",NULL);
140 SwitchToShockNewGameMode(TRUE
);
144 SwitchToShockLoadGameMode(TRUE
);
148 SwitchToShockOptionsMode(TRUE
);
152 MoviePanel("credits.avi");
156 MoviePanel("cs1.avi");
161 AutoAppIPtr_(Application
,pApp
);
173 void OnEscapeKey() // trap escape
179 // Main Menu descriptor
182 static const char* main_button_names
[] =
192 sDarkPanelDesc
cMainMenu::gDesc
=
195 cMainMenu::kNumRects
,
196 cMainMenu::kNumRects
,
197 cMainMenu::kNumRects
,
204 //------------------------------------------------------------
208 class cShockNetMainMenu
: public cShockMainMenu
210 static sDarkPanelDesc gDesc
;
211 typedef cShockMainMenu cParent
;
214 cShockNetMainMenu() : cParent(&gDesc
)
234 void OnButtonList(ushort action
, int button
)
236 if (!(action
& BUTTONGADG_LCLICK
))
242 SwitchToShockMultiplayUIMode(TRUE
);
246 cParent::OnButtonList(action
,button
);
252 void OnLoopMsg(eLoopMessage msg
, tLoopMessageData data
)
254 cParent::OnLoopMsg(msg
,data
);
260 // Disconnect any net session we may be in
261 AutoAppIPtr(NetManager
);
262 pNetManager
->Leave();
263 // If we had network synch disabled, make sure it's normal
276 // Main Menu descriptor
279 static const char* netmain_button_names
[] =
290 sDarkPanelDesc
cShockNetMainMenu::gDesc
=
293 cShockNetMainMenu::kNumRects
,
294 cShockNetMainMenu::kNumRects
,
295 cShockNetMainMenu::kNumRects
,
296 netmain_button_names
,
305 static cMainMenu
* gpMainMenu
= NULL
;
307 void SwitchToShockMainMenuMode(BOOL push
)
311 cAutoIPtr
<IPanelMode
> panel
= gpMainMenu
->GetPanelMode();
312 panel
->Switch((push
) ? kLoopModePush
: kLoopModeSwitch
);
317 const sLoopInstantiator
* DescribeShockMainMenuMode(void)
321 cAutoIPtr
<IPanelMode
> panel
= gpMainMenu
->GetPanelMode();
322 return panel
->Instantiator();
327 //------------------------------------------------------------
331 // Avoid name conflicts
333 typedef cShockSimMenu cSimMenu
;
335 class cShockSimMenu
: public cMenuBase
337 static sDarkPanelDesc gDesc
;
340 cSimMenu() : cMenuBase(&gDesc
)
357 void OnButtonList(ushort action
, int button
)
359 if (!(action
& BUTTONGADG_LCLICK
))
362 //SchemaPlay((Label *)"menubutt",NULL);
364 AutoAppIPtr(NetManager
);
370 cAutoIPtr
<IPanelMode
> mode
= GetPanelMode();
377 SwitchToShockOptionsMode(TRUE
);
381 if (pNetManager
->IsNetworkGame())
384 ShockGetLevelName(levelname
,sizeof(levelname
));
385 // okay this is hack-a-riffic
386 if ((stricmp(levelname
,"station") == 0) || (stricmp(levelname
,"earth") == 0))
389 SwitchToShockSaveGameMode(TRUE
);
393 SwitchToShockLoadGameMode(TRUE
);
400 // Unwind to the main menu
401 cAutoIPtr
<IPanelMode
> panel
= gpMainMenu
->GetPanelMode();
402 panel
->Switch(kLoopModeUnwindTo
);
410 Warning(("%s button is unimplemented\n",gDesc
.string_names
[button
]));
418 // Sim Menu descriptor
421 static const char* sim_button_names
[] =
430 sDarkPanelDesc
cSimMenu::gDesc
=
440 static cSimMenu
* gpSimMenu
= NULL
;
442 void SwitchToShockSimMenuMode(BOOL push
)
446 cAutoIPtr
<IPanelMode
> panel
= gpSimMenu
->GetPanelMode();
447 panel
->Switch((push
) ? kLoopModePush
: kLoopModeSwitch
);
452 const sLoopInstantiator
* DescribeShockSimMenuMode(void)
456 cAutoIPtr
<IPanelMode
> panel
= gpSimMenu
->GetPanelMode();
457 return panel
->Instantiator();
463 //------------------------------------------------------------
469 #define DIFF2BUTT(x) (((x) < MIN_DIFF) ? MIN_DIFF - 1 : (x) - 1)
470 #define BUTT2DIFF(x) ((x) + 1)
472 class cShockNewGame
: public cDarkPanel
474 static sDarkPanelDesc gDesc
;
480 memset(&mDiffButtons
,0,sizeof(mDiffButtons
));
490 kDifficulty
= kNumButts
,
498 kNumDiffs
= kNumRects
- kDiff0
,
504 LGadButtonList mDiffButtons
;
505 DrawElement mDiffElems
[kNumDiffs
];
506 cStr mDiffStrs
[kNumDiffs
];
508 static bool DiffCB (ushort action
, int button
, void *data
, LGadBox
*)
510 g_diff
= BUTT2DIFF(button
);
516 cDarkPanel::InitUI();
518 // default to current style colors
519 AssertMsg(GetCurrentStyle(),"No current style for diff defaults");
520 memset(&mDiffStyle
,0,sizeof(mDiffStyle
));
521 memcpy(mDiffStyle
.colors
,GetCurrentStyle()->colors
,sizeof(mDiffStyle
.colors
));
522 uiGameLoadStyle("diff_",&mDiffStyle
,mResPath
);
524 // set up drawlelems for diff
525 for (int i
= 0; i
< kNumDiffs
; i
++)
527 DrawElement
& elem
= mDiffElems
[i
];
528 memset(&elem
,0,sizeof(elem
));
531 sprintf(buf
,"diff_%d",i
);
532 mDiffStrs
[i
] = FetchUIString(panel_name
,buf
,mResPath
);
533 elem
.draw_type
= DRAWTYPE_TEXT
;
534 elem
.draw_data
= (void*)(const char*)mDiffStrs
[i
];
535 elem
.draw_flags
= INTERNAL(DRAWFLAG_INT_TRANSP
);
538 LGadButtonListDesc desc
=
541 &mRects
[(int)kDiff0
],
545 BUTTONLIST_RADIO_FLAG
,
548 LGadCreateButtonListDesc(&mDiffButtons
,LGadCurrentRoot(),&desc
);
550 //set the current difficulty setting
551 if (g_diff
< MIN_DIFF
) g_diff
= MIN_DIFF
;
552 LGadRadioButtonSelect (&mDiffButtons
, DIFF2BUTT(g_diff
));
553 int flags
= LGadBoxFlags(&mDiffButtons
);
554 LGadBoxSetFlags(&mDiffButtons
, flags
| BOXFLAG_CLEAR
);
555 LGadBoxSetStyle(&mDiffButtons
,&mDiffStyle
);
560 g_diff
= BUTT2DIFF(LGadRadioButtonSelection(&mDiffButtons
));
561 LGadDestroyButtonList(&mDiffButtons
);
562 memset(&mDiffElems
,0,sizeof(mDiffElems
));
563 for (int i
= 0; i
< kNumDiffs
; i
++)
566 uiGameUnloadStyle(&mDiffStyle
);
567 cDarkPanel::TermUI();
573 // Draw the difficulty string. This is a lot of code to draw a lousy string.
575 cStr str
= FetchUIString(panel_name
,"difficulty",mResPath
); // copy the string
576 char* s
= (char*)(const char*)str
; // get a mutable pointer
578 Rect
& r
= mRects
[(int)kDifficulty
];
581 GUIsetup(&c
,&r
,GUIcomposeFlags(ComposeFlagClear
|ComposeFlagRead
),GUI_CANV_ANY
);
583 guiStyleSetupFont(&mDiffStyle
,StyleFontTitle
);
584 gr_set_fcolor(guiStyleGetColor(&mDiffStyle
,StyleColorText
));
586 gr_font_string_wrap(gr_get_font(),s
,RectWidth(&r
));
589 gr_string_size(s
,&w
,&h
);
591 gr_string(s
,(RectWidth(&r
) - w
)/2,(RectHeight(&r
) - h
)/2);
592 // gr_string(s,gr_char_width('X'),(RectHeight(&r) - h)/2);
594 guiStyleCleanupFont(&mDiffStyle
,StyleFontTitle
) ;
599 // Make sure the buttonlist gets drawn
601 region_expose(LGadBoxRegion(&mDiffButtons
),LGadBoxRect(&mDiffButtons
));
605 // Actually do the work of starting a game
610 // Push the init game mode, and the initial cutscene
611 // mode to the mode stack. That way the cutscene happens first.
612 SwitchToShockInitGame(FALSE
);
613 MoviePanel("cs1.avi");
619 void OnButtonList(ushort action
, int button
)
621 if (!(action
& BUTTONGADG_LCLICK
))
624 //SchemaPlay((Label *)"menubutt",NULL);
635 SwitchToShockOptionsMode(TRUE
);
640 cAutoIPtr
<IPanelMode
> mode
= GetPanelMode();
649 void OnLoopMsg(eLoopMessage msg
, tLoopMessageData data
)
656 case kMsgNormalFrame
:
657 if (mGo
) StartGame();
661 cDarkPanel::OnLoopMsg(msg
,data
);
668 // NewGame Menu descriptor
671 static const char* newgame_button_names
[] =
678 sDarkPanelDesc
cShockNewGame::gDesc
=
681 cShockNewGame::kNumButts
,
682 cShockNewGame::kNumRects
,
683 cShockNewGame::kNumButts
,
684 newgame_button_names
,
691 static cShockNewGame
* gpNewGame
= NULL
;
693 void SwitchToShockNewGameMode(BOOL push
)
697 cAutoIPtr
<IPanelMode
> panel
= gpNewGame
->GetPanelMode();
698 panel
->Switch((push
) ? kLoopModePush
: kLoopModeSwitch
);
703 const sLoopInstantiator
* DescribeShockNewGameMode(void)
707 cAutoIPtr
<IPanelMode
> panel
= gpNewGame
->GetPanelMode();
708 return panel
->Instantiator();
713 //------------------------------------------------------------------
718 void init_commands();
721 void ShockMenusInit()
723 if (config_is_defined("netplay_ui"))
724 gpMainMenu
= new cShockNetMainMenu
;
726 gpMainMenu
= new cMainMenu
;
727 gpSimMenu
= new cSimMenu
;
728 gpNewGame
= new cShockNewGame
;
732 // default difficulty
733 g_diff
= MIN_DIFF
+ 1;
735 // What the hell. Initialize the loading screens too
737 ShockMultiplayUIInit();
740 void ShockMenusTerm()
747 ShockMultiplayUITerm();
751 //----------------------------------------
755 static void do_mainmenu()
757 SwitchToShockMainMenuMode(TRUE
);
760 static void do_simmenu()
762 // don't do anything if the trigger is pulled
763 AutoAppIPtr(PlayerGun
);
764 ObjID gun
= pPlayerGun
->Get();
765 if ((gun
!= OBJ_NULL
) && pPlayerGun
->IsTriggerPulled())
768 // throw any objects on the cursor into the world
769 if (drag_obj
!= OBJ_NULL
)
771 ThrowObj(drag_obj
,PlayerObject());
774 SwitchToShockSimMenuMode(TRUE
);
779 static Command commands
[] =
781 { "main_menu", FUNC_VOID
, do_mainmenu
, "Go to main menu.", HK_ALL
},
782 { "sim_menu", FUNC_VOID
, do_simmenu
, "Go to sim menu.", HK_ALL
},
787 static void init_commands()
789 COMMANDS(commands
,HK_ALL
);