Wargus / stratagus

The Stratagus strategy game engine
GNU General Public License v2.0
626 stars 119 forks source link

CPlayerColorGraphic shows wrong color when other players' units are selected #101

Closed timfel closed 8 years ago

timfel commented 8 years ago

CPlayerColorGraphic is showing the current player's color instead of the unit's owner color, so that when enemy units are selected, their icon shows up in the current player's color instead of that of their owner.


Imported from Launchpad using lp2gh.

timfel commented 8 years ago

(by dinky-dye-aussie) What version of Stratagus are you using? Also, what platform are you playing it on? WIndows?

timfel commented 8 years ago

(by andre-ng) Yes, I'm playing on windows (with the binaries you provided on the forum, so commit 8874).

timfel commented 8 years ago

(by dinky-dye-aussie) OK :) Well, I just tried to test your problem out, and when I selected my peasents (red) and then any other player, it never changed color on the other players peasents or even buildings.

could be a scripts issue maybe.

timfel commented 8 years ago

(by andre-ng) I don't think it is a script issue. Looking at the source code, we can see that the DrawIcon() function (icons.cpp) sets the correct player for the player color:

void CIcon::DrawIcon(const CPlayer &player, const PixelPos &pos) const { CPlayerColorGraphic g = dynamic_cast<CPlayerColorGraphic >(this->G); if (g) { g->DrawPlayerColorFrameClip(player.Index, this->Frame, pos.x, pos.y); } else { this->G->DrawFrameClip(this->Frame, pos.x, pos.y); } }

However, this is not the function used to create the unit's main icon. That function is DrawUIButton() (uibuttons_proc.cpp). The function is too long to quote here, but here is the relevant part:

if (pimage->Sprite) {
    CPlayerColorGraphic *colorGraphic = dynamic_cast<CPlayerColorGraphic *>(pimage->Sprite);

    if (colorGraphic && ThisPlayer) {
        colorGraphic->DrawPlayerColorFrameClip(ThisPlayer->Index, pimage->Frame, x, y);
    } else {
        pimage->Sprite->DrawFrame(pimage->Frame, x, y);
    }
}

As we can see, the function uses "ThisPlayer" instead of the unit's owner to create the icon, which results in the person player's player color being used.

timfel commented 8 years ago

(by iddqd-mail) Fixed in rev.8883