allow land info tool to work in measurement mode (dragdrop)

This commit is contained in:
Pavel Stupnikov
2015-03-23 22:42:57 +03:00
parent 74ddc68c3f
commit e7047bd71b
8 changed files with 27 additions and 73 deletions

View File

@@ -48,7 +48,7 @@ void ShowGenerateLandscape();
void ShowHeightmapLoad();
/* misc_gui.cpp */
void ShowLandInfo(TileIndex tile);
void ShowLandInfo(TileIndex tile, TileIndex end_tile=INVALID_TILE);
void ShowAboutWindow();
void ShowBuildTreesToolbar();
void ShowTownDirectory();

View File

@@ -276,8 +276,7 @@ STR_MEASURE_LENGTH :{BLACK}Length:
STR_MEASURE_AREA :{BLACK}Area: {NUM} x {NUM}
STR_MEASURE_LENGTH_HEIGHTDIFF :{BLACK}Length: {NUM}{}Height difference: {HEIGHT}
STR_MEASURE_AREA_HEIGHTDIFF :{BLACK}Area: {NUM} x {NUM}{}Height difference: {HEIGHT}
STR_MEASURE_DIST_HEIGHTDIFF :{BLACK}Manhattan Distance: {NUM}{}Bird Fly Distance: {NUM}{}Distance from the nearest edge: {NUM}{}Height from sea level: {HEIGHT}{}Height difference: {HEIGHT}
STR_MEASURE_DIST_HEIGHTDIFF :{BLACK}Area: {NUM} x {NUM}{}Distance: {NUM}{}Height difference: {HEIGHT}
# These are used in buttons
STR_SORT_BY_CAPTION_NAME :{BLACK}Name
@@ -2514,7 +2513,6 @@ STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND :{BLACK}Lower a
STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND :{BLACK}Raise a corner of land. Dragging raises the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
STR_LANDSCAPING_LEVEL_LAND_TOOLTIP :{BLACK}Level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND :{BLACK}Purchase land for future use. Shift toggles building/showing cost estimate
STR_LANDSCAPING_TOOLTIP_RULER_TOOL :{BLACK}Use a virtual ruler to measure distance and height
# Object construction window
STR_OBJECT_BUILD_CAPTION :{WHITE}Object Selection

View File

