| 
 | 1 | +import { colors } from './../../config/colors';  | 
 | 2 | +import { NineSliceSprite, Texture } from 'pixi.js';  | 
 | 3 | +import i18n from '../../config/i18n';  | 
 | 4 | +import { Button } from '../basic/Button';  | 
 | 5 | +import { Window } from '../basic/Window';  | 
 | 6 | +import { Input } from '@pixi/ui';  | 
 | 7 | +import { CheckBox } from '../CheckBox';  | 
 | 8 | +import { type ViewController } from '../../controllers/ViewController';  | 
 | 9 | +import { Windows } from '../../config/windows';  | 
 | 10 | + | 
 | 11 | +/** Game menu component. */  | 
 | 12 | +export class LoginWindow extends Window {  | 
 | 13 | +    constructor(private views: ViewController) {  | 
 | 14 | +        const substrateTexture = Texture.from('MenuWindow');  | 
 | 15 | + | 
 | 16 | +        const background = new NineSliceSprite({  | 
 | 17 | +            texture: substrateTexture,  | 
 | 18 | +            leftWidth: 100,  | 
 | 19 | +            topHeight: 100,  | 
 | 20 | +            rightWidth: 100,  | 
 | 21 | +            bottomHeight: 200,  | 
 | 22 | +        });  | 
 | 23 | + | 
 | 24 | +        // give config differences to the Window base component  | 
 | 25 | +        super({  | 
 | 26 | +            // Window constructor accepts an object with all the config  | 
 | 27 | +            title: i18n.titleScreen.login.title, // menu title text  | 
 | 28 | +            styles: {  | 
 | 29 | +                // styles is an object with all the styles that will be applied to the window  | 
 | 30 | +                background: background, // menu window background  | 
 | 31 | +                width: 700,  | 
 | 32 | +                height: 700,  | 
 | 33 | +                maxHeight: '80%', // set max height to 80% of parent, so it will scale down to fit the screen height on canvas resize  | 
 | 34 | +                maxWidth: '95%', // set max width to 95% of parent, so it will scale down to fit the screen width on canvas resize  | 
 | 35 | +            },  | 
 | 36 | +            ribbonStyles: {  | 
 | 37 | +                // ribbonStyles is an object with all the styles that will be applied to the ribbon layout  | 
 | 38 | +                marginTop: -34, // move the ribbon 27px up from the top of the parent  | 
 | 39 | +                scale: 0.7, // scale the ribbon sprite to 70% of it's original size  | 
 | 40 | +            },  | 
 | 41 | +        });  | 
 | 42 | +    }  | 
 | 43 | + | 
 | 44 | +    /** Create content of the component. Automatically called by extended class (see  Window.ts). */  | 
 | 45 | +    override createContent() {  | 
 | 46 | +        const loginInput = new Input({  | 
 | 47 | +            bg: 'input',  | 
 | 48 | +            nineSliceSprite: [160, 27, 160, 27],  | 
 | 49 | +            textStyle: {  | 
 | 50 | +                // styles of the text  | 
 | 51 | +                fill: colors.text, // color of the text  | 
 | 52 | +                fontSize: 30, // font size of the text,  | 
 | 53 | +                stroke: { width: 3, color: colors.hoverStroke }, // text stroke thickness  | 
 | 54 | +            },  | 
 | 55 | +            align: 'center',  | 
 | 56 | +            placeholder: i18n.titleScreen.login.items.login,  | 
 | 57 | +            addMask: true,  | 
 | 58 | +            cleanOnFocus: true,  | 
 | 59 | +        });  | 
 | 60 | + | 
 | 61 | +        loginInput.width = 450;  | 
 | 62 | +        loginInput.height = 60;  | 
 | 63 | + | 
 | 64 | +        const passwordInput = new Input({  | 
 | 65 | +            bg: 'input',  | 
 | 66 | +            nineSliceSprite: [160, 27, 160, 27],  | 
 | 67 | +            textStyle: {  | 
 | 68 | +                // styles of the text  | 
 | 69 | +                fill: colors.text, // color of the text  | 
 | 70 | +                fontSize: 30, // font size of the text,  | 
 | 71 | +                stroke: { width: 3, color: colors.hoverStroke }, // text stroke thickness  | 
 | 72 | +            },  | 
 | 73 | +            align: 'center',  | 
 | 74 | +            placeholder: i18n.titleScreen.login.items.password,  | 
 | 75 | +            addMask: true,  | 
 | 76 | +        });  | 
 | 77 | + | 
 | 78 | +        passwordInput.width = 450;  | 
 | 79 | +        passwordInput.height = 60;  | 
 | 80 | + | 
 | 81 | +        const remember = new CheckBox({  | 
 | 82 | +            // create a new CheckBox component (see CheckBox.ts)  | 
 | 83 | +            text: i18n.titleScreen.login.items.remember, // text of the checkbox  | 
 | 84 | +            checked: true, // initial state of the checkbox  | 
 | 85 | +            checkboxBG: 'RoundSubstrate', // background of the checkbox  | 
 | 86 | +            checkboxFG: 'CheckBox', // foreground of the checkbox  | 
 | 87 | +            onChange: () => {  | 
 | 88 | +                console.log('remember me'); // callback function that will be called when the checkbox state changes  | 
 | 89 | +            }, // callback function that will be called when the checkbox state changes  | 
 | 90 | +            textOffset: {  | 
 | 91 | +                // offset of the text from the checkbox  | 
 | 92 | +                x: 20, // move the text 300px to the left from the checkbox  | 
 | 93 | +                y: 0, // move the text 3px down from the checkbox  | 
 | 94 | +            },  | 
 | 95 | +        });  | 
 | 96 | + | 
 | 97 | +        const enterButton = new Button( // create an exit button  | 
 | 98 | +            i18n.titleScreen.login.items.enter, // button text  | 
 | 99 | +            () => {  | 
 | 100 | +                console.table({  | 
 | 101 | +                    login: loginInput.value,  | 
 | 102 | +                    password: passwordInput.value,  | 
 | 103 | +                    remember: remember.checked,  | 
 | 104 | +                });  | 
 | 105 | + | 
 | 106 | +                // TODO: implement check login errors here  | 
 | 107 | + | 
 | 108 | +                this.views.show(Windows.levels);  | 
 | 109 | +            },  | 
 | 110 | +        );  | 
 | 111 | + | 
 | 112 | +        enterButton.scale.set(0.5);  | 
 | 113 | + | 
 | 114 | +        this.addContent({  | 
 | 115 | +            // add the buttons to the window layout system  | 
 | 116 | +            menu: {  | 
 | 117 | +                // menu is the id of the layout  | 
 | 118 | +                content: {  | 
 | 119 | +                    login: {  | 
 | 120 | +                        // login is the id of the input  | 
 | 121 | +                        content: loginInput, // content is the button component  | 
 | 122 | +                        styles: {  | 
 | 123 | +                            // styles is an object with all the styles that will be applied to the button  | 
 | 124 | +                            marginTop: 30, // move the button 10px down from the neighbour buttons  | 
 | 125 | +                        },  | 
 | 126 | +                    },  | 
 | 127 | +                    password: {  | 
 | 128 | +                        // login is the id of the input  | 
 | 129 | +                        content: passwordInput, // content is the button component  | 
 | 130 | +                        styles: {  | 
 | 131 | +                            // styles is an object with all the styles that will be applied to the button  | 
 | 132 | +                            marginTop: 30, // move the button 10px down from the neighbour buttons  | 
 | 133 | +                        },  | 
 | 134 | +                    },  | 
 | 135 | +                    remember: {  | 
 | 136 | +                        // exit is the id of the button  | 
 | 137 | +                        content: remember, // content is the button component  | 
 | 138 | +                        styles: {  | 
 | 139 | +                            // styles is an object with all the styles that will be applied to the button  | 
 | 140 | +                            marginTop: 30,  | 
 | 141 | +                            marginLeft: 40,  | 
 | 142 | +                        },  | 
 | 143 | +                    },  | 
 | 144 | +                    exit: {  | 
 | 145 | +                        // exit is the id of the button  | 
 | 146 | +                        content: enterButton, // content is the button component  | 
 | 147 | +                        styles: {  | 
 | 148 | +                            // styles is an object with all the styles that will be applied to the button  | 
 | 149 | +                            marginTop: -20, // move the button 10px down from the neighbour buttons  | 
 | 150 | +                            marginLeft: 45,  | 
 | 151 | +                        },  | 
 | 152 | +                    },  | 
 | 153 | +                },  | 
 | 154 | +                styles: {  | 
 | 155 | +                    // styles is an object with all the styles that will be applied to the layout  | 
 | 156 | +                    position: 'centerTop', // center the layout in the middle of the parent  | 
 | 157 | +                    marginTop: 120, // move the layout 120px down from the top of the parent  | 
 | 158 | +                    width: 450, // set width to 66% of parent, so children will be able to use 66% of the screen width  | 
 | 159 | +                },  | 
 | 160 | +            },  | 
 | 161 | +        });  | 
 | 162 | +    }  | 
 | 163 | +}  | 
0 commit comments