Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/credits/credits.js
var g_PanelNames = ["special", "programming", "art", "translators", "misc", "donators"]; | var g_PanelNames = ["special", "programming", "art", "translators", "misc", "donators"]; | ||||
var g_ButtonNames = {}; | var g_ButtonNames = {}; | ||||
var g_PanelTexts = {}; | var g_PanelTexts = {}; | ||||
var g_SelectedPanel = 0; | |||||
elexis: g_SelectedPanel | |||||
function init() | function init() | ||||
{ | { | ||||
// Load credits list from the disk and parse them | // Load credits list from the disk and parse them | ||||
for (let name of g_PanelNames) | for (let name of g_PanelNames) | ||||
{ | { | ||||
let json = Engine.ReadJSONFile("gui/credits/texts/" + name + ".json"); | let json = Engine.ReadJSONFile("gui/credits/texts/" + name + ".json"); | ||||
if (!json || !json.Content) | if (!json || !json.Content) | ||||
{ | { | ||||
error("Could not load credits for " + name + "!"); | error("Could not load credits for " + name + "!"); | ||||
continue; | continue; | ||||
} | } | ||||
g_ButtonNames[name] = json.Title || name; | g_ButtonNames[name] = json.Title || name; | ||||
g_PanelTexts[name] = parseHelper(json.Content); | g_PanelTexts[name] = parseHelper(json.Content); | ||||
} | } | ||||
placeButtons(); | placeButtons(); | ||||
selectPanel(0); | selectPanel(0); | ||||
} | } | ||||
function placeButtons() | /* | ||||
* Show next/previous panel. | |||||
* @param direction - 1/-1 forward, backward panel. | |||||
*/ | |||||
function selectNextTab(direction) | |||||
{ | { | ||||
selectPanel((g_SelectedPanel + direction + g_PanelNames.length) % g_PanelNames.length); | |||||
} | |||||
function placeButtons() | |||||
{ | |||||
for (let i = 0; i < g_PanelNames.length; ++i) | for (let i = 0; i < g_PanelNames.length; ++i) | ||||
{ | { | ||||
let button = Engine.GetGUIObjectByName("creditsPanelButton[" + i + "]"); | let button = Engine.GetGUIObjectByName("creditsPanelButton[" + i + "]"); | ||||
if (!button) | if (!button) | ||||
{ | { | ||||
warn("Could not display some credits."); | warn("Could not display some credits."); | ||||
break; | break; | ||||
} | } | ||||
button.onMouseWheelUp = () => selectNextTab(1); | |||||
button.onMouseWheelDown = () => selectNextTab(-1); | |||||
button.hidden = false; | button.hidden = false; | ||||
let size = button.size; | let size = button.size; | ||||
size.top = i * 35; | size.top = i * 35; | ||||
size.bottom = size.top + 30; | size.bottom = size.top + 30; | ||||
button.size = size; | button.size = size; | ||||
button.onPress = (i => function() {selectPanel(i);})(i); | button.onPress = (i => function() {selectPanel(i);})(i); | ||||
let buttonText = Engine.GetGUIObjectByName("creditsPanelButtonText[" + i + "]"); | let buttonText = Engine.GetGUIObjectByName("creditsPanelButtonText[" + i + "]"); | ||||
Show All 35 Lines | if (object.Content) | ||||
result += "\n" + parseHelper(object.Content) + "\n"; | result += "\n" + parseHelper(object.Content) + "\n"; | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
function selectPanel(i) | function selectPanel(i) | ||||
{ | { | ||||
g_SelectedPanel = i; | |||||
Engine.GetGUIObjectByName("creditsPanelButtons").children.forEach((button, j) => { | Engine.GetGUIObjectByName("creditsPanelButtons").children.forEach((button, j) => { | ||||
button.sprite = i == j ? "ModernTabVerticalForeground" : "ModernTabVerticalBackground"; | button.sprite = i == j ? "ModernTabVerticalForeground" : "ModernTabVerticalBackground"; | ||||
}); | }); | ||||
Engine.GetGUIObjectByName("creditsText").caption = g_PanelTexts[g_PanelNames[i]]; | Engine.GetGUIObjectByName("creditsText").caption = g_PanelTexts[g_PanelNames[i]]; | ||||
} | } |
Wildfire Games · Phabricator
g_SelectedPanel