From 251c931c90a70532ddd4c7f1d7e0d73b66f11e76 Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 23 Jan 2009 10:51:33 +0000 Subject: [PATCH] cvar list editor git-svn-id: svn://svn.icculus.org/nexuiz/trunk@5637 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/menu/classes.c | 2 + data/qcsrc/menu/item/label.c | 15 +- data/qcsrc/menu/mbuiltin.qh | 3 + data/qcsrc/menu/nexuiz/campaign.c | 34 +--- data/qcsrc/menu/nexuiz/cvarlist.c | 172 ++++++++++++++++++ data/qcsrc/menu/nexuiz/dialog_settings_misc.c | 7 + .../menu/nexuiz/dialog_settings_misc_cvars.c | 69 +++++++ data/qcsrc/menu/nexuiz/mainwindow.c | 5 + data/qcsrc/menu/nexuiz/util.qc | 37 ++++ data/qcsrc/menu/nexuiz/util.qh | 3 + data/qcsrc/menu/skin-customizables.inc | 8 + 11 files changed, 327 insertions(+), 28 deletions(-) create mode 100644 data/qcsrc/menu/nexuiz/cvarlist.c create mode 100644 data/qcsrc/menu/nexuiz/dialog_settings_misc_cvars.c diff --git a/data/qcsrc/menu/classes.c b/data/qcsrc/menu/classes.c index e0d265925..fd032b256 100644 --- a/data/qcsrc/menu/classes.c +++ b/data/qcsrc/menu/classes.c @@ -76,3 +76,5 @@ #include "nexuiz/dialog_multiplayer_demo.c" #include "nexuiz/demolist.c" #include "nexuiz/colorpicker.c" +#include "nexuiz/cvarlist.c" +#include "nexuiz/dialog_settings_misc_cvars.c" diff --git a/data/qcsrc/menu/item/label.c b/data/qcsrc/menu/item/label.c index 103dcf397..0302f4e20 100644 --- a/data/qcsrc/menu/item/label.c +++ b/data/qcsrc/menu/item/label.c @@ -20,6 +20,7 @@ CLASS(Label) EXTENDS(Item) ATTRIB(Label, disabled, float, 0) ATTRIB(Label, disabledAlpha, float, 0.3) ATTRIB(Label, textEntity, entity, NULL) + ATTRIB(Label, allowWrap, float, 0) ENDCLASS(Label) #endif @@ -54,6 +55,7 @@ void configureLabelLabel(entity me, string txt, float sz, float algn) void drawLabel(entity me) { string t; + vector o; if(me.disabled) draw_alpha *= me.disabledAlpha; @@ -68,8 +70,19 @@ void drawLabel(entity me) if(me.fontSize) if(t) { - if(me.allowCut) + if(me.allowCut) // FIXME allowCut incompatible with align != 0 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight) / me.realFontSize_x, 0), me.realFontSize, me.colorL, me.alpha, 0); + else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0 + { + getWrappedLine_remaining = t; + o = me.realOrigin; + while(getWrappedLine_remaining) + { + t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight) / me.realFontSize_x); + draw_Text(o, t, me.realFontSize, me.colorL, me.alpha, 0); + o_y += me.realFontSize_y; + } + } else draw_Text(me.realOrigin, t, me.realFontSize, me.colorL, me.alpha, 0); } diff --git a/data/qcsrc/menu/mbuiltin.qh b/data/qcsrc/menu/mbuiltin.qh index 78adf25db..643a4aa15 100644 --- a/data/qcsrc/menu/mbuiltin.qh +++ b/data/qcsrc/menu/mbuiltin.qh @@ -287,6 +287,8 @@ string(float bufhandle, float string_index) bufstr_get = #446; void(float bufhandle, float string_index, string str) bufstr_set = #447; float(float bufhandle, string str, float order) bufstr_add = #448; void(float bufhandle, float string_index) bufstr_free = #449; +void(float bufhandle, string pattern, string antipattern) buf_cvarlist = #517; +string(string name) cvar_description = #518; //DP_QC_CRC16 //idea: div0 @@ -302,6 +304,7 @@ float CVAR_TYPEFLAG_SAVED = 2; float CVAR_TYPEFLAG_PRIVATE = 4; float CVAR_TYPEFLAG_ENGINE = 8; float CVAR_TYPEFLAG_HASDESCRIPTION = 16; +float CVAR_TYPEFLAG_READONLY = 32; //DP_QC_URI_ESCAPE //idea: div0 diff --git a/data/qcsrc/menu/nexuiz/campaign.c b/data/qcsrc/menu/nexuiz/campaign.c index 824245ad4..90e9da4ca 100644 --- a/data/qcsrc/menu/nexuiz/campaign.c +++ b/data/qcsrc/menu/nexuiz/campaign.c @@ -52,7 +52,7 @@ string campaign_longdesc_wrapped[CAMPAIGN_MAX_ENTRIES]; void rewrapCampaign(float w, float l0, float emptyheight) { float i, j; - float n, take, cantake, l; + float n, l; string r, s; for(i = 0; i < campaign_entries; ++i) { @@ -70,33 +70,13 @@ void rewrapCampaign(float w, float l0, float emptyheight) r = strcat(r, "\n"); continue; } - for(;;) + + getWrappedLine_remaining = s; + while(getWrappedLine_remaining) { - cantake = draw_TextLengthUpToWidth(s, w, 0); - if(cantake > 0 && cantake < strlen(s)) - { - take = cantake - 1; - while(take > 0 && substring(s, take, 1) != " ") - --take; - if(take == 0) - { - if(--l < 0) goto toolong; - r = strcat(r, substring(s, 0, cantake), "\n"); - s = substring(s, cantake, strlen(s) - cantake); - } - else - { - if(--l < 0) goto toolong; - r = strcat(r, substring(s, 0, take), "\n"); - s = substring(s, take + 1, strlen(s) - take); - } - } - else - { - if(--l < 0) goto toolong; - r = strcat(r, s, "\n"); - break; - } + s = getWrappedLine(w); + if(--l < 0) goto toolong; + r = strcat(r, s, "\n"); } } goto nottoolong; diff --git a/data/qcsrc/menu/nexuiz/cvarlist.c b/data/qcsrc/menu/nexuiz/cvarlist.c new file mode 100644 index 000000000..f2ca75dd3 --- /dev/null +++ b/data/qcsrc/menu/nexuiz/cvarlist.c @@ -0,0 +1,172 @@ +#ifdef INTERFACE +CLASS(NexuizCvarList) EXTENDS(NexuizListBox) + METHOD(NexuizCvarList, configureNexuizCvarList, void(entity)) + ATTRIB(NexuizCvarList, rowsPerItem, float, 1) + METHOD(NexuizCvarList, drawListBoxItem, void(entity, float, vector, float)) + METHOD(NexuizCvarList, resizeNotify, void(entity, vector, vector, vector, vector)) + METHOD(NexuizCvarList, keyDown, float(entity, float, float, float)) + + ATTRIB(NexuizCvarList, realFontSize, vector, '0 0 0') + ATTRIB(NexuizCvarList, realUpperMargin, float, 0) + ATTRIB(NexuizCvarList, columnNameOrigin, float, 0) + ATTRIB(NexuizCvarList, columnNameSize, float, 0) + ATTRIB(NexuizCvarList, columnValueOrigin, float, 0) + ATTRIB(NexuizCvarList, columnValueSize, float, 0) + + METHOD(NexuizCvarList, setSelected, void(entity, float)) + ATTRIB(NexuizCvarList, controlledTextbox, entity, NULL) + ATTRIB(NexuizCvarList, cvarNameBox, entity, NULL) + ATTRIB(NexuizCvarList, cvarDescriptionBox, entity, NULL) + ATTRIB(NexuizCvarList, cvarTypeBox, entity, NULL) + ATTRIB(NexuizCvarList, cvarValueBox, entity, NULL) + ATTRIB(NexuizCvarList, cvarDefaultBox, entity, NULL) + + ATTRIB(NexuizCvarList, handle, float, -1) + ATTRIB(NexuizCvarList, cvarName, string, string_null) + ATTRIB(NexuizCvarList, cvarDescription, string, string_null) + ATTRIB(NexuizCvarList, cvarType, string, string_null) + ATTRIB(NexuizCvarList, cvarDefault, string, string_null) +ENDCLASS(NexuizCvarList) +entity makeNexuizCvarList(); +void CvarList_Filter_Change(entity box, entity me); +void CvarList_Value_Change(entity box, entity me); +void CvarList_Revert_Click(entity btn, entity me); +#endif + +#ifdef IMPLEMENTATION +entity makeNexuizCvarList() +{ + entity me; + me = spawnNexuizCvarList(); + me.configureNexuizCvarList(me); + return me; +} +void configureNexuizCvarListNexuizCvarList(entity me) +{ + me.configureNexuizListBox(me); + + me.handle = buf_create(); + buf_cvarlist(me.handle, "", "_"); + me.nItems = buf_getsize(me.handle); +} +void setSelectedNexuizCvarList(entity me, float i) +{ + string s; + + setSelectedListBox(me, i); + if(me.nItems == 0) + return; + + if(me.cvarName) + strunzone(me.cvarName); + if(me.cvarDescription) + strunzone(me.cvarDescription); + if(me.cvarType) + strunzone(me.cvarType); + if(me.cvarDefault) + strunzone(me.cvarDefault); + me.cvarName = strzone(bufstr_get(me.handle, me.selectedItem)); + me.cvarDescription = strzone(cvar_description(me.cvarName)); + me.cvarDefault = strzone(cvar_defstring(me.cvarName)); + + float t; + t = cvar_type(me.cvarName); + me.cvarType = ""; + if(t & CVAR_TYPEFLAG_SAVED) + me.cvarType = strcat(me.cvarType, ", will be saved to config.cfg"); + else + me.cvarType = strcat(me.cvarType, ", will not be saved"); + if(t & CVAR_TYPEFLAG_PRIVATE) + me.cvarType = strcat(me.cvarType, ", private"); + if(t & CVAR_TYPEFLAG_ENGINE) + me.cvarType = strcat(me.cvarType, ", engine setting"); + if(t & CVAR_TYPEFLAG_READONLY) + me.cvarType = strcat(me.cvarType, ", read only"); + me.cvarType = strzone(substring(me.cvarType, 2, strlen(me.cvarType) - 2)); + + me.cvarNameBox.setText(me.cvarNameBox, me.cvarName); + me.cvarDescriptionBox.setText(me.cvarDescriptionBox, me.cvarDescription); + me.cvarTypeBox.setText(me.cvarTypeBox, me.cvarType); + me.cvarDefaultBox.setText(me.cvarDefaultBox, me.cvarDefault); + + // this one can handle tempstrings + s = cvar_string(me.cvarName); + me.cvarValueBox.setText(me.cvarValueBox, s); + me.cvarValueBox.cursorPos = strlen(s); +} +void CvarList_Filter_Change(entity box, entity me) +{ + buf_cvarlist(me.handle, box.text, "_"); + me.nItems = buf_getsize(me.handle); + + me.setSelected(me, 0); +} +void resizeNotifyNexuizCvarList(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) +{ + resizeNotifyNexuizListBox(me, relOrigin, relSize, absOrigin, absSize); + + me.realFontSize_y = me.fontSize / (absSize_y * me.itemHeight); + me.realFontSize_x = me.fontSize / (absSize_x * (1 - me.controlWidth)); + me.realUpperMargin = 0.5 * (1 - me.realFontSize_y); + + me.columnNameOrigin = 0; + me.columnValueSize = me.realFontSize_x * 20; + me.columnNameSize = 1 - me.columnValueSize - me.realFontSize_x; + me.columnValueOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize_x; + + me.setSelected(me, me.selectedItem); +} +void drawListBoxItemNexuizCvarList(entity me, float i, vector absSize, float isSelected) +{ + string k, v, d; + float t; + + vector theColor; + float theAlpha; + + string s; + + if(isSelected) + draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); + + k = bufstr_get(me.handle, i); + + v = cvar_string(k); + d = cvar_defstring(k); + t = cvar_type(k); + if(t & CVAR_TYPEFLAG_SAVED) + theAlpha = SKINALPHA_CVARLIST_SAVED; + else + theAlpha = SKINALPHA_CVARLIST_TEMPORARY; + if(v == d) + theColor = SKINCOLOR_CVARLIST_UNCHANGED; + else + theColor = SKINCOLOR_CVARLIST_CHANGED; + + s = draw_TextShortenToWidth(k, me.columnNameSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0); + s = draw_TextShortenToWidth(v, me.columnValueSize / me.realFontSize_x, 0); + draw_Text(me.realUpperMargin * eY + me.columnValueOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0); +} + +float keyDownNexuizCvarList(entity me, float scan, float ascii, float shift) +{ + if(keyDownListBox(me, scan, ascii, shift)) + return 1; + else if(!me.controlledTextbox) + return 0; + else + return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift); +} + +void CvarList_Value_Change(entity box, entity me) +{ + cvar_set(me.cvarNameBox.text, box.text); +} + +void CvarList_Revert_Click(entity btn, entity me) +{ + me.cvarValueBox.setText(me.cvarValueBox, me.cvarDefault); + me.cvarValueBox.cursorPos = strlen(me.cvarDefault); +} +#endif diff --git a/data/qcsrc/menu/nexuiz/dialog_settings_misc.c b/data/qcsrc/menu/nexuiz/dialog_settings_misc.c index fd15920b6..93364434e 100644 --- a/data/qcsrc/menu/nexuiz/dialog_settings_misc.c +++ b/data/qcsrc/menu/nexuiz/dialog_settings_misc.c @@ -49,5 +49,12 @@ void fillNexuizMiscSettingsTab(entity me) me.TD(me, 1, 2.8/3, e = makeNexuizRadioButton(1, "showspeed", "3", "km/h")); me.TD(me, 1, 2.8/3, e = makeNexuizRadioButton(1, "showspeed", "4", "mph")); me.TD(me, 1, 2.8/3, e = makeNexuizRadioButton(1, "showspeed", "5", "knots")); + me.TR(me); + me.TR(me); + me.TDempty(me, 0.5); + me.TD(me, 1, 2, e = makeNexuizButton("Advanced settings...", '0 0 0')); + e.onClick = DialogOpenButton_Click; + e.onClickEntity = main.cvarsDialog; + me.TDempty(me, 0.5); } #endif diff --git a/data/qcsrc/menu/nexuiz/dialog_settings_misc_cvars.c b/data/qcsrc/menu/nexuiz/dialog_settings_misc_cvars.c new file mode 100644 index 000000000..7b10a8d08 --- /dev/null +++ b/data/qcsrc/menu/nexuiz/dialog_settings_misc_cvars.c @@ -0,0 +1,69 @@ +#ifdef INTERFACE +CLASS(NexuizCvarsDialog) EXTENDS(NexuizDialog) + METHOD(NexuizCvarsDialog, toString, string(entity)) + METHOD(NexuizCvarsDialog, fill, void(entity)) + METHOD(NexuizCvarsDialog, showNotify, void(entity)) + ATTRIB(NexuizCvarsDialog, title, string, "Advanced settings") + ATTRIB(NexuizCvarsDialog, color, vector, SKINCOLOR_DIALOG_CVARS) + ATTRIB(NexuizCvarsDialog, intendedWidth, float, 0.8) + ATTRIB(NexuizCvarsDialog, rows, float, 25) + ATTRIB(NexuizCvarsDialog, columns, float, 6) +ENDCLASS(NexuizCvarsDialog) +#endif + +#ifdef IMPLEMENTATION +void showNotifyNexuizCvarsDialog(entity me) +{ + loadAllCvars(me); +} +string toStringNexuizCvarsDialog(entity me) +{ + return "XXX"; +} +void fillNexuizCvarsDialog(entity me) +{ + entity e, cvarlist, btn; + cvarlist = makeNexuizCvarList(); + me.TR(me); + me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Cvar filter:")); + me.TD(me, 1, 0.5, btn = makeNexuizButton("Clear", '0 0 0')); + me.TD(me, 1, me.columns - 1.5, e = makeNexuizInputBox(0, string_null)); + e.onChange = CvarList_Filter_Change; + e.onChangeEntity = cvarlist; + btn.onClick = InputBox_Clear_Click; + btn.onClickEntity = e; + cvarlist.controlledTextbox = e; // this COULD also be the Value box, but this leads to accidentally editing stuff + me.TR(me); + me.TD(me, me.rows - me.currentRow - 7, me.columns, cvarlist); + me.gotoRC(me, me.rows - 7, 0); + me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Setting:")); + me.TD(me, 1, me.columns - 1, e = makeNexuizTextLabel(0, string_null)); + cvarlist.cvarNameBox = e; + me.TR(me); + me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Type:")); + me.TD(me, 1, me.columns - 1, e = makeNexuizTextLabel(0, string_null)); + cvarlist.cvarTypeBox = e; + me.TR(me); + me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Value:")); + me.TD(me, 1, me.columns - 2, e = makeNexuizInputBox(0, string_null)); + cvarlist.cvarValueBox = e; + e.onChange = CvarList_Value_Change; + e.onChangeEntity = cvarlist; + me.TD(me, 1, 1, e = makeNexuizButton(string_null, SKINCOLOR_CVARLIST_REVERTBUTTON)); + cvarlist.cvarDefaultBox = e; + e.onClick = CvarList_Revert_Click; + e.onClickEntity = cvarlist; + e.allowCut = 1; + e.marginLeft = e.marginRight = 0.5; + me.TR(me); + me.TD(me, 1, 1, e = makeNexuizTextLabel(0, "Description:")); + me.TD(me, 1, me.columns - 1, e = makeNexuizTextLabel(0, string_null)); + cvarlist.cvarDescriptionBox = e; + e.allowWrap = 1; + me.gotoRC(me, me.rows - 1, 0); + me.TD(me, 1, me.columns, e = makeNexuizButton("OK", '0 0 0')); + e.onClick = Dialog_Close; + e.onClickEntity = me; +} + +#endif diff --git a/data/qcsrc/menu/nexuiz/mainwindow.c b/data/qcsrc/menu/nexuiz/mainwindow.c index e47ddb88c..d6012de52 100644 --- a/data/qcsrc/menu/nexuiz/mainwindow.c +++ b/data/qcsrc/menu/nexuiz/mainwindow.c @@ -8,6 +8,7 @@ CLASS(MainWindow) EXTENDS(ModalController) ATTRIB(MainWindow, winnerDialog, entity, NULL) ATTRIB(MainWindow, radarDialog, entity, NULL) ATTRIB(MainWindow, serverInfoDialog, entity, NULL) + ATTRIB(MainWindow, cvarsDialog, entity, NULL) ATTRIB(MainWindow, mainNexposee, entity, NULL) ATTRIB(MainWindow, fadedAlpha, float, SKINALPHA_BEHIND) ENDCLASS(MainWindow) @@ -59,6 +60,10 @@ void configureMainWindowMainWindow(entity me) i.configureDialog(i); me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z); + me.cvarsDialog = i = spawnNexuizCvarsDialog(); + i.configureDialog(i); + me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z); + me.mainNexposee = n = spawnNexuizNexposee(); /* if(checkextension("DP_GECKO_SUPPORT")) diff --git a/data/qcsrc/menu/nexuiz/util.qc b/data/qcsrc/menu/nexuiz/util.qc index fdf62799f..35968f931 100644 --- a/data/qcsrc/menu/nexuiz/util.qc +++ b/data/qcsrc/menu/nexuiz/util.qc @@ -312,3 +312,40 @@ void preMenuDraw() campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won")); } } + +string getWrappedLine_remaining; +string getWrappedLine(float w) +{ + float cantake; + float take; + string s; + + s = getWrappedLine_remaining; + + cantake = draw_TextLengthUpToWidth(s, w, 0); + if(cantake > 0 && cantake < strlen(s)) + { + take = cantake - 1; + while(take > 0 && substring(s, take, 1) != " ") + --take; + if(take == 0) + { + getWrappedLine_remaining = substring(s, cantake, strlen(s) - cantake); + if(getWrappedLine_remaining == "") + getWrappedLine_remaining = string_null; + return substring(s, 0, cantake); + } + else + { + getWrappedLine_remaining = substring(s, take + 1, strlen(s) - take); + if(getWrappedLine_remaining == "") + getWrappedLine_remaining = string_null; + return substring(s, 0, take); + } + } + else + { + getWrappedLine_remaining = string_null; + return s; + } +} diff --git a/data/qcsrc/menu/nexuiz/util.qh b/data/qcsrc/menu/nexuiz/util.qh index f5d1f75ce..d2be97aa5 100644 --- a/data/qcsrc/menu/nexuiz/util.qh +++ b/data/qcsrc/menu/nexuiz/util.qh @@ -9,3 +9,6 @@ void setDependentAND(entity e, string theCvarName, float theCvarMin, float theCv void setDependentOR(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max); void setDependentAND3(entity e, string theCvarName, float theCvarMin, float theCvarMax, string theCvar2Name, float theCvar2Min, float theCvar2Max, string theCvar3Name, float theCvar3Min, float theCvar3Max); void setDependentStringNotEqual(entity e, string theCvarName, string theCvarValue); + +string getWrappedLine_remaining; +string getWrappedLine(float w); diff --git a/data/qcsrc/menu/skin-customizables.inc b/data/qcsrc/menu/skin-customizables.inc index 2d1866cd1..c78d7bd30 100644 --- a/data/qcsrc/menu/skin-customizables.inc +++ b/data/qcsrc/menu/skin-customizables.inc @@ -53,6 +53,7 @@ SKINBEGIN SKINVECTOR(COLOR_DIALOG_WEAPONS, '1 0.7 0.7'); SKINVECTOR(COLOR_DIALOG_RADAR, '0.7 0.7 1'); SKINVECTOR(COLOR_DIALOG_SERVERINFO, '0.7 0.7 1'); + SKINVECTOR(COLOR_DIALOG_CVARS, '1 0 0'); // nexposee positions of windows (they are the scale transformation // centers, NOT the actual positions of the windows!) @@ -119,6 +120,13 @@ SKINBEGIN // item: crosshair button SKINSTRING(GFX_CROSSHAIRBUTTON, "crosshairbutton"); + // item: cvar list + SKINFLOAT(ALPHA_CVARLIST_SAVED, 1); + SKINFLOAT(ALPHA_CVARLIST_TEMPORARY, 0.7); + SKINVECTOR(COLOR_CVARLIST_CHANGED, '1 1 0.4'); + SKINVECTOR(COLOR_CVARLIST_REVERTBUTTON, '1 0 0'); + SKINVECTOR(COLOR_CVARLIST_UNCHANGED, '1 1 1'); + // item: dialog SKINSTRING(GFX_DIALOGBORDER, "border"); SKINSTRING(GFX_CLOSEBUTTON, "closebutton"); -- 2.39.2