| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Source: $ |
| 21 | * $Revision: 27 $ |
| 22 | * $Author: Matt $ |
| 23 | * $Date: 12/06/01 9:26a $ |
| 24 | * |
| 25 | * main menu interface |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/mmItem.cpp $ |
| 28 | * |
| 29 | * 27 12/06/01 9:26a Matt |
| 30 | * Added code to override main menu bitmap. |
| 31 | * |
| 32 | * 26 3/20/00 12:17p Matt |
| 33 | * Merge of Duane's post-1.3 changes. |
| 34 | * Don't show build number in release versions (Mac only) |
| 35 | * |
| 36 | * 25 8/02/99 9:01a Duane |
| 37 | * turned off menusound for mac |
| 38 | * |
| 39 | * 24 4/29/99 3:21a Samir |
| 40 | * reorganized main menu music to work in config, multiplayer, whereever. |
| 41 | * |
| 42 | * 23 4/21/99 4:10p Samir |
| 43 | * changed sound names for table file. |
| 44 | * |
| 45 | * 22 4/20/99 1:58a Matt |
| 46 | * Changed version number text from old UI font to briefing font. |
| 47 | * |
| 48 | * 21 4/18/99 8:35p Samir |
| 49 | * replaced placeholder sounds with newer placeholder sounds. |
| 50 | * |
| 51 | * 20 4/15/99 2:32p Kevin |
| 52 | * Added some code for the Demo |
| 53 | * |
| 54 | * 19 4/14/99 11:48a Matt |
| 55 | * Moved the main menu movie to the movies directory |
| 56 | * |
| 57 | * 18 4/02/99 3:03p Samir |
| 58 | * opengl doesn't use main menu movie. |
| 59 | * |
| 60 | * 17 3/31/99 11:53a Samir |
| 61 | * slow opengl code for movies. |
| 62 | * |
| 63 | * 16 3/23/99 9:06p Samir |
| 64 | * properly sync wait dialog and sound system calls. |
| 65 | * |
| 66 | * 15 3/22/99 10:14a Kevin |
| 67 | * Added a build number to the release builds of main. Also put in code to |
| 68 | * increment the build number each time a release build is done. |
| 69 | * |
| 70 | * 14 3/18/99 10:13a Samir |
| 71 | * new main menu interface. |
| 72 | * |
| 73 | * 13 3/02/99 11:52a Kevin |
| 74 | * Fixes for OEM Beta 4.1 |
| 75 | * |
| 76 | * 12 2/26/99 5:34p Samir |
| 77 | * oem screen. |
| 78 | * |
| 79 | * 11 2/20/99 12:33p Kevin |
| 80 | * Added some OEM stuff |
| 81 | * |
| 82 | * 10 10/23/98 7:05p Samir |
| 83 | * fixed keyboard select prob. |
| 84 | * |
| 85 | * 9 10/22/98 5:23p Matt |
| 86 | * Moved the version number and made it not print the build number if the |
| 87 | * build number was zero. |
| 88 | * |
| 89 | * 8 10/20/98 3:52p Samir |
| 90 | * tweaked main menu look. |
| 91 | * |
| 92 | * 7 10/13/98 6:06p Samir |
| 93 | * fixed booboo. |
| 94 | * |
| 95 | * 6 10/13/98 5:51p Samir |
| 96 | * moved version number |
| 97 | * |
| 98 | * 5 10/13/98 3:16p Samir |
| 99 | * enhanced gadgets some more with new effects (added Credits option). |
| 100 | * |
| 101 | * 4 10/13/98 12:03p Kevin |
| 102 | * Changed use of preprocessors for debug, etc. |
| 103 | * |
| 104 | * 3 10/12/98 4:40p Samir |
| 105 | * fancy effect for hotspots in main menu. |
| 106 | * |
| 107 | * 2 10/12/98 1:46p Samir |
| 108 | * initial new main menu |
| 109 | * |
| 110 | */ |
| 111 | |
| 112 | #include "mmItem.h" |
| 113 | #include "game.h" |
| 114 | #include "program.h" |
| 115 | #include "descent.h" |
| 116 | #include "cinematics.h" |
| 117 | #include "hlsoundlib.h" |
| 118 | #include "soundload.h" |
| 119 | #include "d3music.h" |
| 120 | |
| 121 | #include "ddio.h" |
| 122 | // #include <malloc.h> |
| 123 | #include "mem.h" |
| 124 | |
| 125 | #include <string.h> |
| 126 | |
| 127 | // externed from newui.cpp |
| 128 | extern int UI_frame_result; |
| 129 | |
| 130 | static mmInterface *MM_object = NULL; |
| 131 | // attached window. |
| 132 | mmInterface *mmItem::m_window = NULL; |
| 133 | |
| 134 | const char *MMSoundFiles[N_MM_SOUNDS] = {"MenuBeepEnter", "MenuBeepSelect"}; |
| 135 | void PlayMenuSound(int sound_index, bool wait_till_done = false); |
| 136 | |
| 137 | /* |
| 138 | $$TABLE_SOUND "MenuBeepEnter" |
| 139 | $$TABLE_SOUND "MenuBeepSelect" |
| 140 | */ |
| 141 | |
| 142 | ////////////////////////////////////////////////////////////////////// |
| 143 | // Construction/Destruction |
| 144 | ////////////////////////////////////////////////////////////////////// |
| 145 | |
| 146 | mmItem::mmItem() { m_text = NULL; } |
| 147 | |
| 148 | mmItem::~mmItem() { |
| 149 | if (m_text) |
| 150 | mem_free(m_text); |
| 151 | } |
| 152 | |
| 153 | // attaches a window to all mmitems. |
| 154 | void mmItem::AttachInterface(mmInterface *wnd) { mmItem::m_window = wnd; } |
| 155 | |
| 156 | void mmItem::Create(int id, int key, int x, int y, const char *text, int flags, tmmItemFX init_fx) { |
| 157 | m_alpha = 0; |
| 158 | m_satcount = 0; |
| 159 | m_fxqueue.flush(); |
| 160 | |
| 161 | m_text = text ? mem_strdup(text) : NULL; |
| 162 | m_fxqueue.send(init_fx); |
| 163 | m_curfx = mmItemFXNull; |
| 164 | m_process_speed = 0.0f; |
| 165 | |
| 166 | // set colors |
| 167 | m_colors[0] = MMITEM_COLOR; |
| 168 | m_last_frametime = UI_TIME(); |
| 169 | |
| 170 | UIGadget::Create(m_window, id, x, y, 0, 0, UIF_FIT | flags); |
| 171 | UIGadget::SetHotkey(key); |
| 172 | } |
| 173 | |
| 174 | void mmItem::AddEffect(tmmItemFX fx) { m_fxqueue.send(fx); } |
| 175 | |
| 176 | void mmItem::ClearEffects() { m_fxqueue.flush(); } |
| 177 | |
| 178 | // override: called when resized or before drawing. |
| 179 | void mmItem::OnFormat() { |
| 180 | if (m_Flags & UIF_FIT) { |
| 181 | ui_DrawSetFont(MMITEM_FONT); |
| 182 | |
| 183 | m_W = (m_text ? ui_GetTextWidth(m_text) : 0); |
| 184 | m_H = (m_text ? ui_GetTextHeight(m_text) : 0); |
| 185 | } |
| 186 | |
| 187 | UIGadget::OnFormat(); |
| 188 | } |
| 189 | |
| 190 | // override: behavior when gadget is destroyed. |
| 191 | void mmItem::OnDestroy() { |
| 192 | if (m_text) { |
| 193 | mem_free(m_text); |
| 194 | m_text = NULL; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | void mmItem::OnSelect() { |
| 199 | PlayMenuSound(m_window->SoundHandles[MM_SELECT_SOUND], true); |
| 200 | UIGadget::OnSelect(); |
| 201 | } |
| 202 | |
| 203 | // override: behavior when mouse button is pressed. |
| 204 | void mmItem::OnMouseBtnDown(int btn) { |
| 205 | if (btn == UILMSEBTN) { |
| 206 | LOCK_FOCUS(this); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // override: behavior when mouse button is released. |
| 211 | void mmItem::OnMouseBtnUp(int btn) { |
| 212 | if (btn == UILMSEBTN) { |
| 213 | if (HasFocus()) { |
| 214 | if (PT_IN_GADGET(UIGadget::m_Wnd, this, UI_input.mx, UI_input.my)) { |
| 215 | OnSelect(); |
| 216 | } |
| 217 | } |
| 218 | UNLOCK_FOCUS(this); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // override: behavior when gadget loses input focus. |
| 223 | void mmItem::OnLostFocus() { AddEffect(mmItemFXFadeOutToNormal); } |
| 224 | |
| 225 | // override: behavior when gadget gains input focus. |
| 226 | void mmItem::OnGainFocus() { |
| 227 | AddEffect(mmItemFXFadeInToBright); |
| 228 | PlayMenuSound(m_window->SoundHandles[MM_FOCUS_SOUND]); |
| 229 | } |
| 230 | |
| 231 | // override: behavior when gadget is processed |
| 232 | void mmItem::OnUserProcess() { |
| 233 | // if (HasFocus() && !PT_IN_GADGET(m_Wnd, this, UI_input.mx, UI_input.my)) { |
| 234 | // LostFocus(); |
| 235 | // } |
| 236 | } |
| 237 | |
| 238 | // override: behavior when gadget is being drawn. |
| 239 | void mmItem::OnDraw() { |
| 240 | // if not disabled, do fancy effects. |
| 241 | if (m_text) { |
| 242 | int i; |
| 243 | |
| 244 | ui_DrawSetFont(MMITEM_FONT); |
| 245 | ui_DrawSetTextType(0); |
| 246 | ui_SetCharAlpha(255); |
| 247 | ui_DrawString(m_colors[0], 0, 0, m_text); |
| 248 | ui_DrawSetTextType(UI_TEXTTYPE_SATURATE); |
| 249 | ui_SetCharAlpha((uint8_t)m_alpha); |
| 250 | for (i = 0; i < m_satcount; i++) |
| 251 | ui_DrawString(m_colors[0], 0, 0, m_text); |
| 252 | } |
| 253 | |
| 254 | if ((UI_TIME() - m_last_frametime) >= m_process_speed) { |
| 255 | // process special fx. |
| 256 | switch (m_curfx) { |
| 257 | case mmItemFXNull: |
| 258 | break; |
| 259 | case mmItemFXNormal: |
| 260 | m_alpha = MMITEM_ALPHA; |
| 261 | m_satcount = MMITEM_SAT; |
| 262 | m_process_speed = 0.0f; |
| 263 | m_curfx = mmItemFXNull; |
| 264 | break; |
| 265 | |
| 266 | case mmItemFXFadeOutToNormal: |
| 267 | m_process_speed = 0.075f; |
| 268 | m_satcount = (m_satcount < MMITEM_SAT) ? MMITEM_SAT : (m_satcount - 1); |
| 269 | if (m_satcount == MMITEM_SAT) { |
| 270 | m_curfx = mmItemFXNull; |
| 271 | } |
| 272 | break; |
| 273 | |
| 274 | case mmItemFXFadeInToBright: |
| 275 | m_process_speed = 0.075f; |
| 276 | m_satcount = (m_satcount > 2) ? 2 : (m_satcount + 1); |
| 277 | if (m_satcount == 2) { |
| 278 | m_curfx = mmItemFXNull; |
| 279 | } |
| 280 | break; |
| 281 | } |
| 282 | |
| 283 | // grab new fx. |
| 284 | if (m_curfx == mmItemFXNull) { |
| 285 | tmmItemFX newfx; |
| 286 | if (m_fxqueue.recv(&newfx)) { |
| 287 | m_process_speed = 0.0f; |
| 288 | m_curfx = newfx; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | m_last_frametime = UI_TIME(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | ////////////////////////////////////////////////////////////////////////////// |
| 297 | // MAIN MENU INTERFACE CODE |
| 298 | |
| 299 | #include "stdlib.h" //need this to get _MAX_PATH, which really ought to be in ddio.h |
| 300 | |
| 301 | bool static_menu_background = false; |
| 302 | |
| 303 | void mmInterface::Create() { |
| 304 | int i; |
| 305 | |
| 306 | MM_object = this; |
| 307 | |
| 308 | UIWindow::Create(0, 0, Max_window_w, Max_window_h); |
| 309 | mmItem::AttachInterface(this); |
| 310 | |
| 311 | #ifndef MOVIE_MENU |
| 312 | #if defined(OEM) |
| 313 | if (!LoadLargeBitmap("oemmenu.ogf", &m_art)) { |
| 314 | Error("Unable to load main menu art oemmenu.ogf."); |
| 315 | } |
| 316 | #elif defined(DEMO) |
| 317 | if (!LoadLargeBitmap("demomenu.ogf", &m_art)) { |
| 318 | Error("Unable to load main menu art demomenu.ogf."); |
| 319 | } |
| 320 | #else |
| 321 | if (!LoadLargeBitmap("mainmenu.ogf", &m_art)) { |
| 322 | Error("Unable to load main menu art mainmenu.ogf."); |
| 323 | } |
| 324 | #endif |
| 325 | #else |
| 326 | if (cfexist("mainmenuoverride.ogf")) { |
| 327 | if (!LoadLargeBitmap("mainmenuoverride.ogf", &m_art)) { |
| 328 | Error("Unable to load main menu art mainmenuoverride.ogf."); |
| 329 | } |
| 330 | m_movie = NULL; |
| 331 | static_menu_background = true; |
| 332 | } else { |
| 333 | char filename[_MAX_PATH]; |
| 334 | ddio_MakePath(filename, Base_directory, "movies", "mainmenu", NULL); |
| 335 | m_movie = StartMovie(filename, true); |
| 336 | |
| 337 | if (!m_movie) //[ISB] Didn't find the menu movie? |
| 338 | { |
| 339 | if (!LoadLargeBitmap("mainmenu.ogf", &m_art)) { |
| 340 | Error("Unable to load main menu art mainmenu.ogf."); |
| 341 | } else { |
| 342 | static_menu_background = true; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | #endif |
| 347 | |
| 348 | // load sounds and music |
| 349 | for (i = 0; i < N_MM_SOUNDS; i++) { |
| 350 | SoundHandles[i] = FindSoundName(IGNORE_TABLE(MMSoundFiles[i])); |
| 351 | } |
| 352 | |
| 353 | D3MusicStart("mainmenu.omf"); |
| 354 | SetMusicRegion(MM_MUSIC_REGION); |
| 355 | |
| 356 | SetUICallback(MenuScene); |
| 357 | m_nmenu_items = 0; |
| 358 | } |
| 359 | |
| 360 | // does user interface. |
| 361 | int mmInterface::DoUI() { |
| 362 | UI_frame_result = -1; |
| 363 | ui_ShowCursor(); |
| 364 | |
| 365 | SetUICallback(MenuScene); |
| 366 | |
| 367 | while (UI_frame_result == -1) { |
| 368 | Descent->defer(); |
| 369 | DoUIFrame(); |
| 370 | rend_Flip(); |
| 371 | } |
| 372 | |
| 373 | ui_HideCursor(); |
| 374 | ui_Flush(); |
| 375 | |
| 376 | return UI_frame_result; |
| 377 | } |
| 378 | |
| 379 | // add item. |
| 380 | bool mmInterface::AddItem(int id, int key, const char *text, int type) { |
| 381 | if (m_nmenu_items == N_MMENU_ITEMS) { |
| 382 | Int3(); // N_MMENU_ITEMS needs to be upped! (Samir) |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | m_menuitems[m_nmenu_items].Create(id, key, MMITEM_X, MMITEM_Y + (m_nmenu_items * 20), text, |
| 387 | (type == 1) ? UIF_GROUP_START |
| 388 | : (type == 2) ? UIF_GROUP_END |
| 389 | : (type == 3) ? (UIF_GROUP_START + UIF_GROUP_END) |
| 390 | : 0); |
| 391 | m_nmenu_items++; |
| 392 | |
| 393 | return true; |
| 394 | } |
| 395 | |
| 396 | // When interface is being nuked. |
| 397 | void mmInterface::OnDestroy() { |
| 398 | UIWindow::OnDestroy(); |
| 399 | |
| 400 | D3MusicStop(); |
| 401 | Sound_system.StopAllSounds(); |
| 402 | |
| 403 | if (static_menu_background) { |
| 404 | FreeLargeBitmap(&m_art); |
| 405 | } else { |
| 406 | #ifdef MOVIE_MENU |
| 407 | if (m_movie) { |
| 408 | EndMovie(m_movie); |
| 409 | m_movie = NULL; |
| 410 | } |
| 411 | #else |
| 412 | FreeLargeBitmap(&m_art); |
| 413 | #endif |
| 414 | } |
| 415 | |
| 416 | SetUICallback(DEFAULT_UICALLBACK); |
| 417 | MM_object = NULL; |
| 418 | } |
| 419 | |
| 420 | // displays the copyright text |
| 421 | void mmInterface::CopyrightText() { |
| 422 | int i; |
| 423 | char type[16]; |
| 424 | type[0] = 0; |
| 425 | #ifdef DEMO |
| 426 | strcpy(type, "Demo "); |
| 427 | #endif |
| 428 | |
| 429 | if (PROGRAM(beta)) |
| 430 | strcpy(type, "Beta "); |
| 431 | |
| 432 | #ifdef OEM |
| 433 | strcat(type, "OEM "); |
| 434 | #endif |
| 435 | |
| 436 | if (Program_version.version_type == DEVELOPMENT_VERSION) { |
| 437 | strcat(type, "Dev"); |
| 438 | } else if (Program_version.version_type == RELEASE_VERSION) { |
| 439 | strcat(type, "Ver"); |
| 440 | } |
| 441 | |
| 442 | int x = Max_window_w - 164, y = Max_window_h - 29; // was -128 and -16 |
| 443 | |
| 444 | // attempt to print text nicely. |
| 445 | grtext_SetFont(BRIEFING_FONT); |
| 446 | grtext_SetAlpha(192); |
| 447 | grtext_SetColor(GR_RGB(255, 32, 32)); |
| 448 | |
| 449 | grtext_Printf(x, y, "%s %d.%d.%d %s", type, Program_version.major, |
| 450 | Program_version.minor, Program_version.build, D3_GIT_HASH); |
| 451 | grtext_SetFlags(GRTEXTFLAG_SHADOW); |
| 452 | grtext_Printf(x, y, "%s %d.%d.%d %s", type, Program_version.major, |
| 453 | Program_version.minor, Program_version.build, D3_GIT_HASH); |
| 454 | |
| 455 | grtext_Flush(); |
| 456 | } |
| 457 | |
| 458 | void mmInterface::SetMusicRegion(int region) { |
| 459 | if (region == -1) { |
| 460 | D3MusicStop(); |
| 461 | D3MusicStart("mainmenu.omf"); |
| 462 | SetMusicRegion(MM_MUSIC_REGION); |
| 463 | } else { |
| 464 | D3MusicSetRegion(region, true); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // display menu scene |
| 469 | void MenuScene() { |
| 470 | extern bool NewUI_wait_dialog; // is wait dialog up? |
| 471 | |
| 472 | if (MM_object) { |
| 473 | StartFrame(); |
| 474 | |
| 475 | if (static_menu_background) { |
| 476 | DrawLargeBitmap(&MM_object->m_art, 0, 0, 1.0f); |
| 477 | } else { |
| 478 | #ifdef MOVIE_MENU |
| 479 | FrameMovie(MM_object->m_movie, -1, -1, true); |
| 480 | #else |
| 481 | DrawLargeBitmap(&MM_object->m_art, 0, 0, 1.0f); |
| 482 | #endif |
| 483 | } |
| 484 | |
| 485 | MM_object->CopyrightText(); |
| 486 | |
| 487 | EndFrame(); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | #define N_MENU_SOUND_SLOTS 4 |
| 492 | |
| 493 | void PlayMenuSound(int sound_index, bool wait_till_done) { |
| 494 | int sound_uid; |
| 495 | |
| 496 | Sound_system.BeginSoundFrame(false); |
| 497 | sound_uid = Sound_system.Play2dSound(sound_index, 1.0f); |
| 498 | Sound_system.EndSoundFrame(); |
| 499 | |
| 500 | if (wait_till_done) { |
| 501 | float timer = timer_GetTime(); |
| 502 | while (Sound_system.IsSoundPlaying(sound_uid) && ((timer + 5.0f) > timer_GetTime())) { |
| 503 | Sound_system.BeginSoundFrame(false); |
| 504 | Descent->defer(); |
| 505 | Sound_system.EndSoundFrame(); |
| 506 | } |
| 507 | } |
| 508 | } |