From 36ab19cc8c241af15d1b02fda7899fe1b8ed3c39 Mon Sep 17 00:00:00 2001 From: BenCheung0422 <74168521+BenCheung0422@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:56:27 +0800 Subject: [PATCH] Add support for in-app notifications --- src/client/java/minicraft/core/Game.java | 5 +- src/client/java/minicraft/core/Renderer.java | 16 +- src/client/java/minicraft/core/Updater.java | 13 +- src/client/java/minicraft/core/World.java | 2 +- .../java/minicraft/entity/furniture/Bed.java | 2 +- .../entity/furniture/DeathChest.java | 4 +- .../entity/furniture/KnightStatue.java | 6 +- .../java/minicraft/entity/mob/Player.java | 2 +- .../java/minicraft/item/FishingRodItem.java | 2 +- .../java/minicraft/item/PotionType.java | 2 +- src/client/java/minicraft/item/Recipes.java | 280 +++++++++--------- .../java/minicraft/item/SummonItem.java | 12 +- src/client/java/minicraft/item/TileItem.java | 2 +- .../minicraft/level/tile/BossDoorTile.java | 4 +- .../minicraft/level/tile/BossFloorTile.java | 2 +- .../minicraft/level/tile/BossWallTile.java | 2 +- .../minicraft/level/tile/HardRockTile.java | 2 +- .../java/minicraft/level/tile/WallTile.java | 4 +- .../minicraft/screen/AchievementsDisplay.java | 2 +- .../java/minicraft/screen/LoadingDisplay.java | 2 +- .../java/minicraft/screen/Notification.java | 56 ++++ .../screen/TutorialDisplayHandler.java | 2 +- 22 files changed, 249 insertions(+), 175 deletions(-) create mode 100644 src/client/java/minicraft/screen/Notification.java diff --git a/src/client/java/minicraft/core/Game.java b/src/client/java/minicraft/core/Game.java index 8fc3f1e7a..520422aea 100644 --- a/src/client/java/minicraft/core/Game.java +++ b/src/client/java/minicraft/core/Game.java @@ -4,13 +4,13 @@ import minicraft.core.io.Settings; import minicraft.core.io.Sound; import minicraft.entity.mob.Player; -import minicraft.gfx.Screen; import minicraft.level.Level; import minicraft.level.tile.Tiles; import minicraft.network.Analytics; import minicraft.saveload.Load; import minicraft.saveload.Version; import minicraft.screen.Display; +import minicraft.screen.Notification; import minicraft.screen.ResourcePackDisplay; import minicraft.screen.TitleDisplay; import minicraft.util.Logging; @@ -30,7 +30,8 @@ protected Game() {} // Can't instantiate the Game class. public static InputHandler input; // Input used in Game, Player, and just about all the *Menu classes. public static Player player; - public static List notifications = new ArrayList<>(); + public static List inGameNotifications = new ArrayList<>(); + public static ArrayDeque inAppNotifications = new ArrayDeque<>(); public static int MAX_FPS; diff --git a/src/client/java/minicraft/core/Renderer.java b/src/client/java/minicraft/core/Renderer.java index 3d2fcce91..5407e3630 100644 --- a/src/client/java/minicraft/core/Renderer.java +++ b/src/client/java/minicraft/core/Renderer.java @@ -27,6 +27,7 @@ import minicraft.level.Level; import minicraft.screen.LoadingDisplay; import minicraft.screen.Menu; +import minicraft.screen.Notification; import minicraft.screen.QuestsDisplay; import minicraft.screen.RelPos; import minicraft.screen.TutorialDisplayHandler; @@ -123,6 +124,11 @@ public static void render() { if (currentDisplay != null) // Renders menu, if present. currentDisplay.render(screen); + Notification notification; + if ((notification = inAppNotifications.peek()) != null) { + notification.render(screen); + } + if (!canvas.hasFocus()) renderFocusNagger(); // Calls the renderFocusNagger() method, which creates the "Click to Focus" message. @@ -268,18 +274,18 @@ private static void renderGui() { // NOTIFICATIONS Updater.updateNoteTick = false; - if (permStatus.size() == 0 && notifications.size() > 0) { + if (permStatus.size() == 0 && inGameNotifications.size() > 0) { Updater.updateNoteTick = true; - if (notifications.size() > 3) { // Only show 3 notifs max at one time; erase old notifs. - notifications = notifications.subList(notifications.size() - 3, notifications.size()); + if (inGameNotifications.size() > 3) { // Only show 3 notifs max at one time; erase old notifs. + inGameNotifications = inGameNotifications.subList(inGameNotifications.size() - 3, inGameNotifications.size()); } if (Updater.notetick > 180) { // Display time per notification. - notifications.remove(0); + inGameNotifications.remove(0); Updater.notetick = 0; } List print = new ArrayList<>(); - for (String n : notifications) { + for (String n : inGameNotifications) { for (String l : Font.getLines(n, Screen.w, Screen.h, 0)) print.add(l); } diff --git a/src/client/java/minicraft/core/Updater.java b/src/client/java/minicraft/core/Updater.java index fb45c9e29..b86c46738 100644 --- a/src/client/java/minicraft/core/Updater.java +++ b/src/client/java/minicraft/core/Updater.java @@ -11,6 +11,7 @@ import minicraft.screen.Display; import minicraft.screen.EndGameDisplay; import minicraft.screen.LevelTransitionDisplay; +import minicraft.screen.Notification; import minicraft.screen.PlayerDeathDisplay; import minicraft.screen.TutorialDisplayHandler; import minicraft.screen.WorldSelectDisplay; @@ -177,6 +178,16 @@ public static void tick() { } if (updateNoteTick) notetick++; + Notification notification; + if ((notification = inAppNotifications.peek()) != null) { + boolean refresh = true; + if (notification.isExpired()) { + inAppNotifications.pop(); // Removes + refresh = (notification = inAppNotifications.peek()) != null; // Tries getting new + } + + if (refresh) notification.tick(); + } // This is the general action statement thing! Regulates menus, mostly. if (!Renderer.canvas.hasFocus()) { @@ -331,7 +342,7 @@ public static void notifyAll(String msg) { } public static void notifyAll(String msg, int notetick) { msg = Localization.getLocalized(msg); - notifications.add(msg); + inGameNotifications.add(msg); Updater.notetick = notetick; } } diff --git a/src/client/java/minicraft/core/World.java b/src/client/java/minicraft/core/World.java index 4e5a2aa8d..a2dc31376 100644 --- a/src/client/java/minicraft/core/World.java +++ b/src/client/java/minicraft/core/World.java @@ -72,7 +72,7 @@ public static void resetGame(boolean keepPlayer) { playerDeadTime = 0; currentLevel = 3; Updater.asTick = 0; - Updater.notifications.clear(); + Updater.inGameNotifications.clear(); // Adds a new player if (keepPlayer) { diff --git a/src/client/java/minicraft/entity/furniture/Bed.java b/src/client/java/minicraft/entity/furniture/Bed.java index 41f57fd99..fd6849654 100644 --- a/src/client/java/minicraft/entity/furniture/Bed.java +++ b/src/client/java/minicraft/entity/furniture/Bed.java @@ -46,7 +46,7 @@ public static boolean checkCanSleep(Player player) { // It is too early to sleep; display how much time is remaining. int sec = (int)Math.ceil((Updater.sleepStartTime - Updater.tickCount)*1.0 / Updater.normSpeed); // gets the seconds until sleeping is allowed. // normSpeed is in tiks/sec. String note = Localization.getLocalized("minicraft.notification.cannot_sleep", sec / 60, sec % 60); - Game.notifications.add(note); // Add the notification displaying the time remaining in minutes and seconds. + Game.inGameNotifications.add(note); // Add the notification displaying the time remaining in minutes and seconds. return false; } diff --git a/src/client/java/minicraft/entity/furniture/DeathChest.java b/src/client/java/minicraft/entity/furniture/DeathChest.java index 3e7741dd4..eb00bb8e7 100644 --- a/src/client/java/minicraft/entity/furniture/DeathChest.java +++ b/src/client/java/minicraft/entity/furniture/DeathChest.java @@ -103,7 +103,7 @@ public void touchedBy(Entity other) { int returned = playerInv.add(i); if (returned < total) { - Game.notifications.add("Your inventory is full!"); + Game.inGameNotifications.add("Your inventory is full!"); return; } @@ -111,7 +111,7 @@ public void touchedBy(Entity other) { } remove(); - Game.notifications.add(Localization.getLocalized("minicraft.notification.death_chest_retrieved")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.death_chest_retrieved")); } } diff --git a/src/client/java/minicraft/entity/furniture/KnightStatue.java b/src/client/java/minicraft/entity/furniture/KnightStatue.java index 566b0ed13..0d6910127 100644 --- a/src/client/java/minicraft/entity/furniture/KnightStatue.java +++ b/src/client/java/minicraft/entity/furniture/KnightStatue.java @@ -22,10 +22,10 @@ public KnightStatue(int health) { public boolean interact(Player player, Item heldItem, Direction attackDir) { if (!ObsidianKnight.active) { if (touches == 0) { // Touched the first time. - Game.notifications.add(Localization.getLocalized("minicraft.notifications.statue_tapped")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notifications.statue_tapped")); touches++; } else if (touches == 1) { // Touched the second time. - Game.notifications.add(Localization.getLocalized("minicraft.notifications.statue_touched")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notifications.statue_touched")); touches++; } else { // Touched the third time. // Awoken notifications is in Boss class @@ -37,7 +37,7 @@ public boolean interact(Player player, Item heldItem, Direction attackDir) { return true; } else { // The boss is active. - Game.notifications.add(Localization.getLocalized("minicraft.notification.boss_limit")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.boss_limit")); return false; } } diff --git a/src/client/java/minicraft/entity/mob/Player.java b/src/client/java/minicraft/entity/mob/Player.java index a21c083f5..4d88ef95e 100644 --- a/src/client/java/minicraft/entity/mob/Player.java +++ b/src/client/java/minicraft/entity/mob/Player.java @@ -757,7 +757,7 @@ private void goFishing() { } if (itemData.startsWith(";")) { // For secret messages :=) - Game.notifications.add(itemData.substring(1)); + Game.inGameNotifications.add(itemData.substring(1)); } else { if (Items.get(itemData).equals(Items.get("Raw Fish"))) { AchievementsDisplay.setAchievement("minicraft.achievement.fish",true); diff --git a/src/client/java/minicraft/item/FishingRodItem.java b/src/client/java/minicraft/item/FishingRodItem.java index 5a8fade64..72cd0897f 100644 --- a/src/client/java/minicraft/item/FishingRodItem.java +++ b/src/client/java/minicraft/item/FishingRodItem.java @@ -74,7 +74,7 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, @Override public boolean isDepleted() { if (random.nextInt(100) > 120 - uses + level * 6) { // Breaking is random, the lower the level, and the more times you use it, the higher the chance - Game.notifications.add("Your Fishing rod broke."); + Game.inGameNotifications.add("Your Fishing rod broke."); return true; } return false; diff --git a/src/client/java/minicraft/item/PotionType.java b/src/client/java/minicraft/item/PotionType.java index 51bad8ba3..e80409195 100644 --- a/src/client/java/minicraft/item/PotionType.java +++ b/src/client/java/minicraft/item/PotionType.java @@ -40,7 +40,7 @@ public boolean toggleEffect(Player player, boolean addEffect) { if (playerDepth == 0) { // player is in overworld - Game.notifications.add("You can't escape from here!"); + Game.inGameNotifications.add("You can't escape from here!"); return false; } diff --git a/src/client/java/minicraft/item/Recipes.java b/src/client/java/minicraft/item/Recipes.java index 534561380..1c28699d2 100644 --- a/src/client/java/minicraft/item/Recipes.java +++ b/src/client/java/minicraft/item/Recipes.java @@ -1,140 +1,140 @@ -package minicraft.item; - -import java.util.ArrayList; - -public class Recipes { - - public static final ArrayList anvilRecipes = new ArrayList<>(); - public static final ArrayList ovenRecipes = new ArrayList<>(); - public static final ArrayList furnaceRecipes = new ArrayList<>(); - public static final ArrayList workbenchRecipes = new ArrayList<>(); - public static final ArrayList enchantRecipes = new ArrayList<>(); - public static final ArrayList craftRecipes = new ArrayList<>(); - public static final ArrayList loomRecipes = new ArrayList<>(); - - static { - craftRecipes.add(new Recipe("Workbench_1", "Wood_10")); - craftRecipes.add(new Recipe("Torch_2", "Wood_1", "coal_1")); - craftRecipes.add(new Recipe("plank_2", "Wood_1")); - craftRecipes.add(new Recipe("Plank Wall_1", "plank_3")); - craftRecipes.add(new Recipe("Wood Door_1", "plank_5")); - - workbenchRecipes.add(new Recipe("Workbench_1", "Wood_10")); - workbenchRecipes.add(new Recipe("Torch_2", "Wood_1", "coal_1")); - workbenchRecipes.add(new Recipe("plank_2", "Wood_1")); - workbenchRecipes.add(new Recipe("Plank Wall_1", "plank_3")); - workbenchRecipes.add(new Recipe("Wood Door_1", "plank_5")); - workbenchRecipes.add(new Recipe("Lantern_1", "Wood_8", "slime_4", "glass_3")); - workbenchRecipes.add(new Recipe("Stone Brick_1", "Stone_2")); - workbenchRecipes.add(new Recipe("Ornate Stone_1", "Stone_2")); - workbenchRecipes.add(new Recipe("Stone Wall_1", "Stone Brick_3")); - workbenchRecipes.add(new Recipe("Stone Door_1", "Stone Brick_5")); - workbenchRecipes.add(new Recipe("Obsidian Brick_1", "Raw Obsidian_2")); - workbenchRecipes.add(new Recipe("Ornate Obsidian_1", "Raw Obsidian_2")); - workbenchRecipes.add(new Recipe("Obsidian Wall_1", "Obsidian Brick_3")); - workbenchRecipes.add(new Recipe("Obsidian Door_1", "Obsidian Brick_5")); - workbenchRecipes.add(new Recipe("Oven_1", "Stone_15")); - workbenchRecipes.add(new Recipe("Furnace_1", "Stone_20")); - workbenchRecipes.add(new Recipe("Enchanter_1", "Wood_5", "String_2", "Lapis_10")); - workbenchRecipes.add(new Recipe("Chest_1", "Wood_20")); - workbenchRecipes.add(new Recipe("Anvil_1", "iron_5")); - workbenchRecipes.add(new Recipe("Tnt_1", "Gunpowder_10", "Sand_8")); - workbenchRecipes.add(new Recipe("Loom_1", "Wood_10", "Wool_5")); - workbenchRecipes.add(new Recipe("Wood Fishing Rod_1", "Wood_10", "String_3")); - workbenchRecipes.add(new Recipe("Iron Fishing Rod_1", "Iron_10", "String_3")); - workbenchRecipes.add(new Recipe("Gold Fishing Rod_1", "Gold_10", "String_3")); - workbenchRecipes.add(new Recipe("Gem Fishing Rod_1", "Gem_10", "String_3")); - - workbenchRecipes.add(new Recipe("Wood Sword_1", "Wood_5")); - workbenchRecipes.add(new Recipe("Wood Axe_1", "Wood_5")); - workbenchRecipes.add(new Recipe("Wood Hoe_1", "Wood_5")); - workbenchRecipes.add(new Recipe("Wood Pickaxe_1", "Wood_5")); - workbenchRecipes.add(new Recipe("Wood Shovel_1", "Wood_5")); - workbenchRecipes.add(new Recipe("Wood Bow_1", "Wood_5", "string_2")); - workbenchRecipes.add(new Recipe("Rock Sword_1", "Wood_5", "Stone_5")); - workbenchRecipes.add(new Recipe("Rock Axe_1", "Wood_5", "Stone_5")); - workbenchRecipes.add(new Recipe("Rock Hoe_1", "Wood_5", "Stone_5")); - workbenchRecipes.add(new Recipe("Rock Pickaxe_1", "Wood_5", "Stone_5")); - workbenchRecipes.add(new Recipe("Rock Shovel_1", "Wood_5", "Stone_5")); - workbenchRecipes.add(new Recipe("Rock Bow_1", "Wood_5", "Stone_5", "string_2")); - - workbenchRecipes.add(new Recipe("arrow_3", "Wood_2", "Stone_2")); - workbenchRecipes.add(new Recipe("Leather Armor_1", "leather_10")); - workbenchRecipes.add(new Recipe("Snake Armor_1", "scale_15")); - - loomRecipes.add(new Recipe("String_2", "Wool_1")); - loomRecipes.add(new Recipe("red wool_1", "Wool_1", "rose_1")); - loomRecipes.add(new Recipe("blue wool_1", "Wool_1", "Lapis_1")); - loomRecipes.add(new Recipe("green wool_1", "Wool_1", "Cactus_1")); - loomRecipes.add(new Recipe("yellow wool_1", "Wool_1", "Flower_1")); - loomRecipes.add(new Recipe("black wool_1", "Wool_1", "coal_1")); - loomRecipes.add(new Recipe("Bed_1", "Wood_5", "Wool_3")); - - loomRecipes.add(new Recipe("blue clothes_1", "cloth_5", "Lapis_1")); - loomRecipes.add(new Recipe("green clothes_1", "cloth_5", "Cactus_1")); - loomRecipes.add(new Recipe("yellow clothes_1", "cloth_5", "Flower_1")); - loomRecipes.add(new Recipe("black clothes_1", "cloth_5", "coal_1")); - loomRecipes.add(new Recipe("orange clothes_1", "cloth_5", "rose_1", "Flower_1")); - loomRecipes.add(new Recipe("purple clothes_1", "cloth_5", "Lapis_1", "rose_1")); - loomRecipes.add(new Recipe("cyan clothes_1", "cloth_5", "Lapis_1", "Cactus_1")); - loomRecipes.add(new Recipe("reg clothes_1", "cloth_5")); - - loomRecipes.add(new Recipe("Leather Armor_1", "leather_10")); - - anvilRecipes.add(new Recipe("Iron Armor_1", "iron_10")); - anvilRecipes.add(new Recipe("Gold Armor_1", "gold_10")); - anvilRecipes.add(new Recipe("Gem Armor_1", "gem_65")); - anvilRecipes.add(new Recipe("Empty Bucket_1", "iron_5")); - anvilRecipes.add(new Recipe("Iron Lantern_1", "iron_8", "slime_5", "glass_4")); - anvilRecipes.add(new Recipe("Gold Lantern_1", "gold_10", "slime_5", "glass_4")); - anvilRecipes.add(new Recipe("Iron Sword_1", "Wood_5", "iron_5")); - anvilRecipes.add(new Recipe("Iron Claymore_1", "Iron Sword_1", "shard_15")); - anvilRecipes.add(new Recipe("Iron Axe_1", "Wood_5", "iron_5")); - anvilRecipes.add(new Recipe("Iron Hoe_1", "Wood_5", "iron_5")); - anvilRecipes.add(new Recipe("Iron Pickaxe_1", "Wood_5", "iron_5")); - anvilRecipes.add(new Recipe("Iron Shovel_1", "Wood_5", "iron_5")); - anvilRecipes.add(new Recipe("Iron Bow_1", "Wood_5", "iron_5", "string_2")); - anvilRecipes.add(new Recipe("Gold Sword_1", "Wood_5", "gold_5")); - anvilRecipes.add(new Recipe("Gold Claymore_1", "Gold Sword_1", "shard_15")); - anvilRecipes.add(new Recipe("Gold Axe_1", "Wood_5", "gold_5")); - anvilRecipes.add(new Recipe("Gold Hoe_1", "Wood_5", "gold_5")); - anvilRecipes.add(new Recipe("Gold Pickaxe_1", "Wood_5", "gold_5")); - anvilRecipes.add(new Recipe("Gold Shovel_1", "Wood_5", "gold_5")); - anvilRecipes.add(new Recipe("Gold Bow_1", "Wood_5", "gold_5", "string_2")); - anvilRecipes.add(new Recipe("Gem Sword_1", "Wood_5", "gem_50")); - anvilRecipes.add(new Recipe("Gem Claymore_1", "Gem Sword_1", "shard_15")); - anvilRecipes.add(new Recipe("Gem Axe_1", "Wood_5", "gem_50")); - anvilRecipes.add(new Recipe("Gem Hoe_1", "Wood_5", "gem_50")); - anvilRecipes.add(new Recipe("Gem Pickaxe_1", "Wood_5", "gem_50")); - anvilRecipes.add(new Recipe("Gem Shovel_1", "Wood_5", "gem_50")); - anvilRecipes.add(new Recipe("Gem Bow_1", "Wood_5", "gem_50", "string_2")); - anvilRecipes.add(new Recipe("Shears_1", "Iron_4")); - anvilRecipes.add(new Recipe("Watering Can_1", "Iron_3")); - - furnaceRecipes.add(new Recipe("iron_1", "iron Ore_4", "coal_1")); - furnaceRecipes.add(new Recipe("gold_1", "gold Ore_4", "coal_1")); - furnaceRecipes.add(new Recipe("glass_1", "sand_4", "coal_1")); - furnaceRecipes.add(new Recipe("glass bottle_1", "glass_3")); - - ovenRecipes.add(new Recipe("cooked pork_1", "raw pork_1", "coal_1")); - ovenRecipes.add(new Recipe("steak_1", "raw beef_1", "coal_1")); - ovenRecipes.add(new Recipe("cooked fish_1", "raw fish_1", "coal_1")); - ovenRecipes.add(new Recipe("bread_1", "wheat_4")); - ovenRecipes.add(new Recipe("Baked Potato_1", "Potato_1")); - - enchantRecipes.add(new Recipe("Gold Apple_1", "apple_1", "gold_8")); - enchantRecipes.add(new Recipe("awkward potion_1", "glass bottle_1", "Lapis_3")); - enchantRecipes.add(new Recipe("speed potion_1", "awkward potion_1", "Cactus_5")); - enchantRecipes.add(new Recipe("light potion_1", "awkward potion_1", "slime_5")); - enchantRecipes.add(new Recipe("swim potion_1", "awkward potion_1", "raw fish_5")); - enchantRecipes.add(new Recipe("haste potion_1", "awkward potion_1", "Wood_5", "Stone_5")); - enchantRecipes.add(new Recipe("lava potion_1", "awkward potion_1", "Lava Bucket_1")); - enchantRecipes.add(new Recipe("energy potion_1", "awkward potion_1", "gem_25")); - enchantRecipes.add(new Recipe("regen potion_1", "awkward potion_1", "Gold Apple_1")); - enchantRecipes.add(new Recipe("Health Potion_1", "awkward potion_1", "GunPowder_2", "Leather Armor_1")); - enchantRecipes.add(new Recipe("Escape Potion_1", "awkward potion_1", "GunPowder_3", "Lapis_7")); - enchantRecipes.add(new Recipe("Totem of Air_1", "gold_10", "gem_10", "Lapis_5", "Cloud Ore_5")); - enchantRecipes.add(new Recipe("Obsidian Poppet_1", "gold_10", "gem_10", "Lapis_5", "Shard_15")); - enchantRecipes.add(new Recipe("Arcane Fertilizer_3", "Lapis_6", "Bone_2")); - } -} +package minicraft.item; + +import java.util.ArrayList; + +public class Recipes { + + public static final ArrayList anvilRecipes = new ArrayList<>(); + public static final ArrayList ovenRecipes = new ArrayList<>(); + public static final ArrayList furnaceRecipes = new ArrayList<>(); + public static final ArrayList workbenchRecipes = new ArrayList<>(); + public static final ArrayList enchantRecipes = new ArrayList<>(); + public static final ArrayList craftRecipes = new ArrayList<>(); + public static final ArrayList loomRecipes = new ArrayList<>(); + + static { + craftRecipes.add(new Recipe("Workbench_1", "Wood_10")); + craftRecipes.add(new Recipe("Torch_2", "Wood_1", "coal_1")); + craftRecipes.add(new Recipe("plank_2", "Wood_1")); + craftRecipes.add(new Recipe("Plank Wall_1", "plank_3")); + craftRecipes.add(new Recipe("Wood Door_1", "plank_5")); + + workbenchRecipes.add(new Recipe("Workbench_1", "Wood_10")); + workbenchRecipes.add(new Recipe("Torch_2", "Wood_1", "coal_1")); + workbenchRecipes.add(new Recipe("plank_2", "Wood_1")); + workbenchRecipes.add(new Recipe("Plank Wall_1", "plank_3")); + workbenchRecipes.add(new Recipe("Wood Door_1", "plank_5")); + workbenchRecipes.add(new Recipe("Lantern_1", "Wood_8", "slime_4", "glass_3")); + workbenchRecipes.add(new Recipe("Stone Brick_1", "Stone_2")); + workbenchRecipes.add(new Recipe("Ornate Stone_1", "Stone_2")); + workbenchRecipes.add(new Recipe("Stone Wall_1", "Stone Brick_3")); + workbenchRecipes.add(new Recipe("Stone Door_1", "Stone Brick_5")); + workbenchRecipes.add(new Recipe("Obsidian Brick_1", "Raw Obsidian_2")); + workbenchRecipes.add(new Recipe("Ornate Obsidian_1", "Raw Obsidian_2")); + workbenchRecipes.add(new Recipe("Obsidian Wall_1", "Obsidian Brick_3")); + workbenchRecipes.add(new Recipe("Obsidian Door_1", "Obsidian Brick_5")); + workbenchRecipes.add(new Recipe("Oven_1", "Stone_15")); + workbenchRecipes.add(new Recipe("Furnace_1", "Stone_20")); + workbenchRecipes.add(new Recipe("Enchanter_1", "Wood_5", "String_2", "Lapis_10")); + workbenchRecipes.add(new Recipe("Chest_1", "Wood_20")); + workbenchRecipes.add(new Recipe("Anvil_1", "iron_5")); + workbenchRecipes.add(new Recipe("Tnt_1", "Gunpowder_10", "Sand_8")); + workbenchRecipes.add(new Recipe("Loom_1", "Wood_10", "Wool_5")); + workbenchRecipes.add(new Recipe("Wood Fishing Rod_1", "Wood_10", "String_3")); + workbenchRecipes.add(new Recipe("Iron Fishing Rod_1", "Iron_10", "String_3")); + workbenchRecipes.add(new Recipe("Gold Fishing Rod_1", "Gold_10", "String_3")); + workbenchRecipes.add(new Recipe("Gem Fishing Rod_1", "Gem_10", "String_3")); + + workbenchRecipes.add(new Recipe("Wood Sword_1", "Wood_5")); + workbenchRecipes.add(new Recipe("Wood Axe_1", "Wood_5")); + workbenchRecipes.add(new Recipe("Wood Hoe_1", "Wood_5")); + workbenchRecipes.add(new Recipe("Wood Pickaxe_1", "Wood_5")); + workbenchRecipes.add(new Recipe("Wood Shovel_1", "Wood_5")); + workbenchRecipes.add(new Recipe("Wood Bow_1", "Wood_5", "string_2")); + workbenchRecipes.add(new Recipe("Rock Sword_1", "Wood_5", "Stone_5")); + workbenchRecipes.add(new Recipe("Rock Axe_1", "Wood_5", "Stone_5")); + workbenchRecipes.add(new Recipe("Rock Hoe_1", "Wood_5", "Stone_5")); + workbenchRecipes.add(new Recipe("Rock Pickaxe_1", "Wood_5", "Stone_5")); + workbenchRecipes.add(new Recipe("Rock Shovel_1", "Wood_5", "Stone_5")); + workbenchRecipes.add(new Recipe("Rock Bow_1", "Wood_5", "Stone_5", "string_2")); + + workbenchRecipes.add(new Recipe("arrow_3", "Wood_2", "Stone_2")); + workbenchRecipes.add(new Recipe("Leather Armor_1", "leather_10")); + workbenchRecipes.add(new Recipe("Snake Armor_1", "scale_15")); + + loomRecipes.add(new Recipe("String_2", "Wool_1")); + loomRecipes.add(new Recipe("red wool_1", "Wool_1", "rose_1")); + loomRecipes.add(new Recipe("blue wool_1", "Wool_1", "Lapis_1")); + loomRecipes.add(new Recipe("green wool_1", "Wool_1", "Cactus_1")); + loomRecipes.add(new Recipe("yellow wool_1", "Wool_1", "Flower_1")); + loomRecipes.add(new Recipe("black wool_1", "Wool_1", "coal_1")); + loomRecipes.add(new Recipe("Bed_1", "Wood_5", "Wool_3")); + + loomRecipes.add(new Recipe("blue clothes_1", "cloth_5", "Lapis_1")); + loomRecipes.add(new Recipe("green clothes_1", "cloth_5", "Cactus_1")); + loomRecipes.add(new Recipe("yellow clothes_1", "cloth_5", "Flower_1")); + loomRecipes.add(new Recipe("black clothes_1", "cloth_5", "coal_1")); + loomRecipes.add(new Recipe("orange clothes_1", "cloth_5", "rose_1", "Flower_1")); + loomRecipes.add(new Recipe("purple clothes_1", "cloth_5", "Lapis_1", "rose_1")); + loomRecipes.add(new Recipe("cyan clothes_1", "cloth_5", "Lapis_1", "Cactus_1")); + loomRecipes.add(new Recipe("reg clothes_1", "cloth_5")); + + loomRecipes.add(new Recipe("Leather Armor_1", "leather_10")); + + anvilRecipes.add(new Recipe("Iron Armor_1", "iron_10")); + anvilRecipes.add(new Recipe("Gold Armor_1", "gold_10")); + anvilRecipes.add(new Recipe("Gem Armor_1", "gem_65")); + anvilRecipes.add(new Recipe("Empty Bucket_1", "iron_5")); + anvilRecipes.add(new Recipe("Iron Lantern_1", "iron_8", "slime_5", "glass_4")); + anvilRecipes.add(new Recipe("Gold Lantern_1", "gold_10", "slime_5", "glass_4")); + anvilRecipes.add(new Recipe("Iron Sword_1", "Wood_5", "iron_5")); + anvilRecipes.add(new Recipe("Iron Claymore_1", "Iron Sword_1", "shard_15")); + anvilRecipes.add(new Recipe("Iron Axe_1", "Wood_5", "iron_5")); + anvilRecipes.add(new Recipe("Iron Hoe_1", "Wood_5", "iron_5")); + anvilRecipes.add(new Recipe("Iron Pickaxe_1", "Wood_5", "iron_5")); + anvilRecipes.add(new Recipe("Iron Shovel_1", "Wood_5", "iron_5")); + anvilRecipes.add(new Recipe("Iron Bow_1", "Wood_5", "iron_5", "string_2")); + anvilRecipes.add(new Recipe("Gold Sword_1", "Wood_5", "gold_5")); + anvilRecipes.add(new Recipe("Gold Claymore_1", "Gold Sword_1", "shard_15")); + anvilRecipes.add(new Recipe("Gold Axe_1", "Wood_5", "gold_5")); + anvilRecipes.add(new Recipe("Gold Hoe_1", "Wood_5", "gold_5")); + anvilRecipes.add(new Recipe("Gold Pickaxe_1", "Wood_5", "gold_5")); + anvilRecipes.add(new Recipe("Gold Shovel_1", "Wood_5", "gold_5")); + anvilRecipes.add(new Recipe("Gold Bow_1", "Wood_5", "gold_5", "string_2")); + anvilRecipes.add(new Recipe("Gem Sword_1", "Wood_5", "gem_50")); + anvilRecipes.add(new Recipe("Gem Claymore_1", "Gem Sword_1", "shard_15")); + anvilRecipes.add(new Recipe("Gem Axe_1", "Wood_5", "gem_50")); + anvilRecipes.add(new Recipe("Gem Hoe_1", "Wood_5", "gem_50")); + anvilRecipes.add(new Recipe("Gem Pickaxe_1", "Wood_5", "gem_50")); + anvilRecipes.add(new Recipe("Gem Shovel_1", "Wood_5", "gem_50")); + anvilRecipes.add(new Recipe("Gem Bow_1", "Wood_5", "gem_50", "string_2")); + anvilRecipes.add(new Recipe("Shears_1", "Iron_4")); + anvilRecipes.add(new Recipe("Watering Can_1", "Iron_3")); + + furnaceRecipes.add(new Recipe("iron_1", "iron Ore_4", "coal_1")); + furnaceRecipes.add(new Recipe("gold_1", "gold Ore_4", "coal_1")); + furnaceRecipes.add(new Recipe("glass_1", "sand_4", "coal_1")); + furnaceRecipes.add(new Recipe("glass bottle_1", "glass_3")); + + ovenRecipes.add(new Recipe("cooked pork_1", "raw pork_1", "coal_1")); + ovenRecipes.add(new Recipe("steak_1", "raw beef_1", "coal_1")); + ovenRecipes.add(new Recipe("cooked fish_1", "raw fish_1", "coal_1")); + ovenRecipes.add(new Recipe("bread_1", "wheat_4")); + ovenRecipes.add(new Recipe("Baked Potato_1", "Potato_1")); + + enchantRecipes.add(new Recipe("Gold Apple_1", "apple_1", "gold_8")); + enchantRecipes.add(new Recipe("awkward potion_1", "glass bottle_1", "Lapis_3")); + enchantRecipes.add(new Recipe("speed potion_1", "awkward potion_1", "Cactus_5")); + enchantRecipes.add(new Recipe("light potion_1", "awkward potion_1", "slime_5")); + enchantRecipes.add(new Recipe("swim potion_1", "awkward potion_1", "raw fish_5")); + enchantRecipes.add(new Recipe("haste potion_1", "awkward potion_1", "Wood_5", "Stone_5")); + enchantRecipes.add(new Recipe("lava potion_1", "awkward potion_1", "Lava Bucket_1")); + enchantRecipes.add(new Recipe("energy potion_1", "awkward potion_1", "gem_25")); + enchantRecipes.add(new Recipe("regen potion_1", "awkward potion_1", "Gold Apple_1")); + enchantRecipes.add(new Recipe("Health Potion_1", "awkward potion_1", "GunPowder_2", "Leather Armor_1")); + enchantRecipes.add(new Recipe("Escape Potion_1", "awkward potion_1", "GunPowder_3", "Lapis_7")); + enchantRecipes.add(new Recipe("Totem of Air_1", "gold_10", "gem_10", "Lapis_5", "Cloud Ore_5")); + enchantRecipes.add(new Recipe("Obsidian Poppet_1", "gold_10", "gem_10", "Lapis_5", "Shard_15")); + enchantRecipes.add(new Recipe("Arcane Fertilizer_3", "Lapis_6", "Bone_2")); + } +} diff --git a/src/client/java/minicraft/item/SummonItem.java b/src/client/java/minicraft/item/SummonItem.java index 15c0d286e..a39d4b2b0 100644 --- a/src/client/java/minicraft/item/SummonItem.java +++ b/src/client/java/minicraft/item/SummonItem.java @@ -56,10 +56,10 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, } } else { - Game.notifications.add(Localization.getLocalized("minicraft.notification.boss_limit")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.boss_limit")); } } else { - Game.notifications.add(Localization.getLocalized("minicraft.notification.wrong_level_sky")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.wrong_level_sky")); } break; @@ -85,16 +85,16 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, success = true; } } else { - Game.notifications.add(Localization.getLocalized("minicraft.notification.knight_statue_exists")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.knight_statue_exists")); } } else { - Game.notifications.add(Localization.getLocalized("minicraft.notification.boss_limit")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.boss_limit")); } } else { - Game.notifications.add(Localization.getLocalized("minicraft.notification.spawn_on_boss_tile")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.spawn_on_boss_tile")); } } else { - Game.notifications.add(Localization.getLocalized("minicraft.notification.wrong_level_dungeon")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.wrong_level_dungeon")); } break; default: diff --git a/src/client/java/minicraft/item/TileItem.java b/src/client/java/minicraft/item/TileItem.java index dad79ffee..242718083 100644 --- a/src/client/java/minicraft/item/TileItem.java +++ b/src/client/java/minicraft/item/TileItem.java @@ -154,7 +154,7 @@ else if ((model.tile.contains("BRICK") || model.tile.contains("PLANK") || model. } if (note.length() > 0) { - Game.notifications.add(note); + Game.inGameNotifications.add(note); } } diff --git a/src/client/java/minicraft/level/tile/BossDoorTile.java b/src/client/java/minicraft/level/tile/BossDoorTile.java index 581030dd5..700294d88 100644 --- a/src/client/java/minicraft/level/tile/BossDoorTile.java +++ b/src/client/java/minicraft/level/tile/BossDoorTile.java @@ -24,7 +24,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D ToolItem tool = (ToolItem) item; if (tool.type == type.getRequiredTool()) { if (player.payStamina(1)) { - Game.notifications.add(Localization.getLocalized(doorMsg)); + Game.inGameNotifications.add(Localization.getLocalized(doorMsg)); Sound.play("monsterhurt"); return true; } @@ -41,7 +41,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction attackDir) { if (source instanceof Player) { if (ObsidianKnight.active && !Game.isMode("minicraft.settings.mode.creative")) { - Game.notifications.add(doorMsg); + Game.inGameNotifications.add(doorMsg); return true; } } diff --git a/src/client/java/minicraft/level/tile/BossFloorTile.java b/src/client/java/minicraft/level/tile/BossFloorTile.java index b7ac654c5..0624a9a82 100644 --- a/src/client/java/minicraft/level/tile/BossFloorTile.java +++ b/src/client/java/minicraft/level/tile/BossFloorTile.java @@ -23,7 +23,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D ToolItem tool = (ToolItem) item; if (tool.type == type.getRequiredTool()) { if (player.payStamina(1)) { - Game.notifications.add(Localization.getLocalized(floorMsg)); + Game.inGameNotifications.add(Localization.getLocalized(floorMsg)); Sound.play("monsterhurt"); return true; } diff --git a/src/client/java/minicraft/level/tile/BossWallTile.java b/src/client/java/minicraft/level/tile/BossWallTile.java index 12d1ea05f..9b5136f62 100644 --- a/src/client/java/minicraft/level/tile/BossWallTile.java +++ b/src/client/java/minicraft/level/tile/BossWallTile.java @@ -29,7 +29,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D ToolItem tool = (ToolItem) item; if (tool.type == type.getRequiredTool()) { if (player.payStamina(1)) { - Game.notifications.add(Localization.getLocalized(wallMsg)); + Game.inGameNotifications.add(Localization.getLocalized(wallMsg)); Sound.play("monsterhurt"); return true; } diff --git a/src/client/java/minicraft/level/tile/HardRockTile.java b/src/client/java/minicraft/level/tile/HardRockTile.java index 07c18c4d2..ac4ab48aa 100644 --- a/src/client/java/minicraft/level/tile/HardRockTile.java +++ b/src/client/java/minicraft/level/tile/HardRockTile.java @@ -55,7 +55,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D return true; } } else { - Game.notifications.add("minicraft.notification.gem_pickaxe_required"); + Game.inGameNotifications.add("minicraft.notification.gem_pickaxe_required"); } } return false; diff --git a/src/client/java/minicraft/level/tile/WallTile.java b/src/client/java/minicraft/level/tile/WallTile.java index df986e62a..95828cfc0 100644 --- a/src/client/java/minicraft/level/tile/WallTile.java +++ b/src/client/java/minicraft/level/tile/WallTile.java @@ -51,7 +51,7 @@ public boolean hurt(Level level, int x, int y, Mob source, int dmg, Direction at hurt(level, x, y, 0); return true; } else { - Game.notifications.add(Localization.getLocalized(obrickMsg)); + Game.inGameNotifications.add(Localization.getLocalized(obrickMsg)); return false; } } @@ -72,7 +72,7 @@ public boolean interact(Level level, int xt, int yt, Player player, Item item, D return true; } } else { - Game.notifications.add(obrickMsg); + Game.inGameNotifications.add(obrickMsg); } } } diff --git a/src/client/java/minicraft/screen/AchievementsDisplay.java b/src/client/java/minicraft/screen/AchievementsDisplay.java index aceab7e75..6577b04dc 100644 --- a/src/client/java/minicraft/screen/AchievementsDisplay.java +++ b/src/client/java/minicraft/screen/AchievementsDisplay.java @@ -165,7 +165,7 @@ private static boolean setAchievement(String id, boolean unlocked, boolean save, achievementScore += a.score; // Tells the player that they got an achievement. - Game.notifications.add(Localization.getLocalized("minicraft.notification.achievement_unlocked", Localization.getLocalized(id))); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.achievement_unlocked", Localization.getLocalized(id))); } else achievementScore -= a.score; diff --git a/src/client/java/minicraft/screen/LoadingDisplay.java b/src/client/java/minicraft/screen/LoadingDisplay.java index 62c2e20d6..53ce2e80a 100644 --- a/src/client/java/minicraft/screen/LoadingDisplay.java +++ b/src/client/java/minicraft/screen/LoadingDisplay.java @@ -63,7 +63,7 @@ public void onExit() { msg = "minicraft.displays.loading.message.saving"; progressType = "minicraft.displays.loading.message.world"; new Save(WorldSelectDisplay.getWorldName()); - Game.notifications.clear(); + Game.inGameNotifications.clear(); } } diff --git a/src/client/java/minicraft/screen/Notification.java b/src/client/java/minicraft/screen/Notification.java new file mode 100644 index 000000000..4c2e85ca8 --- /dev/null +++ b/src/client/java/minicraft/screen/Notification.java @@ -0,0 +1,56 @@ +package minicraft.screen; + +import minicraft.core.io.Localization; +import minicraft.gfx.Color; +import minicraft.gfx.Font; +import minicraft.gfx.MinicraftImage; +import minicraft.gfx.Point; +import minicraft.gfx.Rectangle; +import minicraft.gfx.Screen; +import minicraft.screen.entry.StringEntry; + +import java.util.ArrayList; +import java.util.Arrays; + +public class Notification { + private static final int GAP = 10; + private static final int ANIMATION_TIME = 20; + + private final int expireTime; + private final Menu menu; + + private int tick = 0; + private int animationTick = 0; // 0 to ANIMATION_TIME, ANIMATION_TIME to 0 + + public Notification(String value) { + this(value, 240, Color.WHITE); + } // Default with 4 seconds + + public Notification(String value, int expireTime, int color) { + this.expireTime = expireTime; + menu = new Menu.Builder(true, 2, RelPos.RIGHT, + StringEntry.useLines(color, false, Font.getLines(value, + Screen.w - (GAP + MinicraftImage.boxWidth) * 2, Screen.h, 2))) + .setPositioning(new Point(Screen.w - GAP, Screen.h - GAP), RelPos.TOP_LEFT) + .createMenu(); + } + + public void tick() { + if (tick == 0 && animationTick < ANIMATION_TIME) animationTick++; + else if (tick < expireTime) tick++; + else if (tick == expireTime) animationTick--; + } + + public void render(Screen screen) { + Rectangle bounds = menu.getBounds(); + int width = bounds.getWidth(); + int curX = bounds.getLeft(); + int toX = Screen.w - (width + GAP) * animationTick / ANIMATION_TIME; // Shifting with animation (sliding) + menu.translate(toX - curX, 0); + menu.render(screen); + } + + public boolean isExpired() { + return tick >= expireTime && animationTick <= 0; + } +} diff --git a/src/client/java/minicraft/screen/TutorialDisplayHandler.java b/src/client/java/minicraft/screen/TutorialDisplayHandler.java index 1e86d9ea0..2475a15be 100644 --- a/src/client/java/minicraft/screen/TutorialDisplayHandler.java +++ b/src/client/java/minicraft/screen/TutorialDisplayHandler.java @@ -152,7 +152,7 @@ public static void turnOffTutorials() { currentOngoingElement = null; Settings.set("tutorials", false); Logging.TUTORIAL.debug("Tutorial completed."); - Game.notifications.add(Localization.getLocalized("minicraft.notification.tutorial_completed")); + Game.inGameNotifications.add(Localization.getLocalized("minicraft.notification.tutorial_completed")); } private static void turnOffGuides() {