Merge branch 'master' into jgrpp
# Conflicts: # src/lang/russian.txt # src/linkgraph/linkgraph_gui.cpp # src/news_gui.cpp # src/town_cmd.cpp # src/town_gui.cpp
This commit is contained in:
@@ -170,7 +170,7 @@ void LinkGraphOverlay::RebuildCache(bool incremental)
|
||||
item->from_pt = from_pt;
|
||||
item->to_pt = to_pt;
|
||||
}
|
||||
this->AddStats(lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
|
||||
this->AddStats(c, lg.Monthly(edge.Capacity()), lg.Monthly(edge.Usage()),
|
||||
ge.flows.GetFlowVia(to->index), from->owner == OWNER_NONE || to->owner == OWNER_NONE,
|
||||
item->prop);
|
||||
}
|
||||
@@ -345,11 +345,12 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
|
||||
* @param new_shared If the new link is shared.
|
||||
* @param cargo LinkProperties to write the information to.
|
||||
*/
|
||||
/* static */ void LinkGraphOverlay::AddStats(uint new_cap, uint new_usg, uint new_plan, bool new_shared, LinkProperties &cargo)
|
||||
/* static */ void LinkGraphOverlay::AddStats(CargoID new_cargo, uint new_cap, uint new_usg, uint new_plan, bool new_shared, LinkProperties &cargo)
|
||||
{
|
||||
/* multiply the numbers by 32 in order to avoid comparing to 0 too often. */
|
||||
if (cargo.capacity == 0 ||
|
||||
std::max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < std::max(new_usg, new_plan) * 32 / (new_cap + 1)) {
|
||||
cargo.Usage() * 32 / (cargo.capacity + 1) < std::max(new_usg, new_plan) * 32 / (new_cap + 1)) {
|
||||
cargo.cargo = new_cargo;
|
||||
cargo.capacity = new_cap;
|
||||
cargo.usage = new_usg;
|
||||
cargo.planned = new_plan;
|
||||
@@ -417,7 +418,7 @@ void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
|
||||
*/
|
||||
void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
|
||||
{
|
||||
uint usage_or_plan = std::min(cargo.capacity * 2 + 1, std::max(cargo.usage, cargo.planned));
|
||||
uint usage_or_plan = std::min(cargo.capacity * 2 + 1, cargo.Usage());
|
||||
int colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS[0]) / (cargo.capacity * 2 + 2)];
|
||||
int width = ScaleGUITrad(this->scale);
|
||||
int dash = cargo.shared ? width * 4 : 0;
|
||||
@@ -483,6 +484,56 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
|
||||
GfxDrawLine(x + w2, y - w1, x + w2, y + w2, border_colour);
|
||||
}
|
||||
|
||||
bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||
{
|
||||
for (LinkList::const_reverse_iterator i(this->cached_links.rbegin()); i != this->cached_links.rend(); ++i) {
|
||||
if (!Station::IsValidID(i->from_id)) continue;
|
||||
if (!Station::IsValidID(i->to_id)) continue;
|
||||
|
||||
Point pta = i->from_pt;
|
||||
Point ptb = i->to_pt;
|
||||
|
||||
/* Check the distance from the cursor to the line defined by the two stations. */
|
||||
auto check_distance = [&]() -> bool {
|
||||
int64 a = ((ptb.x - pta.x) * (pta.y - pt.y) - (pta.x - pt.x) * (ptb.y - pta.y));
|
||||
return ((a * a) / ((ptb.x - pta.x) * (ptb.x - pta.x) + (ptb.y - pta.y) * (ptb.y - pta.y))) <= 16;
|
||||
};
|
||||
const auto &link = i->prop;
|
||||
if (link.Usage() > 0 &&
|
||||
pt.x + 2 >= std::min(pta.x, ptb.x) &&
|
||||
pt.x - 2 <= std::max(pta.x, ptb.x) &&
|
||||
check_distance()) {
|
||||
|
||||
static char buf[1024];
|
||||
buf[0] = 0;
|
||||
|
||||
/* Fill buf with more information if this is a bidirectional link. */
|
||||
for (LinkList::const_reverse_iterator j = std::next(i); j != this->cached_links.rend(); ++j) {
|
||||
if (j->from_id == i->to_id && j->to_id == i->from_id) {
|
||||
if (j->prop.Usage() > 0) {
|
||||
SetDParam(0, j->prop.cargo);
|
||||
SetDParam(1, j->prop.Usage());
|
||||
SetDParam(2, j->prop.Usage() * 100 / (j->prop.capacity + 1));
|
||||
GetString(buf, STR_LINKGRAPH_STATS_TOOLTIP_RETURN_EXTENSION, lastof(buf));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SetDParam(0, link.cargo);
|
||||
SetDParam(1, link.Usage());
|
||||
SetDParam(2, i->from_id);
|
||||
SetDParam(3, i->to_id);
|
||||
SetDParam(4, link.Usage() * 100 / (link.capacity + 1));
|
||||
SetDParamStr(5, buf);
|
||||
GuiShowTooltips(this->window, STR_LINKGRAPH_STATS_TOOLTIP, 0, nullptr, close_cond);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
GuiShowTooltips(this->window, STR_NULL, 0, nullptr, close_cond);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the middle of a station in the current window.
|
||||
* @param st The station we're looking for.
|
||||
|
Reference in New Issue
Block a user