Menu Items and Views - hovgaardgames/startupcompany GitHub Wiki
This page will learn you how to create your own menu item linked with his view.
First, we need to add a new icon to the menu in the bottom of the game. You do this by adding the following lines to your initialize
method :
let _modPath;
exports.initialize = modPath => {
_modPath = modPath;
Modding.setMenuItem({
name: 'mymod',
tooltip: "My Mod",
tooltipPosition: 'right',
faIcon: 'fa-cubes',
badgeCount: 0,
});
};
Properties :
Property | Description |
---|---|
name | The name property has to be equal to the name of your view |
tooltip | The tooltip shown when hovering the icon |
tooltipPosition | The direction of the shown tooltip |
faIcon | The icon to be used, for example "fa-cubes". See icons *here |
badgeCount | Sets a number shown as a badge next to the icon |
- Font Awesome icons for Startup Company are from version 4. FA version 5 icons do not work.
In Startup Company dialogs are called views. Each view has his own HTML file. The game is using AngularJS (1) to compile the HTML, so you can use any functionality available in AngularJS (1).
If you want to make your own dialog (view), you can do this by providing a controller method, a view and informations about the menu item you created above.
First, we will declare our view in the start.js initialize
method under the menu item we have created. Views are defined in the exports.view
array like this :
let _modPath;
exports.initialize = modPath => {
_modPath = modPath;
// Menu item created above
Modding.setMenuItem({
name: 'mymod',
tooltip: "My Mod",
tooltipPosition: 'right',
faIcon: 'fa-cubes',
badgeCount: 0,
});
// Create view and logic
exports.views = [{
name: 'my_mod',
viewPath: _modPath + 'view.html',
controller: ["$scope", function ($scope) {
// Do some logic related to the view
}]
}];
};
Now, create your view you have defined above in the viewPath
(i.e. <path_to_your_mod_folder>/view.html
) :
<h1>
<i class="fa fa-cubes"></i>
Hello from your future mod!
<i class="fa fa-times pull-right close-button" close-all-ui></i>
</h1>
<div class="padding"><h4>Hello {{mymodCtrl.name}}. Nice to meet you.</h4></div>
When creating a view, you also can create a controller in order to process some logic when the user is in the view.
The controller name is pretty simple : name_of_mod + Ctrl (e.g. mymodCtrl
).
The controller name depends on the name
property you have filled in your mod.json
. For example, if the name
property in mod.json
is equals to mymod
, your controller will be called mymodCtrl
.
If you need to update the badge count of a menu item, you can do it in your start.js
like this :
Modding.setMenuItemBadgeCount('mymod', 5);