2213 |
2215 |
2214 if (_patches.measure_tooltip) { |
2216 if (_patches.measure_tooltip) { |
2215 TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y); |
2217 TileIndex t0 = TileVirtXY(thd->selstart.x, thd->selstart.y); |
2216 TileIndex t1 = TileVirtXY(x, y); |
2218 TileIndex t1 = TileVirtXY(x, y); |
2217 uint distance = DistanceManhattan(t0, t1) + 1; |
2219 uint distance = DistanceManhattan(t0, t1) + 1; |
2218 int heightdiff = CalcHeightdiff(b, distance, t0, t1); |
2220 byte index = 0; |
2219 uint params[2]; |
2221 uint params[2]; |
2220 |
2222 |
2221 /* If we are showing a tooltip for horizontal or vertical drags, |
2223 if (distance != 1) { |
2222 * 2 tiles have a length of 1. To bias towards the ceiling we add |
2224 int heightdiff = CalcHeightdiff(b, distance, t0, t1); |
2223 * one before division. It feels more natural to count 3 lengths as 2 */ |
2225 /* If we are showing a tooltip for horizontal or vertical drags, |
2224 if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) { |
2226 * 2 tiles have a length of 1. To bias towards the ceiling we add |
2225 distance = (distance + 1) / 2; |
2227 * one before division. It feels more natural to count 3 lengths as 2 */ |
2226 } |
2228 if ((b & HT_DIR_MASK) != HT_DIR_X && (b & HT_DIR_MASK) != HT_DIR_Y) { |
2227 |
2229 distance = (distance + 1) / 2; |
2228 params[0] = distance; |
2230 } |
2229 if (heightdiff == 0) { |
2231 |
2230 GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, params); |
2232 params[index++] = distance; |
2231 } else { |
2233 if (heightdiff != 0) params[index++] = heightdiff; |
2232 params[1] = heightdiff; |
2234 } |
2233 GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH_HEIGHTDIFF, 2, params); |
2235 |
2234 } |
2236 GuiShowTooltipsWithArgs(measure_strings_length[index], index, params); |
2235 } |
2237 } |
2236 |
2238 |
2237 thd->selend.x = x; |
2239 thd->selend.x = x; |
2238 thd->selend.y = y; |
2240 thd->selend.y = y; |
2239 thd->next_drawstyle = b; |
2241 thd->next_drawstyle = b; |
2292 calc_heightdiff_single_direction:; |
2294 calc_heightdiff_single_direction:; |
2293 if (_patches.measure_tooltip) { |
2295 if (_patches.measure_tooltip) { |
2294 TileIndex t0 = TileVirtXY(sx, sy); |
2296 TileIndex t0 = TileVirtXY(sx, sy); |
2295 TileIndex t1 = TileVirtXY(x, y); |
2297 TileIndex t1 = TileVirtXY(x, y); |
2296 uint distance = DistanceManhattan(t0, t1) + 1; |
2298 uint distance = DistanceManhattan(t0, t1) + 1; |
2297 /* With current code passing a HT_LINE style to calculate the height |
2299 byte index = 0; |
2298 * difference is enough. However if/when a point-tool is created |
|
2299 * with this method, function should be called with new_style (below) |
|
2300 * instead of HT_LINE | style case HT_POINT is handled specially |
|
2301 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */ |
|
2302 int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1); |
|
2303 uint params[2]; |
2300 uint params[2]; |
2304 |
2301 |
2305 params[0] = distance; |
2302 if (distance != 1) { |
2306 if (heightdiff == 0) { |
2303 /* With current code passing a HT_LINE style to calculate the height |
2307 GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH, 1, params); |
2304 * difference is enough. However if/when a point-tool is created |
2308 } else { |
2305 * with this method, function should be called with new_style (below) |
2309 params[1] = heightdiff; |
2306 * instead of HT_LINE | style case HT_POINT is handled specially |
2310 GuiShowTooltipsWithArgs(STR_MEASURE_LENGTH_HEIGHTDIFF, 2, params); |
2307 * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */ |
2311 } |
2308 int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1); |
|
2309 |
|
2310 params[index++] = distance; |
|
2311 if (heightdiff != 0) params[index++] = heightdiff; |
|
2312 } |
|
2313 |
|
2314 GuiShowTooltipsWithArgs(measure_strings_length[index], index, params); |
2312 } break; |
2315 } break; |
2313 |
2316 |
2314 case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */ |
2317 case VPM_X_AND_Y_LIMITED: { /* drag an X by Y constrained rect area */ |
2315 int limit = (_thd.sizelimit - 1) * TILE_SIZE; |
2318 int limit = (_thd.sizelimit - 1) * TILE_SIZE; |
2316 x = sx + clamp(x - sx, -limit, limit); |
2319 x = sx + clamp(x - sx, -limit, limit); |
2317 y = sy + clamp(y - sy, -limit, limit); |
2320 y = sy + clamp(y - sy, -limit, limit); |
2318 /* Fallthrough */ |
2321 /* Fallthrough */ |
2319 case VPM_X_AND_Y: { /* drag an X by Y area */ |
2322 case VPM_X_AND_Y: /* drag an X by Y area */ |
2320 if (_patches.measure_tooltip) { |
2323 if (_patches.measure_tooltip) { |
|
2324 static const StringID measure_strings_area[] = { |
|
2325 STR_NULL, STR_NULL, STR_MEASURE_AREA, STR_MEASURE_AREA_HEIGHTDIFF |
|
2326 }; |
|
2327 |
2321 TileIndex t0 = TileVirtXY(sx, sy); |
2328 TileIndex t0 = TileVirtXY(sx, sy); |
2322 TileIndex t1 = TileVirtXY(x, y); |
2329 TileIndex t1 = TileVirtXY(x, y); |
2323 uint dx = abs(TileX(t0) - TileX(t1)) + 1; |
2330 uint dx = abs(TileX(t0) - TileX(t1)) + 1; |
2324 uint dy = abs(TileY(t0) - TileY(t1)) + 1; |
2331 uint dy = abs(TileY(t0) - TileY(t1)) + 1; |
2325 int heightdiff; |
2332 byte index = 0; |
2326 uint params[3]; |
2333 uint params[3]; |
2327 |
2334 |
2328 /* If dragging an area (eg dynamite tool) and it is actually a single |
2335 /* If dragging an area (eg dynamite tool) and it is actually a single |
2329 * row/column, change the type to 'line' to get proper calculation for height */ |
2336 * row/column, change the type to 'line' to get proper calculation for height */ |
2330 style = _thd.next_drawstyle; |
2337 style = _thd.next_drawstyle; |
2334 } else if (dy == 1) { |
2341 } else if (dy == 1) { |
2335 style = HT_LINE | HT_DIR_X; |
2342 style = HT_LINE | HT_DIR_X; |
2336 } |
2343 } |
2337 } |
2344 } |
2338 |
2345 |
2339 heightdiff = CalcHeightdiff(style, 0, t0, t1); |
2346 if (dx != 1 || dy != 1) { |
2340 |
2347 int heightdiff = CalcHeightdiff(style, 0, t0, t1); |
2341 params[0] = dx; |
2348 |
2342 params[1] = dy; |
2349 params[index++] = dx; |
2343 if (heightdiff == 0) { |
2350 params[index++] = dy; |
2344 GuiShowTooltipsWithArgs(STR_MEASURE_AREA, 2, params); |
2351 if (heightdiff != 0) params[index++] = heightdiff; |
2345 } else { |
2352 } |
2346 params[2] = heightdiff; |
2353 |
2347 GuiShowTooltipsWithArgs(STR_MEASURE_AREA_HEIGHTDIFF, 3, params); |
2354 GuiShowTooltipsWithArgs(measure_strings_area[index], index, params); |
2348 } |
2355 } |
2349 } |
2356 break; |
2350 } break; |
|
2351 |
2357 |
2352 } |
2358 } |
2353 default: NOT_REACHED(); |
2359 default: NOT_REACHED(); |
2354 } |
2360 } |
2355 |
2361 |