[+] Added CPreference::GrayscaleIcons, to enable and disable support for grayscale icons\n[-] Fixed bug with incorrect unit icons display

This commit is contained in:
cybermind 2014-05-26 15:56:59 +06:00
parent 57391a45cf
commit 00972d1aa2
14 changed files with 64 additions and 47 deletions

View file

@ -573,7 +573,7 @@ static void DrawUnitIcons()
}
CIcon &icon = *Editor.ShownUnitTypes[i]->Icon.Icon;
const PixelPos pos(x, y);
icon.DrawIcon(Players[Editor.SelectedPlayer], pos);
icon.DrawIcon(pos, Players[Editor.SelectedPlayer].Index);
Video.DrawRectangleClip(ColorGray, x, y, icon.G->Width, icon.G->Height);
if (i == Editor.SelectedUnitIndex) {
@ -753,7 +753,7 @@ static void DrawEditorPanel_StartIcon()
int flag = (ButtonUnderCursor == StartButton ? IconActive : 0)
| (Editor.State == EditorSetStartLocation ? IconSelected : 0);
icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "");
icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "", Editor.SelectedPlayer);
} else {
// No unit specified : draw a cross.
// Todo : FIXME Should we just warn user to define Start unit ?

View file

@ -99,6 +99,7 @@
----------------------------------------------------------------------------*/
class CGraphic;
class CPlayerColorGraphic;
class CPlayer;
class ButtonStyle;
@ -115,20 +116,20 @@ public:
void Load();
/// Draw icon
void DrawIcon(const CPlayer &player, const PixelPos &pos) const;
virtual void DrawIcon(const PixelPos &pos, const int player = -1) const;
/// Draw grayscale icon
void DrawGrayscaleIcon(const PixelPos &pos) const;
void DrawGrayscaleIcon(const PixelPos &pos, const int player = -1) const;
/// Draw cooldown spell
void DrawCooldownSpellIcon(const PixelPos &pos, const int percent) const;
/// Draw icon of a unit
void DrawUnitIcon(const ButtonStyle &style,
unsigned flags, const PixelPos &pos, const std::string &text) const;
unsigned flags, const PixelPos &pos, const std::string &text, const int player = -1) const;
const std::string &GetIdent() const { return this->Ident; }
public:
CGraphic *G; /// Graphic data
CGraphic *GScale; /// Icon when drawn grayscaled
CPlayerColorGraphic *G; /// Graphic data
CPlayerColorGraphic *GScale; /// Icon when drawn grayscaled
int Frame; /// Frame number in graphic
private:
std::string Ident; /// Icon identifier

View file

@ -99,7 +99,7 @@ public:
ButtonCheckFunc Allowed; /// Check if this button is allowed
std::string AllowStr; /// argument for allowed
std::string UnitMask; /// for which units is it available
IconConfig Icon; /// icon to display
IconConfig Icon; /// icon to display
int Key; /// alternative on keyboard
std::string Hint; /// tip texts
std::string Description; /// description shown on status bar (optional)

View file

@ -47,7 +47,7 @@ class ButtonStyle;
/// Draw menu button
extern void DrawUIButton(ButtonStyle *style, unsigned flags,
int x, int y, const std::string &text);
int x, int y, const std::string &text, int player = -1);
/// Pre menu setup
extern void PreMenuSetup();

View file

