Skip to content

Commit

Permalink
refactor: revert to the previous version of map info in new UI
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 5edbeec7531d23d1682dca6863a2e40eed7844121e29d44d0252acf11b3a22f1
  • Loading branch information
thindil committed Jan 31, 2025
1 parent 0e237ca commit 69e8b2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/newsteamsky.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 27 additions & 23 deletions src/newui/mapsui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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])
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 69e8b2f

Please sign in to comment.