mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Convert to new unit APIs, remove old APIs.
There are probably plenty of raw ints around that never used the old conversion APIs, but we'll just need to fix those when we see them. Fixes https://github.com/Khopa/dcs_liberation/issues/558
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
from PySide2.QtCore import Qt
|
||||
from PySide2.QtWidgets import QLabel, QHBoxLayout, QGroupBox, QVBoxLayout, QFrame, QGridLayout
|
||||
from PySide2.QtGui import QPixmap
|
||||
|
||||
from game.weather import Conditions, TimeOfDay, Weather
|
||||
from game.utils import meter_to_nm, mps_to_knots
|
||||
from PySide2.QtWidgets import (
|
||||
QFrame,
|
||||
QGridLayout,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
QVBoxLayout,
|
||||
)
|
||||
from dcs.weather import Weather as PydcsWeather
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game.utils import mps
|
||||
from game.weather import Conditions, TimeOfDay
|
||||
|
||||
|
||||
class QTimeTurnWidget(QGroupBox):
|
||||
"""
|
||||
@@ -163,20 +169,20 @@ class QWeatherWidget(QGroupBox):
|
||||
def updateWinds(self):
|
||||
"""Updates the UI with the current conditions wind info.
|
||||
"""
|
||||
windGlSpeed = mps_to_knots(self.conditions.weather.wind.at_0m.speed or 0)
|
||||
windGlSpeed = mps(self.conditions.weather.wind.at_0m.speed or 0)
|
||||
windGlDir = str(self.conditions.weather.wind.at_0m.direction or 0).rjust(3, '0')
|
||||
self.windGLSpeedLabel.setText('{}kts'.format(windGlSpeed))
|
||||
self.windGLDirLabel.setText('{}º'.format(windGlDir))
|
||||
self.windGLSpeedLabel.setText(f'{int(windGlSpeed.knots)}kts')
|
||||
self.windGLDirLabel.setText(f'{windGlDir}º')
|
||||
|
||||
windFL08Speed = mps_to_knots(self.conditions.weather.wind.at_2000m.speed or 0)
|
||||
windFL08Speed = mps(self.conditions.weather.wind.at_2000m.speed or 0)
|
||||
windFL08Dir = str(self.conditions.weather.wind.at_2000m.direction or 0).rjust(3, '0')
|
||||
self.windFL08SpeedLabel.setText('{}kts'.format(windFL08Speed))
|
||||
self.windFL08DirLabel.setText('{}º'.format(windFL08Dir))
|
||||
self.windFL08SpeedLabel.setText(f'{int(windFL08Speed.knots)}kts')
|
||||
self.windFL08DirLabel.setText(f'{windFL08Dir}º')
|
||||
|
||||
windFL26Speed = mps_to_knots(self.conditions.weather.wind.at_8000m.speed or 0)
|
||||
windFL26Speed = mps(self.conditions.weather.wind.at_8000m.speed or 0)
|
||||
windFL26Dir = str(self.conditions.weather.wind.at_8000m.direction or 0).rjust(3, '0')
|
||||
self.windFL26SpeedLabel.setText('{}kts'.format(windFL26Speed))
|
||||
self.windFL26DirLabel.setText('{}º'.format(windFL26Dir))
|
||||
self.windFL26SpeedLabel.setText(f'{int(windFL26Speed.knots)}kts')
|
||||
self.windFL26DirLabel.setText(f'{windFL26Dir}º')
|
||||
|
||||
def updateForecast(self):
|
||||
"""Updates the Forecast Text and icon with the current conditions wind info.
|
||||
@@ -223,11 +229,10 @@ class QWeatherWidget(QGroupBox):
|
||||
if not fog:
|
||||
self.forecastFog.setText('No fog')
|
||||
else:
|
||||
visvibilityNm = round(meter_to_nm(fog.visibility), 1)
|
||||
self.forecastFog.setText('Fog vis: {}nm'.format(visvibilityNm))
|
||||
visibility = round(fog.visibility.nautical_miles, 1)
|
||||
self.forecastFog.setText(f'Fog vis: {visibility}nm')
|
||||
icon = [time, ('cloudy' if cloudDensity > 1 else None), 'fog']
|
||||
|
||||
|
||||
icon_key = "Weather_{}".format('-'.join(filter(None.__ne__, icon)))
|
||||
icon = CONST.ICONS.get(icon_key) or CONST.ICONS['Weather_night-partly-cloudy']
|
||||
self.weather_icon.setPixmap(icon)
|
||||
|
||||
@@ -5,8 +5,8 @@ import logging
|
||||
import math
|
||||
from typing import Iterable, Iterator, List, Optional, Tuple
|
||||
|
||||
from PySide2 import QtWidgets, QtCore
|
||||
from PySide2.QtCore import QPointF, Qt, QLineF, QRectF
|
||||
from PySide2 import QtCore, QtWidgets
|
||||
from PySide2.QtCore import QLineF, QPointF, QRectF, Qt
|
||||
from PySide2.QtGui import (
|
||||
QBrush,
|
||||
QColor,
|
||||
@@ -14,13 +14,15 @@ from PySide2.QtGui import (
|
||||
QPen,
|
||||
QPixmap,
|
||||
QPolygonF,
|
||||
QWheelEvent, )
|
||||
QWheelEvent,
|
||||
)
|
||||
from PySide2.QtWidgets import (
|
||||
QFrame,
|
||||
QGraphicsItem,
|
||||
QGraphicsOpacityEffect,
|
||||
QGraphicsScene,
|
||||
QGraphicsView, QGraphicsSceneMouseEvent,
|
||||
QGraphicsSceneMouseEvent,
|
||||
QGraphicsView,
|
||||
)
|
||||
from dcs import Point
|
||||
from dcs.mapping import point_from_heading
|
||||
@@ -32,7 +34,7 @@ from game.theater.conflicttheater import FrontLine, ReferencePoint
|
||||
from game.theater.theatergroundobject import (
|
||||
TheaterGroundObject,
|
||||
)
|
||||
from game.utils import meter_to_feet, nm_to_meter, meter_to_nm
|
||||
from game.utils import Distance, meters, nautical_miles
|
||||
from game.weather import TimeOfDay
|
||||
from gen import Conflict
|
||||
from gen.flights.flight import Flight, FlightWaypoint, FlightWaypointType
|
||||
@@ -45,7 +47,7 @@ from qt_ui.widgets.map.QMapControlPoint import QMapControlPoint
|
||||
from qt_ui.widgets.map.QMapGroundObject import QMapGroundObject
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
|
||||
MAX_SHIP_DISTANCE = 80
|
||||
MAX_SHIP_DISTANCE = nautical_miles(80)
|
||||
|
||||
def binomial(i: int, n: int) -> float:
|
||||
"""Binomial coefficient"""
|
||||
@@ -171,7 +173,7 @@ class QLiberationMap(QGraphicsView):
|
||||
self.game = game
|
||||
if self.game is not None:
|
||||
logging.debug("Reloading Map Canvas")
|
||||
self.nm_to_pixel_ratio = self.km_to_pixel(float(nm_to_meter(1)) / 1000.0)
|
||||
self.nm_to_pixel_ratio = self.distance_to_pixels(nautical_miles(1))
|
||||
self.reload_scene()
|
||||
|
||||
"""
|
||||
@@ -567,7 +569,7 @@ class QLiberationMap(QGraphicsView):
|
||||
BIG_LINE = 5
|
||||
SMALL_LINE = 2
|
||||
|
||||
dist = self.km_to_pixel(nm_to_meter(scale_distance_nm)/1000.0)
|
||||
dist = self.distance_to_pixels(nautical_miles(scale_distance_nm))
|
||||
self.scene().addRect(POS_X, POS_Y-PADDING, PADDING*2 + dist, BIG_LINE*2+3*PADDING, pen=CONST.COLORS["black"], brush=CONST.COLORS["black"])
|
||||
l = self.scene().addLine(POS_X + PADDING, POS_Y + BIG_LINE*2, POS_X + PADDING + dist, POS_Y + BIG_LINE*2)
|
||||
|
||||
@@ -663,12 +665,12 @@ class QLiberationMap(QGraphicsView):
|
||||
Point(offset.x / scale.x, offset.y / scale.y))
|
||||
return point_a.world_coordinates - scaled
|
||||
|
||||
def km_to_pixel(self, km):
|
||||
def distance_to_pixels(self, distance: Distance) -> int:
|
||||
p1 = Point(0, 0)
|
||||
p2 = Point(0, 1000*km)
|
||||
p2 = Point(0, distance.meters)
|
||||
p1a = Point(*self._transform_point(p1))
|
||||
p2a = Point(*self._transform_point(p2))
|
||||
return p1a.distance_to_point(p2a)
|
||||
return int(p1a.distance_to_point(p2a))
|
||||
|
||||
def highlight_color(self, transparent: Optional[bool] = False) -> QColor:
|
||||
return QColor(255, 255, 0, 20 if transparent else 255)
|
||||
@@ -820,7 +822,7 @@ class QLiberationMap(QGraphicsView):
|
||||
distance = self.selected_cp.control_point.position.distance_to_point(
|
||||
world_destination
|
||||
)
|
||||
if meter_to_nm(distance) > MAX_SHIP_DISTANCE:
|
||||
if meters(distance) > MAX_SHIP_DISTANCE:
|
||||
return False
|
||||
return self.game.theater.is_in_sea(world_destination)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from PySide2.QtCore import QItemSelectionModel, QPoint
|
||||
from PySide2.QtGui import QStandardItem, QStandardItemModel
|
||||
from PySide2.QtWidgets import QHeaderView, QTableView
|
||||
|
||||
from game.utils import meter_to_feet
|
||||
from gen.ato import Package
|
||||
from gen.flights.flight import Flight, FlightWaypoint, FlightWaypointType
|
||||
from qt_ui.windows.mission.flight.waypoints.QFlightWaypointItem import \
|
||||
|
||||
Reference in New Issue
Block a user