/** * Configure a ViewPort for rendering (a part of) the map into a screenshot. * @param t Screenshot type * @param [out] vp Result viewport */ void SetupScreenshotViewport(ScreenshotType t, ViewPort *vp) { /* Determine world coordinates of screenshot */ if (t == SC_WORLD) { vp->zoom = ZOOM_LVL_WORLD_SCREENSHOT; TileIndex north_tile = _settings_game.construction.freeform_edges ? TileXY(1, 1) : TileXY(0, 0); TileIndex south_tile = MapSize() - 1; /* We need to account for a hill or high building at tile 0,0. */ int extra_height_top = TilePixelHeight(north_tile) + 150; /* If there is a hill at the bottom don't create a large black area. */ int reclaim_height_bottom = TilePixelHeight(south_tile); vp->virtual_left = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, 0).x; vp->virtual_top = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(north_tile) * TILE_SIZE, extra_height_top).y; vp->virtual_width = RemapCoords(TileX(north_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, 0).x - vp->virtual_left + 1; vp->virtual_height = RemapCoords(TileX(south_tile) * TILE_SIZE, TileY(south_tile) * TILE_SIZE, reclaim_height_bottom).y - vp->virtual_top + 1; } else { vp->zoom = (t == SC_ZOOMEDIN) ? _settings_client.gui.zoom_min : ZOOM_LVL_VIEWPORT; Window *w = FindWindowById(WC_MAIN_WINDOW, 0); vp->virtual_left = w->viewport->virtual_left; vp->virtual_top = w->viewport->virtual_top; vp->virtual_width = w->viewport->virtual_width; vp->virtual_height = w->viewport->virtual_height; } /* Compute pixel coordinates */ vp->left = 0; vp->top = 0; vp->width = UnScaleByZoom(vp->virtual_width, vp->zoom); vp->height = UnScaleByZoom(vp->virtual_height, vp->zoom); vp->overlay = NULL; }
void SndPlayTileFx(SoundID sound, TileIndex tile) { /* emits sound from center of the tile */ int x = min(MapMaxX() - 1, TileX(tile)) * TILE_SIZE + TILE_SIZE / 2; int y = min(MapMaxY() - 1, TileY(tile)) * TILE_SIZE - TILE_SIZE / 2; uint z = (y < 0 ? 0 : GetSlopeZ(x, y)); Point pt = RemapCoords(x, y, z); y += 2 * TILE_SIZE; Point pt2 = RemapCoords(x, y, GetSlopeZ(x, y)); SndPlayScreenCoordFx(sound, pt.x, pt2.x, pt.y, pt2.y); }
/** * Display animated feeder income. * @param x World X position of the animation location. * @param y World Y position of the animation location. * @param z World Z position of the animation location. * @param cost Estimated feeder income. */ void ShowFeederIncomeAnimation(int x, int y, int z, Money cost) { Point pt = RemapCoords(x, y, z); SetDParam(0, cost); AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING); }
ExtraViewportWindow(WindowDesc *desc, int window_number, TileIndex tile) : Window(desc) { this->InitNested(window_number); NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_EV_VIEWPORT); nvp->InitializeViewport(this, 0, ZOOM_LVL_VIEWPORT); if (_settings_client.gui.zoom_min == ZOOM_LVL_VIEWPORT) this->DisableWidget(WID_EV_ZOOM_IN); Point pt; if (tile == INVALID_TILE) { /* No tile? Use center of main viewport. */ const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); /* center on same place as main window (zoom is maximum, no adjustment needed) */ pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2; pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2; } else { pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile)); } this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2; this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2; this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x; this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y; }
ExtraViewportWindow(const WindowDesc *desc, int window_number, TileIndex tile) : Window() { this->InitNested(desc, window_number); NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(EVW_VIEWPORT); nvp->InitializeViewport(this, 0, ZOOM_LVL_NORMAL); this->DisableWidget(EVW_ZOOMIN); Point pt; if (tile == INVALID_TILE) { /* the main window with the main view */ const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); /* center on same place as main window (zoom is maximum, no adjustment needed) */ pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2; pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2; } else { pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile)); } this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2; this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2; this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x; this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y; }
/** * Display vehicle loading indicators. * @param x World X position of the animation location. * @param y World Y position of the animation location. * @param z World Z position of the animation location. * @param percent Estimated feeder income. * @param string String which is drawn on the map. * @return TextEffectID to be used for future updates of the loading indicators. */ TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID string) { Point pt = RemapCoords(x, y, z); assert(string != STR_NULL); SetDParam(0, percent); return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC); }
/** * Display animated income or costs on the map. * @param x World X position of the animation location. * @param y World Y position of the animation location. * @param z World Z position of the animation location. * @param cost Estimated cost (or income if negative). */ void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost) { Point pt = RemapCoords(x, y, z); StringID msg = STR_INCOME_FLOAT_COST; if (cost < 0) { cost = -cost; msg = STR_INCOME_FLOAT_INCOME; } SetDParam(0, cost); AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING); }
/** * Display animated feeder income. * @param x World X position of the animation location. * @param y World Y position of the animation location. * @param z World Z position of the animation location. * @param transfer Estimated feeder income. * @param income Real income from goods being delivered to their final destination. */ void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income) { Point pt = RemapCoords(x, y, z); SetDParam(0, transfer); if (income == 0) { AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING); } else { StringID msg = STR_FEEDER_COST; if (income < 0) { income = -income; msg = STR_FEEDER_INCOME; } SetDParam(1, income); AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING); } }
/** * Update the coordinate of one sign */ void Sign::UpdateVirtCoord() { Point pt = RemapCoords(this->x, this->y, this->z); SetDParam(0, this->index); this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_LVL_BASE, STR_WHITE_SIGN, STR_WHITE_SIGN); }