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
GTAV-UI Implementation #8
Comments
|
I have started working on something, but I haven't got very far yet to be honest. I put together a TextLabel class that holds all the relevent properties for rendering Text, but I'm having trouble calling the _DRAW_TEXT native from C++. It's very strange, if I make the call manually from .NET, it works just fine, but if I use it on the C++ side, not only does it not draw, but the script just seems to stop running, though I'm not seeing any exceptions in the logs. I'm looking into it right now |
|
^^ Having the same problem here... its working fine when i call it from the .net side... |
|
Mm... strange, I will have a look at it when im at home |
|
I've pinpointed where the error is occuring, but I'm still not sure why. I realized an exception is thrown from the ScriptHook SDK and logged in ScriptHookV.log It happens in If I include natives.h and make the calls directly, it works fine though. I understand we need Native::Function::Call to call the natives from .NET, but is there a dowside to making the calls directly from the C++/CLI side? |
|
Can you clarify which calls you made? I only tried some UI calls yet, |
|
Sure, so to clarify, when trying to draw text on screen for a given frame: From .NET, the following works as expected, and prints "debug text" in the centre of the screen: From C++, the following fails at the last line: An exception occurs in the However if I Now, I just did some more testing, and while in the 2nd example above, it is |
|
Well, I experience the same issue, but just replacing one function did not fix it for me. Native::Function::Call(Native::Hash::SET_TEXT_FONT, 0);
Native::Function::Call(Native::Hash::SET_TEXT_SCALE, 0.3f, 0.3f);
Native::Function::Call(Native::Hash::SET_TEXT_COLOUR, 255, 255, 255, 255);
Native::Function::Call(Native::Hash::SET_TEXT_CENTRE, 1);
UI::_SET_TEXT_ENTRY("STRING");
UI::_ADD_TEXT_COMPONENT_STRING("debug text"); //Needed to replace it here too
Native::Function::Call(Native::Hash::_DRAW_TEXT, 0.5f, 0.5f);Weird, I conclude some kind of wrong string marshalling from the errors, but it shouldn't work in the C# Script then... |
|
Okay, sorry, I was wrong.
This does not actually work for me either. I had "debug text" stored in a member of type System::String^, and passing that in works. Which means it must be a problem with passing in a Storing "STRING" in a System::String^ allows this to work: where |
|
Maybe I know the problem, give me 2 minutes |
|
So I kinda found the problem. If you write Native::Function::Call(Native::Hash::_SET_TEXT_ENTRY, "STRING");it will actually handle the "STRING" as a Then I added the following to the InputArgument: InputArgument(const char value[]);
InputArgument::InputArgument(const char value[]) : mData(ScriptDomain::CurrentDomain->PinString(gcnew String(value)).ToInt64()) //We need a better ToInt64() Method hereand Boom, it works. Now, it also makes a little bit sense why it was working from the script. It wasn't handled as a Will submit a PR tomorrow |
|
That's weird, I just tried adding that constructor, and I still get the same behaviour as before |
|
Mm....weird... |
|
Did you also add the inline operator? Native.hpp: InputArgument(const char value[]);
static inline operator InputArgument ^ (const char value[])
{
return gcnew InputArgument(value);
}Native.cpp: InputArgument::InputArgument(const char value[]) : mData(ScriptDomain::CurrentDomain->PinString(gcnew String(value)).ToInt64())
{
}Works fine for me |
|
Ah, no I didn't. Adding that it in as well did the trick, now it works. Thanks! |
|
No problem! I'v already got some structures implemented(e.g GTAV uses relative float coordinates like (0.5f, 0.5f), do we want to stick with this or offer absolute coordinates like (1000,1500)? Relative coordinates have advantages like looking the same on all screen resolutions, but they also make it hard to align stuff properly. |
|
Ya, I noticed that. I've been thinking that maybe we keep the relative coordinates and implement a hierarchical system, where everything is drawn relative to its parent? |
|
Maybe following hierarchy? abstract class UIElement //provides Methods like GetSize() and Draw()
class Container implements UIElement,Rectangle //Inherits Rectangle (which CAN be colored). Provides functions for adding/removing UIElements.
class Rectangle implements UIElement //A Rectangle (Same as Container, but you can't add UIElements to it)
class Text implements UIElement //A Text-String.
Usage:
Container cont = new Container() //Without parameters: Full screen height/width
cont.add(new Rectangle(Color.Red)); //Again: Full Screen height/width
cont.add(new Text("test", Color.Red, new Vector2(0.5f, 0.5f) ...); //Text centered in the container
//Somewhere in an OnTickCallback
cont.Draw() //Calls all the parent Draw-Functions |
|
Yup, that's more or less what I had in mind, I think that should work |
|
While I thougth some more about this, I realized that all this relative stuff will be hard to understand for new users and we should provide a friendlier way to handle Drawing. Although, the only solution which came in my mind is the following: We initialy scale the backend-UI down to 800x600 and the UIElements need direct coordinates like |
|
Another note: Just saw that GTAV always uses 1280:720 as resolution for Graphics (At least thats what |
|
Returns the same for me on UHD
|
|
Alright, I guess we can go for the absolute way then. Should make a lot of things easier |
|
This looks good, i also get 1280x720 aswell just to confirm. |
|
Looks good to me. Some thoughts: (1) I think our teminology is getting a little mixed up here. The way I see it, there's 2 types of conversions to be done: from relative to absolute coordinates, and from pixel to normalized screen space. The native draw functions take an absolute normalized coordinate, ie, between (2) What happens if a child goes outside of its parent container? Say in your example, the UIRectangle has a width of 300 instead of 200. Are we going to have the container clip it, or will it just overflow? If we don't clip it, then does UIContainer really need to be a UIRectangle, or can we just represent it as a single Point, without a size? (3) Things are drawn in the order that the native functions are called, so if there are multiple rectangles that overlap, the one called last is in front. Maybe we want to have a way of specifying the draw order with a z-index? Once we have this working, we should think about higher level constructs, such as Buttons, Menus, TextFields. Of course, we'll also have to decide how we want to do input/event handling. This is a great start though |
|
Number 3: the overlapping will cause problems. didn't think of that, and for input i have just been using indexing with the numpad. |
Yea, Buttons and TextInputs are good ideas, but before we can add that we would at least require a Low-Level Keyboard and Mouse hook (So we can supress mouse clicks and keyboard strokes). And we need to define how "far" this library should go, should we just provide OOP-Bindings or do we really want to deliver a whole GUI-Library with it. |
|
You're right that it would be difficult to do for for text without a size, so overflowing is fine The draw order may not be a problem, I was just thinking out loud I guess. I suppose users should be able to handle it by making sure they add them in the right order We should start with simple bindings, but I think the easier we make things to use, the better. We may not need the most robust GUI system, but I do think there should be a way of easily creating the most common UI components |
|
Looks good! Some improvements/ideas:
|
|
Agree with @JohnnyCrazy the padding doesn't fit in. apart from that tho its looking good. |
|
@JohnnyCrazy I'm working on the colors, I'm thinking of making I realized the padding looked weird after I first tested it too. I made the padding customizable and defaulting to zero pixels now. I think padding may be useful when using sprites for buttons in the future (when somebody reverse-engineers them), but I'll just default it to 0. I'm also working on giving an option for centering the text, the problem was when I first made the infrastructure for There is also an option to have a footer with a description of the selected item, which is disableable. Anyway, here's a screenshot of how it looks currently (with the footer disabled): |
|
@JohnnyCrazy Is there a way to query how big text is going to be? Like, if you draw text with a scale of 1f, is there a way to know what the height of that text is in pixels? |
|
@StijnBrouwer looking really good dude. |
|
@Monsterxsync Thank you! I'm going to take a break now, I'll get back to it tomorrow. |
|
@JohnnyCrazy Reminds me to figure out how the GTA Online notifications are drawn. Using that system would sure be nice. |
|
Ah yea, I Already know how they work. The default ones (Notifications above the map and subtitles) should come with the PR tomorrow |
|
I'd use the default notifications. Maybe provide an override option if the user wants to use custom drawn ones. |
|
@JohnnyCrazy Another thing this really needs is those menu blip sounds, and the ability to switch menus. I might change Viewport to not be static, and then let the scripts sort that out themselves. |
|
I rewrote the whole infrastructure of the menus to be hierarchical. Now there is a (I know the footer description is bigger than the footer, it's fixed now) |
|
I added easing for when menus open and close. I think everything will be done tomorrow. |
|
@JohnnyCrazy thanks for the notifications! been trying to find that. |
|
I'm very interested in combining the two once they are up. |
|
I'm almost done, I have added messageboxes now. I'm going to do some refactoring and add an example script. And then I'm going to pull request. I think it would be easy to use @Nacorpio's custom elements in menu items, so I will definitely add that when it's there. I however do think that I will need to refactor my and @Nacorpio's code to work together better, otherwise we're going to end up with two menu classes. |
|
If you don't mind, @StijnBrouwer, please add me on Skype so that we can discuss this further. |
|
First time solving merge conflicts and making pull requests, tell me if I did anything wrong. |
|
So, my Menu API is now merged with upstream. I'm working on adding new |
|
I'm changing the example into a really basic trainer. The |
|
I think we can close this since we now provide a perfect way for menus etc. |
Add various features








This issue is covering the discussion about the upcoming GTAV-UI part of the library.👍
I just had a short look at the native-db today, but it seems like there a already a lot of functions named and useable. I'm looking forward to it so we can give a good UI-API for Trainers etc.
@WozStudios You are already working on it, aren't you? If not, I would take it
The text was updated successfully, but these errors were encountered: