Performance improvement - tile taps and long-clicks are now done at the TileMapHolder level, meaning we can only create one instead of one per tile, massive memory saving!

Map now zooms with mouse scroll in Desktop!
This commit is contained in:
Yair Morgenstern
2019-11-16 23:02:09 +02:00
parent 70c9d989c6
commit 1ecc6bbb2a
11 changed files with 176 additions and 163 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 771 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 971 B

View File

@ -2496,27 +2496,27 @@ TileSets/FantasyHex/Tiles/Coast
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert
TileSets/FantasyHex/Tiles/Customs house
rotate: false
xy: 1656, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+City
TileSets/FantasyHex/Tiles/Desert
rotate: false
xy: 1690, 33
size: 32, 33
orig: 32, 33
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Customs house
rotate: false
xy: 1724, 38
xy: 1690, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+City
rotate: false
xy: 1724, 33
size: 32, 33
orig: 32, 33
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Farm
rotate: false
xy: 1758, 38
@ -2531,79 +2531,65 @@ TileSets/FantasyHex/Tiles/Desert+Flood plains
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Flood plains+Customs house
TileSets/FantasyHex/Tiles/Desert+Flood plains+Farm
rotate: false
xy: 1826, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Flood plains+Farm
TileSets/FantasyHex/Tiles/Desert+Flood plains+Trading post
rotate: false
xy: 1860, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Flood plains+Trading post
TileSets/FantasyHex/Tiles/Desert+Oasis
rotate: false
xy: 1894, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Oasis
TileSets/FantasyHex/Tiles/Desert+Trading post
rotate: false
xy: 1928, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Desert+Trading post
TileSets/FantasyHex/Tiles/Fishing Boats
rotate: false
xy: 1962, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Fishing Boats
rotate: false
xy: 1996, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Fort
rotate: false
xy: 2064, 30
xy: 2030, 30
size: 32, 33
orig: 32, 33
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Grassland
rotate: false
xy: 2424, 1212
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Grassland+Customs house
rotate: false
xy: 2424, 1182
xy: 488, 1052
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Grassland+Farm
rotate: false
xy: 2424, 1152
xy: 2424, 1212
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Grassland+Forest
rotate: false
xy: 2424, 1119
xy: 2424, 1179
size: 32, 31
orig: 32, 31
offset: 0, 0
@ -2624,7 +2610,7 @@ TileSets/FantasyHex/Tiles/Grassland+Jungle+Trading post
index: -1
TileSets/FantasyHex/Tiles/Grassland+Marsh
rotate: false
xy: 2424, 1088
xy: 2424, 1148
size: 32, 29
orig: 32, 29
offset: 0, 0
@ -2671,37 +2657,44 @@ TileSets/FantasyHex/Tiles/Hill+Quarry
orig: 32, 32
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Hill+Terrace Farm
rotate: false
xy: 2428, 841
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Lakes
rotate: false
xy: 2428, 581
xy: 2428, 635
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Landmark
rotate: false
xy: 2428, 491
xy: 2428, 545
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Manufactory
rotate: false
xy: 2428, 276
xy: 2428, 330
size: 32, 35
orig: 32, 35
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Mine
rotate: false
xy: 1690, 3
xy: 2428, 210
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Moai
rotate: false
xy: 1758, 8
xy: 1724, 3
size: 32, 28
orig: 32, 28
offset: 0, 0
@ -2715,14 +2708,14 @@ TileSets/FantasyHex/Tiles/Mountain
index: -1
TileSets/FantasyHex/Tiles/Ocean
rotate: false
xy: 1962, 8
xy: 1928, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Oil well
rotate: false
xy: 1996, 8
xy: 1962, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
@ -2748,170 +2741,149 @@ TileSets/FantasyHex/Tiles/Plains+City
orig: 32, 35
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plains+Customs house
TileSets/FantasyHex/Tiles/Plains+Farm
rotate: false
xy: 878, 10
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plains+Farm
rotate: false
xy: 912, 10
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plains+Forest
rotate: false
xy: 2098, 2
xy: 2064, 2
size: 32, 33
orig: 32, 33
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plains+Jungle
rotate: false
xy: 946, 3
xy: 912, 3
size: 32, 35
orig: 32, 35
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plains+Jungle+Trading post
rotate: false
xy: 980, 3
xy: 946, 3
size: 32, 35
orig: 32, 35
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plains+Trading post
rotate: false
xy: 2132, 7
xy: 2098, 7
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Plantation
rotate: false
xy: 1014, 10
xy: 980, 10
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Polder
rotate: false
xy: 1048, 10
xy: 1014, 10
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Quarry
rotate: false
xy: 1082, 10
xy: 1048, 10
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/River-Bottom
rotate: false
xy: 1150, 8
xy: 1116, 8
size: 32, 30
orig: 32, 30
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/River-BottomLeft
rotate: false
xy: 1184, 2
xy: 1150, 8
size: 32, 30
orig: 32, 30
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/River-BottomRight
rotate: false
xy: 1218, 2
xy: 1184, 2
size: 32, 30
orig: 32, 30
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/River-Top
rotate: false
xy: 1252, 6
xy: 1218, 2
size: 32, 30
orig: 32, 30
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/River-TopLeft
rotate: false
xy: 1286, 6
xy: 2132, 3
size: 32, 30
orig: 32, 30
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/River-TopRight
rotate: false
xy: 1320, 6
xy: 1252, 6
size: 32, 30
orig: 32, 30
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Terrace Farm
rotate: false
xy: 2423, 1554
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra
rotate: false
xy: 2362, 176
xy: 2423, 1558
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra+Camp
rotate: false
xy: 2344, 146
xy: 2423, 1528
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra+City
rotate: false
xy: 2344, 109
xy: 2419, 1491
size: 32, 35
orig: 32, 35
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra+Customs house
rotate: false
xy: 2344, 79
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra+Forest
rotate: false
xy: 2344, 45
xy: 2419, 1457
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra+Forest+Camp
rotate: false
xy: 2344, 11
xy: 2344, 144
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
TileSets/FantasyHex/Tiles/Tundra+Trading post
rotate: false
xy: 2378, 146
xy: 2344, 114
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/TopBorder
rotate: false
xy: 2423, 1524
xy: 2423, 1646
size: 32, 28
orig: 32, 28
offset: 0, 0
@ -3079,35 +3051,35 @@ TileSets/FantasyHex/Units/Crossbowman
index: -1
TileSets/FantasyHex/Units/Foreign Legion
rotate: false
xy: 2030, 35
xy: 1996, 38
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Galleass
rotate: false
xy: 2098, 37
xy: 2064, 37
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Galley
rotate: false
xy: 2132, 37
xy: 2098, 37
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Gatling Gun
rotate: false
xy: 488, 1052
xy: 2132, 35
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Machine Gun
rotate: false
xy: 488, 1052
xy: 2132, 35
size: 32, 28
orig: 32, 28
offset: 0, 0
@ -3135,238 +3107,238 @@ TileSets/FantasyHex/Units/Worker
index: -1
TileSets/FantasyHex/Units/Great General
rotate: false
xy: 2424, 1058
xy: 2424, 1118
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Great Merchant
rotate: false
xy: 1588, 8
xy: 2424, 1088
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Settler
rotate: false
xy: 1588, 8
xy: 2424, 1088
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Great Scientist
rotate: false
xy: 1622, 8
xy: 2424, 1058
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Great War Infantry
rotate: false
xy: 1656, 8
xy: 1588, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Infantry
rotate: false
xy: 1656, 8
xy: 1588, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Hoplite
rotate: false
xy: 2428, 845
xy: 1622, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Horseman
rotate: false
xy: 2428, 815
xy: 2428, 811
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Hwach'a
rotate: false
xy: 2428, 785
xy: 1656, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Ironclad
rotate: false
xy: 2428, 757
xy: 1690, 10
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Jaguar
rotate: false
xy: 2428, 727
xy: 2428, 781
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Janissary
rotate: false
xy: 2428, 697
xy: 2428, 751
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Keshik
rotate: false
xy: 2428, 669
xy: 2428, 723
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Khan
rotate: false
xy: 2428, 641
xy: 2428, 695
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Knight
rotate: false
xy: 2428, 611
xy: 2428, 665
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Lancer
rotate: false
xy: 2428, 551
xy: 2428, 605
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/LandUnit
rotate: false
xy: 2428, 521
xy: 2428, 575
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Warrior
rotate: false
xy: 2428, 521
xy: 2428, 575
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Landship
rotate: false
xy: 2428, 461
xy: 2428, 515
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Landsknecht
rotate: false
xy: 2428, 431
xy: 2428, 485
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Legion
rotate: false
xy: 2428, 401
xy: 2428, 455
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Longbowman
rotate: false
xy: 2428, 371
xy: 2428, 425
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Longswordsman
rotate: false
xy: 2428, 341
xy: 2428, 395
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Mandekalu Cavalry
rotate: false
xy: 2428, 313
xy: 2428, 367
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Maori Warrior
rotate: false
xy: 2428, 246
xy: 2428, 300
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Marine
rotate: false
xy: 2428, 216
xy: 2428, 270
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Mechanized Infantry
rotate: false
xy: 2428, 186
xy: 2428, 240
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Minuteman
rotate: false
xy: 1724, 8
xy: 2428, 180
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Mohawk Warrior
rotate: false
xy: 1792, 8
xy: 1758, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Musketeer
rotate: false
xy: 1826, 8
xy: 1792, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Musketman
rotate: false
xy: 1860, 8
xy: 1826, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Naresuan's Elephant
rotate: false
xy: 1894, 10
xy: 1860, 10
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Norwegian Ski Infantry
rotate: false
xy: 1928, 8
xy: 1894, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Panzer
rotate: false
xy: 2030, 7
xy: 1996, 10
size: 32, 26
orig: 32, 26
offset: 0, 0
@ -3394,126 +3366,126 @@ TileSets/FantasyHex/Units/Pikeman
index: -1
TileSets/FantasyHex/Units/Rifleman
rotate: false
xy: 1116, 10
xy: 1082, 10
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Rocket Artillery
rotate: false
xy: 2423, 1824
xy: 1286, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Scout
rotate: false
xy: 2423, 1794
xy: 1320, 8
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Ship of the Line
rotate: false
xy: 2064, 2
xy: 2030, 2
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Sipahi
rotate: false
xy: 2423, 1766
xy: 2362, 178
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Slinger
rotate: false
xy: 2423, 1736
xy: 2423, 1824
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Spearman
rotate: false
xy: 2423, 1706
xy: 2423, 1794
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Submarine
rotate: false
xy: 2423, 1678
xy: 2423, 1766
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Swordsman
rotate: false
xy: 2423, 1648
xy: 2423, 1736
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Tank
rotate: false
xy: 2423, 1618
xy: 2423, 1706
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Tercio
rotate: false
xy: 2423, 1588
xy: 2423, 1676
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Trebuchet
rotate: false
xy: 2419, 1494
xy: 2423, 1616
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Trireme
rotate: false
xy: 2419, 1466
xy: 2423, 1588
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Turtle Ship
rotate: false
xy: 2378, 118
xy: 2344, 86
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/War Chariot
rotate: false
xy: 2378, 88
xy: 2344, 56
size: 32, 28
orig: 32, 28
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/War Elephant
rotate: false
xy: 2378, 60
xy: 2344, 28
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/WaterUnit
rotate: false
xy: 2378, 32
xy: 2378, 150
size: 32, 26
orig: 32, 26
offset: 0, 0
index: -1
TileSets/FantasyHex/Units/Work Boats
rotate: false
xy: 2378, 4
xy: 2378, 122
size: 32, 26
orig: 32, 26
offset: 0, 0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@ -56,5 +56,6 @@ class TileGroupMap<T: TileGroup>(val tileGroups:Collection<T>, padding:Float): G
// there are tiles "below the zero",
// so we zero out the starting position of the whole board so they will be displayed as well
setSize(topX - bottomX + padding*2, topY - bottomY + padding*2)
}
}

