| 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 | * $Logfile: /DescentIII/main/newui.cpp $ |
| 21 | * $Revision: 85 $ |
| 22 | * $Date: 4/29/99 3:20a $ |
| 23 | * $Author: Samir $ |
| 24 | * |
| 25 | * New UI Enhancements for D3 |
| 26 | * |
| 27 | * $Log: /DescentIII/main/newui.cpp $ |
| 28 | * |
| 29 | * 85 4/29/99 3:20a Samir |
| 30 | * took out Newui_wait_flag. Not needed. |
| 31 | * |
| 32 | * 84 4/28/99 1:55a Samir |
| 33 | * interface change for UIEdit. |
| 34 | * |
| 35 | * 83 4/25/99 3:35a Jeff |
| 36 | * added a please wait popup dialog when entering telcom |
| 37 | * |
| 38 | * 82 4/22/99 7:41p Matt |
| 39 | * Use new art for old UI. |
| 40 | * |
| 41 | * 81 4/21/99 2:15p Samir |
| 42 | * table file filter fixes. |
| 43 | * |
| 44 | * 80 4/20/99 3:32p Kevin |
| 45 | * made it possible for an edit box to not have a cancel button... used it |
| 46 | * for choosing team count for server |
| 47 | * |
| 48 | * 79 4/20/99 11:46a Samir |
| 49 | * numerous ui 'feel' fixes. |
| 50 | * |
| 51 | * 78 4/18/99 7:55p Samir |
| 52 | * new progress indicator for delays when loading data. |
| 53 | * |
| 54 | * 77 4/15/99 5:28p Samir |
| 55 | * added advanced messagebox |
| 56 | * |
| 57 | * 76 4/06/99 10:44p Samir |
| 58 | * Fixed residue from changes to UID_OK and UID_CANCEL. |
| 59 | * |
| 60 | * 75 3/23/99 9:05p Samir |
| 61 | * don't do sound system calls in wait dialog. time with main menu, since |
| 62 | * that's the place where we have to sync sound initialization with menu |
| 63 | * selection. |
| 64 | * |
| 65 | * 74 3/18/99 10:13a Samir |
| 66 | * wait dialog tied more to menu system. |
| 67 | * |
| 68 | * 73 3/04/99 6:09p Samir |
| 69 | * changed DoWaitMessage to properly center (works for single lines, not |
| 70 | * sure about multiple lines, but since most messages are single lined, it |
| 71 | * works for now.) |
| 72 | * |
| 73 | * 72 3/03/99 5:13a Jeff |
| 74 | * added DoWaitMessage() |
| 75 | * |
| 76 | * 71 3/03/99 4:16a Samir |
| 77 | * added fix for DoEditDialog, setting focus on edit gadget by default for |
| 78 | * all sheets with editboxes (1st one.) |
| 79 | * |
| 80 | * 70 3/01/99 6:55p Samir |
| 81 | * fixed saturation problems with old ui text. |
| 82 | * |
| 83 | * 69 2/27/99 8:34p Samir |
| 84 | * NewuiGameWindow inherits newuiTiledWindow. |
| 85 | * |
| 86 | * 68 2/27/99 4:17p Jeff |
| 87 | * crude fix for text wrapping in DoEdit |
| 88 | * |
| 89 | * 67 2/21/99 6:39p Samir |
| 90 | * new edit box. |
| 91 | * |
| 92 | * 66 2/16/99 12:06p Samir |
| 93 | * added new ui api. |
| 94 | * |
| 95 | * 65 2/07/99 1:17a Jeff |
| 96 | * peppered UI dialogs that were missing NEWUIRES_FORCEQUIT to handle it |
| 97 | * |
| 98 | * 64 1/28/99 6:49p Samir |
| 99 | * frame limit ui system. |
| 100 | * |
| 101 | * 63 12/09/98 4:17p Samir |
| 102 | * messageboxes use new art. |
| 103 | * |
| 104 | * 62 11/19/98 5:40p Kevin |
| 105 | * Demo system |
| 106 | * |
| 107 | * 61 11/02/98 6:00p Jeff |
| 108 | * fixed MessageBox to use new UI artwork...had to redo the way it |
| 109 | * calculates button centers |
| 110 | * |
| 111 | * 60 10/30/98 1:34p Samir |
| 112 | * better sizable UIwindow. |
| 113 | * |
| 114 | * 59 10/23/98 12:53p Samir |
| 115 | * bail from DoUIFrameWithoutInput for multiplayer too. |
| 116 | * |
| 117 | * 58 10/18/98 2:59p Jason |
| 118 | * fixes for beta4 |
| 119 | * |
| 120 | * 57 10/16/98 4:20p Samir |
| 121 | * hotspots replaced by keys Y or N for yesno messagebox. |
| 122 | * |
| 123 | * 56 10/14/98 11:24p Jeff |
| 124 | * fixed DoMessageBox (so keys work in it) |
| 125 | * |
| 126 | * 55 10/12/98 10:23a Samir |
| 127 | * made UI_frame_result non-static. |
| 128 | * |
| 129 | * 54 10/11/98 3:01a Jeff |
| 130 | * made some dialogs multiplayer friendly with multi_bail_ui_menu |
| 131 | * |
| 132 | * 53 10/08/98 7:31p Samir |
| 133 | * moved multi_bail_menu flag to gamesequence.cpp. |
| 134 | * |
| 135 | * 52 10/07/98 6:29p Samir |
| 136 | * bail if multiplayer game ended in ui. |
| 137 | * |
| 138 | * 51 10/07/98 11:24a Jeff |
| 139 | * fixed text centering function |
| 140 | * |
| 141 | * 50 10/06/98 5:34p Jeff |
| 142 | * various UI changes/improvements |
| 143 | * |
| 144 | * 49 9/23/98 6:19p Jeff |
| 145 | * finished up (hopefully) updating the config/ui dialogs to meet our |
| 146 | * standard. Keyboard/joystick config still needs some work |
| 147 | * |
| 148 | * 48 9/23/98 3:07p Jeff |
| 149 | * updated the colors and various other items of config and UI |
| 150 | * |
| 151 | * 47 9/22/98 3:55p Samir |
| 152 | * moved simple callback to NewUI system. |
| 153 | * |
| 154 | * 46 9/14/98 11:22a Samir |
| 155 | * enhanced editboxes |
| 156 | * |
| 157 | * 45 9/10/98 6:33p Samir |
| 158 | * messageboxes should use up to 3 lines of text without a problem. |
| 159 | * |
| 160 | * 44 9/02/98 6:50p Samir |
| 161 | * added new combo box. |
| 162 | * |
| 163 | * 43 9/01/98 4:12p Samir |
| 164 | * added screenshot caparbilities. |
| 165 | * |
| 166 | * 42 9/01/98 12:29p Jeff |
| 167 | * error handling in DoMessageBox (handles extra long strings) |
| 168 | * |
| 169 | * 41 8/31/98 12:38p Samir |
| 170 | * took out hotspots in messageboxes. functionality implented internally. |
| 171 | * |
| 172 | * 40 8/27/98 5:03p Kevin |
| 173 | * Prettied up multiplayer screens and fixed some bugs. |
| 174 | * |
| 175 | * 39 8/27/98 2:51p Samir |
| 176 | * you must specify UIF_BORDER to print the border for a NewUIWindow. |
| 177 | * |
| 178 | * 38 8/24/98 3:12p Samir |
| 179 | * fixed listbox text clipping. |
| 180 | * |
| 181 | * 37 8/20/98 6:46p Samir |
| 182 | * added DoEditDialog. |
| 183 | * |
| 184 | * 36 8/14/98 7:37p Matt |
| 185 | * Since PSFILENAME_LEN is now considered to be the max length of the |
| 186 | * string itself (not counting the terminating null), buffers for file |
| 187 | * name need to be PSFILENAME_LEN+1 bytes long. |
| 188 | * |
| 189 | * 35 7/22/98 2:38p Jeff |
| 190 | * added Y and N keys for the DoMessageBox |
| 191 | * |
| 192 | * 34 6/25/98 12:34p Jeff |
| 193 | * added enter and esc key to DoMessageBox |
| 194 | * |
| 195 | * 33 6/24/98 5:16p Matt |
| 196 | * Don't reset screen mode in DoMessageBox(), so we still see the game |
| 197 | * screen when the pause message is up. |
| 198 | * |
| 199 | * 32 6/22/98 2:34p Samir |
| 200 | * added ability to use a bitmap as background for NewUIWindows. |
| 201 | * |
| 202 | * 31 6/16/98 10:54a Jeff |
| 203 | * |
| 204 | * 30 6/01/98 10:57a Jeff |
| 205 | * (Samir) Fixed bug if a file couldn't be loaded |
| 206 | * |
| 207 | * 29 5/26/98 8:15p Samir |
| 208 | * implemented UIFileDialog's ONDestroy function. |
| 209 | * |
| 210 | * 28 5/25/98 8:18p Samir |
| 211 | * File dialogs implemented. |
| 212 | * |
| 213 | * 27 5/24/98 2:57a Jeff |
| 214 | * updated DoMessageBox to use NewUIButton |
| 215 | * |
| 216 | * 26 5/19/98 6:23p Samir |
| 217 | * added NewUIButton |
| 218 | * |
| 219 | * 25 5/08/98 12:55p Samir |
| 220 | * improved ui handling when switch screen modes. |
| 221 | * |
| 222 | * 24 4/29/98 12:55p Samir |
| 223 | * added titile bar to NewUIWindow. |
| 224 | * |
| 225 | * 23 4/18/98 2:09a Samir |
| 226 | * error checking. |
| 227 | * |
| 228 | * 22 4/13/98 7:01p Samir |
| 229 | * added snazzy listbox and edit box art. |
| 230 | * |
| 231 | * 21 4/10/98 7:51p Samir |
| 232 | * added ui_Flush |
| 233 | * |
| 234 | * 20 4/02/98 12:39p Samir |
| 235 | * don't clear screen in NULL callback. |
| 236 | * |
| 237 | * 19 4/02/98 11:12a Samir |
| 238 | * Always set screen mode to menu for message boxes, and clear screen if |
| 239 | * UICallback if 0. |
| 240 | * |
| 241 | * 18 3/24/98 10:45a Samir |
| 242 | * Added GetUICallback. |
| 243 | * |
| 244 | * 17 3/13/98 12:00p Jeff |
| 245 | * Fixed up DoMessageBox so the text position is correct, it prints a |
| 246 | * window title, and you can specify text color |
| 247 | * |
| 248 | * 16 3/11/98 2:35p Samir |
| 249 | * New message box implemented. |
| 250 | * |
| 251 | * 15 3/10/98 7:26p Samir |
| 252 | * Added new slider. |
| 253 | * |
| 254 | * 14 3/10/98 12:49p Samir |
| 255 | * Bitmapped dialog supported. |
| 256 | * |
| 257 | * 13 3/05/98 6:38p Samir |
| 258 | * Use UI_FONT now. |
| 259 | * |
| 260 | * 12 3/03/98 12:09p Samir |
| 261 | * Clear out keyboard buffer after UI is done. |
| 262 | * |
| 263 | * 11 3/02/98 5:53p Samir |
| 264 | * Default value for alpha of windows is set. |
| 265 | * |
| 266 | * 10 2/15/98 7:07p Samir |
| 267 | * Updated NewUIWindow to UIWindow's changes. |
| 268 | * |
| 269 | * 9 2/13/98 6:37p Samir |
| 270 | * Added DoUIFrameWithoutInput. |
| 271 | * |
| 272 | * 8 1/30/98 7:33p Samir |
| 273 | * Took out 'ok' button. |
| 274 | * |
| 275 | * 7 1/30/98 7:04p Samir |
| 276 | * Added the first NewUIWindow class. |
| 277 | * |
| 278 | * 6 1/26/98 2:15p Samir |
| 279 | * Message box params are char*. |
| 280 | * |
| 281 | * 5 1/18/98 4:22p Samir |
| 282 | * Implemented new UIItem system. |
| 283 | * |
| 284 | * 4 1/13/98 6:29p Samir |
| 285 | * Moved Large Bitmap code from Menu.cpp to newui.cpp. |
| 286 | * |
| 287 | * 3 1/08/98 12:18p Samir |
| 288 | * New menu interface. |
| 289 | * |
| 290 | * 2 1/05/98 10:56a Samir |
| 291 | * New menu stuff. |
| 292 | * |
| 293 | * 1 1/02/98 2:09p Samir |
| 294 | * Initial revision. |
| 295 | * |
| 296 | * |
| 297 | * $NoKeywords: $ |
| 298 | */ |
| 299 | |
| 300 | #include "newui.h" |
| 301 | #include "game.h" |
| 302 | #include "descent.h" |
| 303 | #include "renderer.h" |
| 304 | #include "3d.h" |
| 305 | #include "gamefont.h" |
| 306 | #include "bitmap.h" |
| 307 | #include "ddio.h" |
| 308 | #include "stringtable.h" |
| 309 | #include "textaux.h" |
| 310 | #include "newui_core.h" |
| 311 | #include "hlsoundlib.h" |
| 312 | #include "dedicated_server.h" |
| 313 | |
| 314 | #include <stdlib.h> |
| 315 | #include <string.h> |
| 316 | #include <stdarg.h> |
| 317 | |
| 318 | #define MSGBOX_HEIGHT msgbox.H() |
| 319 | #define BTN_WIDTH 96 |
| 320 | #define NEWUI_FRAMETIME (1.0f / 25.0f) |
| 321 | |
| 322 | ////////////////////////////////////////////////////////////////////////////// |
| 323 | // Declarations |
| 324 | |
| 325 | static struct { |
| 326 | int bmp; |
| 327 | chunked_bitmap chunk; |
| 328 | } NewUI_bitmap_list[NEWUIBMP_NUM]; |
| 329 | |
| 330 | static bool NewUI_init = false; |
| 331 | |
| 332 | // closes New UI system |
| 333 | void NewUIClose(); |
| 334 | |
| 335 | ////////////////////////////////////////////////////////////////////////////// |
| 336 | // Functions |
| 337 | |
| 338 | // returns x coordinates to use to determine center position of text items for in a window/dialog |
| 339 | // width - total width of dialog/window |
| 340 | // gap - size (in pixels) of the gap you want between the left and right item |
| 341 | // left_item_width - the width (in pixels) of the left item |
| 342 | // right_item_width - the widht (in pixels) of the right item |
| 343 | // lx - will contain the left item's x coord |
| 344 | // rx - will contain the right item's x coord |
| 345 | void GetCenteredTextPos(int width, int gap, int left_item_width, int right_item_width, int *lx, int *rx) { |
| 346 | int center_x = width / 2; |
| 347 | |
| 348 | // the left side of the left item should be same distance as the right side of the right item is from the middle |
| 349 | |
| 350 | int width_of_items = gap + left_item_width + right_item_width; |
| 351 | int center_of_items = width_of_items / 2; |
| 352 | |
| 353 | int left_gap = 0, right_gap = 0; |
| 354 | |
| 355 | left_gap = center_of_items - left_item_width; |
| 356 | right_gap = center_of_items - right_item_width; |
| 357 | |
| 358 | *lx = center_x - (left_gap + left_item_width); |
| 359 | *rx = center_x + right_gap; |
| 360 | } |
| 361 | |
| 362 | // returns x coordinates to use to determine center position of text items for in a window/dialog |
| 363 | // width - total width of dialog/window |
| 364 | // gap - size (in pixels) of the gap you want between the left and right item |
| 365 | // left_item_width - the width (in pixels) of the left item |
| 366 | // middle_item_width - the width (in pixels) of the middle item |
| 367 | // right_item_width - the width (in pixels) of the right item |
| 368 | // lx - will contain the left item's x coord |
| 369 | // rx - will contain the right item's x coord |
| 370 | // mx - will contain the middle item's x coord |
| 371 | void GetCenteredTextPos(int width, int gap, int left_item_width, int middle_item_width, int right_item_width, int *lx, |
| 372 | int *mx, int *rx) { |
| 373 | int center_x = width / 2; |
| 374 | int width_of_items = 2 * gap + left_item_width + middle_item_width + right_item_width; |
| 375 | int center_of_items = width_of_items / 2; |
| 376 | |
| 377 | *lx = center_x - (width_of_items / 2); |
| 378 | *mx = (*lx) + gap + left_item_width; |
| 379 | *rx = (*mx) + gap + middle_item_width; |
| 380 | } |
| 381 | |
| 382 | // load in D3 user interface resources |
| 383 | void NewUIInit() { |
| 384 | int i; |
| 385 | |
| 386 | if (NewUI_init) { |
| 387 | NewUIClose(); |
| 388 | } else { |
| 389 | NewUI_init = true; |
| 390 | atexit(NewUIClose); |
| 391 | } |
| 392 | |
| 393 | for (i = 0; i < NEWUIBMP_NUM; i++) { |
| 394 | NewUI_bitmap_list[i].bmp = -3; |
| 395 | } |
| 396 | |
| 397 | // load in bitmap handles here. |
| 398 | int bm_handle; |
| 399 | |
| 400 | NewUI_bitmap_list[NEWUIBMP_DIALOG_CORNER1].bmp = bm_AllocLoadFileBitmap("d3dlg_nw.ogf", 0); |
| 401 | NewUI_bitmap_list[NEWUIBMP_DIALOG_CORNER2].bmp = bm_AllocLoadFileBitmap("d3dlg_ne.ogf", 0); |
| 402 | NewUI_bitmap_list[NEWUIBMP_DIALOG_CORNER3].bmp = bm_AllocLoadFileBitmap("d3dlg_se.ogf", 0); |
| 403 | NewUI_bitmap_list[NEWUIBMP_DIALOG_CORNER4].bmp = bm_AllocLoadFileBitmap("d3dlg_sw.ogf", 0); |
| 404 | NewUI_bitmap_list[NEWUIBMP_DIALOG_HORIZTOP].bmp = bm_AllocLoadFileBitmap("d3dlg_n.ogf", 0); |
| 405 | NewUI_bitmap_list[NEWUIBMP_DIALOG_VERTRIGHT].bmp = bm_AllocLoadFileBitmap("d3dlg_e.ogf", 0); |
| 406 | NewUI_bitmap_list[NEWUIBMP_DIALOG_HORIZBOT].bmp = bm_AllocLoadFileBitmap("d3dlg_s.ogf", 0); |
| 407 | NewUI_bitmap_list[NEWUIBMP_DIALOG_VERTLEFT].bmp = bm_AllocLoadFileBitmap("d3dlg_w.ogf", 0); |
| 408 | NewUI_bitmap_list[NEWUIBMP_DIALOG_BACK].bmp = bm_AllocLoadFileBitmap("d3dlg_bk.ogf", 0); |
| 409 | // NewUI_bitmap_list[NEWUIBMP_DIALOG_PANEL].bmp= bm_AllocLoadFileBitmap("d3dlg_tb.ogf",0); |
| 410 | NewUI_bitmap_list[NEWUIBMP_MSGBOX_LEFT].bmp = bm_AllocLoadFileBitmap("d3mbox_l.ogf", 0); |
| 411 | NewUI_bitmap_list[NEWUIBMP_MSGBOX_RIGHT].bmp = bm_AllocLoadFileBitmap("d3mbox_r.ogf", 0); |
| 412 | NewUI_bitmap_list[NEWUIBMP_MSGBOX_CENTER].bmp = bm_AllocLoadFileBitmap("d3mbox_c.ogf", 0); |
| 413 | NewUI_bitmap_list[NEWUIBMP_LIST_CORNER1].bmp = bm_AllocLoadFileBitmap("lbTopLeft32.ogf", 0); |
| 414 | NewUI_bitmap_list[NEWUIBMP_LIST_CORNER2].bmp = bm_AllocLoadFileBitmap("lbTopRight32.ogf", 0); |
| 415 | NewUI_bitmap_list[NEWUIBMP_LIST_CORNER3].bmp = bm_AllocLoadFileBitmap("lbBottomRight32.ogf", 0); |
| 416 | NewUI_bitmap_list[NEWUIBMP_LIST_CORNER4].bmp = bm_AllocLoadFileBitmap("lbBottomLeft32.ogf", 0); |
| 417 | NewUI_bitmap_list[NEWUIBMP_LIST_HORIZTOP].bmp = bm_AllocLoadFileBitmap("lbTop32.ogf", 0); |
| 418 | NewUI_bitmap_list[NEWUIBMP_LIST_VERTRIGHT].bmp = bm_AllocLoadFileBitmap("lbRight32.ogf", 0); |
| 419 | NewUI_bitmap_list[NEWUIBMP_LIST_HORIZBOT].bmp = bm_AllocLoadFileBitmap("lbBottom32.ogf", 0); |
| 420 | NewUI_bitmap_list[NEWUIBMP_LIST_VERTLEFT].bmp = bm_AllocLoadFileBitmap("lbLeft32.ogf", 0); |
| 421 | NewUI_bitmap_list[NEWUIBMP_LIST_BACK].bmp = bm_AllocLoadFileBitmap("d3_lb_bk.ogf", 0); |
| 422 | NewUI_bitmap_list[NEWUIBMP_EDIT_LEFT].bmp = bm_AllocLoadFileBitmap("tbLeft.ogf", 0); |
| 423 | NewUI_bitmap_list[NEWUIBMP_EDIT_RIGHT].bmp = bm_AllocLoadFileBitmap("tbRight.ogf", 0); |
| 424 | NewUI_bitmap_list[NEWUIBMP_EDIT_CENTER].bmp = bm_AllocLoadFileBitmap("tbCenter.ogf", 0); |
| 425 | NewUI_bitmap_list[NEWUIBMP_BTN_UP].bmp = bm_AllocLoadFileBitmap("d3_btn_up.ogf", 0); |
| 426 | NewUI_bitmap_list[NEWUIBMP_BTN_DOWN].bmp = bm_AllocLoadFileBitmap("d3_btn_down.ogf", 0); |
| 427 | NewUI_bitmap_list[NEWUIBMP_BTN_HILITE].bmp = bm_AllocLoadFileBitmap("d3_btn_hilite.ogf", 0); |
| 428 | NewUI_bitmap_list[NEWUIBMP_BTN_UP_L].bmp = bm_AllocLoadFileBitmap("d3_btn_up_l.ogf", 0); |
| 429 | NewUI_bitmap_list[NEWUIBMP_BTN_DOWN_L].bmp = bm_AllocLoadFileBitmap("d3_btn_down_l.ogf", 0); |
| 430 | NewUI_bitmap_list[NEWUIBMP_BTN_HILITE_L].bmp = bm_AllocLoadFileBitmap("d3_btn_hilite_l.ogf", 0); |
| 431 | NewUI_bitmap_list[NEWUIBMP_BTN_UP_R].bmp = bm_AllocLoadFileBitmap("d3_btn_up_r.ogf", 0); |
| 432 | NewUI_bitmap_list[NEWUIBMP_BTN_DOWN_R].bmp = bm_AllocLoadFileBitmap("d3_btn_down_r.ogf", 0); |
| 433 | NewUI_bitmap_list[NEWUIBMP_BTN_HILITE_R].bmp = bm_AllocLoadFileBitmap("d3_btn_hilite_r.ogf", 0); |
| 434 | |
| 435 | bm_handle = bm_AllocLoadFileBitmap("d3slider.ogf", 0); |
| 436 | if (bm_handle > 0) { |
| 437 | NewUI_bitmap_list[NEWUIBMP_SLIDER_BUTTON].bmp = -2; |
| 438 | bm_CreateChunkedBitmap(bm_handle, &NewUI_bitmap_list[NEWUIBMP_SLIDER_BUTTON].chunk); |
| 439 | bm_FreeBitmap(bm_handle); |
| 440 | } else { |
| 441 | NewUI_bitmap_list[NEWUIBMP_SLIDER_BUTTON].bmp = -1; |
| 442 | } |
| 443 | bm_handle = bm_AllocLoadFileBitmap("d3sliderbar.ogf", 0); |
| 444 | if (bm_handle > 0) { |
| 445 | NewUI_bitmap_list[NEWUIBMP_SLIDER_BAR].bmp = -2; |
| 446 | bm_CreateChunkedBitmap(bm_handle, &NewUI_bitmap_list[NEWUIBMP_SLIDER_BAR].chunk); |
| 447 | bm_FreeBitmap(bm_handle); |
| 448 | } else { |
| 449 | NewUI_bitmap_list[NEWUIBMP_SLIDER_BAR].bmp = -1; |
| 450 | } |
| 451 | |
| 452 | for (i = 0; i < NEWUIBMP_NUM; i++) { |
| 453 | if (NewUI_bitmap_list[i].bmp == 0 || NewUI_bitmap_list[i].bmp == -1) |
| 454 | Error("Unable to load new user interface bitmap #%d.\n", i); |
| 455 | } |
| 456 | |
| 457 | UITextItem::SetSaturationFactor(0); |
| 458 | |
| 459 | // new ui init 2 |
| 460 | newuiCore_Init(); |
| 461 | } |
| 462 | |
| 463 | // closes New UI system |
| 464 | void NewUIClose() { |
| 465 | // new ui init 2 |
| 466 | newuiCore_Close(); |
| 467 | |
| 468 | for (int i = 0; i < NEWUIBMP_NUM; i++) { |
| 469 | if (NewUI_bitmap_list[i].bmp >= BAD_BITMAP_HANDLE) { |
| 470 | bm_FreeBitmap(NewUI_bitmap_list[i].bmp); |
| 471 | NewUI_bitmap_list[i].bmp = -1; |
| 472 | } else if (NewUI_bitmap_list[i].bmp == -2) { |
| 473 | bm_DestroyChunkedBitmap(&NewUI_bitmap_list[i].chunk); |
| 474 | NewUI_bitmap_list[i].bmp = -1; |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | // Displays a 'temporary' dialog with a message |
| 480 | // for example: |
| 481 | // ... |
| 482 | // DoWaitMessage(true,"Please Wait..."); |
| 483 | // ... //some code |
| 484 | // DoWaitMessage(false); |
| 485 | void DoWaitMessage(bool enable, const char *message) { |
| 486 | static bool opened = false; |
| 487 | static uint8_t cur_pos = 0; |
| 488 | float curpos_f; |
| 489 | |
| 490 | // if (1) return; |
| 491 | |
| 492 | if (Dedicated_server) |
| 493 | return; |
| 494 | if (!enable && !opened) |
| 495 | return; |
| 496 | if (GetScreenMode() != SM_MENU) { |
| 497 | opened = false; |
| 498 | return; |
| 499 | } |
| 500 | if (enable && !opened) { |
| 501 | opened = true; |
| 502 | cur_pos = -1; |
| 503 | } |
| 504 | if (!enable && opened) { |
| 505 | opened = false; |
| 506 | return; |
| 507 | } |
| 508 | |
| 509 | // render a ui frame |
| 510 | DoUIFrame(); |
| 511 | cur_pos++; |
| 512 | if (cur_pos > 10) |
| 513 | cur_pos = 0; |
| 514 | curpos_f = (cur_pos / 10.0f); |
| 515 | |
| 516 | // print our downloading data message. |
| 517 | g3Point *pntlist[4], points[4]; |
| 518 | int i, rx, ry, rw, rh; |
| 519 | |
| 520 | StartFrame(0, 0, Max_window_w, Max_window_h); |
| 521 | grtext_SetFont(MONITOR9_NEWUI_FONT); |
| 522 | rw = Max_window_w; |
| 523 | rh = grfont_GetHeight(MONITOR9_NEWUI_FONT) + 8; |
| 524 | rx = 0; |
| 525 | ry = Max_window_h - rh; |
| 526 | points[0].p3_sx = rx; |
| 527 | points[0].p3_sy = ry; |
| 528 | points[1].p3_sx = rx + rw; |
| 529 | points[1].p3_sy = ry; |
| 530 | points[2].p3_sx = rx + rw; |
| 531 | points[2].p3_sy = ry + rh; |
| 532 | points[3].p3_sx = rx; |
| 533 | points[3].p3_sy = ry + rh; |
| 534 | |
| 535 | for (i = 0; i < 4; i++) { |
| 536 | points[i].p3_z = 0; |
| 537 | points[i].p3_flags = PF_PROJECTED; |
| 538 | pntlist[i] = &points[i]; |
| 539 | } |
| 540 | |
| 541 | rend_SetZBufferState(0); |
| 542 | rend_SetTextureType(TT_FLAT); |
| 543 | rend_SetAlphaType(AT_CONSTANT); |
| 544 | rend_SetLighting(LS_NONE); |
| 545 | rend_SetFlatColor(GR_BLACK); |
| 546 | rend_SetAlphaValue(230); |
| 547 | rend_DrawPolygon2D(0, pntlist, 4); |
| 548 | |
| 549 | if (cur_pos > 0) { |
| 550 | points[0].p3_sx = rx; |
| 551 | points[0].p3_sy = ry + rh - (rh / 2) + 2; |
| 552 | points[1].p3_sx = rx + ((float)rw * curpos_f); |
| 553 | points[1].p3_sy = ry + rh - (rh / 2) + 2; |
| 554 | points[2].p3_sx = rx + ((float)rw * curpos_f); |
| 555 | points[2].p3_sy = ry + rh; |
| 556 | points[3].p3_sx = rx; |
| 557 | points[3].p3_sy = ry + rh; |
| 558 | |
| 559 | rend_SetFlatColor(GR_RGB(255, 0, 0)); |
| 560 | rend_SetAlphaValue(230); |
| 561 | rend_DrawPolygon2D(0, pntlist, 4); |
| 562 | } |
| 563 | |
| 564 | grtext_SetAlpha(255); |
| 565 | grtext_SetColor(NEWUI_MONITORFONT_COLOR); |
| 566 | if (message) { |
| 567 | grtext_Puts(0, ry, message); |
| 568 | } else { |
| 569 | grtext_Puts(0, ry, TXT_INITDATA); |
| 570 | } |
| 571 | grtext_Flush(); |
| 572 | |
| 573 | EndFrame(); |
| 574 | rend_Flip(); |
| 575 | } |
| 576 | |
| 577 | void DoWaitPopup(bool enable, const char *message) { |
| 578 | #define FDWM_HEIGHT 128 |
| 579 | #define FDWM_WIDTH 256 |
| 580 | |
| 581 | static newuiTiledWindow *msgbox = NULL; |
| 582 | static UIText text; |
| 583 | static bool opened = false; |
| 584 | newuiSheet *sheet; |
| 585 | |
| 586 | if (opened == enable) { |
| 587 | Int3(); |
| 588 | } |
| 589 | |
| 590 | opened = enable; |
| 591 | |
| 592 | if (enable) { |
| 593 | msgbox = new newuiTiledWindow; |
| 594 | |
| 595 | if (msgbox) { |
| 596 | |
| 597 | msgbox->Create(NULL, 0, 0, FDWM_WIDTH, FDWM_HEIGHT); |
| 598 | |
| 599 | sheet = msgbox->GetSheet(); |
| 600 | if (message) { |
| 601 | char msg[512]; |
| 602 | int w, h; |
| 603 | textaux_WordWrap(message, msg, FDWM_WIDTH, MONITOR9_NEWUI_FONT); |
| 604 | grtext_SetFont(MONITOR9_NEWUI_FONT); |
| 605 | w = grtext_GetTextLineWidth(msg); |
| 606 | h = grtext_GetTextHeight(msg); |
| 607 | UITextItem item{MONITOR9_NEWUI_FONT, msg, NEWUI_MONITORFONT_COLOR}; |
| 608 | text.Create(msgbox, &item, (msgbox->W() - w) / 2, (msgbox->H() - h) / 2); |
| 609 | |
| 610 | // sheet->NewGroup(NULL, , 25); |
| 611 | // sheet->AddText(msg); |
| 612 | } |
| 613 | |
| 614 | msgbox->Open(); |
| 615 | // sheet->Realize(); |
| 616 | |
| 617 | // fake a DoUI |
| 618 | DoUIFrame(); |
| 619 | rend_Flip(); |
| 620 | } |
| 621 | } else { |
| 622 | |
| 623 | if (msgbox) { |
| 624 | msgbox->Close(); |
| 625 | msgbox->Destroy(); |
| 626 | delete msgbox; |
| 627 | } |
| 628 | msgbox = NULL; |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | // puts up a message box with a title and message. |
| 633 | int DoMessageBox(const char *title, const char *msg, int type, ddgr_color title_color, ddgr_color text_color) { |
| 634 | newuiMessageBox mbox; |
| 635 | newuiSheet *sheet; |
| 636 | |
| 637 | int old_screen_mode, res; |
| 638 | char msgbuf[256]; |
| 639 | |
| 640 | // force menu mode |
| 641 | old_screen_mode = GetScreenMode(); |
| 642 | |
| 643 | textaux_WordWrap(msg, msgbuf, NEWUI_MSGBOX_SHEET_W, MONITOR9_NEWUI_FONT); |
| 644 | |
| 645 | // make message box |
| 646 | mbox.Create(title, type); |
| 647 | |
| 648 | sheet = mbox.GetSheet(); |
| 649 | sheet->NewGroup(NULL, 0, 0); |
| 650 | sheet->AddText(msgbuf); |
| 651 | |
| 652 | mbox.Open(); |
| 653 | res = mbox.DoUI(); |
| 654 | mbox.Close(); |
| 655 | |
| 656 | mbox.Destroy(); |
| 657 | |
| 658 | // restore screen |
| 659 | SetScreenMode(old_screen_mode); |
| 660 | |
| 661 | // return correct value. |
| 662 | return ((res == UID_OK) ? 1 : 0); |
| 663 | } |
| 664 | |
| 665 | // puts up a message box with a title and message. |
| 666 | // define text for buttons, btn0_title, btn1_title, ..., until NULL. |
| 667 | // also define hotkey for button immediately after title is defined. |
| 668 | // |
| 669 | // DoMessageBoxAdvanced("Title", "Hi", "Abort", KEY_A, "Retry", KEY_R, "Cancel", KEY_ESC, NULL) |
| 670 | // |
| 671 | // if button with btn0_title pressed, returns 0, btn1_title, returns 1, etc. |
| 672 | // safe for up to three buttons. |
| 673 | int DoMessageBoxAdvanced(const char *title, const char *msg, const char *btn0_title, int key0, ...) { |
| 674 | newuiMessageBox mbox; |
| 675 | newuiSheet *sheet; |
| 676 | va_list args; |
| 677 | const char *curbtntitle; |
| 678 | int i; |
| 679 | |
| 680 | int old_screen_mode, res; |
| 681 | char msgbuf[256]; |
| 682 | |
| 683 | // force menu mode |
| 684 | old_screen_mode = GetScreenMode(); |
| 685 | |
| 686 | textaux_WordWrap(msg, msgbuf, NEWUI_MSGBOX_SHEET_W, MONITOR9_NEWUI_FONT); |
| 687 | |
| 688 | // make message box |
| 689 | mbox.Create(title, MSGBOX_NULL); |
| 690 | i = 0; |
| 691 | if (btn0_title) { |
| 692 | mbox.AddButton(btn0_title, i, key0); |
| 693 | i++; |
| 694 | } |
| 695 | |
| 696 | // go through all titles. |
| 697 | va_start(args, key0); |
| 698 | while ((curbtntitle = va_arg(args, char *)) != NULL) { |
| 699 | int key = va_arg(args, int); |
| 700 | |
| 701 | mbox.AddButton(curbtntitle, i, key); |
| 702 | i++; |
| 703 | if (i == NEWUI_MSGBOX_MAXBTNS) |
| 704 | break; |
| 705 | } |
| 706 | |
| 707 | va_end(args); |
| 708 | |
| 709 | sheet = mbox.GetSheet(); |
| 710 | sheet->NewGroup(NULL, 0, 0); |
| 711 | sheet->AddText(msgbuf); |
| 712 | |
| 713 | mbox.Open(); |
| 714 | res = mbox.DoUI(); |
| 715 | mbox.Close(); |
| 716 | |
| 717 | mbox.Destroy(); |
| 718 | |
| 719 | // restore screen |
| 720 | SetScreenMode(old_screen_mode); |
| 721 | |
| 722 | // return correct value. |
| 723 | return res; |
| 724 | } |
| 725 | |
| 726 | bool DoEditDialog(const char *title, char *buffer, int buflen, bool showcancel) { |
| 727 | newuiMessageBox mbox; |
| 728 | newuiSheet *sheet; |
| 729 | |
| 730 | int old_screen_mode, res; |
| 731 | char msgbuf[256]; |
| 732 | char *edit; |
| 733 | |
| 734 | // force menu mode |
| 735 | old_screen_mode = GetScreenMode(); |
| 736 | |
| 737 | textaux_WordWrap(title, msgbuf, NEWUI_MSGBOX_SHEET_W, MONITOR9_NEWUI_FONT); |
| 738 | |
| 739 | // make message box |
| 740 | mbox.Create("", showcancel ? MSGBOX_OKCANCEL : MSGBOX_OK); |
| 741 | |
| 742 | sheet = mbox.GetSheet(); |
| 743 | sheet->NewGroup(NULL, 0, 25); |
| 744 | edit = sheet->AddEditBox("", buflen, 0, DEFAULT_NEWUID, 0, true); |
| 745 | strcpy(edit, buffer); |
| 746 | |
| 747 | sheet->NewGroup(NULL, 0, 0); |
| 748 | sheet->AddText(msgbuf); |
| 749 | |
| 750 | mbox.Open(); |
| 751 | res = mbox.DoUI(); |
| 752 | mbox.Close(); |
| 753 | |
| 754 | if (res != UID_CANCEL && res != NEWUIRES_FORCEQUIT) { |
| 755 | if (strcmp(edit, NEWUI_EDIT_CANCELED_STR) != 0) { |
| 756 | strcpy(buffer, edit); |
| 757 | mprintf(0, "editdialog=%s\n", buffer); |
| 758 | } else { |
| 759 | res = UID_CANCEL; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | mbox.Destroy(); |
| 764 | |
| 765 | // restore screen |
| 766 | SetScreenMode(old_screen_mode); |
| 767 | |
| 768 | // return correct value. |
| 769 | return ((res != UID_CANCEL && res != NEWUIRES_FORCEQUIT) ? true : false); |
| 770 | } |
| 771 | |
| 772 | // puts up a file selector box |
| 773 | // Parameters: max_filename_len - the max length for the filename. filebuf have a length of at least max_filename_len+1 |
| 774 | bool DoFileDialog(const char *title, const char *search_path, const char *ext, char *filebuf, |
| 775 | unsigned max_filename_len) { |
| 776 | NewUIFileDialog dlg; |
| 777 | int w = 256, h = 256; |
| 778 | int x = Game_window_w / 2 - w / 2; |
| 779 | int y = Game_window_h / 2 - h / 2; |
| 780 | |
| 781 | dlg.Create(title, x, y, w, h, search_path, ext); |
| 782 | |
| 783 | if (dlg.DoModal()) { |
| 784 | if (strlen(dlg.GetFilename()) > max_filename_len) |
| 785 | Error("Runtime error. NewUI system DoFileDialog: (%d,%d)", strlen(dlg.GetFilename()), max_filename_len); |
| 786 | strcpy(filebuf, dlg.GetFilename()); |
| 787 | return true; |
| 788 | } |
| 789 | |
| 790 | filebuf[0] = 0; |
| 791 | return false; |
| 792 | } |
| 793 | |
| 794 | // shows or hides windows |
| 795 | void OpenUIWindow(UIWindow *wnd) { |
| 796 | ASSERT(wnd); |
| 797 | wnd->Open(); |
| 798 | } |
| 799 | |
| 800 | void CloseUIWindow(UIWindow *wnd) { |
| 801 | ASSERT(wnd); |
| 802 | wnd->Close(); |
| 803 | } |
| 804 | |
| 805 | /////////////////////////////////////////////////////////////////////////////// |
| 806 | // large bitmap library |
| 807 | |
| 808 | int LoadLargeBitmap(const char *filename, tLargeBitmap *bmp) { |
| 809 | chunked_bitmap chunk; |
| 810 | int bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(filename), 0); |
| 811 | if (bm_handle == -1) { |
| 812 | bmp->bm_array = NULL; |
| 813 | bmp->bmps_w = 0; |
| 814 | bmp->bmps_h = 0; |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | bm_CreateChunkedBitmap(bm_handle, &chunk); |
| 819 | |
| 820 | if (bm_handle > BAD_BITMAP_HANDLE) |
| 821 | bm_FreeBitmap(bm_handle); |
| 822 | |
| 823 | bmp->bmps_w = chunk.w; |
| 824 | bmp->bmps_h = chunk.h; |
| 825 | bmp->bm_array = chunk.bm_array; |
| 826 | |
| 827 | return 1; |
| 828 | } |
| 829 | |
| 830 | void FreeLargeBitmap(tLargeBitmap *bmp) { |
| 831 | chunked_bitmap chunk; |
| 832 | |
| 833 | chunk.w = bmp->bmps_w; |
| 834 | chunk.h = bmp->bmps_h; |
| 835 | chunk.bm_array = bmp->bm_array; |
| 836 | bm_DestroyChunkedBitmap(&chunk); |
| 837 | } |
| 838 | |
| 839 | void DrawLargeBitmap(tLargeBitmap *bmp, int x, int y, float alpha) { |
| 840 | chunked_bitmap chunk; |
| 841 | |
| 842 | chunk.w = bmp->bmps_w; |
| 843 | chunk.h = bmp->bmps_h; |
| 844 | chunk.bm_array = bmp->bm_array; |
| 845 | rend_DrawChunkedBitmap(&chunk, x, y, alpha * 255); |
| 846 | } |
| 847 | |
| 848 | /////////////////////////////////////////////////////////////////////////////// |
| 849 | // Listbox procedure. |
| 850 | |
| 851 | uint8_t NewUIWindow_alpha = 192; |
| 852 | |
| 853 | NewUIWindow::NewUIWindow() : UIWindow() {} |
| 854 | |
| 855 | // initializes the window |
| 856 | void NewUIWindow::Create(int x, int y, int w, int h, int flags) { |
| 857 | UIWindow::Create(x, y, w, h, flags); |
| 858 | UIPrimativeItem item{GR_BLACK, NewUIWindow_alpha}; |
| 859 | UIWindow::SetBackItem(&item); |
| 860 | memset(&m_Chunk, 0, sizeof(m_Chunk)); |
| 861 | } |
| 862 | |
| 863 | // settings and state info |
| 864 | |
| 865 | // ui system overridables |
| 866 | // overridable draws the window background before gadgets |
| 867 | void NewUIWindow::OnDraw() { |
| 868 | UIWindow::OnDraw(); |
| 869 | |
| 870 | if (m_Flags & UIF_BORDER) { |
| 871 | ui_DrawBox(GR_DARKGRAY, 0, 0, m_W, m_H); |
| 872 | ui_DrawBox(GR_LIGHTGRAY, 2, 2, m_W - 2, m_H - 2); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | void NewUIWindow::OnDestroy() { bm_DestroyChunkedBitmap(&m_Chunk); } |
| 877 | |
| 878 | void NewUIWindow::LoadBackgroundImage(const char *image_name) { |
| 879 | UIBitmapItem back_bm; |
| 880 | |
| 881 | bm_DestroyChunkedBitmap(&m_Chunk); |
| 882 | memset(&m_Chunk, 0, sizeof(m_Chunk)); |
| 883 | |
| 884 | if (image_name) { |
| 885 | int bm_handle = bm_AllocLoadFileBitmap(IGNORE_TABLE(image_name), 0); |
| 886 | |
| 887 | if (bm_handle <= BAD_BITMAP_HANDLE) { |
| 888 | Error("Unable to load image %s for background.", image_name); |
| 889 | } |
| 890 | |
| 891 | // takes a large static bitmap and breaks it into smaller managable bitmaps |
| 892 | if (!bm_CreateChunkedBitmap(bm_handle, &m_Chunk)) { |
| 893 | Error("Failed to chunk background bitmap %s.", image_name); |
| 894 | } |
| 895 | |
| 896 | back_bm.set_chunked_bitmap(&m_Chunk); |
| 897 | UIWindow::SetBackItem(&back_bm); |
| 898 | bm_FreeBitmap(bm_handle); |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | /////////////////////////////////////////////////////////////////////////////// |
| 903 | // NewUIGameWindow implementation. |
| 904 | |
| 905 | NewUIGameWindow::NewUIGameWindow() {} |
| 906 | |
| 907 | // initializes the window |
| 908 | void NewUIGameWindow::Create(int x, int y, int w, int h, int flags) { |
| 909 | newuiTiledWindow::Create(NULL, x, y, w, h, flags); |
| 910 | } |
| 911 | |
| 912 | /////////////////////////////////////////////////////////////////////////////// |
| 913 | // NewUIMessageBox implementation. |
| 914 | |
| 915 | NewUIMessageBox::NewUIMessageBox() : NewUIGameWindow() {} |
| 916 | |
| 917 | // initializes the window |
| 918 | void NewUIMessageBox::Create(int x, int y, int w, int flags) { |
| 919 | NewUIGameWindow::Create(x, y, w, 128, flags | UIF_PROCESS_ALL); |
| 920 | } |
| 921 | |
| 922 | // settings and state info |
| 923 | |
| 924 | /////////////////////////////////////////////////////////////////////////////// |
| 925 | // NewUISlider implementation. |
| 926 | |
| 927 | // settings |
| 928 | |
| 929 | void NewUISlider::Create(UIWindow *parent, int id, int x, int y, int flags) { |
| 930 | m_Slider.set_chunked_bitmap(&NewUI_bitmap_list[NEWUIBMP_SLIDER_BUTTON].chunk); |
| 931 | m_SliderBar.set_chunked_bitmap(&NewUI_bitmap_list[NEWUIBMP_SLIDER_BAR].chunk); |
| 932 | |
| 933 | UISlider::Create(parent, id, x, y, 5, 5, flags); |
| 934 | |
| 935 | UISlider::SetSliderSwitchItem(&m_Slider); |
| 936 | UISlider::SetSliderItem(&m_SliderBar); |
| 937 | } |
| 938 | |
| 939 | /////////////////////////////////////////////////////////////////////////////// |
| 940 | // NewUIEdit implementation. |
| 941 | |
| 942 | // settings |
| 943 | |
| 944 | void NewUIEdit::Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags) { |
| 945 | m_EditLeft.set_bitmap(NewUI_bitmap_list[NEWUIBMP_EDIT_LEFT].bmp); |
| 946 | m_EditCen.set_bitmap(NewUI_bitmap_list[NEWUIBMP_EDIT_CENTER].bmp); |
| 947 | m_EditRight.set_bitmap(NewUI_bitmap_list[NEWUIBMP_EDIT_RIGHT].bmp); |
| 948 | |
| 949 | // adjust w and height acoordingly with bitmap background width and height. |
| 950 | int bk_width = (w - m_EditLeft.width() - m_EditRight.width()) / m_EditCen.width(); |
| 951 | int bk_height = 1; |
| 952 | |
| 953 | if (bk_width < 0) |
| 954 | bk_width = 0; |
| 955 | else { |
| 956 | if ((w - m_EditLeft.width() - m_EditRight.width()) % m_EditCen.width()) |
| 957 | bk_width++; |
| 958 | } |
| 959 | |
| 960 | w = (bk_width * m_EditCen.width()) + m_EditLeft.width() + m_EditRight.width(); |
| 961 | h = (bk_height * m_EditLeft.height()); |
| 962 | m_TileWidth = bk_width; |
| 963 | |
| 964 | UIEdit::Create(parent, id, x, y, w, h, flags); |
| 965 | UIEdit::SetTextBounds(m_EditLeft.width() / 2, m_W - m_EditRight.height() / 2, 0); |
| 966 | } |
| 967 | |
| 968 | void NewUIEdit::OnDraw() { |
| 969 | // draw tiles. |
| 970 | int x, tx; |
| 971 | |
| 972 | tx = x = 0; |
| 973 | |
| 974 | // top row. |
| 975 | m_EditLeft.draw(x, 0); |
| 976 | x += m_EditRight.width(); |
| 977 | while (tx++ < m_TileWidth) { |
| 978 | m_EditCen.draw(x, 0); |
| 979 | x += m_EditCen.width(); |
| 980 | } |
| 981 | m_EditRight.draw(x, 0); |
| 982 | |
| 983 | DrawText(); |
| 984 | } |
| 985 | |
| 986 | /////////////////////////////////////////////////////////////////////////////// |
| 987 | // NewUIListBox Implementation |
| 988 | |
| 989 | void NewUIListBox::Create(UIWindow *parent, int id, int x, int y, int w, int h, int flags) { |
| 990 | m_BackNW.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_CORNER1].bmp); |
| 991 | m_BackN.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_HORIZTOP].bmp); |
| 992 | m_BackNE.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_CORNER2].bmp); |
| 993 | m_BackE.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_VERTRIGHT].bmp); |
| 994 | m_BackSE.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_CORNER3].bmp); |
| 995 | m_BackS.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_HORIZBOT].bmp); |
| 996 | m_BackSW.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_CORNER4].bmp); |
| 997 | m_BackW.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_VERTLEFT].bmp); |
| 998 | m_Back.set_bitmap(NewUI_bitmap_list[NEWUIBMP_LIST_BACK].bmp); |
| 999 | |
| 1000 | // adjust w and height acoordingly with bitmap background width and height. |
| 1001 | int bk_width = (w - m_BackNW.width() - m_BackNE.width()) / m_BackN.width(); |
| 1002 | int bk_height = (h - m_BackNW.height() - m_BackSW.height()) / m_BackW.height(); |
| 1003 | |
| 1004 | if (bk_width < 0) |
| 1005 | bk_width = 0; |
| 1006 | else { |
| 1007 | if ((w - m_BackNW.width() - m_BackNE.width()) % m_BackN.width()) |
| 1008 | bk_width++; |
| 1009 | } |
| 1010 | |
| 1011 | if (bk_height < 0) |
| 1012 | bk_height = 0; |
| 1013 | else { |
| 1014 | if ((h - m_BackNW.height() - m_BackSW.height()) % m_BackW.height()) |
| 1015 | bk_height++; |
| 1016 | } |
| 1017 | |
| 1018 | w = (bk_width * m_BackN.width()) + m_BackNW.width() + m_BackNE.width(); |
| 1019 | h = (bk_height * m_BackW.height()) + m_BackNW.height() + m_BackSW.height(); |
| 1020 | m_TileWidth = bk_width; |
| 1021 | m_TileHeight = bk_height; |
| 1022 | |
| 1023 | UIListBox::Create(parent, id, x, y, w, h, flags); |
| 1024 | |
| 1025 | // redefine special paramaeters for the new listbox |
| 1026 | m_TextOffX = m_BackW.width() / 2; |
| 1027 | m_TextOffY = m_BackN.height() / 2; |
| 1028 | m_CX = m_TextOffX; |
| 1029 | m_CY = m_TextOffY; |
| 1030 | m_CX2 = m_W - m_TextOffX; |
| 1031 | m_CY2 = m_H - m_TextOffY; |
| 1032 | } |
| 1033 | |
| 1034 | void NewUIListBox::OnDraw() { |
| 1035 | int x, y, tx, ty; |
| 1036 | |
| 1037 | // draw tiles. |
| 1038 | tx = x = 0; |
| 1039 | ty = y = 0; |
| 1040 | |
| 1041 | // top row. |
| 1042 | m_BackNW.draw(x, y); |
| 1043 | x += m_BackNW.width(); |
| 1044 | while (tx++ < m_TileWidth) { |
| 1045 | m_BackN.draw(x, y); |
| 1046 | x += m_BackN.width(); |
| 1047 | } |
| 1048 | m_BackNE.draw(x, y); |
| 1049 | |
| 1050 | x = 0; |
| 1051 | y += m_BackNW.height(); |
| 1052 | |
| 1053 | // mid rows. |
| 1054 | while (ty++ < m_TileHeight) { |
| 1055 | m_BackW.draw(x, y); |
| 1056 | x += m_BackW.width(); |
| 1057 | tx = 0; |
| 1058 | while (tx++ < m_TileWidth) { |
| 1059 | m_Back.draw(x, y); |
| 1060 | x += m_Back.width(); |
| 1061 | } |
| 1062 | m_BackE.draw(x, y); |
| 1063 | x = 0; |
| 1064 | y += m_BackW.height(); |
| 1065 | } |
| 1066 | |
| 1067 | // bottom row. |
| 1068 | m_BackSW.draw(x, y); |
| 1069 | x += m_BackSW.width(); |
| 1070 | tx = 0; |
| 1071 | while (tx++ < m_TileWidth) { |
| 1072 | m_BackS.draw(x, y); |
| 1073 | x += m_BackS.width(); |
| 1074 | } |
| 1075 | m_BackSE.draw(x, y); |
| 1076 | |
| 1077 | // draw text! |
| 1078 | UIListBox::OnDraw(); |
| 1079 | } |
| 1080 | |
| 1081 | // NewUIComboBox |
| 1082 | // displays a listbox just one item. |
| 1083 | |
| 1084 | void NewUIComboBox::Create(UIWindow *parent, int id, int x, int y, int w, int flags) { |
| 1085 | int h; |
| 1086 | |
| 1087 | m_CmbLeft.set_bitmap(NewUI_bitmap_list[NEWUIBMP_EDIT_LEFT].bmp); |
| 1088 | m_CmbCen.set_bitmap(NewUI_bitmap_list[NEWUIBMP_EDIT_CENTER].bmp); |
| 1089 | m_CmbRight.set_bitmap(NewUI_bitmap_list[NEWUIBMP_EDIT_RIGHT].bmp); |
| 1090 | |
| 1091 | // adjust w and height acoordingly with bitmap background width and height. |
| 1092 | int bk_width = (w - m_CmbLeft.width() - m_CmbRight.width()) / m_CmbCen.width(); |
| 1093 | int bk_height = 1; |
| 1094 | |
| 1095 | if (bk_width < 0) |
| 1096 | bk_width = 0; |
| 1097 | else { |
| 1098 | if ((w - m_CmbLeft.width() - m_CmbRight.width()) % m_CmbCen.width()) |
| 1099 | bk_width++; |
| 1100 | } |
| 1101 | |
| 1102 | w = (bk_width * m_CmbCen.width()) + m_CmbLeft.width() + m_CmbRight.width(); |
| 1103 | h = (bk_height * m_CmbLeft.height()); |
| 1104 | m_TileWidth = bk_width; |
| 1105 | |
| 1106 | UIComboBox::Create(parent, id, x, y, w, h, flags); |
| 1107 | m_CX = m_CmbLeft.width() / 2; |
| 1108 | m_CY = 1 + m_CmbLeft.height() / 4; |
| 1109 | m_CX2 = m_W - m_CmbRight.width() / 2; |
| 1110 | m_CY2 = m_H - m_CmbRight.height() / 4; |
| 1111 | } |
| 1112 | |
| 1113 | void NewUIComboBox::OnDraw() { |
| 1114 | // draw tiles. |
| 1115 | int x, tx; |
| 1116 | |
| 1117 | tx = x = 0; |
| 1118 | |
| 1119 | // top row. |
| 1120 | m_CmbLeft.draw(x, 0); |
| 1121 | x += m_CmbRight.width(); |
| 1122 | while (tx++ < m_TileWidth) { |
| 1123 | m_CmbCen.draw(x, 0); |
| 1124 | x += m_CmbCen.width(); |
| 1125 | } |
| 1126 | m_CmbRight.draw(x, 0); |
| 1127 | |
| 1128 | // draw text! |
| 1129 | UIComboBox::OnDraw(); |
| 1130 | } |
| 1131 | |
| 1132 | /////////////////////////////////////////////////////////////////////////////// |
| 1133 | // NewUIButton Implementation |
| 1134 | |
| 1135 | #define NEWBTN_HEIGHT 25 |
| 1136 | |
| 1137 | void NewUIButton::Create(UIWindow *parent, int id, UIItem *item, int x, int y, int w, int h, int flags) { |
| 1138 | flags |= UIF_FIT; |
| 1139 | |
| 1140 | m_BtnUpC.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_UP].bmp); |
| 1141 | m_BtnDownC.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_DOWN].bmp); |
| 1142 | m_BtnHiliteC.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_HILITE].bmp); |
| 1143 | m_BtnUpL.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_UP_L].bmp); |
| 1144 | m_BtnDownL.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_DOWN_L].bmp); |
| 1145 | m_BtnHiliteL.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_HILITE_L].bmp); |
| 1146 | m_BtnUpR.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_UP_R].bmp); |
| 1147 | m_BtnDownR.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_DOWN_R].bmp); |
| 1148 | m_BtnHiliteR.set_bitmap(NewUI_bitmap_list[NEWUIBMP_BTN_HILITE_R].bmp); |
| 1149 | |
| 1150 | // adjust w and height acoordingly with bitmap background width and height. |
| 1151 | UIButton::Create(parent, id, item, x, y, w, h, flags); |
| 1152 | OnFormat(); |
| 1153 | } |
| 1154 | |
| 1155 | void NewUIButton::SetTitle(UIItem *item) { |
| 1156 | UIButton::SetStateItem(UI_BTS_DISABLED, item); |
| 1157 | UIButton::SetStateItem(UI_BTS_INACTIVE, item); |
| 1158 | UIButton::SetStateItem(UI_BTS_HILITE, item); |
| 1159 | UIButton::SetStateItem(UI_BTS_ACTIVATED, item); |
| 1160 | } |
| 1161 | |
| 1162 | // drawing behavior of the new bitmap. |
| 1163 | void NewUIButton::OnDraw() { |
| 1164 | // draw tiles. |
| 1165 | int x, tx; |
| 1166 | UIBitmapItem *ltile = NULL, *ctile = NULL, *rtile = NULL; |
| 1167 | |
| 1168 | tx = x = 0; |
| 1169 | |
| 1170 | // top row. |
| 1171 | switch (m_State) { |
| 1172 | case UI_BTS_DISABLED: |
| 1173 | case UI_BTS_INACTIVE: |
| 1174 | ltile = &m_BtnUpL; |
| 1175 | rtile = &m_BtnUpR; |
| 1176 | ctile = &m_BtnUpC; |
| 1177 | break; |
| 1178 | |
| 1179 | case UI_BTS_HILITE: |
| 1180 | ltile = &m_BtnHiliteL; |
| 1181 | rtile = &m_BtnHiliteR; |
| 1182 | ctile = &m_BtnHiliteC; |
| 1183 | break; |
| 1184 | |
| 1185 | case UI_BTS_ACTIVATED: |
| 1186 | ltile = &m_BtnDownL; |
| 1187 | rtile = &m_BtnDownR; |
| 1188 | ctile = &m_BtnDownC; |
| 1189 | break; |
| 1190 | |
| 1191 | default: |
| 1192 | ASSERT(0); |
| 1193 | } |
| 1194 | |
| 1195 | ltile->draw(x, 0); |
| 1196 | x += ltile->width(); |
| 1197 | while (tx++ < m_TileWidth) { |
| 1198 | ctile->draw(x, 0); |
| 1199 | x += ctile->width(); |
| 1200 | } |
| 1201 | rtile->draw(x, 0); |
| 1202 | |
| 1203 | // draw title |
| 1204 | if (GetStateItem(m_State)) { |
| 1205 | UIItem *item = GetStateItem(m_State); |
| 1206 | int x = (m_W / 2 - item->width() / 2); |
| 1207 | int y = (m_H / 2 - item->height() / 2); |
| 1208 | item->draw(x, y); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | // override: called when resized or before drawing. |
| 1213 | void NewUIButton::OnFormat() { |
| 1214 | int bk_width; |
| 1215 | int bk_height; |
| 1216 | |
| 1217 | // check fit flag than resize according to bitmap aligned coords, then call UIGadget's one that does |
| 1218 | // centering! |
| 1219 | if ((m_Flags & UIF_FIT) && m_BtnTitle) { |
| 1220 | m_W = m_BtnTitle->width() + 10; |
| 1221 | } |
| 1222 | |
| 1223 | bk_width = (m_W - m_BtnUpL.width() - m_BtnUpR.width()) / m_BtnUpC.width(); |
| 1224 | bk_height = 1; |
| 1225 | |
| 1226 | if (bk_width < 0) |
| 1227 | bk_width = 0; |
| 1228 | else { |
| 1229 | if ((m_W - m_BtnUpL.width() - m_BtnUpR.width()) % m_BtnUpC.width()) |
| 1230 | bk_width++; |
| 1231 | } |
| 1232 | |
| 1233 | m_W = (bk_width * m_BtnUpC.width()) + m_BtnUpL.width() + m_BtnUpR.width(); |
| 1234 | m_H = NEWBTN_HEIGHT; |
| 1235 | m_TileWidth = bk_width; |
| 1236 | |
| 1237 | UIGadget::OnFormat(); |
| 1238 | } |
| 1239 | |
| 1240 | /////////////////////////////////////////////////////////////////////////////// |
| 1241 | // NewUIFileDialog |
| 1242 | // this draws a file lister. |
| 1243 | |
| 1244 | #define UID_FILELIST 0x100 |
| 1245 | |
| 1246 | void NewUIFileDialog::Create(const char *title, int x, int y, int w, int h, const char *path, const char *filecard) { |
| 1247 | int list_y, list_w, list_h; |
| 1248 | |
| 1249 | NewUIGameWindow::Create(x, y, w, h); |
| 1250 | |
| 1251 | strcpy(m_SearchExt, filecard); |
| 1252 | SetSearchPath(path); |
| 1253 | |
| 1254 | list_w = w - 48; |
| 1255 | list_h = h - 64; |
| 1256 | list_y = 24; |
| 1257 | |
| 1258 | UITextItem itemTitle{(char *)title}; |
| 1259 | m_TitleStr.Create(this, &itemTitle, 0, 5, UIF_CENTER); |
| 1260 | m_ListBox.Create(this, UID_FILELIST, 0, list_y, list_w, list_h, UIF_CENTER); |
| 1261 | UITextItem itemList{TXT_OK}; |
| 1262 | m_Ok.Create(this, UID_OK, &itemList, 32, m_H - 32, 0, 0, UIF_FIT); |
| 1263 | UITextItem itemCancel{TXT_CANCEL}; |
| 1264 | m_Cancel.Create(this, UID_CANCEL, &itemCancel, m_W - m_Ok.W() - 32, m_H - 32, 0, 0, UIF_FIT); |
| 1265 | |
| 1266 | m_FileItems = NULL; |
| 1267 | |
| 1268 | UpdateList(); |
| 1269 | } |
| 1270 | |
| 1271 | void NewUIFileDialog::SetSearchPath(const char *path) { strcpy(m_SearchPath, path); } |
| 1272 | |
| 1273 | const char *NewUIFileDialog::GetFilename() { return m_NewPath; } |
| 1274 | |
| 1275 | void NewUIFileDialog::UpdateList() { |
| 1276 | char search_str[_MAX_PATH]; |
| 1277 | char filename[_MAX_PATH]; |
| 1278 | |
| 1279 | // remove items from listbox, free them. |
| 1280 | while (m_ListBox.GetNumItems()) { |
| 1281 | UIItem *item = m_ListBox.GetItem(0); |
| 1282 | m_ListBox.RemoveItem(item); |
| 1283 | delete item; |
| 1284 | } |
| 1285 | |
| 1286 | // read in all files that have all search parameters met |
| 1287 | ddio_MakePath(search_str, m_SearchPath, m_SearchExt, NULL); |
| 1288 | |
| 1289 | if (ddio_FindFileStart(search_str, filename)) { |
| 1290 | UIItem *item = new UITextItem(filename); |
| 1291 | m_ListBox.AddItem(item); |
| 1292 | |
| 1293 | while (ddio_FindNextFile(filename)) { |
| 1294 | item = new UITextItem(filename); |
| 1295 | m_ListBox.AddItem(item); |
| 1296 | } |
| 1297 | |
| 1298 | ddio_FindFileClose(); |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | bool NewUIFileDialog::DoModal() { |
| 1303 | bool exit_menu = false, return_value = false; |
| 1304 | |
| 1305 | this->Open(); |
| 1306 | |
| 1307 | // update file list in listbox. |
| 1308 | UpdateList(); |
| 1309 | |
| 1310 | while (!exit_menu) { |
| 1311 | const char *filename; |
| 1312 | int index; |
| 1313 | int result; |
| 1314 | |
| 1315 | result = DoUI(); |
| 1316 | |
| 1317 | switch (result) { |
| 1318 | case NEWUIRES_FORCEQUIT: |
| 1319 | case UID_CANCEL: |
| 1320 | exit_menu = true; |
| 1321 | return_value = false; |
| 1322 | break; |
| 1323 | |
| 1324 | case UID_OK: |
| 1325 | case UID_FILELIST: |
| 1326 | index = m_ListBox.GetSelectedIndex(); |
| 1327 | filename = ((UITextItem *)m_ListBox.GetItem(index))->GetBuffer(); |
| 1328 | ASSERT(strlen(filename) < (_MAX_PATH)); |
| 1329 | strcpy(m_NewPath, filename); |
| 1330 | return_value = true; |
| 1331 | exit_menu = true; |
| 1332 | break; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | this->Close(); |
| 1337 | this->Destroy(); |
| 1338 | |
| 1339 | return return_value; |
| 1340 | } |
| 1341 | |
| 1342 | void NewUIFileDialog::OnDestroy() { |
| 1343 | // remove items from listbox, free them. |
| 1344 | while (m_ListBox.GetNumItems()) { |
| 1345 | UIItem *item = m_ListBox.GetItem(0); |
| 1346 | m_ListBox.RemoveItem(item); |
| 1347 | delete item; |
| 1348 | } |
| 1349 | |
| 1350 | UIWindow::OnDestroy(); |
| 1351 | } |
| 1352 | |
| 1353 | //@@class NewUIFileDialog: public NewUIGameWindow |
| 1354 | //@@{ |
| 1355 | //@@ NewUIListBox m_ListBox; |
| 1356 | //@@ NewUIButton m_Ok; |
| 1357 | //@@ |
| 1358 | //@@ char m_SearchPath[_MAX_PATH]; |
| 1359 | //@@ char m_SearchExt[PSFILENAME_LEN]; |
| 1360 | //@@ char m_NewPath[_MAX_PATH]; |
| 1361 | //@@ |
| 1362 | //@@public: |
| 1363 | //@@ void Create(int x, int y, int w, int h, const char *path, const char *ext); |
| 1364 | //@@ |
| 1365 | //@@}; |