diff --git a/src/gui.h b/src/gui.h index fc0381c9b7..d7634aa8a4 100644 --- a/src/gui.h +++ b/src/gui.h @@ -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(); diff --git a/src/lang/english.txt b/src/lang/english.txt index dee2fd87fd..88e9952559 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -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 diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 3ea4b8a5b2..68a945e037 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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[] = { diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index 0d5143587f..fe1b52459e 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -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), diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 4d8b3c917e..f980e03bab 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -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(); diff --git a/src/viewport.cpp b/src/viewport.cpp index d2c54c7245..019581fc81 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -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); diff --git a/src/viewport_type.h b/src/viewport_type.h index 09a2cdbb4c..14c89ca975 100644 --- a/src/viewport_type.h +++ b/src/viewport_type.h @@ -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 }; diff --git a/src/widgets/terraform_widget.h b/src/widgets/terraform_widget.h index e56b38916a..74f168d82b 100644 --- a/src/widgets/terraform_widget.h +++ b/src/widgets/terraform_widget.h @@ -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. };