-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added feature to save unitType promotion. #12894
Merged
+113
−54
Merged
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9dd38f5
Settler settle best tile when not escort and dangerous Tiles instead …
Emandac ab36bac
Merge branch 'master' of https://github.com/Emandac/Unciv
Emandac 3a67ef7
Merge branch 'yairm210:master' into master
Emandac 919a082
Update WorkerAutomation.kt
Emandac ed21943
Update SpecificUnitAutomation.kt
Emandac b9a832a
Update WorkerAutomation.kt
Emandac 5edf4b7
Update SpecificUnitAutomation.kt
Emandac 545572f
Merge branch 'yairm210:master' into master
Emandac 904e5a8
Merge branch 'yairm210:master' into master
Emandac 938091f
Merge branch 'yairm210:master' into master
Emandac 6faa088
Merge branch 'master' of https://github.com/Emandac/Unciv
Emandac aaabab0
Now city states get mad when you steal their Lands
Emandac cb96cff
new version
Emandac e400964
change to getDiplomacyManagerOrMeet
Emandac 61f90fa
added text to template.properties and changed AlertPopup.kt
Emandac ff67bb7
Update template.properties
Emandac 467e725
with period at the end :b
Emandac aa532e9
add flag now
Emandac 5ee629f
Merge branch 'yairm210:master' into master
Emandac b300c51
Made Option to declare war when a city state is bullied unavailable
Emandac 342d56a
Merge branch 'yairm210:master' into master
Emandac 04f6be5
Merge branch 'yairm210:master' into master
Emandac 1623290
added option to change the Maximum Autosave turns stored
Emandac 4edcd24
remove print
Emandac 0d5295e
change letter
Emandac 1599dd2
should fix issue with building test
Emandac eab98f2
update with changes
Emandac bd60cc4
Merge branch 'yairm210:master' into master
Emandac 4fadce6
Added UniqueType.FoundPuppetCity
Emandac 9d0ac5f
Merge branch 'yairm210:master' into master
Emandac a7a2e75
Added save promotion
Emandac 48d4770
Merge branch 'master' of https://github.com/Emandac/Unciv
Emandac eb54ab4
Merge branch 'yairm210:master' into master
Emandac dc00ad5
Updated for PR
Emandac ef0bb39
Updated with requested changes
Emandac fe66e04
Removed unnecessary check
Emandac bb78c9e
updated PR
Emandac b02d9cb
Merge branch 'yairm210:master' into master
Emandac 74aa1ff
Update PromotionPickerScreen.kt to save promotion cells too
Emandac 547a393
change name and added !
Emandac 503fbe1
updated name of variable
Emandac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import com.unciv.models.ruleset.unit.Promotion | |
import com.unciv.models.translations.tr | ||
import com.unciv.ui.audio.SoundPlayer | ||
import com.unciv.ui.components.extensions.isEnabled | ||
import com.unciv.ui.components.extensions.toCheckBox | ||
import com.unciv.ui.components.extensions.toTextButton | ||
import com.unciv.ui.components.input.KeyCharAndCode | ||
import com.unciv.ui.components.input.KeyboardBinding | ||
|
@@ -64,6 +65,8 @@ class PromotionPickerScreen private constructor( | |
// Logic | ||
private val tree = PromotionTree(unit) | ||
|
||
// This if we should save the unit promotion or not. | ||
private var saveUnitTypePromotion = false | ||
|
||
init { | ||
closeButton.onActivation { | ||
|
@@ -77,6 +80,8 @@ class PromotionPickerScreen private constructor( | |
rightSideButton.setText("Pick promotion".tr()) | ||
rightSideButton.onClick(UncivSound.Silent) { | ||
acceptPromotion(selectedPromotion) | ||
|
||
checkSaveUnitTypePrormotion() | ||
} | ||
} else { | ||
rightSideButton.isVisible = false | ||
|
@@ -191,9 +196,29 @@ class PromotionPickerScreen private constructor( | |
} | ||
|
||
topTable.add(promotionsTable) | ||
saveUnitTypePromotionForCity() | ||
addConnectingLines(emptySet()) | ||
} | ||
|
||
|
||
// adds the checkBoxs to choice to save unit promotion. | ||
private fun saveUnitTypePromotionForCity() { | ||
val checkBoxSaveUnitPromotion = "Default promotions for [${unit.baseUnit.unitType}]".toCheckBox(saveUnitTypePromotion) {saveUnitTypePromotion = it} | ||
promotionsTable.add(checkBoxSaveUnitPromotion) | ||
} | ||
|
||
// going to reuse this bit of code 2 time so turn it into a funtion | ||
private fun checkSaveUnitTypePrormotion() { | ||
if (saveUnitTypePromotion) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverse the if checks, e.g. if (!save) return |
||
val unitCurrentCity = unit.currentTile.getCity() | ||
|
||
if (unitCurrentCity != null) { | ||
// If you are clicked the save unitType promotion, you want the next unitType to have the same promotion. | ||
unitCurrentCity.unitTypeToPromotion.put(unit.baseUnit.unitType,true) | ||
unitCurrentCity.cityUnitTypePromotions.put(unit.baseUnit.unitType,unit.promotions) | ||
} | ||
} | ||
} | ||
|
||
private fun getButton(tree: PromotionTree, node: PromotionTree.PromotionNode) : PromotionButton { | ||
val isPickable = canPromoteNow && | ||
(!node.pathIsAmbiguous || node.distanceToAdopted == 1) && | ||
|
@@ -221,6 +246,7 @@ class PromotionPickerScreen private constructor( | |
if (isPickable) | ||
button.onDoubleClick(UncivSound.Silent) { | ||
acceptPromotion(button) | ||
checkSaveUnitTypePrormotion() | ||
} | ||
|
||
return button | ||
|
@@ -352,7 +378,6 @@ class PromotionPickerScreen private constructor( | |
} | ||
|
||
override fun recreate() = recreate(closeOnPick) | ||
|
||
fun recreate(closeOnPick: Boolean): BaseScreen { | ||
val newScreen = PromotionPickerScreen(unit, closeOnPick, originalName, onChange) | ||
newScreen.setScrollY(scrollPane.scrollY) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, rename these :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a good name for this variable 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly are you saving here? unitType is the key, sure but the value isn't promotion, is it?
Similarly the bottom hashmap
Maps should almost always be named in such a way that you can understand what is being mapped to what - "unitTypeTo" is a great start, e.g. "unitTypeToShouldUseSavedPromotion" or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter is better, but "long and understandable" is better than "short but not understandable"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would 'unitTypeBuildWithSavedPromtion' be a good name ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the boolen is true build unit with save promotion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand - per city there are saved promotions per type, right?
And also you can decide to... Not use them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes like the player can build a unit without the saved promotion, like that with that unit they can change the save promotion to something else if needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this config will stick to all other units of this type?
By type do you mean like "archery" or like "archer"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes