diff --git a/config/menus/advanced_options.cfg b/config/menus/advanced_options.cfg old mode 100644 new mode 100755 index 59d34881b..20151b849 --- a/config/menus/advanced_options.cfg +++ b/config/menus/advanced_options.cfg @@ -6,6 +6,12 @@ new_ui advanced_options [ menu_variables ] + ui_tab "Weapon Vars" + ui_strut 0.5 + ui_stay_open [ + ui_list [ weapmenu ] + ] + ui_tab "Autoexec" ui_strut 0.5 ui_stay_open [ @@ -16,4 +22,9 @@ new_ui advanced_options [ ] ] ] -] \ No newline at end of file +] [ + if (= $guipasses 0) [ + fill_variable_lists + ] +] + diff --git a/config/menus/glue.cfg b/config/menus/glue.cfg old mode 100644 new mode 100755 index f108c5c2d..016944a7a --- a/config/menus/glue.cfg +++ b/config/menus/glue.cfg @@ -24,6 +24,22 @@ ui_right = [ ui_list [ ui_spring 1; arg1 ] ] ui_center = [ ui_list [ ui_spring 1; arg1; ui_spring 1 ] ] ui_center_z = [ ui_list [ ui_spring 1; ui_list [ arg1 ]; ui_spring 1 ] ] + +// ui_border_box, creates box with textfield background and border and configurable padding. +// arg1 = padding left, arg2 = padding right, arg3 = padding top, arg4 = padding bottom, arg5 = body +ui_border_box = [ + ui_list [ + ui_background $ui_color_textfield_background $ui_blend_textfield_background $ui_color_textfield_border $ui_blend_textfield_border 1 + ui_strut $arg1 + ui_list [ + ui_strut $arg3 + arg5 + ui_strut $arg4 + ] + ui_strut $arg2 + ] +] + // spacers ui_small_spacer = [ ui_strut 0.2 ] ui_big_spacer = [ ui_strut 0.8 ] diff --git a/config/menus/package.cfg b/config/menus/package.cfg old mode 100644 new mode 100755 index c872b812b..385803231 --- a/config/menus/package.cfg +++ b/config/menus/package.cfg @@ -11,6 +11,7 @@ exec "config/menus/options.cfg" //exec "config/menus/vars_alt.cfg" //create_header_lists exec "config/menus/vars.cfg" +exec "config/menus/weapon_vars.cfg" exec "config/menus/editing.cfg" exec "config/menus/help.cfg" exec "config/menus/console.cfg" diff --git a/config/menus/weapon_vars.cfg b/config/menus/weapon_vars.cfg new file mode 100644 index 000000000..4e0c032fa --- /dev/null +++ b/config/menus/weapon_vars.cfg @@ -0,0 +1,597 @@ +// CC BY-SA 4-0 https://creativecommons.org/licenses/by-sa/4.0/legalcode +// Iceflower iceflower@gmx.de +// Modified by MoonPadUSer moonpaduser@mailbox.org + +VAR_TYPE_INTEGER = 0 +VAR_TYPE_FLOAT = 1 +VAR_TYPE_STRING = 2 + +variable_reset_button = [ + if (var_is_modified $cur_variable_name) [ + ui_button "^foReset" (format "%1 %2" $cur_variable_name $cur_variable_value_def) + ] [ ui_button "^faReset" ] +] + +selected_export_import_action = 0 +export_weapon_variables__all = 0 +export_weapon_variables__server = 0 +import_export_weapon_variables__filename = "" +chosenvar = "" +show_primary = 1 + +set_chosenvar = [ + chosenvar = $arg1 +] + +var_is_modified = [ + case (getvartype $arg1) $VAR_TYPE_INTEGER [ result ( != (getvardef $arg1) $$arg1 ) + ] $VAR_TYPE_FLOAT [ result ( != (getfvardef $arg1) $$arg1 ) + ] $VAR_TYPE_STRING [ result ( !=s (getsvardef $arg1) $$arg1 ) ] +] + +vardef = [ + var_name = [@[weap]@[arg1]] + + ui_button (format "^f%1%2" (? (var_is_modified $var_name) "o" "w") $arg2) (format "set_chosenvar %1" $arg1) "" "radiobox" 0xFFFFFF 0xFFFFFF -1 1 (? (=s $chosenvar $arg1) "radioboxon") $ui_color_radiobutton_box +] + +vardef2 = [ + if $show_primary [ vardef [@[arg1]1] $arg2 + ] [ vardef [@[arg1]2] $arg2 ] +] +varcategory = [ + ui_list [ + ui_strut 2 + ui_text (format "^fB%1" $arg1) + ] +] + +weapon_variables_one = [ + [ name "Name" ] + [ longname "Long Name" ] + [ colour "Colour" ] + [ ammomax "Ammo Max" ] + [ cookzoom "Cook Zoom" ] + [ cookzoommin "Cook Zoom Min" ] + [ cookzoommax "Cook Zoom Max" ] + [ disabled "Disabled" ] + [ delayreload "Delay Reload" ] + [ frequency "Frequency" ] + [ laser "Laser" ] + [ lightpersist "Light Persist" ] + [ lightradius "Light Radius" ] + [ modes "Modes" ] + [ muts "Mutators" ] +] + +weapon_variables_two = [ + [ "category" "Uncategorized" ] + [ desc "Description" ] + [ aidist "AI Dist" ] + [ aiskew "AI Skew" ] + [ ammosub "Ammo Sub" ] + [ blend "Blend" ] + [ collide "Collide" ] + [ extinguish "Extinguish" ] + [ delayattack "Delay Attack" ] + [ drill "Drill" ] + [ elasticity "Elasticity" ] + [ escapedelay "Escape Delay" ] + [ fullauto "Full Auto" ] + [ grab "Grab" ] + [ headmin "Head Min" ] + [ interacts "Interacts" ] + [ kickpush "Kick Push" ] + [ lightcol "Light Color" ] + [ liquidcoast "Liquid Coast" ] + [ obituary "Obituary" ] + [ obitsuicide "Obit Suicide" ] + [ radial "Radial" ] + [ radius "Radius" ] + [ rays "Rays / Bullets" ] + [ reflectivity "Reflectivity" ] + [ trace "Trace" ] + [ weight "Weight" ] + [ wavepush "Wave Push" ] + [ "category" "Cook" ] + [ cooked "Cooked" ] + [ cooktime "Cook Time" ] + [ "category" "Damage" ] + [ damage "Damage" ] + [ damagehead "Damage Head" ] + [ damagelegs "Damage Legs" ] + [ damageself "Damage Self" ] + [ damageteam "Damage Team" ] + [ damagetorso "Damage Torso" ] + [ damagepenalty "Damage Penalty" ] + [ damagewhiplash "Damage Whiplash" ] + [ "category" "Explode" ] + [ explcol "Explode Colour" ] + [ explode "Explode" ] + [ "category" "Fade" ] + [ fade "Fade" ] + [ fadeat "Fade At" ] + [ fadecut "Fade Cut" ] + [ fadetime "Fade Time" ] + [ "category" "Fragment" ] + [ fragjump "Fragment Jump" ] + [ fragoffset "Fragment Offset" ] + [ fragrays "Fragment Rays" ] + [ fragrel "Fragment Rel" ] + [ fragscale "Fragment Scale" ] + [ fragskew "Fragment Skew" ] + [ fragspeed "Fragment Speed" ] + [ fragspeedmin "Fragment Speed Min" ] + [ fragspeedmax "Fragment Speed Max" ] + [ fragspread "Fragment Spread" ] + [ fragtime "Fragment Time" ] + [ fragtimedelay "Fragment Time Delay" ] + [ fragtimeiter "Fragment Time Iter" ] + [ fragweap "Fragment Weapon" ] + [ "category" "Guided" ] + [ guided "Guided" ] + [ guideddelay "Guided Delay" ] + [ "category" "Hit" ] + [ hitpush "Hit Push" ] + [ hitvel "Hit Velocity" ] + [ "category" "Particle" ] + [ partblend "Particle Blend" ] + [ partcol "Particle Color" ] + [ partfade "Particle Fade" ] + [ partlen "Particle Length" ] + [ partsize "Particle Size" ] + [ parttype "Particle Type" ] + [ "category" "Proximity" ] + [ proxdelay "Proximity Delay" ] + [ proxdist "Proximity Distance" ] + [ proxtime "Proximity Time" ] + [ proxtype "Proximity Type" ] + [ "category" "Residual" ] + [ residual "Residual" ] + [ residualundo "Residual Undo" ] + [ "category" "Speed" ] + [ speed "Speed" ] + [ speeddelta "Speed Delta" ] + [ speedlimit "Speed Limit" ] + [ speedmin "Speed Min" ] + [ speedmax "Speed Max" ] + [ "category" "Spread" ] + [ spread "Spread" ] + [ spreadmax "Spread Max" ] + [ spreadmin "Spread Min" ] + [ spreadz "Spread Z" ] + [ "category" "Stun" ] + [ stun "Stun" ] + [ stunfall "Stun Fall" ] + [ stuntime "Stun Time" ] + [ "category" "Taper" ] + [ taper "Taper" ] + [ taperin "Taper In" ] + [ taperout "Taper Out" ] + [ tapermin "Taper Min" ] + [ tapermax "Taper Max" ] + [ "category" "Time" ] + [ time "Time" ] + [ timedelay "Time Delay" ] + [ timeiter "Time Iter" ] + [ timestick "Time Stick" ] + [ "category" "Vis" ] + [ visfade "Vis Fade" ] + [ vistime "Vis Time" ] + [ "category" "Flak" ] + [ flakblend "Flak Blend" ] + [ flakcollide "Flak Collide" ] + [ flakdrill "Flak Drill" ] + [ flakelasticity "Flak Elasticity" ] + [ flakextinguish "Flak Extinguish" ] + [ flakgrab "Flak Grab" ] + [ flakheadmin "Flak Head Min" ] + [ flakinteracts "Flak Interacts" ] + [ flaklightcol "Flak Light Color" ] + [ flakliquidcoast "Flak Liquid Coast" ] + [ flakobituary "Flak Obituary" ] + [ flakobitsuicide "Flak Obit Suicide" ] + [ flaktimestick "Flak Time Stick" ] + [ flakwavepush "Flak Wave Push" ] + [ flakweight "Flak Weight" ] + [ "category" "Flak Damage" ] + [ flakdamage "Flak Damage" ] + [ flakdamagehead "Flak Damage Head" ] + [ flakdamagelegs "Flak Damage Legs" ] + [ flakdamageself "Flak Damage Self" ] + [ flakdamageteam "Flak Damage Team" ] + [ flakdamagetorso "Flak Damage Torso" ] + [ flakdamagepenalty "Flak Damage Penalty" ] + [ flakdamagewhiplash "Flak Damage Whiplash" ] + [ "category" "Flak Explode" ] + [ flakexplcol "Flak Explode Colour" ] + [ flakexplode "Flak Explode" ] + [ "category" "Flak Fade" ] + [ flakfade "Flak Fade" ] + [ flakfadeat "Flak Fade At" ] + [ flakfadecut "Flak Fade Cut" ] + [ flakfadetime "Flak Fade Time" ] + [ "category" "Flak Guided" ] + [ flakguided "Flak Guided" ] + [ flakguideddelay "Flak Guided Delay" ] + [ "category" "Flak Hit" ] + [ flakhitpush "Flak Hit Push" ] + [ flakhitvel "Flak Hit Velocity" ] + [ "category" "Flak Particle" ] + [ flakpartblend "Flak Particle Blend" ] + [ flakpartcol "Flak Particle Color" ] + [ flakpartfade "Flak Particle Fade" ] + [ flakpartlen "Flak Particle Length" ] + [ flakpartsize "Flak Particle Size" ] + [ flakparttype "Flak Particle Type" ] + [ "category" "Flak Proximity" ] + [ flakproxdelay "Flak Proximity Delay" ] + [ flakproxdist "Flak Proximity Distance" ] + [ flakproxtime "Flak Proximity Time" ] + [ flakproxtype "Flak Proximity Type" ] + [ flakradial "Flak Radial" ] + [ flakradius "Flak Radius" ] + [ flakreflectivity "Flak Reflectivity" ] + [ "category" "Flak Residual" ] + [ flakresidual "Flak Residual" ] + [ flakresidualundo "Flak Residual Undo" ] + [ "category" "Flak Speed" ] + [ flakspeeddelta "Flak Speed Delta" ] + [ flakspeedmin "Flak Speed Min" ] + [ flakspeedmax "Flak Speed Max" ] + [ "category" "Flak Stun" ] + [ flakstun "Flak Stun" ] + [ flakstunfall "Flak Stun Fall" ] + [ flakstuntime "Flak Stun Time" ] + [ "category" "Flak Taper" ] + [ flaktaper "Flak Taper" ] + [ flaktaperin "Flak Taper In" ] + [ flaktaperout "Flak Taper Out" ] + [ flaktapermin "Flak Taper Min" ] + [ flaktapermax "Flak Taper Max" ] + [ "category" "Flak Vis" ] + [ flakvisfade "Flak Vis Fade" ] + [ flakvistime "Flak Vis Time" ] +] + +variables_one_idx = 0 +variables_two_idx = 0 + +variable_list_one = $weapon_variables_one +variable_list_two = $weapon_variables_two +variable_list_one_length = (listlen $variable_list_one) +variable_list_two_length = (listlen $variable_list_two) + +variable_search = "" +variable_search_on = 0 +variable_search_results_one = "" +variable_search_results_two = "" + +fill_variable_lists = [ + if ($variable_search_on) [ + // add all variables from weapon_variables_one that contain the search term to temp_variable_list_one + temp_variable_list_one = "" + looplist i $weapon_variables_one [ + var_display_name = (sublist $i 1 (- (listlen $i) 1)) + if (| (> (stringstr (at $i 0) $variable_search) -1) (> (stringstr $var_display_name $variable_search) -1)) [ + temp_variable_list_one = (concat $temp_variable_list_one (format "[%1 %2]" (at $i 0) $var_display_name)) + ] + ] + // make sure there are always at least 8 elements in the list so the view doesnt get smaller + loop i (- 8 (listlen $temp_variable_list_one)) [ + temp_variable_list_one = (concat $temp_variable_list_one "spacer") + ] + + variable_list_one = $temp_variable_list_one + + // add all variables from weapon_variables_two that contain the search term to temp_variable_list_two + temp_variable_list_two = "" + looplist j $weapon_variables_two [ + var_display_name = (sublist $j 1 (- (listlen $j) 1)) + if (| (> (stringstr (at $j 0) $variable_search) -1) (> (stringstr $var_display_name $variable_search) -1)) [ + temp_variable_list_two = (concat $temp_variable_list_two (format "[%1 %2]" (at $j 0) $var_display_name)) + ] + ] + // make sure there are always at least 16 elements in the list so the view doesnt get smaller + loop i (- 16 (listlen $temp_variable_list_two)) [ + temp_variable_list_two = (concat $temp_variable_list_two "spacer") + ] + variable_list_two = $temp_variable_list_two + ] [ + variable_list_one = $weapon_variables_one + variable_list_two = $weapon_variables_two + ] + calculate_variable_list_lengths + variables_one_idx = 0 + variables_two_idx = 0 +] + +calculate_variable_list_lengths = [ + variable_list_one_length = (listlen $variable_list_one) + variable_list_two_length = (listlen $variable_list_two) +] + +weapons = [ claw pistol sword shotgun smg flamer plasma zapper rifle grenade mine rocket melee ] + +weapindex = 0 + +weapindexdelta = [ + weapindex = (+ $weapindex $arg1) + if (< $weapindex 0) [ weapindex = (+ $weapindex $weapidxnum) ] + if (>= $weapindex $weapidxnum) [ weapindex = (- $weapindex $weapidxnum) ] +] + +weapmenu = [ + ui_stay_open [ + ui_list [ + ui_list2 [ + ui_strut 80 1 + weap = (at $weapons $weapindex) + ui_list [ + ui_image (getweap $weapindex 1) [weapindexdelta 1] 2 0 "textures/nothumb" "" $[@[weap]colour] + ui_strut 2 + ui_list [ + ui_font default [ ui_text [@weap (@[weapindex]/@($weapidxnum - $weapindex))] ] // FAULT: looks 0/12 and not 1/12 or 0/11 + ui_list [ + ui_button "^fo" [weapindexdelta 1] + ] +y + local _loop_weapon + ui_list [ + loop idx 7 [ + _loop_weapon = (at $weapons $idx) + ui_image (getweap $idx 1) (format "weapindex = %1" $idx) 0.4 0 "textures/nothumb" "" $[@[_loop_weapon]colour] (? (= $idx $weapindex) "textures/guiskinborder" "") + ] + + // make sure the import and export menu is aligned correctly + ui_strut 2 + ] + ui_list [ + local real_idx + loop idx 6 [ + real_idx = (+ $idx 7) + _loop_weapon = (at $weapons $real_idx) + ui_image (getweap $real_idx 1) (format "weapindex = %1" $real_idx) 0.4 0 "textures/nothumb" "" $[@[_loop_weapon]colour] (? (= $real_idx $weapindex) "textures/guiskinborder" "") + ] + ] + ] + + ui_bar + + ui_list [ + ui_strut 0.25 + ui_list [ + ui_radiobutton "^fgImport" selected_export_import_action 0; ui_strut 2 + ui_radiobutton "^fbExport" selected_export_import_action 1 + ] + + ui_strut 0.1 + ui_list [ + ui_text "Filename:"; ui_strut 0.5 + ui_textfield import_export_weapon_variables__filename 25; ui_strut 1 + + case $selected_export_import_action 0 [ // selected Import + ui_button "Ok" [ + if (!=s $import_export_weapon_variables__filename "") [ + if (exec (format "weapon_configs/%1" $import_export_weapon_variables__filename) 0 1) [ + import_export_weapon_variables__filename = "" + echo "^fgSuccessfull" + ] [ echo "^frUnsuccessfull" ] + ] [ echo "^frPlease enter a valid filename " $import_export_weapon_variables__filename ] + ] + ] 1 [ // selected Export + ui_checkbox "All" export_weapon_variables__all 1 0; ui_strut 1 + ui_checkbox "Server" export_weapon_variables__server 1 0; ui_strut 1 + + ui_button "Ok" [ + if (!=s $import_export_weapon_variables__filename "") [ + writeweapvars [@[weap]] (format "weapon_configs/%1" $import_export_weapon_variables__filename) $export_weapon_variables__all $export_weapon_variables__server + import_export_weapon_variables__filename = "" + ] [ + echo "^frPlease enter a valid filename" + ] + ] + ] + ] + ] + ] + ui_bar + ] + + ui_list [ + ui_list [ + ui_font "little" [ + + ui_list [ + ui_textfield variable_search 24 [ + if (stringlen $variable_search) [ variable_search_on = 1 ] [ variable_search_on = 0 ] + fill_variable_lists + ] -1 0 "" 0 "^fd Search" 1 + ui_strut 0.7 + if (= $variable_search_on 1) [//show the button for disable filter only if something is searched + ui_center [ + ui_button "Filter" [ variable_search = "" ; variable_search_on = 0; fill_variable_lists] [] "textures/guiexit" + ] + ] + ] + + ui_strut 0.2 + + ui_center [ ui_text "General" ] + + ui_border_box 1 0 0.25 0.25 [ ui_list [ + ui_list [ + ui_strut 30 1 + looplist i (sublist $variable_list_one $variables_one_idx 8) [ + if (=s (at $i 0) "spacer") [ ui_text " " + ] [ vardef (at $i 0) (at $i 1) ] + ] + ] + ui_slider variables_one_idx 0 (max 0 (- $variable_list_one_length 8)) [] 1 1 + ] ] + + ui_strut 0.5 + + ui_center [ ui_text "Action Specific" ] + + ui_center [ + ui_radiobutton "Primary" show_primary 1; ui_strut 1 + ui_radiobutton "Secondary" show_primary 0 + ] + + ui_border_box 1 0 0.25 0.25 [ ui_list [ + ui_list [ + ui_strut 30 1 + looplist j (sublist $variable_list_two $variables_two_idx 16) [ + if (=s (at $j 0) "category") [ varcategory (at $j 1) + ] [ if (=s (at $j 0) "spacer") [ ui_text " " + ] [ vardef2 (at $j 0) (at $j 1) ] ] + ] + ] + ui_slider variables_two_idx 0 (max 0 (- $variable_list_two_length 16)) [] 1 1 + ] ] + ] + ] + + ui_strut 3 + + ui_list [ + ui_strut 50 1 + + + ui_list [ + ui_list [ if (!=s $chosenvar "") [ + cur_variable_name = [@[weap]@[chosenvar]] + cur_variable_type = (getvartype $cur_variable_name) + cur_variable_flags = (getvarflags $cur_variable_name) + cur_variable_description = (getvardesc $cur_variable_name) + cur_variable_fields = (getvarfields $cur_variable_name) + + case $cur_variable_type $VAR_TYPE_INTEGER [ + cur_variable_value_min = (getvarmin $cur_variable_name) + cur_variable_value_max = (getvarmax $cur_variable_name) + cur_variable_value_def = (getvardef $cur_variable_name) + + ] $VAR_TYPE_FLOAT [ + cur_variable_value_min = (getfvarmin $cur_variable_name) + cur_variable_value_max = (getfvarmax $cur_variable_name) + cur_variable_value_def = (getfvardef $cur_variable_name) + + ] $VAR_TYPE_STRING [ + cur_variable_value_def = (getsvardef $cur_variable_name) + + ] () [ // everything else + cur_variable_value_def = (getvardef $cur_variable_name) + ] + + ui_strut 1 + + ui_list [ + ui_list [ + ui_strut 8 + ] + + ui_list [ + case $cur_variable_type $VAR_TYPE_INTEGER [ + + if (& (= $cur_variable_value_min 0) (= $cur_variable_value_max 1)) [ + ui_text "^faVariable Type: ^fwBoolean" + ui_text (format "^faVariable Name: ^fw%1" $cur_variable_name) + ui_strut 0.5 + + ui_checkbox "Toggle" $cur_variable_name 1 0 + ] [ + if (& 256 $cur_variable_flags) [ + ui_text "^faVariable Type: ^fwHex Color" + ui_text (format "^faVariable Name: ^fw%1" $cur_variable_name) + ui_strut 0.5 + + ui_list [ ui_body [ ui_list [ + ui_hex_preview $$cur_variable_name (hexcolour $$cur_variable_name) + ] ] [ pick_color $cur_variable_name ] ] + variable_reset_button + ] [ + ui_text "^faVariable Type: ^fwInteger" + ui_text (format "^faVariable Name: ^fw%1" $cur_variable_name) + ui_strut 0.5 + + ui_list [ + ui_text (format "^fbMin: ^fw%1" $cur_variable_value_min); ui_strut 1 + ui_text (format "^frMax: ^fw%1" $cur_variable_value_max) + ] + ui_text (format "^fgDefault: ^fw%1" $cur_variable_value_def) + ui_strut 1 + + ui_list [ + ui_textfield $cur_variable_name; ui_strut 1 + variable_reset_button + ] + ] + ] + ] $VAR_TYPE_FLOAT [ + + ui_text "^faVariable Type: ^fwFloat" + ui_text (format "^faVariable Name: ^fw%1" $cur_variable_name) + ui_strut 0.5 + + ui_list [ + ui_text (format "^fbMin: ^fw%1" $cur_variable_value_min); ui_strut 1 + ui_text (format "^frMax: ^fw%1" $cur_variable_value_max) + ] + ui_text (format "^fgDefault: ^fw%1" $cur_variable_value_def) + ui_strut 1 + + ui_list [ + ui_textfield $cur_variable_name; ui_strut 1 + variable_reset_button + ] + + ] $VAR_TYPE_STRING [ + + ui_text "^faVariable Type: ^fwString" + ui_text (format "^faVariable Name: ^fw%1" $cur_variable_name) + ui_strut 0.5 + + ui_text (format "^fgDefault: ^fw%1" $cur_variable_value_def) "" -1 -1 1000 + ui_strut 1 + + ui_textfield $cur_variable_name 45 + ui_strut 1 + + variable_reset_button + + ] () [ + ui_text "^faVariable Type: ^fw???" + ] + ] + ] + + ui_strut 0 1 + + ui_font "emphasis" [ ui_text "Info:" ] + ui_text $cur_variable_description "" -1 -1 1200 + + scurfmax = (- (<< 1 $cur_variable_fields) 1) + if (& (= $cur_variable_type $VAR_TYPE_INTEGER) (> $cur_variable_fields 1)) [ + if (!= $scurfmax $cur_variable_value_max) [ + ui_text (format "^fyUsage description of %1 implies a max value of %2, but it should be %3." $cur_variable_name $scurfmax $cur_variable_value_max) + ] + ui_list [ + ui_strut 5 + ui_list [ + loop i $cur_variable_fields [ + ui_font "little" [ ui_bitfield (getvarfields $cur_variable_name $i) $cur_variable_name (<< 1 $i) ] + ] + ] + ] + ] + ] ] + ] + ] + ] + + ] + ] +] + diff --git a/config/setup.cfg b/config/setup.cfg old mode 100644 new mode 100755 index dda30aa85..cae5bfd56 --- a/config/setup.cfg +++ b/config/setup.cfg @@ -173,7 +173,7 @@ bind F3 [ showgui maps 1 ] bind F4 [ showgui maps 2 ] bind F5 [ showservers ] bind F6 [ showgui profile 2 ] -bind F7 [ showgui team ] +bind F7 [ showgui advanced_options ] bind F8 [ showgui clients ] bind F9 [ thirdpersonswitch ] bind F10 [ toggleconsole ] diff --git a/config/usage.cfg b/config/usage.cfg old mode 100644 new mode 100755 index e0478a916..460a397f2 --- a/config/usage.cfg +++ b/config/usage.cfg @@ -731,6 +731,7 @@ setdesc "goto" "jumps the spectator camera to the position of the specified clie setdesc "hexcolour" "converts a decimal color value to a ^"pretty-printed^" hexadecimal color value;^nexample: (hexcolour 342344) will give 0x093548" "color" setdesc "precf" "returns the value float truncated to accuracy number of decimals;^nexample: (precf 0.14986 2) will give 0.14" "float accuracy" setdesc "writevars" "writes the current server's variables to a config file named file;^nif [all] is true, every variable will be written with default values commented out; if false, only changed variables will be written (default: false)^nif [sv_] is true, variables will be prefixed with ^"sv_^" (default: false)" "file [all] [sv_]" +setdesc "writeweapvars" "writes the current server's variables for a specific weapon to a config file named file;^nif [all] is true, every variable will be written with default values commented out; if false, only changed variables will be written (default: false)^nif [sv_] is true, variables will be prefixed with ^"sv_^" (default: false)" "[weapon name] file [all] [sv_]" setdesc "case" "executes the first body where the corresponding test_value is equivalent to integer using integer comparison;^nfor the 'default' case (always true), use () for the test_value, has a limit of 12 conditions,^nexample: case (rnd 3) 0 [ echo 0 ] 1 [ echo 1 ] () [ echo default ]" "integer [test_value body] [test_value body] [...]" setdesc "casef" "executes the first body where the corresponding test_value is equivalent to float using float comparison;^nfor the 'default' case (always true) use () for the test_value, has a limit of 12 conditions,^nexample: case (+f (rnd 3) .1) 0.1 [ echo 0.1 ] 1.1 [ echo 1.1 ] () [ echo default ]" "float [test_value body] [test_value body] [...]" setdesc "cases" "executes the first body where the corresponding test_value is equivalent to string using string comparison;^nfor the 'default' case (always true) use () for the test_value, has a limit of 12 conditions,^nexample: case (substring ^"abc^" (rnd 3) 1) a [ echo a ] b [ echo b ] () [ echo default ]" "string [test_value body] [test_value body] [...]" diff --git a/src/engine/command.cpp b/src/engine/command.cpp index a28e6f813..80026cb08 100644 --- a/src/engine/command.cpp +++ b/src/engine/command.cpp @@ -2478,7 +2478,7 @@ const char *intstr(int v) return retbuf[retidx]; } -const char *intstr(ident *id) +const char *intstr(const ident *id) { retidx = (retidx + 1)%4; formatstring(retbuf[retidx], id->flags&IDF_HEX && *id->storage.i >= 0 ? (id->maxval==0xFFFFFF ? "0x%.6X" : "0x%X") : "%d", *id->storage.i); diff --git a/src/game/client.cpp b/src/game/client.cpp old mode 100644 new mode 100755 index 95f82a5a0..c052b5e46 --- a/src/game/client.cpp +++ b/src/game/client.cpp @@ -1,5 +1,7 @@ #include using std::swap; +#include +#include #include "game.h" namespace client @@ -245,51 +247,84 @@ namespace client }); ICOMMAND(0, hasauthkey, "i", (int *n), intret(accountname[0] && accountpass[0] && (!*n || authconnect) ? 1 : 0)); - void writegamevars(const char *name, bool all = false, bool server = false) + void writegamevars(const char *name, bool all = false, bool server = false, const char* weapon_name = "") { - if(!name || !*name) name = "vars.cfg"; - stream *f = openfile(name, "w"); - if(!f) return; - vector ids; - enumerate(idents, ident, id, ids.add(&id)); - ids.sortname(); - loopv(ids) - { - ident &id = *ids[i]; - if(id.flags&IDF_CLIENT && !(id.flags&IDF_READONLY) && !(id.flags&IDF_WORLD)) switch(id.type) + if (!name || !*name) name = "vars.cfg"; + + stream* f = openfile(name, "w"); + // if we fail to open a file stream, stop and print error message + if (!f) { + conoutft(CON_EVENT, "\frFailed to open filestream for file: \fb%s \fr. Variables have not been saved.", name); + return; + } + + bool export_weapon = !std::string(weapon_name).empty(); + std::vector ids; + enumerate(idents, ident, id, ids.push_back(&id)); + + // sort the identifiers so the output file will be alphabetically sorted + std::sort(ids.begin(), ids.end(), [](const ident* a, const ident* b) { + return strcmp(a->name, b->name) < 0; + }); + + for (const ident* id : ids) + { + // do not save the variable if: + // it's not a client sided variable + // it's readonly + // it's a world variable + // or if we export a weapon and it the variablename doesn't start with the weapon name + if ( !(id->flags & IDF_CLIENT) + || (id->flags & IDF_READONLY) + || (id->flags & IDF_WORLD) + || ((export_weapon == true) ? (strncmp(id->name, weapon_name, strlen(weapon_name)) != 0) : false)) + { + continue; + } + + bool value_changed = false; + std::string write_value = ""; + + switch (id->type) { case ID_VAR: - if(*id.storage.i == id.def.i) - { - if(all) f->printf("// "); - else break; - } - if(server) f->printf("sv_"); - f->printf("%s %s\n", escapeid(id), intstr(&id)); + value_changed = *id->storage.i != id->def.i; + write_value = intstr(id); break; case ID_FVAR: - if(*id.storage.f == id.def.f) - { - if(all) f->printf("// "); - else break; - } - if(server) f->printf("sv_"); - f->printf("%s %s\n", escapeid(id), floatstr(*id.storage.f)); + value_changed = *id->storage.f != id->def.f; + write_value = floatstr(*id->storage.f); break; case ID_SVAR: - if(!strcmp(*id.storage.s, id.def.s)) - { - if(all) f->printf("// "); - else break; - } - if(server) f->printf("sv_"); - f->printf("%s %s\n", escapeid(id), escapestring(*id.storage.s)); + value_changed = strcmp(*id->storage.s, id->def.s) != 0; + write_value = escapestring(*id->storage.s); break; } + + // if the value didn't change, but we write all variables, comment the line out + if (!value_changed && all) { + f->printf("// "); + } else if (!value_changed && !all) { + // we shouldn't write it to the file + continue; + } + + // prefix the variable with "sv_", so the file can be used as config for servers + if (server) { + f->printf("sv_"); + } + + f->printf("%s %s\n", escapeid(*id), write_value.c_str()); } delete f; + + if (export_weapon) { + conoutft(CON_EVENT, "\fgSuccessfully exported \fb%s \fgconfig into file \fy%s", weapon_name, name); + } } ICOMMAND(0, writevars, "sii", (char *name, int *all, int *sv), if(!(identflags&IDF_WORLD)) writegamevars(name, *all!=0, *sv!=0)); + ICOMMAND(0, writeweapvars, "ssii", (char* weapon_name, char* name, int* all, int* sv), if (!(identflags & IDF_WORLD)) writegamevars(name, *all != 0, *sv != 0, weapon_name)); + void writegamevarsinfo(const char *name) { @@ -3399,7 +3434,7 @@ namespace client void getservers(int server, int prop, int idx) { - if(server < 0) + if(server < 0) { if (hideincompatibleservers) { diff --git a/src/shared/command.h b/src/shared/command.h index 4636c55c9..b1f4f90f3 100644 --- a/src/shared/command.h +++ b/src/shared/command.h @@ -206,7 +206,7 @@ extern void addident(ident *id); extern tagval *commandret; extern const char *intstr(int v); -extern const char *intstr(ident *id); +extern const char *intstr(const ident *id); extern void intret(int v); extern const char *floatstr(float v); extern void floatret(float v); @@ -345,7 +345,7 @@ extern bool interactive; extern const char *escapestring(const char *s); extern const char *escapeid(const char *s); -static inline const char *escapeid(ident &id) { return escapeid(id.name); } +static inline const char *escapeid(const ident &id) { return escapeid(id.name); } extern bool validateblock(const char *s); extern char *parsetext(const char *&p); extern void explodelist(const char *s, vector &elems, int limit = -1);