Permalink
Browse files

Feature: Group liveries, and livery window usability enhancements. (#…

…7108)

* Change: Replace checkbox in livery selection window with Default option in drop down selection.

This reduces clutter in the UI and allows for primary/secondary colours to independently follow the default scheme if desired.

* Feature: Add vehicle group liveries.
  • Loading branch information...
PeterN authored and planetmaker committed Jan 31, 2019
1 parent ba38a7c commit 23960d0f2c82a634e0ca1be720c229ac22f14962
BIN +987 Bytes (100%) bin/baseset/openttd.grf
Binary file not shown.
@@ -14,6 +14,8 @@
// allowing it to be used.
//

//@@WARNING DISABLE 60

//
// Number of sprites, it is wrong, but GRFcodec automagically gets it right.
//
@@ -7,7 +7,7 @@
// See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
//
-1 * 0 0C "OpenTTD GUI graphics"
-1 * 3 05 15 \b 175 // OPENTTD_SPRITE_COUNT
-1 * 3 05 15 \b 179 // OPENTTD_SPRITE_COUNT
-1 sprites/openttdgui.png 8bpp 66 8 64 31 -31 7 normal
-1 sprites/openttdgui.png 8bpp 146 8 64 31 -31 7 normal
-1 sprites/openttdgui.png 8bpp 226 8 64 31 -31 7 normal
@@ -183,3 +183,7 @@
-1 sprites/openttdgui.png 8bpp 440 440 20 20 0 0 normal
-1 sprites/openttdgui.png 8bpp 466 440 20 20 0 0 normal
-1 sprites/openttdgui.png 8bpp 490 440 20 20 0 0 normal
-1 sprites/openttdgui_group_livery.png 8bpp 0 0 20 20 0 0 normal
-1 sprites/openttdgui_group_livery.png 8bpp 21 0 20 20 0 0 normal
-1 sprites/openttdgui_group_livery.png 8bpp 42 0 20 20 0 0 normal
-1 sprites/openttdgui_group_livery.png 8bpp 63 0 20 20 0 0 normal
Binary file not shown.
@@ -190,6 +190,7 @@ CommandProc CmdAddVehicleGroup;
CommandProc CmdAddSharedVehicleGroup;
CommandProc CmdRemoveAllVehiclesGroup;
CommandProc CmdSetGroupReplaceProtection;
CommandProc CmdSetGroupLivery;

