Skip to content

Commit

Permalink
fix the ui sometimes being off the screen. add a toggle to hide it if…
Browse files Browse the repository at this point in the history
… you want
  • Loading branch information
dschu012 committed Aug 17, 2020
1 parent e69550c commit 34acf82
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ Debug/
Packaging/*
BH/Release/*
Release/*
/.vs/BH/v15
/.vs/*
/BH.VC.db
/out/*
18 changes: 18 additions & 0 deletions BH/BH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
<ModuleDefinitionFile>
</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>set "D2Path=$(D2Path)"
if defined D2Path (
xcopy "$(SolutionDir)$(Configuration)" "$(D2Path)" /h /i /c /k /e /r /y
)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -98,6 +104,12 @@
<ModuleDefinitionFile>
</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>set "D2Path=$(D2Path)"
if defined D2Path (
xcopy "$(SolutionDir)$(Configuration)" "$(D2Path)" /h /i /c /k /e /r /y
)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Packaging|Win32'">
<ClCompile>
Expand All @@ -114,6 +126,12 @@
<ModuleDefinitionFile>
</ModuleDefinitionFile>
</Link>
<PostBuildEvent>
<Command>set "D2Path=$(D2Path)"
if defined D2Path (
xcopy "$(SolutionDir)$(Configuration)" "$(D2Path)" /h /i /c /k /e /r /y
)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AsyncDrawBuffer.cpp" />
Expand Down
37 changes: 37 additions & 0 deletions BH/Drawing/UI/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void UI::SetMinimizedY(unsigned int newY) {
}

void UI::OnDraw() {
if (!IsVisible()) return;
EnsureInBounds();
if (IsMinimized()) {
int n = 0;
for (list<UI*>::iterator it = Minimized.begin(); it != Minimized.end(); it++, n++)
Expand Down Expand Up @@ -174,6 +176,37 @@ void UI::OnDraw() {
}
}

void UI::EnsureInBounds() {
if (IsMinimized()) {
if (GetMinimizedX() < 0) {
SetMinimizedX(0);
}
if (GetMinimizedX() + GetXSize() > Hook::GetScreenWidth()) {
SetMinimizedX(Hook::GetScreenWidth() - GetXSize());
}
if (GetMinimizedY() < 0) {
SetMinimizedY(0);
}
if (GetMinimizedY() + TITLE_BAR_HEIGHT > Hook::GetScreenHeight()) {
SetMinimizedY(Hook::GetScreenHeight() - TITLE_BAR_HEIGHT);
}
}
else {
if (GetX() < 0) {
SetX(0);
}
if(GetX() + GetXSize() > Hook::GetScreenWidth()) {
SetX(Hook::GetScreenWidth() - GetXSize());
}
if (GetY() < 0) {
SetY(0);
}
if (GetY() + GetYSize() > Hook::GetScreenHeight()) {
SetY(Hook::GetScreenHeight() - GetYSize());
}
}
}

void UI::SetDragged(bool state, bool write_file) {
Lock();
dragged = state;
Expand All @@ -190,6 +223,10 @@ void UI::SetDragged(bool state) {
SetDragged(state, false);
}

void UI::SetVisible(bool newState) {
visible = newState;
}

void UI::SetMinimized(bool newState) {
if (newState == minimized)
return;
Expand Down
6 changes: 5 additions & 1 deletion BH/Drawing/UI/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ namespace Drawing {
static std::list<UI*> Minimized;
unsigned int x, y, xSize, ySize, zOrder;//Position and Size and Order
unsigned int minimizedX, minimizedY;//Position when minimized
bool active, minimized, dragged;//If UI is active or minimized or dragged
bool active, minimized, dragged, visible;//If UI is active or minimized or dragged
unsigned int dragX, dragY;//Position where we grabbed it.
unsigned int startX, startY;//Position where we grabbed it.
std::string name;//Name of the UI
UITab* currentTab;//Current tab open at the time.
CRITICAL_SECTION crit;//Critical section

void EnsureInBounds();
public:
std::list<UITab*> Tabs;

Expand All @@ -43,6 +45,7 @@ namespace Drawing {
bool IsActive() { return active; };
bool IsMinimized() { return minimized; };
bool IsDragged() { return dragged; };
bool IsVisible() { return visible; };
std::string GetName() { return name; };
unsigned int GetZOrder() { return zOrder; };

Expand All @@ -54,6 +57,7 @@ namespace Drawing {
void SetMinimizedY(unsigned int newY);
void SetActive(bool newState) { Lock(); active = newState; Unlock(); };
void SetMinimized(bool newState);
void SetVisible(bool newState);
void SetName(std::string newName) { Lock(); name = newName; Unlock(); };
void SetDragged(bool state, bool write_file); // only write config to file if write_file is true
void SetDragged(bool state); // never writes the config file
Expand Down
2 changes: 2 additions & 0 deletions BH/Modules/Maphack/Maphack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void Maphack::ReadConfig() {
BH::config->ReadInt("Manaburn Monster Color", mbMonColor);

BH::config->ReadKey("Reload Config", "VK_NUMPAD0", reloadConfig);
BH::config->ReadToggle("Show Settings", "VK_NUMPAD8", true, Toggles["Show Settings"]);

BH::config->ReadAssoc("Missile Color", missileColors);
BH::config->ReadAssoc("Monster Color", monsterColors);
Expand Down Expand Up @@ -304,6 +305,7 @@ void Maphack::OnUnload() {
void Maphack::OnLoop() {
//// Remove or install patchs based on state.
ResetPatches();
BH::settingsUI->SetVisible(Toggles["Show Settings"].state);

// Get the player unit for area information.
UnitAny* unit = D2CLIENT_GetPlayerUnit();
Expand Down

0 comments on commit 34acf82

Please sign in to comment.