Menu-FN: Adjustments to the Updates menu, move code into platform/updates.{h,qc}

This commit is contained in:
Marco Cawthorne 2023-08-15 14:24:46 -07:00
parent 60128c6b1e
commit 410e3fc34e
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
9 changed files with 258 additions and 173 deletions

View File

@ -50,7 +50,7 @@ Colors_Init(void)
col_refresh_text = [255,255,255] / 255;
col_refresh_bg = [56,56,56] / 255;
col_button_bg = [1,1,1];
col_button_bg = [247,181,57] / 255;
col_button_select = [1,0,0];
col_button_click = [1,1,0];
col_button_disabled = [0.25, 0.25, 0.25];

View File

@ -103,44 +103,6 @@ var int gameinfo_current = -1;
int gameinfo_count;
gameinfo_t *games;
#ifndef WEBMENU
string(float id, float b) getgamedirinfo = #0;
string(int packageidx, int desiredfield) getpackagemanagerinfo = #0;
enum
{
GPMI_NAME, // name of the package, for use with the pkg command.
GPMI_CATEGORY, // category text
GPMI_TITLE, // name of the package, for showing the user.
GPMI_VERSION, // version info (may have multiple with the same name but different versions)
GPMI_DESCRIPTION, // some blurb
GPMI_LICENSE, // what license its distributed under
GPMI_AUTHOR, // name of the person(s) who created it
GPMI_WEBSITE, // where to contribute/find out more info/etc
GPMI_INSTALLED, // current state
GPMI_ACTION, // desired state
GPMI_AVAILABLE, // whether it may be downloaded or not.
GPMI_FILESIZE, // whether it may be downloaded or not.
};
typedef struct
{
string name;
string category;
string title;
string version;
string description;
string license;
string author;
string website;
string installed;
int size;
int uid;
} update_t;
int update_count;
update_t *updates;
#endif
int g_menupage;
enum

View File

@ -63,6 +63,22 @@ Menu_GammaHack(void)
}
}
bool
Menu_HasStartupVideos(void)
{
if (Platform_FileInCurrentGamedir("media/valve.avi"))
return true;
return false;
}
void
Menu_PlayStartupVideos(void)
{
print("playing startup videos\n");
//localcmd("playvideo av:media/sierra.avi av:media/valve.avi\n");
}
/* called upon menu init/restart */
void
m_init(void)
@ -121,6 +137,7 @@ m_init(void)
Colors_Init();
Strings_Init();
Updates_Init();
if (games[gameinfo_current].gamedir != "valve" || games[gameinfo_current].steambg == 1) {
m_intro_skip();
@ -153,6 +170,9 @@ m_init(void)
/* prepare spray logo keys */
spray_setinfokeys();
if (Menu_HasStartupVideos() == true)
Menu_PlayStartupVideos();
g_initialized = true;
}

View File

@ -721,10 +721,12 @@ customgame_lbmods_changed(void)
void
games_setdefaultpkgs(int id)
{
#if 0
if (games[id].gamedir == "valve") {
games[id].pkgname = "valve_patch;addon_furtherdata;addon_holidaymodels";
games[id].pkgfile = "maps/crossfire.bsp"; /* only found in patches */
}
#endif
}
void

View File

