Few base methods for the encyclopedia menu
This commit is contained in:
parent
7ff3b79ba2
commit
6fd3cee98c
@ -12,16 +12,6 @@ namespace TJAPlayer3
|
||||
base.tDBInitSavable();
|
||||
}
|
||||
|
||||
/*
|
||||
public void tDBCDN()
|
||||
{
|
||||
if (!File.Exists(@".\Databases\CDN.json"))
|
||||
tSaveFile();
|
||||
|
||||
tLoadFile();
|
||||
}
|
||||
*/
|
||||
|
||||
#region [Auxiliary classes]
|
||||
|
||||
public class CDNHooks
|
||||
@ -74,23 +64,5 @@ namespace TJAPlayer3
|
||||
|
||||
#endregion
|
||||
|
||||
/*
|
||||
public Dictionary<string, CDNData> data = new Dictionary<string, CDNData>();
|
||||
|
||||
|
||||
#region [private]
|
||||
|
||||
private void tSaveFile()
|
||||
{
|
||||
ConfigManager.SaveConfig(data, @".\Databases\CDN.json");
|
||||
}
|
||||
|
||||
private void tLoadFile()
|
||||
{
|
||||
data = ConfigManager.GetConfig<Dictionary<string, CDNData>>(@".\Databases\CDN.json");
|
||||
}
|
||||
|
||||
#endregion
|
||||
*/
|
||||
}
|
||||
}
|
@ -4,10 +4,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace TJAPlayer3
|
||||
{
|
||||
class DBEncyclopediaMenus : CSavableT<Dictionary<int, string>>
|
||||
class DBEncyclopediaMenus : CSavableT<DBEncyclopediaMenus.EncyclopediaMenu>
|
||||
{
|
||||
public DBEncyclopediaMenus()
|
||||
{
|
||||
@ -15,6 +16,16 @@ namespace TJAPlayer3
|
||||
base.tDBInitSavable();
|
||||
}
|
||||
|
||||
#region [Auxiliary classes]
|
||||
public class EncyclopediaMenu
|
||||
{
|
||||
[JsonProperty("menus")]
|
||||
public KeyValuePair<int, EncyclopediaMenu>[] Menus;
|
||||
|
||||
[JsonProperty("pages")]
|
||||
public int[] Pages;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,10 @@ namespace TJAPlayer3
|
||||
public void tDatabases()
|
||||
{
|
||||
DBCDN = new DBCDN();
|
||||
DBEncyclopediaMenus = new DBEncyclopediaMenus();
|
||||
}
|
||||
|
||||
public DBCDN DBCDN;
|
||||
public DBEncyclopediaMenus DBEncyclopediaMenus;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@ namespace TJAPlayer3
|
||||
static internal class CLangManager
|
||||
{
|
||||
// Cheap factory-like design pattern
|
||||
|
||||
public static (string, int) DefaultLanguage = ("jp", 0);
|
||||
public static void langAttach(string lang)
|
||||
{
|
||||
switch (lang) {
|
||||
@ -49,10 +51,25 @@ namespace TJAPlayer3
|
||||
return 1;
|
||||
case "jp":
|
||||
default:
|
||||
return 0;
|
||||
return DefaultLanguage.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
public static string fetchLang()
|
||||
{
|
||||
if (LangInstance is CLang_jp)
|
||||
return "jp";
|
||||
else if (LangInstance is CLang_en)
|
||||
return "en";
|
||||
else if (LangInstance is CLang_fr)
|
||||
return "fr";
|
||||
else if (LangInstance is CLang_es)
|
||||
return "es";
|
||||
else if (LangInstance is CLang_zh)
|
||||
return "zh";
|
||||
return DefaultLanguage.Item1;
|
||||
}
|
||||
|
||||
public static string intToLang(int idx)
|
||||
{
|
||||
switch (idx)
|
||||
@ -67,7 +84,7 @@ namespace TJAPlayer3
|
||||
return "en";
|
||||
case 0:
|
||||
default:
|
||||
return "jp";
|
||||
return DefaultLanguage.Item1;
|
||||
}
|
||||
}
|
||||
|
||||
|
114
TJAPlayer3/Stages/15.OpenEncyclopedia/CEncyclopediaControler.cs
Normal file
114
TJAPlayer3/Stages/15.OpenEncyclopedia/CEncyclopediaControler.cs
Normal file
@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using FDK;
|
||||
using static TJAPlayer3.CActSelect曲リスト;
|
||||
|
||||
namespace TJAPlayer3
|
||||
{
|
||||
class CEncyclopediaControler
|
||||
{
|
||||
|
||||
public CEncyclopediaControler()
|
||||
{
|
||||
_callStack = new Stack<DBEncyclopediaMenus.EncyclopediaMenu>();
|
||||
|
||||
_callStack.Push(TJAPlayer3.Databases.DBEncyclopediaMenus.data);
|
||||
_current = _callStack.Peek();
|
||||
|
||||
MenuIndex = 0;
|
||||
_lang = CLangManager.fetchLang();
|
||||
tReloadFonts();
|
||||
tReallocateSubMenus();
|
||||
}
|
||||
|
||||
private void tReloadFonts()
|
||||
{
|
||||
_pfEncyclopediaMenu?.Dispose();
|
||||
if (!string.IsNullOrEmpty(TJAPlayer3.ConfigIni.FontName))
|
||||
{
|
||||
_pfEncyclopediaMenu = new CPrivateFastFont(new FontFamily(TJAPlayer3.ConfigIni.FontName), 14);
|
||||
}
|
||||
else
|
||||
{
|
||||
_pfEncyclopediaMenu = new CPrivateFastFont(new FontFamily("MS UI Gothic"), 14);
|
||||
}
|
||||
}
|
||||
|
||||
private string _GetPathTextFile(string parent)
|
||||
{
|
||||
string _expected = parent + @"\" + _lang + ".txt";
|
||||
string _default = parent + @"\" + CLangManager.DefaultLanguage.Item1 + ".txt";
|
||||
|
||||
if (File.Exists(_expected))
|
||||
return _expected;
|
||||
return _default;
|
||||
}
|
||||
|
||||
private string _GetSectionContents(ref KeyValuePair<int, DBEncyclopediaMenus.EncyclopediaMenu> menu)
|
||||
{
|
||||
try
|
||||
{
|
||||
string _path = _GetPathTextFile(@".\Encyclopedia\" + (tIsMenu(menu.Value) ? @"Menus\" : @"Pages\") + menu.Key.ToString());
|
||||
|
||||
return File.ReadAllText(_path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "[File fetching failed]";
|
||||
}
|
||||
}
|
||||
private void tReallocateSubMenus()
|
||||
{
|
||||
if (Submenus != null)
|
||||
{
|
||||
for (int i = 0; i < Submenus.Length; i++)
|
||||
{
|
||||
Submenus[i].Item2?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
int _count = _current.Menus.Length + 1;
|
||||
Submenus = new (int, CTexture)[_count];
|
||||
|
||||
Submenus[0].Item1 = -1;
|
||||
Submenus[0].Item2 = TJAPlayer3.stage選曲.act曲リスト.ResolveTitleTexture(
|
||||
new TitleTextureKey(CLangManager.LangInstance.GetString(401), _pfEncyclopediaMenu, Color.White, Color.DarkOrange, 1000));
|
||||
|
||||
for (int i = 1; i < _count; i++)
|
||||
{
|
||||
int _idx = i - 1; // Excluding return
|
||||
var _menu = _current.Menus[_idx];
|
||||
Submenus[i].Item1 = _menu.Key;
|
||||
Submenus[i].Item2 = TJAPlayer3.stage選曲.act曲リスト.ResolveTitleTexture(
|
||||
new TitleTextureKey(_GetSectionContents(ref _menu), _pfEncyclopediaMenu, Color.White, Color.DarkOrange, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
// Verify if submenu has pages or not
|
||||
public bool tIsMenu(DBEncyclopediaMenus.EncyclopediaMenu menu)
|
||||
{
|
||||
return (menu.Menus == null || menu.Menus.Length == 0);
|
||||
}
|
||||
|
||||
#region [public]
|
||||
|
||||
public (int, CTexture)[] Submenus;
|
||||
public int MenuIndex;
|
||||
|
||||
#endregion
|
||||
|
||||
#region [private]
|
||||
|
||||
private Stack<DBEncyclopediaMenus.EncyclopediaMenu> _callStack;
|
||||
private DBEncyclopediaMenus.EncyclopediaMenu _current;
|
||||
private string _lang;
|
||||
private static CPrivateFastFont _pfEncyclopediaMenu;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user