diff --git a/app/build.gradle b/app/build.gradle index f10723fb5..0c2b91906 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -82,8 +82,8 @@ android { defaultConfig { minSdkVersion 19 /*Dont change this unless you know why*/ targetSdkVersion 29 /*Dont change this unless you know why*/ - versionCode 69 - versionName "5.5.2" + versionCode 70 + versionName "5.5.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } diff --git a/app/src/main/java/com/kamron/pogoiv/GoIVSettings.java b/app/src/main/java/com/kamron/pogoiv/GoIVSettings.java index b2730cbaf..21703f619 100644 --- a/app/src/main/java/com/kamron/pogoiv/GoIVSettings.java +++ b/app/src/main/java/com/kamron/pogoiv/GoIVSettings.java @@ -62,7 +62,7 @@ public class GoIVSettings { public static final String DOWNLOADED_MOVESET_INFO = "downloaded_moveset_info_goiv"; // Increment this value when you want to make all users recalibrate GoIV - public static int LATEST_SCREEN_CALIBRATION_VERSION = 1; + public static int LATEST_SCREEN_CALIBRATION_VERSION = 2; private static GoIVSettings instance; @@ -106,6 +106,8 @@ public String getCalibrationValue(String valueName) { } public void saveScreenCalibrationResults(ScanFieldResults results) { + results.finalAdjustments(); + SharedPreferences.Editor editor = prefs.edit(); editor.putString(ScanFieldNames.POKEMON_NAME_AREA, results.pokemonNameArea.toString()); diff --git a/app/src/main/java/com/kamron/pogoiv/ScreenGrabber.java b/app/src/main/java/com/kamron/pogoiv/ScreenGrabber.java index 9a19a9d84..f96408a77 100644 --- a/app/src/main/java/com/kamron/pogoiv/ScreenGrabber.java +++ b/app/src/main/java/com/kamron/pogoiv/ScreenGrabber.java @@ -86,7 +86,7 @@ public void exit() { Bitmap grabScreen() { Image image = null; Bitmap bmp = null; - Integer retries = 60; // Retry for an entire second (given the rendering speed of 60fps) + int retries = 60; // Retry for an entire second (given the rendering speed of 60fps) while (retries > 0) { try { diff --git a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java index 8f14f820e..e9e05f3ff 100644 --- a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java +++ b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/OcrHelper.java @@ -1100,6 +1100,7 @@ public ScanData scanPokemon(@NonNull GoIVSettings settings, } ensureCorrectLevelArcSettings(settings, trainerLevel); //todo, make it so it doesnt initiate on every scan? int totalOffset = 0; + boolean is_lucky = false; double offsetBase; // offsets are calculated off height of powerup candy cost field. Double to retain precision // Since we only care about height, its fine that we don't know the proper offset yet ScanArea powerUpCandyArea = ScanArea.calibratedFromSettings(POKEMON_POWER_UP_CANDY_COST, settings); @@ -1132,6 +1133,7 @@ public ScanData scanPokemon(@NonNull GoIVSettings settings, if (hp.isPresent()) { // Found successfully; assume this is a lucky pokemon and offset all further scans below that line totalOffset += luckyOffset; + is_lucky = true; } } @@ -1197,7 +1199,7 @@ public ScanData scanPokemon(@NonNull GoIVSettings settings, .toString() + powerUpStardustCost.toString() + powerUpCandyCost.toString(); return new ScanData(estimatedLevelRange, name, type, candyNames, gender, hp, cp, candyAmount, evolutionCost, - powerUpStardustCost, powerUpCandyCost, null, null, (totalOffset != 0), uniqueIdentifier); + powerUpStardustCost, powerUpCandyCost, null, null, is_lucky, uniqueIdentifier); } /** diff --git a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldAutomaticLocator.java b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldAutomaticLocator.java index 96c340ede..dcc82fb31 100644 --- a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldAutomaticLocator.java +++ b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldAutomaticLocator.java @@ -33,6 +33,8 @@ import java.util.Iterator; import java.util.List; +import static java.lang.Math.abs; + /** * Created by johan on 2017-07-27. @@ -203,7 +205,7 @@ public ScanFieldAutomaticLocator(@NonNull Bitmap bmp, int displayWidth, float di } else if (r.width - maxRect.width > screenshotDensity) { // Take the largest maxRect = r; - } else if (Math.abs(r.width - maxRect.width) < screenshotDensity && r.y < maxRect.y) { + } else if (abs(r.width - maxRect.width) < screenshotDensity && r.y < maxRect.y) { // Take the upper with same width maxRect = r; } @@ -276,6 +278,7 @@ public ScanFieldResults scan(@NonNull Handler mainThreadHandler, @NonNull WeakRe String findingName = null; String findingType = null; String findingGender = null; + String findingStardustLabel = null; String findingCandyName = null; String findingHp = null; String findingCp = null; @@ -291,6 +294,7 @@ public ScanFieldResults scan(@NonNull Handler mainThreadHandler, @NonNull WeakRe findingName = context.getString(R.string.ocr_finding_name); findingType = context.getString(R.string.ocr_finding_type); findingGender = context.getString(R.string.ocr_finding_gender); + findingStardustLabel = "Finding STARDUST label"; findingCandyName = context.getString(R.string.ocr_finding_candy_name); findingHp = context.getString(R.string.ocr_finding_hp); findingCp = context.getString(R.string.ocr_finding_cp); @@ -314,8 +318,14 @@ public ScanFieldResults scan(@NonNull Handler mainThreadHandler, @NonNull WeakRe postMessage(mainThreadHandler, dialog.get(), findingGender); findPokemonGenderArea(results); + postMessage(mainThreadHandler, dialog.get(), findingCandyAmount); + findPokemonCandyAmountArea(results); + + postMessage(mainThreadHandler, dialog.get(), findingStardustLabel); + int stardustHeight = findStardustLabelHeight(results); + postMessage(mainThreadHandler, dialog.get(), findingCandyName); - findPokemonCandyNameArea(results); + findPokemonCandyNameArea(results, stardustHeight); postMessage(mainThreadHandler, dialog.get(), findingHp); findPokemonHPArea(results); @@ -323,17 +333,14 @@ public ScanFieldResults scan(@NonNull Handler mainThreadHandler, @NonNull WeakRe postMessage(mainThreadHandler, dialog.get(), findingCp); findPokemonCPScanArea(results); - postMessage(mainThreadHandler, dialog.get(), findingCandyAmount); - findPokemonCandyAmountArea(results); - postMessage(mainThreadHandler, dialog.get(), findingEvolutionCost); - findPokemonEvolutionCostArea(results); // Always call after findPokemonCandyAmountArea - - postMessage(mainThreadHandler, dialog.get(), findingPowerUpStardustCost); - findPokemonPowerUpStardustCostArea(results); // Always call after findPokemonCandyAmountArea + findPokemonEvolutionCostArea(results); postMessage(mainThreadHandler, dialog.get(), findingPowerUpCandyCost); - findPokemonPowerUpCandyCostArea(results); // Always call after findPokemonCandyAmountArea + findPokemonPowerUpCandyCostArea(results); // Always call after findPokemonEvolutionCostArea + + postMessage(mainThreadHandler, dialog.get(), findingPowerUpStardustCost); + findPokemonPowerUpStardustCostArea(results); // Always call after findPokemonEvolutionCostArea postMessage(mainThreadHandler, dialog.get(), findingLevelArc); findArcValues(results); @@ -524,11 +531,9 @@ private void findArcValues(ScanFieldResults results) { */ private void findPokemonEvolutionCostArea(ScanFieldResults results) { final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics - - //noinspection UnusedAssignment Canvas c = null; - //noinspection UnusedAssignment Paint p = null; + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -537,7 +542,7 @@ private void findPokemonEvolutionCostArea(ScanFieldResults results) { debugPrintRectList(boundingRectList, c, p); } - if (powerUpButton == null || results.pokemonCandyAmountArea == null) { + if (powerUpButton == null) { return; } @@ -545,14 +550,11 @@ private void findPokemonEvolutionCostArea(ScanFieldResults results) { // Keep only rect that are below the power up button and above the height of the evolution button .filter(ByMinY.of(powerUpButton.y + powerUpButton.height)) .filter(ByMaxY.of((int) (powerUpButton.y + powerUpButton.height * 2.5f))) - // Keep only bounding rect between the pokemonCandyAmountArea x coordinates - .filter(ByMinX.of(results.pokemonCandyAmountArea.xPoint)) - .filter(ByMaxX.of(results.pokemonCandyAmountArea.xPoint + results.pokemonCandyAmountArea.width)) + .filter(ByMinX.of(width50Percent)) .toList(); //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.RED); debugPrintRectList(candidates, c, p); } @@ -577,7 +579,6 @@ private void findPokemonEvolutionCostArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.YELLOW); debugPrintRectList(candidates, c, p); } @@ -589,7 +590,6 @@ private void findPokemonEvolutionCostArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.GREEN); debugPrintRectList(candidates, c, p); } @@ -623,11 +623,9 @@ private void findPokemonEvolutionCostArea(ScanFieldResults results) { */ private void findPokemonPowerUpStardustCostArea(ScanFieldResults results) { final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics - - //noinspection UnusedAssignment Canvas c = null; - //noinspection UnusedAssignment Paint p = null; + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -636,7 +634,7 @@ private void findPokemonPowerUpStardustCostArea(ScanFieldResults results) { debugPrintRectList(boundingRectList, c, p); } - if (powerUpButton == null || results.pokemonCandyAmountArea == null) { + if (powerUpButton == null || results.pokemonEvolutionCostArea == null) { return; } @@ -644,14 +642,13 @@ private void findPokemonPowerUpStardustCostArea(ScanFieldResults results) { // Keep only rect that are between the power up button Y coordinates .filter(ByMinY.of(powerUpButton.y)) .filter(ByMaxY.of(powerUpButton.y + powerUpButton.height)) - // Keep only bounding rect between half width and candy amount rect start + // Keep only bounding rect between half width and evolution cost rect start .filter(ByMinX.of(width50Percent)) - .filter(ByMaxX.of(results.pokemonCandyAmountArea.xPoint)) + .filter(ByMaxX.of(results.pokemonEvolutionCostArea.xPoint)) .toList(); //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.RED); debugPrintRectList(candidates, c, p); } @@ -665,7 +662,6 @@ private void findPokemonPowerUpStardustCostArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.YELLOW); debugPrintRectList(candidates, c, p); } @@ -677,7 +673,6 @@ private void findPokemonPowerUpStardustCostArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.GREEN); debugPrintRectList(candidates, c, p); } @@ -704,11 +699,9 @@ private void findPokemonPowerUpStardustCostArea(ScanFieldResults results) { */ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics - - //noinspection UnusedAssignment Canvas c = null; - //noinspection UnusedAssignment Paint p = null; + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -717,7 +710,7 @@ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { debugPrintRectList(boundingRectList, c, p); } - if (powerUpButton == null || results.pokemonCandyAmountArea == null) { + if (powerUpButton == null || results.pokemonEvolutionCostArea == null) { return; } @@ -726,13 +719,12 @@ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { .filter(ByMinY.of(powerUpButton.y)) .filter(ByMaxY.of(powerUpButton.y + powerUpButton.height)) // Keep only bounding rect between the candy amount area X coordinates - .filter(ByMinX.of(results.pokemonCandyAmountArea.xPoint)) - .filter(ByMaxX.of(results.pokemonCandyAmountArea.xPoint + results.pokemonCandyAmountArea.width)) + .filter(ByMinX.of(results.pokemonEvolutionCostArea.xPoint)) + .filter(ByMaxX.of(results.pokemonEvolutionCostArea.xPoint + results.pokemonEvolutionCostArea.width)) .toList(); //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.RED); debugPrintRectList(candidates, c, p); } @@ -746,7 +738,6 @@ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.YELLOW); debugPrintRectList(candidates, c, p); } @@ -758,7 +749,6 @@ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.GREEN); debugPrintRectList(candidates, c, p); } @@ -771,8 +761,8 @@ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { // Increase the width of 10% on the left result.x -= result.width * 0.1; - // Make it end exactly where Pokémon candy amount ends - result.width = (results.pokemonCandyAmountArea.xPoint + results.pokemonCandyAmountArea.width) - result.x; + // Make it end exactly where Pokémon evolution cost ends + result.width = (results.pokemonEvolutionCostArea.xPoint + results.pokemonEvolutionCostArea.width) - result.x; // Increase the height of 20% on top and 20% below result.y -= result.height * 0.2; @@ -787,11 +777,9 @@ private void findPokemonPowerUpCandyCostArea(ScanFieldResults results) { */ private void findPokemonCandyAmountArea(ScanFieldResults results) { final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics - - //noinspection UnusedAssignment Canvas c = null; - //noinspection UnusedAssignment Paint p = null; + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -820,19 +808,17 @@ private void findPokemonCandyAmountArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.RED); debugPrintRectList(candidates, c, p); } candidates = FluentIterable.from(candidates) - // Check if the dominant color of the contour matches the light green hue of PoGO text + // Check if the dominant color of the contour matches the dark green hue of PoGO text .filter(ByHsvColor.of(image, mask1, contours, boundingRectList, HSV_GREEN_DARK, 5, 0.275f, 0.275f)) .toList(); //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.YELLOW); debugPrintRectList(candidates, c, p); } @@ -844,7 +830,6 @@ private void findPokemonCandyAmountArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.GREEN); debugPrintRectList(candidates, c, p); } @@ -1018,15 +1003,101 @@ private void findPokemonHPArea(ScanFieldResults results) { } /** - * Find the area where the candy name (such as "eevee candy") is listed. + * Find the height of the STARDUST label (used fixing the candy name area height) */ - private void findPokemonCandyNameArea(ScanFieldResults results) { + private int findStardustLabelHeight(ScanFieldResults results) { final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics + Canvas c = null; + Paint p = null; - //noinspection UnusedAssignment + //noinspection PointlessBooleanExpression + if (BuildConfig.DEBUG && debugExecution) { + c = new Canvas(bmp); + p = getDebugPaint(); + p.setColor(Color.MAGENTA); + //debugPrintRectList(boundingRectList, c, p); + } + + if ( (greyHorizontalLine == null && results.pokemonCandyAmountArea == null) + || powerUpButton == null) { + return 0; + } + + int upperBound; + if (results.pokemonCandyAmountArea != null) { + upperBound = results.pokemonCandyAmountArea.yPoint + results.pokemonCandyAmountArea.height; + } else { + upperBound = greyHorizontalLine.y + greyHorizontalLine.height; + } + + //noinspection PointlessBooleanExpression + if (BuildConfig.DEBUG && debugExecution) { + c = new Canvas(bmp); + p = getDebugPaint(); + p.setColor(Color.BLUE); + debugPrintRectList(Collections.singletonList(greyHorizontalLine), c, p); + debugPrintRectList(Collections.singletonList(powerUpButton), c, p); + debugPrintLineVertical(width33Percent, c, p); + debugPrintLineVertical(greyHorizontalLine.x, c, p); + debugPrintLineHorizontal(upperBound, c, p); + debugPrintLineHorizontal(powerUpButton.y, c, p); + } + + List candidates = FluentIterable.from(boundingRectList) + // Keep only bounding rect between 50% of the image width, before the end of the horizontal grey + // divider line and below it and above the power up button + .filter(Predicates.and(ByMinX.of(greyHorizontalLine.x), + ByMaxX.of(width33Percent), + ByMinY.of(upperBound), + ByMaxY.of(powerUpButton.y))) + .toList(); + + //noinspection PointlessBooleanExpression + if (BuildConfig.DEBUG && debugExecution) { + p.setColor(Color.RED); + debugPrintRectList(candidates, c, p); + } + + candidates = FluentIterable.from(candidates) + // Check if the dominant color of the contour matches the light green hue of PoGO small text + .filter(ByHsvColor.of(image, mask1, contours, boundingRectList, HSV_GREEN_LIGHT, 5, 0.125f, 0.090f)) + .toList(); + + //noinspection PointlessBooleanExpression + if (BuildConfig.DEBUG && debugExecution) { + p.setColor(Color.YELLOW); + debugPrintRectList(candidates, c, p); + } + + candidates = FluentIterable.from(candidates) + // Remove the outliers + .filter(ByChauvenetCriterionOnBottomY.of(candidates)) + .toList(); + + //noinspection PointlessBooleanExpression + if (BuildConfig.DEBUG && debugExecution) { + p.setColor(Color.GREEN); + debugPrintRectList(candidates, c, p); + } + + if (candidates.size() == 0) { + return 0; + } + + Rect result = mergeRectList(candidates); + + // increase the height by 20% on each side (like candy name) + return result.height; + } + + /** + * Find the area where the candy name (such as "eevee candy") is listed. + */ + private void findPokemonCandyNameArea(ScanFieldResults results, int stardustHeight) { + final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics Canvas c = null; - //noinspection UnusedAssignment Paint p = null; + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -1035,10 +1106,18 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { debugPrintRectList(boundingRectList, c, p); } - if (greyHorizontalLine == null || powerUpButton == null) { + if ( (greyHorizontalLine == null && results.pokemonCandyAmountArea == null) + || powerUpButton == null) { return; } + int upperBound; + if (results.pokemonCandyAmountArea != null) { + upperBound = results.pokemonCandyAmountArea.yPoint + results.pokemonCandyAmountArea.height; + } else { + upperBound = greyHorizontalLine.y + greyHorizontalLine.height; + } + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -1048,7 +1127,7 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { debugPrintRectList(Collections.singletonList(powerUpButton), c, p); debugPrintLineVertical(width33Percent, c, p); debugPrintLineVertical(greyHorizontalLine.x + greyHorizontalLine.width, c, p); - debugPrintLineHorizontal(greyHorizontalLine.y + greyHorizontalLine.height, c, p); + debugPrintLineHorizontal(upperBound, c, p); debugPrintLineHorizontal(powerUpButton.y, c, p); } @@ -1057,13 +1136,12 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { // divider line and below it and above the power up button .filter(Predicates.and(ByMinX.of(width33Percent), ByMaxX.of(greyHorizontalLine.x + greyHorizontalLine.width), - ByMinY.of(greyHorizontalLine.y + greyHorizontalLine.height), + ByMinY.of(upperBound), ByMaxY.of(powerUpButton.y))) .toList(); //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.RED); debugPrintRectList(candidates, c, p); } @@ -1075,7 +1153,6 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.YELLOW); debugPrintRectList(candidates, c, p); } @@ -1087,7 +1164,6 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.GREEN); debugPrintRectList(candidates, c, p); } @@ -1107,9 +1183,16 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { result.width = width90Percent - result.x; } + // Using the height of the stardust label allows us to get a good calibration on wrapped text + if (stardustHeight > 0) { + if (abs(stardustHeight - result.height) > Math.min(stardustHeight, result.height) * 0.1) { + results.candyNameWrapped = true; + } + result.height = stardustHeight; + } // Increase the height of 20% on top and 20% below result.y -= result.height * 0.2; - result.height += result.height * 0.4; + result.height *= 1.4; results.candyNameArea = new ScanArea(result.x, result.y, result.width, result.height); } @@ -1119,11 +1202,9 @@ private void findPokemonCandyNameArea(ScanFieldResults results) { */ private void findPokemonTypeArea(ScanFieldResults results) { final boolean debugExecution = false; // Activate this flag to display the onscreen debug graphics - - //noinspection UnusedAssignment Canvas c = null; - //noinspection UnusedAssignment Paint p = null; + //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { c = new Canvas(bmp); @@ -1154,7 +1235,6 @@ private void findPokemonTypeArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.RED); debugPrintRectList(candidates, c, p); } @@ -1166,7 +1246,6 @@ private void findPokemonTypeArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.YELLOW); debugPrintRectList(candidates, c, p); } @@ -1178,7 +1257,6 @@ private void findPokemonTypeArea(ScanFieldResults results) { //noinspection PointlessBooleanExpression if (BuildConfig.DEBUG && debugExecution) { - //noinspection ConstantConditions p.setColor(Color.GREEN); debugPrintRectList(candidates, c, p); } @@ -1541,7 +1619,7 @@ public static ByWidth of(float targetWidth, float delta) { } @Override public boolean apply(@Nullable Rect input) { - return input != null && Math.abs(input.width - targetWidth) < delta; + return input != null && abs(input.width - targetWidth) < delta; } } @@ -1559,7 +1637,7 @@ public static ByHeight of(float targetHeight, float delta) { } @Override public boolean apply(@Nullable Rect input) { - return input != null && Math.abs(input.height - targetHeight) < delta; + return input != null && abs(input.height - targetHeight) < delta; } } @@ -1648,11 +1726,11 @@ public static ByHsvColor of(Mat image, Mat mask, List contours, List Imgproc.drawContours(mask, contours, contours.indexOf(contour), SCALAR_ON, -1); Scalar meanColor = Core.mean(image, mask); Color.RGBToHSV((int) meanColor.val[0], (int) meanColor.val[1], (int) meanColor.val[2], meanHsv); - if ((Math.abs(color[0] - meanHsv[0]) <= dH + if ((abs(color[0] - meanHsv[0]) <= dH || meanHsv[0] > 360 + color[0] - dH || meanHsv[0] < -color[0] + dH) - && Math.abs(color[1] - meanHsv[1]) <= dS - && Math.abs(color[2] - meanHsv[2]) <= dV) { + && abs(color[1] - meanHsv[1]) <= dS + && abs(color[2] - meanHsv[2]) <= dV) { return true; } } diff --git a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldResults.java b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldResults.java index 07404c3d3..b2a6414a8 100644 --- a/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldResults.java +++ b/app/src/main/java/com/kamron/pogoiv/pokeflycomponents/ocrhelper/ScanFieldResults.java @@ -11,16 +11,17 @@ public class ScanFieldResults { public ScanArea candyNameArea; public ScanArea pokemonHpArea; public ScanArea pokemonCpArea; - public ScanArea pokemonCandyAmountArea; - public ScanArea pokemonEvolutionCostArea; - public ScanArea pokemonPowerUpStardustCostArea; - public ScanArea pokemonPowerUpCandyCostArea; + public ScanArea pokemonCandyAmountArea = null; + public ScanArea pokemonEvolutionCostArea = null; + public ScanArea pokemonPowerUpStardustCostArea = null; + public ScanArea pokemonPowerUpCandyCostArea = null; public ScanPoint arcCenter; public Integer arcRadius; public ScanPoint infoScreenCardWhitePixelPoint; public @ColorInt Integer infoScreenCardWhitePixelColor; public ScanPoint infoScreenFabGreenPixelPoint; public @ColorInt Integer infoScreenFabGreenPixelColor; + public Boolean candyNameWrapped = false; public boolean isCompleteCalibration() { return pokemonNameArea != null @@ -41,4 +42,25 @@ public boolean isCompleteCalibration() { && infoScreenFabGreenPixelColor != null; } + /** + * Adjusts the relevant scan areas upwards if the calibration pokemon's candy text wrapped to a second line + */ + public void finalAdjustments() { + if (!candyNameWrapped) { + return; + } + // Same as in OcrHelper + int adj = (int) (candyNameArea.height * 0.8); + + if (pokemonPowerUpCandyCostArea != null) { + pokemonPowerUpCandyCostArea.yPoint -= adj; + } + if (pokemonPowerUpStardustCostArea != null) { + pokemonPowerUpStardustCostArea.yPoint -= adj; + } + if (pokemonEvolutionCostArea != null) { + pokemonEvolutionCostArea.yPoint -= adj; + } + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 933026eec..ddcb34a55 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -212,7 +212,7 @@ Unable to pick white marker pixel color\n Unable to locate green marker pixel\n Unable to pick green marker pixel color\n - \nATTENTION! Please verify that:\n① The info screen is scrolled all the way up\n② The 3D model doesn\'t cover any important information\n③ Is not a final evolution! I suggest a Caterpie!\n④ Is not lucky + \nATTENTION! Please verify that:\n① The info screen is scrolled all the way up\n② The 3D model doesn\'t cover any important information\n③ Is not a final evolution! I suggest a Caterpie!\n④ Is not lucky or shadow\n⑤ Doesn\'t have mega energy Calibration saved!\nRestart GoIV to apply the changes! Finding name area Finding type area