Skip to content

Commit

Permalink
Fix the user count string to suck less
Browse files Browse the repository at this point in the history
  • Loading branch information
zero318 committed Nov 15, 2024
1 parent fcd3dca commit 5360bbf
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 18 deletions.
18 changes: 3 additions & 15 deletions replacement_files/network.nut
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ for( local i = 0; i < 5; i = ++i )
this.server_port_v.push(c);
}

this.lobby_user_str <- ::font.CreateSystemString("Users: ");
this.lobby_user_str.x = 300;
this.lobby_user_str.y = 300;
this.lobby_user_str.ConnectRenderSlot(::graphics.slot.front,-1);
this.lobby_user_str.visible = false;

this.server_port_h <- this.Cursor(1, 5, ::input_all);
this.cursor_upnp <- this.Cursor(1, 2, ::input_all);
this.cursor_allow_watch <- this.Cursor(1, 2, ::input_all);
Expand Down Expand Up @@ -253,14 +247,6 @@ function UpdateMain()
::menu.help.Set(this.help);
this.cursor_item.Update();

if (::LOBBY.GetNetworkState() == 2) {
this.lobby_user_str.Set("Users: " + ::lobby.user_count());
this.lobby_user_str.visible = true;
}
else {
this.lobby_user_str.visible = false;
}

