edouardlicn

How to set a menu close by default

Recommended Posts

I use 

 for my main menu.But when I login with login window,that menu open by default in other file.

Quote

const NativeUI = require("./base_nativeui/index.js");
const Menu = NativeUI.Menu;
const UIMenuItem = NativeUI.UIMenuItem;
const UIMenuListItem = NativeUI.UIMenuListItem;
const UIMenuCheckboxItem = NativeUI.UIMenuCheckboxItem;
const UIMenuSliderItem = NativeUI.UIMenuSliderItem;
const BadgeStyle = NativeUI.BadgeStyle;
const Point = NativeUI.Point;
const ItemsCollection = NativeUI.ItemsCollection;
const Color = NativeUI.Color;
const ListItem = NativeUI.ListItem;

mp.gui.chat.show(false);

const ui = new Menu("Main menu", "Mainmenu", new Point(50, 50));
ui.AddItem(new UIMenuListItem(
    "Language",
    "Setting of UI language.",
    new ItemsCollection(["English", "Chinese_simplify", "Chinese_traditional"])
));
ui.AddItem(new UIMenuSliderItem(
    "Slider Item",
    ["Fugiat", "pariatur", "consectetur", "ex", "duis", "magna", "nostrud", "et", "dolor", "laboris"],
    5,
    "Fugiat pariatur consectetur ex duis magna nostrud et dolor laboris est do pariatur amet sint.",
    true
));
ui.AddItem(new UIMenuCheckboxItem(
    "Checkbox Item",
    false,
    "Fugiat pariatur consectetur ex duis magna nostrud et dolor laboris est do pariatur amet sint."
));

ui.ItemSelect.on(item => {
    if (item instanceof UIMenuListItem) {
        console.log(item.SelectedItem.DisplayText, item.SelectedItem.Data);
    } else if (item instanceof UIMenuSliderItem) {
        console.log(item.Text, item.Index, item.IndexToItem(item.Index));
    } else {
        console.log(item.Text);
    }
});

 

How can I set it be close default?

Edited by edouardlicn

Share this post


Link to post
Share on other sites

As says the github page: https://github.com/BlueDadjun/Native-Menu-RageMP

You have 4 main functions:

  • add(menuItem: MenuItem)
  • render(x: number, y: number)
  • open()
  • close()

So use ui.close() for your case, but it is not recommended for your case, let me explain:

 

You should put you menu in a function called when you want it to be called, with mp.events.add();

 

Hope it helped you!

Share this post


Link to post
Share on other sites
8 minutes ago, Protocole said:

As says the github page: https://github.com/BlueDadjun/Native-Menu-RageMP

You have 4 main functions:

  • add(menuItem: MenuItem)
  • render(x: number, y: number)
  • open()
  • close()

So use ui.close() for your case, but it is not recommended for your case, let me explain:

 

You should put you menu in a function called when you want it to be called, with mp.events.add();

 

Hope it helped you!

I m not using Native-Menu-RageMP but NativeUI though they have the similar function.

But I'm not sure what event equal to "not activate on game boot but a key trigger."

 

Share this post


Link to post
Share on other sites

So, to correct myself, from https://hackmd.io/s/HJO_CdHaM

You have the pretty same function, as you said:

  • Functions
  • AddItem(UIMenuItem)
  • Open()
  • Close()

So: ui.Close();

To answer to your second problem:

"Not activate on game boot but a key trigger", this means that you UI Menu in under a function, that when u trigger a key, it runs this function & the menu, also to bind a key client side use this:

mp.keys.bind(0x71, false, function() {
    CallMyFunction();
});

You can see the wiki for this:

https://wiki.rage.mp/index.php?title=Key::bind

 

Edited by Protocole

Share this post


Link to post
Share on other sites
4 minutes ago, Protocole said:

So, to correct myself, from https://hackmd.io/s/HJO_CdHaM

