From 065edf31e2d69caa3a477fd789d337f049e771df Mon Sep 17 00:00:00 2001 From: vijer Date: Mon, 21 Jun 2021 15:51:51 +0700 Subject: [PATCH 1/2] Create README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..20c7852 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# SubnauticaModSystem + +Change AutosortLockers to get all category and techtype information from json files. From 8bda51eac342afd20e7cb91cb9d2b146dcb4a630 Mon Sep 17 00:00:00 2001 From: Vijer Date: Mon, 21 Jun 2021 17:07:21 +0700 Subject: [PATCH 2/2] These are the changes I made to DaWraka's port of AutosortLockers to BZ. --- .../AutosortLockers/Assets/filters.json | 720 ---------- .../Assets/type_reference.json | 1206 ----------------- .../AutosortLockers/AutosortLocker.cs | 793 ++++++----- ...ckers.csproj => AutosortLockersSML.csproj} | 90 +- .../AutosortLockers/AutosortLockersSML.sln | 34 + .../AutosortLockers/AutosortTarget.cs | 244 +++- .../AutosortLockers/AutosortTypePicker.cs | 128 +- .../AutosortLockers/AutosorterCategories.cs | 552 +------- .../AutosortLockers/CanvasLink_Patch.cs | 43 + .../AutosortLockers/ColorPicker.cs | 17 +- .../AutosortLockers/ColorPickerButton.cs | 11 +- .../AutosortLockers/ColorPickerPageButton.cs | 10 +- .../AutosortLockers/ColorSetting.cs | 32 +- .../AutosortLockers/ColoredIconButton.cs | 33 +- SubnauticaModSystem/AutosortLockers/Config.cs | 35 +- .../AutosortLockers/ConfigureButton.cs | 6 +- .../AutosortLockers/CustomizeScreen.cs | 60 +- .../AutosortLockers/FilterPickerButton.cs | 142 ++ .../AutosortLockers/GetLists.cs | 72 + .../AutosortLockers/LabelController.cs | 36 +- SubnauticaModSystem/AutosortLockers/Mod.cs | 38 +- SubnauticaModSystem/AutosortLockers/Picker.cs | 98 +- .../AutosortLockers/PickerPageButton.cs | 10 +- .../AutosortLockers/SaveData.cs | 4 +- SubnauticaModSystem/Common/Mod/ImageUtils.cs | 2 +- .../Common/Mod/LockerPrefabShared.cs | 70 +- SubnauticaModSystem/Common/Mod/ModUtils.cs | 88 +- .../Common/Mod/SerializableColor.cs | 2 +- SubnauticaModSystem/GameDir.targets | 9 + 29 files changed, 1377 insertions(+), 3208 deletions(-) delete mode 100644 SubnauticaModSystem/AutosortLockers/Assets/filters.json delete mode 100644 SubnauticaModSystem/AutosortLockers/Assets/type_reference.json rename SubnauticaModSystem/AutosortLockers/{AutosortLockers.csproj => AutosortLockersSML.csproj} (58%) create mode 100644 SubnauticaModSystem/AutosortLockers/AutosortLockersSML.sln create mode 100644 SubnauticaModSystem/AutosortLockers/CanvasLink_Patch.cs create mode 100644 SubnauticaModSystem/AutosortLockers/FilterPickerButton.cs create mode 100644 SubnauticaModSystem/AutosortLockers/GetLists.cs create mode 100644 SubnauticaModSystem/GameDir.targets diff --git a/SubnauticaModSystem/AutosortLockers/Assets/filters.json b/SubnauticaModSystem/AutosortLockers/Assets/filters.json deleted file mode 100644 index 2b39b59..0000000 --- a/SubnauticaModSystem/AutosortLockers/Assets/filters.json +++ /dev/null @@ -1,720 +0,0 @@ -[ - { - "Category": "", - "Types": [ - 3021 - ] - }, - { - "Category": "", - "Types": [ - 34 - ] - }, - { - "Category": "", - "Types": [ - 59 - ] - }, - { - "Category": "", - "Types": [ - 3063 - ] - }, - { - "Category": "", - "Types": [ - 504 - ] - }, - { - "Category": "", - "Types": [ - 61 - ] - }, - { - "Category": "", - "Types": [ - 27 - ] - }, - { - "Category": "", - "Types": [ - 3034 - ] - }, - { - "Category": "", - "Types": [ - 35 - ] - }, - { - "Category": "", - "Types": [ - 44 - ] - }, - { - "Category": "", - "Types": [ - 7 - ] - }, - { - "Category": "", - "Types": [ - 32 - ] - }, - { - "Category": "", - "Types": [ - 3502 - ] - }, - { - "Category": "", - "Types": [ - 23 - ] - }, - { - "Category": "", - "Types": [ - 3035 - ] - }, - { - "Category": "", - "Types": [ - 65 - ] - }, - { - "Category": "", - "Types": [ - 36 - ] - }, - { - "Category": "", - "Types": [ - 42 - ] - }, - { - "Category": "", - "Types": [ - 3 - ] - }, - { - "Category": "", - "Types": [ - 4514 - ] - }, - { - "Category": "", - "Types": [ - 2530 - ] - }, - { - "Category": "", - "Types": [ - 3010 - ] - }, - { - "Category": "", - "Types": [ - 15 - ] - }, - { - "Category": "", - "Types": [ - 21 - ] - }, - { - "Category": "", - "Types": [ - 1547 - ] - }, - { - "Category": "", - "Types": [ - 53 - ] - }, - { - "Category": "", - "Types": [ - 4210 - ] - }, - { - "Category": "", - "Types": [ - 66 - ] - }, - { - "Category": "", - "Types": [ - 4209 - ] - }, - { - "Category": "", - "Types": [ - 68 - ] - }, - { - "Category": "", - "Types": [ - 8 - ] - }, - { - "Category": "", - "Types": [ - 40 - ] - }, - { - "Category": "", - "Types": [ - 62 - ] - }, - { - "Category": "", - "Types": [ - 54 - ] - }, - { - "Category": "", - "Types": [ - 2 - ] - }, - { - "Category": "", - "Types": [ - 69 - ] - }, - { - "Category": "", - "Types": [ - 41 - ] - }, - { - "Category": "", - "Types": [ - 56 - ] - }, - { - "Category": "", - "Types": [ - 43 - ] - }, - { - "Category": "", - "Types": [ - 1 - ] - }, - { - "Category": "", - "Types": [ - 64 - ] - }, - { - "Category": "", - "Types": [ - 52 - ] - }, - { - "Category": "", - "Types": [ - 9 - ] - }, - { - "Category": "", - "Types": [ - 17 - ] - }, - { - "Category": "", - "Types": [ - 28 - ] - }, - { - "Category": "", - "Types": [ - 3504 - ] - }, - { - "Category": "", - "Types": [ - 57 - ] - }, - { - "Category": "", - "Types": [ - 3501 - ] - }, - { - "Category": "", - "Types": [ - 16 - ] - }, - { - "Category": "", - "Types": [ - 30 - ] - }, - { - "Category": "", - "Types": [ - 63 - ] - }, - { - "Category": "", - "Types": [ - 33 - ] - }, - - { - "Category": "Food", - "Types": [ - 4506, - 4509, - 4510, - 4504, - 4503, - 4512, - 4507, - 4519, - 4518, - 4511, - 4502, - 4505, - 4508, - 4517, - 4604, - 4607, - 4608, - 4602, - 4601, - 4610, - 4605, - 4613, - 4612, - 4609, - 4600, - 4603, - 4606, - 4611, - 4513, - 4520, - 4521, - 4522, - 3506, - 3513, - 3516, - 3514 - ] - }, - { - "Category": "Water", - "Types": [ - 4516, - 4523, - 4501, - 4500, - 4515 - ] - }, - { - "Category": "Plants & Seeds", - "Types": [ - 3509, - 3520, - 3506, - 2529, - 2503, - 3531, - 3529, - 3525, - 3513, - 3524, - 3503, - 3516, - 3517, - 3527, - 3507, - 3530, - 3528, - 3511, - 3518, - 3540, - 3521, - 3512, - 3533, - 3523, - 3508, - 3514, - 3534, - 3535, - 3536, - 3532, - 3539, - 3526, - 3537, - 3522, - 3515, - 3541, - 3519, - 3538, - 3510 - ] - }, - { - "Category": "Metals", - "Types": [ - 7, - 21, - 8, - 40, - 54, - 2, - 69, - 28, - 16 - ] - }, - { - "Category": "Electronics", - "Types": [ - 34, - 44, - 32, - 65, - 64, - 33 - ] - }, - { - "Category": "Batteries", - "Types": [ - 504, - 43, - 4210, - 4209 - ] - }, - { - "Category": "Natural Materials", - "Types": [ - 2530, - 3502, - 3035, - 3021, - 3501, - 3034, - 35, - 9, - 3063, - 3504, - 3010 - ] - }, - { - "Category": "Synthetic Materials", - "Types": [ - 59, - 57, - 61, - 27, - 42, - 3, - 15, - 1547, - 53, - 62, - 56, - 66, - 17, - 30, - 41 - ] - }, - { - "Category": "Crystal Materials", - "Types": [ - 52, - 36, - 68, - 1, - 23, - 63 - ] - }, - { - "Category": "Fish", - "Types": [ - 2515, - 2510, - 2554, - 2513, - 2555, - 2507, - 2501, - 2531, - 2546, - 2516, - 2505, - 2504, - 2519, - 2520, - 2522, - 2534, - 2550, - 2539, - 2509, - 2523, - 2517, - 2502, - 2551, - 2535, - 2506, - 2518, - 2524, - 2545, - 2512, - 2538 - ] - }, - { - "Category": "Eggs", - "Types": [ - 1266, - 1267, - 1283, - 1281, - 1285, - 1269, - 1265, - 1263, - 1287, - 1262, - 1261, - 1259, - 1264, - 1268, - 1260, - 1258, - 1253, - 1252, - 1251, - 1255, - 1257, - 1254, - 1250, - 1256, - 1270, - 1271, - 1272, - 1273, - 1274, - 1275, - 1276, - 1277, - 1278, - 1279, - 1280, - 1281, - 1282, - 1283, - 1284, - 1285, - 1286, - 1287, - 1288, - 1289, - 1290 - ] - }, - { - "Category": "Tools", - "Types": [ - 513, - 508, - 509, - 527, - 800, - 517, - 528, - 524, - 754, - 507, - 758, - 801, - 505, - 761, - 762, - 515, - 526, - 757, - 807, - 523, - 751, - 759, - 755, - 750, - 1807 - ] - }, - { - "Category": "Equipment", - "Types": [ - 525, - 518, - 512, - 502, - 804, - 803, - 521, - 520, - 519, - 522, - 529, - 808, - 806, - 503, - 805 - ] - }, - { - "Category": "Mysterious Tablets", - "Types": [ - 4201, - 4202, - 4204 - ] - }, - { - "Category": "Scanner Room Upgrades", - "Types": [ - 2250, - 2251, - 5527 - ] - }, - { - "Category": "General Upgrades", - "Types": [ - 1501, - 1516, - 2105, - 2101, - 2103 - ] - }, - { - "Category": "Seamoth Upgrades", - "Types": [ - 2104, - 2100, - 2102, - 2110, - 2112, - 2113, - 2114, - 2109 - ] - }, - { - "Category": "PrawnSuit Upgrades", - "Types": [ - 2128, - 2129, - 2116, - 2121, - 2115, - 2120, - 2117, - 2122 - ] - }, - { - "Category": "Cyclops Upgrades", - "Types": [ - 1554, - 1555, - 1537, - 1538, - 1558, - 1553, - 1551, - 1552, - 1557 - ] - }, - { - "Category": "Torpedoes", - "Types": [ - 2119, - 2111 - ] - }, - { - "Category": "Alterra Stuff", - "Types": [ - 1816, - 1817, - 1818, - 1808, - 1814, - 1815, - 1809, - 1810, - 1811, - 1143, - 1823, - 6005, - 1824, - 1825, - 1826, - 1827 - ] - } -] \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/Assets/type_reference.json b/SubnauticaModSystem/AutosortLockers/Assets/type_reference.json deleted file mode 100644 index 9b2c805..0000000 --- a/SubnauticaModSystem/AutosortLockers/Assets/type_reference.json +++ /dev/null @@ -1,1206 +0,0 @@ -[ - { - "Name": "Quartz", - "Value": 1 - }, - { - "Name": "ScrapMetal", - "Value": 2 - }, - { - "Name": "FiberMesh", - "Value": 3 - }, - { - "Name": "Copper", - "Value": 7 - }, - { - "Name": "Lead", - "Value": 8 - }, - { - "Name": "Salt", - "Value": 9 - }, - { - "Name": "MercuryOre", - "Value": 12 - }, - { - "Name": "Glass", - "Value": 15 - }, - { - "Name": "Titanium", - "Value": 16 - }, - { - "Name": "Silicone", - "Value": 17 - }, - { - "Name": "Gold", - "Value": 21 - }, - { - "Name": "Magnesium", - "Value": 22 - }, - { - "Name": "Sulphur", - "Value": 23 - }, - { - "Name": "SandLoot", - "Value": 26 - }, - { - "Name": "Bleach", - "Value": 27 - }, - { - "Name": "Silver", - "Value": 28 - }, - { - "Name": "TitaniumIngot", - "Value": 30 - }, - { - "Name": "CopperWire", - "Value": 32 - }, - { - "Name": "WiringKit", - "Value": 33 - }, - { - "Name": "AdvancedWiringKit", - "Value": 34 - }, - { - "Name": "CrashPowder", - "Value": 35 - }, - { - "Name": "Diamond", - "Value": 36 - }, - { - "Name": "Lithium", - "Value": 40 - }, - { - "Name": "PlasteelIngot", - "Value": 41 - }, - { - "Name": "EnameledGlass", - "Value": 42 - }, - { - "Name": "PowerCell", - "Value": 43 - }, - { - "Name": "ComputerChip", - "Value": 44 - }, - { - "Name": "Uranium", - "Value": 51 - }, - { - "Name": "AluminumOxide", - "Value": 52 - }, - { - "Name": "HydrochloricAcid", - "Value": 53 - }, - { - "Name": "Magnetite", - "Value": 54 - }, - { - "Name": "Polyaniline", - "Value": 56 - }, - { - "Name": "AramidFibers", - "Value": 57 - }, - { - "Name": "Aerogel", - "Value": 59 - }, - { - "Name": "Benzene", - "Value": 61 - }, - { - "Name": "Lubricant", - "Value": 62 - }, - { - "Name": "UraniniteCrystal", - "Value": 63 - }, - { - "Name": "ReactorRod", - "Value": 64 - }, - { - "Name": "DepletedReactorRod", - "Value": 65 - }, - { - "Name": "PrecursorIonCrystal", - "Value": 66 - }, - { - "Name": "PrecursorIonCrystalMatrix", - "Value": 67 - }, - { - "Name": "Kyanite", - "Value": 68 - }, - { - "Name": "Nickel", - "Value": 69 - }, - { - "Name": "Fins", - "Value": 502 - }, - { - "Name": "Tank", - "Value": 503 - }, - { - "Name": "Battery", - "Value": 504 - }, - { - "Name": "Knife", - "Value": 505 - }, - { - "Name": "Flashlight", - "Value": 507 - }, - { - "Name": "Beacon", - "Value": 508 - }, - { - "Name": "Builder", - "Value": 509 - }, - { - "Name": "Compass", - "Value": 512 - }, - { - "Name": "AirBladder", - "Value": 513 - }, - { - "Name": "Terraformer", - "Value": 514 - }, - { - "Name": "Pipe", - "Value": 515 - }, - { - "Name": "Thermometer", - "Value": 516 - }, - { - "Name": "DiveReel", - "Value": 517 - }, - { - "Name": "Rebreather", - "Value": 518 - }, - { - "Name": "RadiationSuit", - "Value": 519 - }, - { - "Name": "RadiationHelmet", - "Value": 520 - }, - { - "Name": "RadiationGloves", - "Value": 521 - }, - { - "Name": "ReinforcedDiveSuit", - "Value": 522 - }, - { - "Name": "Scanner", - "Value": 523 - }, - { - "Name": "FireExtinguisher", - "Value": 524 - }, - { - "Name": "MapRoomHUDChip", - "Value": 525 - }, - { - "Name": "PipeSurfaceFloater", - "Value": 526 - }, - { - "Name": "CyclopsDecoy", - "Value": 527 - }, - { - "Name": "DoubleTank", - "Value": 528 - }, - { - "Name": "ReinforcedGloves", - "Value": 529 - }, - { - "Name": "Welder", - "Value": 750 - }, - { - "Name": "Seaglide", - "Value": 751 - }, - { - "Name": "Constructor", - "Value": 752 - }, - { - "Name": "Transfuser", - "Value": 753 - }, - { - "Name": "Flare", - "Value": 754 - }, - { - "Name": "StasisRifle", - "Value": 755 - }, - { - "Name": "PropulsionCannon", - "Value": 757 - }, - { - "Name": "Gravsphere", - "Value": 758 - }, - { - "Name": "SmallStorage", - "Value": 759 - }, - { - "Name": "LaserCutter", - "Value": 761 - }, - { - "Name": "LEDLight", - "Value": 762 - }, - { - "Name": "DiamondBlade", - "Value": 800 - }, - { - "Name": "HeatBlade", - "Value": 801 - }, - { - "Name": "LithiumIonBattery", - "Value": 802 - }, - { - "Name": "PlasteelTank", - "Value": 803 - }, - { - "Name": "HighCapacityTank", - "Value": 804 - }, - { - "Name": "UltraGlideFins", - "Value": 805 - }, - { - "Name": "SwimChargeFins", - "Value": 806 - }, - { - "Name": "RepulsionCannon", - "Value": 807 - }, - { - "Name": "Stillsuit", - "Value": 808 - }, - { - "Name": "StasisRifleFragment", - "Value": 1101 - }, - { - "Name": "ReinforceHullFragment", - "Value": 1105 - }, - { - "Name": "PropulsionCannonFragment", - "Value": 1107 - }, - { - "Name": "SeaglideFragment", - "Value": 1117 - }, - { - "Name": "SolarPanelFragment", - "Value": 1119 - }, - { - "Name": "PowerTransmitterFragment", - "Value": 1120 - }, - { - "Name": "SpecimenAnalyzerFragment", - "Value": 1130 - }, - { - "Name": "LEDLightFragment", - "Value": 1143 - }, - { - "Name": "SafeShallowsEgg", - "Value": 1250 - }, - { - "Name": "KelpForestEgg", - "Value": 1251 - }, - { - "Name": "GrassyPlateausEgg", - "Value": 1252 - }, - { - "Name": "GrandReefsEgg", - "Value": 1253 - }, - { - "Name": "MushroomForestEgg", - "Value": 1254 - }, - { - "Name": "KooshZoneEgg", - "Value": 1255 - }, - { - "Name": "TwistyBridgesEgg", - "Value": 1256 - }, - { - "Name": "LavaZoneEgg", - "Value": 1257 - }, - { - "Name": "StalkerEgg", - "Value": 1258 - }, - { - "Name": "ReefbackEgg", - "Value": 1259 - }, - { - "Name": "SpadefishEgg", - "Value": 1260 - }, - { - "Name": "RabbitrayEgg", - "Value": 1261 - }, - { - "Name": "MesmerEgg", - "Value": 1262 - }, - { - "Name": "JumperEgg", - "Value": 1263 - }, - { - "Name": "SandsharkEgg", - "Value": 1264 - }, - { - "Name": "JellyrayEgg", - "Value": 1265 - }, - { - "Name": "BonesharkEgg", - "Value": 1266 - }, - { - "Name": "CrabsnakeEgg", - "Value": 1267 - }, - { - "Name": "ShockerEgg", - "Value": 1268 - }, - { - "Name": "GasopodEgg", - "Value": 1269 - }, - { - "Name": "CrashEgg", - "Value": 1281 - }, - { - "Name": "CrabsquidEgg", - "Value": 1283 - }, - { - "Name": "CutefishEgg", - "Value": 1285 - }, - { - "Name": "LavaLizardEgg", - "Value": 1287 - }, - { - "Name": "HullReinforcementModule", - "Value": 1501 - }, - { - "Name": "PowerUpgradeModule", - "Value": 1516 - }, - { - "Name": "CyclopsHullModule1", - "Value": 1537 - }, - { - "Name": "CyclopsHullModule2", - "Value": 1538 - }, - { - "Name": "HatchingEnzymes", - "Value": 1547 - }, - { - "Name": "CyclopsShieldModule", - "Value": 1551 - }, - { - "Name": "CyclopsSonarModule", - "Value": 1552 - }, - { - "Name": "CyclopsSeamothRepairModule", - "Value": 1553 - }, - { - "Name": "CyclopsDecoyModule", - "Value": 1554 - }, - { - "Name": "CyclopsFireSuppressionModule", - "Value": 1555 - }, - { - "Name": "CyclopsThermalReactorModule", - "Value": 1557 - }, - { - "Name": "CyclopsHullModule3", - "Value": 1558 - }, - { - "Name": "LuggageBag", - "Value": 1807 - }, - { - "Name": "ArcadeGorgetoy", - "Value": 1808 - }, - { - "Name": "LabEquipment1", - "Value": 1809 - }, - { - "Name": "LabEquipment2", - "Value": 1810 - }, - { - "Name": "LabEquipment3", - "Value": 1811 - }, - { - "Name": "Cap1", - "Value": 1814 - }, - { - "Name": "Cap2", - "Value": 1815 - }, - { - "Name": "LabContainer", - "Value": 1816 - }, - { - "Name": "LabContainer2", - "Value": 1817 - }, - { - "Name": "LabContainer3", - "Value": 1818 - }, - { - "Name": "StarshipSouvenir", - "Value": 1823 - }, - { - "Name": "PosterAurora", - "Value": 1824 - }, - { - "Name": "PosterExoSuit1", - "Value": 1825 - }, - { - "Name": "PosterExoSuit2", - "Value": 1826 - }, - { - "Name": "PosterKitty", - "Value": 1827 - }, - { - "Name": "Signal", - "Value": 2005 - }, - { - "Name": "SeamothReinforcementModule", - "Value": 2100 - }, - { - "Name": "VehiclePowerUpgradeModule", - "Value": 2101 - }, - { - "Name": "SeamothSolarCharge", - "Value": 2102 - }, - { - "Name": "VehicleStorageModule", - "Value": 2103 - }, - { - "Name": "SeamothElectricalDefense", - "Value": 2104 - }, - { - "Name": "VehicleArmorPlating", - "Value": 2105 - }, - { - "Name": "SeamothTorpedoModule", - "Value": 2109 - }, - { - "Name": "SeamothSonarModule", - "Value": 2110 - }, - { - "Name": "WhirlpoolTorpedo", - "Value": 2111 - }, - { - "Name": "VehicleHullModule1", - "Value": 2112 - }, - { - "Name": "VehicleHullModule2", - "Value": 2113 - }, - { - "Name": "VehicleHullModule3", - "Value": 2114 - }, - { - "Name": "ExosuitJetUpgradeModule", - "Value": 2115 - }, - { - "Name": "ExosuitDrillArmModule", - "Value": 2116 - }, - { - "Name": "ExosuitThermalReactorModule", - "Value": 2117 - }, - { - "Name": "GasTorpedo", - "Value": 2119 - }, - { - "Name": "ExosuitPropulsionArmModule", - "Value": 2120 - }, - { - "Name": "ExosuitGrapplingArmModule", - "Value": 2121 - }, - { - "Name": "ExosuitTorpedoArmModule", - "Value": 2122 - }, - { - "Name": "ExosuitPropulsionArmFragment", - "Value": 2124 - }, - { - "Name": "ExosuitGrapplingArmFragment", - "Value": 2125 - }, - { - "Name": "ExosuitTorpedoArmFragment", - "Value": 2126 - }, - { - "Name": "ExoHullModule1", - "Value": 2128 - }, - { - "Name": "ExoHullModule2", - "Value": 2129 - }, - { - "Name": "MapRoomUpgradeScanRange", - "Value": 2250 - }, - { - "Name": "MapRoomUpgradeScanSpeed", - "Value": 2251 - }, - { - "Name": "HoleFish", - "Value": 2501 - }, - { - "Name": "CreepvineSeedCluster", - "Value": 2503 - }, - { - "Name": "Peeper", - "Value": 2504 - }, - { - "Name": "Oculus", - "Value": 2505 - }, - { - "Name": "GarryFish", - "Value": 2507 - }, - { - "Name": "Boomerang", - "Value": 2510 - }, - { - "Name": "Eyeye", - "Value": 2513 - }, - { - "Name": "Bladderfish", - "Value": 2515 - }, - { - "Name": "Hoverfish", - "Value": 2516 - }, - { - "Name": "Reginald", - "Value": 2519 - }, - { - "Name": "Spadefish", - "Value": 2520 - }, - { - "Name": "Floater", - "Value": 2522 - }, - { - "Name": "CreepvinePiece", - "Value": 2529 - }, - { - "Name": "GasPod", - "Value": 2530 - }, - { - "Name": "Hoopfish", - "Value": 2531 - }, - { - "Name": "Spinefish", - "Value": 2546 - }, - { - "Name": "LavaBoomerang", - "Value": 2554 - }, - { - "Name": "LavaEyeye", - "Value": 2555 - }, - { - "Name": "JellyPlant", - "Value": 3010 - }, - { - "Name": "AcidMushroom", - "Value": 3021 - }, - { - "Name": "BloodOil", - "Value": 3034 - }, - { - "Name": "WhiteMushroom", - "Value": 3035 - }, - { - "Name": "PinkMushroom", - "Value": 3039 - }, - { - "Name": "PurpleRattle", - "Value": 3040 - }, - { - "Name": "SeaTreaderPoop", - "Value": 3063 - }, - { - "Name": "JeweledDiskPiece", - "Value": 3501 - }, - { - "Name": "CoralChunk", - "Value": 3502 - }, - { - "Name": "KooshChunk", - "Value": 3503 - }, - { - "Name": "StalkerTooth", - "Value": 3504 - }, - { - "Name": "BulboTreePiece", - "Value": 3506 - }, - { - "Name": "OrangeMushroomSpore", - "Value": 3507 - }, - { - "Name": "PurpleVasePlantSeed", - "Value": 3508 - }, - { - "Name": "AcidMushroomSpore", - "Value": 3509 - }, - { - "Name": "WhiteMushroomSpore", - "Value": 3510 - }, - { - "Name": "PinkMushroomSpore", - "Value": 3511 - }, - { - "Name": "PurpleRattleSpore", - "Value": 3512 - }, - { - "Name": "HangingFruit", - "Value": 3513 - }, - { - "Name": "PurpleVegetable", - "Value": 3514 - }, - { - "Name": "SmallMelon", - "Value": 3515 - }, - { - "Name": "Melon", - "Value": 3516 - }, - { - "Name": "MelonSeed", - "Value": 3517 - }, - { - "Name": "PurpleBrainCoralPiece", - "Value": 3518 - }, - { - "Name": "SpikePlantSeed", - "Value": 3519 - }, - { - "Name": "BluePalmSeed", - "Value": 3520 - }, - { - "Name": "PurpleFanSeed", - "Value": 3521 - }, - { - "Name": "SmallFanSeed", - "Value": 3522 - }, - { - "Name": "PurpleTentacleSeed", - "Value": 3523 - }, - { - "Name": "JellyPlantSeed", - "Value": 3524 - }, - { - "Name": "GabeSFeatherSeed", - "Value": 3525 - }, - { - "Name": "SeaCrownSeed", - "Value": 3526 - }, - { - "Name": "MembrainTreeSeed", - "Value": 3527 - }, - { - "Name": "PinkFlowerSeed", - "Value": 3528 - }, - { - "Name": "FernPalmSeed", - "Value": 3529 - }, - { - "Name": "OrangePetalsPlantSeed", - "Value": 3530 - }, - { - "Name": "EyesPlantSeed", - "Value": 3531 - }, - { - "Name": "RedGreenTentacleSeed", - "Value": 3532 - }, - { - "Name": "PurpleStalkSeed", - "Value": 3533 - }, - { - "Name": "RedBasketPlantSeed", - "Value": 3534 - }, - { - "Name": "RedBushSeed", - "Value": 3535 - }, - { - "Name": "RedConePlantSeed", - "Value": 3536 - }, - { - "Name": "ShellGrassSeed", - "Value": 3537 - }, - { - "Name": "SpottedLeavesPlantSeed", - "Value": 3538 - }, - { - "Name": "RedRollPlantSeed", - "Value": 3539 - }, - { - "Name": "PurpleBranchesSeed", - "Value": 3540 - }, - { - "Name": "SnakeMushroomSpore", - "Value": 3541 - }, - { - "Name": "PrecursorKey_Red", - "Value": 4200 - }, - { - "Name": "PrecursorKey_Blue", - "Value": 4201 - }, - { - "Name": "PrecursorKey_Orange", - "Value": 4202 - }, - { - "Name": "PrecursorKey_White", - "Value": 4203 - }, - { - "Name": "PrecursorKey_Purple", - "Value": 4204 - }, - { - "Name": "PrecursorIonPowerCell", - "Value": 4209 - }, - { - "Name": "PrecursorIonBattery", - "Value": 4210 - }, - { - "Name": "FilteredWater", - "Value": 4500 - }, - { - "Name": "DisinfectedWater", - "Value": 4501 - }, - { - "Name": "CookedPeeper", - "Value": 4502 - }, - { - "Name": "CookedHoleFish", - "Value": 4503 - }, - { - "Name": "CookedGarryFish", - "Value": 4504 - }, - { - "Name": "CookedReginald", - "Value": 4505 - }, - { - "Name": "CookedBladderfish", - "Value": 4506 - }, - { - "Name": "CookedHoverfish", - "Value": 4507 - }, - { - "Name": "CookedSpadefish", - "Value": 4508 - }, - { - "Name": "CookedBoomerang", - "Value": 4509 - }, - { - "Name": "CookedEyeye", - "Value": 4510 - }, - { - "Name": "CookedOculus", - "Value": 4511 - }, - { - "Name": "CookedHoopfish", - "Value": 4512 - }, - { - "Name": "NutrientBlock", - "Value": 4513 - }, - { - "Name": "FirstAidKit", - "Value": 4514 - }, - { - "Name": "StillsuitWater", - "Value": 4515 - }, - { - "Name": "BigFilteredWater", - "Value": 4516 - }, - { - "Name": "CookedSpinefish", - "Value": 4517 - }, - { - "Name": "CookedLavaEyeye", - "Value": 4518 - }, - { - "Name": "CookedLavaBoomerang", - "Value": 4519 - }, - { - "Name": "Snack1", - "Value": 4520 - }, - { - "Name": "Snack2", - "Value": 4521 - }, - { - "Name": "Snack3", - "Value": 4522 - }, - { - "Name": "Coffee", - "Value": 4523 - }, - { - "Name": "CuredPeeper", - "Value": 4600 - }, - { - "Name": "CuredHoleFish", - "Value": 4601 - }, - { - "Name": "CuredGarryFish", - "Value": 4602 - }, - { - "Name": "CuredReginald", - "Value": 4603 - }, - { - "Name": "CuredBladderfish", - "Value": 4604 - }, - { - "Name": "CuredHoverfish", - "Value": 4605 - }, - { - "Name": "CuredSpadefish", - "Value": 4606 - }, - { - "Name": "CuredBoomerang", - "Value": 4607 - }, - { - "Name": "CuredEyeye", - "Value": 4608 - }, - { - "Name": "CuredOculus", - "Value": 4609 - }, - { - "Name": "CuredHoopfish", - "Value": 4610 - }, - { - "Name": "CuredSpinefish", - "Value": 4611 - }, - { - "Name": "CuredLavaEyeye", - "Value": 4612 - }, - { - "Name": "CuredLavaBoomerang", - "Value": 4613 - }, - { - "Name": "MapRoomCamera", - "Value": 5527 - }, - { - "Name": "Poster", - "Value": 6005 - }, - { - "Name": "BoneShark", - "Value": 2534 - }, - { - "Name": "CrabSquid", - "Value": 2550 - }, - { - "Name": "Crabsnake", - "Value": 2539 - }, - { - "Name": "Crash", - "Value": 2509 - }, - { - "Name": "Gasopod", - "Value": 2523 - }, - { - "Name": "Jellyray", - "Value": 2517 - }, - { - "Name": "Jumper", - "Value": 2502 - }, - { - "Name": "LavaLizard", - "Value": 2551 - }, - { - "Name": "Mesmer", - "Value": 2535 - }, - { - "Name": "RabbitRay", - "Value": 2506 - }, - { - "Name": "Reefback", - "Value": 2518 - }, - { - "Name": "Sandshark", - "Value": 2524 - }, - { - "Name": "Shocker", - "Value": 2545 - }, - { - "Name": "Stalker", - "Value": 2512 - }, - { - "Name": "Cutefish", - "Value": 2538 - } -] \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/AutosortLocker.cs b/SubnauticaModSystem/AutosortLockers/AutosortLocker.cs index c454801..6bfbb87 100644 --- a/SubnauticaModSystem/AutosortLockers/AutosortLocker.cs +++ b/SubnauticaModSystem/AutosortLockers/AutosortLocker.cs @@ -7,369 +7,436 @@ using SMLHelper.V2.Crafting; using UnityEngine; using UnityEngine.UI; +#if SUBNAUTICA +//using RecipeData = SMLHelper.V2.Crafting.RecipeData; +#elif BELOWZERO +using TMPro; +#endif namespace AutosortLockers { - public class AutosortLocker : MonoBehaviour - { - private static readonly Color MainColor = new Color(1, 0.2f, 0.2f); - private static readonly Color PulseColor = Color.white; - - private bool initialized; - private Constructable constructable; - private StorageContainer container; - private List singleItemTargets = new List(); - private List categoryTargets = new List(); - private List anyTargets = new List(); - - private int unsortableItems = 0; - - [SerializeField] - private Image background; - [SerializeField] - private Image icon; - [SerializeField] - private Text text; - [SerializeField] - private Text sortingText; - [SerializeField] - private bool isSorting; - [SerializeField] - private bool sortedItem; - - public bool IsSorting => isSorting; - - private void Awake() - { - constructable = GetComponent(); - container = GetComponent(); - container.hoverText = "Open autosorter"; - container.storageLabel = "Autosorter"; - } - - private void Update() - { - if (!initialized && constructable._constructed && transform.parent != null) - { - Initialize(); - } - - if (!initialized || !constructable._constructed) - { - return; - } - - UpdateText(); - } - - private void UpdateText() - { - string output = ""; - if (isSorting) - { - output = "Sorting..."; - } - else if (unsortableItems > 0) - { - output = "Unsorted Items: " + unsortableItems; - } - else - { - output = "Ready to Sort"; - } - - sortingText.text = output; - } - - private void Initialize() - { - background.gameObject.SetActive(true); - icon.gameObject.SetActive(true); - text.gameObject.SetActive(true); - sortingText.gameObject.SetActive(true); - - background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("LockerScreen.png")); - icon.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("Sorter.png")); - - initialized = true; - } - - private IEnumerator Start() - { - while (true) - { - yield return new WaitForSeconds(Mathf.Max(0, Mod.config.SortInterval - (unsortableItems / 60.0f))); - - yield return Sort(); - } - } - - private void AccumulateTargets() - { - singleItemTargets.Clear(); - categoryTargets.Clear(); - anyTargets.Clear(); - - SubRoot subRoot = gameObject.GetComponentInParent(); - if (subRoot == null) - { - return; - } - - var allTargets = subRoot.GetComponentsInChildren().ToList(); - foreach (var target in allTargets) - { - if (target.isActiveAndEnabled && target.CanAddItems()) - { - if (target.CanTakeAnyItem()) - { - anyTargets.Add(target); - } - else - { - if (target.HasItemFilters()) - { - singleItemTargets.Add(target); - } - if (target.HasCategoryFilters()) - { - categoryTargets.Add(target); - } - } - } - } - } - - private IEnumerator Sort() - { - sortedItem = false; - unsortableItems = container.container.count; - - if (!initialized || container.IsEmpty()) - { - isSorting = false; - yield break; - } - - AccumulateTargets(); - if (NoTargets()) - { - isSorting = false; - yield break; - } - - isSorting = true; - yield return SortFilteredTargets(false); - if (sortedItem) - { - yield break; - } - - yield return SortFilteredTargets(true); - if (sortedItem) - { - yield break; - } - - yield return SortAnyTargets(); - if (sortedItem) - { - yield break; - } - - isSorting = false; - } - - private bool NoTargets() - { - return singleItemTargets.Count <= 0 && categoryTargets.Count <= 0 && anyTargets.Count <= 0; - } - - private IEnumerator SortFilteredTargets(bool byCategory) - { - int callsToCanAddItem = 0; - const int CanAddItemCallThreshold = 10; - - foreach (AutosortTarget target in byCategory ? categoryTargets : singleItemTargets) - { - foreach (AutosorterFilter filter in target.GetCurrentFilters()) - { - if (filter.IsCategory() == byCategory) - { - foreach (var techType in filter.Types) - { - callsToCanAddItem++; - var items = container.container.GetItems(techType); - if (items != null && items.Count > 0 && target.CanAddItem(items[0].item)) - { - unsortableItems -= items.Count; - SortItem(items[0].item, target); - sortedItem = true; - yield break; - } - else if (callsToCanAddItem > CanAddItemCallThreshold) - { - callsToCanAddItem = 0; - yield return null; - } - } - } - } - } - } - - private IEnumerator SortAnyTargets() - { - int callsToCanAddItem = 0; - const int CanAddItemCallThreshold = 10; - foreach (var item in container.container.ToList()) - { - foreach (AutosortTarget target in anyTargets) - { - callsToCanAddItem++; - if (target.CanAddItem(item.item)) - { - SortItem(item.item, target); - unsortableItems--; - sortedItem = true; - yield break; - } - else if (callsToCanAddItem > CanAddItemCallThreshold) - { - callsToCanAddItem = 0; - yield return null; - } - } - } - } - - private void SortItem(Pickupable pickup, AutosortTarget target) - { - container.container.RemoveItem(pickup, true); - target.AddItem(pickup); - - StartCoroutine(PulseIcon()); - } - - public IEnumerator PulseIcon() - { - float t = 0; - float rate = 0.5f; - while (t < 1.0) - { - t += Time.deltaTime * rate; - icon.color = Color.Lerp(PulseColor, MainColor, t); - yield return null; - } - } - - private AutosortTarget FindTarget(Pickupable item) - { - foreach (AutosortTarget target in singleItemTargets) - { - if (target.CanAddItemByItemFilter(item)) - { - return target; - } - } - foreach (AutosortTarget target in categoryTargets) - { - if (target.CanAddItemByCategoryFilter(item)) - { - return target; - } - } - foreach (AutosortTarget target in anyTargets) - { - if (target.CanAddItem(item)) - { - return target; - } - } - return null; - } - - internal class AutosortLockerBuildable : Buildable - { - public AutosortLockerBuildable() - : base("Autosorter", - "Autosort Locker", - "Small, wall-mounted smart-locker that automatically transfers items into linked Autosort Receptacles.") - { - } - - public override TechGroup GroupForPDA => TechGroup.InteriorModules; - - public override TechCategory CategoryForPDA => TechCategory.InteriorModule; - - public override GameObject GetGameObject() - { - GameObject originalPrefab = CraftData.GetPrefabForTechType(TechType.SmallLocker); - GameObject prefab = GameObject.Instantiate(originalPrefab); - - var container = prefab.GetComponent(); - container.width = Mod.config.AutosorterWidth; - container.height = Mod.config.AutosorterHeight; - container.container.Resize(Mod.config.AutosorterWidth, Mod.config.AutosorterHeight); - - var meshRenderers = prefab.GetComponentsInChildren(); - foreach (var meshRenderer in meshRenderers) - { - meshRenderer.material.color = new Color(1, 0, 0); - } - - var prefabText = prefab.GetComponentInChildren(); - var label = prefab.FindChild("Label"); - DestroyImmediate(label); - - var autoSorter = prefab.AddComponent(); - - var canvas = LockerPrefabShared.CreateCanvas(prefab.transform); - autoSorter.background = LockerPrefabShared.CreateBackground(canvas.transform); - autoSorter.icon = LockerPrefabShared.CreateIcon(autoSorter.background.transform, MainColor, 40); - autoSorter.text = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, 0, 14, "Autosorter"); - - autoSorter.sortingText = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, -120, 12, "Sorting..."); - autoSorter.sortingText.alignment = TextAnchor.UpperCenter; - - autoSorter.background.gameObject.SetActive(false); - autoSorter.icon.gameObject.SetActive(false); - autoSorter.text.gameObject.SetActive(false); - autoSorter.sortingText.gameObject.SetActive(false); - - return prefab; - } - - protected override TechData GetBlueprintRecipe() - { - return new TechData - { - craftAmount = 1, - Ingredients = Mod.config.EasyBuild - ? new List - { - new Ingredient(TechType.Titanium, 2) - } - : new List - { - new Ingredient(TechType.Titanium, 2), - new Ingredient(TechType.ComputerChip, 1), - new Ingredient(TechType.AluminumOxide, 2) - } - }; - } - - protected override Atlas.Sprite GetItemSprite() - { - return SMLHelper.V2.Utility.ImageUtils.LoadSpriteFromFile(Mod.GetAssetPath("AutosortLocker.png")); - } - } - - /////////////////////////////////////////////////////////////////////////////////////////// - public static void AddBuildable() - { - var autosorter = new AutosortLockerBuildable(); - autosorter.Patch(); - } - } -} + public class AutosortLocker : MonoBehaviour + { + private static readonly Color MainColor = new Color(1, 0.2f, 0.2f); + private static readonly Color PulseColor = Color.white; + + private bool initialized; + private Constructable constructable; + private StorageContainer container; + private List singleItemTargets = new List(); + private List categoryTargets = new List(); + private List anyTargets = new List(); + + private int unsortableItems = 0; + + [SerializeField] + private Image background; + [SerializeField] + private Image icon; +#if SUBNAUTICA + [SerializeField] + private Text text; + [SerializeField] + private Text sortingText; +#elif BELOWZERO + [SerializeField] + private TextMeshProUGUI text; + [SerializeField] + private TextMeshProUGUI sortingText; +#endif + [SerializeField] + private bool isSorting; + [SerializeField] + private bool sortedItem; + + public bool IsSorting => isSorting; + + private void Awake() + { + constructable = GetComponent(); + container = GetComponent(); + container.hoverText = "Open Autosorter"; + container.storageLabel = "Autosorter"; + } + + private void Update() + { + if (!initialized && constructable._constructed && transform.parent != null) + { + Initialize(); + } + + if (!initialized || !constructable._constructed) + { + return; + } + + UpdateText(); + } + + private void UpdateText() + { + string output = ""; + if (isSorting) + { + output = "Sorting..."; + } + else if (unsortableItems > 0) + { + output = "Unsorted Items: " + unsortableItems; + } + else + { + output = "Ready to Sort"; + } + + sortingText.text = output; + } + + private void Initialize() + { + background.gameObject.SetActive(true); + icon.gameObject.SetActive(true); + text.gameObject.SetActive(true); + sortingText.gameObject.SetActive(true); + + background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("LockerScreen.png")); + icon.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("Sorter.png")); + + initialized = true; + } + + private IEnumerator Start() + { + while (true) + { + yield return new WaitForSeconds(Mathf.Max(0, Mod.config.SortInterval - (unsortableItems / 60.0f))); + + yield return Sort(); + } + } + + private void AccumulateTargets() + { + singleItemTargets.Clear(); + categoryTargets.Clear(); + anyTargets.Clear(); + + SubRoot subRoot = gameObject.GetComponentInParent(); + if (subRoot == null) + { + return; + } + + var allTargets = subRoot.GetComponentsInChildren().ToList(); + foreach (var target in allTargets) + { + if (target.isActiveAndEnabled && target.CanAddItems()) + { + if (target.CanTakeAnyItem()) + { + anyTargets.Add(target); + } + else + { + if (target.HasItemFilters()) + { + singleItemTargets.Add(target); + } + if (target.HasCategoryFilters()) + { + categoryTargets.Add(target); + } + } + } + } + } + + private IEnumerator Sort() + { + sortedItem = false; + unsortableItems = container.container.count; + + if (!initialized || container.IsEmpty()) + { + isSorting = false; + yield break; + } + + AccumulateTargets(); + if (NoTargets()) + { + isSorting = false; + yield break; + } + + isSorting = true; + yield return SortFilteredTargets(false); + if (sortedItem) + { + yield break; + } + + yield return SortFilteredTargets(true); + if (sortedItem) + { + yield break; + } + + yield return SortAnyTargets(); + if (sortedItem) + { + yield break; + } + isSorting = false; + } + + private bool NoTargets() + { + return singleItemTargets.Count <= 0 && categoryTargets.Count <= 0 && anyTargets.Count <= 0; + } + + private IEnumerator SortFilteredTargets(bool byCategory) + { + int callsToCanAddItem = 0; + const int CanAddItemCallThreshold = 10; + + foreach (AutosortTarget target in byCategory ? categoryTargets : singleItemTargets) + { + foreach (AutosorterFilter filter in target.GetCurrentFilters()) + { + if (filter.IsCategory() == byCategory) + { + foreach (var techType in filter.Types) + { + callsToCanAddItem++; + var items = container.container.GetItems(techType); + + if (items != null && items.Count > 0 && target.CanAddItem(items[0].item)) + { + unsortableItems -= items.Count; + SortItem(items[0].item, target); + sortedItem = true; + + yield break; + } + else if (callsToCanAddItem > CanAddItemCallThreshold) + { + callsToCanAddItem = 0; + yield return null; + } + } + } + } + } + } + + private IEnumerator SortAnyTargets() + { + int callsToCanAddItem = 0; + const int CanAddItemCallThreshold = 10; + foreach (var item in container.container.ToList()) + { + foreach (AutosortTarget target in anyTargets) + { + callsToCanAddItem++; + if (target.CanAddItem(item.item)) + { + SortItem(item.item, target); + unsortableItems--; + sortedItem = true; + yield break; + } + else if (callsToCanAddItem > CanAddItemCallThreshold) + { + callsToCanAddItem = 0; + yield return null; + } + } + } + } + + private void SortItem(Pickupable pickup, AutosortTarget target) + { + container.container.RemoveItem(pickup, true); + target.AddItem(pickup); + + StartCoroutine(PulseIcon()); + } + + public IEnumerator PulseIcon() + { + float t = 0; + float rate = 0.5f; + while (t < 1.0) + { + t += Time.deltaTime * rate; + icon.color = Color.Lerp(PulseColor, MainColor, t); + yield return null; + } + } + + private AutosortTarget FindTarget(Pickupable item) + { + foreach (AutosortTarget target in singleItemTargets) + { + if (target.CanAddItemByItemFilter(item)) + { + return target; + } + } + foreach (AutosortTarget target in categoryTargets) + { + if (target.CanAddItemByCategoryFilter(item)) + { + return target; + } + } + foreach (AutosortTarget target in anyTargets) + { + if (target.CanAddItem(item)) + { + return target; + } + } + return null; + } + + internal class AutosortLockerBuildable : Buildable + { + public AutosortLockerBuildable() + : base("Autosorter", + "Autosort Locker", + "Small, wall-mounted smart-locker that automatically transfers items into linked Autosort Receptacles.") + { + } + + public override TechGroup GroupForPDA => TechGroup.InteriorModules; + + public override TechCategory CategoryForPDA => TechCategory.InteriorModule; + +#if SUBNAUTICA + public override GameObject GetGameObject() + { + GameObject originalPrefab = CraftData.GetPrefabForTechType(TechType.SmallLocker); + GameObject prefab = GameObject.Instantiate(originalPrefab); + + var container = prefab.GetComponent(); + container.width = Mod.config.AutosorterWidth; + container.height = Mod.config.AutosorterHeight; + container.container.Resize(Mod.config.AutosorterWidth, Mod.config.AutosorterHeight); + + var meshRenderers = prefab.GetComponentsInChildren(); + foreach (var meshRenderer in meshRenderers) + { + meshRenderer.material.color = new Color(1, 0, 0); + } + + var prefabText = prefab.GetComponentInChildren(); + var label = prefab.FindChild("Label"); + DestroyImmediate(label); + + var autoSorter = prefab.AddComponent(); + + var canvas = LockerPrefabShared.CreateCanvas(prefab.transform); + autoSorter.background = LockerPrefabShared.CreateBackground(canvas.transform); + autoSorter.icon = LockerPrefabShared.CreateIcon(autoSorter.background.transform, MainColor, 40); + autoSorter.text = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, 0, 14, "Autosorter"); + + autoSorter.sortingText = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, -120, 12, "Sorting..."); + autoSorter.sortingText.alignment = TextAnchor.UpperCenter; + + autoSorter.background.gameObject.SetActive(false); + autoSorter.icon.gameObject.SetActive(false); + autoSorter.text.gameObject.SetActive(false); + autoSorter.sortingText.gameObject.SetActive(false); + + return prefab; + } +#endif + + public override IEnumerator GetGameObjectAsync(IOut gameObject) + { + CoroutineTask task = CraftData.GetPrefabForTechTypeAsync(TechType.SmallLocker); + yield return task; + + GameObject originalPrefab = task.GetResult(); + GameObject prefab = GameObject.Instantiate(originalPrefab); + + StorageContainer container = prefab.GetComponent(); + container.width = Mod.config.AutosorterWidth; + container.height = Mod.config.AutosorterHeight; + container.Resize(Mod.config.AutosorterWidth, Mod.config.AutosorterHeight); + var meshRenderers = prefab.GetComponentsInChildren(); + foreach (var meshRenderer in meshRenderers) + { + meshRenderer.material.color = new Color(1, 0, 0); + } + +#if SUBNAUTICA + var prefabText = prefab.GetComponentInChildren(); +#elif BELOWZERO + var prefabText = prefab.GetComponentInChildren(); +#endif + var label = prefab.FindChild("Label"); + DestroyImmediate(label); + + var autoSorter = prefab.AddComponent(); + + var canvas = LockerPrefabShared.CreateCanvas(prefab.transform); + autoSorter.background = LockerPrefabShared.CreateBackground(canvas.transform, autoSorter.name); + autoSorter.icon = LockerPrefabShared.CreateIcon(autoSorter.background.transform, MainColor, 40); + // The first number is the vertical position, the second number is the font + autoSorter.text = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, 0, 14, "Autosorter", "Autosorter"); + autoSorter.text.rectTransform.anchoredPosition += new Vector2(20, 0); + + autoSorter.sortingText = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, -120, 18, "Sorting...", "Autosorter"); +#if SUBNAUTICA + autoSorter.sortingText.alignment = TextAnchor.UpperCenter; +#elif BELOWZERO + autoSorter.sortingText.alignment = TextAlignmentOptions.Top; +#endif + + autoSorter.background.gameObject.SetActive(false); + autoSorter.icon.gameObject.SetActive(false); + autoSorter.text.gameObject.SetActive(false); + autoSorter.sortingText.gameObject.SetActive(false); + + gameObject.Set(prefab); + yield break; + } + + protected override RecipeData GetBlueprintRecipe() + { + return new RecipeData() + { + craftAmount = 1, + Ingredients = Mod.config.EasyBuild + ? new List + { + new Ingredient(TechType.Titanium, 2) + } + : new List + { + new Ingredient(TechType.Titanium, 2), + new Ingredient(TechType.ComputerChip, 1), + new Ingredient(TechType.AluminumOxide, 2) + } + }; + } + + protected override Sprite GetItemSprite() + { + return SMLHelper.V2.Utility.ImageUtils.LoadSpriteFromFile(Mod.GetAssetPath("AutosortLocker.png")); + } + } + + /*_____________________________________________________________________________________________________*/ + + public static void AddBuildable() + { + var autosorter = new AutosortLockerBuildable(); + autosorter.Patch(); + } + } +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/AutosortLockers.csproj b/SubnauticaModSystem/AutosortLockers/AutosortLockersSML.csproj similarity index 58% rename from SubnauticaModSystem/AutosortLockers/AutosortLockers.csproj rename to SubnauticaModSystem/AutosortLockers/AutosortLockersSML.csproj index 8c1c9af..0ab39f0 100644 --- a/SubnauticaModSystem/AutosortLockers/AutosortLockers.csproj +++ b/SubnauticaModSystem/AutosortLockers/AutosortLockersSML.csproj @@ -1,6 +1,7 @@  + Debug AnyCPU @@ -9,7 +10,8 @@ Properties AutosortLockers AutosortLockersSML - v4.0 + $(SolutionDir)$(AssemblyName)\$(Configuration)\ + v4.7.2 512 @@ -35,77 +37,103 @@ Always + + BZ;BELOWZERO + true + true + $(CommonDir)SubnauticaZero.Stable + SubnauticaZero_Data + SMLHelper_BZ + AnyCPU + 7.1 + prompt + false + + + SN1;SUBNAUTICA + true + true + $(CommonDir)Subnautica.Stable + Subnautica_Data + Modding Helper + AnyCPU + 7.1 + prompt + false + - - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\0Harmony-1.2.0.1.dll - False + + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\BepInEx\core\0Harmony.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Assembly-CSharp.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\Assembly-CSharp.dll False False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Assembly-CSharp-firstpass.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\Assembly-CSharp-firstpass.dll False False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\Newtonsoft.Json.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\Newtonsoft.Json.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\QModInstaller.dll + ..\..\..\SteamLibrary\steamapps\common\Subnautica\BepInEx\plugins\QModManager\QModInstaller.dll False - D:\SteamLibrary\steamapps\common\Subnautica\QMods\Modding Helper\SMLHelper.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\QMods\SMLHelper_BZ\SMLHelper.dll False + + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\Unity.TextMeshPro.dll + - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.CoreModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.CoreModule.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.InputLegacyModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.InputLegacyModule.dll False False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.Physics2DModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.Physics2DModule.dll False False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.PhysicsModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.PhysicsModule.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.TextCoreModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.TextCoreModule.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.TextRenderingModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.TextRenderingModule.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UI.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.UI.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UIElementsModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.UIElementsModule.dll False - D:\SteamLibrary\steamapps\common\Subnautica\Subnautica_Data\Managed\UnityEngine.UIModule.dll + ..\..\..\SteamLibrary\steamapps\common\SubnauticaZero\SubnauticaZero_Data\Managed\UnityEngine.UIModule.dll False @@ -114,6 +142,7 @@ + @@ -121,6 +150,7 @@ + @@ -130,7 +160,7 @@ - + True @@ -139,27 +169,21 @@ - - - PreserveNewest - - ResXFileCodeGenerator Resources.Designer.cs + Designer - + + + - xcopy $(TargetPath) D:\SteamLibrary\steamapps\common\Subnautica\QMods\$(ProjectName)\ /q /y -xcopy $(ProjectDir)mod.json D:\SteamLibrary\steamapps\common\Subnautica\QMods\$(ProjectName)\ /q /y -xcopy $(ProjectDir)Assets D:\SteamLibrary\steamapps\common\Subnautica\QMods\$(ProjectName)\Assets\ /q /y /i - -xcopy $(TargetPath) D:\EpicGames\Subnautica\QMods\$(ProjectName)\ /q /y -xcopy $(ProjectDir)mod.json D:\EpicGames\Subnautica\QMods\$(ProjectName)\ /q /y -xcopy $(ProjectDir)Assets D:\EpicGames\Subnautica\QMods\$(ProjectName)\Assets\ /q /y /i + If $(Configuration) == SN1 D:\Code\below_zero\copy_SN_dll.bat +If $(Configuration) == BZ D:\Code\below_zero\copy_BZ_dll.bat + \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/AutosortLockersSML.sln b/SubnauticaModSystem/AutosortLockers/AutosortLockersSML.sln new file mode 100644 index 0000000..5e0e693 --- /dev/null +++ b/SubnauticaModSystem/AutosortLockers/AutosortLockersSML.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31321.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutosortLockersSML", "AutosortLockersSML.csproj", "{6C883B28-31E6-4C26-B32B-BF5BE0D70190}" +EndProject +Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\Common\Common.projitems*{6c883b28-31e6-4c26-b32b-bf5be0d70190}*SharedItemsImports = 4 + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + BZ|Any CPU = BZ|Any CPU + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + SN1|Any CPU = SN1|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.BZ|Any CPU.ActiveCfg = BZ|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.BZ|Any CPU.Build.0 = BZ|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.Release|Any CPU.Build.0 = Release|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.SN1|Any CPU.ActiveCfg = SN1|Any CPU + {6C883B28-31E6-4C26-B32B-BF5BE0D70190}.SN1|Any CPU.Build.0 = SN1|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {225DA48E-099A-4A1B-93BB-50193BFA7900} + EndGlobalSection +EndGlobal diff --git a/SubnauticaModSystem/AutosortLockers/AutosortTarget.cs b/SubnauticaModSystem/AutosortLockers/AutosortTarget.cs index c311362..35cdd00 100644 --- a/SubnauticaModSystem/AutosortLockers/AutosortTarget.cs +++ b/SubnauticaModSystem/AutosortLockers/AutosortTarget.cs @@ -7,12 +7,19 @@ using SMLHelper.V2.Crafting; using UnityEngine; using UnityEngine.UI; +using UnityEngine.EventSystems; +using UWE; +#if SUBNAUTICA +using RecipeData = SMLHelper.V2.Crafting.RecipeData; +#elif BELOWZERO +using TMPro; +#endif namespace AutosortLockers { public class AutosortTarget : MonoBehaviour { - public const int MaxTypes = 7; + public const int MaxTypes = 10; public const float MaxDistance = 3; private bool initialized; @@ -23,8 +30,29 @@ public class AutosortTarget : MonoBehaviour private Coroutine plusCoroutine; private SaveDataEntry saveData; +#if SUBNAUTICA [SerializeField] private Text textPrefab; + [SerializeField] + private Text text; + [SerializeField] + private Text label; + [SerializeField] + private Text plus; + [SerializeField] + private Text quantityText; +#elif BELOWZERO + [SerializeField] + private TextMeshProUGUI textPrefab; + [SerializeField] + private TextMeshProUGUI text; + [SerializeField] + private TextMeshProUGUI label; + [SerializeField] + private TextMeshProUGUI plus; + [SerializeField] + private TextMeshProUGUI quantityText; +#endif [SerializeField] private Image background; [SerializeField] @@ -38,14 +66,6 @@ public class AutosortTarget : MonoBehaviour [SerializeField] private Image customizeButtonImage; [SerializeField] - private Text text; - [SerializeField] - private Text label; - [SerializeField] - private Text plus; - [SerializeField] - private Text quantityText; - [SerializeField] private List currentFilters = new List(); private void Awake() @@ -126,16 +146,50 @@ public void RemoveFilter(AutosorterFilter filter) private void UpdateText() { + int strLen = 17; + string lockerType = container.name; + if (lockerType == "AutosortTarget(Clone)") + { + strLen = 17; // Trim filter lables so they don't wrap on the lockers + } + else + { + strLen = 22; // Trim filter lables so they don't wrap on the lockers + } + if (text != null) { if (currentFilters == null || currentFilters.Count == 0) { text.text = "[Any]"; +#if SUBNAUTICA + text.alignment = TextAnchor.MiddleCenter; +#elif BELOWZERO + text.alignment = TextAlignmentOptions.Center; +#endif } else { - string filtersText = string.Join("\n", currentFilters.Select((f) => f.IsCategory() ? "[" + f.GetString() + "]" : f.GetString()).ToArray()); + string filtersText = string.Join("\n", currentFilters.Select((f) => f.IsCategory() ? "[" + (f.GetString().Length > strLen ? f.GetString().Substring(0, strLen) : f.GetString()) + "]" : f.GetString().Length > strLen ? f.GetString().Substring(0, strLen) : f.GetString()).ToArray()); + // Filter text displayed on the lockers text.text = filtersText; + + if (currentFilters.Count == 1) + { +#if SUBNAUTICA + text.alignment = TextAnchor.MiddleCenter; +#elif BELOWZERO + text.alignment = TextAlignmentOptions.Center; +#endif + } + else + { +#if SUBNAUTICA + text.alignment = TextAnchor.MiddleLeft; +#elif BELOWZERO + text.alignment = TextAlignmentOptions.Left; +#endif + } } } } @@ -370,10 +424,25 @@ private void Initialize() UpdateText(); + StartCoroutine("FinalSetup"); + initialized = true; + } + + internal bool bPrefabsLoaded = false; + internal GameObject lockerPrefab; + + private IEnumerator FinalSetup() + { + IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync("Submarine/Build/SmallLocker.prefab"); + yield return request; + request.TryGetPrefab(out GameObject prefab); + lockerPrefab = prefab; + bPrefabsLoaded = true; + CreatePicker(); CreateCustomizeScreen(); - initialized = true; + yield break; } private void InitializeFromSaveData() @@ -381,6 +450,7 @@ private void InitializeFromSaveData() Logger.Log("Object Initialize from Save Data"); label.text = saveData.Label; label.color = saveData.LabelColor.ToColor(); + DestroyImmediate(label); icon.color = saveData.IconColor.ToColor(); configureButtonImage.color = saveData.ButtonsColor.ToColor(); customizeButtonImage.color = saveData.ButtonsColor.ToColor(); @@ -421,7 +491,9 @@ private List GetNewVersion(List filterData) { Dictionary validItems = new Dictionary(); Dictionary validCategories = new Dictionary(); + var filterList = AutosorterList.GetFilters(); + foreach (var filter in filterList) { if (filter.IsCategory()) @@ -449,15 +521,6 @@ private List GetNewVersion(List filterData) newData.Add(filter); continue; } - - var newTypes = AutosorterList.GetOldFilter(filter.Category, out bool success, out string newCategory); - if (success) - { - newData.Add(new AutosorterFilter() { Category = newCategory, Types = newTypes }); - continue; - } - - newData.Add(filter); } return newData; } @@ -472,7 +535,7 @@ private void CreatePicker() private void CreateCustomizeScreen() { - customizeScreen = CustomizeScreen.Create(background.transform, saveData); + customizeScreen = CustomizeScreen.Create(background.transform, saveData, lockerPrefab); customizeScreen.onModified += InitializeFromSaveData; customizeScreen.Initialize(saveData); customizeScreen.gameObject.SetActive(false); @@ -518,15 +581,16 @@ public IEnumerator ShowPlus() private void UpdateQuantityText() { var count = container.container.count; - quantityText.text = count == 0 ? "empty" : count.ToString(); + + quantityText.text = count == 0 ? "Empty" : count.ToString(); } internal class AutosortTargetBuildable : Buildable { public AutosortTargetBuildable() : base("AutosortTarget", - "Autosort Receptacle", - "Wall locker linked to an Autosorter that receives sorted items.") + "Autosort Receptacle", + "Wall locker linked to an Autosorter that receives sorted items.") { } @@ -534,21 +598,26 @@ public AutosortTargetBuildable() public override TechCategory CategoryForPDA => TechCategory.InteriorModule; - public override GameObject GetGameObject() + public override IEnumerator GetGameObjectAsync(IOut gameObject) { - GameObject prefab = GetPrefab(TechType.SmallLocker); + TaskResult result = new TaskResult(); + yield return GetPrefabAsync(TechType.SmallLocker, result); + + GameObject basePrefab = result.Get(); + GameObject prefab = GameObject.Instantiate(basePrefab); StorageContainer container = prefab.GetComponent(); container.width = Mod.config.ReceptacleWidth; container.height = Mod.config.ReceptacleHeight; - container.container.Resize(Mod.config.ReceptacleWidth, Mod.config.ReceptacleHeight); + container.Resize(Mod.config.ReceptacleWidth, Mod.config.ReceptacleHeight); - return prefab; + gameObject.Set(prefab); + yield break; } - protected override TechData GetBlueprintRecipe() + protected override RecipeData GetBlueprintRecipe() { - return new TechData + return new RecipeData { craftAmount = 1, Ingredients = Mod.config.EasyBuild @@ -564,7 +633,7 @@ protected override TechData GetBlueprintRecipe() }; } - protected override Atlas.Sprite GetItemSprite() + protected override Sprite GetItemSprite() { return SMLHelper.V2.Utility.ImageUtils.LoadSpriteFromFile(Mod.GetAssetPath("AutosortTarget.png")); } @@ -574,8 +643,8 @@ internal class AutosortStandingTargetBuildable : Buildable { public AutosortStandingTargetBuildable() : base("AutosortTargetStanding", - "Standing Autosort Receptacle", - "Large locker linked to an Autosorter that receives sorted items.") + "Standing Autosort Receptacle", + "Large locker linked to an Autosorter that receives sorted items.") { } @@ -583,21 +652,25 @@ public AutosortStandingTargetBuildable() public override TechCategory CategoryForPDA => TechCategory.InteriorModule; - public override GameObject GetGameObject() + public override IEnumerator GetGameObjectAsync(IOut gameObject) { - var prefab = GetPrefab(TechType.Locker); + TaskResult result = new TaskResult(); + yield return GetPrefabAsync(TechType.Locker, result); + + GameObject basePrefab = result.Get(); + GameObject prefab = GameObject.Instantiate(basePrefab); - var container = prefab.GetComponent(); + StorageContainer container = prefab.GetComponent(); container.width = Mod.config.StandingReceptacleWidth; container.height = Mod.config.StandingReceptacleHeight; - container.container.Resize(Mod.config.StandingReceptacleWidth, Mod.config.StandingReceptacleHeight); - - return prefab; + container.Resize(Mod.config.StandingReceptacleWidth, Mod.config.StandingReceptacleHeight); + gameObject.Set(prefab); + yield break; } - protected override TechData GetBlueprintRecipe() + protected override RecipeData GetBlueprintRecipe() { - return new TechData + return new RecipeData { craftAmount = 1, Ingredients = Mod.config.EasyBuild @@ -615,13 +688,14 @@ protected override TechData GetBlueprintRecipe() }; } - protected override Atlas.Sprite GetItemSprite() + protected override Sprite GetItemSprite() { return SMLHelper.V2.Utility.ImageUtils.LoadSpriteFromFile(Mod.GetAssetPath("AutosortTargetStanding.png")); } } - /////////////////////////////////////////////////////////////////////////////////////////// + /*__________________________________________________________________________________________________________*/ + public static void AddBuildable() { var sorterTarget = new AutosortTargetBuildable(); @@ -631,9 +705,12 @@ public static void AddBuildable() sorterStandingTarget.Patch(); } - public static GameObject GetPrefab(TechType basePrefab) + public static IEnumerator GetPrefabAsync(TechType basePrefab, IOut gameObject) { - GameObject originalPrefab = CraftData.GetPrefabForTechType(basePrefab); + CoroutineTask task = CraftData.GetPrefabForTechTypeAsync(basePrefab); + yield return task; + + GameObject originalPrefab = task.GetResult(); GameObject prefab = GameObject.Instantiate(originalPrefab); var meshRenderers = prefab.GetComponentsInChildren(); @@ -644,40 +721,85 @@ public static GameObject GetPrefab(TechType basePrefab) var autosortTarget = prefab.AddComponent(); - var smallLockerPrefab = CraftData.GetPrefabForTechType(TechType.SmallLocker); + task = CraftData.GetPrefabForTechTypeAsync(TechType.SmallLocker); + yield return task; + var smallLockerPrefab = GameObject.Instantiate(task.GetResult()); + +#if SUBNAUTICA autosortTarget.textPrefab = GameObject.Instantiate(smallLockerPrefab.GetComponentInChildren()); +#elif BELOWZERO + autosortTarget.textPrefab = GameObject.Instantiate(smallLockerPrefab.GetComponentInChildren()); +#endif + // Destroys the lable on the small locker var label = prefab.FindChild("Label"); DestroyImmediate(label); + label = prefab.FindChild("Locker"); + DestroyImmediate(label); var canvas = LockerPrefabShared.CreateCanvas(prefab.transform); if (basePrefab == TechType.Locker) { - canvas.transform.localPosition = new Vector3(0, 1.1f, 0.25f); + // Positions the rectangle on the standing locker horz, vert, depth + canvas.transform.localPosition = new Vector3(0.04f, 1.0f, 0.25f); } - autosortTarget.background = LockerPrefabShared.CreateBackground(canvas.transform); - autosortTarget.icon = LockerPrefabShared.CreateIcon(autosortTarget.background.transform, autosortTarget.textPrefab.color, 70); - autosortTarget.text = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, -20, 12, "Any"); + autosortTarget.background = LockerPrefabShared.CreateBackground(canvas.transform, prefab.name); - autosortTarget.label = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, 100, 12, "Locker"); + int iconPos = 75; // The vertical pos of the icon at the top of the container + int textPos = 110; // The vertical pos of the "Locker" text at the top of the container + int buttonPos = -104; // The vertical positions of the color and customize buttons + int labelFont = 12; // The font for the label on the lockers + if (Mod.config.ShowLabel) + { // This is a cludge until I can find the placeholder + labelFont = 0; // Set to zero and the Locker text does not display + } + else + { + labelFont = 12; + } + + // Change the positions for the Standing Locker + if (prefab.name == "Locker(Clone)") + { + iconPos = 93; + textPos = 120; + buttonPos = -120; + } + + // Position the locker icon + autosortTarget.icon = LockerPrefabShared.CreateIcon(autosortTarget.background.transform, autosortTarget.textPrefab.color, iconPos); + // Position the Filter lables, the first number is the horizontal position, the second number is the font size. + autosortTarget.text = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, 0, 12, "[Any] - Doesn't display", prefab.name); + // Position the "Locker" text + autosortTarget.label = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, textPos, labelFont, "Locker - Doesn't display", prefab.name); autosortTarget.background.gameObject.SetActive(false); autosortTarget.icon.gameObject.SetActive(false); autosortTarget.text.gameObject.SetActive(false); + // The container filters ?? + autosortTarget.plus = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, 0, 12, "+ - Doesn't display", prefab.name); - autosortTarget.plus = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, 0, 30, "+"); + // Pos of the color picker autosortTarget.plus.color = new Color(autosortTarget.textPrefab.color.r, autosortTarget.textPrefab.color.g, autosortTarget.textPrefab.color.g, 0); - autosortTarget.plus.rectTransform.anchoredPosition += new Vector2(30, 70); - - autosortTarget.quantityText = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, 0, 10, "XX"); - autosortTarget.quantityText.rectTransform.anchoredPosition += new Vector2(-35, -104); - - autosortTarget.configureButton = ConfigureButton.Create(autosortTarget.background.transform, autosortTarget.textPrefab.color, 40); + // Pos of the item count on the locker + autosortTarget.quantityText = LockerPrefabShared.CreateText(autosortTarget.background.transform, autosortTarget.textPrefab, autosortTarget.textPrefab.color, 0, 12, "XX - Doesn't display", prefab.name); + // Pos the quantity text on the locker + if (prefab.name == "Locker(Clone)") + { + autosortTarget.quantityText.rectTransform.anchoredPosition += new Vector2(14, -210); + } + else + { + autosortTarget.quantityText.rectTransform.anchoredPosition += new Vector2(4, -198); + } + // Pos of the configure button on the locker + autosortTarget.configureButton = ConfigureButton.Create(autosortTarget.background.transform, autosortTarget.textPrefab.color, 45, buttonPos); autosortTarget.configureButtonImage = autosortTarget.configureButton.GetComponent(); - autosortTarget.customizeButton = ConfigureButton.Create(autosortTarget.background.transform, autosortTarget.textPrefab.color, 20); + // Pos of the customize button on the locker + autosortTarget.customizeButton = ConfigureButton.Create(autosortTarget.background.transform, autosortTarget.textPrefab.color, 20, buttonPos); autosortTarget.customizeButtonImage = autosortTarget.customizeButton.GetComponent(); - return prefab; + gameObject.Set(prefab); } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/AutosortTypePicker.cs b/SubnauticaModSystem/AutosortLockers/AutosortTypePicker.cs index 6c70d0d..2d3efc9 100644 --- a/SubnauticaModSystem/AutosortLockers/AutosortTypePicker.cs +++ b/SubnauticaModSystem/AutosortLockers/AutosortTypePicker.cs @@ -3,6 +3,9 @@ using System.Linq; using Common.Mod; using Common.Utility; +#if BELOWZERO +using TMPro; +#endif using UnityEngine; using UnityEngine.UI; @@ -20,25 +23,30 @@ private enum Mode { Categories, Items } [SerializeField] private AutosortTarget locker; [SerializeField] - private PickerButton[] currentList = new PickerButton[AutosortTarget.MaxTypes]; + private FilterPickerButton[] currentList = new FilterPickerButton[AutosortTarget.MaxTypes]; [SerializeField] - private PickerButton[] availableList = new PickerButton[AutosortTarget.MaxTypes]; + private FilterPickerButton[] availableList = new FilterPickerButton[AutosortTarget.MaxTypes]; [SerializeField] private Image background; [SerializeField] private Image[] underlines = new Image[2]; [SerializeField] private PickerCloseButton closeButton; +#if SUBNAUTICA [SerializeField] private Text pageText; +#elif BELOWZERO + [SerializeField] + private TextMeshProUGUI pageText; +#endif [SerializeField] private PickerPageButton prevPageButton; [SerializeField] private PickerPageButton nextPageButton; [SerializeField] - private PickerButton categoriesTabButton; + private FilterPickerButton categoriesTabButton; [SerializeField] - private PickerButton itemsTabButton; + private FilterPickerButton itemsTabButton; public void Initialize(AutosortTarget locker) { @@ -102,7 +110,6 @@ public void OnCurrentListItemClick(AutosorterFilter filter) { return; } - locker.RemoveFilter(filter); RefreshCurrentFilters(); } @@ -113,7 +120,6 @@ public void OnAvailableListItemClick(AutosorterFilter filter) { return; } - locker.AddFilter(filter); RefreshCurrentFilters(); } @@ -165,9 +171,14 @@ private void SetCurrentPage(int page) } } + public static AutosortTypePicker Create(Transform parent, +#if SUBNAUTICA + Text textPrefab +#elif BELOWZERO + TextMeshProUGUI textPrefab +#endif + ) - - public static AutosortTypePicker Create(Transform parent, Text textPrefab) { var picker = LockerPrefabShared.CreateCanvas(parent).gameObject.AddComponent(); picker.GetComponent().sortingLayerID = 0; @@ -175,43 +186,64 @@ public static AutosortTypePicker Create(Transform parent, Text textPrefab) var t = picker.transform; t.localEulerAngles = new Vector3(0, 180, 0); - t.localPosition = new Vector3(0, 0, 0.4f); + //t.localPosition = new Vector3(0, 0, 0.4f); - picker.background = LockerPrefabShared.CreateBackground(picker.transform); - picker.background.color = new Color(0, 0, 0, 1); - picker.background.type = Image.Type.Simple; - RectTransformExtensions.SetSize(picker.background.rectTransform, 240, 220); + picker.background = LockerPrefabShared.CreateBackground(picker.transform, picker.name); + //picker.background.color = new Color(0, 0, 0, 1); + //picker.background.type = Image.Type.Simple; + // Set the size of the Item Picker background - first number width, second height + RectTransformExtensions.SetSize(picker.background.rectTransform, 250, 295); + // Position the Item Picker on the locker + if (parent.name.Contains("Standing(Clone)")) + { + picker.background.rectTransform.anchoredPosition = new Vector2(0.2f, 0.0f); + } + else + { + picker.background.rectTransform.anchoredPosition = new Vector2(0.15f, 0.0f); + } + // Hoizontal spacing between items in the picker int spacing = 20; - int startY = 60; - int x = 55; - - picker.underlines[0] = CreateUnderline(picker.background.transform, x); - picker.underlines[1] = CreateUnderline(picker.background.transform, -x); - - var currentText = LockerPrefabShared.CreateText(picker.background.transform, textPrefab, Color.white, 90, 12, "Current"); - currentText.rectTransform.anchoredPosition = new Vector2(-x, 90); - - picker.categoriesTabButton = CreatePickerButton(picker.background.transform, x - 23 + 2, 90, textPrefab, picker.OnCategoriesButtonClick, 60); - picker.categoriesTabButton.Override("Categories", true); - - picker.itemsTabButton = CreatePickerButton(picker.background.transform, x + 30 + 2, 90, textPrefab, picker.OnItemsButtonClick, 38); - picker.itemsTabButton.Override("Items", false); - - picker.pageText = LockerPrefabShared.CreateText(picker.background.transform, textPrefab, Color.white, 90, 10, "1/X"); - picker.pageText.rectTransform.anchoredPosition = new Vector2(x, -80); - - picker.prevPageButton = AddPageButton(picker.background.transform, picker, -1, x - 20, -80); - picker.nextPageButton = AddPageButton(picker.background.transform, picker, +1, x + 20, -80); - + // Top position of the Item Picker list, but not the Item and Category buttons + int startY = 88; + // Offset from the center of Selected and Available Item columns in the picker + int centOff = 58; + // The horizontal offset of the Current Filters, Category, and Items + // and the Close and Page buttons + int horzOff = 120; + + picker.underlines[0] = CreateUnderline(picker.background.transform, centOff); + picker.underlines[1] = CreateUnderline(picker.background.transform, -centOff); + + // The first number is the vertical pos of the Item button, the second number is the font size + var currentText = LockerPrefabShared.CreateText(picker.background.transform, textPrefab, Color.white, horzOff, 12, "Current Filters", "Picker"); + // The vertical position of the "Current Filters" text in the picker is set by the second number + currentText.rectTransform.anchoredPosition = new Vector2(-33, 27); + // The width of the Categories button is the last number, x - is the horizontal pos, the next number is the vertical pos + picker.categoriesTabButton = CreatePickerButton(picker.background.transform, 35, horzOff, textPrefab, picker.OnCategoriesButtonClick, 65); + // Prefix with space until I can find the button instance to override + picker.categoriesTabButton.Override(" Categories", true); + // The width of the Items button is the last number, x - is the horizontal pos, the next number is the vertical pos + picker.itemsTabButton = CreatePickerButton(picker.background.transform, 92, horzOff, textPrefab, picker.OnItemsButtonClick, 40); + // Prefix with space until I can find the button instance to override + picker.itemsTabButton.Override(" Items", false); + // The smaller number is the font size, the vertical position is overwritten below + picker.pageText = LockerPrefabShared.CreateText(picker.background.transform, textPrefab, Color.white, 0, 14, "1/X", "Picker"); + // The vertical position of the page numbers + picker.pageText.rectTransform.anchoredPosition = new Vector2(95, -211); + + // The vertical and horizontal position of the page arrows + picker.prevPageButton = AddPageButton(picker.background.transform, picker, -1, 28, -120); + picker.nextPageButton = AddPageButton(picker.background.transform, picker, +1, 89, -120); + // The vertical position of the close button ? picker.closeButton = AddCloseButton(picker.background.transform); for (int i = 0; i < AutosortTarget.MaxTypes; ++i) { - picker.currentList[i] = CreatePickerButton(picker.background.transform, -x, startY - (i * spacing), textPrefab, picker.OnCurrentListItemClick); - picker.availableList[i] = CreatePickerButton(picker.background.transform, x, startY - (i * spacing), textPrefab, picker.OnAvailableListItemClick); + picker.currentList[i] = CreatePickerButton(picker.background.transform, -centOff, startY - (i * spacing), textPrefab, picker.OnCurrentListItemClick); + picker.availableList[i] = CreatePickerButton(picker.background.transform, centOff, startY - (i * spacing), textPrefab, picker.OnAvailableListItemClick); } - return picker; } @@ -220,7 +252,8 @@ private static PickerPageButton AddPageButton(Transform parent, AutosortTypePick var pageButton = LockerPrefabShared.CreateIcon(parent, Color.white, y); pageButton.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath(pageOffset < 0 ? "ArrowLeft.png" : "ArrowRight.png")); pageButton.rectTransform.anchoredPosition = new Vector2(x, y); - RectTransformExtensions.SetSize(pageButton.rectTransform, 44 / 4.0f, 73 / 4.0f); + // Sets the size of the arrows + RectTransformExtensions.SetSize(pageButton.rectTransform, 14.0f, 16.0f); var controller = pageButton.gameObject.AddComponent(); controller.target = target; @@ -235,7 +268,8 @@ private static Image CreateUnderline(Transform parent, int x) RectTransformExtensions.SetParams(underline.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); RectTransformExtensions.SetSize(underline.rectTransform, 272 / 3, 78 / 3); underline.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("TitleUnderline.png")); - underline.rectTransform.anchoredPosition = new Vector2(x, 90); + // Vertical position of Underline + underline.rectTransform.anchoredPosition = new Vector2(x, 115); return underline; } @@ -246,16 +280,24 @@ public static PickerCloseButton AddCloseButton(Transform parent) RectTransformExtensions.SetParams(closeImage.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); RectTransformExtensions.SetSize(closeImage.rectTransform, 20, 20); closeImage.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("Close.png")); - closeImage.rectTransform.anchoredPosition = new Vector2(0, -90); + // Vertical and horizontal pos of the X - close button + closeImage.rectTransform.anchoredPosition = new Vector2(0, -120); var closeButton = closeImage.gameObject.AddComponent(); return closeButton; } - public static PickerButton CreatePickerButton(Transform parent, int x, int y, Text textPrefab, Action action, int width = 100) + public static FilterPickerButton CreatePickerButton(Transform parent, int x, int y, +#if SUBNAUTICA + Text textPrefab, +#elif BELOWZERO + TextMeshProUGUI textPrefab, +#endif + // The width of the picker button is set here + Action action, int width = 110) { - var button = PickerButton.Create(parent, textPrefab, action, width); + var button = FilterPickerButton.Create(parent, textPrefab, action, width); var rt = button.transform as RectTransform; rt.anchoredPosition = new Vector2(x, y); @@ -263,4 +305,4 @@ public static PickerButton CreatePickerButton(Transform parent, int x, int y, Te return button; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/AutosorterCategories.cs b/SubnauticaModSystem/AutosortLockers/AutosorterCategories.cs index 2873056..ff33739 100644 --- a/SubnauticaModSystem/AutosortLockers/AutosorterCategories.cs +++ b/SubnauticaModSystem/AutosortLockers/AutosorterCategories.cs @@ -1,452 +1,21 @@ -using Oculus.Newtonsoft.Json; +#if SUBNAUTICA +using Newtonsoft.Json; +#elif BELOWZERO +using Newtonsoft.Json; +#endif using System; -using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; -using UnityEngine; namespace AutosortLockers { - [Serializable] - public enum AutoSorterCategory - { - None, - Food, - Water, - PlantsAndSeeds, - Metals, - Electronics, - Batteries, - NaturalMaterials, - SyntheticMaterials, - CrystalMaterials, - Fish, - Eggs, - Tools, - Equipment, - MysteriousTablets, - ScannerRoomUpgrades, - GeneralUpgrades, - SeamothUpgrades, - PrawnSuitUpgrades, - CyclopsUpgrades, - Torpedoes, - AlterraStuff, - } - - public static class AutosorterCategoryData - { - public static List Fish = new List { - TechType.Bladderfish, - TechType.Boomerang, - TechType.LavaBoomerang, - TechType.Eyeye, - TechType.LavaEyeye, - TechType.GarryFish, - TechType.HoleFish, - TechType.Hoopfish, - TechType.Spinefish, - TechType.Hoverfish, - TechType.Oculus, - TechType.Peeper, - TechType.Reginald, - TechType.Spadefish, - }; - - public static List AlterraArtifacts = new List { - TechType.LabContainer, - TechType.LabContainer2, - TechType.LabContainer3, - TechType.ArcadeGorgetoy, - TechType.Cap1, - TechType.Cap2, - TechType.LabEquipment1, - TechType.LabEquipment2, - TechType.LabEquipment3, - TechType.LEDLightFragment, - TechType.StarshipSouvenir, - TechType.Poster, - TechType.PosterAurora, - TechType.PosterExoSuit1, - TechType.PosterExoSuit2, - TechType.PosterKitty, - }; - - public static List MysteriousTablets = new List { - TechType.PrecursorKey_Blue, - TechType.PrecursorKey_Orange, - TechType.PrecursorKey_Purple, - }; - - public static List CreatureEggs = new List { - TechType.BonesharkEgg, - TechType.CrabsnakeEgg, - TechType.CrabsquidEgg, - TechType.CrashEgg, - TechType.CutefishEgg, - TechType.GasopodEgg, - TechType.JellyrayEgg, - TechType.JumperEgg, - TechType.LavaLizardEgg, - TechType.MesmerEgg, - TechType.RabbitrayEgg, - TechType.ReefbackEgg, - TechType.SandsharkEgg, - TechType.ShockerEgg, - TechType.SpadefishEgg, - TechType.StalkerEgg, - TechType.GrandReefsEgg, - TechType.GrassyPlateausEgg, - TechType.KelpForestEgg, - TechType.KooshZoneEgg, - TechType.LavaZoneEgg, - TechType.MushroomForestEgg, - TechType.SafeShallowsEgg, - TechType.TwistyBridgesEgg, - TechType.RabbitrayEggUndiscovered, - TechType.JellyrayEggUndiscovered, - TechType.StalkerEggUndiscovered, - TechType.ReefbackEggUndiscovered, - TechType.JumperEggUndiscovered, - TechType.BonesharkEggUndiscovered, - TechType.GasopodEggUndiscovered, - TechType.MesmerEggUndiscovered, - TechType.SandsharkEggUndiscovered, - TechType.ShockerEggUndiscovered, - TechType.GenericEgg, - TechType.CrashEgg, - TechType.CrashEggUndiscovered, - TechType.CrabsquidEgg, - TechType.CrabsquidEggUndiscovered, - TechType.CutefishEgg, - TechType.CutefishEggUndiscovered, - TechType.LavaLizardEgg, - TechType.LavaLizardEggUndiscovered, - TechType.CrabsnakeEggUndiscovered, - TechType.SpadefishEggUndiscovered - }; - - public static List Food = new List { - TechType.CookedBladderfish, - TechType.CookedBoomerang, - TechType.CookedEyeye, - TechType.CookedGarryFish, - TechType.CookedHoleFish, - TechType.CookedHoopfish, - TechType.CookedHoverfish, - TechType.CookedLavaBoomerang, - TechType.CookedLavaEyeye, - TechType.CookedOculus, - TechType.CookedPeeper, - TechType.CookedReginald, - TechType.CookedSpadefish, - TechType.CookedSpinefish, - TechType.CuredBladderfish, - TechType.CuredBoomerang, - TechType.CuredEyeye, - TechType.CuredGarryFish, - TechType.CuredHoleFish, - TechType.CuredHoopfish, - TechType.CuredHoverfish, - TechType.CuredLavaBoomerang, - TechType.CuredLavaEyeye, - TechType.CuredOculus, - TechType.CuredPeeper, - TechType.CuredReginald, - TechType.CuredSpadefish, - TechType.CuredSpinefish, - TechType.NutrientBlock, - TechType.Snack1, - TechType.Snack2, - TechType.Snack3, - TechType.BulboTreePiece, - TechType.HangingFruit, - TechType.Melon, - TechType.PurpleVegetable, - }; - - public static List Water = new List { - TechType.BigFilteredWater, - TechType.Coffee, - TechType.DisinfectedWater, - TechType.FilteredWater, - TechType.StillsuitWater, - }; - - public static List ScannerRoomUpgrades = new List { - TechType.MapRoomUpgradeScanRange, - TechType.MapRoomUpgradeScanSpeed, - TechType.MapRoomCamera, - }; - - public static List CyclopsUpgrades = new List { - TechType.CyclopsDecoyModule, - TechType.CyclopsFireSuppressionModule, - TechType.CyclopsHullModule1, - TechType.CyclopsHullModule2, - TechType.CyclopsHullModule3, - TechType.CyclopsSeamothRepairModule, - TechType.CyclopsShieldModule, - TechType.CyclopsSonarModule, - TechType.CyclopsThermalReactorModule, - }; - - public static List PrawnSuitUpgrades = new List { - TechType.ExoHullModule1, - TechType.ExoHullModule2, - TechType.ExosuitDrillArmModule, - TechType.ExosuitGrapplingArmModule, - TechType.ExosuitJetUpgradeModule, - TechType.ExosuitPropulsionArmModule, - TechType.ExosuitThermalReactorModule, - TechType.ExosuitTorpedoArmModule, - }; - - public static List SeamothUpgrades = new List { - TechType.SeamothElectricalDefense, - TechType.SeamothReinforcementModule, - TechType.SeamothSolarCharge, - TechType.SeamothSonarModule, - TechType.SeamothTorpedoModule, - }; - - public static List GeneralUpgrades = new List { - TechType.HullReinforcementModule, - TechType.PowerUpgradeModule, - TechType.VehicleArmorPlating, - TechType.VehicleHullModule1, - TechType.VehicleHullModule2, - TechType.VehicleHullModule3, - TechType.VehiclePowerUpgradeModule, - TechType.VehicleStorageModule, - }; - - public static List Equipment = new List { - TechType.MapRoomHUDChip, - TechType.Rebreather, - TechType.Compass, - TechType.Fins, - TechType.HighCapacityTank, - TechType.PlasteelTank, - TechType.RadiationGloves, - TechType.RadiationHelmet, - TechType.RadiationSuit, - TechType.ReinforcedDiveSuit, - TechType.ReinforcedGloves, - TechType.Stillsuit, - TechType.SwimChargeFins, - TechType.Tank, - TechType.UltraGlideFins, - }; - - public static List Tools = new List { - TechType.AirBladder, - TechType.Beacon, - TechType.Builder, - TechType.CyclopsDecoy, - TechType.DiamondBlade, - TechType.DiveReel, - TechType.DoubleTank, - TechType.FireExtinguisher, - TechType.Flare, - TechType.Flashlight, - TechType.Gravsphere, - TechType.HeatBlade, - TechType.Knife, - TechType.LaserCutter, - TechType.LEDLight, - TechType.Pipe, - TechType.PipeSurfaceFloater, - TechType.PropulsionCannon, - TechType.RepulsionCannon, - TechType.Scanner, - TechType.Seaglide, - TechType.SmallStorage, - TechType.StasisRifle, - TechType.Welder, - TechType.LuggageBag, - }; - - public static List Torpedoes = new List { - TechType.GasTorpedo, - TechType.WhirlpoolTorpedo - }; - - public static List PlantsAndSeeds = new List { - TechType.AcidMushroomSpore, - TechType.BluePalmSeed, - TechType.BulboTreePiece, - TechType.CreepvinePiece, - TechType.CreepvineSeedCluster, - TechType.EyesPlantSeed, - TechType.FernPalmSeed, - TechType.GabeSFeatherSeed, - TechType.HangingFruit, - TechType.JellyPlantSeed, - TechType.KooshChunk, - TechType.Melon, - TechType.MelonSeed, - TechType.MembrainTreeSeed, - TechType.OrangeMushroomSpore, - TechType.OrangePetalsPlantSeed, - TechType.PinkFlowerSeed, - TechType.PinkMushroomSpore, - TechType.PurpleBrainCoralPiece, - TechType.PurpleBranchesSeed, - TechType.PurpleFanSeed, - TechType.PurpleRattleSpore, - TechType.PurpleStalkSeed, - TechType.PurpleTentacleSeed, - TechType.PurpleVasePlantSeed, - TechType.PurpleVegetable, - TechType.RedBasketPlantSeed, - TechType.RedBushSeed, - TechType.RedConePlantSeed, - TechType.RedGreenTentacleSeed, - TechType.RedRollPlantSeed, - TechType.SeaCrownSeed, - TechType.ShellGrassSeed, - TechType.SmallFanSeed, - TechType.SmallMelon, - TechType.SnakeMushroomSpore, - TechType.SpikePlantSeed, - TechType.SpottedLeavesPlantSeed, - TechType.WhiteMushroomSpore, - }; - - public static List Metals = new List { - TechType.Copper, - TechType.Gold, - TechType.Lead, - TechType.Lithium, - TechType.Magnetite, - TechType.ScrapMetal, - TechType.Nickel, - TechType.PlasteelIngot, - TechType.Silver, - TechType.Titanium, - TechType.TitaniumIngot, - }; - - public static List NaturalMaterials = new List { - TechType.GasPod, - TechType.CoralChunk, - TechType.WhiteMushroom, - TechType.AcidMushroom, - TechType.JeweledDiskPiece, - TechType.BloodOil, - TechType.CrashPowder, - TechType.Salt, - TechType.SeaTreaderPoop, - TechType.StalkerTooth, - TechType.JellyPlant, - }; - - public static List Electronics = new List { - TechType.AdvancedWiringKit, - TechType.ComputerChip, - TechType.CopperWire, - TechType.DepletedReactorRod, - TechType.ReactorRod, - TechType.WiringKit, - }; - - public static List SyntheticMaterials = new List { - TechType.Aerogel, - TechType.AramidFibers, - TechType.Benzene, - TechType.Bleach, - TechType.EnameledGlass, - TechType.FiberMesh, - TechType.Glass, - TechType.HatchingEnzymes, - TechType.HydrochloricAcid, - TechType.Lubricant, - TechType.Polyaniline, - TechType.PrecursorIonCrystal, - TechType.Silicone, - }; - - public static List CrystalMaterials = new List { - TechType.AluminumOxide, - TechType.Diamond, - TechType.Kyanite, - TechType.Quartz, - TechType.Sulphur, - TechType.UraniniteCrystal, - }; - - public static List Batteries = new List { - TechType.Battery, - TechType.PowerCell, - TechType.PrecursorIonBattery, - TechType.PrecursorIonPowerCell, - }; - - public static List IndividualItems = new List { - TechType.GasPod, - TechType.CoralChunk, - TechType.WhiteMushroom, - TechType.AcidMushroom, - TechType.JeweledDiskPiece, - TechType.AdvancedWiringKit, - TechType.Aerogel, - TechType.AluminumOxide, - TechType.AramidFibers, - TechType.Benzene, - TechType.Bleach, - TechType.BloodOil, - TechType.ComputerChip, - TechType.Copper, - TechType.CopperWire, - TechType.CrashPowder, - TechType.DepletedReactorRod, - TechType.Diamond, - TechType.EnameledGlass, - TechType.FiberMesh, - TechType.FirstAidKit, - TechType.Glass, - TechType.Gold, - TechType.HatchingEnzymes, - TechType.HydrochloricAcid, - TechType.JellyPlant, - TechType.Kyanite, - TechType.Lead, - TechType.Lithium, - TechType.Lubricant, - TechType.Magnetite, - TechType.ScrapMetal, - TechType.Nickel, - TechType.PlasteelIngot, - TechType.Polyaniline, - TechType.PrecursorIonCrystal, - TechType.Quartz, - TechType.ReactorRod, - TechType.Salt, - TechType.SeaTreaderPoop, - TechType.Silicone, - TechType.Silver, - TechType.StalkerTooth, - TechType.Sulphur, - TechType.Titanium, - TechType.TitaniumIngot, - TechType.UraniniteCrystal, - TechType.WiringKit, - TechType.Battery, - TechType.PowerCell, - TechType.PrecursorIonBattery, - TechType.PrecursorIonPowerCell, - }; - } - [Serializable] public class AutosorterFilter { public string Category; public List Types = new List(); - public bool IsCategory() => !string.IsNullOrEmpty(Category); public string GetString() @@ -487,106 +56,39 @@ public static List GetFilters() return Filters; } - public static List GetOldFilter(string oldCategory, out bool success, out string newCategory) - { - var category = AutoSorterCategory.None; - if (!Int32.TryParse(oldCategory, out int oldCategoryInt)) - { - newCategory = ""; - success = false; - return new List(); - } - category = (AutoSorterCategory)oldCategoryInt; - newCategory = category.ToString(); - - success = true; - switch (category) - { - default: - case AutoSorterCategory.None: return AutosorterCategoryData.IndividualItems; - - case AutoSorterCategory.Food: return AutosorterCategoryData.Food; - case AutoSorterCategory.Water: return AutosorterCategoryData.Water; - case AutoSorterCategory.PlantsAndSeeds: return AutosorterCategoryData.PlantsAndSeeds; - case AutoSorterCategory.Metals: return AutosorterCategoryData.Metals; - case AutoSorterCategory.NaturalMaterials: return AutosorterCategoryData.NaturalMaterials; - case AutoSorterCategory.SyntheticMaterials: return AutosorterCategoryData.SyntheticMaterials; - case AutoSorterCategory.Electronics: return AutosorterCategoryData.Electronics; - case AutoSorterCategory.CrystalMaterials: return AutosorterCategoryData.CrystalMaterials; - case AutoSorterCategory.Batteries: return AutosorterCategoryData.Batteries; - case AutoSorterCategory.Fish: return AutosorterCategoryData.Fish; - case AutoSorterCategory.Eggs: return AutosorterCategoryData.CreatureEggs; - case AutoSorterCategory.Tools: return AutosorterCategoryData.Tools; - case AutoSorterCategory.Equipment: return AutosorterCategoryData.Equipment; - case AutoSorterCategory.MysteriousTablets: return AutosorterCategoryData.MysteriousTablets; - case AutoSorterCategory.ScannerRoomUpgrades: return AutosorterCategoryData.ScannerRoomUpgrades; - case AutoSorterCategory.GeneralUpgrades: return AutosorterCategoryData.GeneralUpgrades; - case AutoSorterCategory.SeamothUpgrades: return AutosorterCategoryData.SeamothUpgrades; - case AutoSorterCategory.PrawnSuitUpgrades: return AutosorterCategoryData.PrawnSuitUpgrades; - case AutoSorterCategory.CyclopsUpgrades: return AutosorterCategoryData.CyclopsUpgrades; - case AutoSorterCategory.Torpedoes: return AutosorterCategoryData.Torpedoes; - case AutoSorterCategory.AlterraStuff: return AutosorterCategoryData.AlterraArtifacts; - } - } - [Serializable] private class TypeReference { - public string Name = ""; - public TechType Value = TechType.None; + public string TechName = ""; + public TechType TechID = TechType.None; } private static void InitializeFilters() { - var path = Mod.GetAssetPath("filters.json"); - var file = JsonConvert.DeserializeObject>(File.ReadAllText(path)); - Filters = file.Where((f) => f.IsCategory()).ToList(); - - if (Mod.config.ShowAllItems) - { - var typeRefPath = Mod.GetAssetPath("type_reference.json"); - List typeReferences = - JsonConvert.DeserializeObject>(File.ReadAllText(typeRefPath)); - typeReferences.Sort((TypeReference a, TypeReference b) => - { - string aName = Language.main.Get(a.Value); - string bName = Language.main.Get(b.Value); - return String.Compare(aName.ToLowerInvariant(), bName.ToLowerInvariant(), StringComparison.Ordinal); - }); + string getFilters; + // Gets the list of Cateories that are UsedInMod = true + getFilters = GetLists.GetFiltersFromJson('C', Mod.config.GameVersion); + var categoryList = JsonConvert.DeserializeObject>(getFilters); + Filters = categoryList.Where((f) => f.IsCategory()).ToList(); - foreach (var typeRef in typeReferences) - { - Filters.Add(new AutosorterFilter() {Category = "", Types = new List {typeRef.Value}}); - } - return; - } - var sorted = file.Where(f => !f.IsCategory()).ToList(); - sorted.Sort((x, y) => - { - string xName = Language.main.Get(x.Types.First()); - string yName = Language.main.Get(y.Types.First()); - return string.Compare(xName.ToLowerInvariant(), yName.ToLowerInvariant(), StringComparison.Ordinal); - }); - foreach (var filter in sorted) + // Gets the list of TechTypes for the Game Version SN or BZ + getFilters = GetLists.GetFiltersFromJson('T', Mod.config.GameVersion); + List techTypeList = JsonConvert.DeserializeObject>(getFilters); + + techTypeList.Sort((TypeReference a, TypeReference b) => { - Filters.Add(filter); - } - } + string aName = Language.main.Get(a.TechID); + string bName = Language.main.Get(b.TechID); - private static void AddEntry(string category, List types) - { - Filters.Add(new AutosorterFilter { - Category = category, - Types = types + //Returns the list of items from techtypes.json + return aName.CompareTo(bName); }); - } - private static void AddEntry(TechType type) - { - Filters.Add(new AutosorterFilter { - Category = "", - Types = new List { type } - }); + foreach (var typeRef in techTypeList) + { + Filters.Add(new AutosorterFilter() { Category = "", Types = new List { typeRef.TechID } }); + } + return; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/CanvasLink_Patch.cs b/SubnauticaModSystem/AutosortLockers/CanvasLink_Patch.cs new file mode 100644 index 0000000..9e0fd17 --- /dev/null +++ b/SubnauticaModSystem/AutosortLockers/CanvasLink_Patch.cs @@ -0,0 +1,43 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace AutosortLockers +{ + [HarmonyPatch(typeof(CanvasLink))] + public class CanvasLink_Patch + { + private static readonly FieldInfo canvasesInfo = typeof(CanvasLink).GetField("canvases", BindingFlags.NonPublic | BindingFlags.Instance); + + [HarmonyPatch("SetCanvasesEnabled")] + [HarmonyPrefix] + public static bool PrefixSetCanvasesEnabled(ref CanvasLink __instance) + { + if (__instance == null) + return false; + + Canvas[] array = (Canvas[])(canvasesInfo.GetValue(__instance)); + List list = new List(); + if (array != null && array.Length > 0) + { + for (int i = 0; i < array.Length; i++) + { + if (array[i] != null) + { + list.Add(array[i]); + } + else + { + } + } + canvasesInfo.SetValue(__instance, list.ToArray()); + } + return true; + } + } +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/ColorPicker.cs b/SubnauticaModSystem/AutosortLockers/ColorPicker.cs index 2889211..9f48f24 100644 --- a/SubnauticaModSystem/AutosortLockers/ColorPicker.cs +++ b/SubnauticaModSystem/AutosortLockers/ColorPicker.cs @@ -51,21 +51,20 @@ public override void Open() int buttonPage = index / ButtonsPerPage; ShowPage(buttonPage); } + + /*_____________________________________________________________________________________________________*/ - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static ColorPicker Create(Transform parent) + public static ColorPicker Create(Transform parent, GameObject lockerPrefab = null) { var beaconColorPicker = new GameObject("ColorPicker", typeof(RectTransform)).AddComponent(); - + // Used to calculate the size of the color picker background beaconColorPicker.ButtonSize = 15; beaconColorPicker.Spacing = 15; - beaconColorPicker.ButtonsPerPage = 72; - beaconColorPicker.ButtonsPerRow = 8; - - Picker.Create(parent, beaconColorPicker, Mod.colors.Count); + beaconColorPicker.ButtonsPerPage = 140; + beaconColorPicker.ButtonsPerRow = 10; + Picker.Create(parent, beaconColorPicker, Mod.colors.Count, lockerPrefab); return beaconColorPicker; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/ColorPickerButton.cs b/SubnauticaModSystem/AutosortLockers/ColorPickerButton.cs index 1c97187..e1671ef 100644 --- a/SubnauticaModSystem/AutosortLockers/ColorPickerButton.cs +++ b/SubnauticaModSystem/AutosortLockers/ColorPickerButton.cs @@ -32,12 +32,6 @@ public void OnPointerClick(PointerEventData eventData) } public void Initialize(int id, Color color, bool toggled, Sprite imageSprite) - { - var sprite = new Atlas.Sprite(imageSprite); - Initialize(id, color, toggled, sprite); - } - - public void Initialize(int id, Color color, bool toggled, Atlas.Sprite imageSprite) { this.id = id; this.toggled = toggled; @@ -74,9 +68,8 @@ public void OnPointerExit(PointerEventData eventData) pointerOver = false; } + /*_____________________________________________________________________________________________________*/ - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static ColorPickerButton Create(Transform parent, float width, float iconWidth) { var button = new GameObject("ColorPickerButton", typeof(RectTransform)).AddComponent(); @@ -99,4 +92,4 @@ public static ColorPickerButton Create(Transform parent, float width, float icon return button; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/ColorPickerPageButton.cs b/SubnauticaModSystem/AutosortLockers/ColorPickerPageButton.cs index 48e1f01..57632e6 100644 --- a/SubnauticaModSystem/AutosortLockers/ColorPickerPageButton.cs +++ b/SubnauticaModSystem/AutosortLockers/ColorPickerPageButton.cs @@ -42,7 +42,6 @@ public void Initialize(Sprite sprite, Color color) public void Update() { var color = (pointerDown ? DownColor : (pointerOver ? HoverColor : UpColor)); - if (image != null) { image.color = color; @@ -69,20 +68,17 @@ public void OnPointerUp(PointerEventData eventData) pointerDown = false; } + /*_____________________________________________________________________________________________________*/ - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static ColorPickerPageButton Create(Transform parent, Color color, float iconWidth = 20) { var pageButton = new GameObject("ColorPickerPageButton", typeof(RectTransform)); var rt = pageButton.transform as RectTransform; RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); - RectTransformExtensions.SetSize(rt, iconWidth, iconWidth); - rt.anchoredPosition = new Vector2(0, 0); var icon = LockerPrefabShared.CreateIcon(rt, color, 0); + // Size of the arrows RectTransformExtensions.SetSize(icon.rectTransform, iconWidth, iconWidth); - icon.rectTransform.anchoredPosition = new Vector2(0, 0); pageButton.AddComponent(); @@ -92,4 +88,4 @@ public static ColorPickerPageButton Create(Transform parent, Color color, float return button; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/ColorSetting.cs b/SubnauticaModSystem/AutosortLockers/ColorSetting.cs index bf727f2..01d64dc 100644 --- a/SubnauticaModSystem/AutosortLockers/ColorSetting.cs +++ b/SubnauticaModSystem/AutosortLockers/ColorSetting.cs @@ -1,10 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; -using UnityEngine.EventSystems; +#if SUBNAUTICA using UnityEngine.UI; +#elif BELOWZERO +using TMPro; +#endif namespace AutosortLockers { @@ -20,12 +20,18 @@ private void Awake() { rectTransform = transform as RectTransform; } - +#if SUBNAUTICA private void Initialize(Text textPrefab, string label) { activeButton = ColoredIconButton.Create(transform, CustomizeScreen.ScreenContentColor, textPrefab, label, 100, 15); activeButton.text.supportRichText = true; } +#elif BELOWZERO + private void Initialize(TextMeshProUGUI textPrefab, string label) + { + activeButton = ColoredIconButton.Create(transform, CustomizeScreen.ScreenContentColor, textPrefab, label, 100, 15); + } +#endif internal void SetInitialValue(Color initialColor) { @@ -43,15 +49,17 @@ private void OnClick() onClick(); } + /*_____________________________________________________________________________________________________*/ - /////////////////////////////////////////////////////////////////////////////////////////// - public static ColorSetting Create(Transform parent, string label) + public static ColorSetting Create(Transform parent, string label, GameObject lockerPrefab = null) { - var lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); +#if SUBNAUTICA + lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); - textPrefab.fontSize = 12; - textPrefab.color = new Color32(66, 134, 244, 255); - +#elif BELOWZERO + var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); +#endif + var beaconController = new GameObject("ColorSettings", typeof(RectTransform)).AddComponent(); var rt = beaconController.gameObject.transform as RectTransform; RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); @@ -60,4 +68,4 @@ public static ColorSetting Create(Transform parent, string label) return beaconController; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/ColoredIconButton.cs b/SubnauticaModSystem/AutosortLockers/ColoredIconButton.cs index a453539..7d28d1b 100644 --- a/SubnauticaModSystem/AutosortLockers/ColoredIconButton.cs +++ b/SubnauticaModSystem/AutosortLockers/ColoredIconButton.cs @@ -1,12 +1,12 @@ using Common.Mod; using Common.Utility; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; +#if BELOWZERO +using TMPro; +#endif namespace AutosortLockers { @@ -23,7 +23,11 @@ public class ColoredIconButton : MonoBehaviour, IPointerClickHandler, IPointerEn public Color imageColor; public Image image; +#if SUBNAUTICA public Text text; +#elif BELOWZERO + public TextMeshProUGUI text; +#endif public Action onClick = delegate { }; private Color imageDisabledColor; @@ -87,9 +91,15 @@ public void OnPointerUp(PointerEventData eventData) pointerDown = false; } + /*_____________________________________________________________________________________________________*/ - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static ColoredIconButton Create(Transform parent, Color color, Text textPrefab = null, string label = "", float width = 100, float iconWidth = 20) + public static ColoredIconButton Create(Transform parent, Color color, +#if SUBNAUTICA + Text textPrefab = null, +#elif BELOWZERO + TextMeshProUGUI textPrefab = null, +#endif + string label = "", float width = 100, float iconWidth = 20) { var checkboxButton = new GameObject("Checkbox", typeof(RectTransform)); var rt = checkboxButton.transform as RectTransform; @@ -101,14 +111,23 @@ public static ColoredIconButton Create(Transform parent, Color color, Text textP RectTransformExtensions.SetSize(checkbox.rectTransform, iconWidth, iconWidth); checkbox.rectTransform.anchoredPosition = new Vector2(textPrefab != null ? - width / 2 + 10 : 0, 0); +#if SUBNAUTICA Text text = null; +#elif BELOWZERO + TextMeshProUGUI text = null; +#endif + if (textPrefab != null) { var spacing = 5; - text = LockerPrefabShared.CreateText(rt, textPrefab, color, 0, 10, label); + text = LockerPrefabShared.CreateText(rt, textPrefab, color, 0, 10, label, "Label"); RectTransformExtensions.SetSize(text.rectTransform, width - 20 - spacing, 20); text.rectTransform.anchoredPosition = new Vector2(10 + spacing, 0); +#if SUBNAUTICA text.alignment = TextAnchor.MiddleLeft; +#elif BELOWZERO + text.alignment = TextAlignmentOptions.MidlineLeft; +#endif } checkboxButton.AddComponent(); @@ -121,4 +140,4 @@ public static ColoredIconButton Create(Transform parent, Color color, Text textP return button; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/Config.cs b/SubnauticaModSystem/AutosortLockers/Config.cs index 4cc282a..f82cc0d 100644 --- a/SubnauticaModSystem/AutosortLockers/Config.cs +++ b/SubnauticaModSystem/AutosortLockers/Config.cs @@ -1,18 +1,23 @@ -using Oculus.Newtonsoft.Json; +using Newtonsoft.Json; namespace AutosortLockers { - [JsonObject] - public class Config - { - public bool EasyBuild { get; set; } = false; - public float SortInterval { get; set; } = 1.0f; - public bool ShowAllItems { get; set; } = false; - public int AutosorterWidth { get; set; } = 5; - public int AutosorterHeight { get; set; } = 6; - public int ReceptacleWidth { get; set; } = 6; - public int ReceptacleHeight { get; set; } = 8; - public int StandingReceptacleWidth { get; set; } = 6; - public int StandingReceptacleHeight { get; set; } = 8; - } -} + [JsonObject] + public class Config + { + public bool ShowLabel { get; set; } = false; + public bool EasyBuild { get; set; } = false; + public float SortInterval { get; set; } = 1.0f; + public int AutosorterWidth { get; set; } = 5; + public int AutosorterHeight { get; set; } = 6; + public int ReceptacleWidth { get; set; } = 6; + public int ReceptacleHeight { get; set; } = 8; + public int StandingReceptacleWidth { get; set; } = 6; + public int StandingReceptacleHeight { get; set; } = 8; +#if SUBNAUTICA + public char GameVersion { get; set; } = '1'; +#elif BELOWZERO + public char GameVersion { get; set; } = '2'; +#endif + } +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/ConfigureButton.cs b/SubnauticaModSystem/AutosortLockers/ConfigureButton.cs index 9a3bd66..932ea09 100644 --- a/SubnauticaModSystem/AutosortLockers/ConfigureButton.cs +++ b/SubnauticaModSystem/AutosortLockers/ConfigureButton.cs @@ -44,11 +44,11 @@ public void OnPointerExit(PointerEventData eventData) } - public static ConfigureButton Create(Transform parent, Color color, float x) + public static ConfigureButton Create(Transform parent, Color color, float x, int buttonPos) { var config = LockerPrefabShared.CreateIcon(parent, color, 0); RectTransformExtensions.SetSize(config.rectTransform, 20, 20); - config.rectTransform.anchoredPosition = new Vector2(x, -104); + config.rectTransform.anchoredPosition = new Vector2(x, buttonPos); config.gameObject.AddComponent(); var button = config.gameObject.AddComponent(); @@ -56,4 +56,4 @@ public static ConfigureButton Create(Transform parent, Color color, float x) return button; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/CustomizeScreen.cs b/SubnauticaModSystem/AutosortLockers/CustomizeScreen.cs index 09debf6..fbe15b4 100644 --- a/SubnauticaModSystem/AutosortLockers/CustomizeScreen.cs +++ b/SubnauticaModSystem/AutosortLockers/CustomizeScreen.cs @@ -1,11 +1,10 @@ -using Common.Mod; -using Common.Utility; +using Common.Utility; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; using UnityEngine.UI; +#if BELOWZERO +using TMPro; +#endif namespace AutosortLockers { @@ -20,8 +19,6 @@ class CustomizeScreen : MonoBehaviour [SerializeField] private Image background; [SerializeField] - private Text labelLabel; - [SerializeField] private LabelController label; [SerializeField] private ConfigureButton exitButton; @@ -171,56 +168,57 @@ private void OnLockerColorPicked(int index) SetColor(target); } + /*_____________________________________________________________________________________________________*/ - - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static CustomizeScreen Create(Transform parent, SaveDataEntry data) + public static CustomizeScreen Create(Transform parent, SaveDataEntry data, GameObject lockerPrefab = null) { - var lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); +#if SUBNAUTICA + lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); +#elif BELOWZERO + var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); +#endif textPrefab.fontSize = 12; textPrefab.color = CustomizeScreen.ScreenContentColor; - + // The color picker settings var screen = new GameObject("CustomizeScreen", typeof(RectTransform)).AddComponent(); RectTransformExtensions.SetParams(screen.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); RectTransformExtensions.SetSize(screen.rectTransform, 114, 241); screen.background = new GameObject("Background").AddComponent(); screen.background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("CustomizeScreen.png")); - RectTransformExtensions.SetParams(screen.background.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), screen.transform); - RectTransformExtensions.SetSize(screen.background.rectTransform, 114, 241); - - screen.labelLabel = LockerPrefabShared.CreateText(screen.background.transform, textPrefab, ScreenContentColor, 100, 9, "Label:"); - RectTransformExtensions.SetSize(screen.labelLabel.rectTransform, 90, 40); - screen.labelLabel.alignment = TextAnchor.MiddleLeft; - - screen.label = LabelController.Create(data, screen.background.transform); - screen.label.rectTransform.anchoredPosition = new Vector2(0, 80); + // 1st = 2nd = 3rd = horizontal 4th = vertical positon of the color settings + RectTransformExtensions.SetParams(screen.background.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.41f, 0.4f), screen.transform); + RectTransformExtensions.SetSize(screen.background.rectTransform, 114, 220); - screen.exitButton = ConfigureButton.Create(screen.background.transform, Color.white, 40); + screen.label = LabelController.Create(data, screen.background.transform, lockerPrefab); + // The position of the LOCKER label + screen.label.rectTransform.anchoredPosition = new Vector2(0, 70); + // The position of the close (X) button on the color settings + screen.exitButton = ConfigureButton.Create(screen.background.transform, Color.white, 0, -85); var startX = 0; var startY = 30; - screen.labelColorSetting = ColorSetting.Create(screen.background.transform, "Label Color"); - screen.labelColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY); + screen.lockerColorSetting = ColorSetting.Create(screen.background.transform, "Locker Color", lockerPrefab); + screen.lockerColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY); - screen.iconColorSetting = ColorSetting.Create(screen.background.transform, "Icon Color"); + screen.iconColorSetting = ColorSetting.Create(screen.background.transform, "Icon Color", lockerPrefab); screen.iconColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - 19); - screen.textColorSetting = ColorSetting.Create(screen.background.transform, "Filters Color"); + screen.textColorSetting = ColorSetting.Create(screen.background.transform, "Filters Color", lockerPrefab); screen.textColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 2)); - screen.buttonsColorSetting = ColorSetting.Create(screen.background.transform, "Misc Color"); + screen.buttonsColorSetting = ColorSetting.Create(screen.background.transform, "Misc Color", lockerPrefab); screen.buttonsColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 3)); - screen.lockerColorSetting = ColorSetting.Create(screen.background.transform, "Locker Color"); - screen.lockerColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 4)); + screen.labelColorSetting = ColorSetting.Create(screen.background.transform, "Label Color", lockerPrefab); + screen.labelColorSetting.rectTransform.anchoredPosition = new Vector2(startX, startY - (19 * 4)); - screen.colorPicker = ColorPicker.Create(screen.background.transform); + screen.colorPicker = ColorPicker.Create(screen.background.transform, lockerPrefab); screen.colorPicker.gameObject.SetActive(false); screen.colorPicker.rectTransform.anchoredPosition = new Vector2(0, 30); return screen; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/FilterPickerButton.cs b/SubnauticaModSystem/AutosortLockers/FilterPickerButton.cs new file mode 100644 index 0000000..bcb54d1 --- /dev/null +++ b/SubnauticaModSystem/AutosortLockers/FilterPickerButton.cs @@ -0,0 +1,142 @@ +using Common.Utility; +using System; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; +#if BELOWZERO +using TMPro; +#endif + +namespace AutosortLockers +{ + public class FilterPickerButton : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler + { + private static readonly Color inactiveColor = new Color(0.7f, 0.7f, 0.7f, 0.5f); + private static readonly Color inactiveHoverColor = new Color(0.7f, 0.7f, 0.7f, 1f); + private static readonly Color upColor = new Color(0.9f, 0.9f, 0.9f, 1f); + private static readonly Color hoverColor = new Color(1, 1, 1); + private const int Slice = 70; + private bool hover; + private bool tabActive = true; + private AutosorterFilter filter; + + public Action onClick = delegate { }; + + [SerializeField] + private Image background; + [SerializeField] +#if SUBNAUTICA + private Text text; +#elif BELOWZERO + private TextMeshProUGUI text; +#endif + + public AutosorterFilter GetTechType() + { + return filter; + } + + public void Override(string text, bool category) + { + filter = null; + this.text.text = text; + SetBackgroundSprite(category); + gameObject.SetActive(true); + } + + public void SetFilter(AutosorterFilter value) + { + filter = value; + if (filter != null) + { + // The filter text displayed on the lockers + text.text = filter.GetString(); + + SetBackgroundSprite(filter.IsCategory()); + } + gameObject.SetActive(filter != null); + } + + private void SetBackgroundSprite(bool category) + { + if (background != null) + { + var spriteName = category ? "MainMenuPressedSprite.png" : "MainMenuStandardSprite.png"; + background.sprite = ImageUtils.Load9SliceSprite(Mod.GetAssetPath(spriteName), new RectOffset(Slice, Slice, Slice, Slice)); + } + } + + public void Update() + { + if (background != null) + { + if (tabActive) + { + background.color = hover ? hoverColor : upColor; + } + else + { + background.color = hover ? inactiveHoverColor : inactiveColor; + } + } + } + + public void OnPointerClick(PointerEventData eventData) + { + onClick.Invoke(filter); + } + + public void OnPointerEnter(PointerEventData eventData) + { + hover = true; + } + + public void OnPointerExit(PointerEventData eventData) + { + hover = false; + } + + public void SetTabActive(bool active) + { + tabActive = active; + } + + public static FilterPickerButton Create(Transform parent, +#if SUBNAUTICA + Text textPrefab, +#elif BELOWZERO + TextMeshProUGUI textPrefab, +#endif + // The size of the picker buttons, only the height is useful, the width is overwritten later + Action action, int width = 100, int height = 18) + { + var button = new GameObject("PickerButton", typeof(RectTransform)).AddComponent(); + button.transform.SetParent(parent, false); + + button.background = new GameObject("Background", typeof(RectTransform)).AddComponent(); + RectTransformExtensions.SetParams(button.background.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), button.transform); + RectTransformExtensions.SetSize(button.background.rectTransform, width * 10, height * 10); + button.background.rectTransform.localScale = new Vector3(0.1f, 0.1f, 0.5f); + button.background.sprite = ImageUtils.Load9SliceSprite(Mod.GetAssetPath("MainMenuStandardSprite.png"), new RectOffset(Slice, Slice, Slice, Slice)); + button.background.color = upColor; + button.background.type = Image.Type.Sliced; +#if SUBNAUTICA + button.text = new GameObject("Text", typeof(RectTransform)).AddComponent(); + button.text.alignment = TextAnchor.MiddleCenter; +#elif BELOWZERO + button.text = new GameObject("TextMeshProUGUI", typeof(RectTransform)).AddComponent(); +#endif + RectTransformExtensions.SetParams(button.text.rectTransform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), button.transform); + RectTransformExtensions.SetSize(button.text.rectTransform, width, height); + button.text.color = new Color(1, 1, 1); + button.text.font = textPrefab.font; + button.text.fontSize = 10; + button.onClick += action; + button.text.alignment = TextAlignmentOptions.Left; + // Set the left margin + button.text.margin = new Vector4(5.0f, 0.0f); + + return button; + } + } +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/GetLists.cs b/SubnauticaModSystem/AutosortLockers/GetLists.cs new file mode 100644 index 0000000..160e874 --- /dev/null +++ b/SubnauticaModSystem/AutosortLockers/GetLists.cs @@ -0,0 +1,72 @@ +using System.Collections.Generic; +using System.Linq; +using System.IO; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace AutosortLockers +{ + class GetLists + { + // Class to get valid lists of Category and TechTypes + + //Vince + //Logger.Log("Vince: " + text.text); + //QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Debug, $"Vince: " + text.text); + + private static string FilterFromJson; + + public static string GetFiltersFromJson(char listType, char gameVersion) + { + // Load categories.json + JObject catObj = JObject.Load(new JsonTextReader(File.OpenText(Mod.GetModPath() + "/categories.json"))); + // Load techtypes.json + JObject ttObj = JObject.Load(new JsonTextReader(File.OpenText(Mod.GetModPath() + "/techtypes.json"))); + + foreach (var categoriesJson in catObj) + { + // Filter variables + var gameVersions = new HashSet { 'A', gameVersion }; + var categoryIDs = new HashSet { }; + var useInMod = new HashSet { true }; + + // Right outer join on catObj. Select all Items[*] array items + var query = from c in catObj.SelectTokens("Categories[*]").OfType() + // Join catObj with ttObj on CategoryID + join t in ttObj.SelectTokens("TechTypes[*]") on (string)c["CategoryID"] equals (string)t["CategoryID"] + // Process the filters + where categoryIDs.Count() > 0 ? + useInMod.Contains((bool)c["UseInMod"]) + && gameVersions.Contains((char)c["GameVersion"]) + && gameVersions.Contains((char)t["GameVersion"]) + && categoryIDs.Contains((string)c["CategoryID"]) : + useInMod.Contains((bool)c["UseInMod"]) + && gameVersions.Contains((char)c["GameVersion"]) + && gameVersions.Contains((char)t["GameVersion"]) + select new + { + CategoryDescription = c["CategoryDescription"], + CategoryID = c["CategoryID"], + TechName = t["TechName"], + TechType = t["TechType"], + TechID = t["TechID"], + GameVersion = t["GameVersion"] + }; + // Convert the query into a formatted list + if (listType == 'T') + { + FilterFromJson = JsonConvert.SerializeObject(query.ToArray(), Formatting.Indented); + } + else + { + var results = query.GroupBy( + i => i.CategoryDescription, + t => t.TechID, + (key, g) => new { Category = key, Types = g.ToList() }); + FilterFromJson = JsonConvert.SerializeObject(results, Formatting.Indented); + } + } + return FilterFromJson; + } + } +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/LabelController.cs b/SubnauticaModSystem/AutosortLockers/LabelController.cs index 9f1d516..08061bc 100644 --- a/SubnauticaModSystem/AutosortLockers/LabelController.cs +++ b/SubnauticaModSystem/AutosortLockers/LabelController.cs @@ -1,10 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; using UnityEngine.EventSystems; +#if SUBNAUTICA using UnityEngine.UI; +#elif BELOWZERO +using TMPro; +#endif namespace AutosortLockers { @@ -14,8 +15,11 @@ class LabelController : MonoBehaviour, IPointerClickHandler, IPointerEnterHandle public RectTransform rectTransform; public Action onModified = delegate { }; +#if SUBNAUTICA public Text text; - +#elif BELOWZERO + public TextMeshProUGUI text; +#endif [SerializeField] private SaveDataEntry target; @@ -24,12 +28,16 @@ private void Awake() rectTransform = transform as RectTransform; } +#if SUBNAUTICA private void Initialize(SaveDataEntry data, Text textPrefab) +#elif BELOWZERO + private void Initialize(SaveDataEntry data, TextMeshProUGUI textPrefab) +#endif { target = data; text = GameObject.Instantiate(textPrefab); - text.fontSize = 16; + text.fontSize = 12; text.gameObject.name = "Text"; text.rectTransform.SetParent(transform, false); RectTransformExtensions.SetSize(text.rectTransform, 140, 50); @@ -65,17 +73,25 @@ private void Update() if (hover) { HandReticle.main.SetIcon(HandReticle.IconType.Rename); +#if SUBNAUTICA HandReticle.main.SetInteractTextRaw("Set Locker Label", ""); +#elif BELOWZERO + HandReticle.main.SetTextRaw(HandReticle.TextType.Hand, "Set Locker Label"); +#endif } } + /*__________________________________________________________________________________________________________*/ - - /////////////////////////////////////////////////////////////////////////////////////////// - public static LabelController Create(SaveDataEntry data, Transform parent) + public static LabelController Create(SaveDataEntry data, Transform parent, GameObject lockerPrefab = null) { - var lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); +#if SUBNAUTICA + lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); +#elif BELOWZERO + var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); +#endif + textPrefab.fontSize = 12; textPrefab.color = CustomizeScreen.ScreenContentColor; @@ -87,4 +103,4 @@ public static LabelController Create(SaveDataEntry data, Transform parent) return habitatNameController; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/Mod.cs b/SubnauticaModSystem/AutosortLockers/Mod.cs index f617fa2..75de80d 100644 --- a/SubnauticaModSystem/AutosortLockers/Mod.cs +++ b/SubnauticaModSystem/AutosortLockers/Mod.cs @@ -4,15 +4,22 @@ using System.IO; using System.Reflection; using Common.Mod; -using Harmony; -using Oculus.Newtonsoft.Json; +using HarmonyLib; +using Newtonsoft.Json; using UnityEngine; namespace AutosortLockers { internal static class Mod { +#if SUBNAUTICA public const string SaveDataFilename = "AutosortLockerSMLSaveData.json"; +#elif BELOWZERO + public const string SaveDataFilename = "AutosortLockerSMLBZSaveData.json"; +#endif + + private const int MAX_LOCKER_WIDTH = 8; + private const int MAX_LOCKER_HEIGHT = 10; public static Config config; public static SaveData saveData; public static List colors = new List(); @@ -25,13 +32,16 @@ internal static class Mod public static void Patch(string modDirectory = null) { Logger.Log("Starting patching"); - - Mod.modDirectory = modDirectory ?? "Subnautica_Data/Managed"; +#if SUBNAUTICA + Mod.modDirectory = modDirectory ?? "Subnautica_Data/Managed"; +#elif BELOWZERO + Mod.modDirectory = modDirectory ?? "SubnauticaZero_Data/Managed"; +#endif LoadConfig(); AddBuildables(); - HarmonyInstance harmony = HarmonyInstance.Create("com.AutosortLockersSML.mod"); + Harmony harmony = new Harmony("com.AutosortLockersSML.mod"); harmony.PatchAll(Assembly.GetExecutingAssembly()); Logger.Log("Patched"); @@ -58,7 +68,7 @@ private static void LoadConfig() config = ModUtils.LoadConfig(GetModPath() + "/config.json"); ValidateConfig(); - var serializedColors = JsonConvert.DeserializeObject>(File.ReadAllText(GetAssetPath("colors.json"))); + List serializedColors = JsonConvert.DeserializeObject>(File.ReadAllText(GetAssetPath("colors.json"))); foreach (var sColor in serializedColors) { colors.Add(sColor.ToColor()); @@ -70,10 +80,18 @@ private static void ValidateConfig() Config defaultConfig = new Config(); ModUtils.ValidateConfigValue("SortInterval", 0.1f, 10.0f, ref config, ref defaultConfig); - ModUtils.ValidateConfigValue("AutosorterWidth", 1, 8, ref config, ref defaultConfig); - ModUtils.ValidateConfigValue("AutosorterHeight", 1, 10, ref config, ref defaultConfig); - ModUtils.ValidateConfigValue("ReceptacleWidth", 1, 8, ref config, ref defaultConfig); - ModUtils.ValidateConfigValue("ReceptacleHeight", 1, 10, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("ShowLabel", true, false, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("AutosorterWidth", 1, MAX_LOCKER_WIDTH, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("AutosorterHeight", 1, MAX_LOCKER_HEIGHT, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("ReceptacleWidth", 1, MAX_LOCKER_WIDTH, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("ReceptacleHeight", 1, MAX_LOCKER_HEIGHT, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("StandingReceptacleWidth", 1, MAX_LOCKER_WIDTH, ref config, ref defaultConfig); + ModUtils.ValidateConfigValue("StandingReceptacleHeight", 1, MAX_LOCKER_HEIGHT, ref config, ref defaultConfig); +#if SUBNAUTICA + ModUtils.ValidateConfigValue("GameVersion", '1', '1', ref config, ref defaultConfig); +#elif BELOWZERO + ModUtils.ValidateConfigValue("GameVersion", '2', '2', ref config, ref defaultConfig); +#endif } public static SaveData GetSaveData() diff --git a/SubnauticaModSystem/AutosortLockers/Picker.cs b/SubnauticaModSystem/AutosortLockers/Picker.cs index 7e75d8b..2e7d36f 100644 --- a/SubnauticaModSystem/AutosortLockers/Picker.cs +++ b/SubnauticaModSystem/AutosortLockers/Picker.cs @@ -2,10 +2,11 @@ using Common.Utility; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; using UnityEngine.UI; +#if BELOWZERO +using TMPro; +#endif namespace AutosortLockers { @@ -28,12 +29,6 @@ class Picker : MonoBehaviour [SerializeField] private Image background; [SerializeField] - private ColorPickerPageButton prevPageButton; - [SerializeField] - private ColorPickerPageButton nextPageButton; - [SerializeField] - private Text pageText; - [SerializeField] protected List buttons = new List(); private void Awake() @@ -43,50 +38,20 @@ private void Awake() public virtual void Initialize() { - bool firstInitialize = false; - if (background.sprite == null) - { - background.sprite = ImageUtils.Load9SliceSprite(Mod.GetAssetPath("PickerBackground.png"), new RectOffset(100, 100, 100, 100)); - firstInitialize = true; - } - - int pages = GetPageCount(); - int rows = Mathf.CeilToInt(ButtonsPerPage / (float)ButtonsPerRow); float StartX = -(Spacing * (ButtonsPerRow - 1) / 2.0f); - float StartY = (Spacing * ((rows - 0.5f) / 2.0f)) + 10; + float StartY = (Spacing * ((rows - 0.5f) / 2.0f)); for (int i = 0; i < this.buttons.Count; ++i) { var button = this.buttons[i]; int page = i / ButtonsPerPage; int row = (i / ButtonsPerRow) % (ButtonsPerPage / ButtonsPerRow); int col = i % ButtonsPerRow; - button.rectTransform.anchoredPosition = new Vector2(StartX + (Spacing * col), StartY - (row * Spacing)); + button.rectTransform.anchoredPosition = new Vector2(StartX + (Spacing * col), StartY - (row * Spacing) - 3); button.onClick += OnClick; button.gameObject.SetActive(page == 0); button.toggled = false; } - - prevPageButton.Initialize("Left.png", Color.white); - nextPageButton.Initialize("Right.png", Color.white); - - var paginationY = -Spacing * rows / 2.0f; - (prevPageButton.transform as RectTransform).anchoredPosition = new Vector2(-20, paginationY); - (nextPageButton.transform as RectTransform).anchoredPosition = new Vector2(20, paginationY); - pageText.rectTransform.anchoredPosition = new Vector2(0, paginationY); - - if (firstInitialize) - { - prevPageButton.onClick += OnPrevPage; - nextPageButton.onClick += OnNextPage; - } - - page = 0; - //prevPageButton.gameObject.SetActive(pages > 1); - //nextPageButton.gameObject.SetActive(pages > 1); - //pageText.gameObject.SetActive(pages > 1); - - UpdateText(); } private int GetPageCount() @@ -94,12 +59,6 @@ private int GetPageCount() return Mathf.CeilToInt((float)buttons.Count / ButtonsPerPage); } - private void UpdateText() - { - int pages = GetPageCount(); - pageText.text = (page + 1) + "/" + pages; - } - private void OnPrevPage() { ShowPage(page - 1); @@ -114,6 +73,7 @@ protected void ShowPage(int newPage) { int pages = GetPageCount(); page = newPage; + if (page < 0) { page = pages - 1; @@ -129,7 +89,6 @@ protected void ShowPage(int newPage) int buttonPage = i / ButtonsPerPage; button.gameObject.SetActive(page == buttonPage); } - UpdateText(); } protected void OnClick(int index) @@ -168,40 +127,39 @@ public void Close() gameObject.SetActive(false); } + /*__________________________________________________________________________________________________________*/ - - /////////////////////////////////////////////////////////////////////////////////////////////////////// - protected static void Create(Transform parent, Picker instance, int buttonCount) + protected static void Create(Transform parent, Picker colorGrid, int buttonCount, GameObject lockerPrefab = null) { - var lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); +#if SUBNAUTICA + lockerPrefab = Resources.Load("Submarine/Build/SmallLocker"); var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); - textPrefab.fontSize = 16; +#elif BELOWZERO + var textPrefab = Instantiate(lockerPrefab.GetComponentInChildren()); +#endif + + textPrefab.fontSize = 12; textPrefab.color = ScreenContentColor; - float padding = 30; - float width = padding + instance.ButtonSize + ((instance.ButtonsPerRow - 1) * instance.Spacing) - 20; - int rowCount = Mathf.CeilToInt(instance.ButtonsPerPage / (float)instance.ButtonsPerRow); - float height = padding + instance.ButtonSize + ((rowCount - 0.5f) * instance.Spacing); + float padding = 10; + float width = padding + colorGrid.ButtonSize + (colorGrid.ButtonsPerRow * colorGrid.Spacing); + int rowCount = Mathf.CeilToInt(colorGrid.ButtonsPerPage / (float)colorGrid.ButtonsPerRow); + float height = 20 + colorGrid.ButtonSize + ((rowCount - 0.5f) * colorGrid.Spacing); - var rt = instance.rectTransform; - RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); + var rt = colorGrid.rectTransform; + // The first Vector2 positions the colorGrid on the locker horz / vert. + RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.6f), parent); RectTransformExtensions.SetSize(rt, width, height); - instance.background = instance.gameObject.AddComponent(); - instance.background.type = Image.Type.Sliced; - instance.background.rectTransform.anchoredPosition = new Vector2(0, -20); - - instance.pageText = LockerPrefabShared.CreateText(instance.transform, textPrefab, Color.white, 0, 10, "X/X"); - RectTransformExtensions.SetSize(instance.pageText.rectTransform, 30, 20); + colorGrid.background = colorGrid.gameObject.AddComponent(); + colorGrid.background.sprite = ImageUtils.LoadSprite(Mod.GetAssetPath("Background.png")); + colorGrid.background.color = new Color(1, 1, 1); for (int i = 0; i < buttonCount; ++i) { - var colorButton = ColorPickerButton.Create(instance.transform, instance.ButtonSize, instance.ButtonSize * 0.7f); - instance.buttons.Add(colorButton); + var colorButton = ColorPickerButton.Create(colorGrid.transform, colorGrid.ButtonSize, colorGrid.ButtonSize * 0.7f); + colorGrid.buttons.Add(colorButton); } - - instance.prevPageButton = ColorPickerPageButton.Create(instance.transform, Color.white); - instance.nextPageButton = ColorPickerPageButton.Create(instance.transform, Color.white); } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/PickerPageButton.cs b/SubnauticaModSystem/AutosortLockers/PickerPageButton.cs index 22d9504..f0f56e2 100644 --- a/SubnauticaModSystem/AutosortLockers/PickerPageButton.cs +++ b/SubnauticaModSystem/AutosortLockers/PickerPageButton.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -24,7 +20,7 @@ public void Awake() { image = GetComponent(); } - + public void OnPointerClick(PointerEventData eventData) { if (canChangePage) @@ -48,4 +44,4 @@ public void OnPointerExit(PointerEventData eventData) pointerOver = false; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/AutosortLockers/SaveData.cs b/SubnauticaModSystem/AutosortLockers/SaveData.cs index ff43937..e6e6a3a 100644 --- a/SubnauticaModSystem/AutosortLockers/SaveData.cs +++ b/SubnauticaModSystem/AutosortLockers/SaveData.cs @@ -1,8 +1,6 @@ using Common.Mod; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; namespace AutosortLockers @@ -25,4 +23,4 @@ public class SaveData { public List Entries = new List(); } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/Common/Mod/ImageUtils.cs b/SubnauticaModSystem/Common/Mod/ImageUtils.cs index e81b1ff..334ca4b 100644 --- a/SubnauticaModSystem/Common/Mod/ImageUtils.cs +++ b/SubnauticaModSystem/Common/Mod/ImageUtils.cs @@ -49,4 +49,4 @@ public static class ImageUtils return Sprite.Create(tex, new Rect(0f, 0f, tex.width, tex.height), pivot, pixelsPerUnit, 0u, spriteType, border); } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/Common/Mod/LockerPrefabShared.cs b/SubnauticaModSystem/Common/Mod/LockerPrefabShared.cs index ef9eca8..c58c814 100644 --- a/SubnauticaModSystem/Common/Mod/LockerPrefabShared.cs +++ b/SubnauticaModSystem/Common/Mod/LockerPrefabShared.cs @@ -1,5 +1,9 @@ -using UnityEngine; +using System; +using UnityEngine; using UnityEngine.UI; +#if BELOWZERO +using TMPro; +#endif namespace Common.Mod { @@ -15,9 +19,10 @@ internal static Canvas CreateCanvas(Transform parent) var raycaster = canvas.gameObject.AddComponent(); var rt = t as RectTransform; + // Positions the ?? RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f)); RectTransformExtensions.SetSize(rt, 1.7f, 3.0f); - + // Seems to be the front to back position of the small locker t.localPosition = new Vector3(0, 0, 0.345f); t.localRotation = new Quaternion(0, 1, 0, 0); t.localScale = new Vector3(0.5f, 0.5f, 0.5f); @@ -32,25 +37,52 @@ internal static Canvas CreateCanvas(Transform parent) return canvas; } - internal static Image CreateBackground(Transform parent) +#if SUBNAUTICA + internal static Image CreateBackground(Transform parent) + { + var background = new GameObject("Background", typeof(RectTransform)).AddComponent(); + var rt = background.rectTransform; + RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); + RectTransformExtensions.SetSize(rt, 114, 241); + background.color = new Color(0, 0, 0); + + background.transform.localScale = new Vector3(0.01f, 0.01f, 1); + background.type = Image.Type.Sliced; + + return background; + } +#elif BELOWZERO + internal static Image CreateBackground(Transform parent, string lockerType) { var background = new GameObject("Background", typeof(RectTransform)).AddComponent(); var rt = background.rectTransform; - RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); - RectTransformExtensions.SetSize(rt, 114, 241); - background.color = new Color(0, 0, 0); - background.transform.localScale = new Vector3(0.01f, 0.01f, 1); + // The size of the rectangle on the locker, adjusted for locker type + if (lockerType == "Locker(Clone)") + { // The second Vector2 positions the background on the locker, the 1st number is horizontal and the 2nd is vertical + RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.43f, 0.5f), parent); + RectTransformExtensions.SetSize(rt, 150, 280); + } + else //(lockerType == "SmallLocker(Clone)") + { + RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.52f, 0.49f), parent); + RectTransformExtensions.SetSize(rt, 128, 264); + } + // Overrides the color of the png image + background.color = new Color(0, 0, 0); + background.transform.localScale = new Vector3(0.01f, 0.01f, 1f); background.type = Image.Type.Sliced; return background; } +#endif internal static Image CreateIcon(Transform parent, Color color, int y) { var icon = new GameObject("Text", typeof(RectTransform)).AddComponent(); var rt = icon.rectTransform; RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); + // The size of the locker icon RectTransformExtensions.SetSize(rt, 40, 40); rt.anchoredPosition = new Vector2(0, y); @@ -59,21 +91,37 @@ internal static Image CreateIcon(Transform parent, Color color, int y) return icon; } +#if SUBNAUTICA internal static Text CreateText(Transform parent, Text prefab, Color color, int y, int size, string initial) { var text = new GameObject("Text", typeof(RectTransform)).AddComponent(); +#elif BELOWZERO + internal static TextMeshProUGUI CreateText(Transform parent, TextMeshProUGUI prefab, Color color, int y, int size, string initial, string lockerType) + { + var text = new GameObject("TextMeshProUGUI", typeof(RectTransform)).AddComponent(); +#endif var rt = text.rectTransform; + // Positions the "Locker" label on the locker RectTransformExtensions.SetParams(rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), parent); - RectTransformExtensions.SetSize(rt, 120, 200); - rt.anchoredPosition = new Vector2(0, y); + // The size of the Filter rectangle for each locker type + if (lockerType == "Locker(Clone)") + { + RectTransformExtensions.SetSize(rt, 138, 200); + } + else + { + RectTransformExtensions.SetSize(rt, 112, 200); + } + + rt.anchoredPosition = new Vector2(0, y); + text.font = prefab.font; text.fontSize = size; text.color = color; - text.alignment = TextAnchor.MiddleCenter; text.text = initial; return text; } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/Common/Mod/ModUtils.cs b/SubnauticaModSystem/Common/Mod/ModUtils.cs index ad851b2..2576041 100644 --- a/SubnauticaModSystem/Common/Mod/ModUtils.cs +++ b/SubnauticaModSystem/Common/Mod/ModUtils.cs @@ -5,23 +5,26 @@ using System.Linq; using System.Reflection; using System.Text; -using Oculus.Newtonsoft.Json; +using Newtonsoft.Json; +#if SUBNAUTICA using UnityEngine; using UnityEngine.UI; +#elif BELOWZERO +using TMPro; +#endif +using UnityEngine; namespace Common.Mod { internal static class ModUtils { - //private static FieldInfo CraftData_techMapping = typeof(CraftData).GetField("techMapping", BindingFlags.NonPublic | BindingFlags.Static); - - //private static List pickupableTypes; private static MonoBehaviour coroutineObject; public static ConfigT LoadConfig(string configFilePath) where ConfigT : class, new() { if (!File.Exists(configFilePath)) { + QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, $"Could not find config file {configFilePath}", null, true); return WriteDefaultConfig(configFilePath); } @@ -31,6 +34,7 @@ internal static class ModUtils if (string.IsNullOrEmpty(serialilzedConfig)) { + QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, $"Config file {configFilePath} empty; creating default config", null, true); return new ConfigT(); } @@ -38,13 +42,15 @@ internal static class ModUtils if (config == null) { + QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, $"Failed to deserialise configuration object from file {configFilePath}", null, true); config = new ConfigT(); } return config; } - catch + catch (Exception e) { + QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, $"Exception caught while parsing config file {configFilePath}", e, true); return WriteDefaultConfig(configFilePath); } } @@ -64,13 +70,16 @@ public static void ValidateConfigValue(string field, T min, T max, r var value = (T)fieldInfo.GetValue(config, null); if (value.CompareTo(min) < 0 || value.CompareTo(max) > 0) { - Console.WriteLine("Config value for '{0}' ({1}) was not valid. Must be between {2} and {3}", - field, - value, - min, - max - ); - fieldInfo.SetValue(config, fieldInfo.GetValue(defaultConfig, null), null); + string errorString = $"Config value for '{field}' ({value}) was not valid. Must be between {min} and {max}"; + + QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, errorString, null, true); + var newValue = value; + if (value.CompareTo(min) < 0) + newValue = min; + else if (value.CompareTo(max) > 0) + newValue = max; + + fieldInfo.SetValue(config, newValue, null); } } @@ -213,22 +222,29 @@ public static void PrintObjectFields(object obj, string indent = "") Console.WriteLine(indent + " " + property.Name + " : " + property.GetValue(obj, new object[] { })); } } - +#if SUBNAUTICA public static Text GetTextPrefab() { - Text prefab = GameObject.FindObjectOfType().interactPrimaryText; - if (prefab == null) - { - return null; - } - + Text prefab = null; + prefab = GameObject.FindObjectOfType().interactPrimaryText; +#elif BELOWZERO + public static TextMeshProUGUI GetTextPrefab() + { + TextMeshProUGUI prefab = GameObject.FindObjectOfType().progressText; +#endif return prefab; } +#if SUBNAUTICA public static Text InstantiateNewText(string name, Transform parent) { Text text = GameObject.Instantiate(GetTextPrefab()); - text.gameObject.layer = parent.gameObject.layer; +#elif BELOWZERO + public static TextMeshProUGUI InstantiateNewText(string name, Transform parent) + { + TextMeshProUGUI text = GameObject.Instantiate(GetTextPrefab()); +#endif + text.gameObject.layer = parent.gameObject.layer; text.gameObject.name = name; text.transform.SetParent(parent, false); text.transform.localScale = new Vector3(1, 1, 1); @@ -264,36 +280,6 @@ public static GameObject GetChildByName(GameObject parent, string name, bool rec return found; } - /* - public static List GetPickupableTechTypes() - { - if (pickupableTypes != null) - { - return pickupableTypes; - } - - Console.WriteLine("[ModUtils] Initialize Pickupable Types"); - pickupableTypes = new List(); - - var techMapping = (Dictionary)CraftData_techMapping.GetValue(null); - foreach (var entry in techMapping) - { - var techType = entry.Key; - var prefab = CraftData.GetPrefabForTechType(techType); - if (prefab != null) - { - if (prefab.GetComponent() != null) - { - Console.WriteLine("" + techType); - pickupableTypes.Add(techType); - } - } - } - - return pickupableTypes; - } - */ - public static T CopyComponent(T original, GameObject destination) where T : Component { Type type = original.GetType(); @@ -317,4 +303,4 @@ private static Coroutine StartCoroutine(IEnumerator coroutine) return coroutineObject.StartCoroutine(coroutine); } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/Common/Mod/SerializableColor.cs b/SubnauticaModSystem/Common/Mod/SerializableColor.cs index 1ecdcce..093c222 100644 --- a/SubnauticaModSystem/Common/Mod/SerializableColor.cs +++ b/SubnauticaModSystem/Common/Mod/SerializableColor.cs @@ -35,4 +35,4 @@ public static SerializableColor Create(Color c) } } -} +} \ No newline at end of file diff --git a/SubnauticaModSystem/GameDir.targets b/SubnauticaModSystem/GameDir.targets new file mode 100644 index 0000000..112228b --- /dev/null +++ b/SubnauticaModSystem/GameDir.targets @@ -0,0 +1,9 @@ + + + + + S:\Steam\steamapps\common\ + $(CommonDir)\Subnautica\ + $(CommonDir)\SubnauticaZero\ + + \ No newline at end of file