Skip to content

Commit

Permalink
Improved content pack load logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumrunner committed Dec 28, 2024
1 parent 8bd2187 commit 97a21ef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
15 changes: 0 additions & 15 deletions unity/Assets/Scripts/Content/RemoteContentPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ public class RemoteContentPack
public string identifier;
public string type;
public string version;
public int format;
public string package_url;
public DateTime latest_update;
public string defaultLanguage = ValkyrieConstants.DefaultLanguage;

public static int currentFormat = QuestFormat.CURRENT_VERSION;
public static int minimumFormat = 4;

// is package available locally
public bool downloaded = false;
public bool update_available = false;
Expand Down Expand Up @@ -72,16 +68,6 @@ public bool Populate(Dictionary<string, string> iniData)
type = iniData["type"];
}

if (iniData.ContainsKey("format"))
{
int.TryParse(iniData["format"], out format);
}

if (format > currentFormat || format < minimumFormat)
{
return false;
}

if (iniData.ContainsKey("image"))
{
string value = iniData["image"];
Expand Down Expand Up @@ -118,7 +104,6 @@ override public string ToString()
r.AppendLine($"[{ValkyrieConstants.RemoteContentPackIniType}]");
r.Append("identifier=").AppendLine(identifier.ToString());
r.Append("type=").AppendLine(type.ToString());
r.Append("format=").AppendLine(currentFormat.ToString());
r.Append("type=").AppendLine(Game.Get().gameType.TypeName());
r.Append("defaultlanguage=").AppendLine(defaultLanguage);

Expand Down
57 changes: 41 additions & 16 deletions unity/Assets/Scripts/UI/Screens/ContentSelectDownloadScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Assets.Scripts.Content;
using UnityEngine;
using UnityEngine.Events;
Expand All @@ -12,16 +11,13 @@ namespace Assets.Scripts.UI.Screens
{
public class ContentSelectDownloadScreen : MonoBehaviour, IContentImageDrawer
{
private const int LARGE_FONT_LIMIT = 32;

private static readonly StringKey CONTENTPACK_DOWNLOAD = new StringKey("val", "CONTENTPACK_DOWNLOAD_HEADER");

public Game game;

// Persistent UI Element
private UIElement text_connection_status = null;
private UIElementScrollVertical scrollArea = null;
private RemoteContentPackManager manager;
private readonly StringKey GO_OFFLINE = new StringKey("val", "GO_OFFLINE");
private readonly StringKey GO_ONLINE = new StringKey("val", "GO_ONLINE");
private readonly StringKey DOWNLOAD_ONGOING = new StringKey("val", "DOWNLOAD_ONGOING");
Expand All @@ -35,7 +31,6 @@ public class ContentSelectDownloadScreen : MonoBehaviour, IContentImageDrawer
Texture2D picture_pin = null;
private Texture2D button_download = null;
private Texture2D button_update = null;
private Texture2D button_play = null;
private Texture2D button_no_entry = null;
// Display coroutine
Coroutine co_display = null;
Expand All @@ -53,7 +48,6 @@ public ContentSelectDownloadScreen()
picture_pin = Resources.Load("sprites/scenario_list/picture_pin") as Texture2D;
button_download = Resources.Load("sprites/scenario_list/button_download") as Texture2D;
button_update = Resources.Load("sprites/scenario_list/button_update") as Texture2D;
button_play = Resources.Load("sprites/scenario_list/button_play") as Texture2D;
button_no_entry = Resources.Load("sprites/scenario_list/button_no_entry") as Texture2D;

// Clean everything up
Expand Down Expand Up @@ -295,8 +289,6 @@ private void DrawOnlineModeButton()

text_connection_status = new UIElement();


//TODO Continue here
// Display connection status message
if (game.remoteContentPackManager.content_pack_list_Mode == RemoteContentPackManager.RemoteContentPackListMode.ERROR_DOWNLOAD)
{
Expand All @@ -307,20 +299,27 @@ private void DrawOnlineModeButton()
{
// Download ongoing
text_connection_status.SetText(DOWNLOAD_ONGOING, Color.cyan);
manager.Register_cb_download(RemoteQuestsListDownload_cb);
game.remoteContentPackManager.Register_cb_download(RemoteQuestsListDownload_cb);
}
else if (game.remoteContentPackManager.content_pack_list_Mode == RemoteContentPackManager.RemoteContentPackListMode.ONLINE)
{
// Download done, we are online
text_connection_status.SetText(GO_OFFLINE, Color.red);
text_connection_status.SetButton(delegate { SetOnlineMode(false); });
text_connection_status.SetButton(
delegate {
SetOnlineMode(false);
});
border = true;
}
else
{
// Download done, user has switched offline modline
text_connection_status.SetText(GO_ONLINE, Color.green);
text_connection_status.SetButton(delegate { SetOnlineMode(true); });
text_connection_status.SetButton(
delegate
{
SetOnlineMode(true);
});
border = true;
}

Expand All @@ -332,11 +331,12 @@ private void DrawOnlineModeButton()
if (border)
new UIElementBorder(text_connection_status, text_connection_status.GetTextColor());

//TODO check routine logic
//TODO check how Coroutine logic works
//if (co_display != null)
// StopCoroutine(co_display);
//co_display = StartCoroutine(DrawContentPackList());

//TODO when Coroutine logic works remove this line
DrawContentPackList();
}

Expand All @@ -346,17 +346,42 @@ private void SetOnlineMode(bool go_online)
{
ValkyrieDebug.Log("INFO: Set online mode for quests");

game.questsList.SetMode(QuestsManager.QuestListMode.ONLINE);
game.remoteContentPackManager.SetMode(RemoteContentPackManager.RemoteContentPackListMode.ONLINE);
}
else
{
ValkyrieDebug.Log("INFO: Set offline mode for quests");
game.questsList.SetMode(QuestsManager.QuestListMode.LOCAL);
game.remoteContentPackManager.SetMode(RemoteContentPackManager.RemoteContentPackListMode.LOCAL);
}

DrawOnlineModeButton();
//TODO
//ReloadQuestList();

ReloadContentPackList();
}

public void ReloadContentPackList()
{
CleanContentPackList();

//TODO check how Coroutine logic works
//co_display = StartCoroutine(DrawContentPackList());
//TODO when Coroutine logic works remove this line
DrawContentPackList();
}

public void CleanContentPackList()
{
// Clean up everything marked as 'questlist'
foreach (GameObject go in GameObject.FindGameObjectsWithTag(Game.CONTENTPACKLIST))
Destroy(go);

scrollArea = null;

// quest images
images_list.Clear();

if (co_display != null)
StopCoroutine(co_display);
}

private void RemoteQuestsListDownload_cb(bool is_available)
Expand Down

0 comments on commit 97a21ef

Please sign in to comment.