@ -426,9 +426,9 @@ class CPreference
{
public:
CPreference() : ShowSightRange(false), ShowReactionRange(false),
ShowAttackRange(false), ShowMessages(true),
BigScreen(false), PauseOnLeave(true), AiExplores(true), ShowOrders(0), ShowNameDelay(0),
ShowNameTime(0) {};
ShowAttackRange(false), ShowMessages(true), BigScreen(false),
PauseOnLeave(true), AiExplores(true), GrayscaleIcons(false),
ShowOrders(0), ShowNameDelay(0), ShowNameTime(0) {};
bool ShowSightRange; /// Show sight range.
bool ShowReactionRange; /// Show reaction range.
@ -436,7 +436,8 @@ public:
bool ShowMessages; /// Show messages.
bool BigScreen; /// If true, shows the big screen(without panels)
bool PauseOnLeave; /// If true, game pauses when cursor is gone
bool AiExplores; /// If true, AI sends explorers to serch for resources(almost useless thing)
bool AiExplores; /// If true, AI sends explorers to search for resources (almost useless thing)
bool GrayscaleIcons; /// Use grayscaled icons for unavailable units, upgrades, etc
int ShowOrders; /// How many second show orders of unit on map.
int ShowNameDelay; /// How many cycles need to wait until unit's name popup will appear.

View file

@ -108,8 +108,6 @@ public:
static CGraphic *New(const std::string &file, int w = 0, int h = 0);
static CGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
CGraphic *Clone(bool grayscale = false) const;
static void Free(CGraphic *g);
void Load(bool grayscale = false);
@ -168,6 +166,8 @@ public:
static CPlayerColorGraphic *New(const std::string &file, int w = 0, int h = 0);
static CPlayerColorGraphic *ForceNew(const std::string &file, int w = 0, int h = 0);
CPlayerColorGraphic *Clone(bool grayscale = false) const;
#if defined(USE_OPENGL) || defined(USE_GLES)
GLuint *PlayerColorTextures[PlayerMax];/// Textures with player colors
#endif

View file

@ -195,7 +195,7 @@ class CIcon
static CIcon *Get(const std::string ident);
tolua_readonly tolua_property__s std::string Ident;
CGraphic *G;
CPlayerColorGraphic *G;
int Frame;
};

View file

@ -25,6 +25,7 @@ class CPreference
bool BigScreen;
bool PauseOnLeave;
bool AiExplores;
bool GrayscaleIcons;
unsigned int ShowOrders;
unsigned int ShowNameDelay;

View file

@ -245,7 +245,7 @@ static const CUnit *GetUnitRef(const CUnit &unit, EnumUnit e)
const CUnit *unitToDraw = GetUnitRef(unit, this->UnitRef);
if (unitToDraw && unitToDraw->Type->Icon.Icon) {
unitToDraw->Type->Icon.Icon->DrawIcon(*unitToDraw->Player, this->Pos);
unitToDraw->Type->Icon.Icon->DrawIcon(this->Pos, unitToDraw->Player->Index);
}
}

View file

