From 69e8b2f3d0637d27fcf47b08cfb96a50a9e9e669 Mon Sep 17 00:00:00 2001 From: thindil Date: Fri, 31 Jan 2025 04:50:05 +0000 Subject: [PATCH] refactor: revert to the previous version of map info in new UI FossilOrigin-Name: 5edbeec7531d23d1682dca6863a2e40eed7844121e29d44d0252acf11b3a22f1 --- src/newsteamsky.nim | 4 ---- src/newui/mapsui.nim | 50 ++++++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/newsteamsky.nim b/src/newsteamsky.nim index 37d1933e5..a9efaaf4d 100644 --- a/src/newsteamsky.nim +++ b/src/newsteamsky.nim @@ -163,10 +163,6 @@ proc steamsky() {.raises: [], tags: [ReadIOEffect, RootEffect], contractual.} = if oldState != state or oldDialog != dialog: redraw = true - # Map info if needed - if state == map: - showMapInfo() - # Quit from the game if state == quitGame: break diff --git a/src/newui/mapsui.nim b/src/newui/mapsui.nim index 20dc0efa5..3ccef9070 100644 --- a/src/newui/mapsui.nim +++ b/src/newui/mapsui.nim @@ -414,30 +414,30 @@ proc showHeader(dialog: var GameDialog) {.raises: [], tags: [RootEffect], dialog = setError(message = "Can't create popup. Reason: " & getCurrentExceptionMsg()) - -var - mapX: MapXRange = 1 - mapY: MapYRange = 1 - theme: ThemeData - -proc showMapInfo*() {.raises: [ValueError], tags: [WriteIOEffect, TimeEffect, RootEffect], contractual.} = +proc showMapInfo(x: MapXRange; y: MapYRange; theme: ThemeData) {.raises: [ + NuklearException, ValueError], tags: [WriteIOEffect, TimeEffect, + RootEffect], contractual.} = ## Show the map cell info popup + ## + ## * x - the X coordinate of the map cell which info will be show + ## * y - the Y coordinate of the map cell which info will be show + ## * theme - the current game's theme nuklearSetDefaultFont(defaultFont = fonts[0], fontSize = gameSettings.interfaceFontSize + 10) - window(name = "MapInfo", flags = {windowNoScrollbar}, x = (windowWidth - 240), - y = 5, w = 230, h = 350): + popup(pType = dynamicPopup, title = "MapInfo", flags = {windowNoScrollbar}, + x = (windowWidth - 240), y = 5, w = 230, h = 350): layoutStatic(height = 25, cols = 4): row(width = 20): label(str = "X:") row(width = 80): - colorLabel(str = $mapX, color = theme.mapColors[11]) + colorLabel(str = $x, color = theme.mapColors[11]) row(width = 20): label(str = "Y:") row(width = 80): - colorLabel(str = $mapY, color = theme.mapColors[11]) - if playerShip.skyX != mapX or playerShip.skyY != mapY: + colorLabel(str = $y, color = theme.mapColors[11]) + if playerShip.skyX != x or playerShip.skyY != y: let - distance: Natural = countDistance(destinationX = mapX, destinationY = mapY) + distance: Natural = countDistance(destinationX = x, destinationY = y) travelValues: TravelArray = travelInfo(distance = distance) layoutStatic(height = 25, cols = 2): row(width = 80): @@ -456,8 +456,8 @@ proc showMapInfo*() {.raises: [ValueError], tags: [WriteIOEffect, TimeEffect, Ro label(str = "Approx fuel usage:") row(width = 70): colorLabel(str = $travelValues[2], color = theme.mapColors[11]) - if skyMap[mapX][mapY].baseIndex > 0: - let baseIndex: Positive = skyMap[mapX][mapY].baseIndex + if skyMap[x][y].baseIndex > 0: + let baseIndex: Positive = skyMap[x][y].baseIndex if skyBases[baseIndex].known: setLayoutRowDynamic(height = 25, cols = 1) colorLabel(str = "Base info:", color = theme.mapColors[12]) @@ -621,12 +621,13 @@ proc showMap*(state: var GameState; dialog: var GameDialog) {.raises: [], # draw map nuklearSetDefaultFont(defaultFont = fonts[1], fontSize = gameSettings.mapFontSize + 10) - theme = try: - themesList[gameSettings.interfaceTheme] - except: - dialog = setError(message = "Can't get the game's theme.") - return - let height: Positive = gameSettings.mapFontSize + 10 + let + theme: ThemeData = try: + themesList[gameSettings.interfaceTheme] + except: + dialog = setError(message = "Can't get the game's theme.") + return + height: Positive = gameSettings.mapFontSize + 10 rows = ((windowHeight - 35 - gameSettings.messagesPosition.float) / height.float).floor.Natural + 4 let colWidth: Positive = try: @@ -770,8 +771,11 @@ proc showMap*(state: var GameState; dialog: var GameDialog) {.raises: [], dialog = setError(message = "Can't set map color") return if isMouseHovering(rect = getWidgetBounds()): - mapX = x - mapY = y + try: + showMapInfo(x = x, y = y, theme = theme) + except: + dialog = setError(message = "Can't show the map info") + return labelButton(title = mapChar): echo "map pressed" restoreButtonStyle()