bmddota / barebones

:meat_on_bone: A starter Dota 2 custom game with useful hooks, settings, and libraries.
Apache License 2.0
235 stars 128 forks source link

Add tooltip and popup modules #6

Closed sgodwin424 closed 9 years ago

sgodwin424 commented 9 years ago

Here are some small modules I made as I make progress on finishing my settings module. I changed some of the namespacing and prefixing from the what I originally had to help match more of the structure of barebones I guess.

I didn't add any documentation as I am not really sure where it should go.

sgodwin424 commented 9 years ago

Adding settings module. Hopefully it's not too messy. Here is an example usage featuring everything it can do. This is assuming #SettingsWrapper exists and that it has a set width/height.

        var settings = new modules.Settings();
        settings.SetWrapper($('#SettingsWrapper'));

        settings.RegisterGroup(
            {
                id: 'hostOptions',
                settings:
                    [
                        // Row 1.

                        [
                            {
                                title: 'General',
                                type: 'header'
                            }
                        ],

                        // Row 2

                        [
                            {
                                options:
                                    [
                                        {
                                            id: 'difficultyNormal',
                                            text: 'Normal',
                                            value: 0
                                        },
                                        {
                                            id: 'difficultyHard',
                                            text: 'Hard',
                                            value: 1
                                        }
                                    ],
                                default: 'difficultyNormal',
                                text: 'Difficulty',
                                toolTipText: 'Sets the game difficulty. Normal is recommended for beginners.',
                                type: 'dropdown',
                                id: 'difficulty'
                            },
                            {
                                options:
                                    [
                                        {
                                            id: 'lifeCount5',
                                            text: '5'
                                        }
                                    ],
                                default: 'lifeCount5',
                                text: 'Life Count',
                                toolTipText: 'How many lives should everyone have?',
                                toolTipTitle: 'Life Count',
                                type: 'dropdown',
                                id: 'lifeCount'
                            },
                        ],

                        // Row 3.

                        [
                            {
                                default: true,
                                text: 'Enable friendly fire',
                                type: 'checkbox',
                                id: 'friendlyFire'
                            },
                            {
                                default: false,
                                text: 'Enable random disasters',
                                toolTipText: 'Hello boys!',
                                toolTipTitle: 'Enable random disasters',
                                type: 'checkbox',
                                id: 'randomDisasters'
                            }
                        ],

                        // Row 4.

                        [
                            {
                                default: 'stuff here',
                                text: 'TextBox',
                                type: 'textbox',
                                toolTipText: 'This is a description.',
                                toolTipTitle: 'TextBox',
                                id: 'textBox'
                            },
                            {
                                text: 'Textbox 2',
                                type: 'textbox',
                                toolTipText: 'This is another description.',
                                toolTipTitle: 'TextBox2',
                                id: 'textBox2'
                            }
                        ],

                        // Row 5.

                        [
                            {
                                title: 'Misc.',
                                type: 'header'
                            }
                        ],

                        // Row 6.

                        [
                            {
                                text: 'Stuff',
                                group: 'stuff',
                                default: 'test',
                                toolTipTitle: 'Stuff',
                                toolTipText: 'Stuff description',
                                options:
                                    [
                                        {
                                            id: 'test',
                                            text: 'foo',
                                            group: '1',
                                        },
                                        {
                                            id: 'test2',
                                            text: 'foo2',
                                            group: '2'
                                        }
                                    ],
                                type: 'radio',
                                id: 'foo2'
                            },
                            {
                                text: 'Stuff',
                                group: 'stuff2',
                                default: 'test',
                                toolTipTitle: 'Stuff',
                                toolTipText: 'Stuff description',
                                options:
                                    [
                                        {
                                            id: 'test',
                                            text: 'foo',
                                            group: '1',
                                            value: 'foo'
                                        },
                                        {
                                            id: 'test2',
                                            text: 'foo2',
                                            group: '2',
                                            value: 'foo2'
                                        }
                                    ],
                                type: 'radio',
                                id:'stuff'
                            }
                        ],
                    ],
                title: 'HOST OPTIONS'
            });

        settings.RegisterGroup(
            {
                id: 'userOptions',
                title: 'USER OPTIONS',
                settings: [ ] // Settings in here should probably use local=true for any user to edit them.
            });

        settings.SetVisible(true);

I got a little lazy with the exact text and such, but you get the point. The settings array represents all settings within a group. It consists of arrays, each array representing a content row. Then that array holds objects of specific input types. Currently you can do "dropdown", "textbox", "radio", "checkbox", "header", and "divider". The settings panel should adapt fairly well to the width/height you set for the SettingsWrapper, but of course you are the one that actually chooses how many and which settings are within a content row. And any content that is too large vertically is set to scrolling.

After a timer expires or however you want to do it, you can call settings.GetHostState(), and this will retrieve all data that is host only. Likewise, settings.GetLocalState() does the same, but these are options that anyone can alter. My next plan is to allow host options to be updated live as they are changed so other users can see what they are. Currently, other users can see the host options (but disabled), but they only see the default values, not the current values. This will have to use custom game events to do this.

Let me know if you have questions or want something changed @bmddota

sgodwin424 commented 9 years ago

Didn't mean to close it!

sgodwin424 commented 9 years ago

Well, since they actually added popup/tooltip panels, going to go ahead and close this for now. May refactor the settings stuff later to use them, but too lazy at the moment.