Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.19 KB | None | 0 0
  1. #include "../cg_local.h"
  2. #include "../menu/m_local.h"
  3.  
  4. //
  5. //
  6. //
  7. // NOTE: THIS FILE IS PROTOTYPING, IT HAS TO BE CLEANED UP BY SPLITTING IN SEPARATE FILES.
  8. // AND ALSO BY GENERIZING THIS SYSTEM SO IT CAN ACTIVATE REGISTERED MENU_IDS.
  9. //
  10. //
  11. //
  12.  
  13. typedef struct g_messagelist_s
  14. {
  15.     char            *message;
  16. } g_messagelist_t;
  17. typedef struct g_optionlist_s
  18. {
  19.     char            *message;
  20.  
  21.     qBool(*option_use)(char idx);
  22. } g_optionlist_t;
  23.  
  24. // TODO: Clean up.
  25. #define MENU_OPTION_LIMIT 4
  26. typedef struct m_menu_id_1_s {
  27.     // Menu items
  28.     uiFrameWork_t       frameWork;
  29.  
  30.     uiAction_t          message_text;
  31.     uiAction_t          option_actions[MENU_OPTION_LIMIT]; // LIMIT = 4..
  32.  
  33.     // These are important, since they supply the data.
  34.     // NOTE: menu_id is not here, it is elsewhere since it is
  35.     // used with registering etc.
  36.     char                message_id;
  37.     char                optionlist_id;
  38. } m_menu_id_1_t;
  39.  
  40. // Vars, temp too...
  41. static m_menu_id_1_t m_menu_id_1;
  42. qBool menu_init;
  43.  
  44. // These are important, should be redefined in each file for code to be generic.
  45. g_messagelist_t m_menu_messages[] = {
  46.     {
  47.         "I'm just a boring text message. ID #0",
  48.     },
  49.     {
  50.         "The sound of silence bro, really. ID #1",
  51.     },
  52.     {
  53.         NULL
  54.     }
  55. };
  56.  
  57. g_optionlist_t m_menu_options[] = {
  58.     {
  59.         "Option A may be okay. ID #0",
  60.         NULL
  61.     },
  62.     {
  63.         "Option B makes me pee. ID #1",
  64.         NULL
  65.     },
  66.     {
  67.         "Option C is not for me. ID #2",
  68.         NULL
  69.     },
  70.     {
  71.         "Option D is the death of me. ID #3",
  72.         NULL
  73.     }
  74. };
  75.  
  76. static void menu_id_1_no(void *unused) {
  77.     Com_Printf(PRNT_CHATHUD, "NO");
  78. }
  79. static void menu_id_1_yes(void *unused) {
  80.     Com_Printf(PRNT_CHATHUD, "YES");
  81. }
  82.  
  83. void menu_id_1_init() {
  84.     menu_init = qTrue;
  85.  
  86.     // Init menu...
  87.     UI_StartFramework(&m_menu_id_1.frameWork, FWF_CENTERHEIGHT);
  88.  
  89.     //
  90.     // Generate message.
  91.     //
  92.     // TODO: Do out of bounds error checking...
  93.     // If oob, make it say so which message ID is the cause: "Out of bounds, message_id: #.."
  94.     m_menu_id_1.message_text.generic.type = UITYPE_ACTION;
  95.     m_menu_id_1.message_text.generic.flags = UIF_NOSELECT | UIF_CENTERED | UIF_LARGE | UIF_SHADOW;
  96.     m_menu_id_1.message_text.generic.name = m_menu_messages[m_menu_id_1.message_id].message;
  97.     UI_AddItem(&m_menu_id_1.frameWork, &m_menu_id_1.message_text);
  98.  
  99.     //
  100.     // Generate menu options depending on which ID.
  101.     //
  102.     // TODO: Add the room for a space (empty option)
  103.     // TODO: Make sure it is based on size maybe instead of a fixed limit.
  104.     // TODO: Make sure it does out of bounds checking.
  105.     // TODO: Maybe allow a custom callback?
  106.     int i = 0;
  107.     for (i = 0; i < MENU_OPTION_LIMIT; i++) {
  108.         // Add if text is available, otherwise break out.
  109.         if (m_menu_options[i].message == NULL) {
  110.             break;
  111.         }
  112.  
  113.         m_menu_id_1.option_actions[i].generic.type = UITYPE_ACTION;
  114.         m_menu_id_1.option_actions[i].generic.flags = UIF_CENTERED;
  115.         m_menu_id_1.option_actions[i].generic.name = m_menu_options[i].message;
  116.         m_menu_id_1.option_actions[i].generic.callBack = menu_id_1_yes;
  117.         UI_AddItem(&m_menu_id_1.frameWork, &m_menu_id_1.option_actions[i]);
  118.     }
  119.  
  120.     UI_FinishFramework(&m_menu_id_1.frameWork, qTrue);
  121. }
  122.  
  123. static void menu_id_1_draw(void) {
  124.     float   y;
  125.     y = 0;
  126.     // Initialize if necessary
  127.     if (!m_menu_id_1.frameWork.initialized)
  128.         menu_id_1_init();
  129.  
  130.     // Dynamically position
  131.     m_menu_id_1.frameWork.x = cg.refConfig.vidWidth * 0.5f;
  132.     m_menu_id_1.frameWork.y = 0;
  133.  
  134.     m_menu_id_1.message_text.generic.x = 0;
  135.     m_menu_id_1.message_text.generic.y = 0;
  136.  
  137.     int i = 0;
  138.     for (i = 0; i < MENU_OPTION_LIMIT; i++) {
  139.         // Add if text is available, otherwise break out.
  140.         if (m_menu_options[i].message == NULL) {
  141.             break;
  142.         }
  143.  
  144.         m_menu_id_1.option_actions[i].generic.x = 0;
  145.         m_menu_id_1.option_actions[i].generic.y = y += UIFT_SIZEINCLG;
  146.     }
  147.  
  148.     // Render
  149.     UI_DrawInterface(&m_menu_id_1.frameWork);
  150. }
  151.  
  152. static struct sfx_s *menu_id_1_close(void)
  153. {
  154.     return uiMedia.sounds.menuOut;
  155. }
  156.  
  157. // Activate this menu.
  158. void menu_id_1_activate(char menu_id, char message_id, char optionlist_id) {
  159.     // This is temp...
  160.     if (menu_init == qFalse) {
  161.         menu_id_1_init();
  162.     }
  163.  
  164.     // Store IDs for this menu functionality.
  165.     m_menu_id_1.message_id = message_id;
  166.     m_menu_id_1.optionlist_id = optionlist_id;
  167.  
  168.     // Push menu.
  169.     M_PushMenu(&m_menu_id_1.frameWork, menu_id_1_draw, menu_id_1_close, M_KeyHandler);
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement