|
16 | 16 | class ArmorHUDListener : public Listener { |
17 | 17 | public: |
18 | 18 |
|
19 | | - Module* module; |
| 19 | + Module *module; |
20 | 20 | Vec2<float> currentPos; |
21 | 21 | bool enabled = false; |
| 22 | + int durabilities[4][2] = { |
| 23 | + {0,0}, |
| 24 | + {0,0}, |
| 25 | + {0,0}, |
| 26 | + {0,0} |
| 27 | + }; |
| 28 | + // TODO: delete testing variables (or adjust and delete) |
| 29 | + Vec2<float> testOffset = Vec2<float>{4,0}; |
| 30 | + float testSpacing = 46; |
22 | 31 |
|
23 | | - Vec2<float> convert() { |
| 32 | + |
| 33 | + |
| 34 | + [[nodiscard]] Vec2<float> convert() const { |
24 | 35 |
|
25 | 36 | auto e = SDK::clientInstance->guiData; |
26 | 37 | Vec2<float> xd = Vec2<float>(e->ScreenSize.x, e->ScreenSize.y); |
27 | 38 | Vec2<float> LOL = Vec2<float>(e->ScreenSizeScaled.x, e->ScreenSizeScaled.y); |
28 | 39 |
|
29 | | - return {currentPos.x * (LOL.x / xd.x), currentPos.y * (LOL.y / xd.y)}; |
| 40 | + return Vec2<float>{currentPos.x * (LOL.x / xd.x), currentPos.y * (LOL.y / xd.y)}; |
30 | 41 | } |
| 42 | + // TODO: Make it look better |
| 43 | + void renderDurability() { |
| 44 | + if(FlarialGUI::inMenu) return; |
| 45 | + Vec2<float> convert = this->convert(); |
31 | 46 |
|
32 | | - void onRender(RenderEvent& event) override { |
| 47 | + const float textWidth = Constraints::RelativeConstraint(0.12, "height", true); |
| 48 | + const float textHeight = Constraints::RelativeConstraint(0.029, "height", true); |
| 49 | + if (SDK::hasInstanced && SDK::clientInstance != nullptr) { |
| 50 | + if (SDK::clientInstance->getLocalPlayer() != nullptr) |
| 51 | + if (SDK::clientInstance->getLocalPlayer()->playerInventory != nullptr) { |
33 | 52 |
|
34 | | - if(!module->settings.getSettingByName<bool>("enabled")->value) enabled = false; |
| 53 | + if (SDK::clientInstance->getLocalPlayer()->playerInventory->inventory->getItem( |
| 54 | + SDK::clientInstance->getLocalPlayer()->playerInventory->SelectedSlot)->getItem() != |
| 55 | + nullptr) { |
| 56 | + auto currentItem = SDK::clientInstance->getLocalPlayer()->playerInventory->inventory->getItem( |
| 57 | + SDK::clientInstance->getLocalPlayer()->playerInventory->SelectedSlot); |
35 | 58 |
|
36 | | - if(SDK::clientInstance->getTopScreenName() == "hud_screen" && module->settings.getSettingByName<bool>("enabled")->value || SDK::clientInstance->getTopScreenName() == "pause_screen" && module->settings.getSettingByName<bool>("enabled")->value) { |
| 59 | + const std::string text = std::to_string(currentItem->getcount()); |
37 | 60 |
|
38 | | - if(!enabled && ModuleManager::getModule("ClickGUI")->settings.getSettingByName<bool>("enabled")->value) { |
39 | | - FlarialGUI::Notify("To change the position of ArmorHUD, Please click " + ModuleManager::getModule("ClickGUI")->settings.getSettingByName<std::string>("editmenubind")->value + " in the settings tab."); |
40 | | - enabled = true; |
41 | | - } |
| 61 | + std::wstring widestr = std::wstring(text.begin(), text.end()); |
| 62 | + |
| 63 | + const wchar_t *widecstr = widestr.c_str(); |
| 64 | + |
| 65 | + FlarialGUI::FlarialTextWithFont(currentPos.x + testOffset.x, currentPos.y + testOffset.y, |
| 66 | + widecstr, textWidth * 6.9f, |
| 67 | + textHeight, DWRITE_TEXT_ALIGNMENT_LEADING, |
| 68 | + Constraints::RelativeConstraint(0.12, "height", true), |
| 69 | + DWRITE_FONT_WEIGHT_NORMAL); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + float spacing = testSpacing * module->settings.getSettingByName<float>("uiscale")->value; |
| 74 | + |
| 75 | + float xmodifier = 0.0f; |
| 76 | + float ymodifier = 0.0f; |
| 77 | + |
| 78 | + float xoffset = 0.0f; |
| 79 | + float yoffset = 0.0f; |
| 80 | + |
| 81 | + if (module->settings.getSettingByName<bool>("vertical")->value) xoffset += spacing; |
| 82 | + else yoffset += spacing; |
| 83 | + |
| 84 | + for (int i = 0; i < 4; i++) { |
| 85 | + |
| 86 | + if (module->settings.getSettingByName<bool>("vertical")->value) ymodifier += spacing; |
| 87 | + else xmodifier += spacing; |
| 88 | + |
| 89 | + |
| 90 | + if (SDK::clientInstance->getLocalPlayer()->getArmor(i)->getItem() != nullptr) { |
| 91 | + |
| 92 | + convert = this->convert(); |
| 93 | + |
| 94 | + |
| 95 | + const std::string text = |
| 96 | + std::to_string(durabilities[i][0]) + "/" + std::to_string(durabilities[i][1]); |
| 97 | + |
| 98 | + std::wstring widestr = std::wstring(text.begin(), text.end()); |
| 99 | + |
| 100 | + const wchar_t *widecstr = widestr.c_str(); |
42 | 101 |
|
43 | | - float s = Constraints::RelativeConstraint(0.04, "height", true) * module->settings.getSettingByName<float>("uiscale")->value; |
| 102 | + FlarialGUI::FlarialTextWithFont( |
| 103 | + currentPos.x + xmodifier + xoffset + testOffset.x, |
| 104 | + currentPos.y + ymodifier + yoffset + testOffset.y, widecstr, textWidth * 6.9f, |
| 105 | + textHeight, DWRITE_TEXT_ALIGNMENT_LEADING, |
| 106 | + Constraints::RelativeConstraint(0.12, "height", true), |
| 107 | + DWRITE_FONT_WEIGHT_NORMAL); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + void onRender(RenderEvent &event) override { |
| 115 | + if (ClientInstance::getTopScreenName() == "hud_screen" && |
| 116 | + module->isEnabled()) { |
44 | 117 |
|
45 | | - float spacing = Constraints::RelativeConstraint(0.0135, "height", true) * module->settings.getSettingByName<float>("uiscale")->value; |
| 118 | + float s = Constraints::RelativeConstraint(0.04, "height", true) * |
| 119 | + module->settings.getSettingByName<float>("uiscale")->value; |
| 120 | + |
| 121 | + float spacing = Constraints::RelativeConstraint(0.0135, "height", true) * |
| 122 | + module->settings.getSettingByName<float>("uiscale")->value; |
46 | 123 |
|
47 | 124 | Vec2<float> settingperc = Vec2<float>(module->settings.getSettingByName<float>("percentageX")->value, |
48 | | - module->settings.getSettingByName<float>("percentageY")->value); |
| 125 | + module->settings.getSettingByName<float>("percentageY")->value); |
49 | 126 |
|
50 | 127 | if (settingperc.x != 0) |
51 | 128 | currentPos = Vec2<float>(settingperc.x * MC::windowSize.x, |
52 | 129 | settingperc.y * MC::windowSize.y); |
53 | 130 | else |
54 | 131 | currentPos = Constraints::CenterConstraint(s * 3 + spacing * 3, s); |
55 | 132 |
|
56 | | - if(ClickGUIRenderer::editmenu) { |
| 133 | + if (ClickGUIRenderer::editmenu) { |
| 134 | + // bounding boxes |
57 | 135 | if (!module->settings.getSettingByName<bool>("vertical")->value) |
58 | 136 | FlarialGUI::SetWindowRect(currentPos.x, currentPos.y, s * 3 + spacing * 3, s, 18); |
59 | 137 | else FlarialGUI::SetWindowRect(currentPos.x, currentPos.y, s, s * 3 + spacing * 3, 18); |
60 | 138 | } |
61 | 139 |
|
62 | 140 | Vec2<float> vec2; |
63 | | - |
| 141 | + // bounding boxes |
64 | 142 | if (!module->settings.getSettingByName<bool>("vertical")->value) |
65 | | - vec2 = FlarialGUI::CalculateMovedXY(currentPos.x , currentPos.y, 18, s * 3 + spacing * 3, s); |
66 | | - else vec2 = FlarialGUI::CalculateMovedXY(currentPos.x , currentPos.y, 18, s, s * 3 + spacing * 3); |
| 143 | + vec2 = FlarialGUI::CalculateMovedXY(currentPos.x, currentPos.y, 18, s * 3 + spacing * 3, s); |
| 144 | + else vec2 = FlarialGUI::CalculateMovedXY(currentPos.x, currentPos.y, 18, s, s * 3 + spacing * 3); |
67 | 145 |
|
68 | 146 | currentPos.x = vec2.x; |
69 | 147 | currentPos.y = vec2.y; |
70 | 148 |
|
71 | | - currentPos = currentPos; |
72 | | - |
73 | 149 | Vec2<float> percentages = Constraints::CalculatePercentage(currentPos.x, currentPos.y); |
74 | 150 |
|
75 | 151 | module->settings.setValue("percentageX", percentages.x); |
76 | 152 | module->settings.setValue("percentageY", percentages.y); |
77 | 153 |
|
78 | | - if(ClickGUIRenderer::editmenu) |
79 | | - FlarialGUI::UnsetWindowRect(); |
80 | | - } else { |
81 | | - enabled = false; |
| 154 | + if (ClickGUIRenderer::editmenu) |
| 155 | + FlarialGUI::UnsetWindowRect(); |
| 156 | + |
| 157 | + if(module->settings.getSettingByName<bool>("showdurability")->value) |
| 158 | + renderDurability(); |
82 | 159 | } |
83 | 160 |
|
84 | | - if (SDK::CurrentScreen != "hud_screen") ClickGUIRenderer::editmenu = false; |
| 161 | + if (SDK::currentScreen != "hud_screen") ClickGUIRenderer::editmenu = false; |
85 | 162 | } |
86 | 163 |
|
87 | | - void onSetupAndRender(SetupAndRenderEvent& event) override { |
88 | | - |
89 | | - if (SDK::clientInstance->getTopScreenName() == "hud_screen" && module->settings.getSettingByName<bool>("enabled")->value) { |
90 | | - |
91 | | - BaseActorRenderContext barc(event.muirc->screenContext, event.muirc->clientInstance, event.muirc->clientInstance->mcgame); |
| 164 | + void onSetupAndRender(SetupAndRenderEvent &event) override { |
| 165 | + if (ClientInstance::getTopScreenName() == "hud_screen") { |
| 166 | + auto muirc = event.getMuirc(); |
| 167 | + BaseActorRenderContext barc(muirc->screenContext, muirc->clientInstance, |
| 168 | + muirc->clientInstance->mcgame); |
92 | 169 |
|
93 | 170 | Vec2<float> convert = this->convert(); |
94 | | - |
95 | | - if(SDK::clientInstance->getLocalPlayer() != nullptr) |
96 | | - if (SDK::clientInstance->getLocalPlayer()->playerInventory != nullptr) { |
97 | | - if (SDK::clientInstance->getLocalPlayer()->playerInventory->inventory->getItem(SDK::clientInstance->getLocalPlayer()->playerInventory->SelectedSlot)->getItem() != nullptr) |
98 | | - barc.itemRenderer->renderGuiItemNew(&barc, SDK::clientInstance->getLocalPlayer()->playerInventory->inventory->getItem(SDK::clientInstance->getLocalPlayer()->playerInventory->SelectedSlot), 0, convert.x, convert.y, 1.0f, module->settings.getSettingByName<float>("uiscale")->value, false); |
99 | | - |
100 | | - |
101 | | - float spacing = 15 * module->settings.getSettingByName<float>("uiscale")->value; |
102 | | - |
103 | | - float xmodifier = 0.0f; |
104 | | - float ymodifier = 0.0f; |
105 | | - |
106 | | - for (int i = 0; i < 4; i++) { |
107 | | - |
108 | | - if (module->settings.getSettingByName<bool>("vertical")->value) ymodifier += spacing; |
109 | | - else xmodifier += spacing; |
110 | | - |
111 | | - if (SDK::clientInstance->getLocalPlayer()->getArmor(i)->getItem() != nullptr) { |
112 | | - |
113 | | - convert = this->convert(); |
114 | | - barc.itemRenderer->renderGuiItemNew(&barc, SDK::clientInstance->getLocalPlayer()->getArmor(i), 0, convert.x + xmodifier, convert.y + ymodifier, 1.0f, module->settings.getSettingByName<float>("uiscale")->value, false); |
115 | | - |
| 171 | + if (SDK::hasInstanced && SDK::clientInstance != nullptr) { |
| 172 | + if (SDK::clientInstance->getLocalPlayer() != nullptr) |
| 173 | + if (SDK::clientInstance->getLocalPlayer()->playerInventory != nullptr) { |
| 174 | + if (SDK::clientInstance->getLocalPlayer()->playerInventory->inventory->getItem( |
| 175 | + SDK::clientInstance->getLocalPlayer()->playerInventory->SelectedSlot)->getItem() != |
| 176 | + nullptr) |
| 177 | + barc.itemRenderer->renderGuiItemNew(&barc, |
| 178 | + SDK::clientInstance->getLocalPlayer()->playerInventory->inventory->getItem( |
| 179 | + SDK::clientInstance->getLocalPlayer()->playerInventory->SelectedSlot), |
| 180 | + 0, convert.x, convert.y, 1.0f, |
| 181 | + module->settings.getSettingByName<float>( |
| 182 | + "uiscale")->value, |
| 183 | + false); |
| 184 | + |
| 185 | + |
| 186 | + float spacing = 15 * module->settings.getSettingByName<float>("uiscale")->value; |
| 187 | + |
| 188 | + float xmodifier = 0.0f; |
| 189 | + float ymodifier = 0.0f; |
| 190 | + |
| 191 | + for (int i = 0; i < 4; i++) { |
| 192 | + |
| 193 | + if (module->settings.getSettingByName<bool>("vertical")->value) ymodifier += spacing; |
| 194 | + else xmodifier += spacing; |
| 195 | + |
| 196 | + if (SDK::clientInstance->getLocalPlayer()->getArmor(i)->getItem() != nullptr) { |
| 197 | + durabilities[i][1] = SDK::clientInstance->getLocalPlayer()->getArmor(i)->getMaxDamage(); |
| 198 | + durabilities[i][0] = durabilities[i][1] - |
| 199 | + SDK::clientInstance->getLocalPlayer()->getArmor( |
| 200 | + i)->getDamageValue(); |
| 201 | + |
| 202 | + |
| 203 | + convert = this->convert(); |
| 204 | + barc.itemRenderer->renderGuiItemNew(&barc, |
| 205 | + SDK::clientInstance->getLocalPlayer()->getArmor(i), |
| 206 | + 0, |
| 207 | + convert.x + xmodifier, convert.y + ymodifier, 1.0f, |
| 208 | + module->settings.getSettingByName<float>( |
| 209 | + "uiscale")->value, false); |
| 210 | + } |
| 211 | + } |
116 | 212 | } |
117 | | - } |
118 | 213 | } |
119 | 214 | } |
120 | 215 | } |
121 | 216 |
|
122 | 217 | public: |
123 | | - explicit ArmorHUDListener(const char string[5], Module* module) { |
| 218 | + explicit ArmorHUDListener(const char string[5], Module *module) { |
124 | 219 | this->name = string; |
125 | 220 | this->module = module; |
126 | 221 | this->currentPos = Vec2<float>(0, 0); |
|
0 commit comments