summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-05-16 18:52:11 +0000
committeralberth <alberth@openttd.org>2010-05-16 18:52:11 +0000
commit219ae56f8aac67b9e8111500a34700c082eea2fd (patch)
tree105f3f108521ea6a9ee9b8d8f249753a1bcbd0aa /src
parent32713624133e86024b90521702fe1173943243c1 (diff)
downloadopenttd-219ae56f8aac67b9e8111500a34700c082eea2fd.tar.xz
(svn r19836) -Codechange: Move sprite palette selection code in NewGRF gui to its own method.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_gui.cpp59
1 files changed, 35 insertions, 24 deletions
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index e03f0e24f..b7bcd99da 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -623,6 +623,40 @@ struct NewGRFWindow : public Window {
this->DrawWidgets();
}
+ /** Pick the palette for the sprite of the grf to display.
+ * @param c grf to display.
+ * @return Palette for the sprite.
+ */
+ FORCEINLINE PaletteID GetPalette(const GRFConfig *c) const
+ {
+ PaletteID pal;
+
+ /* Pick a colour */
+ switch (c->status) {
+ case GCS_NOT_FOUND:
+ case GCS_DISABLED:
+ pal = PALETTE_TO_RED;
+ break;
+ case GCS_ACTIVATED:
+ pal = PALETTE_TO_GREEN;
+ break;
+ default:
+ pal = PALETTE_TO_BLUE;
+ break;
+ }
+
+ /* Do not show a "not-failure" colour when it actually failed to load */
+ if (pal != PALETTE_TO_RED) {
+ if (HasBit(c->flags, GCF_STATIC)) {
+ pal = PALETTE_TO_GREY;
+ } else if (HasBit(c->flags, GCF_COMPATIBLE)) {
+ pal = PALETTE_TO_ORANGE;
+ }
+ }
+
+ return pal;
+ }
+
virtual void DrawWidget(const Rect &r, int widget) const
{
switch (widget) {
@@ -644,30 +678,7 @@ struct NewGRFWindow : public Window {
if (this->vscroll.IsVisible(i)) {
const char *text = c->GetName();
bool h = (this->active_sel == c);
- PaletteID pal;
-
- /* Pick a colour */
- switch (c->status) {
- case GCS_NOT_FOUND:
- case GCS_DISABLED:
- pal = PALETTE_TO_RED;
- break;
- case GCS_ACTIVATED:
- pal = PALETTE_TO_GREEN;
- break;
- default:
- pal = PALETTE_TO_BLUE;
- break;
- }
-
- /* Do not show a "not-failure" colour when it actually failed to load */
- if (pal != PALETTE_TO_RED) {
- if (HasBit(c->flags, GCF_STATIC)) {
- pal = PALETTE_TO_GREY;
- } else if (HasBit(c->flags, GCF_COMPATIBLE)) {
- pal = PALETTE_TO_ORANGE;
- }
- }
+ PaletteID pal = this->GetPalette(c);
if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156);
DrawSprite(SPR_SQUARE, pal, square_left, y + sprite_offset_y);