← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/bug-1797702-spaces-in-names-clean-start into lp:widelands

 

There is some code duplication that I'd like to see solved.

Diff comments:

> 
> === modified file 'src/ui_fsmenu/netsetup_lan.cc'
> --- src/ui_fsmenu/netsetup_lan.cc	2019-05-11 18:50:30 +0000
> +++ src/ui_fsmenu/netsetup_lan.cc	2019-05-11 23:08:03 +0000
> @@ -247,6 +248,24 @@
>  }
>  
>  void FullscreenMenuNetSetupLAN::change_playername() {
> +	playername.set_warning(false);
> +	playername.set_tooltip("");
> +	hostgame.set_enabled(true);
> +
> +	if (playername.text().find_first_not_of("abcdefghijklmnopqrstuvwxyz"
> +		"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@.+-_") <= playername.text().size()

We have this comparison 3 times in the code, so we decide 3 times what a player name should look like. This is not robust to changes - best pull out a common function.

> +		|| playername.text().empty()) {
> +			playername.set_warning(true);
> +			playername.set_tooltip(_("Enter a valid nickname. This value may contain only "
> +													  "English letters, numbers, and @ . + - _ characters."));
> +			joingame.set_enabled(false);
> +			hostgame.set_enabled(false);
> +			return;
> +	}
> +	if (!hostname.text().empty()) {
> +		joingame.set_enabled(true);
> +	}
> +
>  	g_options.pull_section("global").set_string("nickname", playername.text());
>  }
>  


-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1797702-spaces-in-names-clean-start/+merge/367314
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1827786-metaserver-login-box-clean-start.


References