if (::input_all.b0 == 1)
{
::input_all.Lock();
Expand All @@ -282,6 +268,7 @@ function UpdateMain()
this.lobby_user_state = ::LOBBY.WAIT_INCOMMING;
::network.use_lobby = true;
::network.StartupServer(::config.network.hosting_port, 0);
::lobby.inc_user_count();
this.update = this.UpdateMatch;
::Dialog(-1, this.item_table.wait_incomming[0], null, this.dialog_wait.InitializeWithUPnP);
}
Expand Down Expand Up @@ -597,7 +584,7 @@ function UpdateMatch()
{
if (this.timeout++ > 360)
{
::debug.print(this.retry_count+"\n");
//::debug.print(this.retry_count+"\n");
if (this.retry_count++ > 5)
{
this.lobby_user_state = ::LOBBY.MATCHING;
Expand Down Expand Up @@ -682,6 +669,7 @@ function LobbyUpdate()
else if (::LOBBY.GetNetworkState() != ::LOBBY.CLOSED)
{
::LOBBY.Close();
this.lobby_time_stamp -= 9000;
}
}

Expand Down
161 changes: 161 additions & 0 deletions replacement_files/network_animation.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
this.anime_set <- ::actor.LoadAnimationData("data/system/network/network.pat");
function Initialize()
{
this.action <- ::menu.network.weakref();
this.x <- 0;
this.y <- 0;
this.visible <- true;
this.item <- [];
this.active <- false;
this.texture <- ::manbow.Texture();
this.texture.Load("data/system/network/network_font.png");
local res;
res = this.anime_set.title;
this.title <- ::manbow.Sprite();
this.title.Initialize(this.texture, res.left, res.top, res.width, res.height);
this.item.push(this.title);
local item_table = this.action.item_table;
::menu.common.InitializeLayout.call(this, null, item_table);
local item_width = 548;
local left = ::menu.common.item_x - item_width / 2 - 36;
local text_table = {};

foreach( i, v in this.action.item )
{
if (v == null)
{
continue;
}

local t = this.text[i];
t.x = left;
text_table[v] <- t;
}

this.cursor_x <- left - 20;
local item_left = 340;
this.select_obj <- [];
this.player_name <- ::font.CreateSystemString(::config.network.player_name);
this.player_name.x = text_table.player_name.x + item_left;
this.player_name.y = text_table.player_name.y;
this.player_name.blue = 0;
this.item.push(this.player_name);
this.port <- ::font.CreateSystemString(::config.network.hosting_port.tostring());
this.port.x = text_table.port.x + item_left;
this.port.y = text_table.port.y;
this.port.blue = 0;
this.item.push(this.port);
local select_x = left + item_left + 40;
local _width = item_width - item_left;
local t = [
"upnp",
"allow_watch"
];

foreach( v in t )
{
if (!("cursor_" + v in this.action))
{
continue;
}

this.select_obj.append(this.UIItemSelectorSingle(item_table[v].slice(1), text_table[v].x + item_left, text_table[v].y, this.mat_world, this.action["cursor_" + v]));
this.select_obj.top().SetColor(1, 1, 0);
}

this.select_obj.append(this.UIItemSelectorSingle(this.action.room_title, text_table.lobby_select.x + item_left, text_table.lobby_select.y, this.mat_world, this.action.cursor_lobby));
this.select_obj.top().SetColor(1, 1, 0);
local a = item_table.lobby_state;
local t = ::font.CreateSystemString(a[0]);
t.x = text_table.lobby_incomming.x + item_left;
t.y = text_table.lobby_incomming.y;
this.item.push(t);
this.lobby_state <- [];

for( local i = 1; i < 4; i = ++i )
{
local t = ::font.CreateSystemString(a[i]);
t.x = text_table.lobby_incomming.x + item_left + 200;
t.y = text_table.lobby_incomming.y;
this.item.push(t);
this.lobby_state.push(t);
}

this.lobby_state[0].green = 0;
this.lobby_state[0].blue = 0;
this.lobby_state[1].blue = 0;
this.lobby_state[2].red = 0;

this.lobby_user_str <- ::font.CreateSystemString("Users: ");
this.lobby_user_str.x = 670;
this.lobby_user_str.y = 222;
//this.lobby_user_str.ConnectRenderSlot(::graphics.slot.overlay, 0);
this.lobby_user_str.visible = false;
this.item.push(this.lobby_user_str);

foreach( v in this.item )
{
v.ConnectRenderSlot(::graphics.slot.overlay, 0);
}

this.state <- 0;
::loop.AddTask(this);
}

function Terminate()
{
::menu.common.TerminateLayout.call(this);
this.title = null;
this.item = null;
this.lobby_state = null;
this.port = null;
this.player_name = null;
this.select_obj = null;
this.texture = null;
this.lobby_user_str = null;
::loop.DeleteTask(this);
}

function Update()
{
::menu.common.UpdateLayout.call(this, this);
local state = ::LOBBY.GetNetworkState();

if (state != ::LOBBY.CLOSED) {
this.lobby_user_str.Set("Users: " + ::lobby.user_count());
this.lobby_user_str.visible = true;
} else {
this.lobby_user_str.visible = false;
}

foreach( v in this.lobby_state )
{
v.visible = false;
}

switch(state)
{
case 0:
case 1:
case 2:
this.lobby_state[state].visible = true;
break;

default:
this.lobby_state[0].visible = true;
break;
}

this.player_name.Set(::config.network.player_name);
this.port.Set(::config.network.hosting_port.tostring());

foreach( v in this.select_obj )
{
v.Update();
}

foreach( v in this.item )
{
v.SetWorldTransform(this.mat_world);
}
}
7 changes: 7 additions & 0 deletions th155r/Netcode/file_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ static constexpr uint8_t network_component_nut[] = {
#endif
};

static constexpr uint8_t network_animation_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/network_animation.nut.h"
#endif
};

static constexpr uint8_t version_nut[] = {
#if FILE_REPLACEMENT_TYPE == FILE_REPLACEMENT_NO_CRYPT
#include "replacement_files/version.nut.h"
Expand Down Expand Up @@ -124,6 +130,7 @@ static constexpr uint8_t dialog_wait_nut[] = {
static const std::unordered_map<std::string_view, const EmbedData> replacements = {
{"data/system/network/network.nut"sv, network_nut},
{"data/system/component/network.nut"sv, network_component_nut},
{"data/system/network/network_animation.nut"sv, network_animation_nut},
{"data/script/version.nut"sv, version_nut},
{"data/script/battle/battle.nut"sv, battle_nut},
{"data/script/battle/battle_practice.nut"sv, battle_practice_nut},
Expand Down
12 changes: 10 additions & 2 deletions th155r/Netcode/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,19 @@ SQInteger start_direct_punch_wait(HSQUIRRELVM v) {

SQInteger get_users_in_room(HSQUIRRELVM v) {
sq_pushinteger(v, users_in_room);
//log_printf("Users in room: %u\n", users_in_room);
//log_printf("Users in room: %u\n", users_in_room.load());
return 1;
}

SQInteger inc_users_in_room(HSQUIRRELVM v) {
++users_in_room;
return 0;
}

SQInteger dec_users_in_room(HSQUIRRELVM v) {
--users_in_room;
if (users_in_room) {
--users_in_room;
}
return 0;
}

Expand Down Expand Up @@ -430,6 +437,7 @@ extern "C" {
// custom lobby table
sq_createtable(v, _SC("lobby"), [](HSQUIRRELVM v) {
sq_setfunc(v, _SC("user_count"), get_users_in_room);
sq_setfunc(v, _SC("inc_user_count"), inc_users_in_room);
sq_setfunc(v, _SC("dec_user_count"), dec_users_in_room);
});

Expand Down
2 changes: 1 addition & 1 deletion th155r/Netcode/replacement_files/network.nut.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions th155r/Netcode/replacement_files/network_animation.nut.h

Large diffs are not rendered by default.

0 comments on commit 5360bbf

Please sign in to comment.