diff --git a/src/economy.cpp b/src/economy.cpp index 59983884d5..00bdd6f534 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1690,9 +1690,7 @@ static void LoadUnloadVehicle(Vehicle *front) } } - if (payment != NULL) { - amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment); - } + amount_unloaded = v->cargo.Unload(amount_unloaded, &ge->cargo, payment); remaining = v->cargo.UnloadCount() > 0; if (amount_unloaded > 0) { dirty_vehicle = true; diff --git a/src/gfx.cpp b/src/gfx.cpp index caf07ff2ac..4df8e78c93 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1893,104 +1893,3 @@ void SortResolutions() { std::sort(_resolutions.begin(), _resolutions.end()); } - - -/** - * Returns the initial value for a margin, after telling where are the left and right margins and where we want to draw/write (begining/end of line) - * @param left is the left margin of the horizontal space we want to draw to - * @param right: right margin - * @param to_end_line: 0 if working at the begining of the line, 1 if working at the end - * @return the margin we asked - */ -int InitTempMargin(int left, int right, bool to_end_line) -{ - return to_end_line ^ (_current_text_dir == TD_RTL) ? right :left; -} - -/** - * Consumes a space in an horizontal margin - * @param space: amount of space used - * @param here: the margin where to add the space - * @param to_end_line: 0 if working at the begining of the line, 1 if working at the end - */ -void AddSpace(int space, int &here, bool to_end_line) -{ - here += to_end_line ^ (_current_text_dir == TD_RTL) ? -space : space; -} - -/** - * After drawing something, update a margin - * @param end is where we ended drawing (usually the return value of a DrawString function) - * @param margin is the margin we want to update - * @param to_end_line: 0 if working at the begining of the line, 1 if working at the end - */ -void UpdateMarginEnd(int end, int &margin, bool to_end_line) -{ - margin = to_end_line ^ (_current_text_dir == TD_RTL) ? min(end, margin) : max(end, margin); -} - -/** - * After drawing something, horizontal margins are updated - * @param end: last position drawn - * @param left is the left margin of the horizontal space drawn - * @param right: right margin - * @param to_end_line: 0 if working at the begining of the line, 1 if working at the end - */ -void UpdateMarginsEnd(int end, int &left, int &right, bool to_end_line) -{ - if (to_end_line ^ (_current_text_dir == TD_RTL)) { - right = end; - } else { - left = end; - } -} - -/** - * After drawing something of a certain width, update margins - * @param width: used space - * @param initial left margin - * @param initial right margin - * @param to_end_line: 0 if working at the begining of the line, 1 if working at the end - */ -void UpdateMarginsWidth(int width, int &left, int &right, bool to_end_line) -{ - if (to_end_line ^ (_current_text_dir == TD_RTL)) { - right -= width; - } else { - left += width; - } -} - -/** - * Draws a string in a delimited space; temporal margin gets updated - * @param left is the left margin of the horizontal space we want to draw to - * @param right: right margin of the horizontal space we want to draw to - * @param top: vertical position - * @param margin keeps the most extreme limit used of the line (this should be previously initialized with InitTempLimit) - * @param string to draw - * @param colour for the string - * @param alignment of the string (only left or right alignment) - * @param underline - */ -void DrawString2(int left, int right, int top, int &margin, StringID str, TextColour colour, StringAlignment align, bool underline) -{ - int end = DrawString(left, right, top, str, colour, align, underline); - UpdateMarginEnd(end, margin, align == SA_RIGHT); -} - -/** - * Draws a sprite in a delimited space; temporal margin gets updated - * @param width of the sprite - * @param left is the left margin of the horizontal space we want to draw to - * @param right: right margin of the horizontal space - * @param top: vertical position - * @param margin keeps the most extreme limit used of the line (this should be previously initialized with InitTempLimit) - * @param sprite - * @param palette - * @param to_end_line: 0 if working at the begining of the line, 1 if working at the end - */ -void DrawSprite2(int width, int left, int right, int top, int &margin, SpriteID img, PaletteID pal, bool to_end_line, SubSprite *sub) -{ - DrawSprite(img, pal, to_end_line ^ (_current_text_dir == TD_RTL) ? right - width : left, top, sub); - margin = to_end_line ^ (_current_text_dir == TD_RTL) ? min(right - width, margin): max(margin, left + width); -} diff --git a/src/gfx_func.h b/src/gfx_func.h index ac13e2fe5d..4faa5f245c 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -189,17 +189,6 @@ int GetCharacterHeight(FontSize size); /** Height of characters in the large (#FS_MONO) font. @note Some characters may be oversized. */ #define FONT_HEIGHT_MONO (GetCharacterHeight(FS_MONO)) -int InitTempMargin(int left, int right, bool to_end_line); -void AddSpace(int space, int &here, bool to_end_line); - -void UpdateMarginEnd(int end, int &margin, bool to_end_line); -void UpdateMarginWidth(int adding, int &margin, bool to_end_line); -void UpdateMarginsEnd(int end, int &left, int &right, bool to_end_line); -void UpdateMarginsWidth(int width, int &left, int &right, bool to_end_line); - -void DrawString2(int left, int right, int top, int &margin, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false); -void DrawSprite2(int width, int left, int right, int top, int &margin, SpriteID img, PaletteID pal, bool to_end_line = false, SubSprite *sub = NULL); - /** * Return where to start drawing a centered object inside a widget. * @param top The top coordinate (or the left coordinate) of the widget. diff --git a/src/station_base.h b/src/station_base.h index d6ef468082..0c33a58edb 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -299,14 +299,6 @@ struct GoodsEntry { FlowStatMap::const_iterator flow_it(this->flows.find(source)); return flow_it != this->flows.end() ? flow_it->second.GetVia(excluded, excluded2) : INVALID_STATION; } - - /** - * Return true if a cargo type has a rating here or if there is cargo waiting for this type. - */ - inline bool IsSourceStationForCargo() const - { - return this->HasRating() || this->cargo.TotalCount() > 0; - } }; /** All airport-related information. Only valid if tile != INVALID_TILE. */ diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 041967b7f2..d9485fa4f4 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -153,44 +153,44 @@ void CheckRedrawStationCoverage(const Window *w) * @param type Cargo type * @param amount Cargo amount * @param rating ratings data for that particular cargo + * + * @note Each cargo-bar is 16 pixels wide and 6 pixels high + * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar */ static void StationsWndShowStationRating(int left, int right, int y, CargoID type, uint amount, byte rating) { - static const uint units_full = 1 << 9; ///< Number of units to show station as full. - static const uint rating_full = 224; ///< Rating needed so it is shown as full. + static const uint units_full = 576; ///< number of units to show station as 'full' + static const uint rating_full = 224; ///< rating needed so it is shown as 'full' const CargoSpec *cs = CargoSpec::Get(type); if (!cs->IsValid()) return; - y++; ///< Make boxes 1 pixel shorter. - int left_start = left; - int right_start = right; - int height = GetCharacterHeight(FS_SMALL) - 2; int colour = cs->rating_colour; + TextColour tc = GetContrastColour(colour); + uint w = (minu(amount, units_full) + 5) / 36; - /* Get width of the box to draw. */ - uint width = minu(amount, units_full) * (right - left) / units_full; + int height = GetCharacterHeight(FS_SMALL); - /* Update the end margin, adding the width of the box not to be drawn... */ - if (width != 0) UpdateMarginsWidth(right - left - width, left_start, right_start, true); - /* ... or prepare margins in case width == 0 and amount > 0 (just one pixel bar). */ - else left_start = right_start = _current_text_dir ? right : left; + /* Draw total cargo (limited) on station (fits into 16 pixels) */ + if (w != 0) GfxFillRect(left, y, left + w - 1, y + height, colour); - /* Draw total cargo (limited) on station */ - if (amount > 0) GfxFillRect(left_start, y, right_start, y + height, colour); - - DrawString(left, right, y, cs->abbrev, GetContrastColour(colour), SA_CENTER); - - /* Draw green/red ratings bar*/ - y += height + 2; - left_start = left + 1; - right_start = right - 1; - if (rating != 0) { - GfxFillRect(left_start, y, right_start, y, PC_GREEN); - width = minu(rating, rating_full) * (right_start - left_start) / rating_full; - UpdateMarginsWidth(width, left_start, right_start, false); + /* Draw a one pixel-wide bar of additional cargo meter, useful + * for stations with only a small amount (<=30) */ + if (w == 0) { + uint rest = amount / 5; + if (rest != 0) { + w += left; + GfxFillRect(w, y + height - rest, w, y + height, colour); + } } - GfxFillRect(left_start, y, right_start, y, PC_RED); + + DrawString(left + 1, right, y, cs->abbrev, tc); + + /* Draw green/red ratings bar (fits into 14 pixels) */ + y += height + 2; + GfxFillRect(left + 1, y, left + 14, y, PC_RED); + rating = minu(rating, rating_full) / 16; + if (rating != 0) GfxFillRect(left + 1, y, left + rating, y, PC_GREEN); } typedef GUIList GUIStationList; @@ -457,7 +457,6 @@ public: SetDParam(0, st->index); SetDParam(1, st->facilities); int x = DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_LIST_STATION); - x += rtl ? -5 : 5; /* show cargo waiting and station ratings */