Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix position error on windows 10 #112

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion d2gl/src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct D2GLApp {
bool centered = true;
bool dark_mode = true;
bool resized = false;
bool hide_title_bar = false;
} window;

struct {
Expand Down Expand Up @@ -215,4 +216,4 @@ constexpr inline bool ISHDTEXT()
#endif
}

}
}
7 changes: 6 additions & 1 deletion d2gl/src/d2gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ __declspec(dllexport) void __stdcall setCustomScreenSize(uint32_t width, uint32_
d2gl::App.game.custom_size = { width, height };
}

__declspec(dllexport) bool isHDTextEnabled()
{
return d2gl::App.hd_text.active;
}

#ifdef __cplusplus
}
#endif
#endif
27 changes: 13 additions & 14 deletions d2gl/src/modules/hd_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,15 @@ uint32_t HDText::getNormalTextWidth(const wchar_t* str, const int n_chars)

uint32_t HDText::getFramedTextSize(const wchar_t* str, uint32_t* width, uint32_t* height)
{
const auto font = getFont(m_text_size);
uint32_t text_size = m_text_size == 1? 16 : m_text_size;
const auto font = getFont(text_size);
const auto size = font->getTextSize(str);

*width = (uint32_t)(size.x + (m_text_size == 1 ? 10 : 0));
*height = m_text_size == 1 ? (font->getLineCount() * 18 + 2) : (uint32_t)size.y;
*width = (uint32_t)(size.x + (text_size == 1 ? 10 : 0));
*height = text_size == 1 ? (font->getLineCount() * 18 + 2) : (uint32_t)size.y;
if (m_text_size == 1) {
*height += (uint32_t)(font->getLineHeight() / 4);
}
m_last_text_width = *width;
m_last_text_height = *height;

Expand Down Expand Up @@ -838,16 +842,11 @@ void HDText::drawMonsterHealthBar(d2::UnitAny* unit)
{
auto name = d2::getMonsterName(unit);
if (!name || wcslen(name) <= 0) {
static wchar_t name_str[50] = { 0 };
wcscpy_s(name_str, d2::hovered_monster_name);
const auto len = wcslen(name_str);
if (len <= 0)
return;

auto end = name_str + len - 1;
while (end >= name_str && *end == L' ') end--;
*(end + 1) = '\0';
name = name_str;
static wchar_t unknown[20] = L" ";
unknown[0] = L' ';
unknown[1] = L' ';
unknown[2] = L'\0';
name = unknown;
}

const auto hp = d2::getUnitStat(unit, STAT_HP);
Expand Down Expand Up @@ -1088,4 +1087,4 @@ const std::string& HDText::getAllFontMetricString()
return metric_text;
}
#endif
}
}
13 changes: 13 additions & 0 deletions d2gl/src/option/chinese.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
unsigned short simplified_chinese_chars[] = {
0x4E00, 0x4E0A, 0x4E0B, 0x4E0D, 0x4E2D, 0x4E49, 0x4E8E, 0x4ECB, 0x4ECE, 0x4EF6, 0x4F1A, 0x4F38, 0x4F3C, 0x4F3D, 0x4F4D, 0x4F53,
0x4FDD, 0x5019, 0x503C, 0x50CF, 0x5149, 0x5165, 0x5168, 0x5185, 0x5230, 0x5236, 0x524D, 0x529F, 0x52A8, 0x5305, 0x5316, 0x534A,
0x5355, 0x53BB, 0x53E3, 0x53F0, 0x540C, 0x540E, 0x542F, 0x547D, 0x548C, 0x54C1, 0x5546, 0x5668, 0x56FE, 0x5728, 0x5730, 0x5782,
0x578B, 0x5904, 0x5927, 0x592E, 0x5931, 0x5982, 0x59CB, 0x5B57, 0x5B58, 0x5B9A, 0x5BBD, 0x5C06, 0x5C0F, 0x5C40, 0x5C45, 0x5C4F,
0x5DE6, 0x5E55, 0x5E73, 0x5E94, 0x5E95, 0x5EA6, 0x5F00, 0x5F0F, 0x5F3A, 0x5F84, 0x5FEB, 0x6001, 0x6027, 0x602A, 0x60AC, 0x620F,
0x6253, 0x627E, 0x6297, 0x62C9, 0x62EC, 0x6539, 0x653E, 0x6548, 0x6570, 0x6587, 0x65F6, 0x662F, 0x663E, 0x6655, 0x66DD, 0x66F4,
0x6700, 0x672A, 0x6761, 0x679C, 0x67E5, 0x6807, 0x680F, 0x6821, 0x6837, 0x684C, 0x6A21, 0x6B21, 0x6B63, 0x6B65, 0x6C34, 0x6D3B,
0x6D4B, 0x6D6E, 0x6DF1, 0x6E05, 0x6E38, 0x70B9, 0x7126, 0x7269, 0x72B6, 0x751F, 0x7528, 0x7684, 0x76F4, 0x7740, 0x793A, 0x7A97,
0x7D20, 0x7EA7, 0x7EBF, 0x7EC4, 0x7EC8, 0x7ECD, 0x7F29, 0x7F6E, 0x80FD, 0x81EA, 0x8272, 0x83DC, 0x85CF, 0x884C, 0x8868, 0x89C6,
0x89D2, 0x89E3, 0x8BA1, 0x8BBE, 0x8D28, 0x8DF3, 0x8F93, 0x8FC7, 0x8FD0, 0x8FD1, 0x9009, 0x901F, 0x90E8, 0x914D, 0x91C7, 0x91CF,
0x9501, 0x9510, 0x952F, 0x9650, 0x9690, 0x975E, 0x9762, 0x9875, 0x9879, 0x9884, 0x9891, 0x9898, 0x989C, 0x9A6C, 0x9AD8, 0x9F7F
};
30 changes: 30 additions & 0 deletions d2gl/src/option/convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import re

