From cbdc4c33840ea4efa27e9aa38d71ea504f523081 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Tue, 18 Jan 2011 09:27:27 +0100 Subject: [PATCH] enable the initial language selector --- qcsrc/menu/menu.qc | 1 + qcsrc/menu/menu.qh | 2 ++ qcsrc/menu/xonotic/dialog_firstrun.c | 24 ++++++++++++++++++++---- qcsrc/menu/xonotic/languagelist.c | 9 ++------- qcsrc/menu/xonotic/util.qc | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 8e95cc1dbd..478dc39bc4 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -21,6 +21,7 @@ void SUB_Null() { }; void() m_init = { cvar_set("_menu_alpha", "0"); + prvm_language = strzone(cvar_string("prvm_language")); check_unacceptable_compiler_bugs(); diff --git a/qcsrc/menu/menu.qh b/qcsrc/menu/menu.qh index e42595e582..3188ef0b01 100644 --- a/qcsrc/menu/menu.qh +++ b/qcsrc/menu/menu.qh @@ -41,3 +41,5 @@ void SUB_Null(); float preMenuInit(); // you have to define this for pre-menu initialization. Return 0 if initialization needs to be retried a frame later, 1 if it succeeded. void preMenuDraw(); // this is run before the menu is drawn. You may put some stuff there that has to be done every frame. void postMenuDraw(); // this is run just after the menu is drawn (or not). Useful to draw something over everything else. + +string prvm_language; diff --git a/qcsrc/menu/xonotic/dialog_firstrun.c b/qcsrc/menu/xonotic/dialog_firstrun.c index 5b3e0d1077..b337d138b8 100644 --- a/qcsrc/menu/xonotic/dialog_firstrun.c +++ b/qcsrc/menu/xonotic/dialog_firstrun.c @@ -4,7 +4,7 @@ CLASS(XonoticFirstRunDialog) EXTENDS(XonoticRootDialog) ATTRIB(XonoticFirstRunDialog, title, string, _("Welcome")) ATTRIB(XonoticFirstRunDialog, color, vector, SKINCOLOR_DIALOG_FIRSTRUN) ATTRIB(XonoticFirstRunDialog, intendedWidth, float, 0.6) - ATTRIB(XonoticFirstRunDialog, rows, float, 11) + ATTRIB(XonoticFirstRunDialog, rows, float, 14) ATTRIB(XonoticFirstRunDialog, columns, float, 3) ATTRIB(XonoticFirstRunDialog, name, string, "FirstRun") ATTRIB(XonoticFirstRunDialog, playerNameLabel, entity, NULL) @@ -15,6 +15,15 @@ ENDCLASS(XonoticFirstRunDialog) #endif #ifdef IMPLEMENTATION +float CheckFirstRunButton(entity me) +{ + if(cvar_string("_cl_name") != "Player") + return 1; + if(cvar_string("prvm_language") != prvm_language) + return 1; // OK will then reopen the dialog in another language + return 0; +} + void XonoticFirstRunDialog_fill(entity me) { entity e; @@ -23,6 +32,15 @@ void XonoticFirstRunDialog_fill(entity me) me.TD(me, 2, 3, e = makeXonoticTextLabel(0, _("Please answer a few initial questions to enhance the game experience."))); e.allowWrap = 1; me.TR(me); + me.TR(me); + me.TD(me, 1, 3, e = makeXonoticTextLabel(0, _("Text language:"))); + me.TR(me); + me.TD(me, 3, 3, e = makeXonoticLanguageList()); + e.name = "languageselector_firstrun"; + e.doubleClickCommand = "saveconfig; menu_restart; togglemenu"; + me.TR(me); + me.TR(me); + me.TR(me); me.TD(me, 1, 0.5, me.playerNameLabel = makeXonoticTextLabel(0, _("Name:"))); me.playerNameLabelAlpha = me.playerNameLabel.alpha; @@ -42,12 +60,10 @@ void XonoticFirstRunDialog_fill(entity me) me.TR(me); me.TR(me); me.TR(me); - me.TR(me); - me.TR(me); // because of the language selector, this is a menu_restart! me.gotoRC(me, me.rows - 1, 0); me.TD(me, 1, me.columns, e = makeXonoticCommandButton(_("Save settings"), '0 0 0', "saveconfig; menu_restart; togglemenu", COMMANDBUTTON_APPLY)); - setDependentStringNotEqual(e, "_cl_name", "Player"); + setDependentWeird(e, CheckFirstRunButton); } #endif diff --git a/qcsrc/menu/xonotic/languagelist.c b/qcsrc/menu/xonotic/languagelist.c index 510c7a9ea5..97bbfed46b 100644 --- a/qcsrc/menu/xonotic/languagelist.c +++ b/qcsrc/menu/xonotic/languagelist.c @@ -26,6 +26,7 @@ CLASS(XonoticLanguageList) EXTENDS(XonoticListBox) METHOD(XonoticLanguageList, languageParameter, string(entity, float, float)) ATTRIB(XonoticLanguageList, name, string, "languageselector") // change this to make it noninteractive (for first run dialog) + ATTRIB(XonoticLanguageList, doubleClickCommand, string, "menu_restart\ntogglemenu\ndefer 0.1 \"menu_cmd languageselect\"") ENDCLASS(XonoticLanguageList) entity makeXonoticLanguageList(); @@ -114,8 +115,6 @@ void XonoticLanguageList_saveCvars(entity me) void XonoticLanguageList_clickListBoxItem(entity me, float i, vector where) { - if(me.name != "languageselector") - return; if(i == me.lastClickedLanguage) if(time < me.lastClickedTime + 0.3) { @@ -129,8 +128,6 @@ void XonoticLanguageList_clickListBoxItem(entity me, float i, vector where) float XonoticLanguageList_keyDown(entity me, float scan, float ascii, float shift) { - if(me.name != "languageselector") - return SUPER(XonoticLanguageList).keyDown(me, scan, ascii, shift); if(scan == K_ENTER || scan == K_KP_ENTER) { me.setLanguage(me); return 1; @@ -170,9 +167,7 @@ void XonoticLanguageList_getLanguages(entity me) void XonoticLanguageList_setLanguage(entity me) { - if(me.name != "languageselector") - return; - localcmd("\nmenu_restart\ntogglemenu\ndefer 0.1 \"menu_cmd languageselect\"\n"); + localcmd(sprintf("\n%s\n", me.doubleClickCommand)); } string XonoticLanguageList_languageParameter(entity me, float i, float key) diff --git a/qcsrc/menu/xonotic/util.qc b/qcsrc/menu/xonotic/util.qc index 3053a903db..26a9c9912b 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -571,7 +571,7 @@ string language_filename(string s) { string fn; float fh; - fn = cvar_string("prvm_language"); + fn = prvm_language; if(fn == "" || fn == "dump") return s; fn = strcat(s, ".", fn); -- 2.39.2