@ -41,6 +41,7 @@
#include "player.h"
#include "translate.h"
#include "ui.h"
#include "unit.h"
#include "video.h"
#include <map>
@ -69,8 +70,8 @@ CIcon::CIcon(const std::string &ident) : G(NULL), GScale(NULL), Frame(0), Ident(
*/
CIcon::~CIcon()
{
CGraphic::Free(this->G);
CGraphic::Free(this->GScale);
CPlayerColorGraphic::Free(this->G);
CPlayerColorGraphic::Free(this->GScale);
}
/**
@ -110,7 +111,9 @@ void CIcon::Load()
{
Assert(G);
G->Load();
GScale = G->Clone(true);
if (Preference.GrayscaleIcons) {
GScale = G->Clone(true);
}
if (Frame >= G->NumFrames) {
DebugPrint("Invalid icon frame: %s - %d\n" _C_ Ident.c_str() _C_ Frame);
Frame = 0;
@ -123,11 +126,10 @@ void CIcon::Load()
** @param player Player pointer used for icon colors
** @param pos display pixel position
*/
void CIcon::DrawIcon(const CPlayer &player, const PixelPos &pos) const
void CIcon::DrawIcon(const PixelPos &pos, const int player) const
{
CPlayerColorGraphic *g = dynamic_cast<CPlayerColorGraphic *>(this->G);
if (g) {
g->DrawPlayerColorFrameClip(player.Index, this->Frame, pos.x, pos.y);
if (player != -1 ) {
this->G->DrawPlayerColorFrameClip(player, this->Frame, pos.x, pos.y);
} else {
this->G->DrawFrameClip(this->Frame, pos.x, pos.y);
}
@ -138,9 +140,15 @@ void CIcon::DrawIcon(const CPlayer &player, const PixelPos &pos) const
**
** @param pos display pixel position
*/
void CIcon::DrawGrayscaleIcon(const PixelPos &pos) const
void CIcon::DrawGrayscaleIcon(const PixelPos &pos, const int player) const
{
this->GScale->DrawFrameClip(this->Frame, pos.x, pos.y);
if (this->GScale) {
if (player != -1) {
this->GScale->DrawPlayerColorFrameClip(player, this->Frame, pos.x, pos.y);
} else {
this->GScale->DrawFrameClip(this->Frame, pos.x, pos.y);
}
}
}
/**
@ -152,10 +160,15 @@ void CIcon::DrawGrayscaleIcon(const PixelPos &pos) const
void CIcon::DrawCooldownSpellIcon(const PixelPos &pos, const int percent) const
{
// TO-DO: implement more effect types (clock-like)
this->GScale->DrawFrameClip(this->Frame, pos.x, pos.y);
const int height = (G->Height * (100 - percent)) / 100;
this->G->DrawSubClip(G->frame_map[Frame].x, G->frame_map[Frame].y + G->Height - height,
G->Width, height, pos.x, pos.y + G->Height - height);
if (this->GScale) {
this->GScale->DrawFrameClip(this->Frame, pos.x, pos.y);
const int height = (G->Height * (100 - percent)) / 100;
this->G->DrawSubClip(G->frame_map[Frame].x, G->frame_map[Frame].y + G->Height - height,
G->Width, height, pos.x, pos.y + G->Height - height);
} else {
DebugPrint("Enable grayscale icon drawing in your game to achieve special effects for cooldown spell icons");
this->DrawIcon(pos);
}
}
/**
@ -167,7 +180,7 @@ void CIcon::DrawCooldownSpellIcon(const PixelPos &pos, const int percent) const
** @param text Optional text to display
*/
void CIcon::DrawUnitIcon(const ButtonStyle &style, unsigned flags,
const PixelPos &pos, const std::string &text) const
const PixelPos &pos, const std::string &text, int player) const
{
ButtonStyle s(style);
@ -178,7 +191,7 @@ void CIcon::DrawUnitIcon(const ButtonStyle &style, unsigned flags,
s.Default.BorderColor = 0;
}
// FIXME: player colors
DrawUIButton(&s, flags, pos.x, pos.y, text);
DrawUIButton(&s, flags, pos.x, pos.y, text, player);
}
/**

View file

@ -357,7 +357,7 @@ static void DrawUnitInfo_Training(const CUnit &unit)
const unsigned int flags = (ButtonAreaUnderCursor == ButtonAreaTraining && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.SingleTrainingButton->X, UI.SingleTrainingButton->Y);
icon.DrawUnitIcon(*UI.SingleTrainingButton->Style, flags, pos, "");
icon.DrawUnitIcon(*UI.SingleTrainingButton->Style, flags, pos, "", unit.Player->Index);
}
} else {
if (!UI.TrainingText.empty()) {
@ -374,15 +374,16 @@ static void DrawUnitInfo_Training(const CUnit &unit)
&& static_cast<size_t>(ButtonUnderCursor) == i) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.TrainingButtons[i].X, UI.TrainingButtons[i].Y);
icon.DrawUnitIcon(*UI.TrainingButtons[i].Style, flag, pos, "");
icon.DrawUnitIcon(*UI.TrainingButtons[i].Style, flag, pos, "", unit.Player->Index);
}
}
}
}
}
static void DrawUnitInfo_portrait(const CUnitType &type)
static void DrawUnitInfo_portrait(const CUnit &unit)
{
const CUnitType &type = *unit.Type;
#ifdef USE_MNG
if (type.Portrait.Num) {
type.Portrait.Mngs[type.Portrait.CurrMng]->Draw(
@ -406,7 +407,7 @@ static void DrawUnitInfo_portrait(const CUnitType &type)
const int flag = (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
type.Icon.Icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "");
type.Icon.Icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "", unit.Player->Index);
}
}
@ -425,7 +426,7 @@ static bool DrawUnitInfo_single_selection(const CUnit &unit)
&& ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.UpgradingButton->X, UI.UpgradingButton->Y);
icon.DrawUnitIcon(*UI.UpgradingButton->Style, flag, pos, "");
icon.DrawUnitIcon(*UI.UpgradingButton->Style, flag, pos, "", unit.Player->Index);
}
return true;
}
@ -437,7 +438,7 @@ static bool DrawUnitInfo_single_selection(const CUnit &unit)
&& ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
PixelPos pos(UI.ResearchingButton->X, UI.ResearchingButton->Y);
icon.DrawUnitIcon(*UI.ResearchingButton->Style, flag, pos, "");
icon.DrawUnitIcon(*UI.ResearchingButton->Style, flag, pos, "", unit.Player->Index);
}
return true;
}
@ -459,7 +460,7 @@ static void DrawUnitInfo_transporter(CUnit &unit)
int flag = (ButtonAreaUnderCursor == ButtonAreaTransporting && static_cast<size_t>(ButtonUnderCursor) == j) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.TransportingButtons[j].X, UI.TransportingButtons[j].Y);
icon.DrawUnitIcon(*UI.TransportingButtons[j].Style, flag, pos, "");
icon.DrawUnitIcon(*UI.TransportingButtons[j].Style, flag, pos, "", uins->Player->Index);
UiDrawLifeBar(*uins, pos.x, pos.y);
if (uins->Type->CanCastSpell && uins->Variable[MANA_INDEX].Max) {
UiDrawManaBar(*uins, pos.x, pos.y);
@ -495,7 +496,7 @@ static void DrawUnitInfo(CUnit &unit)
Assert(&type);
// Draw IconUnit
DrawUnitInfo_portrait(type);
DrawUnitInfo_portrait(unit);
if (unit.Player != ThisPlayer && !ThisPlayer->IsAllied(*unit.Player)) {
return;
@ -1155,7 +1156,7 @@ static void InfoPanel_draw_multiple_selection()
icon.DrawUnitIcon(*UI.SelectedButtons[i].Style,
(ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == (int)i) ?
(IconActive | (MouseButtons & LeftButton)) : 0,
pos, "");
pos, "", Selected[i]->Player->Index);
UiDrawLifeBar(*Selected[i], UI.SelectedButtons[i].X, UI.SelectedButtons[i].Y);
if (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == (int) i) {

View file

@ -2142,7 +2142,7 @@ void DrawPieMenu()
if (gray) {
buttons[i].Icon.Icon->DrawGrayscaleIcon(pos);
} else {
buttons[i].Icon.Icon->DrawIcon(player, pos);
buttons[i].Icon.Icon->DrawIcon(pos);
}
// Tutorial show command key in icons

View file

@ -58,7 +58,7 @@
** @param text text to print on button
*/
void DrawUIButton(ButtonStyle *style, unsigned flags, int x, int y,
const std::string &text)
const std::string &text, int player)
{
ButtonStyleProperties *p;
@ -88,8 +88,8 @@ void DrawUIButton(ButtonStyle *style, unsigned flags, int x, int y,
if (pimage->Sprite) {
CPlayerColorGraphic *colorGraphic = dynamic_cast<CPlayerColorGraphic *>(pimage->Sprite);
if (colorGraphic && ThisPlayer) {
colorGraphic->DrawPlayerColorFrameClip(ThisPlayer->Index, pimage->Frame, x, y);
if (colorGraphic && player != -1) {
colorGraphic->DrawPlayerColorFrameClip(player, pimage->Frame, x, y);
} else {
pimage->Sprite->DrawFrame(pimage->Frame, x, y);
}

View file

@ -548,9 +548,9 @@ CGraphic *CGraphic::ForceNew(const std::string &file, int w, int h)
**
** @param grayscale Make grayscale texture
*/
CGraphic *CGraphic::Clone(bool grayscale) const
CPlayerColorGraphic *CPlayerColorGraphic::Clone(bool grayscale) const
{
CGraphic *g = CGraphic::ForceNew(this->File, this->Width, this->Height);
CPlayerColorGraphic *g = CPlayerColorGraphic::ForceNew(this->File, this->Width, this->Height);
if (this->IsLoaded()) {
g->Load(grayscale);