def extract_chinese_characters(file_path):
chinese_chars = set()
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
# Extract all Chinese characters
chinese_chars.update(re.findall(r'[\u4e00-\u9fff]', content))
return chinese_chars

def generate_cpp_array(chinese_chars):
# Convert characters to Unicode code points and sort them
unicode_values = sorted([ord(char) for char in chinese_chars])
# Generate C++ array with 16 characters per line
lines = []
for i in range(0, len(unicode_values), 16):
line = ", ".join(f"0x{value:04X}" for value in unicode_values[i:i+16])
lines.append(line)
cpp_array = "unsigned short simplified_chinese_chars[] = {\n " + ",\n ".join(lines) + "\n};"
return cpp_array

def main():
file_path = 'menu.cpp' # Replace with your file path
chinese_chars = extract_chinese_characters(file_path)
cpp_array = generate_cpp_array(chinese_chars)
with open('chinese.h', "w") as f:
f.write(cpp_array + "\n")

if __name__ == '__main__':
main()
6 changes: 5 additions & 1 deletion d2gl/src/option/ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ void saveIni()
"; Window size.\n"
"window_width=%d\n"
"window_height=%d\n\n"
"; Hide window title bar.\n"
"hide_title_bar=%s\n\n"
"; Always centered window on launch.\n"
"; Window position (window_posx/window_posy) will be ignored.\n"
"centered_window=%s\n\n"
Expand Down Expand Up @@ -161,6 +163,7 @@ void saveIni()
boolString(App.window.fullscreen),
App.window.size.x,
App.window.size.y,
boolString(App.window.hide_title_bar),
boolString(App.window.centered),
App.window.position.x,
App.window.position.y,
Expand Down Expand Up @@ -316,6 +319,7 @@ void loadIni()
App.window.size.y = getInt("Screen", "window_height", App.window.size.y, 600, App.desktop_resolution.w);
App.window.size_save = App.window.size;

App.window.hide_title_bar = getBool("Screen", "hide_title_bar", App.window.hide_title_bar);
App.window.centered = getBool("Screen", "centered_window", App.window.centered);
App.window.position.x = getInt("Screen", "window_posx", App.window.position.x, App.desktop_resolution.x, App.desktop_resolution.z);
App.window.position.y = getInt("Screen", "window_posy", App.window.position.y, App.desktop_resolution.y, App.desktop_resolution.w);
Expand Down Expand Up @@ -399,4 +403,4 @@ void loadIni()
saveIni();
}

}
}
Loading