Opened 12 years ago

Last modified 8 years ago

#1580 closed enhancement

[PATCH] Change player color in the gamesetup — at Version 16

Reported by: O.Davoodi Owned by: Stan
Priority: Nice to Have Milestone: Alpha 19
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description (last modified by elexis)

Change History (26)

comment:1 by Kieran P, 11 years ago

Milestone: Alpha 12Backlog

comment:2 by historic_bruno, 11 years ago

Owner: O.Davoodi removed

comment:3 by Adrián Chaves, 11 years ago

Owner: set to Adrián Chaves

by Adrián Chaves, 11 years ago

Attachment: customColorSupport.patch added

Patch based on the work started by Spahbod.

comment:4 by Adrián Chaves, 11 years ago

Keywords: review patch added
Milestone: BacklogAlpha 15

Based on the previous work that Spahbod posted in the forums, I’m attaching a patch which in addition does the following:

  • Keeps color display names in a string of their own, in preparation for the internationalization feature (#67).
  • Sorts colors in the drop-down list by color.

Although I was planning on doing so, I refrained from including ancient-themed colors. I think that needs more discussion (even if we all agree on doing it, we still need to agree on the RGB and display name of the values to be added), and I’ll try to bump the forum thread about it.

Adding new colors is as easy as editing the relevand JavaScript object in code. In the future, we could even move such data into a separated .json file if needed.

Note also that the implementation is prepared to deal with a color defined in simulation/data/player_defaults.json not being available in the JavaScript object that defined colors and color names in the GUI code. This is to keep simulation and gui code separated, as they should not depend in one another. When this occurs (a color is unknown in the GUI), the drop-down list shows empty, and lets you either keep the current, unknown color, or change to another color; if you change, you can not select back any unknown color. (you’ll probably need to actually read the code to understand this, just look for “-1” in the patch)

comment:5 by Adrián Chaves, 11 years ago

Summary: Adding the ability to change player colour in game setup[PATCH] Adding the ability to change player colour in game setup

comment:6 by Adrián Chaves, 11 years ago

Owner: Adrián Chaves removed

comment:7 by leper, 10 years ago

Milestone: Alpha 15Alpha 16

comment:8 by sanderd17, 10 years ago

Keywords: color gamesetup review removed

Can you make this patch work for skirmish maps too?

And the patch causes some problems when using a low resolution. The colour picker should be made smaller. Maybe only showing coloured squares instead of colour names?

comment:9 by sanderd17, 10 years ago

Milestone: Alpha 16Alpha 17

comment:10 by leper, 10 years ago

Milestone: Alpha 17Backlog

comment:11 by Stan, 9 years ago

Owner: set to Stan

by Stan, 9 years ago

Attachment: 1580.diff added

WIP patch, it's currently broken for some reason, help is appreciated. I can't get the drop down to appear

comment:12 by Stan, 9 years ago

Note that the json file will be removed, I added it in the patch, cause I forgot to delete it. It actually use default_players to get the colors.

comment:13 by elexis, 9 years ago

  • Please create the patch relatively to the trunk directory, so that we can apply the patch from there

settings.js

  • PlayerColors instead of Player_Colors
  • the code was updated

gamesetup.js

  • ++o instead of o++. I'd prefer n or i over o. But even better would be to remove that loop and just use array.find(...).length if possible.
  • getIndexOfColor don't need to do var playerColorsSorted = getPlayerColorsSorted(); every cycle, only once. replace the for loop by a call to findIndex
  • rgbToHsl - exact same function as in lobby.js. we should annoy the devs with a ticket that moves rgbToHsland hslToRgb to a new file common/color.js (the other color functions from lobby.js are almost all baloney, for example the rainbow colored pony-nicknames, and must be deleted in #3383 or so instead of being moved)

getPlayerColorsSorted()

  • early return
  • [] instead of new Array()
  • replacing for with map might be possible
  • if the block has only one line, the brackets can be removed (unless neede for aesthetics)
  • let instead of var in nested blocks so that theoretically a bit of performance can be saved
  • outerloop: try to avoid jumping to labels, I bet we can use a map or something similar for the inner loop and omit the problem that way

copyRgbValuesFromColorIntoColor

  • whitespace

gamesetup.xml

  • a tab missing
  • the position/size you gave the color picker is almost identical to the position of the player assignment dropdown. That might be why the former is invisible (but shows the tooltip when hovering) and why the latter seems disabled. The values are "left top right bottom". The "right" value of the left element must be smaller than the "left" value of the right element, etc. Where do you want to palce the color picker? Left of the playername? The xml should be moved to the correct location too.

Some rtfm's: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf and the other array functions linked there https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions http://trac.wildfiregames.com/wiki/Coding_Conventions

by Stan, 9 years ago

Attachment: 1580.2.diff added

WIP2

by Stan, 9 years ago

Attachment: 1580.3.diff added

Working Color Dropdown

by Stan, 9 years ago

Attachment: 1580.4.diff added

by Stan, 9 years ago

Attachment: 1580.5.diff added

by Stan, 9 years ago

Attachment: 1580.6.diff added

Some Cleanup

by elexis, 9 years ago

Attachment: 1580.7.diff added

comment:14 by elexis, 9 years ago

Milestone: BacklogAlpha 19
  • hardcore cleanup
  • gaia color not selectable anymore
  • colors are actually used ingame after selecting them

TODO:

  • only host can chose colors
  • dropdown element should list only colors that are not picked yet
  • discovered a dropdown list GUI bug. looks like the width of the scrollbar is subtracted even if the scrollbar doesn't exist. Might also have something to do with the xml / width.

by Stan, 9 years ago

Attachment: 1580.8.diff added

comment:15 by Stan, 9 years ago

Keywords: review added
  • As agreed on IRC, it's better for now that only the host can change colors, so that there is no fight about it.
  • There is no need for not showing colors, since we swap between them when they are being used.
  • Only the gui bug remains on certain resolutions. see #3415
Last edited 9 years ago by Stan (previous) (diff)

comment:16 by elexis, 9 years ago

Description: modified (diff)
Summary: [PATCH] Adding the ability to change player colour in game setup[PATCH] Change player color in the gamesetup

by elexis, 9 years ago

Attachment: l10n_longestStrings.7z added

Mock language that contains the longest strings found in the translations of r17026.

Note: See TracTickets for help on using tickets.