-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4385 from matkoniecz/incline
Incline quest where mtb:scale:uphill=* is used
- Loading branch information
Showing
12 changed files
with
234 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...src/main/java/de/westnordost/streetcomplete/quests/incline_direction/AddBicycleIncline.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package de.westnordost.streetcomplete.quests.incline_direction | ||
|
||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.elementfilter.toElementFilterExpression | ||
import de.westnordost.streetcomplete.data.osm.geometry.ElementPolylinesGeometry | ||
import de.westnordost.streetcomplete.data.osm.mapdata.Element | ||
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry | ||
import de.westnordost.streetcomplete.data.osm.osmquests.OsmElementQuestType | ||
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.BICYCLIST | ||
import de.westnordost.streetcomplete.osm.Tags | ||
import de.westnordost.streetcomplete.util.math.measuredLength | ||
|
||
class AddBicycleIncline : OsmElementQuestType<InclineDirectionAnswer> { | ||
|
||
private val tagFilter by lazy { """ | ||
ways with mtb:scale:uphill | ||
and highway ~ footway|cycleway|path|bridleway|track | ||
and (!indoor or indoor = no) | ||
and area != yes | ||
and access !~ private|no | ||
and !incline | ||
""".toElementFilterExpression() } | ||
|
||
override val changesetComment = "Specify which way leads up (where mtb:scale:uphill is present)" | ||
override val wikiLink = "Key:incline" | ||
override val icon = R.drawable.ic_quest_bicycle_incline | ||
override val achievements = listOf(BICYCLIST) | ||
override val hasMarkersAtEnds = false | ||
|
||
override fun getApplicableElements(mapData: MapDataWithGeometry): Iterable<Element> { | ||
// sadly for very long ways shape may be complex and it may be confusing which answer should be given | ||
// once multiple quest markers are appearing it becomes completely unclear | ||
// see for example https://www.openstreetmap.org/way/437205914 | ||
return mapData | ||
.filter { element -> tagFilter.matches(element) } | ||
.filter { element -> | ||
val geometry = mapData.getGeometry(element.type, element.id) as? ElementPolylinesGeometry | ||
geometry?.polylines?.all { it.measuredLength() < 200 } == true | ||
} | ||
} | ||
|
||
override fun isApplicableTo(element: Element): Boolean? { | ||
// we don't want to show overly long things | ||
if (!tagFilter.matches(element)) return false | ||
return null | ||
} | ||
|
||
override fun getTitle(tags: Map<String, String>) = R.string.quest_bicycle_incline_title | ||
|
||
override fun createForm() = AddBicycleInclineForm() | ||
|
||
override fun applyAnswerTo(answer: InclineDirectionAnswer, tags: Tags, timestampEdited: Long) = | ||
answer.applyTo(tags) | ||
} |
49 changes: 49 additions & 0 deletions
49
...main/java/de/westnordost/streetcomplete/quests/incline_direction/AddBicycleInclineForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.westnordost.streetcomplete.quests.incline_direction | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AlertDialog | ||
import de.westnordost.streetcomplete.R | ||
import de.westnordost.streetcomplete.data.osm.geometry.ElementPolylinesGeometry | ||
import de.westnordost.streetcomplete.quests.AImageListQuestForm | ||
import de.westnordost.streetcomplete.quests.AnswerItem | ||
import de.westnordost.streetcomplete.util.math.getOrientationAtCenterLineInDegrees | ||
import kotlin.math.PI | ||
|
||
class AddBicycleInclineForm : AImageListQuestForm<RegularInclineDirection, InclineDirectionAnswer>() { | ||
override val otherAnswers = listOf( | ||
AnswerItem(R.string.quest_bicycle_incline_up_and_down) { confirmUpAndDown() } | ||
) | ||
|
||
override val items get() = | ||
RegularInclineDirection.values().map { it.asItem(requireContext(), wayRotation + mapRotation) } | ||
|
||
override val itemsPerRow = 2 | ||
|
||
private var mapRotation: Float = 0f | ||
private var wayRotation: Float = 0f | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
wayRotation = (geometry as ElementPolylinesGeometry).getOrientationAtCenterLineInDegrees() | ||
imageSelector.cellLayoutId = R.layout.cell_icon_select_with_label_below | ||
} | ||
|
||
override fun onMapOrientation(rotation: Float, tilt: Float) { | ||
mapRotation = (rotation * 180 / PI).toFloat() | ||
imageSelector.items = items | ||
} | ||
|
||
private fun confirmUpAndDown() { | ||
val ctx = context ?: return | ||
AlertDialog.Builder(ctx) | ||
.setTitle(R.string.quest_generic_confirmation_title) | ||
.setPositiveButton(R.string.quest_generic_confirmation_yes) { _, _ -> applyAnswer( | ||
UpdAndDownHopsAnswer) } | ||
.setNegativeButton(R.string.quest_generic_confirmation_no, null) | ||
.show() | ||
} | ||
|
||
override fun onClickOk(selectedItems: List<RegularInclineDirection>) { | ||
applyAnswer(RegularInclineDirectionAnswer(selectedItems.first())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ain/java/de/westnordost/streetcomplete/quests/incline_direction/InclineDirectionAnswer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.westnordost.streetcomplete.quests.incline_direction | ||
|
||
import de.westnordost.streetcomplete.osm.Tags | ||
|
||
sealed interface InclineDirectionAnswer | ||
class RegularInclineDirectionAnswer(val value: RegularInclineDirection) : InclineDirectionAnswer | ||
object UpdAndDownHopsAnswer : InclineDirectionAnswer | ||
|
||
enum class RegularInclineDirection { | ||
UP, UP_REVERSED | ||
} | ||
|
||
fun InclineDirectionAnswer.applyTo(tags: Tags) { | ||
tags["incline"] = when (this) { | ||
is RegularInclineDirectionAnswer -> when (this.value) { | ||
RegularInclineDirection.UP -> "up" | ||
RegularInclineDirection.UP_REVERSED -> "down" | ||
} | ||
is UpdAndDownHopsAnswer -> "up/down" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
app/src/main/java/de/westnordost/streetcomplete/quests/steps_incline/StepsIncline.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="128dp" | ||
android:height="128dp" | ||
android:viewportWidth="128" | ||
android:viewportHeight="128"> | ||
<path | ||
android:pathData="m128,64.06c0,33.42 -28.65,60.52 -64,60.52 -35.35,0 -64,-27.1 -64,-60.52s28.65,-60.52 64,-60.52c35.35,0 64,27.1 64,60.52" | ||
android:strokeWidth=".19449" | ||
android:fillColor="#529add"/> | ||
<path | ||
android:pathData="M30.26,104.11 L110.26,58.72" | ||
android:strokeAlpha="0.2" | ||
android:strokeWidth="7.7795" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000"/> | ||
<path | ||
android:pathData="M30.26,99.11 L110.26,53.72" | ||
android:strokeWidth="7.7795" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#ffffff"/> | ||
<path | ||
android:pathData="m67.26,60.07a10.14,10.14 0,0 0,13.85 3.71,10.14 10.14,0 0,0 3.71,-13.85 10.14,10.14 0,0 0,-13.85 -3.71,10.14 10.14,0 0,0 -3.71,13.85m-28.61,16.52a10.14,10.14 0,0 0,13.85 3.71,10.14 10.14,0 0,0 3.71,-13.85 10.14,10.14 0,0 0,-13.85 -3.71,10.14 10.14,0 0,0 -3.71,13.85m24.7,-32.29 l-3.32,19.88 -12.68,7.32 0.94,-18.51 15.06,-8.7m-16.89,5.52 l-3.87,2.22m17.44,12.14 l-13.57,-14.36m29.43,5.2 l-17.96,-15.86 -6.34,3.66" | ||
android:strokeAlpha="0.2" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="3" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="m67.28,55a10.14,10.14 0,0 0,13.85 3.71,10.14 10.14,0 0,0 3.71,-13.85 10.14,10.14 0,0 0,-13.85 -3.71,10.14 10.14,0 0,0 -3.71,13.85m-28.61,16.52a10.14,10.14 0,0 0,13.85 3.71,10.14 10.14,0 0,0 3.71,-13.85 10.14,10.14 0,0 0,-13.85 -3.71,10.14 10.14,0 0,0 -3.71,13.85m24.7,-32.29 l-3.32,19.88 -12.68,7.32 0.94,-18.51 15.06,-8.7m-16.89,5.52 l-3.87,2.22m17.44,12.14 l-13.57,-14.36m29.43,5.2 l-17.96,-15.86 -6.34,3.66" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="3" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#ffffff" | ||
android:strokeLineCap="round"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.