mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-21 19:45:10 +00:00
Added player description to player list
This commit is contained in:
parent
6198a1208d
commit
dab7cf4c2b
11 changed files with 114 additions and 9 deletions
|
@ -281,6 +281,7 @@
|
|||
- [get_network_player_smallest_global](#get_network_player_smallest_global)
|
||||
- [network_player_connected_count](#network_player_connected_count)
|
||||
- [network_player_from_global_index](#network_player_from_global_index)
|
||||
- [network_player_set_description](#network_player_set_description)
|
||||
|
||||
<br />
|
||||
|
||||
|
@ -4815,6 +4816,31 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [network_player_set_description](#network_player_set_description)
|
||||
|
||||
### Lua Example
|
||||
`network_player_set_description(np, description, r, g, b, a)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| np | [NetworkPlayer](structs.md#NetworkPlayer) |
|
||||
| description | string |
|
||||
| r | integer |
|
||||
| g | integer |
|
||||
| b | integer |
|
||||
| a | integer |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void network_player_set_description(struct NetworkPlayer* np, const char* description, u8 r, u8 g, u8 b, u8 a);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
---
|
||||
# functions from network_utils.h
|
||||
|
||||
|
|
|
@ -598,6 +598,11 @@
|
|||
| currLevelAreaSeqId | integer | read-only |
|
||||
| currLevelNum | integer | read-only |
|
||||
| currLevelSyncValid | bool | read-only |
|
||||
| description | string | read-only |
|
||||
| descriptionA | integer | read-only |
|
||||
| descriptionB | integer | read-only |
|
||||
| descriptionG | integer | read-only |
|
||||
| descriptionR | integer | read-only |
|
||||
| fadeOpacity | integer | read-only |
|
||||
| globalIndex | integer | read-only |
|
||||
| lastReceived | number | read-only |
|
||||
|
|
|
@ -247,6 +247,7 @@ function on_player_connected(m)
|
|||
-- start out as a non-seeker
|
||||
local s = gPlayerSyncTable[m.playerIndex]
|
||||
s.seeking = true
|
||||
network_player_set_description(gNetworkPlayers[m.playerIndex], "seeker", 255, 64, 64, 255)
|
||||
end
|
||||
|
||||
function hud_top_render()
|
||||
|
@ -420,6 +421,12 @@ function on_seeking_changed(tag, oldVal, newVal)
|
|||
sLastSeekerIndex = m.playerIndex
|
||||
sRoundTimer = 0
|
||||
end
|
||||
|
||||
if newVal then
|
||||
network_player_set_description(np, "seeker", 255, 64, 64, 255)
|
||||
else
|
||||
network_player_set_description(np, "hider", 128, 128, 128, 255)
|
||||
end
|
||||
end
|
||||
|
||||
-----------
|
||||
|
@ -440,4 +447,5 @@ hook_on_sync_table_change(gGlobalSyncTable, 'roundState', 0, on_round_state_chan
|
|||
for i=0,(MAX_PLAYERS-1) do
|
||||
gPlayerSyncTable[i].seeking = true
|
||||
hook_on_sync_table_change(gPlayerSyncTable[i], 'seeking', i, on_seeking_changed)
|
||||
network_player_set_description(gNetworkPlayers[i], "seeker", 255, 64, 64, 255)
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define MAX_VOLUME 127
|
||||
#define MAX_CONFIG_STRING 64
|
||||
#define MAX_PLAYER_STRING 20
|
||||
#define MAX_DESCRIPTION_STRING 20
|
||||
|
||||
#define DEFAULT_PORT 7777
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#ifdef DEBUG
|
||||
#include "pc/lua/smlua.h"
|
||||
|
||||
static u8 warpToLevel = LEVEL_BOB;
|
||||
static u8 warpToLevel = LEVEL_SSL;
|
||||
static u8 warpToArea = 27;
|
||||
// warpToArea: 26 = basement
|
||||
// warpToArea: 27 = upstairs
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
struct DjuiThreePanel* gDjuiModList = NULL;
|
||||
|
||||
void djui_panel_modlist_create(UNUSED struct DjuiBase* caller) {
|
||||
int playerListWidth = 580;
|
||||
int playerListWidth = 585;
|
||||
int modListWidth = 280;
|
||||
|
||||
// delete old mod list
|
||||
|
|
|
@ -13,6 +13,7 @@ struct DjuiThreePanel* gDjuiPlayerList = NULL;
|
|||
static struct DjuiFlowLayout* djuiRow[MAX_PLAYERS] = { 0 };
|
||||
static struct DjuiImage* djuiImages[MAX_PLAYERS] = { 0 };
|
||||
static struct DjuiText* djuiTextNames[MAX_PLAYERS] = { 0 };
|
||||
static struct DjuiText* djuiTextDescriptions[MAX_PLAYERS] = { 0 };
|
||||
static struct DjuiText* djuiTextLocations[MAX_PLAYERS] = { 0 };
|
||||
|
||||
static void playerlist_update_row(u8 i, struct NetworkPlayer* np) {
|
||||
|
@ -31,6 +32,9 @@ static void playerlist_update_row(u8 i, struct NetworkPlayer* np) {
|
|||
djui_base_set_color(&djuiTextNames[i]->base, rgb[0], rgb[1], rgb[2], 255);
|
||||
djui_text_set_text(djuiTextNames[i], np->name);
|
||||
|
||||
djui_base_set_color(&djuiTextDescriptions[i]->base, np->descriptionR, np->descriptionG, np->descriptionB, np->descriptionA);
|
||||
djui_text_set_text(djuiTextDescriptions[i], np->description);
|
||||
|
||||
djui_text_set_text(djuiTextLocations[i], get_level_name(np->currCourseNum, np->currLevelNum, np->currAreaIndex));
|
||||
}
|
||||
|
||||
|
@ -56,7 +60,7 @@ void djui_panel_playerlist_create(UNUSED struct DjuiBase* caller) {
|
|||
panel->base.on_render_pre = djui_panel_playerlist_on_render_pre;
|
||||
djui_base_set_alignment(&panel->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
|
||||
djui_base_set_size_type(&panel->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&panel->base, 580, bodyHeight + (32 + 16) + 32 + 32);
|
||||
djui_base_set_size(&panel->base, 585, bodyHeight + (32 + 16) + 32 + 32);
|
||||
djui_base_set_visible(&panel->base, false);
|
||||
struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel);
|
||||
djui_flow_layout_set_margin(body, 4);
|
||||
|
@ -84,11 +88,18 @@ void djui_panel_playerlist_create(UNUSED struct DjuiBase* caller) {
|
|||
djui_base_set_color(&t2->base, t, t, t, 255);
|
||||
djuiTextNames[i] = t2;
|
||||
|
||||
struct DjuiText* t3 = djui_text_create(&row->base, "location");
|
||||
struct DjuiText* t3 = djui_text_create(&row->base, "");
|
||||
djui_base_set_size_type(&t3->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&t3->base, 300, 32.0f);
|
||||
djui_base_set_color(&t3->base, t, t, t, 255);
|
||||
djui_text_set_alignment(t3, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
djuiTextLocations[i] = t3;
|
||||
djui_base_set_size(&t3->base, 100, 32.0f);
|
||||
djui_base_set_color(&t3->base, 220, 220, 220, 255);
|
||||
djui_text_set_alignment(t3, DJUI_HALIGN_CENTER, DJUI_VALIGN_TOP);
|
||||
djuiTextDescriptions[i] = t3;
|
||||
|
||||
struct DjuiText* t4 = djui_text_create(&row->base, "location");
|
||||
djui_base_set_size_type(&t4->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&t4->base, 300 - 100, 32.0f);
|
||||
djui_base_set_color(&t4->base, t, t, t, 255);
|
||||
djui_text_set_alignment(t4, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
djuiTextLocations[i] = t4;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -447,7 +447,7 @@ static struct LuaObjectField sModeTransitionInfoFields[LUA_MODE_TRANSITION_INFO_
|
|||
{ "transitionStart", LVT_COBJECT, offsetof(struct ModeTransitionInfo, transitionStart), true, LOT_LINEARTRANSITIONPOINT },
|
||||
};
|
||||
|
||||
#define LUA_NETWORK_PLAYER_FIELD_COUNT 18
|
||||
#define LUA_NETWORK_PLAYER_FIELD_COUNT 23
|
||||
static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT] = {
|
||||
{ "connected", LVT_BOOL, offsetof(struct NetworkPlayer, connected), true, LOT_NONE },
|
||||
{ "currActNum", LVT_S16, offsetof(struct NetworkPlayer, currActNum), true, LOT_NONE },
|
||||
|
@ -457,6 +457,11 @@ static struct LuaObjectField sNetworkPlayerFields[LUA_NETWORK_PLAYER_FIELD_COUNT
|
|||
{ "currLevelAreaSeqId", LVT_U16, offsetof(struct NetworkPlayer, currLevelAreaSeqId), true, LOT_NONE },
|
||||
{ "currLevelNum", LVT_S16, offsetof(struct NetworkPlayer, currLevelNum), true, LOT_NONE },
|
||||
{ "currLevelSyncValid", LVT_BOOL, offsetof(struct NetworkPlayer, currLevelSyncValid), true, LOT_NONE },
|
||||
{ "description", LVT_STRING, offsetof(struct NetworkPlayer, description), true, LOT_NONE },
|
||||
{ "descriptionA", LVT_U8, offsetof(struct NetworkPlayer, descriptionA), true, LOT_NONE },
|
||||
{ "descriptionB", LVT_U8, offsetof(struct NetworkPlayer, descriptionB), true, LOT_NONE },
|
||||
{ "descriptionG", LVT_U8, offsetof(struct NetworkPlayer, descriptionG), true, LOT_NONE },
|
||||
{ "descriptionR", LVT_U8, offsetof(struct NetworkPlayer, descriptionR), true, LOT_NONE },
|
||||
{ "fadeOpacity", LVT_U8, offsetof(struct NetworkPlayer, fadeOpacity), true, LOT_NONE },
|
||||
{ "globalIndex", LVT_U8, offsetof(struct NetworkPlayer, globalIndex), true, LOT_NONE },
|
||||
{ "lastReceived", LVT_F32, offsetof(struct NetworkPlayer, lastReceived), true, LOT_NONE },
|
||||
|
|
|
@ -2995,6 +2995,27 @@ int smlua_func_network_player_from_global_index(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_network_player_set_description(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 6)) { return 0; }
|
||||
|
||||
struct NetworkPlayer* np = (struct NetworkPlayer*)smlua_to_cobject(L, 1, LOT_NETWORKPLAYER);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
const char* description = smlua_to_string(L, 2);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
u8 r = smlua_to_integer(L, 3);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
u8 g = smlua_to_integer(L, 4);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
u8 b = smlua_to_integer(L, 5);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
u8 a = smlua_to_integer(L, 6);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
network_player_set_description(np, description, r, g, b, a);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
// network_utils.h //
|
||||
/////////////////////
|
||||
|
@ -3793,6 +3814,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "get_network_player_smallest_global", smlua_func_get_network_player_smallest_global);
|
||||
smlua_bind_function(L, "network_player_connected_count", smlua_func_network_player_connected_count);
|
||||
smlua_bind_function(L, "network_player_from_global_index", smlua_func_network_player_from_global_index);
|
||||
smlua_bind_function(L, "network_player_set_description", smlua_func_network_player_set_description);
|
||||
|
||||
// network_utils.h
|
||||
smlua_bind_function(L, "network_get_player_text_color_string", smlua_func_network_get_player_text_color_string);
|
||||
|
|
|
@ -42,6 +42,21 @@ u8 network_player_connected_count(void) {
|
|||
return count;
|
||||
}
|
||||
|
||||
void network_player_set_description(struct NetworkPlayer* np, const char* description, u8 r, u8 g, u8 b, u8 a) {
|
||||
if (np == NULL) { return; }
|
||||
|
||||
if (description != NULL) {
|
||||
snprintf(np->description, MAX_DESCRIPTION_STRING, "%s", description);
|
||||
} else {
|
||||
np->description[0] = '\0';
|
||||
}
|
||||
|
||||
np->descriptionR = r;
|
||||
np->descriptionG = g;
|
||||
np->descriptionB = b;
|
||||
np->descriptionA = a;
|
||||
}
|
||||
|
||||
struct NetworkPlayer* network_player_from_global_index(u8 globalIndex) {
|
||||
for (int i = 0; i < MAX_PLAYERS; i++) {
|
||||
if (!gNetworkPlayers[i].connected) { continue; }
|
||||
|
@ -181,6 +196,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
|
|||
np->localIndex = localIndex;
|
||||
np->globalIndex = globalIndex;
|
||||
if ((type != NPT_LOCAL) && (gNetworkType == NT_SERVER || type == NPT_SERVER)) { gNetworkSystem->save_id(localIndex, 0); }
|
||||
network_player_set_description(np, NULL, 0, 0, 0, 0);
|
||||
|
||||
// update course/level
|
||||
np->currLevelAreaSeqId = 0;
|
||||
|
|
|
@ -37,6 +37,13 @@ struct NetworkPlayer {
|
|||
u8 modelIndex;
|
||||
u8 paletteIndex;
|
||||
char name[MAX_PLAYER_STRING+1];
|
||||
|
||||
char description[MAX_DESCRIPTION_STRING+1];
|
||||
u8 descriptionR;
|
||||
u8 descriptionG;
|
||||
u8 descriptionB;
|
||||
u8 descriptionA;
|
||||
|
||||
u16 rxSeqIds[MAX_RX_SEQ_IDS];
|
||||
u32 rxPacketHash[MAX_RX_SEQ_IDS];
|
||||
};
|
||||
|
@ -49,14 +56,18 @@ void network_player_init(void);
|
|||
void network_player_update_model(u8 localIndex);
|
||||
bool network_player_any_connected(void);
|
||||
u8 network_player_connected_count(void);
|
||||
void network_player_set_description(struct NetworkPlayer* np, const char* description, u8 r, u8 g, u8 b, u8 a);
|
||||
|
||||
struct NetworkPlayer* network_player_from_global_index(u8 globalIndex);
|
||||
struct NetworkPlayer* get_network_player_from_level(s16 courseNum, s16 actNum, s16 levelNum);
|
||||
struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex);
|
||||
struct NetworkPlayer* get_network_player_smallest_global(void);
|
||||
|
||||
void network_player_update(void);
|
||||
|
||||
u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, u8 paletteIndex, char* name);
|
||||
u8 network_player_disconnected(u8 globalIndex);
|
||||
|
||||
void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex);
|
||||
void network_player_shutdown(void);
|
||||
|
||||
|
|
Loading…
Reference in a new issue