@@ -73,6 +73,7 @@ class LandInfoWindow : public Window {
public:
char landinfo_data[LAND_INFO_LINE_END][LAND_INFO_LINE_BUFF_SIZE];
TileIndex tile;
TileIndex end_tile; ///< For use in ruler(dragdrop) mode
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
{
@@ -127,7 +128,8 @@ public:
}
}
LandInfoWindow(TileIndex tile) : Window(&_land_info_desc), tile(tile)
LandInfoWindow(TileIndex tile, TileIndex end_tile=INVALID_TILE) :
Window(&_land_info_desc), tile(tile), end_tile(end_tile)
{
this->InitNested();
CLRBITS(this->flags, WF_WHITE_BORDER);
@@ -396,10 +398,10 @@ public:
* Show land information window.
* @param tile The tile to show information about.
*/
void ShowLandInfo(TileIndex tile)
void ShowLandInfo(TileIndex tile, TileIndex end_tile)
{
DeleteWindowById(WC_LAND_INFO, 0);
new LandInfoWindow(tile);
new LandInfoWindow(tile, end_tile);
}
static const NWidgetPart _nested_about_widgets[] = {

View File

@@ -147,11 +147,6 @@ void PlaceProc_DemolishArea(TileIndex tile)
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
}
static void PlaceProc_Measure(TileIndex tile)
{
VpStartPlaceSizing(tile, VPM_A_B_LINE, DDSP_MEASURE);
}
/** Terra form toolbar managing class. */
struct TerraformToolbarWindow : Window {
int last_user_action; ///< Last started user action.
@@ -209,11 +204,6 @@ struct TerraformToolbarWindow : Window {
ShowBuildTreesToolbar();
break;
case WID_TT_MEASUREMENT_TOOL:
HandlePlacePushButton(this, WID_TT_MEASUREMENT_TOOL, SPR_CURSOR_QUERY, HT_RECT);
this->last_user_action = widget;
break;
case WID_TT_PLACE_SIGN: // Place sign button
HandlePlacePushButton(this, WID_TT_PLACE_SIGN, SPR_CURSOR_SIGN, HT_RECT);
this->last_user_action = widget;
@@ -255,10 +245,6 @@ struct TerraformToolbarWindow : Window {
DoCommandP(tile, OBJECT_OWNED_LAND, 0, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_PURCHASE_THIS_LAND), CcPlaySound1E);
break;
case WID_TT_MEASUREMENT_TOOL:
PlaceProc_Measure(tile);
break;
case WID_TT_PLACE_SIGN: // Place sign button
PlaceProc_Sign(tile);
break;
@@ -294,9 +280,6 @@ struct TerraformToolbarWindow : Window {
case DDSP_LEVEL_AREA:
GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
break;
case DDSP_MEASURE:
//nothing to do, just draw a tooltip
break;
}
}
}
@@ -358,8 +341,6 @@ static const NWidgetPart _nested_terraform_widgets[] = {
SetFill(0, 1), SetDataTip(SPR_IMG_BUY_LAND, STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND),
NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLANT_TREES), SetMinimalSize(22, 22),
SetFill(0, 1), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
// NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_MEASUREMENT_TOOL), SetMinimalSize(22,22),
// SetFill(0, 1), SetDataTip(SPR_IMG_QUERY, STR_LANDSCAPING_TOOLTIP_RULER_TOOL),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_SIGN), SetMinimalSize(22, 22),
SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TT_SHOW_PLACE_OBJECT),

View File

