diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/anvil.png b/Minecraft.Assets/Common/res/1_2_2/gui/anvil.png new file mode 100644 index 000000000..34e8f9f9f Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/gui/anvil.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/beacon.png b/Minecraft.Assets/Common/res/1_2_2/gui/beacon.png new file mode 100644 index 000000000..f51a2ef51 Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/gui/beacon.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/brewing_stand.png b/Minecraft.Assets/Common/res/1_2_2/gui/brewing_stand.png new file mode 100644 index 000000000..e7dc2031a Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/gui/brewing_stand.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/hopper.png b/Minecraft.Assets/Common/res/1_2_2/gui/hopper.png new file mode 100644 index 000000000..3d0054790 Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/gui/hopper.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/horse.png b/Minecraft.Assets/Common/res/1_2_2/gui/horse.png new file mode 100644 index 000000000..194cc6bf6 Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/gui/horse.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/inventory.png b/Minecraft.Assets/Common/res/1_2_2/gui/inventory.png index 4d9911690..d553c4f73 100644 Binary files a/Minecraft.Assets/Common/res/1_2_2/gui/inventory.png and b/Minecraft.Assets/Common/res/1_2_2/gui/inventory.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/gui/villager.png b/Minecraft.Assets/Common/res/1_2_2/gui/villager.png new file mode 100644 index 000000000..3211a7a00 Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/gui/villager.png differ diff --git a/Minecraft.Assets/Common/res/1_2_2/title/bg/panorama.png b/Minecraft.Assets/Common/res/1_2_2/title/bg/panorama.png new file mode 100644 index 000000000..65ae6070c Binary files /dev/null and b/Minecraft.Assets/Common/res/1_2_2/title/bg/panorama.png differ diff --git a/Minecraft.Assets/Common/res/lang/en_US.lang b/Minecraft.Assets/Common/res/lang/en_US.lang index 752a60f39..44040b2b7 100644 --- a/Minecraft.Assets/Common/res/lang/en_US.lang +++ b/Minecraft.Assets/Common/res/lang/en_US.lang @@ -435,6 +435,9 @@ tile.oreEmerald.name=Emerald Ore tile.blockEmerald.name=Block of Emerald tile.tripWire.name=Tripwire tile.tripWireSource.name=Tripwire Hook +tile.beacon.name=Beacon +tile.beacon.primary=Primary Power +tile.beacon.secondary=Secondary Power item.shovelIron.name=Iron Shovel item.pickaxeIron.name=Iron Pickaxe @@ -595,6 +598,9 @@ container.crafting=Crafting container.dispenser=Dispenser container.furnace=Furnace container.enchant=Enchant +container.repair=Repair & Name +container.repair.cost=Enchantment Cost: %d +container.repair.expensive=Too Expensive! container.creative=Item Selection container.brewing=Brewing Stand container.chest=Chest diff --git a/Minecraft.Client/GameState/Options.cpp b/Minecraft.Client/GameState/Options.cpp index 289fdecb0..07549b5c4 100644 --- a/Minecraft.Client/GameState/Options.cpp +++ b/Minecraft.Client/GameState/Options.cpp @@ -238,9 +238,8 @@ void Options::toggle(const Options::Option* option, int dir) { if (option == Option::PARTICLES) particles = (particles + dir) % 3; // 4J-PB - changing - // if (option == Option::VIEW_BOBBING) bobView = !bobView; - if (option == Option::VIEW_BOBBING) - ((dir == 0) ? bobView = false : bobView = true); + // 4jcraft: uncommented this so that the view bobbing option works + if (option == Option::VIEW_BOBBING) bobView = !bobView; if (option == Option::RENDER_CLOUDS) renderClouds = !renderClouds; if (option == Option::ADVANCED_OPENGL) { advancedOpengl = !advancedOpengl; diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 65d5e87dd..ee7ac2623 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -1965,13 +1965,16 @@ void Minecraft::run_middle() { // clear the stored button downs since the tick for this // player will now have actioned them player->ullButtonsPressed = 0LL; + } else if (screen != NULL) { + screen->updateEvents(); + // 4jcraft: this fixes the title screen panorama running + // faster than it should + if (!idx) { + screen->tick(); + } } } - if (screen != NULL) { - screen->updateEvents(); - } - ui.HandleGameTick(); setLocalPlayerIdx(ProfileManager.GetPrimaryPad()); diff --git a/Minecraft.Client/Network/ClientConnection.cpp b/Minecraft.Client/Network/ClientConnection.cpp index e41f43d77..78cc2c789 100644 --- a/Minecraft.Client/Network/ClientConnection.cpp +++ b/Minecraft.Client/Network/ClientConnection.cpp @@ -46,6 +46,7 @@ #include "../ClientConstants.h" #include "../../Minecraft.World/Util/SoundTypes.h" #include "../Textures/Packs/TexturePackRepository.h" +#include "UI/Screens/MerchantScreen.h" #ifdef _XBOX #include "../Platform/Common/XUI/XUI_Scene_Trading.h" #else @@ -3707,6 +3708,17 @@ void ClientConnection::handleCustomPayload( ByteArrayInputStream bais(customPayloadPacket->data); DataInputStream input(&bais); int containerId = input.readInt(); +#ifdef ENABLE_JAVA_GUIS + // 4jcraft: use the java gui getMerchant() to get trader as we don't + // have iggy's screen anymore + if (minecraft->screen && + dynamic_cast(minecraft->screen) && + containerId == minecraft->localplayers[m_userIndex] + ->containerMenu->containerId) { + std::shared_ptr trader = nullptr; + MerchantScreen* screen = (MerchantScreen*)minecraft->screen; + trader = screen->getMerchant(); +#else if (ui.IsSceneInStack(m_userIndex, eUIScene_TradingMenu) && containerId == minecraft->localplayers[m_userIndex] ->containerMenu->containerId) { @@ -3729,7 +3741,7 @@ void ClientConnection::handleCustomPayload( UIScene_TradingMenu* screen = (UIScene_TradingMenu*)scene; trader = screen->getMerchant(); #endif - +#endif MerchantRecipeList* recipeList = MerchantRecipeList::createFromStream(&input); trader->overrideOffers(recipeList); diff --git a/Minecraft.Client/Player/LocalPlayer.cpp b/Minecraft.Client/Player/LocalPlayer.cpp index a02033d66..442bb1f97 100644 --- a/Minecraft.Client/Player/LocalPlayer.cpp +++ b/Minecraft.Client/Player/LocalPlayer.cpp @@ -1,5 +1,12 @@ #include "../Platform/stdafx.h" #include "LocalPlayer.h" +#include "UI/Screens/BeaconScreen.h" +#include "UI/Screens/BrewingStandScreen.h" +#include "UI/Screens/EnchantmentScreen.h" +#include "UI/Screens/HopperScreen.h" +#include "UI/Screens/HorseInventoryScreen.h" +#include "UI/Screens/MerchantScreen.h" +#include "UI/Screens/RepairScreen.h" #include "User.h" #include "../Input/Input.h" #include "../GameState/StatsCounter.h" @@ -584,25 +591,36 @@ bool LocalPlayer::openContainer(std::shared_ptr container) { } bool LocalPlayer::openHopper(std::shared_ptr container) { - // minecraft->setScreen(new HopperScreen(inventory, container)); +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new HopperScreen(inventory, container)); + bool success = true; +#else bool success = app.LoadHopperMenu(GetXboxPad(), inventory, container); if (success) ui.PlayUISFX(eSFX_Press); +#endif return success; } bool LocalPlayer::openHopper(std::shared_ptr container) { - // minecraft->setScreen(new HopperScreen(inventory, container)); +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new HopperScreen(inventory, container)); + bool success = true; +#else bool success = app.LoadHopperMenu(GetXboxPad(), inventory, container); if (success) ui.PlayUISFX(eSFX_Press); +#endif return success; } bool LocalPlayer::openHorseInventory(std::shared_ptr horse, std::shared_ptr container) { - // minecraft->setScreen(new HorseInventoryScreen(inventory, container, - // horse)); +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new HorseInventoryScreen(inventory, container, horse)); + bool success = true; +#else bool success = app.LoadHorseMenu(GetXboxPad(), inventory, container, horse); if (success) ui.PlayUISFX(eSFX_Press); +#endif return success; } @@ -631,17 +649,20 @@ bool LocalPlayer::openFireworks(int x, int y, int z) { bool LocalPlayer::startEnchanting(int x, int y, int z, const std::wstring& name) { +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new EnchantmentScreen(inventory, level, x, y, z)); + bool success = true; +#else bool success = app.LoadEnchantingMenu(GetXboxPad(), inventory, x, y, z, level, name); if (success) ui.PlayUISFX(eSFX_Press); - // minecraft.setScreen(new EnchantmentScreen(inventory, level, x, y, z)); +#endif return success; } bool LocalPlayer::startRepairing(int x, int y, int z) { #ifdef ENABLE_JAVA_GUIS - // minecraft.setScreen(new RepairScreen(inventory, level, x, y, z)); - // FUCK YOU 4J FIRST AND FOREMOST + minecraft->setScreen(new RepairScreen(inventory, level, x, y, z)); bool success = true; #else bool success = @@ -664,33 +685,49 @@ bool LocalPlayer::openFurnace(std::shared_ptr furnace) { bool LocalPlayer::openBrewingStand( std::shared_ptr brewingStand) { +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new BrewingStandScreen(inventory, brewingStand)); + bool success = true; +#else bool success = app.LoadBrewingStandMenu(GetXboxPad(), inventory, brewingStand); if (success) ui.PlayUISFX(eSFX_Press); - // minecraft.setScreen(new BrewingStandScreen(inventory, brewingStand)); +#endif return success; } bool LocalPlayer::openBeacon(std::shared_ptr beacon) { - // minecraft->setScreen(new BeaconScreen(inventory, beacon)); +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new BeaconScreen(inventory, beacon)); + bool success = true; +#else bool success = app.LoadBeaconMenu(GetXboxPad(), inventory, beacon); if (success) ui.PlayUISFX(eSFX_Press); +#endif return success; } bool LocalPlayer::openTrap(std::shared_ptr trap) { +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new TrapScreen(inventory, trap)); + bool success = true; +#else bool success = app.LoadTrapMenu(GetXboxPad(), inventory, trap); if (success) ui.PlayUISFX(eSFX_Press); - // minecraft->setScreen(new TrapScreen(inventory, trap)); +#endif return success; } bool LocalPlayer::openTrading(std::shared_ptr traderTarget, const std::wstring& name) { +#ifdef ENABLE_JAVA_GUIS + minecraft->setScreen(new MerchantScreen(inventory, traderTarget, level)); + bool success = true; +#else bool success = app.LoadTradingMenu(GetXboxPad(), inventory, traderTarget, level, name); if (success) ui.PlayUISFX(eSFX_Press); - // minecraft.setScreen(new MerchantScreen(inventory, traderTarget, level)); +#endif return success; } diff --git a/Minecraft.Client/Textures/Texture.cpp b/Minecraft.Client/Textures/Texture.cpp index 5cd1fbbdd..5d54d9a09 100644 --- a/Minecraft.Client/Textures/Texture.cpp +++ b/Minecraft.Client/Textures/Texture.cpp @@ -471,10 +471,10 @@ void Texture::blit(int x, int y, Texture* source, bool rotated) { } void Texture::transferFromBuffer(intArray buffer) { - //if (depth == 1) { - // return; - //} - // 4jcraft - move pos out of loops + // if (depth == 1) { + // return; + // } + // 4jcraft - move pos out of loops data[0]->clear(); // #ifdef __PS3__ // int byteRemapRGBA[] = { 3, 0, 1, 2 }; @@ -487,7 +487,7 @@ void Texture::transferFromBuffer(intArray buffer) { int totalPixels = width * height * depth; - for (int i = 0; i < totalPixels; i++){ + for (int i = 0; i < totalPixels; i++) { int pixel = buffer[i]; int offset = i * 4; @@ -501,7 +501,7 @@ void Texture::transferFromBuffer(intArray buffer) { updateOnGPU(); } - + /* for (int z = 0; z < depth; z++) { int plane = z * height * width * 4; for (int y = 0; y < height; y++) { diff --git a/Minecraft.Client/Textures/Textures.cpp b/Minecraft.Client/Textures/Textures.cpp index d80099cca..907f51927 100644 --- a/Minecraft.Client/Textures/Textures.cpp +++ b/Minecraft.Client/Textures/Textures.cpp @@ -33,24 +33,12 @@ C4JRender::eTextureFormat Textures::TEXTURE_FORMAT = int Textures::preLoadedIdx[TN_COUNT]; const wchar_t* Textures::preLoaded[TN_COUNT] = { L"%blur%misc/pumpkinblur", - L"%blur%/misc/vignette", // Not currently used L"%clamp%misc/shadow", - L"/achievement/bg", // Not currently used L"art/kz", L"environment/clouds", L"environment/rain", L"environment/snow", L"gui/gui", - L"gui/background", - L"gui/inventory", - L"gui/container", - L"gui/crafting", - L"gui/furnace", - L"gui/creative_inventory/tabs", - L"gui/creative_inventory/tab_items", - L"gui/creative_inventory/tab_inventory", - L"gui/creative_inventory/tab_item_search", - L"title/mclogo", L"gui/icons", L"item/arrows", L"item/boat", @@ -174,6 +162,37 @@ const wchar_t* Textures::preLoaded[TN_COUNT] = { L"item/trapped", L"item/trapped_double", + +// 4jcraft: java UI specific +#ifdef ENABLE_JAVA_GUIS + L"%blur%/misc/vignette", + L"/achievement/bg", + L"gui/background", + L"gui/inventory", + L"gui/container", + L"gui/crafting", + L"gui/furnace", + L"gui/creative_inventory/tabs", + L"gui/creative_inventory/tab_items", + L"gui/creative_inventory/tab_inventory", + L"gui/creative_inventory/tab_item_search", + L"title/mclogo", + L"gui/horse", + L"gui/anvil", + L"gui/trap", + L"gui/beacon", + L"gui/hopper", + L"gui/enchant", + L"gui/villager", + L"gui/brewing_stand", + L"title/bg/panorama", + L"title/bg/panorama0", + L"title/bg/panorama1", + L"title/bg/panorama2", + L"title/bg/panorama3", + L"title/bg/panorama4", + L"title/bg/panorama5", +#endif // L"item/christmas", // L"item/christmas_double", @@ -1486,4 +1505,4 @@ bool Textures::IsOriginalImage(TEXTURE_NAME texId, const std::wstring& name) { i++; } return false; -} +} \ No newline at end of file diff --git a/Minecraft.Client/Textures/Textures.h b/Minecraft.Client/Textures/Textures.h index 46a86b603..fd59fc66b 100644 --- a/Minecraft.Client/Textures/Textures.h +++ b/Minecraft.Client/Textures/Textures.h @@ -16,24 +16,12 @@ class ResourceLocation; typedef enum _TEXTURE_NAME { TN__BLUR__MISC_PUMPKINBLUR, - TN__BLUR__MISC_VIGNETTE, // Not currently used TN__CLAMP__MISC_SHADOW, - TN_ACHIEVEMENT_BG, // Not currently used TN_ART_KZ, TN_ENVIRONMENT_CLOUDS, TN_ENVIRONMENT_RAIN, TN_ENVIRONMENT_SNOW, TN_GUI_GUI, - TN_GUI_BACKGROUND, - TN_GUI_INVENTORY, - TN_GUI_CONTAINER, - TN_GUI_CRAFTING, - TN_GUI_FURNACE, - TN_GUI_CREATIVE_TABS, - TN_GUI_CREATIVE_TAB_ITEMS, - TN_GUI_CREATIVE_TAB_INVENTORY, - TN_GUI_CREATIVE_TAB_ITEM_SEARCH, - TN_TITLE_MCLOGO, TN_GUI_ICONS, TN_ITEM_ARROWS, TN_ITEM_BOAT, @@ -156,6 +144,37 @@ typedef enum _TEXTURE_NAME { TN_TILE_TRAP_CHEST, TN_TILE_LARGE_TRAP_CHEST, + +// 4jcraft: java UI specific +#ifdef ENABLE_JAVA_GUIS + TN__BLUR__MISC_VIGNETTE, + TN_ACHIEVEMENT_BG, + TN_GUI_BACKGROUND, + TN_GUI_INVENTORY, + TN_GUI_CONTAINER, + TN_GUI_CRAFTING, + TN_GUI_FURNACE, + TN_GUI_CREATIVE_TABS, + TN_GUI_CREATIVE_TAB_ITEMS, + TN_GUI_CREATIVE_TAB_INVENTORY, + TN_GUI_CREATIVE_TAB_ITEM_SEARCH, + TN_TITLE_MCLOGO, + TN_GUI_HORSE, + TN_GUI_ANVIL, + TN_GUI_TRAP, + TN_GUI_BEACON, + TN_GUI_HOPPER, + TN_GUI_ENCHANT, + TN_GUI_VILLAGER, + TN_GUI_BREWING_STAND, + TN_TITLE_BG_PANORAMA, + TN_TITLE_BG_PANORAMA0, + TN_TITLE_BG_PANORAMA1, + TN_TITLE_BG_PANORAMA2, + TN_TITLE_BG_PANORAMA3, + TN_TITLE_BG_PANORAMA4, + TN_TITLE_BG_PANORAMA5, +#endif // TN_TILE_XMAS_CHEST, // TN_TILE_LARGE_XMAS_CHEST, @@ -352,4 +371,4 @@ public: // drive static bool IsTUImage(TEXTURE_NAME texId, const std::wstring& name); static bool IsOriginalImage(TEXTURE_NAME texId, const std::wstring& name); -}; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/AbstractBeaconButton.cpp b/Minecraft.Client/UI/AbstractBeaconButton.cpp new file mode 100644 index 000000000..92b49e881 --- /dev/null +++ b/Minecraft.Client/UI/AbstractBeaconButton.cpp @@ -0,0 +1,46 @@ +#include "../../Platform/stdafx.h" +#include "AbstractBeaconButton.h" +#include "../Textures/Textures.h" +#include "../../../Minecraft.Client/Minecraft.h" +#include + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) +#ifdef ENABLE_JAVA_GUIS +extern ResourceLocation GUI_BEACON_LOCATION; +#endif + +AbstractBeaconButton::AbstractBeaconButton(int id, int x, int y) + : Button(id, x, y, 22, 22, L"") { + hovered = false; + selected = false; + iconRes = nullptr; + iconU = iconV = 0; +} + +void AbstractBeaconButton::renderBg(Minecraft* minecraft, int xm, int ym) { +#ifdef ENABLE_JAVA_GUIS + if (!visible) return; + + hovered = (xm >= x && ym >= y && xm < x + w && ym < y + h); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + minecraft->textures->bindTexture(&GUI_BEACON_LOCATION); + + int texU = 0; + if (!active) { + texU += w * 2; + } else if (selected) { + texU += w * 1; + } else if (hovered) { + texU += w * 3; + } + int texV = 219; + + blit(x, y, texU, texV, w, h); + + if (iconRes != nullptr && iconRes != &GUI_BEACON_LOCATION) { + minecraft->textures->bindTexture(iconRes); + } + blit(x + 2, y + 2, iconU, iconV, 18, 18); +#endif +} \ No newline at end of file diff --git a/Minecraft.Client/UI/AbstractBeaconButton.h b/Minecraft.Client/UI/AbstractBeaconButton.h new file mode 100644 index 000000000..3254f4912 --- /dev/null +++ b/Minecraft.Client/UI/AbstractBeaconButton.h @@ -0,0 +1,24 @@ +#pragma once +#include "Button.h" + +class ResourceLocation; + +class AbstractBeaconButton : public Button { +protected: + bool hovered; + bool selected; + ResourceLocation* iconRes; + int iconU, iconV; + +public: + AbstractBeaconButton(int id, int x, int y); + + void setSelected(bool sel) { selected = sel; } + bool isSelected() const { return selected; } + bool isHovered() const { return hovered; } + + virtual void renderTooltip(int xm, int ym) = 0; + +protected: + virtual void renderBg(Minecraft* minecraft, int xm, int ym) override; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/BeaconCancelButton.cpp b/Minecraft.Client/UI/BeaconCancelButton.cpp new file mode 100644 index 000000000..081029e4c --- /dev/null +++ b/Minecraft.Client/UI/BeaconCancelButton.cpp @@ -0,0 +1,25 @@ +#include "../../Platform/stdafx.h" +#include "BeaconCancelButton.h" +#include "Screens/BeaconScreen.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) +#ifdef ENABLE_JAVA_GUIS +extern ResourceLocation GUI_BEACON_LOCATION; +#endif + +BeaconCancelButton::BeaconCancelButton(BeaconScreen* screen, int id, int x, + int y) + : AbstractBeaconButton(id, x, y) { + this->screen = screen; +#ifdef ENABLE_JAVA_GUIS + this->iconRes = &GUI_BEACON_LOCATION; +#endif + this->iconU = 112; + this->iconV = 220; +} + +void BeaconCancelButton::renderTooltip(int xm, int ym) { + screen->renderTooltip(Language::getInstance()->getElement(L"gui.cancel"), + xm, ym); +} \ No newline at end of file diff --git a/Minecraft.Client/UI/BeaconCancelButton.h b/Minecraft.Client/UI/BeaconCancelButton.h new file mode 100644 index 000000000..f9d62456e --- /dev/null +++ b/Minecraft.Client/UI/BeaconCancelButton.h @@ -0,0 +1,13 @@ +#pragma once +#include "AbstractBeaconButton.h" + +class BeaconScreen; + +class BeaconCancelButton : public AbstractBeaconButton { +public: + BeaconCancelButton(BeaconScreen* screen, int id, int x, int y); + void renderTooltip(int xm, int ym) override; + +private: + BeaconScreen* screen; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/BeaconConfirmButton.cpp b/Minecraft.Client/UI/BeaconConfirmButton.cpp new file mode 100644 index 000000000..00871f6e1 --- /dev/null +++ b/Minecraft.Client/UI/BeaconConfirmButton.cpp @@ -0,0 +1,25 @@ +#include "../../Platform/stdafx.h" +#include "BeaconConfirmButton.h" +#include "Screens/BeaconScreen.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) +#ifdef ENABLE_JAVA_GUIS +extern ResourceLocation GUI_BEACON_LOCATION; +#endif + +BeaconConfirmButton::BeaconConfirmButton(BeaconScreen* screen, int id, int x, + int y) + : AbstractBeaconButton(id, x, y) { + this->screen = screen; +#ifdef ENABLE_JAVA_GUIS + this->iconRes = &GUI_BEACON_LOCATION; +#endif + this->iconU = 90; + this->iconV = 220; +} + +void BeaconConfirmButton::renderTooltip(int xm, int ym) { + screen->renderTooltip(Language::getInstance()->getElement(L"gui.done"), xm, + ym); +} \ No newline at end of file diff --git a/Minecraft.Client/UI/BeaconConfirmButton.h b/Minecraft.Client/UI/BeaconConfirmButton.h new file mode 100644 index 000000000..ab1d28177 --- /dev/null +++ b/Minecraft.Client/UI/BeaconConfirmButton.h @@ -0,0 +1,13 @@ +#pragma once +#include "AbstractBeaconButton.h" + +class BeaconScreen; + +class BeaconConfirmButton : public AbstractBeaconButton { +public: + BeaconConfirmButton(BeaconScreen* screen, int id, int x, int y); + void renderTooltip(int xm, int ym) override; + +private: + BeaconScreen* screen; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/BeaconPowerButton.cpp b/Minecraft.Client/UI/BeaconPowerButton.cpp new file mode 100644 index 000000000..958badfe7 --- /dev/null +++ b/Minecraft.Client/UI/BeaconPowerButton.cpp @@ -0,0 +1,39 @@ +#include "../../Platform/stdafx.h" +#include "BeaconPowerButton.h" +#include "Screens/BeaconScreen.h" +#include "../../../Minecraft.World/Entities/MobEffect.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../Textures/Textures.h" +#include "Textures/ResourceLocation.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_INVENTORY_LOCATION = ResourceLocation(TN_GUI_INVENTORY); +#endif + +BeaconPowerButton::BeaconPowerButton(BeaconScreen* screen, int id, int x, int y, + int effectId, int tier) + : AbstractBeaconButton(id, x, y) { + this->screen = screen; + this->effectId = effectId; + this->tier = tier; + +#ifdef ENABLE_JAVA_GUIS + this->iconRes = &GUI_INVENTORY_LOCATION; +#endif + + int statusIconIndex = MobEffect::javaId(effectId); + this->iconU = (statusIconIndex % 8) * 18; + this->iconV = 198 + (statusIconIndex / 8) * 18; +} + +void BeaconPowerButton::renderTooltip(int xm, int ym) { + MobEffect* effect = MobEffect::effects[effectId]; + if (!effect) return; + + std::wstring name = app.GetString(effect->getDescriptionId()); + if (tier >= 3 && effect->id != MobEffect::regeneration->id) { + name += L" II"; + } + screen->renderTooltip(name, xm, ym); +} \ No newline at end of file diff --git a/Minecraft.Client/UI/BeaconPowerButton.h b/Minecraft.Client/UI/BeaconPowerButton.h new file mode 100644 index 000000000..fc6e40266 --- /dev/null +++ b/Minecraft.Client/UI/BeaconPowerButton.h @@ -0,0 +1,18 @@ +#pragma once +#include "AbstractBeaconButton.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.effect.h" + +class BeaconScreen; + +class BeaconPowerButton : public AbstractBeaconButton { +public: + BeaconPowerButton(BeaconScreen* screen, int id, int x, int y, int effectId, + int tier); + void renderTooltip(int xm, int ym) override; + bool isSelected() const { return selected; } + +private: + BeaconScreen* screen; + int effectId; + int tier; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Button.cpp b/Minecraft.Client/UI/Button.cpp index 09630ed6b..ced455e3b 100644 --- a/Minecraft.Client/UI/Button.cpp +++ b/Minecraft.Client/UI/Button.cpp @@ -2,6 +2,10 @@ #include "Button.h" #include "../Textures/Textures.h" +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_GUI_LOCATION = ResourceLocation(TN_GUI_GUI); +#endif + Button::Button(int id, int x, int y, const std::wstring& msg) { init(id, x, y, 200, 20, msg); } @@ -34,12 +38,14 @@ int Button::getYImage(bool hovered) { } void Button::render(Minecraft* minecraft, int xm, int ym) { +#ifdef ENABLE_JAVA_GUIS if (!visible) return; Font* font = minecraft->font; - glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture( - TN_GUI_GUI)); // 4J was L"/gui/gui.png" + // glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture( + // TN_GUI_GUI)); // 4J was L"/gui/gui.png" + minecraft->textures->bindTexture(&GUI_GUI_LOCATION); glColor4f(1, 1, 1, 1); bool hovered = xm >= x && ym >= y && xm < x + w && ym < y + h; @@ -59,6 +65,7 @@ void Button::render(Minecraft* minecraft, int xm, int ym) { drawCenteredString(font, msg, x + w / 2, y + (h - 8) / 2, 0xe0e0e0); } } +#endif } void Button::renderBg(Minecraft* minecraft, int xm, int ym) {} diff --git a/Minecraft.Client/UI/EditBox.cpp b/Minecraft.Client/UI/EditBox.cpp index 2ce3d3224..da48457e7 100644 --- a/Minecraft.Client/UI/EditBox.cpp +++ b/Minecraft.Client/UI/EditBox.cpp @@ -7,6 +7,9 @@ EditBox::EditBox(Screen* screen, Font* font, int x, int y, int width, // 4J - added initialisers maxLength = 0; frame = 0; + enableBackgroundDrawing = + true; // 4jcraft: for toggling the background rendering (from 1.6.4, + // mainly for RepairScreen) this->screen = screen; this->font = font; @@ -68,18 +71,36 @@ void EditBox::focus(bool newFocus) { } void EditBox::render() { - fill(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0); - fill(x, y, x + width, y + height, 0xff000000); + // 4jcraft: render the background conditionally + if (enableBackgroundDrawing) { + fill(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0); + fill(x, y, x + width, y + height, 0xff000000); + } + + // 4jcraft: offset conditionally + int textX = x; + int textY = y; + if (enableBackgroundDrawing) { + textX += 4; + textY += (height - 8) / 2; + } if (active) { bool renderUnderscore = inFocus && (frame / 6 % 2 == 0); - drawString(font, value + (renderUnderscore ? L"_" : L""), x + 4, - y + (height - 8) / 2, 0xe0e0e0); + drawString(font, value + (renderUnderscore ? L"_" : L""), textX, textY, + (enableBackgroundDrawing ? 0xe0e0e0 : 0xffffff)); } else { - drawString(font, value, x + 4, y + (height - 8) / 2, 0x707070); + drawString(font, value, textX, textY, + (enableBackgroundDrawing ? 0xe0e0e0 : 0xffffff)); } } void EditBox::setMaxLength(int maxLength) { this->maxLength = maxLength; } -int EditBox::getMaxLength() { return maxLength; } \ No newline at end of file +int EditBox::getMaxLength() { return maxLength; } + +// 4jcraft: for toggling the background rendering (from 1.6.4, mainly for +// RepairScreen) +void EditBox::setEnableBackgroundDrawing(bool enable) { + enableBackgroundDrawing = enable; +} \ No newline at end of file diff --git a/Minecraft.Client/UI/EditBox.h b/Minecraft.Client/UI/EditBox.h index 1b78d424f..133bfc0f8 100644 --- a/Minecraft.Client/UI/EditBox.h +++ b/Minecraft.Client/UI/EditBox.h @@ -18,6 +18,8 @@ private: public: bool inFocus; bool active; + bool enableBackgroundDrawing; // 4jcraft: for toggling the background + // rendering (mainly for RepairScreen) private: Screen* screen; @@ -34,4 +36,7 @@ public: void render(); void setMaxLength(int maxLength); int getMaxLength(); + + // 4jcraft: for toggling the background rendering (mainly for RepairScreen) + void setEnableBackgroundDrawing(bool enable); }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Gui.cpp b/Minecraft.Client/UI/Gui.cpp index 8d9d12071..dea90b73c 100644 --- a/Minecraft.Client/UI/Gui.cpp +++ b/Minecraft.Client/UI/Gui.cpp @@ -56,6 +56,10 @@ Gui::Gui(Minecraft* minecraft) { tbr = 1.0f; fAlphaIncrementPerCent = 255.0f / 100.0f; + // 4jcraft: backported item switch tooltip display from 1.6.4 + remainingHighlightTicks = 0; + highlightingItemStack = nullptr; + this->minecraft = minecraft; lastTickA = 0.0f; @@ -816,6 +820,31 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { } #if RENDER_HUD + // 4jcraft: backported item switch tooltip display from 1.6.4 + if (remainingHighlightTicks > 0 && highlightingItemStack != nullptr) { + std::wstring displayName = highlightingItemStack->getHoverName(); + int x = (screenWidth - font->width(displayName)) / 2; + int y = screenHeight - 89; + + if (!minecraft->gameMode->canHurtPlayer()) { + y += 14; + } + + int alpha = (int)((float)remainingHighlightTicks * 256.0f / 10.0f); + if (alpha > 255) alpha = 255; + if (alpha > 0) { + glPushMatrix(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + int color = 0xFFFFFF | (alpha << 24); + font->drawShadow(displayName, x, y, color); + + glDisable(GL_BLEND); + glPopMatrix(); + } + } + // Moved so the opacity blend is applied to it if (bDisplayGui && minecraft->gameMode->hasExperience() && minecraft->player->experienceLevel > 0) { @@ -1320,7 +1349,8 @@ void Gui::renderSlot(int slot, int x, int y, float a) { } itemRenderer->renderAndDecorateItem(minecraft->font, minecraft->textures, - item, x, y); + item, x, y, 1.0f, 1.0f, 1.0f, + item->isFoil(), false); if (pop > 0) { glPopMatrix(); @@ -1334,6 +1364,27 @@ void Gui::tick() { if (overlayMessageTime > 0) overlayMessageTime--; tickCount++; + // 4jcraft: backported item switch tooltip display from 1.6.4 + if (minecraft->player != nullptr) { + std::shared_ptr currentItem = + minecraft->player->inventory->getSelected(); + + if (currentItem == nullptr) { + remainingHighlightTicks = 0; + } else if (highlightingItemStack != nullptr && + currentItem->id == highlightingItemStack->id && + currentItem->sameItemWithTags(highlightingItemStack) && + (currentItem->isDamageableItem() || + currentItem->getDamageValue() == + highlightingItemStack->getDamageValue())) { + if (remainingHighlightTicks > 0) --remainingHighlightTicks; + } else { + remainingHighlightTicks = 40; + } + + highlightingItemStack = currentItem; + } + for (int iPad = 0; iPad < XUSER_MAX_COUNT; iPad++) { // 4J Stu - Fix for #10929 - MP LAB: Network Disconnects: Host does not // receive an error message stating the client left the game when diff --git a/Minecraft.Client/UI/Gui.h b/Minecraft.Client/UI/Gui.h index 81ee2b5f8..4077c9c40 100644 --- a/Minecraft.Client/UI/Gui.h +++ b/Minecraft.Client/UI/Gui.h @@ -2,9 +2,9 @@ #include #include "GuiComponent.h" #include "GuiMessage.h" +#include "../../../Minecraft.Client/Rendering/EntityRenderers/ItemRenderer.h" class Random; class Minecraft; -class ItemRenderer; class Gui : public GuiComponent { private: @@ -34,6 +34,10 @@ private: float lastTickA; float fAlphaIncrementPerCent; + // 4jcraft: backported item switch tooltip display from 1.6.4 + int remainingHighlightTicks; + std::shared_ptr highlightingItemStack; + public: static float currentGuiBlendFactor; // 4J added static float currentGuiScaleFactor; // 4J added diff --git a/Minecraft.Client/UI/Screen.cpp b/Minecraft.Client/UI/Screen.cpp index c3260a893..d0d0a744c 100644 --- a/Minecraft.Client/UI/Screen.cpp +++ b/Minecraft.Client/UI/Screen.cpp @@ -174,7 +174,6 @@ void Screen::renderBackground(int vo) { } void Screen::renderDirtBackground(int vo) { - // 4J Unused - Iggy Flash UI renders the background on consoles #ifdef ENABLE_JAVA_GUIS glDisable(GL_LIGHTING); glDisable(GL_FOG); diff --git a/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp b/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp index bf608e7ee..00a7e81f1 100644 --- a/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp +++ b/Minecraft.Client/UI/Screens/AbstractContainerScreen.cpp @@ -95,138 +95,11 @@ void AbstractContainerScreen::render(int xm, int ym, float a) { hoveredSlot->hasItem()) { std::shared_ptr item = hoveredSlot->getItem(); - // std::wstring elementName = - // trimString(Language::getInstance()->getElementName(hoveredSlot->getItem()->getDescriptionId())); - std::vector elementName; - std::vector* tooltipLines = - item->getHoverText(minecraft->player, false, elementName); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; - if (tooltipLines != NULL && tooltipLines->size() > 0) { - int tooltipWidth = 0; - std::vector cleanedLines; - std::vector lineColors; - - for (int lineIndex = 0; lineIndex < (int)tooltipLines->size(); - ++lineIndex) { - std::wstring rawLine = (*tooltipLines)[lineIndex]; - std::wstring clean = L""; - int lineColor = 0xffffffff; - - // 4jcraft: LCE is using HTML font elements for its tooltip - // colors, so make sure to parse them for parity w iggy UI - // - // examples would be enchantment books, potions and music - // discs - size_t fontPos = rawLine.find(L"') { - inTag = false; - } else if (!inTag) { - clean += currentChar; - } - } - - cleanedLines.push_back(clean); - lineColors.push_back(lineColor); - - int lineWidth = font->width(clean); - if (lineWidth > tooltipWidth) { - tooltipWidth = lineWidth; - } - } - - int tooltipX = xm - xo + 12; - int tooltipY = ym - yo - 12; - - int tooltipHeight = 8; - - if (tooltipLines->size() > 1) { - tooltipHeight += 2 + (tooltipLines->size() - 1) * 10; - } - - int bgColor = 0xf0100010; - fillGradient(tooltipX - 3, tooltipY - 4, - tooltipX + tooltipWidth + 3, tooltipY - 3, bgColor, - bgColor); - fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 3, - tooltipX + tooltipWidth + 3, - tooltipY + tooltipHeight + 4, bgColor, bgColor); - fillGradient(tooltipX - 3, tooltipY - 3, - tooltipX + tooltipWidth + 3, - tooltipY + tooltipHeight + 3, bgColor, bgColor); - fillGradient(tooltipX - 4, tooltipY - 3, tooltipX - 3, - tooltipY + tooltipHeight + 3, bgColor, bgColor); - fillGradient(tooltipX + tooltipWidth + 3, tooltipY - 3, - tooltipX + tooltipWidth + 4, - tooltipY + tooltipHeight + 3, bgColor, bgColor); - - int borderStart = 0x505000ff; - int borderFinish = - (borderStart & 0xfefefe) >> 1 | borderStart & 0xff000000; - fillGradient(tooltipX - 3, (tooltipY - 3) + 1, (tooltipX - 3) + 1, - (tooltipY + tooltipHeight + 3) - 1, borderStart, - borderFinish); - fillGradient(tooltipX + tooltipWidth + 2, (tooltipY - 3) + 1, - tooltipX + tooltipWidth + 3, - (tooltipY + tooltipHeight + 3) - 1, borderStart, - borderFinish); - fillGradient(tooltipX - 3, tooltipY - 3, - tooltipX + tooltipWidth + 3, (tooltipY - 3) + 1, - borderStart, borderStart); - fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2, - tooltipX + tooltipWidth + 3, - tooltipY + tooltipHeight + 3, borderFinish, - borderFinish); - - int currentY = tooltipY; - for (int lineIndex = 0; lineIndex < (int)tooltipLines->size(); - ++lineIndex) { - std::wstring& currentLine = cleanedLines[lineIndex]; - int textColor; - - if (lineIndex == 0) { - textColor = app.GetHTMLColour(item->getRarity()->color); - } else { - textColor = (lineColors[lineIndex] != 0xffffffff) - ? lineColors[lineIndex] - : 0xffaaaaaa; - } - - font->drawShadow(currentLine, tooltipX, currentY, textColor); - - if (lineIndex == 0) { - currentY += 2; - } - - currentY += 10; - } - } + // 4jcraft: abstracted tooltip rendering into a new method + renderTooltip(item, xm - xo, ym - yo); } glPopMatrix(); @@ -237,10 +110,167 @@ void AbstractContainerScreen::render(int xm, int ym, float a) { #endif } +// 4jcraft: extracted from render() into a standalone method so this can be used +// in other derived classes +// update: also added 1.6.x era overloads (for the creative inventory and other +// places) +void AbstractContainerScreen::renderTooltipInternal( + const std::vector& cleanedLines, + const std::vector& lineColors, int xm, int ym) { + if (cleanedLines.empty()) return; + + int tooltipWidth = 0; + for (const auto& line : cleanedLines) { + int lineWidth = font->width(line); + if (lineWidth > tooltipWidth) tooltipWidth = lineWidth; + } + + int tooltipX = xm + 12; + int tooltipY = ym - 12; + int tooltipHeight = 8; + + if (cleanedLines.size() > 1) { + tooltipHeight += 2 + (cleanedLines.size() - 1) * 10; + } + + int bgColor = 0xf0100010; + fillGradient(tooltipX - 3, tooltipY - 4, tooltipX + tooltipWidth + 3, + tooltipY - 3, bgColor, bgColor); + fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 3, + tooltipX + tooltipWidth + 3, tooltipY + tooltipHeight + 4, + bgColor, bgColor); + fillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, + tooltipY + tooltipHeight + 3, bgColor, bgColor); + fillGradient(tooltipX - 4, tooltipY - 3, tooltipX - 3, + tooltipY + tooltipHeight + 3, bgColor, bgColor); + fillGradient(tooltipX + tooltipWidth + 3, tooltipY - 3, + tooltipX + tooltipWidth + 4, tooltipY + tooltipHeight + 3, + bgColor, bgColor); + + int borderStart = 0x505000ff; + int borderFinish = (borderStart & 0xfefefe) >> 1 | borderStart & 0xff000000; + fillGradient(tooltipX - 3, (tooltipY - 3) + 1, (tooltipX - 3) + 1, + (tooltipY + tooltipHeight + 3) - 1, borderStart, borderFinish); + fillGradient(tooltipX + tooltipWidth + 2, (tooltipY - 3) + 1, + tooltipX + tooltipWidth + 3, + (tooltipY + tooltipHeight + 3) - 1, borderStart, borderFinish); + fillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, + (tooltipY - 3) + 1, borderStart, borderStart); + fillGradient(tooltipX - 3, tooltipY + tooltipHeight + 2, + tooltipX + tooltipWidth + 3, tooltipY + tooltipHeight + 3, + borderFinish, borderFinish); + + int currentY = tooltipY; + for (size_t lineIndex = 0; lineIndex < cleanedLines.size(); ++lineIndex) { + const std::wstring& currentLine = cleanedLines[lineIndex]; + int textColor = lineColors[lineIndex]; + + font->drawShadow(currentLine, tooltipX, currentY, textColor); + + if (lineIndex == 0) { + currentY += 2; + } + currentY += 10; + } +} + +void AbstractContainerScreen::renderTooltip(std::shared_ptr item, + int xm, int ym) { + if (item == nullptr) return; + + std::vector elementName; + std::vector* tooltipLines = + item->getHoverText(minecraft->player, false, elementName); + + if (tooltipLines != NULL && tooltipLines->size() > 0) { + std::vector cleanedLines; + std::vector lineColors; + + for (int lineIndex = 0; lineIndex < (int)tooltipLines->size(); + ++lineIndex) { + std::wstring rawLine = (*tooltipLines)[lineIndex]; + std::wstring clean = L""; + int lineColor = 0xffffffff; + + // 4jcraft: LCE is using HTML font elements for its tooltip + // colors, so make sure to parse them for parity w iggy UI + // + // examples would be enchantment books, potions and music + // discs + size_t fontPos = rawLine.find(L"') { + inTag = false; + } else if (!inTag) { + clean += currentChar; + } + } + + cleanedLines.push_back(clean); + lineColors.push_back(lineColor); + } + + if (!cleanedLines.empty()) { + lineColors[0] = app.GetHTMLColour(item->getRarity()->color); + } + + renderTooltipInternal(cleanedLines, lineColors, xm, ym); + } +} + +void AbstractContainerScreen::renderTooltip( + const std::vector& lines, int xm, int ym) { + if (lines.empty()) return; + + std::vector cleanedLines = lines; + std::vector lineColors; + lineColors.reserve(lines.size()); + + for (size_t i = 0; i < lines.size(); ++i) { + if (i == 0) { + lineColors.push_back(0xffffffff); + } else { + lineColors.push_back(0xffaaaaaa); + } + } + + renderTooltipInternal(cleanedLines, lineColors, xm, ym); +} + +void AbstractContainerScreen::renderTooltip(const std::wstring& line, int xm, + int ym) { + renderTooltip(std::vector{line}, xm, ym); +} + void AbstractContainerScreen::renderLabels() {} void AbstractContainerScreen::renderSlot(Slot* slot) { - // 4J Unused #if ENABLE_JAVA_GUIS int x = slot->x; int y = slot->y; @@ -278,14 +308,20 @@ Slot* AbstractContainerScreen::findSlot(int x, int y) { return NULL; } -bool AbstractContainerScreen::isHovering(Slot* slot, int xm, int ym) { +// 4jcraft: equivalent to MCP 8.11 (1.6.x)'s GuiContainer.isPointInRegion() for +// use in other derived classes +bool AbstractContainerScreen::isHoveringOver(int x, int y, int w, int h, int xm, + int ym) { int xo = (width - imageWidth) / 2; int yo = (height - imageHeight) / 2; xm -= xo; ym -= yo; - return xm >= slot->x - 1 && xm < slot->x + 16 + 1 && ym >= slot->y - 1 && - ym < slot->y + 16 + 1; + return xm >= x - 1 && xm < x + w + 1 && ym >= y - 1 && ym < y + h + 1; +} + +bool AbstractContainerScreen::isHovering(Slot* slot, int xm, int ym) { + return isHoveringOver(slot->x, slot->y, 16, 16, xm, ym); } void AbstractContainerScreen::mouseClicked(int x, int y, int buttonNum) { diff --git a/Minecraft.Client/UI/Screens/AbstractContainerScreen.h b/Minecraft.Client/UI/Screens/AbstractContainerScreen.h index ace3ec4bf..462e178d5 100644 --- a/Minecraft.Client/UI/Screens/AbstractContainerScreen.h +++ b/Minecraft.Client/UI/Screens/AbstractContainerScreen.h @@ -6,7 +6,8 @@ class Slot; class Container; class AbstractContainerScreen : public Screen { -private: +protected: + // 4jcraft: made protected to match JE 1.6.4 static ItemRenderer* itemRenderer; protected: @@ -17,8 +18,8 @@ public: AbstractContainerMenu* menu; AbstractContainerScreen(AbstractContainerMenu* menu); - virtual void init(); - virtual void render(int xm, int ym, float a); + virtual void init() override; + virtual void render(int xm, int ym, float a) override; protected: virtual void renderLabels(); @@ -27,19 +28,34 @@ protected: // can call findSlot() and isHovering() directly for its custom click // handling. virtual Slot* findSlot(int x, int y); + // 4jcraft: equivalent to MCP 8.11 (1.6.x)'s GuiContainer.isPointInRegion() + // for use in other derived classes + virtual bool isHoveringOver(int x, int y, int w, int h, int xm, int ym); virtual bool isHovering(Slot* slot, int xm, int ym); + // 4jcraft: extracted from render() into a standalone method so this can be + // used in other places + virtual void renderTooltipInternal( + const std::vector& cleanedLines, + const std::vector& lineColors, int xm, int ym); + virtual void renderTooltip(std::shared_ptr item, int xm, + int ym); private: virtual void renderSlot(Slot* slot); protected: - virtual void mouseClicked(int x, int y, int buttonNum); - virtual void mouseReleased(int x, int y, int buttonNum); - virtual void keyPressed(wchar_t eventCharacter, int eventKey); + virtual void mouseClicked(int x, int y, int buttonNum) override; + virtual void mouseReleased(int x, int y, int buttonNum) override; + virtual void keyPressed(wchar_t eventCharacter, int eventKey) override; public: - virtual void removed(); + virtual void removed() override; virtual void slotsChanged(std::shared_ptr container); - virtual bool isPauseScreen(); - virtual void tick(); + virtual bool isPauseScreen() override; + virtual void tick() override; + + // 4jcraft: 1.6.x era overloads + virtual void renderTooltip(const std::vector& lines, int xm, + int ym); + virtual void renderTooltip(const std::wstring& line, int xm, int ym); }; diff --git a/Minecraft.Client/UI/Screens/AchievementPopup.cpp b/Minecraft.Client/UI/Screens/AchievementPopup.cpp index de59ec75b..512533c81 100644 --- a/Minecraft.Client/UI/Screens/AchievementPopup.cpp +++ b/Minecraft.Client/UI/Screens/AchievementPopup.cpp @@ -66,16 +66,15 @@ void AchievementPopup::prepareWindow() { } void AchievementPopup::render() { -// 4J Unused #if ENABLE_JAVA_GUIS - if (Minecraft::warezTime > 0) - { + if (Minecraft::warezTime > 0) { glDisable(GL_DEPTH_TEST); glDepthMask(false); Lighting::turnOff(); prepareWindow(); - std::wstring title = L"Minecraft " + SharedConstants::VERSION_STRING + L" Unlicensed Copy :("; + std::wstring title = L"Minecraft " + SharedConstants::VERSION_STRING + + L" Unlicensed Copy :("; std::wstring msg1 = L"(Or logged in from another location)"; std::wstring msg2 = L"Purchase at minecraft.net"; @@ -89,16 +88,12 @@ void AchievementPopup::render() { if (ach == NULL || startTime == 0) return; double time = (System::currentTimeMillis() - startTime) / 3000.0; - if (isHelper) - { - } - else if (!isHelper && (time < 0 || time > 1)) - { + if (isHelper) { + } else if (!isHelper && (time < 0 || time > 1)) { startTime = 0; return; } - prepareWindow(); glDisable(GL_DEPTH_TEST); glDepthMask(false); @@ -112,7 +107,7 @@ void AchievementPopup::render() { yo = yo * yo; int xx = width - 160; - int yy = 0 - (int) (yo * 36); + int yy = 0 - (int)(yo * 36); int tex = mc->textures->loadTexture(TN_ACHIEVEMENT_BG); glColor4f(1, 1, 1, 1); glEnable(GL_TEXTURE_2D); @@ -122,13 +117,13 @@ void AchievementPopup::render() { blit(xx, yy, 96, 202, 160, 32); // if (isHelper) - // { + // { // mc->font->drawWordWrap(desc, xx + 30, yy + 7, 120, 0xffffffff); // } - // else - // { - mc->font->draw(title, xx + 30, yy + 7, 0xffffff00); - mc->font->draw(desc, xx + 30, yy + 18, 0xffffffff); + // else + // { + mc->font->draw(title, xx + 30, yy + 7, 0xffffff00); + mc->font->draw(desc, xx + 30, yy + 18, 0xffffffff); // } glPushMatrix(); diff --git a/Minecraft.Client/UI/Screens/AchievementScreen.cpp b/Minecraft.Client/UI/Screens/AchievementScreen.cpp index 1ef4a92bc..48ea264b4 100644 --- a/Minecraft.Client/UI/Screens/AchievementScreen.cpp +++ b/Minecraft.Client/UI/Screens/AchievementScreen.cpp @@ -136,7 +136,6 @@ void AchievementScreen::renderLabels() { } void AchievementScreen::renderBg(int xm, int ym, float a) { - // 4J Unused #if 0 int xScroll = Mth::floor(xScrollO + (xScrollP - xScrollO) * a); int yScroll = Mth::floor(yScrollO + (yScrollP - yScrollO) * a); diff --git a/Minecraft.Client/UI/Screens/AchievementScreen.h b/Minecraft.Client/UI/Screens/AchievementScreen.h index 398ab950d..9c8a1223d 100644 --- a/Minecraft.Client/UI/Screens/AchievementScreen.h +++ b/Minecraft.Client/UI/Screens/AchievementScreen.h @@ -43,20 +43,20 @@ public: using Screen::keyPressed; AchievementScreen(StatsCounter* statsCounter); - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; virtual void keyPressed(char eventCharacter, int eventKey); public: - virtual void render(int mouseX, int mouseY, float a); - virtual void tick(); + virtual void render(int mouseX, int mouseY, float a) override; + virtual void tick() override; protected: virtual void renderLabels(); virtual void renderBg(int xm, int ym, float a); public: - virtual bool isPauseScreen(); + virtual bool isPauseScreen() override; }; diff --git a/Minecraft.Client/UI/Screens/BeaconScreen.cpp b/Minecraft.Client/UI/Screens/BeaconScreen.cpp new file mode 100644 index 000000000..d44378d83 --- /dev/null +++ b/Minecraft.Client/UI/Screens/BeaconScreen.cpp @@ -0,0 +1,229 @@ +#include "../../Platform/stdafx.h" +#include "BeaconScreen.h" +#include "../BeaconConfirmButton.h" +#include "../BeaconCancelButton.h" +#include "../BeaconPowerButton.h" +#include +#include +#include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../Rendering/Lighting.h" +#include "../../Textures/Textures.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/Slot.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.item.h" +#include "../../../Minecraft.Client/Minecraft.h" +#include "../../../Minecraft.Client/Network/ClientConnection.h" +#include "../../../Minecraft.World/IO/Streams/ByteArrayOutputStream.h" +#include "../../../Minecraft.World/IO/Streams/DataOutputStream.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing +// container classes (and iggy too) +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_BEACON_LOCATION = ResourceLocation(TN_GUI_BEACON); +#endif + +BeaconScreen::BeaconScreen(std::shared_ptr inventory, + std::shared_ptr beacon) + : AbstractContainerScreen(new BeaconMenu(inventory, beacon)) { + this->inventory = inventory; + this->beacon = beacon; + this->beaconMenu = static_cast(menu); + this->imageWidth = 230; + this->imageHeight = 219; + this->buttonsNotDrawn = true; + this->beaconConfirmButton = nullptr; +} + +BeaconScreen::~BeaconScreen() = default; + +void BeaconScreen::init() { + AbstractContainerScreen::init(); + + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + + beaconConfirmButton = new BeaconConfirmButton(this, -1, xo + 164, yo + 107); + buttons.push_back(beaconConfirmButton); + buttons.push_back(new BeaconCancelButton(this, -2, xo + 190, yo + 107)); + + buttonsNotDrawn = true; + beaconConfirmButton->active = false; +} + +void BeaconScreen::tick() { + if (buttonsNotDrawn && beacon->getLevels() >= 0) { + buttonsNotDrawn = false; + + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + + for (int tier = 0; tier <= 2; ++tier) { + int effectCount = BeaconTileEntity::BEACON_EFFECTS_EFFECTS; + int actualCount = 0; + for (int e = 0; e < effectCount; ++e) { + if (BeaconTileEntity::BEACON_EFFECTS[tier][e] != nullptr) { + actualCount++; + } else { + break; + } + } + + int totalWidth = actualCount * 22 + (actualCount - 1) * 2; + int startX = xo + 53 + (actualCount * 24 - totalWidth) / 2; + + for (int e = 0; e < actualCount; ++e) { + MobEffect* effect = BeaconTileEntity::BEACON_EFFECTS[tier][e]; + if (effect == nullptr) break; + + int buttonId = (tier << 8) | effect->id; + BeaconPowerButton* button = new BeaconPowerButton( + this, buttonId, startX + e * 24, yo + 22 + tier * 25, + effect->id, tier); + buttons.push_back(button); + + if (tier >= beacon->getLevels()) { + button->active = false; + } else if (effect->id == beacon->getPrimaryPower()) { + button->setSelected(true); + } + } + } + + int tier = 3; + int effectCount = BeaconTileEntity::BEACON_EFFECTS_EFFECTS; + int actualCount = 0; + for (int e = 0; e < effectCount; ++e) { + if (BeaconTileEntity::BEACON_EFFECTS[tier][e] != nullptr) { + actualCount++; + } else { + break; + } + } + + int totalWidth = (actualCount + 1) * 22 + actualCount * 2; + int startX = xo + 143 + ((actualCount + 1) * 24 - totalWidth) / 2; + + for (int e = 0; e < actualCount; ++e) { + MobEffect* effect = BeaconTileEntity::BEACON_EFFECTS[tier][e]; + if (effect == nullptr) break; + + int buttonId = (tier << 8) | effect->id; + BeaconPowerButton* button = new BeaconPowerButton( + this, buttonId, startX + e * 24, yo + 47, effect->id, tier); + buttons.push_back(button); + + if (tier >= beacon->getLevels()) { + button->active = false; + } else if (effect->id == beacon->getSecondaryPower()) { + button->setSelected(true); + } + } + + if (beacon->getPrimaryPower() > 0) { + int buttonId = (tier << 8) | beacon->getPrimaryPower(); + BeaconPowerButton* button = + new BeaconPowerButton(this, buttonId, startX + actualCount * 24, + yo + 47, beacon->getPrimaryPower(), tier); + buttons.push_back(button); + + if (tier >= beacon->getLevels()) { + button->active = false; + } else if (beacon->getPrimaryPower() == + beacon->getSecondaryPower()) { + button->setSelected(true); + } + } + } + + beaconConfirmButton->active = + (beacon->getItem(0) != nullptr && beacon->getPrimaryPower() > 0); +} + +void BeaconScreen::removed() { AbstractContainerScreen::removed(); } + +void BeaconScreen::renderLabels() { + std::wstring primaryLabel = + Language::getInstance()->getElement(L"tile.beacon.primary"); + font->drawShadow(primaryLabel, 25, 10, 0xE1E1E1); + + std::wstring secondaryLabel = + Language::getInstance()->getElement(L"tile.beacon.secondary"); + font->drawShadow(secondaryLabel, 125, 10, 0xE1E1E1); +} + +void BeaconScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + minecraft->textures->bindTexture(&GUI_BEACON_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + blit(xo, yo, 0, 0, imageWidth, imageHeight); + + // Render payment item icons + itemRenderer->renderGuiItem( + font, minecraft->textures, + std::shared_ptr(new ItemInstance(Item::emerald_Id, 1, 0)), + xo + 42, yo + 109); + itemRenderer->renderGuiItem( + font, minecraft->textures, + std::shared_ptr(new ItemInstance(Item::diamond_Id, 1, 0)), + xo + 42 + 22, yo + 109); + itemRenderer->renderGuiItem(font, minecraft->textures, + std::shared_ptr( + new ItemInstance(Item::goldIngot_Id, 1, 0)), + xo + 42 + 44, yo + 109); + itemRenderer->renderGuiItem(font, minecraft->textures, + std::shared_ptr( + new ItemInstance(Item::ironIngot_Id, 1, 0)), + xo + 42 + 66, yo + 109); +#endif +} + +void BeaconScreen::render(int xm, int ym, float a) { + AbstractContainerScreen::render(xm, ym, a); + for (Button* button : buttons) { + AbstractBeaconButton* beaconButton = + dynamic_cast(button); + if (beaconButton && beaconButton->isHovered()) { + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + beaconButton->renderTooltip(xm, ym); + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + break; + } + } +} + +void BeaconScreen::buttonClicked(Button* button) { + if (button->id == -2) { + minecraft->player->closeContainer(); + } else if (button->id == -1) { + // 4jcraft: copied from IUIScene_BeaconMenu + ByteArrayOutputStream baos; + DataOutputStream dos(&baos); + dos.writeInt(beacon->getPrimaryPower()); + dos.writeInt(beacon->getSecondaryPower()); + + minecraft->player->connection->send( + std::shared_ptr(new CustomPayloadPacket( + CustomPayloadPacket::SET_BEACON_PACKET, baos.toByteArray()))); + minecraft->player->closeContainer(); + } else if (dynamic_cast(button)) { + int effectId = button->id & 255; + int tier = button->id >> 8; + + if (tier < 3) { + beacon->setPrimaryPower(effectId); + } else { + beacon->setSecondaryPower(effectId); + } + + for (Button* btn : buttons) { + delete btn; + } + buttons.clear(); + init(); + tick(); + } +} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/BeaconScreen.h b/Minecraft.Client/UI/Screens/BeaconScreen.h new file mode 100644 index 000000000..03a9db927 --- /dev/null +++ b/Minecraft.Client/UI/Screens/BeaconScreen.h @@ -0,0 +1,32 @@ +#pragma once + +#include "AbstractContainerScreen.h" +#include "../../../Minecraft.World/Containers/BeaconMenu.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h" + +class BeaconConfirmButton; +class BeaconCancelButton; + +class BeaconScreen : public AbstractContainerScreen { +public: + BeaconScreen(std::shared_ptr inventory, + std::shared_ptr beacon); + virtual ~BeaconScreen(); + + void init() override; + void removed() override; + void tick() override; + void renderLabels() override; + void renderBg(float a) override; + void render(int xm, int ym, float a) override; + void buttonClicked(Button* button) override; + + std::shared_ptr getBeacon() { return beacon; } + +private: + std::shared_ptr inventory; + std::shared_ptr beacon; + BeaconMenu* beaconMenu; + BeaconConfirmButton* beaconConfirmButton; + bool buttonsNotDrawn; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/BrewingStandScreen.cpp b/Minecraft.Client/UI/Screens/BrewingStandScreen.cpp new file mode 100644 index 000000000..1d1239c2a --- /dev/null +++ b/Minecraft.Client/UI/Screens/BrewingStandScreen.cpp @@ -0,0 +1,99 @@ +#include "../../Platform/stdafx.h" +#include "BrewingStandScreen.h" +#include +#include +#include +#include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../Rendering/Lighting.h" +#include "../../Textures/Textures.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/BrewingStandMenu.h" +#include "../../../Minecraft.World/Containers/Slot.h" +#include "../../../Minecraft.Client/Minecraft.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing +// container classes +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_BREWING_STAND_LOCATION = + ResourceLocation(TN_GUI_BREWING_STAND); +#endif + +BrewingStandScreen::BrewingStandScreen( + std::shared_ptr inventory, + std::shared_ptr brewingStand) + : AbstractContainerScreen(new BrewingStandMenu(inventory, brewingStand)) { + this->inventory = inventory; + this->brewingStand = brewingStand; + this->brewMenu = static_cast(menu); +} + +BrewingStandScreen::~BrewingStandScreen() = default; + +void BrewingStandScreen::init() { AbstractContainerScreen::init(); } + +void BrewingStandScreen::removed() { AbstractContainerScreen::removed(); } + +void BrewingStandScreen::renderLabels() { + font->draw(brewingStand->getName(), + (imageWidth / 2) - (font->width(brewingStand->getName()) / 2), 6, + 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); +} + +void BrewingStandScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + Minecraft::GetInstance()->textures->bindTexture( + &GUI_BREWING_STAND_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + blit(xo, yo, 0, 0, imageWidth, imageHeight); + + int brewTime = brewingStand->getBrewTime(); + + if (brewTime > 0) { + int arrowHeight = (int)(28.0f * (1.0f - (float)brewTime / 400.0f)); + + if (arrowHeight > 0) { + blit(xo + 97, yo + 16 + (28 - arrowHeight), 176, 28 - arrowHeight, + 9, arrowHeight); + } + + int bubbleStep = (brewTime / 2) % 7; + int bubbleHeight = 0; + + switch (bubbleStep) { + case 0: + bubbleHeight = 29; + break; + case 1: + bubbleHeight = 24; + break; + case 2: + bubbleHeight = 20; + break; + case 3: + bubbleHeight = 16; + break; + case 4: + bubbleHeight = 11; + break; + case 5: + bubbleHeight = 6; + break; + case 6: + bubbleHeight = 0; + break; + } + + if (bubbleHeight > 0) { + blit(xo + 65, yo + 14 + (29 - bubbleHeight), 185, 29 - bubbleHeight, + 12, bubbleHeight); + } + } +#endif +} + +void BrewingStandScreen::render(int xm, int ym, float a) { + AbstractContainerScreen::render(xm, ym, a); +} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/BrewingStandScreen.h b/Minecraft.Client/UI/Screens/BrewingStandScreen.h new file mode 100644 index 000000000..12f834ed7 --- /dev/null +++ b/Minecraft.Client/UI/Screens/BrewingStandScreen.h @@ -0,0 +1,23 @@ +#pragma once + +#include "AbstractContainerScreen.h" +#include "../../../Minecraft.World/Containers/BrewingStandMenu.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h" + +class BrewingStandScreen : public AbstractContainerScreen { +public: + BrewingStandScreen(std::shared_ptr inventory, + std::shared_ptr brewingStand); + virtual ~BrewingStandScreen(); + + void init() override; + void removed() override; + void renderLabels() override; + void renderBg(float a) override; + void render(int xm, int ym, float a) override; + +private: + std::shared_ptr inventory; + std::shared_ptr brewingStand; + BrewingStandMenu* brewMenu; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ChatScreen.h b/Minecraft.Client/UI/Screens/ChatScreen.h index a1d508fab..ce20f5a62 100644 --- a/Minecraft.Client/UI/Screens/ChatScreen.h +++ b/Minecraft.Client/UI/Screens/ChatScreen.h @@ -10,19 +10,19 @@ private: public: ChatScreen(); // 4J added - virtual void init(); - virtual void removed(); - virtual void tick(); + virtual void init() override; + virtual void removed() override; + virtual void tick() override; private: static const std::wstring allowedChars; protected: - void keyPressed(wchar_t ch, int eventKey); + void keyPressed(wchar_t ch, int eventKey) override; public: - void render(int xm, int ym, float a); + void render(int xm, int ym, float a) override; protected: - void mouseClicked(int x, int y, int buttonNum); + void mouseClicked(int x, int y, int buttonNum) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ConfirmScreen.cpp b/Minecraft.Client/UI/Screens/ConfirmScreen.cpp index 16f4ffe9d..17133b288 100644 --- a/Minecraft.Client/UI/Screens/ConfirmScreen.cpp +++ b/Minecraft.Client/UI/Screens/ConfirmScreen.cpp @@ -47,9 +47,9 @@ void ConfirmScreen::render(int xm, int ym, float a) { Screen::render(xm, ym, a); // 4J - debug code - remove - static int count = 0; - if (count++ == 100) { - count = 0; - buttonClicked(buttons[0]); - } + // static int count = 0; + // if (count++ == 100) { + // count = 0; + // buttonClicked(buttons[0]); + // } } \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ConfirmScreen.h b/Minecraft.Client/UI/Screens/ConfirmScreen.h index d0e337129..d400c70cd 100644 --- a/Minecraft.Client/UI/Screens/ConfirmScreen.h +++ b/Minecraft.Client/UI/Screens/ConfirmScreen.h @@ -16,11 +16,11 @@ public: ConfirmScreen(Screen* parent, const std::wstring& title1, const std::wstring& title2, const std::wstring& yesButton, const std::wstring& noButton, int id); - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ConnectScreen.h b/Minecraft.Client/UI/Screens/ConnectScreen.h index bb817198c..f99add276 100644 --- a/Minecraft.Client/UI/Screens/ConnectScreen.h +++ b/Minecraft.Client/UI/Screens/ConnectScreen.h @@ -10,17 +10,17 @@ private: public: ConnectScreen(Minecraft* minecraft, const std::wstring& ip, int port); - virtual void tick(); + virtual void tick() override; protected: virtual void keyPressed(char eventCharacter, int eventKey); public: - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ContainerScreen.cpp b/Minecraft.Client/UI/Screens/ContainerScreen.cpp index 4f34f524e..ad2513207 100644 --- a/Minecraft.Client/UI/Screens/ContainerScreen.cpp +++ b/Minecraft.Client/UI/Screens/ContainerScreen.cpp @@ -25,7 +25,6 @@ void ContainerScreen::renderLabels() { } void ContainerScreen::renderBg(float a) { - // 4J Unused #ifdef ENABLE_JAVA_GUIS int tex = minecraft->textures->loadTexture(TN_GUI_CONTAINER); glColor4f(1, 1, 1, 1); diff --git a/Minecraft.Client/UI/Screens/ContainerScreen.h b/Minecraft.Client/UI/Screens/ContainerScreen.h index 2e37eafa7..fca18c2f3 100644 --- a/Minecraft.Client/UI/Screens/ContainerScreen.h +++ b/Minecraft.Client/UI/Screens/ContainerScreen.h @@ -14,6 +14,6 @@ public: std::shared_ptr container); protected: - virtual void renderLabels(); - virtual void renderBg(float a); + virtual void renderLabels() override; + virtual void renderBg(float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ControlsScreen.h b/Minecraft.Client/UI/Screens/ControlsScreen.h index c5079aba1..3132fb451 100644 --- a/Minecraft.Client/UI/Screens/ControlsScreen.h +++ b/Minecraft.Client/UI/Screens/ControlsScreen.h @@ -25,12 +25,12 @@ private: int getLeftScreenPosition(); public: - void init(); + void init() override; protected: - void buttonClicked(Button* button); - void keyPressed(wchar_t eventCharacter, int eventKey); + void buttonClicked(Button* button) override; + void keyPressed(wchar_t eventCharacter, int eventKey) override; public: - void render(int xm, int ym, float a); + void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/CraftingScreen.cpp b/Minecraft.Client/UI/Screens/CraftingScreen.cpp index d9c3f4759..666c66878 100644 --- a/Minecraft.Client/UI/Screens/CraftingScreen.cpp +++ b/Minecraft.Client/UI/Screens/CraftingScreen.cpp @@ -2,11 +2,18 @@ #include "CraftingScreen.h" #include "../../Textures/Textures.h" #include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" #include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.h" +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_CRAFTING_LOCATION = ResourceLocation(TN_GUI_CRAFTING); +#endif + CraftingScreen::CraftingScreen(std::shared_ptr inventory, Level* level, int x, int y, int z) - : AbstractContainerScreen(new CraftingMenu(inventory, level, x, y, z)) {} + : AbstractContainerScreen(new CraftingMenu(inventory, level, x, y, z)) { + this->inventory = inventory; +} void CraftingScreen::removed() { AbstractContainerScreen::removed(); @@ -14,16 +21,15 @@ void CraftingScreen::removed() { } void CraftingScreen::renderLabels() { - font->draw(L"Crafting", 8 + 16 + 4, 2 + 2 + 2, 0x404040); - font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040); + font->draw(Language::getInstance()->getElement(L"container.crafting"), + 8 + 16 + 4, 2 + 2 + 2, 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); } void CraftingScreen::renderBg(float a) { - // 4J Unused #ifdef ENABLE_JAVA_GUIS - int tex = minecraft->textures->loadTexture(TN_GUI_CRAFTING); glColor4f(1, 1, 1, 1); - minecraft->textures->bind(tex); + minecraft->textures->bindTexture(&GUI_CRAFTING_LOCATION); int xo = (width - imageWidth) / 2; int yo = (height - imageHeight) / 2; this->blit(xo, yo, 0, 0, imageWidth, imageHeight); diff --git a/Minecraft.Client/UI/Screens/CraftingScreen.h b/Minecraft.Client/UI/Screens/CraftingScreen.h index ba59f871d..77eb664c7 100644 --- a/Minecraft.Client/UI/Screens/CraftingScreen.h +++ b/Minecraft.Client/UI/Screens/CraftingScreen.h @@ -4,12 +4,15 @@ class Inventory; class Level; class CraftingScreen : public AbstractContainerScreen { +private: + std::shared_ptr inventory; + public: CraftingScreen(std::shared_ptr inventory, Level* level, int x, int y, int z); - virtual void removed(); + virtual void removed() override; protected: - virtual void renderLabels(); - virtual void renderBg(float a); + virtual void renderLabels() override; + virtual void renderBg(float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/CreateWorldScreen.cpp b/Minecraft.Client/UI/Screens/CreateWorldScreen.cpp index d38f3d067..593f8416a 100644 --- a/Minecraft.Client/UI/Screens/CreateWorldScreen.cpp +++ b/Minecraft.Client/UI/Screens/CreateWorldScreen.cpp @@ -30,8 +30,8 @@ void CreateWorldScreen::tick() { if (moreOptions) seedEdit->tick(); // 4J - debug code - to be removed - static int count = 0; - if (count++ == 100) buttonClicked(buttons[0]); + // static int count = 0; + // if (count++ == 100) buttonClicked(buttons[0]); } void CreateWorldScreen::init() { @@ -155,7 +155,9 @@ void CreateWorldScreen::buttonClicked(Button* button) { app.DebugPrintf("CreateWorldScreen::buttonClicked START\n"); if (!button->active) return; if (button->id == 1) { - app.DebugPrintf("CreateWorldScreen::buttonClicked 'Cancel' minecraft->setScreen(lastScreen)\n"); + app.DebugPrintf( + "CreateWorldScreen::buttonClicked 'Cancel' " + "minecraft->setScreen(lastScreen)\n"); minecraft->setScreen(lastScreen); } else if (button->id == 0) { minecraft->setScreen( diff --git a/Minecraft.Client/UI/Screens/CreateWorldScreen.h b/Minecraft.Client/UI/Screens/CreateWorldScreen.h index 71a18e4d5..ba38b2ec3 100644 --- a/Minecraft.Client/UI/Screens/CreateWorldScreen.h +++ b/Minecraft.Client/UI/Screens/CreateWorldScreen.h @@ -31,8 +31,8 @@ private: public: CreateWorldScreen(Screen* lastScreen); - virtual void tick(); - virtual void init(); + virtual void tick() override; + virtual void init() override; private: void updateResultFolder(); @@ -41,16 +41,16 @@ private: public: static std::wstring findAvailableFolderName(LevelStorageSource* levelSource, const std::wstring& folder); - virtual void removed(); + virtual void removed() override; protected: - virtual void buttonClicked(Button* button); - virtual void keyPressed(wchar_t ch, int eventKey); - virtual void mouseClicked(int x, int y, int buttonNum); + virtual void buttonClicked(Button* button) override; + virtual void keyPressed(wchar_t ch, int eventKey) override; + virtual void mouseClicked(int x, int y, int buttonNum) override; public: - virtual void render(int xm, int ym, float a); - virtual void tabPressed(); + virtual void render(int xm, int ym, float a) override; + virtual void tabPressed() override; private: int m_iGameModeId; diff --git a/Minecraft.Client/UI/Screens/CreativeInventoryScreen.cpp b/Minecraft.Client/UI/Screens/CreativeInventoryScreen.cpp index 98e2a3aec..ac8481673 100644 --- a/Minecraft.Client/UI/Screens/CreativeInventoryScreen.cpp +++ b/Minecraft.Client/UI/Screens/CreativeInventoryScreen.cpp @@ -17,7 +17,7 @@ // Static member initialization int CreativeInventoryScreen::selectedTabIndex = IUIScene_CreativeMenu::eCreativeInventoryTab_BuildingBlocks; -int CreativeInventoryScreen::tabIconIds +const int CreativeInventoryScreen::tabIconIds [IUIScene_CreativeMenu::eCreativeInventoryTab_COUNT] = { // Building Blocks Tile::redBrick_Id, @@ -48,6 +48,7 @@ int CreativeInventoryScreen::tabIconIds // Materials Item::bucket_lava_Id}; + std::shared_ptr CreativeInventoryScreen::basicInventory = std::make_shared(0, L"", false, ITEMS_PER_PAGE); ItemRenderer* CreativeInventoryScreen::itemRenderer = new ItemRenderer(); @@ -69,7 +70,7 @@ CreativeInventoryScreen::ContainerCreative::ContainerCreative( } // Add hotbar slots (9 slots at bottom) - for (int k = 0; k < 9; k++) { + for (int k = 0; k < 9; ++k) { addSlot(new Slot(inventoryplayer, k, 9 + k * 18, 112)); } @@ -89,8 +90,8 @@ bool CreativeInventoryScreen::ContainerCreative::stillValid( std::shared_ptr CreativeInventoryScreen::ContainerCreative::clicked( - int slotIndex, int buttonNum, int clickType, - std::shared_ptr player) { + int slotIndex, int buttonNum, int clickType, std::shared_ptr player, + bool looped) { std::shared_ptr inventory = player->inventory; std::shared_ptr carried = inventory->getCarried(); @@ -180,8 +181,8 @@ void CreativeInventoryScreen::ContainerCreative::scrollTo(float pos) { j = 0; } - for (int k = 0; k < ROWS; k++) { - for (int l = 0; l < COLUMNS; l++) { + for (int k = 0; k < ROWS; ++k) { + for (int l = 0; l < COLUMNS; ++l) { int i1 = l + (k + j) * COLUMNS; if (i1 >= 0 && i1 < (int)itemList.size()) { @@ -378,6 +379,13 @@ void CreativeInventoryScreen::render(int xm, int ym, float a) { } AbstractContainerScreen::render(xm, ym, a); + + for (int i = 0; i < IUIScene_CreativeMenu::eCreativeInventoryTab_COUNT; + i++) { + if (renderIconTooltip(i, xm, ym)) { + break; + } + } } void CreativeInventoryScreen::renderLabels() { @@ -409,7 +417,7 @@ void CreativeInventoryScreen::renderBg(float a) { for (int tab = 0; tab < IUIScene_CreativeMenu::eCreativeInventoryTab_COUNT; tab++) { if (tab != selectedTabIndex) { - drawTab(tab); + renderTab(tab); } } @@ -433,10 +441,33 @@ void CreativeInventoryScreen::renderBg(float a) { } // Render selected tab last (on top) - drawTab(selectedTabIndex); + renderTab(selectedTabIndex); #endif } +bool CreativeInventoryScreen::isMouseOverInternal(int tab, int mouseX, + int mouseY, int xo, int yo, + int w, int h) { + int tabColumn = tab % 6; + int x = (tabColumn * 28) + xo; + int y = yo; + + if (tabColumn == 5) { + x = imageWidth - 28 + 2; + } else if (tabColumn > 0) { + x += tabColumn; + } + + if (tab < 6) { + y -= 32; + } else { + y = imageHeight; + } + + return ((mouseX >= x && mouseX <= x + w) && + (mouseY >= y && mouseY <= y + h)); +} + void CreativeInventoryScreen::setCurrentCreativeTab(int tab) { if (tab < 0 || tab >= IUIScene_CreativeMenu::eCreativeInventoryTab_COUNT) return; @@ -453,7 +484,7 @@ void CreativeInventoryScreen::setCurrentCreativeTab(int tab) { IUIScene_CreativeMenu::specs[tab]; // Add items from static groups - for (int i = 0; i < spec->m_staticGroupsCount; i++) { + for (int i = 0; i < spec->m_staticGroupsCount; ++i) { int groupIdx = spec->m_staticGroupsA[i]; if (groupIdx >= 0 && groupIdx < @@ -477,27 +508,14 @@ bool CreativeInventoryScreen::needsScrollBars() { } bool CreativeInventoryScreen::isMouseOverTab(int tab, int mouseX, int mouseY) { - int tabColumn = tab % 6; - int x = tabColumn * 28; - int y = 0; - - if (tabColumn == 5) { - x = imageWidth - 28 + 2; - } else if (tabColumn > 0) { - x += tabColumn; - } - - if (tab < 6) { - y -= 32; - } else { - y = imageHeight; - } - - return ((mouseX >= x && mouseX <= x + 28) && - (mouseY >= y && mouseY <= y + 32)); + return isMouseOverInternal(tab, mouseX, mouseY, 0, 0, 28, 32); } -void CreativeInventoryScreen::drawTab(int tab) { +bool CreativeInventoryScreen::isMouseOverIcon(int tab, int mouseX, int mouseY) { + return isMouseOverInternal(tab, mouseX, mouseY, 7, 12, 14, 16); +} + +void CreativeInventoryScreen::renderTab(int tab) { #ifdef ENABLE_JAVA_GUIS bool isSelected = (selectedTabIndex == tab); bool tabFirstRow = (tab < 6); @@ -544,4 +562,22 @@ void CreativeInventoryScreen::drawTab(int tab) { tabIcons[tab], x, y); glDisable(GL_LIGHTING); #endif +} + +bool CreativeInventoryScreen::renderIconTooltip(int tab, int mouseX, + int mouseY) { + int x = mouseX - (width - imageWidth) / 2; + int y = mouseY - (height - imageHeight) / 2; + + if (isMouseOverIcon(tab, x, y)) { + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + renderTooltip( + app.GetString(IUIScene_CreativeMenu::specs[tab]->m_descriptionId), + mouseX, mouseY); + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + return true; + } + return false; } \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/CreativeInventoryScreen.h b/Minecraft.Client/UI/Screens/CreativeInventoryScreen.h index 987ec9a88..e8fd36877 100644 --- a/Minecraft.Client/UI/Screens/CreativeInventoryScreen.h +++ b/Minecraft.Client/UI/Screens/CreativeInventoryScreen.h @@ -20,7 +20,8 @@ private: static int selectedTabIndex; // Array of item ids for the tab icons - static int tabIconIds[IUIScene_CreativeMenu::eCreativeInventoryTab_COUNT]; + static const int + tabIconIds[IUIScene_CreativeMenu::eCreativeInventoryTab_COUNT]; // Temporary inventory for creative mode items static std::shared_ptr basicInventory; @@ -51,34 +52,38 @@ public: std::vector> itemList; ContainerCreative(std::shared_ptr player); - virtual bool stillValid(std::shared_ptr player); + virtual bool stillValid(std::shared_ptr player) override; virtual std::shared_ptr clicked( int slotIndex, int buttonNum, int clickType, - std::shared_ptr player); + std::shared_ptr player, bool looped = false) override; void scrollTo(float pos); bool canScroll(); }; public: CreativeInventoryScreen(std::shared_ptr player); - virtual void removed(); - virtual void init(); + virtual void removed() override; + virtual void init() override; virtual void containerTick(); - virtual void tick(); - virtual void updateEvents(); - virtual void keyPressed(wchar_t eventCharacter, int eventKey); - virtual void mouseClicked(int x, int y, int buttonNum); - virtual void mouseReleased(int x, int y, int buttonNum); - virtual void render(int xm, int ym, float a); + virtual void tick() override; + virtual void updateEvents() override; + virtual void keyPressed(wchar_t eventCharacter, int eventKey) override; + virtual void mouseClicked(int x, int y, int buttonNum) override; + virtual void mouseReleased(int x, int y, int buttonNum) override; + virtual void render(int xm, int ym, float a) override; protected: - virtual void renderLabels(); - virtual void renderBg(float a); + virtual void renderLabels() override; + virtual void renderBg(float a) override; + virtual bool isMouseOverInternal(int tab, int mouseX, int mouseY, int xo, + int yo, int w, int h); private: void setCurrentCreativeTab(int tab); void selectTab(int tab); bool needsScrollBars(); bool isMouseOverTab(int tab, int mouseX, int mouseY); - void drawTab(int tab); -}; + bool isMouseOverIcon(int tab, int mouseX, int mouseY); + void renderTab(int tab); + bool renderIconTooltip(int tab, int mouseX, int mouseY); +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/DeathScreen.h b/Minecraft.Client/UI/Screens/DeathScreen.h index 976832afb..382f0e5b6 100644 --- a/Minecraft.Client/UI/Screens/DeathScreen.h +++ b/Minecraft.Client/UI/Screens/DeathScreen.h @@ -3,13 +3,13 @@ class DeathScreen : public Screen { public: - virtual void init(); + virtual void init() override; protected: virtual void keyPressed(char eventCharacter, int eventKey); - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); - virtual bool isPauseScreen(); + virtual void render(int xm, int ym, float a) override; + virtual bool isPauseScreen() override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/DisconnectedScreen.h b/Minecraft.Client/UI/Screens/DisconnectedScreen.h index 4e49685d7..1dcc1151d 100644 --- a/Minecraft.Client/UI/Screens/DisconnectedScreen.h +++ b/Minecraft.Client/UI/Screens/DisconnectedScreen.h @@ -8,7 +8,7 @@ private: public: DisconnectedScreen(const std::wstring& title, const std::wstring reason, void* reasonObjects, ...); - virtual void tick(); + virtual void tick() override; protected: using Screen::keyPressed; @@ -16,11 +16,11 @@ protected: virtual void keyPressed(char eventCharacter, int eventKey); public: - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; diff --git a/Minecraft.Client/UI/Screens/EnchantmentScreen.cpp b/Minecraft.Client/UI/Screens/EnchantmentScreen.cpp new file mode 100644 index 000000000..24d239382 --- /dev/null +++ b/Minecraft.Client/UI/Screens/EnchantmentScreen.cpp @@ -0,0 +1,322 @@ +#include "../../Platform/stdafx.h" +#include "EnchantmentScreen.h" +#include +#include +#include +#include +#include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../Rendering/Lighting.h" +#include "../../Textures/Textures.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/EnchantmentMenu.h" +#include "../../../Minecraft.World/Containers/Slot.h" +#include "../../Rendering/Models/BookModel.h" +#include "../../../Minecraft.Client/Minecraft.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing +// container classes (and iggy too) +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_ENCHANT_LOCATION = ResourceLocation(TN_GUI_ENCHANT); +ResourceLocation ITEM_BOOK_LOCATION = ResourceLocation(TN_ITEM_BOOK); +#endif + +EnchantmentScreen::EnchantmentScreen(std::shared_ptr inventory, + Level* level, int x, int y, int z) + : AbstractContainerScreen(new EnchantmentMenu(inventory, level, x, y, z)) { + xMouse = yMouse = 0.0f; + + this->inventory = inventory; + this->enchantMenu = static_cast(menu); + bookTick = 0; + flip = oFlip = flipT = flipA = 0.0f; + open = oOpen = 0.0f; + last = nullptr; +} + +EnchantmentScreen::~EnchantmentScreen() = default; + +void EnchantmentScreen::init() { AbstractContainerScreen::init(); } + +void EnchantmentScreen::removed() { AbstractContainerScreen::removed(); } + +void EnchantmentScreen::renderLabels() { + font->draw(Language::getInstance()->getElement(L"container.enchant"), 12, 5, + 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); + + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + + // 4jcraft: our own refactor, text rendering has been moved to the + // foreground here from renderBg() (which is where it was in the JE 1.6.4 + // code) + bool needsUpdate = false; + for (int i = 0; i < 3; ++i) { + if (enchantMenu->costs[i] != lastCosts[i]) { + needsUpdate = true; + lastCosts[i] = enchantMenu->costs[i]; + } + } + if (needsUpdate) { + for (int i = 0; i < 3; ++i) { + if (enchantMenu->costs[i] > 0) { + enchantNames[i] = EnchantmentNames::instance.getRandomName(); + } else { + enchantNames[i] = L""; + } + } + } + + for (int i = 0; i < 3; ++i) { + int cost = enchantMenu->costs[i]; + + int buttonX = 60; + int buttonY = 14 + 19 * i; + + bool isHovering = + (xMouse >= xo + buttonX && xMouse < xo + buttonX + 108 && + yMouse >= yo + buttonY && yMouse < yo + buttonY + 19); + + bool hasEnoughLevels = (minecraft->player->experienceLevel >= cost) || + minecraft->player->abilities.instabuild; + + if (cost > 0) { + std::wstring enchantName = enchantNames[i]; + + Font* weirdEnchantTableFont = minecraft->altFont; + if (weirdEnchantTableFont) { + int nameColor; + + if (!hasEnoughLevels) { + nameColor = 0x342F25; + } else if (isHovering) { + nameColor = 0xFFFF80; + } else { + nameColor = 0x685E4A; + } + + int textX = xo + buttonX + 2; + int textY = yo + buttonY + 2; + + weirdEnchantTableFont->drawWordWrap( + enchantName, buttonX + 2, buttonY + 2, 104, nameColor, 64); + } + + std::wstring costStr = std::to_wstring(cost); + int costX = buttonX + 108 - font->width(costStr) - 2; + int costY = buttonY + 8; + + int costColor; + if (!hasEnoughLevels) { + costColor = 0x407F10; + } else { + costColor = 0x80FF20; + } + + font->drawShadow(costStr, costX, costY, costColor); + } + } +} + +void EnchantmentScreen::render(int xm, int ym, float a) { + AbstractContainerScreen::render(xm, ym, a); + this->xMouse = (float)xm; + this->yMouse = (float)ym; +} + +void EnchantmentScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + Minecraft::GetInstance()->textures->bindTexture(&GUI_ENCHANT_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + blit(xo, yo, 0, 0, imageWidth, imageHeight); + + glPushMatrix(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + ScreenSizeCalculator screenSize(minecraft->options, minecraft->width, + minecraft->height); + int scaledWidth = screenSize.getWidth(); + int scaledHeight = screenSize.getHeight(); + int scaleFactor = screenSize.scale; + + glViewport(((scaledWidth - 320) / 2) * scaleFactor, + ((scaledHeight - 240) / 2) * scaleFactor, 320 * scaleFactor, + 240 * scaleFactor); + + glTranslatef(-0.34f, 0.23f, 0.0f); + gluPerspective(90.0f, 1.3333334f, 9.0f, 80.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + Lighting::turnOn(); + + glTranslatef(0.0f, 3.3f, -16.0f); + glScalef(5.0f, 5.0f, 5.0f); + glRotatef(180.0f, 0.0f, 0.0f, 1.0f); + + Minecraft::GetInstance()->textures->bindTexture(&ITEM_BOOK_LOCATION); + glRotatef(20.0f, 1.0f, 0.0f, 0.0f); + + // 4jcraft: brought over from UIControl_EnchantmentBook + float o = oOpen + (open - oOpen) * a; + glTranslatef((1 - o) * 0.2f, (1 - o) * 0.1f, (1 - o) * 0.25f); + glRotatef(-(1 - o) * 90 - 90, 0, 1, 0); + glRotatef(180, 1, 0, 0); + + float ff1 = oFlip + (flip - oFlip) * a + 0.25f; + float ff2 = oFlip + (flip - oFlip) * a + 0.75f; + ff1 = (ff1 - floor(ff1)) * 1.6f - 0.3f; + ff2 = (ff2 - floor(ff2)) * 1.6f - 0.3f; + + if (ff1 < 0.0f) ff1 = 0.0f; + if (ff2 < 0.0f) ff2 = 0.0f; + if (ff1 > 1.0f) ff1 = 1.0f; + if (ff2 > 1.0f) ff2 = 1.0f; + + glEnable(GL_RESCALE_NORMAL); + + static BookModel bookModel; + bookModel.render(nullptr, 0.0f, ff1, ff2, o, 0.0f, 0.0625f, true); + + glDisable(GL_RESCALE_NORMAL); + Lighting::turnOff(); + + glMatrixMode(GL_PROJECTION); + glViewport(0, 0, minecraft->width, minecraft->height); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + Minecraft::GetInstance()->textures->bindTexture(&GUI_ENCHANT_LOCATION); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + for (int i = 0; i < 3; ++i) { + int cost = enchantMenu->costs[i]; + int buttonX = 60; + int buttonY = 14 + 19 * i; + + bool isHovering = + (xMouse >= xo + buttonX && xMouse < xo + buttonX + 108 && + yMouse >= yo + buttonY && yMouse < yo + buttonY + 19); + + if (cost == 0) { + blit(xo + buttonX, yo + buttonY, 0, 185, 108, 19); + } else { + bool hasEnoughLevels = + (minecraft->player->experienceLevel >= cost) || + minecraft->player->abilities.instabuild; + + int texV; + if (!hasEnoughLevels) { + texV = 185; + } else if (isHovering) { + texV = 204; + } else { + texV = 166; + } + + blit(xo + buttonX, yo + buttonY, 0, texV, 108, 19); + } + } +#endif +} + +void EnchantmentScreen::mouseClicked(int x, int y, int buttonNum) { + AbstractContainerScreen::mouseClicked(x, y, buttonNum); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + + for (int i = 0; i < 3; ++i) { + int buttonX = xo + 60; + int buttonY = yo + 14 + 19 * i; + + if (x >= buttonX && x < buttonX + 108 && y >= buttonY && + y < buttonY + 19) { + if (enchantMenu->clickMenuButton(minecraft->player, i)) { + minecraft->gameMode->handleInventoryButtonClick( + enchantMenu->containerId, i); + } + break; + } + } +} + +void EnchantmentScreen::tick() { + AbstractContainerScreen::tick(); + + // 4jcraft: brought over from UIControl_EnchantmentBook + oFlip = flip; + oOpen = open; + + std::shared_ptr current = + enchantMenu->getSlot(EnchantmentMenu::INGREDIENT_SLOT)->getItem(); + if (!ItemInstance::matches(current, last)) { + last = current; + + if (current) { + do { + flipT += random.nextInt(4) - random.nextInt(4); + } while (flip <= flipT + 1 && flip >= flipT - 1); + } else { + flipT = 0.0f; + } + } + + bool shouldBeOpen = false; + for (int i = 0; i < 3; ++i) { + if (enchantMenu->costs[i] != 0) { + shouldBeOpen = true; + break; + } + } + + if (shouldBeOpen) + open += 0.2f; + else + open -= 0.2f; + + if (open < 0.0f) open = 0.0f; + if (open > 1.0f) open = 1.0f; + + float diff = (flipT - flip) * 0.4f; + float max = 0.2f; + if (diff < -max) diff = -max; + if (diff > max) diff = max; + flipA += (diff - flipA) * 0.9f; + flip = flip + flipA; +} + +// 4jcraft: brought over from UIControl_EnchantmentButton +EnchantmentScreen::EnchantmentNames + EnchantmentScreen::EnchantmentNames::instance; + +EnchantmentScreen::EnchantmentNames::EnchantmentNames() { + std::wstring allWords = + L"the elder scrolls klaatu berata niktu xyzzy bless curse light " + L"darkness fire air earth water hot dry cold wet ignite snuff embiggen " + L"twist shorten stretch fiddle destroy imbue galvanize enchant free " + L"limited range of towards inside sphere cube self other ball mental " + L"physical grow shrink demon elemental spirit animal creature beast " + L"humanoid undead fresh stale "; + std::wistringstream iss(allWords); + std::copy(std::istream_iterator >(iss), + std::istream_iterator >(), + std::back_inserter(words)); +} + +std::wstring EnchantmentScreen::EnchantmentNames::getRandomName() { + int wordCount = random.nextInt(2) + 3; + std::wstring word = L""; + for (int i = 0; i < wordCount; i++) { + if (i > 0) word += L" "; + word += words[random.nextInt(words.size())]; + } + return word; +} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/EnchantmentScreen.h b/Minecraft.Client/UI/Screens/EnchantmentScreen.h new file mode 100644 index 000000000..96a7a6af6 --- /dev/null +++ b/Minecraft.Client/UI/Screens/EnchantmentScreen.h @@ -0,0 +1,50 @@ +#pragma once + +#include "AbstractContainerScreen.h" +#include "../../../Minecraft.World/Containers/EnchantmentMenu.h" + +class EnchantmentScreen : public AbstractContainerScreen { +public: + EnchantmentScreen(std::shared_ptr inventory, Level* level, int x, + int y, int z); + virtual ~EnchantmentScreen(); + + void init() override; + void removed() override; + void tick() override; + void mouseClicked(int mouseX, int mouseY, int buttonNum) override; + void renderLabels() override; + void renderBg(float a) override; + void render(int xm, int ym, float a) override; + +private: + std::shared_ptr inventory; + EnchantmentMenu* enchantMenu; + float xMouse, yMouse; + + Random random; + + // 4jcraft: brought over from UIControl_EnchantmentBook + int bookTick; + float flip, oFlip, flipT, flipA; + float open, oOpen; + std::shared_ptr last; + + // 4jcraft: brought over from UIControl_EnchantmentButton + class EnchantmentNames { + public: + static EnchantmentNames instance; + + private: + Random random; + std::vector words; + + EnchantmentNames(); + + public: + std::wstring getRandomName(); + }; + + std::wstring enchantNames[3]; + int lastCosts[3]; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/ErrorScreen.h b/Minecraft.Client/UI/Screens/ErrorScreen.h index b89b64e5d..4c46d36ff 100644 --- a/Minecraft.Client/UI/Screens/ErrorScreen.h +++ b/Minecraft.Client/UI/Screens/ErrorScreen.h @@ -7,9 +7,9 @@ private: public: ErrorScreen(const std::wstring& title, const std::wstring& message); - virtual void init(); - virtual void render(int xm, int ym, float a); + virtual void init() override; + virtual void render(int xm, int ym, float a) override; protected: - virtual void keyPressed(wchar_t eventCharacter, int eventKey); + virtual void keyPressed(wchar_t eventCharacter, int eventKey) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/FurnaceScreen.cpp b/Minecraft.Client/UI/Screens/FurnaceScreen.cpp index c12ca82dc..170aedb61 100644 --- a/Minecraft.Client/UI/Screens/FurnaceScreen.cpp +++ b/Minecraft.Client/UI/Screens/FurnaceScreen.cpp @@ -6,23 +6,26 @@ #include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.h" #include "../../../Minecraft.World/Blocks/TileEntities/FurnaceTileEntity.h" +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_FURNACE_LOCATION = ResourceLocation(TN_GUI_FURNACE); +#endif + FurnaceScreen::FurnaceScreen(std::shared_ptr inventory, std::shared_ptr furnace) : AbstractContainerScreen(new FurnaceMenu(inventory, furnace)) { + this->inventory = inventory; this->furnace = furnace; } void FurnaceScreen::renderLabels() { - font->draw(L"Furnace", 16 + 4 + 40, 2 + 2 + 2, 0x404040); - font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040); + font->draw(furnace->getName(), 16 + 4 + 40, 2 + 2 + 2, 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); } void FurnaceScreen::renderBg(float a) { - // 4J Unused #ifdef ENABLE_JAVA_GUIS - int tex = minecraft->textures->loadTexture(TN_GUI_FURNACE); glColor4f(1, 1, 1, 1); - minecraft->textures->bind(tex); + minecraft->textures->bindTexture(&GUI_FURNACE_LOCATION); int xo = (width - imageWidth) / 2; int yo = (height - imageHeight) / 2; this->blit(xo, yo, 0, 0, imageWidth, imageHeight); diff --git a/Minecraft.Client/UI/Screens/FurnaceScreen.h b/Minecraft.Client/UI/Screens/FurnaceScreen.h index 6908524ec..cdaab078e 100644 --- a/Minecraft.Client/UI/Screens/FurnaceScreen.h +++ b/Minecraft.Client/UI/Screens/FurnaceScreen.h @@ -6,6 +6,7 @@ class Inventory; class FurnaceScreen : public AbstractContainerScreen { private: + std::shared_ptr inventory; std::shared_ptr furnace; public: @@ -13,6 +14,6 @@ public: std::shared_ptr furnace); protected: - virtual void renderLabels(); - virtual void renderBg(float a); + virtual void renderLabels() override; + virtual void renderBg(float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/HopperScreen.cpp b/Minecraft.Client/UI/Screens/HopperScreen.cpp new file mode 100644 index 000000000..df3b3af9a --- /dev/null +++ b/Minecraft.Client/UI/Screens/HopperScreen.cpp @@ -0,0 +1,36 @@ +#include "../../Platform/stdafx.h" +#include "HopperScreen.h" +#include "../../Textures/Textures.h" +#include "../../Player/LocalPlayer.h" +#include "../Font.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.h" +#include "../../../Minecraft.World/Containers/HopperMenu.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing +// container classes +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_HOPPER_LOCATION = ResourceLocation(TN_GUI_HOPPER); +#endif + +HopperScreen::HopperScreen(std::shared_ptr inventory, + std::shared_ptr hopper) + : AbstractContainerScreen(new HopperMenu(inventory, hopper)) { + this->hopper = hopper; + this->inventory = inventory; + imageHeight = 133; +} + +void HopperScreen::renderLabels() { + font->draw(hopper->getName(), 8, 6, 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); +} + +void HopperScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1, 1, 1, 1); + minecraft->textures->bindTexture(&GUI_HOPPER_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + this->blit(xo, yo, 0, 0, imageWidth, imageHeight); +#endif +} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/HopperScreen.h b/Minecraft.Client/UI/Screens/HopperScreen.h new file mode 100644 index 000000000..e3e3d1eb4 --- /dev/null +++ b/Minecraft.Client/UI/Screens/HopperScreen.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include "AbstractContainerScreen.h" + +class HopperTileEntity; +class MinecartHopper; +class Inventory; + +class HopperScreen : public AbstractContainerScreen { +public: + HopperScreen(std::shared_ptr inventory, + std::shared_ptr hopper); + +protected: + virtual void renderLabels() override; + virtual void renderBg(float a) override; + +private: + std::shared_ptr inventory; + std::shared_ptr hopper; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/HorseInventoryScreen.cpp b/Minecraft.Client/UI/Screens/HorseInventoryScreen.cpp new file mode 100644 index 000000000..f6de569c9 --- /dev/null +++ b/Minecraft.Client/UI/Screens/HorseInventoryScreen.cpp @@ -0,0 +1,100 @@ +#include "../../Platform/stdafx.h" +#include "HorseInventoryScreen.h" +#include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../Rendering/EntityRenderers/EntityRenderDispatcher.h" +#include "../../Rendering/Lighting.h" +#include "../../Textures/Textures.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/HorseInventoryMenu.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing InventoryScreen +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_HORSE_LOCATION = ResourceLocation(TN_GUI_HORSE); +#endif + +HorseInventoryScreen::HorseInventoryScreen( + std::shared_ptr inventory, + std::shared_ptr horseContainer, + std::shared_ptr horse) + : AbstractContainerScreen( + new HorseInventoryMenu(inventory, horseContainer, horse)) { + xMouse = yMouse = 0.0f; // 4J added + + this->inventory = inventory; + this->horseContainer = horseContainer; + this->horse = horse; + this->passEvents = false; +} + +void HorseInventoryScreen::init() { AbstractContainerScreen::init(); } + +void HorseInventoryScreen::renderLabels() { + font->draw(horseContainer->getName(), 8, 6, 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); +} + +void HorseInventoryScreen::render(int xm, int ym, float a) { + AbstractContainerScreen::render(xm, ym, a); + this->xMouse = (float)xm; + this->yMouse = (float)ym; +} + +void HorseInventoryScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1, 1, 1, 1); + minecraft->textures->bindTexture(&GUI_HORSE_LOCATION); + + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + blit(xo, yo, 0, 0, imageWidth, imageHeight); + + if (horse->isChestedHorse()) { + blit(xo + 79, yo + 17, 0, imageHeight, 90, 54); + } + + if (horse->canWearArmor()) { + blit(xo + 7, yo + 35, 0, imageHeight + 54, 18, 18); + } + + glEnable(GL_RESCALE_NORMAL); + glEnable(GL_COLOR_MATERIAL); + + glPushMatrix(); + glTranslatef((float)xo + 51, (float)yo + 60, 50); + float ss = 30; + glScalef(-ss, ss, ss); + glRotatef(180, 0, 0, 1); + + float oybr = horse->yBodyRot; + float oyr = horse->yRot; + float oxr = horse->xRot; + float oyh = horse->yHeadRot; + float oyhp = horse->yHeadRotO; + + float xd = (xo + 51) - xMouse; + float yd = (yo + 75 - 50) - yMouse; + + glRotatef(45 + 90, 0, 1, 0); + Lighting::turnOn(); + glRotatef(-45 - 90, 0, 1, 0); + + glRotatef(-(float)atan(yd / 40.0f) * 20, 1, 0, 0); + + horse->yBodyRot = (float)atan(xd / 40.0f) * 20; + horse->yRot = (float)atan(xd / 40.0f) * 40; + horse->xRot = -(float)atan(yd / 40.0f) * 20; + horse->yHeadRot = (float)atan(xd / 40.0f) * 40; + horse->yHeadRotO = (float)atan(xd / 40.0f) * 40; + glTranslatef(0, horse->heightOffset, 0); + EntityRenderDispatcher::instance->playerRotY = 180; + EntityRenderDispatcher::instance->render(horse, 0, 0, 0, 0, 1); + horse->yBodyRot = oybr; + horse->yRot = oyr; + horse->xRot = oxr; + horse->yHeadRot = oyh; + horse->yHeadRotO = oyhp; + glPopMatrix(); + Lighting::turnOff(); + glDisable(GL_RESCALE_NORMAL); +#endif +} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/HorseInventoryScreen.h b/Minecraft.Client/UI/Screens/HorseInventoryScreen.h new file mode 100644 index 000000000..12b0e68a2 --- /dev/null +++ b/Minecraft.Client/UI/Screens/HorseInventoryScreen.h @@ -0,0 +1,22 @@ +#pragma once +#include +#include "AbstractContainerScreen.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.entity.animal.h" + +class HorseInventoryScreen : public AbstractContainerScreen { +public: + HorseInventoryScreen(std::shared_ptr inventory, + std::shared_ptr horseContainer, + std::shared_ptr horse); + + virtual void init() override; + virtual void renderLabels() override; + virtual void renderBg(float a) override; + virtual void render(int xm, int ym, float a) override; + +private: + std::shared_ptr inventory; + std::shared_ptr horseContainer; + std::shared_ptr horse; + float xMouse, yMouse; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/InBedChatScreen.h b/Minecraft.Client/UI/Screens/InBedChatScreen.h index 3f8625eba..e068f5ce4 100644 --- a/Minecraft.Client/UI/Screens/InBedChatScreen.h +++ b/Minecraft.Client/UI/Screens/InBedChatScreen.h @@ -7,17 +7,17 @@ private: static const int WAKE_UP_BUTTON = 1; public: - virtual void init(); - virtual void removed(); + virtual void init() override; + virtual void removed() override; protected: - virtual void keyPressed(wchar_t ch, int eventKey); + virtual void keyPressed(wchar_t ch, int eventKey) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; private: void sendWakeUp(); diff --git a/Minecraft.Client/UI/Screens/InventoryScreen.cpp b/Minecraft.Client/UI/Screens/InventoryScreen.cpp index 67348db84..f4dccf4f6 100644 --- a/Minecraft.Client/UI/Screens/InventoryScreen.cpp +++ b/Minecraft.Client/UI/Screens/InventoryScreen.cpp @@ -32,7 +32,6 @@ void InventoryScreen::render(int xm, int ym, float a) { } void InventoryScreen::renderBg(float a) { - // 4J Unused #ifdef ENABLE_JAVA_GUIS int tex = minecraft->textures->loadTexture(TN_GUI_INVENTORY); glColor4f(1, 1, 1, 1); diff --git a/Minecraft.Client/UI/Screens/InventoryScreen.h b/Minecraft.Client/UI/Screens/InventoryScreen.h index 0c7080014..d2a5307c7 100644 --- a/Minecraft.Client/UI/Screens/InventoryScreen.h +++ b/Minecraft.Client/UI/Screens/InventoryScreen.h @@ -6,18 +6,18 @@ class Button; class InventoryScreen : public AbstractContainerScreen { public: InventoryScreen(std::shared_ptr player); - virtual void init(); + virtual void init() override; protected: - virtual void renderLabels(); + virtual void renderLabels() override; private: float xMouse, yMouse; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; protected: - virtual void renderBg(float a); - virtual void buttonClicked(Button* button); + virtual void renderBg(float a) override; + virtual void buttonClicked(Button* button) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/JoinMultiplayerScreen.h b/Minecraft.Client/UI/Screens/JoinMultiplayerScreen.h index c04c0d41f..78bce6115 100644 --- a/Minecraft.Client/UI/Screens/JoinMultiplayerScreen.h +++ b/Minecraft.Client/UI/Screens/JoinMultiplayerScreen.h @@ -10,20 +10,20 @@ private: public: JoinMultiplayerScreen(Screen* lastScreen); - virtual void tick(); - virtual void init(); - virtual void removed(); + virtual void tick() override; + virtual void init() override; + virtual void removed() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; private: virtual int parseInt(const std::wstring& str, int def); protected: - virtual void keyPressed(wchar_t ch, int eventKey); - virtual void mouseClicked(int x, int y, int buttonNum); + virtual void keyPressed(wchar_t ch, int eventKey) override; + virtual void mouseClicked(int x, int y, int buttonNum) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/MerchantScreen.cpp b/Minecraft.Client/UI/Screens/MerchantScreen.cpp new file mode 100644 index 000000000..f7e5a51e5 --- /dev/null +++ b/Minecraft.Client/UI/Screens/MerchantScreen.cpp @@ -0,0 +1,207 @@ +#include "../../Platform/stdafx.h" +#include "MerchantScreen.h" +#include +#include +#include "../TradeSwitchButton.h" +#include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../Rendering/Lighting.h" +#include "../../Textures/Textures.h" +#include "../../Rendering/EntityRenderers/ItemRenderer.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/MerchantMenu.h" +#include "../../../Minecraft.World/Containers/Slot.h" +#include "../../../Minecraft.World/Containers/MerchantContainer.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.item.trading.h" +#include "../../../Minecraft.Client/Minecraft.h" +#include "../../../Minecraft.Client/Network/ClientConnection.h" +#include "../../../Minecraft.World/IO/Streams/ByteArrayOutputStream.h" +#include "../../../Minecraft.World/IO/Streams/DataOutputStream.h" +#include "../../../Minecraft.World/Util/Rarity.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing +// container classes (and iggy too) +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_VILLAGER_LOCATION = ResourceLocation(TN_GUI_VILLAGER); +#endif + +MerchantScreen::MerchantScreen(std::shared_ptr inventory, + std::shared_ptr merchant, Level* level) + : AbstractContainerScreen(new MerchantMenu(inventory, merchant, level)) { + this->inventory = inventory; + this->merchantMenu = static_cast(menu); + this->merchant = merchant; + this->currentRecipeIndex = 0; + this->nextRecipeButton = nullptr; + this->prevRecipeButton = nullptr; +} + +MerchantScreen::~MerchantScreen() = default; + +void MerchantScreen::init() { + AbstractContainerScreen::init(); + + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + + nextRecipeButton = + new TradeSwitchButton(1, xo + 120 + 27, yo + 24 - 1, true); + prevRecipeButton = + new TradeSwitchButton(2, xo + 36 - 19, yo + 24 - 1, false); + + nextRecipeButton->active = false; + prevRecipeButton->active = false; + + buttons.push_back(nextRecipeButton); + buttons.push_back(prevRecipeButton); +} + +void MerchantScreen::removed() { AbstractContainerScreen::removed(); } + +void MerchantScreen::renderLabels() { + font->draw(merchant->getDisplayName(), + (imageWidth / 2) - (font->width(merchant->getDisplayName()) / 2), + 6, 0x404040); + + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); +} + +void MerchantScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + minecraft->textures->bindTexture(&GUI_VILLAGER_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + blit(xo, yo, 0, 0, imageWidth, imageHeight); + + MerchantRecipe* activeRecipe = + merchantMenu->getTradeContainer()->getActiveRecipe(); + if (activeRecipe != nullptr && activeRecipe->isDeprecated()) { + blit(xo + 83, yo + 21, 212, 0, 28, 21); + blit(xo + 83, yo + 51, 212, 0, 28, 21); + } +#endif +} + +void MerchantScreen::render(int xm, int ym, float a) { + AbstractContainerScreen::render(xm, ym, a); + +#ifdef ENABLE_JAVA_GUIS + std::shared_ptr player = std::dynamic_pointer_cast( + inventory->player->shared_from_this()); + MerchantRecipeList* offers = merchant->getOffers(player); + + if (offers != nullptr && !offers->empty()) { + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + + MerchantRecipe* recipe = offers->at(currentRecipeIndex); + if (recipe != nullptr && !recipe->isDeprecated()) { + std::shared_ptr buyItem1 = recipe->getBuyAItem(); + std::shared_ptr buyItem2 = recipe->getBuyBItem(); + std::shared_ptr sellItem = recipe->getSellItem(); + + glPushMatrix(); + glTranslatef((float)xo, (float)yo, 0.0f); + + Lighting::turnOnGui(); + glEnable(GL_RESCALE_NORMAL); + glEnable(GL_LIGHTING); + + if (buyItem1 != nullptr) { + itemRenderer->renderGuiItem(font, minecraft->textures, buyItem1, + 36, 24); + itemRenderer->renderGuiItemDecorations( + font, minecraft->textures, buyItem1, 36, 24); + } + + if (buyItem2 != nullptr) { + itemRenderer->renderGuiItem(font, minecraft->textures, buyItem2, + 62, 24); + itemRenderer->renderGuiItemDecorations( + font, minecraft->textures, buyItem2, 62, 24); + } + + if (sellItem != nullptr) { + itemRenderer->renderGuiItem(font, minecraft->textures, sellItem, + 120, 24); + itemRenderer->renderGuiItemDecorations( + font, minecraft->textures, sellItem, 120, 24); + } + + glDisable(GL_LIGHTING); + glDisable(GL_RESCALE_NORMAL); + Lighting::turnOff(); + + glPopMatrix(); + + if (buyItem1 != nullptr && isHoveringOver(36, 24, 16, 16, xm, ym)) { + renderTooltip(buyItem1, xm, ym); + } else if (buyItem2 != nullptr && + isHoveringOver(62, 24, 16, 16, xm, ym)) { + renderTooltip(buyItem2, xm, ym); + } else if (sellItem != nullptr && + isHoveringOver(120, 24, 16, 16, xm, ym)) { + renderTooltip(sellItem, xm, ym); + } + } + } +#endif +} + +void MerchantScreen::tick() { + AbstractContainerScreen::tick(); + + std::shared_ptr player = std::dynamic_pointer_cast( + inventory->player->shared_from_this()); + + MerchantRecipeList* offers = merchant->getOffers(player); + + if (offers != nullptr) { + int offerCount = (int)offers->size(); + + nextRecipeButton->active = (currentRecipeIndex < offerCount - 1); + prevRecipeButton->active = (currentRecipeIndex > 0); + + if (currentRecipeIndex >= offerCount && offerCount > 0) { + currentRecipeIndex = offerCount - 1; + merchantMenu->setSelectionHint(currentRecipeIndex); + + // 4jcraft: taken from IUIScene_TradingMenu + ByteArrayOutputStream rawOutput; + DataOutputStream output(&rawOutput); + output.writeInt(currentRecipeIndex); + minecraft->player->connection->send( + std::shared_ptr(new CustomPayloadPacket( + CustomPayloadPacket::TRADER_SELECTION_PACKET, + rawOutput.toByteArray()))); + } + } else { + nextRecipeButton->active = false; + prevRecipeButton->active = false; + } +} + +void MerchantScreen::buttonClicked(Button* button) { + bool changed = false; + + if (button == nextRecipeButton) { + ++currentRecipeIndex; + changed = true; + } else if (button == prevRecipeButton) { + --currentRecipeIndex; + changed = true; + } + + if (changed) { + merchantMenu->setSelectionHint(currentRecipeIndex); + + // 4jcraft: taken from IUIScene_TradingMenu + ByteArrayOutputStream rawOutput; + DataOutputStream output(&rawOutput); + output.writeInt(currentRecipeIndex); + minecraft->player->connection->send( + std::shared_ptr(new CustomPayloadPacket( + CustomPayloadPacket::TRADER_SELECTION_PACKET, + rawOutput.toByteArray()))); + } +} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/MerchantScreen.h b/Minecraft.Client/UI/Screens/MerchantScreen.h new file mode 100644 index 000000000..4a40bbb72 --- /dev/null +++ b/Minecraft.Client/UI/Screens/MerchantScreen.h @@ -0,0 +1,32 @@ +#pragma once + +#include "AbstractContainerScreen.h" +#include "../../../Minecraft.World/Containers/MerchantMenu.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.item.trading.h" + +class TradeSwitchButton; + +class MerchantScreen : public AbstractContainerScreen { +public: + MerchantScreen(std::shared_ptr inventory, + std::shared_ptr merchant, Level* level); + virtual ~MerchantScreen(); + + void init() override; + void removed() override; + void renderLabels() override; + void renderBg(float a) override; + void render(int xm, int ym, float a) override; + void tick() override; + void buttonClicked(Button* button) override; + + std::shared_ptr getMerchant() { return merchant; } + +private: + std::shared_ptr inventory; + std::shared_ptr merchant; + MerchantMenu* merchantMenu; + TradeSwitchButton* nextRecipeButton; + TradeSwitchButton* prevRecipeButton; + int currentRecipeIndex; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/MessageScreen.h b/Minecraft.Client/UI/Screens/MessageScreen.h index 42a75aa78..62b4ee280 100644 --- a/Minecraft.Client/UI/Screens/MessageScreen.h +++ b/Minecraft.Client/UI/Screens/MessageScreen.h @@ -14,11 +14,11 @@ protected: virtual void keyPressed(char eventCharacter, int eventKey); public: - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/NameEntryScreen.h b/Minecraft.Client/UI/Screens/NameEntryScreen.h index e01c0b428..2f0babddd 100644 --- a/Minecraft.Client/UI/Screens/NameEntryScreen.h +++ b/Minecraft.Client/UI/Screens/NameEntryScreen.h @@ -15,9 +15,9 @@ private: public: NameEntryScreen(Screen* lastScreen, const std::wstring& oldName, int slot); - virtual void init(); - virtual void removed(); - virtual void tick(); + virtual void init() override; + virtual void removed() override; + virtual void tick() override; protected: virtual void buttonClicked(Button button); @@ -26,8 +26,8 @@ private: static const std::wstring allowedChars; protected: - virtual void keyPressed(wchar_t ch, int eventKey); + virtual void keyPressed(wchar_t ch, int eventKey) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/OptionsScreen.h b/Minecraft.Client/UI/Screens/OptionsScreen.h index 9e33e3dfe..509162eff 100644 --- a/Minecraft.Client/UI/Screens/OptionsScreen.h +++ b/Minecraft.Client/UI/Screens/OptionsScreen.h @@ -16,11 +16,11 @@ private: public: OptionsScreen(Screen* lastScreen, Options* options); - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/PauseScreen.h b/Minecraft.Client/UI/Screens/PauseScreen.h index 375d03eb6..ef67c9f14 100644 --- a/Minecraft.Client/UI/Screens/PauseScreen.h +++ b/Minecraft.Client/UI/Screens/PauseScreen.h @@ -8,15 +8,15 @@ private: public: PauseScreen(); // 4J added - virtual void init(); + virtual void init() override; static void exitWorld(Minecraft* minecraft, bool save); protected: using Screen::buttonClicked; - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void tick(); - virtual void render(int xm, int ym, float a); + virtual void tick() override; + virtual void render(int xm, int ym, float a) override; }; diff --git a/Minecraft.Client/UI/Screens/ReceivingLevelScreen.h b/Minecraft.Client/UI/Screens/ReceivingLevelScreen.h index ede53e3a2..fb54bec4d 100644 --- a/Minecraft.Client/UI/Screens/ReceivingLevelScreen.h +++ b/Minecraft.Client/UI/Screens/ReceivingLevelScreen.h @@ -16,12 +16,12 @@ protected: virtual void keyPressed(char eventCharacter, int eventKey); public: - virtual void init(); - virtual void tick(); + virtual void init() override; + virtual void tick() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; diff --git a/Minecraft.Client/UI/Screens/RenameWorldScreen.h b/Minecraft.Client/UI/Screens/RenameWorldScreen.h index 1bf433dd3..11f5ed41d 100644 --- a/Minecraft.Client/UI/Screens/RenameWorldScreen.h +++ b/Minecraft.Client/UI/Screens/RenameWorldScreen.h @@ -11,15 +11,15 @@ private: public: RenameWorldScreen(Screen* lastScreen, const std::wstring& levelId); - virtual void tick(); - virtual void init(); - virtual void removed(); + virtual void tick() override; + virtual void init() override; + virtual void removed() override; protected: - virtual void buttonClicked(Button* button); - virtual void keyPressed(wchar_t ch, int eventKey); - virtual void mouseClicked(int x, int y, int buttonNum); + virtual void buttonClicked(Button* button) override; + virtual void keyPressed(wchar_t ch, int eventKey) override; + virtual void mouseClicked(int x, int y, int buttonNum) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/RepairScreen.cpp b/Minecraft.Client/UI/Screens/RepairScreen.cpp new file mode 100644 index 000000000..6fc1e8697 --- /dev/null +++ b/Minecraft.Client/UI/Screens/RepairScreen.cpp @@ -0,0 +1,191 @@ +#include "../../Platform/stdafx.h" +#include "RepairScreen.h" +#include +#include +#include +#include "../EditBox.h" +#include "../../Player/MultiPlayerLocalPlayer.h" +#include "../../Rendering/Lighting.h" +#include "../../Textures/Textures.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/AnvilMenu.h" +#include "../../../Minecraft.World/Containers/Slot.h" +#include "../../../Minecraft.Client/Network/ClientConnection.h" +#include "../../../Minecraft.Client/Minecraft.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) and the existing +// IUIScene_AnvilMenu (from iggy UI) +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_ANVIL_LOCATION = ResourceLocation(TN_GUI_ANVIL); +#endif + +RepairScreen::RepairScreen(std::shared_ptr inventory, Level* level, + int x, int y, int z) + : AbstractContainerScreen( + new AnvilMenu(inventory, level, x, y, z, + Minecraft::GetInstance()->localplayers[0])) { + this->inventory = inventory; + this->level = level; + this->repairMenu = static_cast(menu); + this->passEvents = false; +} + +RepairScreen::~RepairScreen() = default; + +void RepairScreen::init() { + AbstractContainerScreen::init(); + + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + editName = new EditBox(this, font, xo + 62, yo + 24, 103, 12, L""); + editName->setMaxLength(40); + editName->setEnableBackgroundDrawing(false); + editName->inFocus = true; + + repairMenu->removeSlotListener(this); + repairMenu->addSlotListener(this); +} + +void RepairScreen::removed() { + AbstractContainerScreen::removed(); + repairMenu->removeSlotListener(this); +} + +void RepairScreen::render(int xm, int ym, float a) { + AbstractContainerScreen::render(xm, ym, a); + glDisable(GL_LIGHTING); + if (editName) { + editName->render(); + } +} + +void RepairScreen::renderLabels() { + std::wstring title = + Language::getInstance()->getElement(L"container.repair"); + font->draw(title, 60, 6, 0x404040); + + if (repairMenu->cost > 0) { + int textColor = 0x80ff20; + bool showCost = true; + std::wstring costString; + + if (repairMenu->cost >= 40 && + !Minecraft::GetInstance()->localplayers[0]->abilities.instabuild) { + costString = Language::getInstance()->getElement( + L"container.repair.expensive"); + textColor = 0xff6060; + } else if (!repairMenu->getSlot(AnvilMenu::RESULT_SLOT)->hasItem()) { + showCost = false; + } else if (!repairMenu->getSlot(AnvilMenu::RESULT_SLOT) + ->mayPickup( + Minecraft::GetInstance()->localplayers[0])) { + textColor = 0xff6060; + } + + if (showCost) { + if (costString.empty()) { + costString = Language::getInstance()->getElement( + L"container.repair.cost", repairMenu->cost); + } + + int shadowColor = -0x00ffffff | ((textColor & 0xfcfcfc) >> 2) | + (textColor & -0x00ffffff); + int costX = imageWidth - 8 - font->width(costString); + int costY = 67; + + // if (this.fontRenderer.getUnicodeFlag()) + // { + // drawRect(i1 - 3, b0 - 2, this.xSize - 7, b0 + 10, -16777216); + // drawRect(i1 - 2, b0 - 1, this.xSize - 8, b0 + 9, -12895429); + // } + // else + // { + font->draw(costString, costX, costY + 1, shadowColor); + font->draw(costString, costX + 1, costY, shadowColor); + font->draw(costString, costX + 1, costY + 1, shadowColor); + font->draw(costString, costX, costY, textColor); + // } + } + } +} + +void RepairScreen::renderBg(float a) { +#ifdef ENABLE_JAVA_GUIS + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + Minecraft::GetInstance()->textures->bindTexture(&GUI_ANVIL_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + blit(xo, yo, 0, 0, imageWidth, imageHeight); + + int texV = imageHeight + (repairMenu->getSlot(0)->hasItem() ? 0 : 16); + blit(xo + 59, yo + 20, 0, texV, 110, 16); + + if ((repairMenu->getSlot(AnvilMenu::INPUT_SLOT)->hasItem() || + repairMenu->getSlot(AnvilMenu::ADDITIONAL_SLOT)->hasItem()) && + !repairMenu->getSlot(AnvilMenu::RESULT_SLOT)->hasItem()) { + blit(xo + 99, yo + 45, imageWidth, 0, 28, 21); + } +#endif +} + +void RepairScreen::keyPressed(char ch, int eventKey) { + if (editName) { + editName->keyPressed(ch, eventKey); + updateItemName(); + } else { + AbstractContainerScreen::keyPressed(ch, eventKey); + } +} + +void RepairScreen::mouseClicked(int mouseX, int mouseY, int buttonNum) { + AbstractContainerScreen::mouseClicked(mouseX, mouseY, buttonNum); + if (editName) { + editName->mouseClicked(mouseX, mouseY, buttonNum); + } +} + +void RepairScreen::updateItemName() { + std::wstring itemName; + Slot* slot = repairMenu->getSlot(0); + if (slot != NULL && slot->hasItem()) { + if (!slot->getItem()->hasCustomHoverName() && + itemName == slot->getItem()->getHoverName()) { + itemName = L""; + } + } + + repairMenu->setItemName(itemName); + + ByteArrayOutputStream baos; + DataOutputStream dos(&baos); + dos.writeUTF(itemName); + Minecraft::GetInstance()->player->connection->send( + std::shared_ptr(new CustomPayloadPacket( + CustomPayloadPacket::SET_ITEM_NAME_PACKET, baos.toByteArray()))); +} + +// 4jcraft: these 3 are to implement Containerlistener (see IUIScene_AnvilMenu +// and net.minecraft.world.inventory.ContainerListener) +void RepairScreen::refreshContainer( + AbstractContainerMenu* container, + std::vector >* items) { + slotChanged(container, AnvilMenu::INPUT_SLOT, + container->getSlot(0)->getItem()); +} + +void RepairScreen::slotChanged(AbstractContainerMenu* container, int slotIndex, + std::shared_ptr item) { + if (slotIndex == AnvilMenu::INPUT_SLOT) { + std::wstring itemName = item == NULL ? L"" : item->getHoverName(); + editName->setValue(itemName); + if (item != NULL) { + editName->focus(true); + updateItemName(); + } else { + editName->focus(false); + } + } +} + +void RepairScreen::setContainerData(AbstractContainerMenu* container, int id, + int value) {} \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/RepairScreen.h b/Minecraft.Client/UI/Screens/RepairScreen.h new file mode 100644 index 000000000..b5352a939 --- /dev/null +++ b/Minecraft.Client/UI/Screens/RepairScreen.h @@ -0,0 +1,39 @@ +#pragma once + +#include "../../Platform/stdafx.h" +#include "AbstractContainerScreen.h" +#include "../../../Minecraft.World/Containers/AnvilMenu.h" +#include "../../../Minecraft.World/Headers/net.minecraft.world.inventory.ContainerListener.h" + +class EditBox; + +class RepairScreen : public AbstractContainerScreen, public ContainerListener { +public: + RepairScreen(std::shared_ptr inventory, Level* level, int x, + int y, int z); + virtual ~RepairScreen(); + + void init(); + void removed(); + void render(int xm, int ym, float a); + void renderLabels(); + void renderBg(float a); + void keyPressed(char ch, int eventKey); + void mouseClicked(int mouseX, int mouseY, int buttonNum); + + // 4jcraft: these 3 are to implement Containerlistener (see + // IUIScene_AnvilMenu and net.minecraft.world.inventory.ContainerListener) + void refreshContainer(AbstractContainerMenu* container, + std::vector >* items); + void slotChanged(AbstractContainerMenu* container, int slotIndex, + std::shared_ptr item); + void setContainerData(AbstractContainerMenu* container, int id, int value); + +private: + void updateItemName(); + + std::shared_ptr inventory; + Level* level; + AnvilMenu* repairMenu; + EditBox* editName; +}; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/SelectWorldScreen.cpp b/Minecraft.Client/UI/Screens/SelectWorldScreen.cpp index aa410280b..8c181623d 100644 --- a/Minecraft.Client/UI/Screens/SelectWorldScreen.cpp +++ b/Minecraft.Client/UI/Screens/SelectWorldScreen.cpp @@ -127,7 +127,9 @@ void SelectWorldScreen::buttonClicked(Button* button) { minecraft->setScreen( new RenameWorldScreen(this, getWorldId(selectedWorld))); } else if (button->id == BUTTON_CANCEL_ID) { - app.DebugPrintf("SelectWorldScreen::buttonClicked 'Cancel' minecraft->setScreen(lastScreen)\n"); + app.DebugPrintf( + "SelectWorldScreen::buttonClicked 'Cancel' " + "minecraft->setScreen(lastScreen)\n"); minecraft->setScreen(lastScreen); } else { worldSelectionList->buttonClicked(button); @@ -181,9 +183,9 @@ void SelectWorldScreen::render(int xm, int ym, float a) { static bool forceCreateLevel = false; if (count++ >= 100) { if (!forceCreateLevel && levelList->size() > 0) { - // 4J Stu - For some obscures reason the "delete" button is called - // "renameButton" and vice versa. - // if( levelList->size() > 2 && deleteButton->active ) + // 4J Stu - For some obscures reason the "delete" button is + // called "renameButton" and vice versa. if( levelList->size() > + // 2 && deleteButton->active ) //{ // this->selectedWorld = 2; // count = 0; @@ -205,7 +207,9 @@ void SelectWorldScreen::render(int xm, int ym, float a) { count = 0; } } else { - app.DebugPrintf("SelectWorldScreen::render minecraft->setScreen(new CreateWorldScreen(this))\n"); + app.DebugPrintf( + "SelectWorldScreen::render minecraft->setScreen(new " + "CreateWorldScreen(this))\n"); minecraft->setScreen(new CreateWorldScreen(this)); } } diff --git a/Minecraft.Client/UI/Screens/SelectWorldScreen.h b/Minecraft.Client/UI/Screens/SelectWorldScreen.h index 5531d08e7..39b56c32f 100644 --- a/Minecraft.Client/UI/Screens/SelectWorldScreen.h +++ b/Minecraft.Client/UI/Screens/SelectWorldScreen.h @@ -20,7 +20,7 @@ protected: private: // final DateFormat DATE_FORMAT = new SimpleDateFormat(); // 4J - - //removed + // removed protected: Screen* lastScreen; @@ -41,7 +41,7 @@ private: public: SelectWorldScreen(Screen* lastScreen); - virtual void init(); + virtual void init() override; private: void loadLevelList(); @@ -54,12 +54,12 @@ public: virtual void postInit(); protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: void worldSelected(int id); - void confirmResult(bool result, int id); - virtual void render(int xm, int ym, float a); + void confirmResult(bool result, int id) override; + virtual void render(int xm, int ym, float a) override; class WorldSelectionList : public ScrolledSelectionList { public: diff --git a/Minecraft.Client/UI/Screens/StatsScreen.h b/Minecraft.Client/UI/Screens/StatsScreen.h index 91b0f5c40..dc567006d 100644 --- a/Minecraft.Client/UI/Screens/StatsScreen.h +++ b/Minecraft.Client/UI/Screens/StatsScreen.h @@ -31,14 +31,14 @@ private: public: StatsScreen(Screen* lastScreen, StatsCounter* stats); - virtual void init(); + virtual void init() override; virtual void postInit(); protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; class GeneralStatisticsList : public ScrolledSelectionList { protected: diff --git a/Minecraft.Client/UI/Screens/TextEditScreen.h b/Minecraft.Client/UI/Screens/TextEditScreen.h index 4373bd9c9..0c0af219b 100644 --- a/Minecraft.Client/UI/Screens/TextEditScreen.h +++ b/Minecraft.Client/UI/Screens/TextEditScreen.h @@ -13,19 +13,19 @@ private: public: TextEditScreen(std::shared_ptr sign); - virtual void init(); - virtual void removed(); - virtual void tick(); + virtual void init() override; + virtual void removed() override; + virtual void tick() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; private: static const std::wstring allowedChars; protected: - virtual void keyPressed(wchar_t ch, int eventKey); + virtual void keyPressed(wchar_t ch, int eventKey) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/TitleScreen.cpp b/Minecraft.Client/UI/Screens/TitleScreen.cpp index 27559f215..8aac613d5 100644 --- a/Minecraft.Client/UI/Screens/TitleScreen.cpp +++ b/Minecraft.Client/UI/Screens/TitleScreen.cpp @@ -5,6 +5,7 @@ #include "JoinMultiplayerScreen.h" #include "../../Rendering/Tesselator.h" #include "../../Textures/Textures.h" +#include "../../GameState/Options.h" #include "../../../Minecraft.World/Util/StringHelpers.h" #include "../../../Minecraft.World/IO/Streams/InputOutputStream.h" #include "../../../Minecraft.World/Headers/net.minecraft.locale.h" @@ -24,32 +25,52 @@ TitleScreen::TitleScreen() { // try { // 4J - removed try/catch std::vector splashes; - /* -BufferedReader *br = new BufferedReader(new -InputStreamReader(InputStream::getResourceAsStream(L"res\\title\\splashes.txt"))); -//, Charset.forName("UTF-8") + // 4jcraft: copied over from UIScene_MainMenu + int splashIndex; -std::wstring line = L""; -while ( !(line = br->readLine()).empty() ) - { - line = trimString( line ); - if (line.length() > 0) - { - splashes.push_back(line); + std::wstring filename = L"splashes.txt"; + if (app.hasArchiveFile(filename)) { + byteArray splashesArray = app.getArchiveFile(filename); + ByteArrayInputStream bais(splashesArray); + InputStreamReader isr(&bais); + BufferedReader br(&isr); + + std::wstring line = L""; + while (!(line = br.readLine()).empty()) { + line = trimString(line); + if (line.length() > 0) { + splashes.push_back(line); + } + } + + br.close(); } - br->close(); - delete br; - */ + splashIndex = + eSplashRandomStart + 1 + + random->nextInt((int)splashes.size() - (eSplashRandomStart + 1)); - // splash = L""; //splashes.at(random->nextInt(splashes.size())); + // Override splash text on certain dates + SYSTEMTIME LocalSysTime; + GetLocalTime(&LocalSysTime); + if (LocalSysTime.wMonth == 11 && LocalSysTime.wDay == 9) { + splashIndex = eSplashHappyBirthdayEx; + } else if (LocalSysTime.wMonth == 6 && LocalSysTime.wDay == 1) { + splashIndex = eSplashHappyBirthdayNotch; + } else if (LocalSysTime.wMonth == 12 && + LocalSysTime.wDay == 24) // the Java game shows this on + // Christmas Eve, so we will too + { + splashIndex = eSplashMerryXmas; + } else if (LocalSysTime.wMonth == 1 && LocalSysTime.wDay == 1) { + splashIndex = eSplashHappyNewYear; + } - // } catch (Exception e) { - // } + splash = splashes.at(splashIndex); } void TitleScreen::tick() { - // vo += 1.0f; + vo += 1.0f; // if( vo > 100.0f ) minecraft->setScreen(new SelectWorldScreen(this)); // // 4J - temp testing } @@ -58,6 +79,10 @@ void TitleScreen::keyPressed(wchar_t eventCharacter, int eventKey) {} void TitleScreen::init() { app.DebugPrintf("TitleScreen::init() START\n"); + + // 4jcraft: this is for the blured panorama background + viewportTexture = + minecraft->textures->getTexture(new BufferedImage(256, 256, 2)); /* 4J - removed Calendar c = Calendar.getInstance(); c.setTime(new Date()); @@ -104,38 +129,258 @@ if (c.get(Calendar.MONTH) + 1 == 11 && c.get(Calendar.DAY_OF_MONTH) == 9) { void TitleScreen::buttonClicked(Button* button) { if (button->id == 0) { - app.DebugPrintf("TitleScreen::buttonClicked() 'Options...' if (button->id == 0)\n"); + app.DebugPrintf( + "TitleScreen::buttonClicked() 'Options...' if (button->id == 0)\n"); minecraft->setScreen(new OptionsScreen(this, minecraft->options)); } if (button->id == 1) { - app.DebugPrintf("TitleScreen::buttonClicked() 'Singleplayer' if (button->id == 1)\n"); + app.DebugPrintf( + "TitleScreen::buttonClicked() 'Singleplayer' if (button->id == " + "1)\n"); minecraft->setScreen(new SelectWorldScreen(this)); } if (button->id == 2) { - app.DebugPrintf("TitleScreen::buttonClicked() 'Multiplayer' if (button->id == 2)\n"); + app.DebugPrintf( + "TitleScreen::buttonClicked() 'Multiplayer' if (button->id == " + "2)\n"); minecraft->setScreen(new JoinMultiplayerScreen(this)); } if (button->id == 3) { - app.DebugPrintf("TitleScreen::buttonClicked() 'Texture Pack' if (button->id == 3)\n"); + app.DebugPrintf( + "TitleScreen::buttonClicked() 'Texture Pack' if (button->id == " + "3)\n"); // minecraft->setScreen(new TexturePackSelectScreen(this)); // // 4J - TODO put back in } if (button->id == 4) { - app.DebugPrintf("TitleScreen::buttonClicked() Exit Game if (button->id == 4)\n"); - RenderManager.Close(); //minecraft->stop(); + app.DebugPrintf( + "TitleScreen::buttonClicked() Exit Game if (button->id == 4)\n"); + RenderManager.Close(); // minecraft->stop(); } } -void TitleScreen::render(int xm, int ym, float a) { - // 4J Unused - Iggy Flash UI renders the title screen on consoles +// 4jcraft: render our panorama +// uses the TU panorama instead of JE panorama and as such a different rendering +// method +void TitleScreen::renderPanorama(float a) { #ifdef ENABLE_JAVA_GUIS - renderBackground(); + + Tesselator* t = Tesselator::getInstance(); +#ifdef CLASSIC_PANORAMA + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluPerspective(120.0f, 1.0f, 0.05f, 10.0f); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glRotatef(180.0f, 1.0f, 0.0f, 0.0f); + glEnable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glDisable(GL_CULL_FACE); + glDepthMask(false); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + char offsetPasses = 8; + + for (int i = 0; i < (offsetPasses * offsetPasses); i++) { + glPushMatrix(); + float x = + ((float)(i % offsetPasses) / (float)offsetPasses - 0.5f) / 64.0f; + float y = + ((float)(i / offsetPasses) / (float)offsetPasses - 0.5f) / 64.0f; + float z = 0.0f; + glTranslatef(x, y, z); + glRotatef(sin((vo + a) / 400.0f) * 25.0f + 20.0f, 1.0f, 0.0f, 0.0f); + glRotatef(-(vo + a) * 0.1f, 0.0f, 1.0f, 0.0f); + + for (int j = 0; j < 6; j++) { + glPushMatrix(); + + switch (j) { + case 1: + glRotatef(90.0f, 0.0f, 1.0f, 0.0f); + break; + case 2: + glRotatef(180.0f, 0.0f, 1.0f, 0.0f); + break; + case 3: + glRotatef(-90.0f, 0.0f, 1.0f, 0.0f); + break; + case 4: + glRotatef(90.0f, 1.0f, 0.0f, 0.0f); + break; + case 5: + glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); + break; + default: + break; + } + + glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture( + TN_TITLE_BG_PANORAMA0 + j)); + t->begin(); + t->color(16777215, 255 / (i + 1)); + t->vertexUV(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f); + t->vertexUV(1.0f, -1.0f, 1.0f, 1.0f, 0.0f); + t->vertexUV(1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + t->vertexUV(-1.0f, 1.0f, 1.0f, 0.0f, 1.0f); + t->end(); + glPopMatrix(); + } + glPopMatrix(); + glColorMask(true, true, true, false); + } + + t->offset(0.0f, 0.0f, 0.0f); + glColorMask(true, true, true, true); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glDepthMask(true); + glEnable(GL_CULL_FACE); + glEnable(GL_ALPHA_TEST); + glEnable(GL_DEPTH_TEST); +#else + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, width, height, 0, 1000, 3000); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glTranslatef(0, 0, -2000); + + glDisable(GL_LIGHTING); + glDisable(GL_FOG); + glEnable(GL_TEXTURE_2D); + glDisable(GL_ALPHA_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(false); + + glBindTexture(GL_TEXTURE_2D, + minecraft->textures->loadTexture(TN_TITLE_BG_PANORAMA)); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + float off = vo * 0.0004f; + + float screenAspect = (float)width / (float)height; + float texAspect = 1748.0f / 144.0f; + float scale; + if (screenAspect > texAspect) { + scale = (float)width / 1748.0f; + } else { + scale = (float)height / 144.0f; + } + + float texWidth = 1748.0f * scale; + float texHeight = 144.0f * scale; + float yOff = (height - texHeight) / 2.0f; + + float uMax = off + (texWidth / 1748.0f); + + t->begin(GL_QUADS); + t->color(0xffffff, 255); + t->vertexUV(0, yOff + texHeight, 0, off, 1.0f); + t->vertexUV(texWidth, yOff + texHeight, 0, uMax, 1.0f); + t->vertexUV(texWidth, yOff, 0, uMax, 0.0f); + t->vertexUV(0, yOff, 0, off, 0.0f); + t->end(); + + glDepthMask(true); + glDisable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +#endif +#endif +} + +// 4jcraft +void TitleScreen::renderSkybox(float a) { +#ifdef ENABLE_JAVA_GUIS +#ifdef CLASSIC_PANORAMA + glViewport(0, 0, 256, 256); +#endif + renderPanorama(a); +#ifdef CLASSIC_PANORAMA + glDisable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_2D); + + for (int i = 0; i < 8; i++) { + rotateAndBlur(a); + } + + glViewport(0, 0, minecraft->width, minecraft->height); + + Tesselator* t = Tesselator::getInstance(); + t->begin(); + float aspect = + width > height ? 120.0f / (float)width : 120.0f / (float)height; + float sWidth = (float)height * aspect / 256.0f; + float sHeight = (float)width * aspect / 256.0f; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + t->color(1.0f, 1.0f, 1.0f, 1.0f); + t->vertexUV(0.0f, height, 0.0f, (0.5f - sWidth), (0.5f + sHeight)); + t->vertexUV(width, height, 0.0f, (0.5f - sWidth), (0.5f - sHeight)); + t->vertexUV(width, 0.0f, 0.0f, (0.5f + sWidth), (0.5f - sHeight)); + t->vertexUV(0.0f, 0.0f, 0.0f, (0.5f + sWidth), (0.5f + sHeight)); + t->end(); +#endif +#endif +} + +// 4jcraft +void TitleScreen::rotateAndBlur(float a) { +#if defined(ENABLE_JAVA_GUIS) && defined(CLASSIC_PANORAMA) + glBindTexture(GL_TEXTURE_2D, viewportTexture); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 256, 256); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColorMask(true, true, true, false); + Tesselator* t = Tesselator::getInstance(); + t->begin(); + char blurPasses = 3; + + for (int i = 0; i < blurPasses; i++) { + t->color(1.0f, 1.0f, 1.0f, 1.0f / (float)(i + 1)); + float offset = (float)(i - blurPasses / 2) / 256.0f; + t->vertexUV(width, height, 0.0f, (0.0f + offset), 0.0f); + t->vertexUV(width, 0.0f, 0.0f, (1.0f + offset), 0.0f); + t->vertexUV(0.0f, 0.0f, 0.0f, (1.0f + offset), 1.0f); + t->vertexUV(0.0f, height, 0.0f, (0.0f + offset), 1.0f); + } + + t->end(); + glColorMask(true, true, true, true); +#endif +} + +void TitleScreen::render(int xm, int ym, float a) { +#ifdef ENABLE_JAVA_GUIS + // 4jcraft: panorama + renderSkybox(a); + Tesselator* t = Tesselator::getInstance(); int logoWidth = 155 + 119; int logoX = width / 2 - logoWidth / 2; int logoY = 30; + // 4jcraft: gradient for classic panorama +#ifdef CLASSIC_PANORAMA + fillGradient(0, 0, width, height, -2130706433, 16777215); + fillGradient(0, 0, width, height, 0, INT_MIN); +#endif + glBindTexture(GL_TEXTURE_2D, minecraft->textures->loadTexture(TN_TITLE_MCLOGO)); glColor4f(1, 1, 1, 1); @@ -155,7 +400,9 @@ void TitleScreen::render(int xm, int ym, float a) { drawCenteredString(font, splash, 0, -8, 0xffff00); glPopMatrix(); - drawString(font, ClientConstants::VERSION_STRING, 2, 2, 0x505050); + drawString( + font, ClientConstants::VERSION_STRING, 2, height - 10, + 0xffffff); // 4jcraft: use the same height as the copyright message wstring msg = L"Copyright Mojang AB. Do not distribute."; drawString(font, msg, width - font->width(msg) - 2, height - 10, 0xffffff); diff --git a/Minecraft.Client/UI/Screens/TitleScreen.h b/Minecraft.Client/UI/Screens/TitleScreen.h index 6a27ae427..5df5d4984 100644 --- a/Minecraft.Client/UI/Screens/TitleScreen.h +++ b/Minecraft.Client/UI/Screens/TitleScreen.h @@ -12,19 +12,38 @@ private: std::wstring splash; Button* multiplayerButton; + // 4jcraft: panorama + void renderPanorama(float a); + void renderSkybox(float a); + void rotateAndBlur(float a); + int viewportTexture; + + // 4jcraft: taken from UIScene_MainMenu + // 4J Added + enum eSplashIndexes { + eSplashHappyBirthdayEx = 0, + eSplashHappyBirthdayNotch, + eSplashMerryXmas, + eSplashHappyNewYear, + + // The start index in the splashes vector from which we can select a + // random splash + eSplashRandomStart, + }; + public: TitleScreen(); - virtual void tick(); + virtual void tick() override; protected: - virtual void keyPressed(wchar_t eventCharacter, int eventKey); + virtual void keyPressed(wchar_t eventCharacter, int eventKey) override; public: - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/TrapScreen.cpp b/Minecraft.Client/UI/Screens/TrapScreen.cpp index 80de6d7e9..7936ec174 100644 --- a/Minecraft.Client/UI/Screens/TrapScreen.cpp +++ b/Minecraft.Client/UI/Screens/TrapScreen.cpp @@ -6,23 +6,28 @@ #include "../../../Minecraft.World/Blocks/TileEntities/DispenserTileEntity.h" #include "../../../Minecraft.World/Headers/net.minecraft.world.h" +#ifdef ENABLE_JAVA_GUIS +ResourceLocation GUI_TRAP_LOCATION = ResourceLocation(TN_GUI_TRAP); +#endif + TrapScreen::TrapScreen(std::shared_ptr inventory, std::shared_ptr trap) - : AbstractContainerScreen(new TrapMenu(inventory, trap)) {} + : AbstractContainerScreen(new TrapMenu(inventory, trap)) { + this->trap = trap; + this->inventory = inventory; +} void TrapScreen::renderLabels() { - font->draw(L"Dispenser", 16 + 4 + 40, 2 + 2 + 2, 0x404040); - font->draw(L"Inventory", 8, imageHeight - 96 + 2, 0x404040); + font->draw(trap->getName(), 16 + 4 + 40, 2 + 2 + 2, 0x404040); + font->draw(inventory->getName(), 8, imageHeight - 96 + 2, 0x404040); } void TrapScreen::renderBg(float a) { - // 4J Unused -#if 0 - int tex = minecraft->textures->loadTexture(L"/gui/trap.png"); - glColor4f(1, 1, 1, 1); - minecraft->textures->bind(tex); - int xo = (width - imageWidth) / 2; - int yo = (height - imageHeight) / 2; - this->blit(xo, yo, 0, 0, imageWidth, imageHeight); +#ifdef ENABLE_JAVA_GUIS + glColor4f(1, 1, 1, 1); + minecraft->textures->bindTexture(&GUI_TRAP_LOCATION); + int xo = (width - imageWidth) / 2; + int yo = (height - imageHeight) / 2; + this->blit(xo, yo, 0, 0, imageWidth, imageHeight); #endif } \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/TrapScreen.h b/Minecraft.Client/UI/Screens/TrapScreen.h index fcf8a33fa..ae2b02c89 100644 --- a/Minecraft.Client/UI/Screens/TrapScreen.h +++ b/Minecraft.Client/UI/Screens/TrapScreen.h @@ -1,4 +1,5 @@ #pragma once +#include #include "AbstractContainerScreen.h" class DispenserTileEntity; class Inventory; @@ -11,4 +12,8 @@ public: protected: virtual void renderLabels(); virtual void renderBg(float a); + +private: + std::shared_ptr inventory; + std::shared_ptr trap; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/Screens/VideoSettingsScreen.cpp b/Minecraft.Client/UI/Screens/VideoSettingsScreen.cpp index 5daf8fdcc..e97aa1f54 100644 --- a/Minecraft.Client/UI/Screens/VideoSettingsScreen.cpp +++ b/Minecraft.Client/UI/Screens/VideoSettingsScreen.cpp @@ -6,6 +6,9 @@ #include "ControlsScreen.h" #include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +// 4jcraft +#define ITEM_COUNT 10 + VideoSettingsScreen::VideoSettingsScreen(Screen* lastScreen, Options* options) { this->title = L"Video Settings"; // 4J - added this->lastScreen = lastScreen; @@ -16,18 +19,19 @@ void VideoSettingsScreen::init() { Language* language = Language::getInstance(); this->title = language->getElement(L"options.videoTitle"); - const Options::Option* items[10] = {Options::Option::GRAPHICS, - Options::Option::RENDER_DISTANCE, - Options::Option::AMBIENT_OCCLUSION, - Options::Option::FRAMERATE_LIMIT, - Options::Option::ANAGLYPH, - Options::Option::VIEW_BOBBING, - Options::Option::GUI_SCALE, - Options::Option::ADVANCED_OPENGL, - Options::Option::GAMMA, - Options::Option::FOV}; + const Options::Option* items[ITEM_COUNT] = { + Options::Option::GRAPHICS, + Options::Option::RENDER_DISTANCE, + Options::Option::AMBIENT_OCCLUSION, + Options::Option::FRAMERATE_LIMIT, + Options::Option::ANAGLYPH, + Options::Option::VIEW_BOBBING, + Options::Option::GUI_SCALE, + Options::Option::ADVANCED_OPENGL, + Options::Option::GAMMA, + Options::Option::FOV}; - for (int i = 0; i < 10; i++) { + for (int i = 0; i < ITEM_COUNT; i++) { const Options::Option* item = items[i]; int xPos = width / 2 - 155 + (i % 2 * 160); int yPos = height / 6 + 24 * (i / 2); diff --git a/Minecraft.Client/UI/Screens/VideoSettingsScreen.h b/Minecraft.Client/UI/Screens/VideoSettingsScreen.h index 7075523b2..bbeb74698 100644 --- a/Minecraft.Client/UI/Screens/VideoSettingsScreen.h +++ b/Minecraft.Client/UI/Screens/VideoSettingsScreen.h @@ -14,11 +14,11 @@ private: public: VideoSettingsScreen(Screen* lastScreen, Options* options); - virtual void init(); + virtual void init() override; protected: - virtual void buttonClicked(Button* button); + virtual void buttonClicked(Button* button) override; public: - virtual void render(int xm, int ym, float a); + virtual void render(int xm, int ym, float a) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/SlideButton.h b/Minecraft.Client/UI/SlideButton.h index 28e7726ef..f2db25366 100644 --- a/Minecraft.Client/UI/SlideButton.h +++ b/Minecraft.Client/UI/SlideButton.h @@ -16,10 +16,10 @@ public: const std::wstring& msg, float value); protected: - virtual int getYImage(bool hovered); - virtual void renderBg(Minecraft* minecraft, int xm, int ym); + virtual int getYImage(bool hovered) override; + virtual void renderBg(Minecraft* minecraft, int xm, int ym) override; public: - virtual bool clicked(Minecraft* minecraft, int mx, int my); - virtual void released(int mx, int my); + virtual bool clicked(Minecraft* minecraft, int mx, int my) override; + virtual void released(int mx, int my) override; }; \ No newline at end of file diff --git a/Minecraft.Client/UI/TradeSwitchButton.cpp b/Minecraft.Client/UI/TradeSwitchButton.cpp new file mode 100644 index 000000000..860a2c43f --- /dev/null +++ b/Minecraft.Client/UI/TradeSwitchButton.cpp @@ -0,0 +1,46 @@ +#include "../../Platform/stdafx.h" +#include "TradeSwitchButton.h" +#include "../Textures/Textures.h" +#include "../Rendering/Tesselator.h" +#include "../../../Minecraft.Client/Minecraft.h" +#include "../../../Minecraft.World/Headers/net.minecraft.locale.h" +#include "../../../Minecraft.World/Containers/MerchantMenu.h" + +// 4jcraft: referenced from MCP 8.11 (JE 1.6.4) +#ifdef ENABLE_JAVA_GUIS +// ResourceLocation GUI_VILLAGER_LOCATION = ResourceLocation(TN_GUI_VILLAGER); +extern ResourceLocation GUI_VILLAGER_LOCATION; +#endif + +TradeSwitchButton::TradeSwitchButton(int id, int x, int y, bool mirrored) + : Button(id, x, y, 12, 19, L"") { + this->mirrored = mirrored; +} + +int TradeSwitchButton::getYImage(bool hovered) { return 0; } + +void TradeSwitchButton::renderBg(Minecraft* minecraft, int xm, int ym) { +#ifdef ENABLE_JAVA_GUIS + if (!visible) return; + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + minecraft->textures->bindTexture(&GUI_VILLAGER_LOCATION); + + bool hovered = (xm >= x && ym >= y && xm < x + w && ym < y + h); + + int textureX = 176; + int textureY = 0; + + if (!active) { + textureX += w * 2; + } else if (hovered) { + textureX += w; + } + + if (!mirrored) { + textureY += h; + } + + blit(x, y, textureX, textureY, w, h); +#endif +} \ No newline at end of file diff --git a/Minecraft.Client/UI/TradeSwitchButton.h b/Minecraft.Client/UI/TradeSwitchButton.h new file mode 100644 index 000000000..f5e8e0f0b --- /dev/null +++ b/Minecraft.Client/UI/TradeSwitchButton.h @@ -0,0 +1,14 @@ +#pragma once +#include "Button.h" + +class TradeSwitchButton : public Button { +private: + bool mirrored; + +public: + TradeSwitchButton(int id, int x, int y, bool mirrored); + +protected: + int getYImage(bool hovered) override; + void renderBg(Minecraft* minecraft, int xm, int ym) override; +}; \ No newline at end of file diff --git a/Minecraft.Client/meson.build b/Minecraft.Client/meson.build index 8bcc874b1..9bb614fc4 100644 --- a/Minecraft.Client/meson.build +++ b/Minecraft.Client/meson.build @@ -75,6 +75,10 @@ if get_option('enable_vsync') global_cpp_defs += '-DENABLE_VSYNC' endif +if get_option('classic_panorama') + global_cpp_defs += '-DCLASSIC_PANORAMA' +endif + if get_option('ui_backend') == 'shiggy' shiggy_dep = dependency( 'shiggy', diff --git a/Minecraft.World/Containers/RepairContainer.h b/Minecraft.World/Containers/RepairContainer.h index edb7a6756..1494a1099 100644 --- a/Minecraft.World/Containers/RepairContainer.h +++ b/Minecraft.World/Containers/RepairContainer.h @@ -11,6 +11,6 @@ private: public: RepairContainer(AnvilMenu* menu, int name, bool customName, int size); - void setChanged(); - bool canPlaceItem(int slot, std::shared_ptr item); + void setChanged() override; + bool canPlaceItem(int slot, std::shared_ptr item) override; }; \ No newline at end of file diff --git a/Minecraft.World/Containers/RepairResultSlot.h b/Minecraft.World/Containers/RepairResultSlot.h index 1f8f0f4ea..2dc6b5c17 100644 --- a/Minecraft.World/Containers/RepairResultSlot.h +++ b/Minecraft.World/Containers/RepairResultSlot.h @@ -14,9 +14,10 @@ public: std::shared_ptr container, int slot, int x, int y); - bool mayPlace(std::shared_ptr item); - bool mayPickup(std::shared_ptr player); + bool mayPlace(std::shared_ptr item) override; + bool mayPickup(std::shared_ptr player) override; void onTake(std::shared_ptr player, - std::shared_ptr carried); - virtual bool mayCombine(std::shared_ptr item); // 4J Added + std::shared_ptr carried) override; + virtual bool mayCombine( + std::shared_ptr item) override; // 4J Added }; \ No newline at end of file diff --git a/Minecraft.World/Containers/ResultContainer.h b/Minecraft.World/Containers/ResultContainer.h index 69ed8ed1e..dc4ff7a9e 100644 --- a/Minecraft.World/Containers/ResultContainer.h +++ b/Minecraft.World/Containers/ResultContainer.h @@ -10,19 +10,21 @@ public: // 4J Stu Added a ctor to init items ResultContainer(); - virtual unsigned int getContainerSize(); - virtual std::shared_ptr getItem(unsigned int slot); - virtual std::wstring getName(); - virtual std::wstring getCustomName(); - virtual bool hasCustomName(); + virtual unsigned int getContainerSize() override; + virtual std::shared_ptr getItem(unsigned int slot) override; + virtual std::wstring getName() override; + virtual std::wstring getCustomName() override; + virtual bool hasCustomName() override; virtual std::shared_ptr removeItem(unsigned int slot, - int count); - virtual std::shared_ptr removeItemNoUpdate(int slot); - virtual void setItem(unsigned int slot, std::shared_ptr item); - virtual int getMaxStackSize(); - virtual void setChanged(); - virtual bool stillValid(std::shared_ptr player); - virtual void startOpen() {} // TODO Auto-generated method stub - virtual void stopOpen() {} // TODO Auto-generated method stub - virtual bool canPlaceItem(int slot, std::shared_ptr item); + int count) override; + virtual std::shared_ptr removeItemNoUpdate(int slot) override; + virtual void setItem(unsigned int slot, + std::shared_ptr item) override; + virtual int getMaxStackSize() override; + virtual void setChanged() override; + virtual bool stillValid(std::shared_ptr player) override; + virtual void startOpen() override {} // TODO Auto-generated method stub + virtual void stopOpen() override {} // TODO Auto-generated method stub + virtual bool canPlaceItem(int slot, + std::shared_ptr item) override; }; \ No newline at end of file diff --git a/Minecraft.World/Containers/ResultSlot.h b/Minecraft.World/Containers/ResultSlot.h index b2a0347f4..46fecd0b2 100644 --- a/Minecraft.World/Containers/ResultSlot.h +++ b/Minecraft.World/Containers/ResultSlot.h @@ -14,15 +14,18 @@ public: std::shared_ptr container, int id, int x, int y); virtual ~ResultSlot() {} - virtual bool mayPlace(std::shared_ptr item); - virtual std::shared_ptr remove(int c); + virtual bool mayPlace(std::shared_ptr item) override; + virtual std::shared_ptr remove(int c) override; protected: - virtual void onQuickCraft(std::shared_ptr picked, int count); - virtual void checkTakeAchievements(std::shared_ptr carried); + virtual void onQuickCraft(std::shared_ptr picked, + int count) override; + virtual void checkTakeAchievements( + std::shared_ptr carried) override; public: virtual void onTake(std::shared_ptr player, - std::shared_ptr carried); - virtual bool mayCombine(std::shared_ptr item); // 4J Added + std::shared_ptr carried) override; + virtual bool mayCombine( + std::shared_ptr item) override; // 4J Added }; \ No newline at end of file diff --git a/Minecraft.World/Containers/SimpleContainer.h b/Minecraft.World/Containers/SimpleContainer.h index 74392b3f3..e9164c1eb 100644 --- a/Minecraft.World/Containers/SimpleContainer.h +++ b/Minecraft.World/Containers/SimpleContainer.h @@ -19,20 +19,22 @@ public: virtual void addListener(net_minecraft_world::ContainerListener* listener); virtual void removeListener( net_minecraft_world::ContainerListener* listener); - virtual std::shared_ptr getItem(unsigned int slot); + virtual std::shared_ptr getItem(unsigned int slot) override; virtual std::shared_ptr removeItem(unsigned int slot, - int count); - virtual std::shared_ptr removeItemNoUpdate(int slot); - virtual void setItem(unsigned int slot, std::shared_ptr item); - virtual unsigned int getContainerSize(); - virtual std::wstring getName(); - virtual std::wstring getCustomName(); - virtual bool hasCustomName(); + int count) override; + virtual std::shared_ptr removeItemNoUpdate(int slot) override; + virtual void setItem(unsigned int slot, + std::shared_ptr item) override; + virtual unsigned int getContainerSize() override; + virtual std::wstring getName() override; + virtual std::wstring getCustomName() override; + virtual bool hasCustomName() override; virtual void setCustomName(const std::wstring& name); - virtual int getMaxStackSize(); - virtual void setChanged(); - virtual bool stillValid(std::shared_ptr player); - virtual void startOpen() {} // TODO Auto-generated method stub - virtual void stopOpen() {} // TODO Auto-generated method stub - virtual bool canPlaceItem(int slot, std::shared_ptr item); + virtual int getMaxStackSize() override; + virtual void setChanged() override; + virtual bool stillValid(std::shared_ptr player) override; + virtual void startOpen() override {} // TODO Auto-generated method stub + virtual void stopOpen() override {} // TODO Auto-generated method stub + virtual bool canPlaceItem(int slot, + std::shared_ptr item) override; }; \ No newline at end of file diff --git a/Minecraft.World/Containers/TrapMenu.h b/Minecraft.World/Containers/TrapMenu.h index 03b818380..c4f38b626 100644 --- a/Minecraft.World/Containers/TrapMenu.h +++ b/Minecraft.World/Containers/TrapMenu.h @@ -18,7 +18,7 @@ public: TrapMenu(std::shared_ptr inventory, std::shared_ptr trap); - virtual bool stillValid(std::shared_ptr player); + virtual bool stillValid(std::shared_ptr player) override; virtual std::shared_ptr quickMoveStack( - std::shared_ptr player, int slotIndex); + std::shared_ptr player, int slotIndex) override; }; \ No newline at end of file diff --git a/Minecraft.World/Entities/MobEffect.cpp b/Minecraft.World/Entities/MobEffect.cpp index a0822934f..828b5a4e3 100644 --- a/Minecraft.World/Entities/MobEffect.cpp +++ b/Minecraft.World/Entities/MobEffect.cpp @@ -443,4 +443,53 @@ void MobEffect::addAttributeModifiers(std::shared_ptr entity, double MobEffect::getAttributeModifierValue(int amplifier, AttributeModifier* original) { return original->getAmount() * (amplifier + 1); +} + +// 4jcraft: helper for inventoryscreen and beaconscreen +int MobEffect::javaId(int id) { + // mapped to java based on the inventory texture (see gui/inventory.png) + switch (id) { + case 1: + return 0; + case 2: + return 1; + case 3: + return 2; + case 4: + return 3; + case 5: + return 4; + case 18: + return 5; + case 19: + return 6; + case 10: + return 7; + case 14: + return 8; + case 17: + return 9; + case 8: + return 10; + case 9: + return 11; + case 16: + return 12; + case 15: + return 13; + case 11: + return 14; + case 12: + return 15; + case 13: + return 16; + case 20: + return 17; + case 21: + return 18; + case 22: + return 18; + default: + return 0; + } } \ No newline at end of file diff --git a/Minecraft.World/Entities/MobEffect.h b/Minecraft.World/Entities/MobEffect.h index 8e7ccce17..5576a2b4b 100644 --- a/Minecraft.World/Entities/MobEffect.h +++ b/Minecraft.World/Entities/MobEffect.h @@ -134,4 +134,6 @@ public: int amplifier); virtual double getAttributeModifierValue(int amplifier, AttributeModifier* original); + static int javaId( + int id); // 4jcraft: helper for inventoryscreen and beaconscreen }; \ No newline at end of file diff --git a/meson.options b/meson.options index 545d2a159..68eb92598 100644 --- a/meson.options +++ b/meson.options @@ -4,6 +4,11 @@ option('ui_backend', value : 'shiggy', description : 'Specifies a backend implementation for the game UI.') +option('classic_panorama', + type : 'boolean', + value : false, + description : 'Enable classic java edition panorama (ui_backend=java ONLY).') + option('enable_vsync', type : 'boolean', value : true,