added a SHIT ton of modules
This commit is contained in:
1 parent
b1634d195c
commit
361892bf0b
64 files changed
+5346
-482
No files matched your search
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
#include "module.h"
|
||||
#include "../game/inventory_tools.h"
|
||||
#include "../gui/hud_card.h"
|
||||
|
||||
class inventory_tools_module : public module {
|
||||
public:
|
||||
inventory_tools_module():module("inventory tools","steal, dump and middle-click sorting in container screens",category::utility) {
|
||||
buttons_=&add_toggle("UI buttons",true);middle_=&add_toggle("middle-click sort",true);
|
||||
hotbar_=&add_toggle("include hotbar when dumping",false);
|
||||
delay_=&add_int("action delay (ms)",75,30,500);
|
||||
x_=&add_float("buttons X (screen fraction)",.5f,0,1);y_=&add_float("buttons Y (screen fraction)",.1f,0,1);
|
||||
add_action("stop",[]{inventory_tools::queue(inventory_tools::action::stop);});
|
||||
instance_=this;inventory_tools::initialize();
|
||||
}
|
||||
void on_enable() override {
|
||||
if(!inventory_tools::ready){set_enabled(false);notifications::push("Inventory tools unavailable","The container hooks could not be verified.",notifications::kind::warning);return;}
|
||||
inventory_tools::enabled=true;input::inventory_handler=&handle_input;
|
||||
}
|
||||
void on_disable() override {inventory_tools::enabled=false;input::inventory_handler=nullptr;left_owned_=false;middle_owned_=false;inventory_tools::reset();}
|
||||
void on_render() override {
|
||||
inventory_tools::delay=delay_->int_value;inventory_tools::include_hotbar=hotbar_->bool_value;
|
||||
button_enabled_=buttons_->bool_value;middle_enabled_=middle_->bool_value;
|
||||
const auto state=inventory_tools::latest();if(!inventory_tools::fresh(state) || !inventory_tools::playing_ui())return;
|
||||
if(!buttons_->bool_value)return;
|
||||
const auto size=ImGui::GetIO().DisplaySize;
|
||||
const ImVec2 pos{std::clamp(size.x*x_->float_value-156.f,0.f,(std::max)(0.f,size.x-312.f)),std::clamp(size.y*y_->float_value,0.f,(std::max)(0.f,size.y-32.f))};
|
||||
{std::lock_guard lock(button_mutex_);button_pos_=pos;button_stamp_=GetTickCount64();}
|
||||
auto* draw=ImGui::GetForegroundDrawList();
|
||||
const bool chest=inventory_tools::find(state,"container_items")!=nullptr;
|
||||
const char* labels[]={"steal","dump",state.busy ? "stop" : "sort"};
|
||||
for(int i=0;i<3;++i) {
|
||||
const ImVec2 at{pos.x+i*104.f,pos.y};
|
||||
hud_card::background(draw,at,{100,30},1,true);
|
||||
const auto color=theme::u32(i<2 && !chest || state.cursor ? theme::muted() : theme::fg());
|
||||
const auto text=fonts::text_size(fonts::semibold,fonts::k_body_size,labels[i]);
|
||||
hud_card::text(draw,fonts::semibold,1,{at.x+(100-text.x)/2,at.y+7},color,labels[i],true);
|
||||
}
|
||||
}
|
||||
private:
|
||||
setting *buttons_,*middle_,*hotbar_,*delay_,*x_,*y_;
|
||||
static inline inventory_tools_module* instance_=nullptr;
|
||||
inline static std::mutex button_mutex_;inline static ImVec2 button_pos_;inline static uint64_t button_stamp_=0;
|
||||
inline static std::atomic<bool> left_owned_{false},middle_owned_{false};
|
||||
inline static std::atomic<bool> button_enabled_{true},middle_enabled_{true};
|
||||
static bool handle_input(HWND,UINT message,WPARAM,LPARAM param) {
|
||||
if(message==WM_LBUTTONUP && left_owned_){left_owned_=false;return true;}
|
||||
if(message==WM_MBUTTONUP && middle_owned_){middle_owned_=false;return true;}
|
||||
if(!instance_ || !inventory_tools::playing_ui())return false;
|
||||
const auto state=inventory_tools::latest();if(!inventory_tools::fresh(state))return false;
|
||||
if((message==WM_MBUTTONDOWN || message==WM_MBUTTONDBLCLK) && middle_enabled_ && inventory_tools::find(state,state.hover) && state.hover!="hotbar_items") {
|
||||
inventory_tools::queue(inventory_tools::action::sort);middle_owned_=true;return true;
|
||||
}
|
||||
if(message!=WM_LBUTTONDOWN && message!=WM_LBUTTONDBLCLK)return false;
|
||||
if(!button_enabled_){if(state.busy)inventory_tools::queue(inventory_tools::action::stop);return false;}
|
||||
ImVec2 pos;uint64_t stamp;{std::lock_guard lock(button_mutex_);pos=button_pos_;stamp=button_stamp_;}
|
||||
const int x=short(LOWORD(param)),y=short(HIWORD(param));
|
||||
if(GetTickCount64()-stamp>150 || x<pos.x || x>=pos.x+312 || y<pos.y || y>=pos.y+30) {
|
||||
if(state.busy)inventory_tools::queue(inventory_tools::action::stop);return false;
|
||||
}
|
||||
const int button=int((x-pos.x)/104);left_owned_=true;
|
||||
if(!state.cursor) {
|
||||
if(button==2)inventory_tools::queue(state.busy ? inventory_tools::action::stop : inventory_tools::action::sort,
|
||||
inventory_tools::find(state,"container_items") ? "container_items" : "inventory_items");
|
||||
else if(inventory_tools::find(state,"container_items"))inventory_tools::queue(button==0 ? inventory_tools::action::steal : inventory_tools::action::dump);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user