@ -14,27 +14,8 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define FN_UPDATE_IMGURL "http://www.frag-net.com/dl/img/%s.jpg"
#ifndef WEBMENU
enum
{
GPMI_NAME, // name of the package, for use with the pkg command.
GPMI_CATEGORY, // category text
GPMI_TITLE, // name of the package, for showing the user.
GPMI_VERSION, // version info (may have multiple with the same name but different versions)
GPMI_DESCRIPTION, // some blurb
GPMI_LICENSE, // what license its distributed under
GPMI_AUTHOR, // name of the person(s) who created it
GPMI_WEBSITE, // where to contribute/find out more info/etc
GPMI_INSTALLED, // current state
GPMI_ACTION, // desired state
GPMI_AVAILABLE, // whether it may be downloaded or not.
GPMI_FILESIZE, // size to download.
};
string(int, int) getpackagemanagerinfo = #0;
var int g_updates_initialized = FALSE;
var int autocvar_menu_updating = FALSE;
@ -63,49 +44,25 @@ up_btndone_start(void)
void
up_btninstall_start(void)
{
int pkgid;
pkgid = up_lbUpdates.GetSelected();
localcmd(sprintf("pkg add %s\n", updates[pkgid].name));
updates[pkgid].installed = "pending";
print(sprintf("Marking package %s for install.\n", updates[pkgid].title));
Updates_Remove(up_lbUpdates.GetSelected());
}
void
up_btnremove_start(void)
{
int pkgid;
pkgid = up_lbUpdates.GetSelected();
localcmd(sprintf("pkg rem %s\n", updates[pkgid].name));
updates[pkgid].installed = "rem";
print(sprintf("Marking package %s for 'removal'.\n", updates[pkgid].title));
Updates_Install(up_lbUpdates.GetSelected());
}
void
up_toggleinstall(void)
{
int pkgid;
pkgid = up_lbUpdates.GetSelected();
switch (updates[pkgid].installed) {
case "":
case "rem":
localcmd(sprintf("pkg add %s\n", updates[pkgid].name));
updates[pkgid].installed = "pending";
break;
default:
localcmd(sprintf("pkg rem %s\n", updates[pkgid].name));
updates[pkgid].installed = "rem";
}
Updates_Toggle(up_lbUpdates.GetSelected());
}
void
up_btnapply_start(void)
{
cvar_set("menu_updating", "1");
localcmd("pkg apply\n");
print("Applying package changes.\n");
Updates_ApplyPendingChanges();
}
void
@ -134,94 +91,14 @@ up_sbupdates_changed(int val)
up_lbUpdates.SetScroll(val);
}
void
menu_updates_refresh(void)
{
int c;
update_count = 0;
Updates_Refresh();
int updateCount = Updates_GetPackageCount();
if (updates) {
memfree(updates);
}
#if 0
for (int i = 0; (getpackagemanagerinfo(i, GPMI_NAME)); i++) {
string cat = getpackagemanagerinfo(i, GPMI_CATEGORY);
if (cat == "Plugins/") {
continue;
}
if (cat == "Mod/") {
continue;
}
update_count++;
}
#else
/* look for the valid packages in the gameinfo pkgname */
int pkgcount = tokenize(games[gameinfo_current].pkgname);
for (int i = 0i; i < pkgcount; i++) {
int id = game_getpackageid(argv(i));
if (id == -1)
continue;
update_count++;
}
#endif
c = 0;
updates = memalloc(sizeof(update_t) * update_count);
#if 0
for (int i = 0; (getpackagemanagerinfo(i, GPMI_NAME)); i++) {
string cat = getpackagemanagerinfo(i, GPMI_CATEGORY);
if (cat == "Plugins/") {
continue;
}
if (cat == "Mod/") {
continue;
}
updates[c].name = getpackagemanagerinfo(i, GPMI_NAME);
updates[c].category = getpackagemanagerinfo(i, GPMI_CATEGORY);
updates[c].title = getpackagemanagerinfo(i, GPMI_TITLE);
updates[c].version = getpackagemanagerinfo(i, GPMI_VERSION);
updates[c].description = getpackagemanagerinfo(i, GPMI_DESCRIPTION);
updates[c].license = getpackagemanagerinfo(i, GPMI_LICENSE);
updates[c].author = getpackagemanagerinfo(i, GPMI_AUTHOR);
updates[c].website = getpackagemanagerinfo(i, GPMI_WEBSITE);
updates[c].installed = getpackagemanagerinfo(i, GPMI_INSTALLED);
updates[c].size = (int)stof(getpackagemanagerinfo(i, GPMI_FILESIZE));
updates[c].uid = i;
precache_pic(sprintf(FN_UPDATE_IMGURL, updates[c].name));
c++;
}
#else
for (int i = 0i; i < pkgcount; i++) {
int id = game_getpackageid(argv(i));
if (id == -1)
continue;
updates[c].name = getpackagemanagerinfo(id, GPMI_NAME);
updates[c].category = getpackagemanagerinfo(id, GPMI_CATEGORY);
updates[c].title = getpackagemanagerinfo(id, GPMI_TITLE);
updates[c].version = getpackagemanagerinfo(id, GPMI_VERSION);
updates[c].description = getpackagemanagerinfo(id, GPMI_DESCRIPTION);
updates[c].license = getpackagemanagerinfo(id, GPMI_LICENSE);
updates[c].author = getpackagemanagerinfo(id, GPMI_AUTHOR);
updates[c].website = getpackagemanagerinfo(id, GPMI_WEBSITE);
updates[c].installed = getpackagemanagerinfo(id, GPMI_INSTALLED);
updates[c].size = (int)stof(getpackagemanagerinfo(id, GPMI_FILESIZE));
updates[c].uid = id;
precache_pic(sprintf(FN_UPDATE_IMGURL, updates[c].name));
c++;
}
#endif
up_sbUpdates.SetMax(update_count);
up_lbUpdates.SetMax(update_count);
up_sbUpdates.SetMax(updateCount);
up_lbUpdates.SetMax(updateCount);
up_lbUpdates.SetSelected(0);
}
#endif
@ -281,6 +158,8 @@ menu_updates_init(void)
up_frPreview.SetPos(350,160);
up_frPreview.SetSize(256+6,128+6);
Widget_Add(fn_updates, up_frPreview);
Updates_Refresh();
#endif
}
@ -312,8 +191,8 @@ menu_updates_draw(void)
}
/* query until 1 package is ready */
for (int i = 0; (getpackagemanagerinfo(i, GPMI_NAME)); i++) {
string installed = getpackagemanagerinfo(i, GPMI_INSTALLED);
for (int i = 0; (Updates_GetInfo(i, GPMI_NAME)); i++) {
string installed = Updates_GetInfo(i, GPMI_INSTALLED);
/* increment to keep track */
if (installed == "enabled")
old_enabled++;

View File

@ -14,6 +14,7 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "util.h"
#include "achievements.h"
#include "master.h"
#include "modserver.h"
@ -21,4 +22,4 @@
#include "richpresence.h"
#include "servers.h"
#include "tcp.h"
#include "util.h"
#include "updates.h"

View File

@ -7,4 +7,5 @@ richpresence.qc
servers.qc
tcp.qc
util.qc
updates.qc
#endlist

67
src/platform/updates.h Normal file
View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2016-2022 Vera Visions LLC.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
string(float id, float b) getgamedirinfo = #0;
string(int packageidx, int desiredfield) getpackagemanagerinfo = #0;
typedef enum
{
GPMI_NAME, /**< name of the package, for use with the pkg command. */
GPMI_CATEGORY, /**< category text */
GPMI_TITLE, /**< name of the package, for showing the user. */
GPMI_VERSION, /**< version info (may have multiple with the same name but different versions) */
GPMI_DESCRIPTION, /**< some blurb */
GPMI_LICENSE, /**< what license its distributed under */
GPMI_AUTHOR, /**< name of the person(s) who created it */
GPMI_WEBSITE, /**< where to contribute/find out more info/etc */
GPMI_INSTALLED, /**< current state */
GPMI_ACTION, /**< desired state */
GPMI_AVAILABLE, /**< whether it may be downloaded or not. */
GPMI_FILESIZE, /**< size to download. */
} updateType_t;
typedef struct
{
string name;
string category;
string title;
string version;
string description;
string license;
string author;
string website;
string installed;
int size;
int uid;
} update_t;
int g_platform_update_count;
update_t *updates;
#define FN_UPDATE_IMGURL "http://www.frag-net.com/dl/img/%s.jpg"
void Updates_Init(void);
void Updates_Refresh(void);
int Updates_GetPackageCount(void);
int Updates_IDForName(string);
string Updates_NameForID(int);
string Updates_GetInfo(int, updateType_t);
bool Updates_Available(void);
bool Updates_Toggle(int);
bool Updates_Install(int);
bool Updates_Remove(int);
bool Updates_ApplyPendingChanges(void);

153
src/platform/updates.qc Normal file
View File

@ -0,0 +1,153 @@
/** needs to be called upon menu-init, and call Updates_Refresh() if auto-updates
are enabled. if a chooser does not want updates, then we won't. */
void
Updates_Init(void)
{
/*localcmd("pkg addsource https://www.frag-net.com/pkgs/list\n");*/
print("Update system initialized.\n");
}
/** will return a cached value */
int
Updates_GetPackageCount(void)
{
return g_platform_update_count;
}
/** called whenever we need to re-initialize the updates struct */
void
Updates_Refresh(void)
{
int c = 0i;
g_platform_update_count = 0i;
/* clear */
if (updates) {
memfree(updates);
}
/* count all updates that we've got in our package sources */
for (int i = 0i; (Updates_GetInfo(i, GPMI_NAME)); i++) {
g_platform_update_count++;
}
updates = memalloc(sizeof(update_t) * g_platform_update_count);
/* limit it to packages that the game wants */
tokenizebyseparator(games[gameinfo_current].pkgname, ";");
/* fill in all the package values */
for (int i = 0i; i < g_platform_update_count; i++) {
int id = game_getpackageid(argv(i));
if (id == -1)
continue;
updates[c].name = Updates_GetInfo(id, GPMI_NAME);
updates[c].category = Updates_GetInfo(id, GPMI_CATEGORY);
updates[c].title = Updates_GetInfo(id, GPMI_TITLE);
updates[c].version = Updates_GetInfo(id, GPMI_VERSION);
updates[c].description = Updates_GetInfo(id, GPMI_DESCRIPTION);
updates[c].license = Updates_GetInfo(id, GPMI_LICENSE);
updates[c].author = Updates_GetInfo(id, GPMI_AUTHOR);
updates[c].website = Updates_GetInfo(id, GPMI_WEBSITE);
updates[c].installed = Updates_GetInfo(id, GPMI_INSTALLED);
updates[c].size = (int)stof(Updates_GetInfo(id, GPMI_FILESIZE));
updates[c].uid = id;
precache_pic(sprintf(FN_UPDATE_IMGURL, updates[c].name));
c++;
}
print(sprintf("Updates packages for this game: %i (%i Total)\n", c, g_platform_update_count));
g_platform_update_count = c;
}
/** Returns the package ID for a given name. Will return -1 when not available. */
int
Updates_IDForName(string packageName)
{
string tempString = "";
for (int i = 0i; (tempString = getpackagemanagerinfo(i, GPMI_NAME)); i++) {
if (tempString == packageName)
return i;
}
return -1i;
}
/** Returns the package name for a given ID. Returns __NULL__ when not available. */
string
Updates_NameForID(int packageID)
{
string packageName = getpackagemanagerinfo(packageID, GPMI_NAME);
if not (packageName)
return __NULL__;
return packageName;
}
/** Query a package (by ID) for its various info fields. See updateType_t for available fields. */
string
Updates_GetInfo(int packageID, updateType_t fieldType)
{
return getpackagemanagerinfo(packageID, (int)fieldType);
}
/** Returns if our current game has updates available for any installed packages. */
bool
Updates_Available(void)
{
return true;
}
/** Toggle the installation of a package. Will return true if it was done. */
bool
Updates_Toggle(int packageID)
{
switch (updates[packageID].installed) {
case "":
case "rem":
localcmd(sprintf("pkg add %s\n", updates[packageID].name));
updates[packageID].installed = "pending";
break;
default:
localcmd(sprintf("pkg rem %s\n", updates[packageID].name));
updates[packageID].installed = "rem";
}
return true;
}
/** Mark a package as pending installion. May return true/false if it succeeded in marking the package. */
bool
Updates_Install(int packageID)
{
localcmd(sprintf("pkg add %s\n", updates[packageID].name));
updates[packageID].installed = "pending";
print(sprintf("Marking package %s for install.\n", updates[packageID].title));
return true;
}
/** Mark a package as pending deletion. May return true/false if it succeeded in marking the package. */
bool
Updates_Remove(int packageID)
{
localcmd(sprintf("pkg rem %s\n", updates[packageID].name));
updates[packageID].installed = "rem";
print(sprintf("Marking package %s for 'removal'.\n", updates[packageID].title));
return true;
}
/** Apply all pending changes to packages. May return true/false if it succeeded in doing so. */
bool
Updates_ApplyPendingChanges(void)
{
cvar_set("menu_updating", "1");
localcmd("pkg apply\n");
print("Applying package changes.\n");
return true;
}