CommandProc CmdMoveOrder;
CommandProc CmdChangeTimetable;
@@ -349,6 +350,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdAddSharedVehicleGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ADD_SHARE_VEHICLE_GROUP
DEF_CMD(CmdRemoveAllVehiclesGroup, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_REMOVE_ALL_VEHICLES_GROUP
DEF_CMD(CmdSetGroupReplaceProtection, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_REPLACE_PROTECTION
DEF_CMD(CmdSetGroupLivery, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_GROUP_LIVERY
DEF_CMD(CmdMoveOrder, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_MOVE_ORDER
DEF_CMD(CmdChangeTimetable, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_CHANGE_TIMETABLE
DEF_CMD(CmdSetVehicleOnTime, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_SET_VEHICLE_ON_TIME
@@ -322,6 +322,7 @@ enum Commands {
CMD_ADD_SHARED_VEHICLE_GROUP, ///< add all other shared vehicles to a group which are missing
CMD_REMOVE_ALL_VEHICLES_GROUP, ///< remove all vehicles from a group
CMD_SET_GROUP_REPLACE_PROTECTION, ///< set the autoreplace-protection for a group
CMD_SET_GROUP_LIVERY, ///< set the livery for a group

CMD_MOVE_ORDER, ///< move an order
CMD_CHANGE_TIMETABLE, ///< change the timetable for a vehicle
@@ -517,10 +517,19 @@ restart:;
void ResetCompanyLivery(Company *c)
{
for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) {
c->livery[scheme].in_use = false;
c->livery[scheme].in_use = 0;
c->livery[scheme].colour1 = c->colour;
c->livery[scheme].colour2 = c->colour;
}

Group *g;
FOR_ALL_GROUPS(g) {
if (g->owner == c->index) {
g->livery.in_use = 0;
g->livery.colour1 = c->colour;
g->livery.colour2 = c->colour;
}
}
}

/**
@@ -946,76 +955,75 @@ CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32
* @param flags operation to perform
* @param p1 bitstuffed:
* p1 bits 0-7 scheme to set
* p1 bits 8-9 set in use state or first/second colour
* p1 bit 8 set first/second colour
* @param p2 new colour for vehicles, property, etc.
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Colours colour = Extract<Colours, 0, 4>(p2);
Colours colour = Extract<Colours, 0, 8>(p2);
LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
byte state = GB(p1, 8, 2);
bool second = HasBit(p1, 8);

if (scheme >= LS_END || state >= 3 || colour == INVALID_COLOUR) return CMD_ERROR;
if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR;

/* Default scheme can't be reset to invalid. */
if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;

Company *c = Company::Get(_current_company);

/* Ensure no two companies have the same primary colour */
if (scheme == LS_DEFAULT && state == 0) {
if (scheme == LS_DEFAULT && !second) {
const Company *cc;
FOR_ALL_COMPANIES(cc) {
if (cc != c && cc->colour == colour) return CMD_ERROR;
}
}

if (flags & DC_EXEC) {
switch (state) {
case 0:
c->livery[scheme].colour1 = colour;

/* If setting the first colour of the default scheme, adjust the
* original and cached company colours too. */
if (scheme == LS_DEFAULT) {
_company_colours[_current_company] = colour;
c->colour = colour;
CompanyAdminUpdate(c);
if (!second) {
if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 0, 1, colour != INVALID_COLOUR);
if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour1;
c->livery[scheme].colour1 = colour;

/* If setting the first colour of the default scheme, adjust the
* original and cached company colours too. */
if (scheme == LS_DEFAULT) {
for (int i = 1; i < LS_END; i++) {
if (!HasBit(c->livery[i].in_use, 0)) c->livery[i].colour1 = colour;
}
break;

case 1:
c->livery[scheme].colour2 = colour;
break;

case 2:
c->livery[scheme].in_use = colour != 0;

/* Now handle setting the default scheme's in_use flag.
* This is different to the other schemes, as it signifies if any
* scheme is active at all. If this flag is not set, then no
* processing of vehicle types occurs at all, and only the default
* colours will be used. */
_company_colours[_current_company] = colour;
c->colour = colour;
CompanyAdminUpdate(c);
}
} else {
if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 1, 1, colour != INVALID_COLOUR);
if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour2;
c->livery[scheme].colour2 = colour;

/* If enabling a scheme, set the default scheme to be in use too */
if (colour != 0) {
c->livery[LS_DEFAULT].in_use = true;
break;
if (scheme == LS_DEFAULT) {
for (int i = 1; i < LS_END; i++) {
if (!HasBit(c->livery[i].in_use, 1)) c->livery[i].colour2 = colour;
}
}
}

/* Else loop through all schemes to see if any are left enabled.
* If not, disable the default scheme too. */
c->livery[LS_DEFAULT].in_use = false;
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
if (c->livery[scheme].in_use) {
c->livery[LS_DEFAULT].in_use = true;
break;
}
if (c->livery[scheme].in_use != 0) {
/* If enabling a scheme, set the default scheme to be in use too */
c->livery[LS_DEFAULT].in_use = 1;
} else {
/* Else loop through all schemes to see if any are left enabled.
* If not, disable the default scheme too. */
c->livery[LS_DEFAULT].in_use = 0;
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
if (c->livery[scheme].in_use != 0) {
c->livery[LS_DEFAULT].in_use = 1;
break;
}
break;

default:
break;
}
}

ResetVehicleColourMap();
MarkWholeScreenDirty();

Oops, something went wrong.

0 comments on commit 23960d0

Please sign in to comment.