-
Notifications
You must be signed in to change notification settings - Fork 6
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
HUD System #6
HUD System #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future this should probably be merged with the normal ui system (they mostly differ in how positioning works, ui elements could also need the extra control)
Co-authored-by: platz1de <51201131+platz1de@users.noreply.github.com>
Co-authored-by: platz1de <51201131+platz1de@users.noreply.github.com>
Will change |
I think it should be all good now, I'll do some testing and double-checking later today when I have more spare time. |
documentation needs to be updated to mention show/hide instead of spawn, rest looks good |
Yes I will do that |
Making some last changes, adding a It looks something like this: import ExampleElement from "./elements/ExampleElement";
export function initHudElements() {
new ExampleElement();
} All HUD elements should have their constructors called here. Registering elements could potentially be automated during the build process. |
That should be all. Would be nice to implement some basic game stuff using the system to see it in action :-) |
@@ -3,5 +3,28 @@ import {HudElement} from "../HudElement"; | |||
export class ExampleElement extends HudElement { | |||
constructor() { | |||
super("ExampleElement"); | |||
|
|||
this.setCoordinates(100, 100); | |||
document.addEventListener("keydown", (event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui elements shouldn't listen to global events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this was just for the sake of the example. Probably shouldn't have committed it.
|
||
} | ||
}); | ||
this.show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The element won't be able to become hidden as the instance isn't saved
constructor() { | ||
super("ExampleElement"); | ||
|
||
this.setCoordinates(100, 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elements shouldn't decide their own position
import {ExampleElement} from "./elements/ExampleElement"; | ||
|
||
export function initHudElements() { | ||
//new ExampleElement(); // Uncomment this to enable the example element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not create a long list of class constructors
* | ||
* @param shift Units to shift the element along the Y axis | ||
*/ | ||
shiftYCoord(shift: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ui elements are pretty much always fixed and will never be shifted around, having three methods for that is overkill
In regards to
and
I think you and I have different ideas of how ui elements should behave. The way I've designed it is that the bulk of the element's logic is handled within the element class itself, hence no need to save the instance as all necessary functionality is setup in the constructor. Operations exclusive to the element should generally be handled by the element. I do, however, admit not saving the instance is not a good design choice. |
Only very simple actions should directly be handled by the element (e.g. a timer). But pretty much every element i can think of requires information of other game objects to work correctly, this info should be directly sent to the element and not need to be requested every tick (e.g. chat messages get pushed to the element by network handlers, we don't want to store those for a tick just for the chat element to request them a tick too late) |
Okay, I'll rewrite soon™ |
Hi, if anyone reading this is willing to help with this PR, that would be great. I'm still really busy with schoolwork and still don't have much time to work on this, otherwise it will just have to wait another few weeks for me to find sufficient time for it. |
I can try, but I guess I'll need a day or two to really get into the depths of this. |
Okay, I've carefully reviewed the code, but I do have some remarks before continuing with this, so hopefully @theotherhades can shed some light on the matter:
All in all I'm wondering right now if the scope of HUD elements is maybe a bit too narrow to warrant the time of full-scale implementation, but I'm ready to be convinced otherwise 😄 |
|
Superseded by ae17c5b |
A system for implementing HUD elements. Most details of how it works can be found in the included documentation file (
./src/hud/HUD.md
)Please don't merge yet, could use review, polishing, and example implementation. Let me know what you think.