ui_popup.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 */
00024 
00025 #include "ui_main.h"
00026 #include "ui_nodes.h"
00027 #include "ui_popup.h"
00028 #include "ui_actions.h"
00029 #include "node/ui_node_abstractnode.h"
00030 
00031 #define POPUPBUTTON_WINDOW_NAME "popup_button"
00032 #define POPUPBUTTON_NODE_NAME "popup_button_"
00033 #define POPUP_WINDOW_NAME "popup"
00034 
00036 char popupText[UI_MAX_SMALLTEXTLEN];
00037 static char popupAction1[UI_MAX_SMALLTEXTLEN];
00038 static char popupAction2[UI_MAX_SMALLTEXTLEN];
00039 static char popupAction3[UI_MAX_SMALLTEXTLEN];
00040 
00046 void UI_Popup (const char *title, const char *text)
00047 {
00048     Cvar_Set("mn_sys_popup_title", title);
00049     UI_RegisterText(TEXT_POPUP_INFO, text);
00050     if (!UI_IsWindowOnStack(POPUP_WINDOW_NAME))
00051         UI_PushWindow(POPUP_WINDOW_NAME, NULL);
00052 }
00053 
00061 uiNode_t *UI_PopupList (const char *title, const char *headline, linkedList_t* entries, const char *clickAction)
00062 {
00063     uiNode_t* window;
00064     uiNode_t* listNode;
00065 
00066     Cvar_Set("mn_sys_popup_title", title);
00067     UI_RegisterText(TEXT_POPUP_INFO, headline);
00068 
00069     /* make sure, that we are using the linked list */
00070     UI_ResetData(TEXT_LIST);
00071     UI_RegisterLinkedListText(TEXT_LIST, entries);
00072 
00073     window = UI_GetWindow(POPUPLIST_WINDOW_NAME);
00074     if (!window)
00075         Com_Error(ERR_FATAL, "Could not get "POPUPLIST_WINDOW_NAME" window");
00076     listNode = UI_GetNode(window, POPUPLIST_NODE_NAME);
00077     if (!listNode)
00078         Com_Error(ERR_FATAL, "Could not get "POPUPLIST_NODE_NAME" node in "POPUPLIST_WINDOW_NAME" window");
00079 
00080     /* free previous actions */
00081     if (listNode->onClick) {
00082         assert(listNode->onClick->d.terminal.d1.data);
00083         Mem_Free(listNode->onClick->d.terminal.d1.data);
00084         Mem_Free(listNode->onClick);
00085         listNode->onClick = NULL;
00086     }
00087 
00088     if (clickAction) {
00089         UI_PoolAllocAction(&listNode->onClick, EA_CMD, clickAction);
00090     } else {
00091         listNode->onClick = NULL;
00092     }
00093 
00094     if (!UI_IsWindowOnStack(window->name))
00095         UI_PushWindow(window->name, NULL);
00096     return listNode;
00097 }
00098 
00106 static void UI_SetOneButton (uiNode_t* window, const char *button, const char *clickAction)
00107 {
00108     uiNode_t* buttonNode;
00109 
00110     buttonNode = UI_GetNode(window, button);
00111     if (!buttonNode)
00112         Com_Error(ERR_FATAL, "Could not get %s node in %s window", button, window->name);
00113 
00114     /* free previous actions */
00115     if (buttonNode->onClick) {
00116         assert(buttonNode->onClick->d.terminal.d1.data);
00117         Mem_Free(buttonNode->onClick->d.terminal.d1.data);
00118         Mem_Free(buttonNode->onClick);
00119         buttonNode->onClick = NULL;
00120     }
00121 
00122     if (clickAction) {
00123         UI_PoolAllocAction(&buttonNode->onClick, EA_CMD, clickAction);
00124         buttonNode->invis = qfalse;
00125     } else {
00126         buttonNode->onClick = NULL;
00127         buttonNode->invis = qtrue;
00128     }
00129 }
00130 
00146 void UI_PopupButton (const char *title, const char *text,
00147     const char *clickAction1, const char *clickText1, const char *tooltip1,
00148     const char *clickAction2, const char *clickText2, const char *tooltip2,
00149     const char *clickAction3, const char *clickText3, const char *tooltip3)
00150 {
00151     uiNode_t* window;
00152 
00153     Cvar_Set("mn_sys_popup_title", title);
00154     if (text)
00155         UI_RegisterText(TEXT_POPUP_INFO, text);
00156     else
00157         UI_RegisterText(TEXT_POPUP_INFO, popupText);
00158 
00159     window = UI_GetWindow(POPUPBUTTON_WINDOW_NAME);
00160     if (!window)
00161         Com_Error(ERR_FATAL, "Could not get \""POPUPBUTTON_WINDOW_NAME"\" window");
00162 
00163     Cvar_Set("mn_sys_popup_button_text1", clickText1);
00164     Cvar_Set("mn_sys_popup_button_tooltip1", tooltip1);
00165     if (!clickAction1 && !clickText1) {
00166         UI_SetOneButton(window, va("%s1", POPUPBUTTON_NODE_NAME),
00167             NULL);
00168     } else {
00169         UI_SetOneButton(window, va("%s1", POPUPBUTTON_NODE_NAME),
00170             clickAction1 ? clickAction1 : popupAction1);
00171     }
00172 
00173     Cvar_Set("mn_sys_popup_button_text2", clickText2);
00174     Cvar_Set("mn_sys_popup_button_tooltip2", tooltip2);
00175     if (!clickAction2 && !clickText2) {
00176         UI_SetOneButton(window, va("%s2", POPUPBUTTON_NODE_NAME), NULL);
00177     } else {
00178         UI_SetOneButton(window, va("%s2", POPUPBUTTON_NODE_NAME),
00179             clickAction2 ? clickAction2 : popupAction2);
00180     }
00181 
00182     Cvar_Set("mn_sys_popup_button_text3", clickText3);
00183     Cvar_Set("mn_sys_popup_button_tooltip3", tooltip3);
00184     if (!clickAction3 && !clickText3) {
00185         UI_SetOneButton(window, va("%s3", POPUPBUTTON_NODE_NAME), NULL);
00186     } else {
00187         UI_SetOneButton(window, va("%s3", POPUPBUTTON_NODE_NAME),
00188             clickAction3 ? clickAction3 : popupAction3);
00189     }
00190 
00191     if (!UI_IsWindowOnStack(window->name))
00192         UI_PushWindow(window->name, NULL);
00193 }

Generated by  doxygen 1.6.2