@@ -1864,6 +1864,7 @@ struct MainToolbarWindow : Window {
break;
case CBF_PLACE_LANDINFO:
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_MEASURE);
break;
case CBF_BUILD_HQ:
@@ -1877,6 +1878,11 @@ struct MainToolbarWindow : Window {
}
}
virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
{
VpSelectTilesWithMethod(pt.x, pt.y, select_method);
}
virtual void OnTick()
{
if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
@@ -2216,6 +2222,7 @@ struct ScenarioEditorToolbarWindow : Window {
break;
case CBF_PLACE_LANDINFO:
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_MEASURE);
break;
default: NOT_REACHED();

View File

@@ -2598,7 +2598,6 @@ void UpdateTileSelection()
*/
static inline void ShowMeasurementTooltips(StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_cond = TCC_LEFT_CLICK)
{
if (!_settings_client.gui.measure_tooltip) return;
GuiShowTooltips(_thd.GetCallbackWnd(), str, paramcount, params, close_cond);
}
@@ -2662,7 +2661,8 @@ void VpSetPresizeRange(TileIndex from, TileIndex to)
_thd.next_drawstyle = HT_RECT;
/* show measurement only if there is any length to speak of */
if (distance > 1) ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1, &distance, TCC_HOVER);
if (distance > 1 && _settings_client.gui.measure_tooltip)
ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1, &distance, TCC_HOVER);
}
static void VpStartPreSizing()
@@ -3392,45 +3392,6 @@ calc_heightdiff_single_direction:;
ShowLengthMeasurement(HT_LINE | style, TileVirtXY(sx, sy), TileVirtXY(x, y));
break;
case VPM_A_B_LINE: { // drag an A to B line
TileIndex t0 = TileVirtXY(sx, sy);
TileIndex t1 = TileVirtXY(x, y);
uint dx = Delta(TileX(t0), TileX(t1));
uint dy = Delta(TileY(t0), TileY(t1));
byte index = 0;
uint64 params[5];
memset( params, 0, sizeof( params ) );
/* If dragging an area (eg dynamite tool) and it is actually a single
* row/column, change the type to 'line' to get proper calculation for height */
style = (HighLightStyle)_thd.next_drawstyle;
if (style & HT_RECT) {
if (dx == 0) {
style = HT_LINE | HT_DIR_Y;
} else if (dy == 0) {
style = HT_LINE | HT_DIR_X;
}
}
int heightdiff = 0;
if (dx != 0 || dy != 0) {
heightdiff = CalcHeightdiff(style, 0, t0, t1);
params[index++] = DistanceManhattan(t0, t1);
params[index++] = sqrtl(dx * dx + dy * dy); //DistanceSquare does not like big numbers
} else {
params[index++] = 0;
params[index++] = 0;
}
params[index++] = DistanceFromEdge(t1);
params[index++] = GetTileMaxZ(t1) / TILE_HEIGHT * TILE_HEIGHT_STEP;
params[index++] = heightdiff;
//Show always the measurement tooltip
GuiShowTooltips(_thd.GetCallbackWnd(),STR_MEASURE_DIST_HEIGHTDIFF, index, params, TCC_LEFT_CLICK);
break;
}
case VPM_X_AND_Y_LIMITED: // Drag an X by Y constrained rect area.
limit = (_thd.sizelimit - 1) * TILE_SIZE;
x = sx + Clamp(x - sx, -limit, limit);
@@ -3438,9 +3399,10 @@ calc_heightdiff_single_direction:;
/* FALL THROUGH */
case VPM_X_AND_Y: // drag an X by Y area
if (_settings_client.gui.measure_tooltip) {
if (_settings_client.gui.measure_tooltip || _thd.select_proc == DDSP_MEASURE) {
static const StringID measure_strings_area[] = {
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF
STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF,
STR_MEASURE_DIST_HEIGHTDIFF,
};
TileIndex t0 = TileVirtXY(sx, sy);
@@ -3448,7 +3410,7 @@ calc_heightdiff_single_direction:;
uint dx = Delta(TileX(t0), TileX(t1)) + 1;
uint dy = Delta(TileY(t0), TileY(t1)) + 1;
byte index = 0;
uint64 params[3];
uint64 params[4];
/* If dragging an area (eg dynamite tool) and it is actually a single
* row/column, change the type to 'line' to get proper calculation for height */
@@ -3495,7 +3457,13 @@ calc_heightdiff_single_direction:;
params[index++] = dx - (style & HT_POINT ? 1 : 0);
params[index++] = dy - (style & HT_POINT ? 1 : 0);
if (heightdiff != 0) params[index++] = heightdiff;
if (_thd.select_proc == DDSP_MEASURE) {
params[index++] = sqrtl(dx * dx + dy * dy);
}
if (heightdiff != 0 || index == 3)
params[index++] = heightdiff;
}
ShowMeasurementTooltips(measure_strings_area[index], index, params);

View File

@@ -87,7 +87,6 @@ enum ViewportPlaceMethod {
VPM_FIX_VERTICAL = 6, ///< drag only in vertical direction
VPM_X_LIMITED = 7, ///< Drag only in X axis with limited size
VPM_Y_LIMITED = 8, ///< Drag only in Y axis with limited size
VPM_A_B_LINE = 9, ///< Drag a line from tile A to tile B
VPM_RAILDIRS = 0x40, ///< all rail directions
VPM_SIGNALDIRS = 0x80, ///< similar to VMP_RAILDIRS, but with different cursor
};

View File

@@ -22,7 +22,6 @@ enum TerraformToolbarWidgets {
WID_TT_DEMOLISH, ///< Demolish aka dynamite button.
WID_TT_BUY_LAND, ///< Buy land button.
WID_TT_PLANT_TREES, ///< Plant trees button (note: opens separate window, no place-push-button).
WID_TT_MEASUREMENT_TOOL, ///< Ruler tool button
WID_TT_PLACE_SIGN, ///< Place sign button.
WID_TT_PLACE_OBJECT, ///< Place object button.
};