View File

@ -4,10 +4,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Interpolation
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.scenes.scene2d.InputEvent
import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.*
import com.badlogic.gdx.scenes.scene2d.actions.FloatAction
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.Table
@ -28,12 +25,21 @@ import com.unciv.ui.worldscreen.unit.UnitContextMenu
import kotlin.concurrent.thread
import kotlin.math.sqrt
class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap: TileMap) : ScrollPane(null) {
internal var selectedTile: TileInfo? = null
val tileGroups = HashMap<TileInfo, WorldTileGroup>()
var unitActionOverlay :Actor?=null
init{
// Remove the existing inputListener
// which defines that mouse scroll = vertical movement
val zoomListener = listeners.last { it is InputListener && it !in captureListeners }
removeListener (zoomListener)
}
// Used to transfer data on the "move here" button that should be created, from the side thread to the main thread
class MoveHereButtonDto(val unit: MapUnit, val tileInfo: TileInfo, val turnsToGetThere: Int)
@ -45,20 +51,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
val allTiles = TileGroupMap(daTileGroups,worldScreen.stage.width)
// Memory profiling reveals that creating an GestureDetector inside the ActorGestureListener
// for every tile is VERY memory-intensive
for(tileGroup in tileGroups.values){
tileGroup.addListener (object: ActorGestureListener() {
override fun tap(event: InputEvent?, x: Float, y: Float, count: Int, button: Int) {
onTileClicked(tileGroup.tileInfo)
}
override fun longPress(actor: Actor?, x: Float, y: Float): Boolean {
if(!worldScreen.isPlayersTurn) return false // no long click when it's not your turn
return onTileLongClicked(tileGroup.tileInfo)
}
})
tileGroup.cityButtonLayerGroup.onClick("") {
onTileClicked(tileGroup.tileInfo)
}
@ -69,11 +62,28 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
setSize(worldScreen.stage.width*2, worldScreen.stage.height*2)
setOrigin(width/2,height/2)
center(worldScreen.stage)
addZoomListener()
addGestureListener()
addListener(object :InputListener(){
override fun scrolled(event: InputEvent?, x: Float, y: Float, amount: Int): Boolean {
if(amount>0) zoom(scaleX*0.8f)
else zoom(scaleX/0.8f)
return false
}
})
layout() // Fit the scroll pane to the contents - otherwise, setScroll won't work!
}
private fun addZoomListener() {
fun zoom(zoomScale:Float){
if (zoomScale < 0.5f) return
setScale(zoomScale)
for (tilegroup in tileGroups.values.filter { it.cityButton != null })
tilegroup.cityButton!!.setScale(1 / zoomScale)
}
private fun addGestureListener() {
addListener(object : ActorGestureListener() {
var lastScale = 1f
var lastInitialDistance = 0f
@ -86,10 +96,40 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
lastScale = scaleX
}
val scale: Float = sqrt((distance / initialDistance).toDouble()).toFloat() * lastScale
if (scale < 0.5f) return
setScale(scale)
for (tilegroup in tileGroups.values.filter { it.cityButton != null })
tilegroup.cityButton!!.setScale(1 / scale)
zoom(scale)
}
// Memory profiling reveals that creating an GestureDetector inside the ActorGestureListener
// for every tile is VERY memory-intensive.
// Instead, we now create a single GestureListener, and in it check which tileGroup was hit.
fun toTileGroup(stageCoordinatesVector:Vector2): WorldTileGroup? {
for(tileGroup in tileGroups.values) {
val point = stageCoordinatesVector.cpy()
tileGroup.stageToLocalCoordinates(point)
val hit = tileGroup.hit(point.x, point.y, false)
if (hit != null) return tileGroup
}
return null
}
override fun tap(event: InputEvent, x: Float, y: Float, count: Int, button: Int) {
val tileGroup = toTileGroup(Vector2(event.stageX,event.stageY))
if(tileGroup!=null) onTileClicked(tileGroup.tileInfo)
}
override fun longPress(actor: Actor, x: Float, y: Float): Boolean {
if(!worldScreen.isPlayersTurn) return false // no long click when it's not your turn
// x and y are in local coordinates, so convert to stage coordinates
// (we're basically undoing what the ActorGestureListener did)
val coords = Vector2(x,y)
actor.localToStageCoordinates(coords)
val tileGroup = toTileGroup(coords)
if(tileGroup!=null)
return onTileLongClicked(tileGroup.tileInfo)
return false
}
})