Added network_get_player_text_color_string() to lua api
This commit is contained in:
parent
6fcc60a791
commit
b6a3733bf0
|
@ -202,7 +202,9 @@ def build_call(function):
|
|||
lfunc = 'lua_pushnumber'
|
||||
elif ftype == 'bool':
|
||||
lfunc = 'lua_pushboolean'
|
||||
elif '???' not in flot:
|
||||
elif ftype == 'char*':
|
||||
lfunc = 'lua_pushstring'
|
||||
elif '???' not in flot and flot != 'LOT_NONE':
|
||||
return ' smlua_push_object(L, %s, %s);\n' % (flot, ccall)
|
||||
|
||||
return ' %s(L, %s);\n' % (lfunc, ccall)
|
||||
|
|
|
@ -66,6 +66,13 @@ function vec3f_mul(dest, a)
|
|||
return dest
|
||||
end
|
||||
|
||||
function vec3f_dist(v1, v2)
|
||||
dx = v1.x - v2.x
|
||||
dy = v1.y - v2.y
|
||||
dz = v1.z - v2.z
|
||||
return math.sqrt(dx * dx + dy * dy + dz * dz)
|
||||
end
|
||||
|
||||
function vec3s_copy(dest, src)
|
||||
dest.x = src.x
|
||||
dest.y = src.y
|
||||
|
@ -101,6 +108,13 @@ function vec3s_mul(dest, a)
|
|||
return dest
|
||||
end
|
||||
|
||||
function vec3s_dist(v1, v2)
|
||||
dx = v1.x - v2.x
|
||||
dy = v1.y - v2.y
|
||||
dz = v1.z - v2.z
|
||||
return math.sqrt(dx * dx + dy * dy + dz * dz)
|
||||
end
|
||||
|
||||
function approach_f32(current, target, inc, dec)
|
||||
if current < target then
|
||||
current = current + inc
|
||||
|
|
|
@ -241,6 +241,7 @@
|
|||
<br />
|
||||
|
||||
- network_utils.h
|
||||
- [network_get_player_text_color_string](#network_get_player_text_color_string)
|
||||
- [network_global_index_from_local](#network_global_index_from_local)
|
||||
- [network_is_server](#network_is_server)
|
||||
- [network_local_index_from_global](#network_local_index_from_global)
|
||||
|
@ -4143,6 +4144,26 @@
|
|||
<br />
|
||||
|
||||
|
||||
## [network_get_player_text_color_string](#network_get_player_text_color_string)
|
||||
|
||||
### Lua Example
|
||||
`local stringValue = network_get_player_text_color_string(localIndex)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| localIndex | integer |
|
||||
|
||||
### Returns
|
||||
- string
|
||||
|
||||
### C Prototype
|
||||
`char* network_get_player_text_color_string(u8 localIndex);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [network_global_index_from_local](#network_global_index_from_local)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
@ -45,9 +45,11 @@ static void djui_chat_message_destroy(struct DjuiBase* base) {
|
|||
|
||||
void djui_chat_message_create_from(u8 globalIndex, const char* message) {
|
||||
struct NetworkPlayer* np = network_player_from_global_index(globalIndex);
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
|
||||
char* playerColorString = network_get_player_text_color_string(np->localIndex);
|
||||
char chatMsg[256] = { 0 };
|
||||
snprintf(chatMsg, 256, "\\#%02x%02x%02x\\%s:\\#dcdcdc\\ %s", rgb[0], rgb[1], rgb[2], (np != NULL) ? np->name : "Player", message);
|
||||
snprintf(chatMsg, 256, "%s%s:\\#dcdcdc\\ %s", playerColorString, (np != NULL) ? np->name : "Player", message);
|
||||
|
||||
play_sound((globalIndex == gNetworkPlayerLocal->globalIndex) ? SOUND_MENU_MESSAGE_DISAPPEAR : SOUND_MENU_MESSAGE_APPEAR, gDefaultSoundArgs);
|
||||
djui_chat_message_create(chatMsg);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ static void playerlist_update_row(u8 i, struct NetworkPlayer* np) {
|
|||
|
||||
djui_base_set_visible(&djuiRow[i]->base, visible);
|
||||
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
u8* rgb = network_get_player_text_color(np->localIndex);
|
||||
djui_base_set_color(&djuiTextNames[i]->base, rgb[0], rgb[1], rgb[2], 255);
|
||||
djui_text_set_text(djuiTextNames[i], np->name);
|
||||
|
||||
|
|
|
@ -59,6 +59,12 @@ char gSmluaConstants[] = ""
|
|||
" dest.z = dest.z * a\n"
|
||||
" return dest\n"
|
||||
"end\n"
|
||||
"function vec3f_dist(v1, v2)\n"
|
||||
" dx = v1.x - v2.x\n"
|
||||
" dy = v1.y - v2.y\n"
|
||||
" dz = v1.z - v2.z\n"
|
||||
" return math.sqrt(dx * dx + dy * dy + dz * dz)\n"
|
||||
"end\n"
|
||||
"function vec3s_copy(dest, src)\n"
|
||||
" dest.x = src.x\n"
|
||||
" dest.y = src.y\n"
|
||||
|
@ -89,6 +95,12 @@ char gSmluaConstants[] = ""
|
|||
" dest.z = dest.z * a\n"
|
||||
" return dest\n"
|
||||
"end\n"
|
||||
"function vec3s_dist(v1, v2)\n"
|
||||
" dx = v1.x - v2.x\n"
|
||||
" dy = v1.y - v2.y\n"
|
||||
" dz = v1.z - v2.z\n"
|
||||
" return math.sqrt(dx * dx + dy * dy + dz * dz)\n"
|
||||
"end\n"
|
||||
"function approach_f32(current, target, inc, dec)\n"
|
||||
" if current < target then\n"
|
||||
" current = current + inc\n"
|
||||
|
|
|
@ -2630,6 +2630,30 @@ int smlua_func_stop_and_set_height_to_floor(lua_State* L) {
|
|||
// network_utils.h //
|
||||
/////////////////////
|
||||
|
||||
/*
|
||||
int smlua_func_network_get_player_text_color(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
u8 localIndex = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
UNIMPLEMENTED -->(L, network_get_player_text_color(localIndex));
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
int smlua_func_network_get_player_text_color_string(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
u8 localIndex = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { return 0; }
|
||||
|
||||
lua_pushstring(L, network_get_player_text_color_string(localIndex));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_network_global_index_from_local(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
|
@ -3115,6 +3139,8 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "stop_and_set_height_to_floor", smlua_func_stop_and_set_height_to_floor);
|
||||
|
||||
// network_utils.h
|
||||
//smlua_bind_function(L, "network_get_player_text_color", smlua_func_network_get_player_text_color); <--- UNIMPLEMENTED
|
||||
smlua_bind_function(L, "network_get_player_text_color_string", smlua_func_network_get_player_text_color_string);
|
||||
smlua_bind_function(L, "network_global_index_from_local", smlua_func_network_global_index_from_local);
|
||||
smlua_bind_function(L, "network_is_server", smlua_func_network_is_server);
|
||||
smlua_bind_function(L, "network_local_index_from_global", smlua_func_network_local_index_from_global);
|
||||
|
|
|
@ -219,9 +219,9 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
|
|||
|
||||
// display connected popup
|
||||
if (type != NPT_SERVER && (gNetworkType != NT_SERVER || type != NPT_LOCAL)) {
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
char* playerColorString = network_get_player_text_color_string(np->localIndex);
|
||||
char popupMsg[128] = { 0 };
|
||||
snprintf(popupMsg, 128, "\\#%02x%02x%02x\\%s\\#dcdcdc\\ connected", rgb[0], rgb[1], rgb[2], np->name);
|
||||
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ connected", playerColorString, np->name);
|
||||
djui_popup_create(popupMsg, 1);
|
||||
}
|
||||
LOG_INFO("player connected, local %d, global %d", localIndex, np->globalIndex);
|
||||
|
@ -264,9 +264,9 @@ u8 network_player_disconnected(u8 globalIndex) {
|
|||
LOG_INFO("player disconnected, local %d, global %d", i, globalIndex);
|
||||
|
||||
// display popup
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
char* playerColorString = network_get_player_text_color_string(np->localIndex);
|
||||
char popupMsg[128] = { 0 };
|
||||
snprintf(popupMsg, 128, "\\#%02x%02x%02x\\%s\\#dcdcdc\\ disconnected", rgb[0], rgb[1], rgb[2], np->name);
|
||||
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ disconnected", playerColorString, np->name);
|
||||
djui_popup_create(popupMsg, 1);
|
||||
|
||||
packet_ordered_clear(globalIndex);
|
||||
|
@ -282,15 +282,15 @@ u8 network_player_disconnected(u8 globalIndex) {
|
|||
void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
|
||||
// display popup
|
||||
if (np->currCourseNum != courseNum && np->localIndex != 0) {
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
char* playerColorString = network_get_player_text_color_string(np->localIndex);
|
||||
char popupMsg[128] = { 0 };
|
||||
bool matchingLocal = (np->currCourseNum == gNetworkPlayerLocal->currCourseNum) && (np->currActNum == gNetworkPlayerLocal->currActNum);
|
||||
if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) {
|
||||
snprintf(popupMsg, 128, "\\#%02x%02x%02x\\%s\\#dcdcdc\\ left this level", rgb[0], rgb[1], rgb[2], np->name);
|
||||
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ left this level", playerColorString, np->name);
|
||||
} else if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) {
|
||||
snprintf(popupMsg, 128, "\\#%02x%02x%02x\\%s\\#dcdcdc\\ entered this level", rgb[0], rgb[1], rgb[2], np->name);
|
||||
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered this level", playerColorString, np->name);
|
||||
} else {
|
||||
snprintf(popupMsg, 128, "\\#%02x%02x%02x\\%s\\#dcdcdc\\ entered\n%s", rgb[0], rgb[1], rgb[2], np->name, get_level_name(courseNum, levelNum, areaIndex));
|
||||
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered\n%s", playerColorString, np->name, get_level_name(courseNum, levelNum, areaIndex));
|
||||
}
|
||||
djui_popup_create(popupMsg, 1);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include "network_utils.h"
|
||||
#include "game/mario_misc.h"
|
||||
|
||||
u8 network_global_index_from_local(u8 localIndex) {
|
||||
if (gNetworkType == NT_SERVER) { return localIndex; }
|
||||
|
@ -23,3 +25,24 @@ u8 network_local_index_from_global(u8 globalIndex) {
|
|||
bool network_is_server(void) {
|
||||
return gNetworkType == NT_SERVER;
|
||||
}
|
||||
|
||||
u8* network_get_player_text_color(u8 localIndex) {
|
||||
if (localIndex >= MAX_PLAYERS) { localIndex = 0; }
|
||||
|
||||
struct NetworkPlayer* np = &gNetworkPlayers[localIndex];
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
static u8 sTextRgb[3] = { 0 };
|
||||
for (int i = 0; i < 3; i++) {
|
||||
sTextRgb[i] = 127 + rgb[i] / 2;
|
||||
}
|
||||
|
||||
return sTextRgb;
|
||||
}
|
||||
|
||||
char* network_get_player_text_color_string(u8 localIndex) {
|
||||
if (localIndex >= MAX_PLAYERS) { localIndex = 0; }
|
||||
u8* rgb = network_get_player_text_color(localIndex);
|
||||
static char sColorString[10] = { 0 };
|
||||
snprintf(sColorString, 10, "\\#%02x%02x%02x\\", rgb[0], rgb[1], rgb[2]);
|
||||
return sColorString;
|
||||
}
|
||||
|
|
|
@ -9,4 +9,7 @@ u8 network_local_index_from_global(u8 globalIndex);
|
|||
|
||||
bool network_is_server(void);
|
||||
|
||||
u8* network_get_player_text_color(u8 localIndex);
|
||||
char* network_get_player_text_color_string(u8 localIndex);
|
||||
|
||||
#endif
|
|
@ -339,9 +339,9 @@ void network_receive_player(struct Packet* p) {
|
|||
// inform of player death
|
||||
if (oldData.action != ACT_BUBBLED && data.action == ACT_BUBBLED) {
|
||||
// display popup
|
||||
u8* rgb = get_player_color(np->paletteIndex, 0);
|
||||
char* playerColorString = network_get_player_text_color_string(np->localIndex);
|
||||
char popupMsg[128] = { 0 };
|
||||
snprintf(popupMsg, 128, "\\#%02x%02x%02x\\%s\\#dcdcdc\\ died", rgb[0], rgb[1], rgb[2], np->name);
|
||||
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ died", playerColorString, np->name);
|
||||
djui_popup_create(popupMsg, 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue