Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/tab_buttons.js
/** | /** | ||||
* Number of categories. | * Number of categories. | ||||
*/ | */ | ||||
var g_TabCategoryCount; | var g_TabCategoryCount; | ||||
/** | /** | ||||
* Horizontally or vertically align the buttons. | |||||
Imarok: Sounds grammatically weird.
What about `Align the buttons horizontally or vertically.`? | |||||
Done Inline ActionsDon't think it was too wrong, but your string is certainly good. bb: Don't think it was too wrong, but your string is certainly good. | |||||
*/ | |||||
var g_TabHorizontal; | |||||
Done Inline Actionsg_Tab prefix, the variable name sounds like it's very easy to get a naming conflict with some other global. elexis: `g_Tab` prefix, the variable name sounds like it's very easy to get a naming conflict with some… | |||||
Not Done Inline Actionsffs bb: ffs | |||||
/** | |||||
* Index of the currently visible tab, set first tab as default. | * Index of the currently visible tab, set first tab as default. | ||||
*/ | */ | ||||
var g_TabCategorySelected = 0; | var g_TabCategorySelected = 0; | ||||
/** | /** | ||||
* Function to be executed when selecting a tab. The new category index is passed. | * Function to be executed when selecting a tab. The new category index is passed. | ||||
*/ | */ | ||||
var g_OnSelectTab; | var g_OnSelectTab; | ||||
/** | /** | ||||
* Create tab buttons. | * Create tab buttons. | ||||
* | * | ||||
* @param {Array} categoriesData - Arrays of objects containing for every tab a (translated) label and tooltip. | * @param {Array} categoriesData - Arrays of objects containing for every tab a (translated) label and tooltip. | ||||
* @param {number} buttonHeight - Vertical distance between the top and bottom of a button. | * @param {bool} horizontal - Have the tabs horizontally or vertically aligned. | ||||
StanUnsubmitted Not Done Inline Actionshttps://jsdoc.app/tags-type.html I believe it should be boolean :) Stan: https://jsdoc.app/tags-type.html I believe it should be boolean :) | |||||
* @param {number} spacing - Vertical distance between two buttons. | * @param {number} buttonSize - Size of a button in the specified direction. | ||||
* @param {number} spacing - Distance between two buttons in the specified direction. | |||||
* @param {function} onPress - Function to be executed when a button is pressed, it gets the new category index passed. | * @param {function} onPress - Function to be executed when a button is pressed, it gets the new category index passed. | ||||
* @param {function} onSelect - Function to be executed whenever the selection changes (so also for scrolling), it gets the new category index passed. | * @param {function} onSelect - Function to be executed whenever the selection changes (so also for scrolling), it gets the new category index passed. | ||||
*/ | */ | ||||
function placeTabButtons(categoriesData, buttonHeight, spacing, onPress, onSelect) | function placeTabButtons(categoriesData, horizontal, buttonSize, spacing, onPress, onSelect) | ||||
{ | { | ||||
g_OnSelectTab = onSelect; | |||||
g_TabCategoryCount = categoriesData.length; | g_TabCategoryCount = categoriesData.length; | ||||
g_TabHorizontal = horizontal; | |||||
g_OnSelectTab = onSelect; | |||||
for (let category in categoriesData) | for (let category in categoriesData) | ||||
{ | { | ||||
let button = Engine.GetGUIObjectByName("tabButton[" + category + "]"); | let button = Engine.GetGUIObjectByName("tabButton[" + category + "]"); | ||||
if (!button) | if (!button) | ||||
{ | { | ||||
warn("Too few tab-buttons!"); | warn("Too few tab-buttons!"); | ||||
break; | break; | ||||
} | } | ||||
button.style = "ModernTabButton" + (horizontal ? "Horizontal" : "Vertical"); | |||||
button.hidden = false; | button.hidden = false; | ||||
let size = button.size; | let size = button.size; | ||||
size.top = category * (buttonHeight + spacing) + spacing / 2; | if (horizontal) | ||||
size.bottom = size.top + buttonHeight; | { | ||||
size.left = category * (buttonSize + spacing) + spacing / 2; | |||||
size.right = size.left + buttonSize; | |||||
size.rright = 0; | |||||
} | |||||
else | |||||
{ | |||||
size.top = category * (buttonSize + spacing) + spacing / 2; | |||||
size.bottom = size.top + buttonSize; | |||||
size.rbottom = 0; | |||||
} | |||||
button.size = size; | button.size = size; | ||||
button.tooltip = categoriesData[category].tooltip || ""; | button.tooltip = categoriesData[category].tooltip || ""; | ||||
button.onPress = (category => function() { onPress(category); })(+category); | button.onPress = (category => function() { onPress(category); })(+category); | ||||
Engine.GetGUIObjectByName("tabButtonText[" + category + "]").caption = categoriesData[category].label; | Engine.GetGUIObjectByName("tabButtonText[" + category + "]").caption = categoriesData[category].label; | ||||
} | } | ||||
selectPanel(g_TabCategorySelected); | selectPanel(g_TabCategorySelected); | ||||
} | } | ||||
/** | /** | ||||
* Show next/previous panel. | * Show next/previous panel. | ||||
* @param direction - +1/-1 for forward/backward. | * @param direction - +1/-1 for forward/backward. | ||||
*/ | */ | ||||
function selectNextTab(direction) | function selectNextTab(direction) | ||||
{ | { | ||||
selectPanel((g_TabCategorySelected + direction + g_TabCategoryCount) % g_TabCategoryCount); | selectPanel((g_TabCategorySelected + direction + g_TabCategoryCount) % g_TabCategoryCount); | ||||
} | } | ||||
function selectPanel(category) | function selectPanel(category) | ||||
{ | { | ||||
g_TabCategorySelected = category; | g_TabCategorySelected = category; | ||||
Engine.GetGUIObjectByName("tabButtons").children.forEach((button, j) => { | Engine.GetGUIObjectByName("tabButtons").children.forEach((button, j) => { | ||||
button.sprite = category == j ? "ModernTabVerticalForeground" : "ModernTabVerticalBackground"; | button.sprite = g_TabHorizontal ? | ||||
category == j ? | |||||
"ModernTabHorizontalForeground" : | |||||
"ModernTabHorizontalBackground" : | |||||
category == j ? | |||||
"ModernTabVerticalForeground" : | |||||
"ModernTabVerticalBackground"; | |||||
Done Inline ActionsDon't split strings that are filenames, people should be able to search for them elexis: Don't split strings that are filenames, people should be able to search for them | |||||
Not Done Inline Actionssad we need more code now... bb: sad we need more code now... | |||||
}); | }); | ||||
g_OnSelectTab(category); | g_OnSelectTab(category); | ||||
} | } |
Wildfire Games · Phabricator
Sounds grammatically weird.
What about Align the buttons horizontally or vertically.?