You have the pretty same function, as you said:

  • Functions
  • AddItem(UIMenuItem)
  • Open()
  • Close()

So: ui.Close();

To answer to your second problem:

"Not activate on game boot but a key trigger", this means that you UI Menu in under a function, that when u trigger a key, it runs this function & the menu, also to bind a key client side use this:

mp.keys.bind(0x71, false, function() {
    CallMyFunction();
});

You can see the wiki for this:

https://wiki.rage.mp/index.php?title=Key::bind

 

sry i knew key bind already and forgot to say 

but how in iniciate game?

Share this post


Link to post
Share on other sites

You take everything in your menu, and put it in a function:

function setLanguageMenu() {
mp.gui.chat.show(false);

const ui = new Menu("Main menu", "Mainmenu", new Point(50, 50));
ui.AddItem(new UIMenuListItem(
    "Language",
    "Setting of UI language.",
    new ItemsCollection(["English", "Chinese_simplify", "Chinese_traditional"])
));
ui.AddItem(new UIMenuSliderItem(
    "Slider Item",
    ["Fugiat", "pariatur", "consectetur", "ex", "duis", "magna", "nostrud", "et", "dolor", "laboris"],
    5,
    "Fugiat pariatur consectetur ex duis magna nostrud et dolor laboris est do pariatur amet sint.",
    true
));
ui.AddItem(new UIMenuCheckboxItem(
    "Checkbox Item",
    false,
    "Fugiat pariatur consectetur ex duis magna nostrud et dolor laboris est do pariatur amet sint."
));

ui.ItemSelect.on(item => {
    if (item instanceof UIMenuListItem) {
        console.log(item.SelectedItem.DisplayText, item.SelectedItem.Data);
    } else if (item instanceof UIMenuSliderItem) {
        console.log(item.Text, item.Index, item.IndexToItem(item.Index));
    } else {
        console.log(item.Text);
    }
});
}

Then, you add after this the bind function:

mp.keys.bind(0x71, false, function() { // Functions runs on F2 Key
    setLanguageMenu();
});

Initiate game means when the player has download all the client files.

Else i'm sorry i don't understand what you want ....

 

Share this post


Link to post
Share on other sites
2 hours ago, Protocole said:

You take everything in your menu, and put it in a function:

function setLanguageMenu() {
mp.gui.chat.show(false);

const ui = new Menu("Main menu", "Mainmenu", new Point(50, 50));
ui.AddItem(new UIMenuListItem(
    "Language",
    "Setting of UI language.",
    new ItemsCollection(["English", "Chinese_simplify", "Chinese_traditional"])
));
ui.AddItem(new UIMenuSliderItem(
    "Slider Item",
    ["Fugiat", "pariatur", "consectetur", "ex", "duis", "magna", "nostrud", "et", "dolor", "laboris"],
    5,
    "Fugiat pariatur consectetur ex duis magna nostrud et dolor laboris est do pariatur amet sint.",
    true
));
ui.AddItem(new UIMenuCheckboxItem(
    "Checkbox Item",
    false,
    "Fugiat pariatur consectetur ex duis magna nostrud et dolor laboris est do pariatur amet sint."
));

ui.ItemSelect.on(item => {
    if (item instanceof UIMenuListItem) {
        console.log(item.SelectedItem.DisplayText, item.SelectedItem.Data);
    } else if (item instanceof UIMenuSliderItem) {
        console.log(item.Text, item.Index, item.IndexToItem(item.Index));
    } else {
        console.log(item.Text);
    }
});
}

Then, you add after this the bind function:

mp.keys.bind(0x71, false, function() { // Functions runs on F2 Key
    setLanguageMenu();
});

Initiate game means when the player has download all the client files.

Else i'm sorry i don't understand what you want ....

 

u can log into my test server:ifxoss rageex to have a try.u can find it in list.just have a look.

and thx for reply but what u told me i had made it myself before u told.what i don't understand is the iniciation.

Edited by edouardlicn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.