Skip to content

Commit 80d7832

Browse files
Contributing.md update
1 parent 987c6e7 commit 80d7832

2 files changed

Lines changed: 113 additions & 10 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,68 @@
1-
# Contributing
1+
# Contributing to DynamicHUD
22

3-
Anyone is free to commit and make pull requests. Just make sure that you are well documenting your code and making necessary changes.
4-
Also please review your changes for any bugs that may occur.
3+
Thank you for your interest in contributing to DynamicHUD! We welcome all contributions, including bug fixes, feature suggestions, documentation updates, and new widget types or context menu skins.
4+
Please follow the following guidelines.
5+
---
6+
7+
## **1. Getting Started**
8+
9+
### **Setting Up the Workspace**
10+
DynamicHUD is built on the **Fabric Loader** toolchain using **Fabric Loom**.
11+
1. **Clone the repository**:
12+
```bash
13+
git clone https://github.com/tanishisherewith/DynamicHUD.git
14+
cd DynamicHUD
15+
```
16+
2. **Setup the Gradle environment**:
17+
- For IntelliJ IDEA, import the folder as a Gradle project.
18+
- Run the task to generate Minecraft source mappings:
19+
```bash
20+
gradlew genSources
21+
```
22+
3. **Run Minecraft**:
23+
- Run the client using the run configuration generated by Loom:
24+
```bash
25+
gradlew runClient
26+
```
27+
28+
---
29+
30+
## **2. Coding Standards & Guidelines**
31+
32+
### **Java Standards**
33+
- Use standard Java camelCase naming conventions.
34+
- Maintain visibility access levels. Use package-private or `protected` fields appropriately for widget extensions.
35+
- Do not check in raw absolute coordinates in widgets or hardcoded resolution values. Use the snap-alignment and ratio-anchored dynamic coordinate updates from `Widget.java`.
36+
37+
### **Official Mappings**
38+
- DynamicHUD uses **Official Mojang Mappings** since 1.21.11 (`v4.0.0`) onwards.
39+
40+
### **Core Components Reference**
41+
> More to be listed later. TODO
42+
- **Text & Truncation**: To prevent option names from overflowing card limits, use `Util.getTruncatedName(Component, int)` and render with `Util.drawTruncatedScaledText(...)` or `Util.drawScaledText(...)`.
43+
44+
---
45+
46+
## **3. Creating a Pull Request**
47+
48+
1. **Create a Feature Branch**:
49+
```bash
50+
git checkout -b feature/my-new-feature
51+
```
52+
2. **Write Clean Commits**:
53+
- Write clear, concise commit messages.
54+
- Separate refactoring from new features.
55+
3. **Test Your Changes**:
56+
- Run a clean build to make sure java compilation passes without warnings:
57+
```bash
58+
gradlew clean build
59+
```
60+
- Verify that your layout strategy matches visual guides and screen resize snapping works.
61+
4. **Submit your PR**:
62+
- Provide a clear description of the problem solved and links to relevant issues.
63+
- Add screenshots or recordings if your changes affect the GUI.
64+
65+
---
66+
67+
## **4. Code of Conduct**
68+
We expect all contributors to adhere to our [Code of Conduct](CODE_OF_CONDUCT.md) in all community interactions.

‎src/main/java/com/tanishisherewith/dynamichud/widget/Widget.java‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,49 @@ public float getScale() {
121121
public float getWidth() { return widgetBox.getWidth(); }
122122
public float getHeight() { return widgetBox.getHeight(); }
123123

124+
private Anchor determineBestAnchor(int x, int y, int width, int height, int screenWidth, int screenHeight) {
125+
if (screenWidth <= 0 || screenHeight <= 0) return Anchor.TOP_LEFT;
126+
127+
int centerX = x + width / 2;
128+
int centerY = y + height / 2;
129+
130+
int xZone = 0; // 0 = Left, 1 = Center, 2 = Right
131+
if (centerX < screenWidth / 3) {
132+
xZone = 0;
133+
} else if (centerX < 2 * screenWidth / 3) {
134+
xZone = 1;
135+
} else {
136+
xZone = 2;
137+
}
138+
139+
int yZone = 0; // 0 = Top, 1 = Center, 2 = Bottom
140+
if (centerY < screenHeight / 3) {
141+
yZone = 0;
142+
} else if (centerY < 2 * screenHeight / 3) {
143+
yZone = 1;
144+
} else {
145+
yZone = 2;
146+
}
147+
148+
if (xZone == 0) {
149+
if (yZone == 0) return Anchor.TOP_LEFT;
150+
if (yZone == 1) return Anchor.CENTER_LEFT;
151+
return Anchor.BOTTOM_LEFT;
152+
} else if (xZone == 1) {
153+
if (yZone == 0) return Anchor.TOP_CENTER;
154+
if (yZone == 1) return Anchor.CENTER;
155+
return Anchor.BOTTOM_CENTER;
156+
} else {
157+
if (yZone == 0) return Anchor.TOP_RIGHT;
158+
if (yZone == 1) return Anchor.CENTER_RIGHT;
159+
return Anchor.BOTTOM_RIGHT;
160+
}
161+
}
162+
124163
private void calculateOffset(int initialX, int initialY, int screenWidth, int screenHeight) {
164+
if (screenWidth > 0 && screenHeight > 0) {
165+
this.anchor = determineBestAnchor(initialX, initialY, (int) getWidth(), (int) getHeight(), screenWidth, screenHeight);
166+
}
125167
int anchorX = anchor.getBaseX(screenWidth);
126168
int anchorY = anchor.getBaseY(screenHeight);
127169
this.offsetX = initialX - anchorX;
@@ -130,15 +172,12 @@ private void calculateOffset(int initialX, int initialY, int screenWidth, int sc
130172

131173
// Update position based on anchor and offset
132174
void updatePosition(int screenWidth, int screenHeight) {
133-
if (offsetX == 0 && offsetY == 0) {
134-
calculateOffset(x, y, mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight());
135-
}
136-
137175
int anchorX = anchor.getBaseX(screenWidth);
138176
int anchorY = anchor.getBaseY(screenHeight);
139177
this.x = anchorX + offsetX;
140178
this.y = anchorY + offsetY;
141179
clampPosition();
180+
calculateOffset(x, y, screenWidth, screenHeight);
142181
}
143182

144183
public void setPosition(int x, int y) {
@@ -220,7 +259,9 @@ private void renderWidgetInEditor(GuiGraphics graphics, int mouseX, int mouseY)
220259
public boolean mouseClicked(double mouseX, double mouseY, int button) {
221260
if (widgetBox.isMouseOver(mouseX, mouseY) && button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
222261
wasDragged = false;
223-
if (!isLocked) {
262+
if (isLocked) {
263+
toggle(); // Static widgets toggle immediately
264+
} else {
224265
startX = (int) (mouseX - x);
225266
startY = (int) (mouseY - y);
226267
dragging = true;
@@ -232,8 +273,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
232273
}
233274
}
234275
}
235-
} else {
236-
toggle(); // Static widgets toggle immediately
237276
}
238277
return true;
239278
}

0 commit comments

Comments
 (0)