From 5c3d7d80cc1b3ba97497b92f6ec54fe7f8fc80d6 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 30 Mar 2018 17:06:29 -0300 Subject: [PATCH] Improve ETTP chat and til death net screens --- .../ScreenNetRoom decorations/default.lua | 19 +- .../ScreenNetRoom decorations/profile.lua | 2 +- .../ScreenNetRoom decorations/roomsearch.lua | 17 +- .../ScreenNetRoom decorations/tabs.lua | 11 +- .../ScreenNetSelectBase overlay/default.lua | 2 +- .../default.lua | 5 +- .../ScreenSelectMusic overlay/default.lua | 8 +- .../ScreenChatOverlay overlay.lua | 97 ++++++--- src/BitmapText.cpp | 198 ++++++++++-------- src/BitmapText.h | 1 + src/NetworkSyncManager.cpp | 7 + src/Screen.cpp | 27 +-- src/ScreenSMOnlineLogin.cpp | 73 +++++-- src/ScreenSMOnlineLogin.h | 5 +- 14 files changed, 304 insertions(+), 168 deletions(-) diff --git a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/default.lua b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/default.lua index c5c7cd8680..73f9a0e1c3 100644 --- a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/default.lua +++ b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/default.lua @@ -1,14 +1,27 @@ local t = Def.ActorFrame{} - -t[#t+1] = LoadActor("../_chatbox") +if not NSMAN:IsETTP() then + t[#t+1] = LoadActor("../_chatbox") +end t[#t+1] = LoadActor("profile") t[#t+1] = LoadActor("roomsearch") t[#t+1] = LoadActor("tabs") local g = Def.ActorFrame{ + BeginCommand=function(self) + local top= SCREENMAN:GetTopScreen() + if getTabIndex() == 0 and not NSMAN:IsETTP() then + top:ChatboxVisible(true) + top:ChatboxInput(true) + top:InfoSetVisible(true) + else + top:ChatboxVisible(false) + top:ChatboxInput(false) + top:InfoSetVisible(false) + end + end, TabChangedMessageCommand=function(self) local top= SCREENMAN:GetTopScreen() - if getTabIndex() == 0 then + if getTabIndex() == 0 and not NSMAN:IsETTP() then top:ChatboxVisible(true) top:ChatboxInput(true) top:InfoSetVisible(true) diff --git a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/profile.lua b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/profile.lua index fb487662e0..a2e8beb5bc 100644 --- a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/profile.lua +++ b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/profile.lua @@ -11,7 +11,7 @@ local t = Def.ActorFrame{ end, SetCommand=function(self) self:finishtweening() - if getTabIndex() == 2 then + if getTabIndex() == (NSMAN:IsETTP() and 1 or 2) then self:queuecommand("On") self:visible(true) update = true diff --git a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/roomsearch.lua b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/roomsearch.lua index 3293e4b1cf..2003cb44f7 100644 --- a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/roomsearch.lua +++ b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/roomsearch.lua @@ -105,14 +105,25 @@ local function ButtonActive(self) end local t = Def.ActorFrame{ - OnCommand=function(self) + BeginCommand=function(self) whee = SCREENMAN:GetTopScreen():GetMusicWheel() SCREENMAN:GetTopScreen():AddInputCallback(searchInput) - self:visible(false) + self:finishtweening() + if NSMAN:IsETTP() then + ms.ok("Song search activated") + self:visible(true) + active = true + whee:Move(0) + MESSAGEMAN:Broadcast("BeginningSearch") + MESSAGEMAN:Broadcast("RefreshSearchResults") + else + self:visible(false) + end + self:queuecommand("Set") end, SetCommand=function(self) self:finishtweening() - if getTabIndex() == 1 then + if getTabIndex() == (NSMAN:IsETTP() and 0 or 1) then ms.ok("Song search activated") MESSAGEMAN:Broadcast("BeginningSearch") self:visible(true) diff --git a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/tabs.lua b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/tabs.lua index eaff2e0018..8221302440 100644 --- a/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/tabs.lua +++ b/Themes/Til Death/BGAnimations/ScreenNetRoom decorations/tabs.lua @@ -3,7 +3,7 @@ local active = true local CtrlPressed = false local function input(event) if event.type ~= "InputEventType_Release" and active then - for i=1,3 do + for i=1,(NSMAN:IsETTP() and 2 or 3) do if event.DeviceInput.button == "DeviceButton_"..i and CtrlPressed == true then setTabIndex(i-1) MESSAGEMAN:Broadcast("TabChanged") @@ -59,9 +59,14 @@ t[#t+1] = LoadFont("Common Normal") .. { --]] --====================================================================================== -local tabNames = {"Chatbox","Search","Profile"} -- this probably should be in tabmanager. +local tabNames +if NSMAN:IsETTP() then + tabNames = {"Search","Profile"} +else + tabNames = {"Chatbox","Search","Profile"} +end -local frameWidth = (SCREEN_WIDTH*(9/24))/(#tabNames-1) +local frameWidth = (SCREEN_WIDTH*(7/24))/(#tabNames-1) local frameX = frameWidth/2 local frameY = SCREEN_HEIGHT-70 diff --git a/Themes/Til Death/BGAnimations/ScreenNetSelectBase overlay/default.lua b/Themes/Til Death/BGAnimations/ScreenNetSelectBase overlay/default.lua index 9551c517af..895151410c 100644 --- a/Themes/Til Death/BGAnimations/ScreenNetSelectBase overlay/default.lua +++ b/Themes/Til Death/BGAnimations/ScreenNetSelectBase overlay/default.lua @@ -38,7 +38,7 @@ t[#t+1] = LoadActor("../_PlayerInfo") t[#t+1] = LoadActor("currentsort") t[#t+1] = LoadActor("currenttime") t[#t+1] = LoadFont("Common Large")..{InitCommand=function(self) - self:xy(5,32):halign(0):valign(1):zoom(0.55):diffuse(getMainColor("positive")):settext("Select Music:") + self:xy(5,32):halign(0):valign(1):zoom(0.55):diffuse(getMainColor("positive")):maxwidth(SCREEN_WIDTH/2-10):settext("Room: "..NSMAN:GetCurrentRoomName()) end} t[#t+1] = LoadActor("../_cursor") t[#t+1] = LoadActor("../_mouseselect") diff --git a/Themes/Til Death/BGAnimations/ScreenNetSelectMusic decorations/default.lua b/Themes/Til Death/BGAnimations/ScreenNetSelectMusic decorations/default.lua index 428e24e5f5..0dcc48905f 100644 --- a/Themes/Til Death/BGAnimations/ScreenNetSelectMusic decorations/default.lua +++ b/Themes/Til Death/BGAnimations/ScreenNetSelectMusic decorations/default.lua @@ -1,5 +1,8 @@ local t = Def.ActorFrame{} - +if NSMAN:IsETTP() then + t[#t+1] = LoadActor("../ScreenSelectMusic decorations/default") + return t +end t[#t+1] = LoadActor("../_chatbox") t[#t+1] = LoadActor("../ScreenSelectMusic decorations/profile") t[#t+1] = LoadActor("../ScreenSelectMusic decorations/msd") diff --git a/Themes/Til Death/BGAnimations/ScreenSelectMusic overlay/default.lua b/Themes/Til Death/BGAnimations/ScreenSelectMusic overlay/default.lua index 58258d072a..be553764f2 100644 --- a/Themes/Til Death/BGAnimations/ScreenSelectMusic overlay/default.lua +++ b/Themes/Til Death/BGAnimations/ScreenSelectMusic overlay/default.lua @@ -18,7 +18,13 @@ return false; end local t = Def.ActorFrame{ - OnCommand=function(self) SCREENMAN:GetTopScreen():AddInputCallback(input) SCREENMAN:GetTopScreen():UsersVisible(false) end; + OnCommand=function(self) + local s = SCREENMAN:GetTopScreen() + s:AddInputCallback(input) + if s:GetName() == "ScreenNetSelectMusic" then + s:UsersVisible(false) + end + end } t[#t+1] = Def.Actor{ diff --git a/Themes/_fallback/BGAnimations/ScreenChatOverlay overlay.lua b/Themes/_fallback/BGAnimations/ScreenChatOverlay overlay.lua index f515d2d650..db835956fa 100644 --- a/Themes/_fallback/BGAnimations/ScreenChatOverlay overlay.lua +++ b/Themes/_fallback/BGAnimations/ScreenChatOverlay overlay.lua @@ -14,6 +14,7 @@ local typing = false local typingText = '' local transparency = 0.5 local curmsgh = 0 +local closeTabSize = 10 local Colors = { background = color("#7777FF"), input = color("#777777"), @@ -38,8 +39,12 @@ function changeTab(tabName, tabType) currentTabName = tabName currentTabType = tabType if not chats[tabType][tabName] then + local i = 1 + local done = false + while not done do + if not tabs[i] then tabs[i] = {tabType, tabName}; done = true; end + end chats[tabType][tabName] = {} - tabs[#tabs+1] = {tabType, tabName} end messages = chats[tabType][tabName] end @@ -169,26 +174,28 @@ chatWindow[#chatWindow+1] = Def.Quad{ MESSAGEMAN:Broadcast("UpdateChatOverlayMsgs") end } -for i = 0, lineNumber-1 do - chatWindow[#chatWindow+1] = LoadColorFont("Common Normal")..{ - Name = "ChatText"..i, - InitCommand = function(self) - self:settext('') - self:halign(0):valign(1) - self:vertspacing(0) - self:zoom(scale) - self:diffuse(color("#000000")) - end, - UpdateChatOverlayMsgsMessageCommand = function(self) - self:settext((i < #messages and messages[#messages-i] ~= nil) and messages[#messages-i] or '') - self:wrapwidthpixels((width-8)/scale) - - self:xy(x+4, y+height*(lineNumber+tabHeight)-4 - i*29/2) - self:croptop((height+y - (self:GetY()-self:GetHeight())) / self:GetHeight()) - curmsgh = curmsgh + (self:GetHeight()+8)/29 +chatWindow[#chatWindow+1] = LoadColorFont("Common Normal")..{ + Name = "ChatText", + InitCommand = function(self) + self:settext('') + self:halign(0):valign(1) + self:vertspacing(0) + self:zoom(scale) + self:SetMaxLines(lineNumber, 0) + self:wrapwidthpixels((width-8)/scale) + end, + UpdateChatOverlayMsgsMessageCommand = function(self) + local t = "" + for i = lineNumber-1,0,-1 do + if messages[#messages-i] then + t = t..messages[#messages-i].."\n" + end end - } -end + self:settext(t) + self:xy(x+4, y+height*(lineNumber+tabHeight)-4) + end +} + local tabWidth = width/maxTabs for i = 0, maxTabs-1 do chatWindow[#chatWindow+1] = Def.ActorFrame{ @@ -226,6 +233,18 @@ for i = 0, maxTabs-1 do end end }, + LoadFont("Common Normal")..{ + InitCommand = function(self) + self:halign(0):valign(0) + self:maxwidth(tabWidth) + self:zoom(scale) + self:diffuse(color("#000000")) + self:xy(x+tabWidth*(i+1)-closeTabSize, y+height*(1+(tabHeight/4))) + end, + UpdateChatOverlayMessageCommand = function(self) + self:settext((tabs[i+1] and tabs[i+1][2]) and "X" or "") + end + }, } end @@ -246,7 +265,7 @@ chatWindow[#chatWindow+1] = LoadFont("Common Normal")..{ self:halign(0):valign(0) self:zoom(scale) self:wrapwidthpixels((width-8)/scale) - self:diffuse(color("#000000")) + self:diffuse(color("#FFFFFF")) end, UpdateChatOverlayMessageCommand = function(self) self:settext(typingText) @@ -264,11 +283,11 @@ function overTab(mx, my) for i = 0, maxTabs-1 do if tabs[i+1] then if mx >= x+tabWidth*i and my>= y+height and mx <= x+tabWidth*(i+1) and my<= y+height*(1+tabHeight) then - return i+1 + return i+1, mx >= x+tabWidth*(i+1)-closeTabSize end end end - return nil + return nil, nil end function input(event) if(not show or not online) then @@ -291,14 +310,31 @@ function input(event) lastx, lasty = x, y update = true else - local tabButton = overTab(mx, my) + local tabButton, closeTab = overTab(mx, my) if not tabButton then mousex, mousey = -1, -1 if typing then update = true end else - changeTab(tabs[tabButton][2], tabs[tabButton][1]) + if not closeTab then + changeTab(tabs[tabButton][2], tabs[tabButton][1]) + else + local tabT = tabs[tabButton][1] + local tabN = tabs[tabButton][2] + if (tabT == 0 and tabN == "") or (tabT == 1 and tabN == NSMAN:GetCurrentRoomName()) then + return false + end + tabs[tabButton] = nil + if chats[tabT][tabN] == messages then + for i = #tabs,1,-1 do + if tabs[i] then + changeTab(tabs[i][2], tabs[i][1]) + end + end + end + chats[tabT][tabN] = {} + end update = true end end @@ -316,6 +352,10 @@ function input(event) end typing = false update = true + elseif event.button == "Back" then + typingText = '' + typing = false + update = true elseif event.DeviceInput.button == "DeviceButton_space" then typingText = typingText .. ' ' update = true @@ -325,10 +365,7 @@ function input(event) elseif event.DeviceInput.button == "DeviceButton_backspace" then typingText = typingText:sub(1, -2) update = true - elseif event.DeviceInput.button == "DeviceButton_=" then - typingText = typingText .. '=' - update = true - elseif event.DeviceInput.button:gsub("DeviceButton_", ''):len() == 1 then + elseif event.char then typingText = typingText .. event.char update = true end @@ -338,7 +375,7 @@ function input(event) end - return update + return update or typing end diff --git a/src/BitmapText.cpp b/src/BitmapText.cpp index 8042fb1cf4..27eb47c9d3 100644 --- a/src/BitmapText.cpp +++ b/src/BitmapText.cpp @@ -958,98 +958,6 @@ void BitmapText::Attribute::FromStack( lua_State *L, int iPos ) lua_settop( L, iTab - 1 ); } -// lua start -#include "FontCharAliases.h" - -/** @brief Allow Lua to have access to the BitmapText. */ -class LunaBitmapText: public Luna -{ -public: - static int wrapwidthpixels( T* p, lua_State *L ) { p->SetWrapWidthPixels( IArg(1) ); COMMON_RETURN_SELF; } -#define MAX_DIMENSION(maxdimension, SetMaxDimension) \ - static int maxdimension( T* p, lua_State *L ) \ - { p->SetMaxDimension(FArg(1)); COMMON_RETURN_SELF; } - MAX_DIMENSION(maxwidth, SetMaxWidth); - MAX_DIMENSION(maxheight, SetMaxHeight); -#undef MAX_DIMENSION - static int max_dimension_use_zoom(T* p, lua_State* L) - { - p->SetMaxDimUseZoom(lua_toboolean(L, 1)); - COMMON_RETURN_SELF; - } - static int vertspacing( T* p, lua_State *L ) { p->SetVertSpacing( IArg(1) ); COMMON_RETURN_SELF; } - static int settext( T* p, lua_State *L ) - { - RString s = SArg(1); - RString sAlt; - /* XXX: Lua strings should simply use "\n" natively. However, some - * settext calls may be made from GetMetric() calls to other strings, and - * it's confusing for :: to work in some strings and not others. - * Eventually, all strings should be Lua expressions, but until then, - * continue to support this. */ - s.Replace("::","\n"); - FontCharAliases::ReplaceMarkers( s ); - - if( lua_gettop(L) > 1 ) - { - sAlt = SArg(2); - sAlt.Replace("::","\n"); - FontCharAliases::ReplaceMarkers( sAlt ); - } - - p->SetText( s, sAlt ); - COMMON_RETURN_SELF; - } - static int rainbowscroll( T* p, lua_State *L ) { p->SetRainbowScroll( BArg(1) ); COMMON_RETURN_SELF; } - static int jitter( T* p, lua_State *L ) { p->SetJitter( BArg(1) ); COMMON_RETURN_SELF; } - static int distort( T* p, lua_State *L) { p->SetDistortion( FArg(1) ); COMMON_RETURN_SELF; } - static int undistort( T* p, lua_State *L) { p->UnSetDistortion(); COMMON_RETURN_SELF; } - GETTER_SETTER_BOOL_METHOD(mult_attrs_with_diffuse); - static int GetText( T* p, lua_State *L ) { lua_pushstring( L, p->GetText() ); return 1; } - static int AddAttribute( T* p, lua_State *L ) - { - size_t iPos = IArg(1); - BitmapText::Attribute attr = p->GetDefaultAttribute(); - - attr.FromStack( L, 2 ); - p->AddAttribute( iPos, attr ); - COMMON_RETURN_SELF; - } - static int ClearAttributes( T* p, lua_State *L ) { p->ClearAttributes(); COMMON_RETURN_SELF; } - static int strokecolor( T* p, lua_State *L ) { RageColor c; c.FromStackCompat( L, 1 ); p->SetStrokeColor( c ); COMMON_RETURN_SELF; } - DEFINE_METHOD(getstrokecolor, GetStrokeColor()); - static int uppercase( T* p, lua_State *L ) { p->SetUppercase( BArg(1) ); COMMON_RETURN_SELF; } - static int textglowmode( T* p, lua_State *L ) { p->SetTextGlowMode( Enum::Check(L, 1) ); COMMON_RETURN_SELF; } - - LunaBitmapText() - { - ADD_METHOD( wrapwidthpixels ); - ADD_METHOD( maxwidth ); - ADD_METHOD( maxheight ); - ADD_METHOD( max_dimension_use_zoom ); - ADD_METHOD( vertspacing ); - ADD_METHOD( settext ); - ADD_METHOD( rainbowscroll ); - ADD_METHOD( jitter ); - ADD_METHOD( distort ); - ADD_METHOD( undistort ); - ADD_GET_SET_METHODS(mult_attrs_with_diffuse); - ADD_METHOD( GetText ); - ADD_METHOD( AddAttribute ); - ADD_METHOD( ClearAttributes ); - ADD_METHOD( strokecolor ); - ADD_METHOD( getstrokecolor ); - ADD_METHOD( uppercase ); - ADD_METHOD( textglowmode ); - //ADD_METHOD( LoadFromFont ); - //ADD_METHOD( LoadFromTextureAndChars ); - } -}; - -LUA_REGISTER_DERIVED_CLASS( BitmapText, Actor ) - -// lua end - /** ColorBitmapText ***********************************************************/ void ColorBitmapText::SetText(const RString& _sText, const RString& _sAlternateText, int iWrapWidthPixels) @@ -1473,6 +1381,112 @@ void ColorBitmapText::SetMaxLines(int iNumLines, int iDirection) } +// lua start +#include "FontCharAliases.h" + +/** @brief Allow Lua to have access to the BitmapText. */ +class LunaBitmapText : public Luna +{ +public: + static int wrapwidthpixels(T* p, lua_State *L) { p->SetWrapWidthPixels(IArg(1)); COMMON_RETURN_SELF; } +#define MAX_DIMENSION(maxdimension, SetMaxDimension) \ + static int maxdimension( T* p, lua_State *L ) \ + { p->SetMaxDimension(FArg(1)); COMMON_RETURN_SELF; } + MAX_DIMENSION(maxwidth, SetMaxWidth); + MAX_DIMENSION(maxheight, SetMaxHeight); +#undef MAX_DIMENSION + static int max_dimension_use_zoom(T* p, lua_State* L) + { + p->SetMaxDimUseZoom(lua_toboolean(L, 1)); + COMMON_RETURN_SELF; + } + static int vertspacing(T* p, lua_State *L) { p->SetVertSpacing(IArg(1)); COMMON_RETURN_SELF; } + static int settext(T* p, lua_State *L) + { + RString s = SArg(1); + RString sAlt; + /* XXX: Lua strings should simply use "\n" natively. However, some + * settext calls may be made from GetMetric() calls to other strings, and + * it's confusing for :: to work in some strings and not others. + * Eventually, all strings should be Lua expressions, but until then, + * continue to support this. */ + s.Replace("::", "\n"); + FontCharAliases::ReplaceMarkers(s); + + if (lua_gettop(L) > 1) + { + sAlt = SArg(2); + sAlt.Replace("::", "\n"); + FontCharAliases::ReplaceMarkers(sAlt); + } + + p->SetText(s, sAlt); + COMMON_RETURN_SELF; + } + static int rainbowscroll(T* p, lua_State *L) { p->SetRainbowScroll(BArg(1)); COMMON_RETURN_SELF; } + static int jitter(T* p, lua_State *L) { p->SetJitter(BArg(1)); COMMON_RETURN_SELF; } + static int distort(T* p, lua_State *L) { p->SetDistortion(FArg(1)); COMMON_RETURN_SELF; } + static int undistort(T* p, lua_State *L) { p->UnSetDistortion(); COMMON_RETURN_SELF; } + GETTER_SETTER_BOOL_METHOD(mult_attrs_with_diffuse); + static int GetText(T* p, lua_State *L) { lua_pushstring(L, p->GetText()); return 1; } + static int AddAttribute(T* p, lua_State *L) + { + size_t iPos = IArg(1); + BitmapText::Attribute attr = p->GetDefaultAttribute(); + + attr.FromStack(L, 2); + p->AddAttribute(iPos, attr); + COMMON_RETURN_SELF; + } + static int ClearAttributes(T* p, lua_State *L) { p->ClearAttributes(); COMMON_RETURN_SELF; } + static int strokecolor(T* p, lua_State *L) { RageColor c; c.FromStackCompat(L, 1); p->SetStrokeColor(c); COMMON_RETURN_SELF; } + DEFINE_METHOD(getstrokecolor, GetStrokeColor()); + static int uppercase(T* p, lua_State *L) { p->SetUppercase(BArg(1)); COMMON_RETURN_SELF; } + static int textglowmode(T* p, lua_State *L) { p->SetTextGlowMode(Enum::Check(L, 1)); COMMON_RETURN_SELF; } + + LunaBitmapText() + { + ADD_METHOD(wrapwidthpixels); + ADD_METHOD(maxwidth); + ADD_METHOD(maxheight); + ADD_METHOD(max_dimension_use_zoom); + ADD_METHOD(vertspacing); + ADD_METHOD(settext); + ADD_METHOD(rainbowscroll); + ADD_METHOD(jitter); + ADD_METHOD(distort); + ADD_METHOD(undistort); + ADD_GET_SET_METHODS(mult_attrs_with_diffuse); + ADD_METHOD(GetText); + ADD_METHOD(AddAttribute); + ADD_METHOD(ClearAttributes); + ADD_METHOD(strokecolor); + ADD_METHOD(getstrokecolor); + ADD_METHOD(uppercase); + ADD_METHOD(textglowmode); + //ADD_METHOD( LoadFromFont ); + //ADD_METHOD( LoadFromTextureAndChars ); + } +}; + +LUA_REGISTER_DERIVED_CLASS(BitmapText, Actor) + + +class LunaColorBitmapText : public Luna +{ +public: + static int SetMaxLines(T* p, lua_State *L) { + p->SetMaxLines(IArg(1), lua_isnil(L, 2) ? 0 : IArg(2)); + return 1; + } + LunaColorBitmapText() + { + ADD_METHOD(SetMaxLines); + } +}; +LUA_REGISTER_DERIVED_CLASS(ColorBitmapText, BitmapText) +// lua end + /* * (c) 2003-2007 Chris Danford, Charles Lohr, Steve Checkoway * All rights reserved. diff --git a/src/BitmapText.h b/src/BitmapText.h index 51a1c09bf0..c0e6e07793 100644 --- a/src/BitmapText.h +++ b/src/BitmapText.h @@ -161,6 +161,7 @@ class ColorBitmapText : public BitmapText void SetMaxLines(int iLines, bool bCutBottom = true); //if bCutBottom = false then, it will crop the top void SimpleAddLine(const RString &sAddition, int iWidthPixels); void SetMaxLines(int iNumLines, int iDirection); + void PushSelf(lua_State *L) override; protected: struct ColorChange { diff --git a/src/NetworkSyncManager.cpp b/src/NetworkSyncManager.cpp index ec2c0a7573..405bdee17b 100644 --- a/src/NetworkSyncManager.cpp +++ b/src/NetworkSyncManager.cpp @@ -1083,6 +1083,8 @@ void ETTProtocol::LeaveRoom(NetworkSyncManager* n) leaveRoom["type"] = ettClientMessageMap[ettpc_leaveroom]; leaveRoom["id"] = msgId++; Send(leaveRoom.dump().c_str()); + roomName = ""; + roomDesc = ""; } void ETTProtocol::EnterRoom(RString name, RString password) { @@ -2172,6 +2174,10 @@ class LunaNetworkSyncManager : public Luna lua_pushstring(L,p->chat[{tabName, tabType}][l].c_str()); return 1; } + static int GetCurrentRoomName(T* p, lua_State *L) { + lua_pushstring(L, p->IsETTP() ? p->ETTP.roomName.c_str() : ""); + return 1; + } static int SendChatMsg(T* p, lua_State *L) { string msg = SArg(1); int tabType = IArg(2); @@ -2195,6 +2201,7 @@ class LunaNetworkSyncManager : public Luna ADD_METHOD(Login); ADD_METHOD(Logout); ADD_METHOD(IsETTP); + ADD_METHOD(GetCurrentRoomName); } }; diff --git a/src/Screen.cpp b/src/Screen.cpp index 701b26b00d..3998849bfd 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -189,19 +189,20 @@ bool Screen::Input( const InputEventPlus &input ) default: return false; // don't care } - - // Always broadcast mouse input so themers can grab it. -aj - if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_LEFT ) ) - MESSAGEMAN->Broadcast( (MessageID)(Message_LeftClick) ); - if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_RIGHT ) ) - MESSAGEMAN->Broadcast( (MessageID)(Message_RightClick) ); - if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_MIDDLE ) ) - MESSAGEMAN->Broadcast( (MessageID)(Message_MiddleClick) ); - // Can't do MouseWheelUp and MouseWheelDown at the same time. -aj - if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_WHEELUP ) ) - MESSAGEMAN->Broadcast( (MessageID)(Message_MouseWheelUp) ); - else if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_WHEELDOWN ) ) - MESSAGEMAN->Broadcast( (MessageID)(Message_MouseWheelDown) ); + if (input.type == IET_FIRST_PRESS) { + // Always broadcast mouse input so themers can grab it. -aj + if (input.DeviceI == DeviceInput(DEVICE_MOUSE, MOUSE_LEFT)) + MESSAGEMAN->Broadcast((MessageID)(Message_LeftClick)); + if (input.DeviceI == DeviceInput(DEVICE_MOUSE, MOUSE_RIGHT)) + MESSAGEMAN->Broadcast((MessageID)(Message_RightClick)); + if (input.DeviceI == DeviceInput(DEVICE_MOUSE, MOUSE_MIDDLE)) + MESSAGEMAN->Broadcast((MessageID)(Message_MiddleClick)); + // Can't do MouseWheelUp and MouseWheelDown at the same time. -aj + if (input.DeviceI == DeviceInput(DEVICE_MOUSE, MOUSE_WHEELUP)) + MESSAGEMAN->Broadcast((MessageID)(Message_MouseWheelUp)); + else if (input.DeviceI == DeviceInput(DEVICE_MOUSE, MOUSE_WHEELDOWN)) + MESSAGEMAN->Broadcast((MessageID)(Message_MouseWheelDown)); + } // default input handler used by most menus switch( input.MenuI ) diff --git a/src/ScreenSMOnlineLogin.cpp b/src/ScreenSMOnlineLogin.cpp index 49ff59210e..7a79edd703 100644 --- a/src/ScreenSMOnlineLogin.cpp +++ b/src/ScreenSMOnlineLogin.cpp @@ -17,9 +17,10 @@ REGISTER_SCREEN_CLASS(ScreenSMOnlineLogin); -AutoScreenMessage( SM_SMOnlinePack ); -AutoScreenMessage( SM_PasswordDone ); -AutoScreenMessage( SM_NoProfilesDefined ); +AutoScreenMessage(SM_SMOnlinePack); +AutoScreenMessage(SM_PasswordDone); +AutoScreenMessage(SM_UsernameDone); +AutoScreenMessage(SM_NoProfilesDefined); AutoScreenMessage(ETTP_Disconnect); AutoScreenMessage(ETTP_LoginResponse); @@ -43,7 +44,7 @@ void ScreenSMOnlineLogin::Init() pHand->m_Def.m_vEnabledForPlayers.insert( pn ); PROFILEMAN->GetLocalProfileDisplayNames( pHand->m_Def.m_vsChoices ); - + pHand->m_Def.m_vsChoices.emplace_back("Type Username"); if( pHand->m_Def.m_vsChoices.empty() ) { // Give myself a message so that I can bail out later @@ -88,8 +89,15 @@ void ScreenSMOnlineLogin::ExportOptions( int iRow, const vector &v vector vsProfiles; PROFILEMAN->GetLocalProfileIDs( vsProfiles ); - FOREACH_EnabledPlayer( pn ) - ProfileManager::m_sDefaultLocalProfileID[pn].Set( vsProfiles[m_pRows[0]->GetOneSelection(pn)] ); + FOREACH_EnabledPlayer(pn) { + auto selection = m_pRows[0]->GetOneSelection(pn); + if (selection < m_pRows[0]->GetHandler()->m_Def.m_vsChoices.size() - 1) { + ProfileManager::m_sDefaultLocalProfileID[pn].Set(vsProfiles[selection]); + typeUsername = false; + } + else + typeUsername = true; + } } break; } @@ -107,17 +115,28 @@ void ScreenSMOnlineLogin::HandleScreenMessage(const ScreenMessage SM) if( SM == SM_PasswordDone ) { if(!ScreenTextEntry::s_bCancelledLast) - SendLogin(ScreenTextEntry::s_sLastAnswer); + if(typeUsername) + SendLogin(ScreenTextEntry::s_sLastAnswer, username); + else + SendLogin(ScreenTextEntry::s_sLastAnswer); else SCREENMAN->PostMessageToTopScreen( SM_GoToPrevScreen, 0 ); } + else if (SM == SM_UsernameDone) + { + username = ScreenTextEntry::s_sLastAnswer.c_str(); + sLoginQuestion = YOU_ARE_LOGGING_ON_AS.GetValue() + "\n" + + GAMESTATE->GetPlayerDisplayName((PlayerNumber)m_iPlayer) + "\n" + + ENTER_YOUR_PASSWORD.GetValue(); + ScreenTextEntry::Password(SM_PasswordDone, NSMAN->loginResponse + "\n\n" + sLoginQuestion, NULL); + } else if( SM == SM_NoProfilesDefined ) { SCREENMAN->SystemMessage(DEFINE_A_PROFILE); SCREENMAN->SetNewScreen("ScreenOptionsManageProfiles"); } else if (SM == ETTP_Disconnect) { - + Cancel(SM_GoToPrevScreen); } else if (SM == ETTP_LoginResponse) { if (NSMAN->loggedIn) { @@ -125,10 +144,16 @@ void ScreenSMOnlineLogin::HandleScreenMessage(const ScreenMessage SM) m_iPlayer = 0; } else { - sLoginQuestion = YOU_ARE_LOGGING_ON_AS.GetValue() + "\n" - + GAMESTATE->GetPlayerDisplayName((PlayerNumber)m_iPlayer) + "\n" + - ENTER_YOUR_PASSWORD.GetValue(); - ScreenTextEntry::Password(SM_PasswordDone, NSMAN->loginResponse + "\n\n" + sLoginQuestion, NULL); + if (!typeUsername) { + sLoginQuestion = YOU_ARE_LOGGING_ON_AS.GetValue() + "\n" + + GAMESTATE->GetPlayerDisplayName((PlayerNumber)m_iPlayer) + "\n" + + ENTER_YOUR_PASSWORD.GetValue(); + ScreenTextEntry::Password(SM_PasswordDone, NSMAN->loginResponse + "\n\n" + sLoginQuestion, NULL); + } + else { + sLoginQuestion = "Enter username"; + ScreenTextEntry::Password(SM_UsernameDone, NSMAN->loginResponse + "\n\n" + sLoginQuestion, NULL); + } } } else if( SM == SM_SMOnlinePack ) @@ -182,11 +207,17 @@ void ScreenSMOnlineLogin::HandleScreenMessage(const ScreenMessage SM) } else { - m_iPlayer=0; - while(!GAMESTATE->IsPlayerEnabled((PlayerNumber) m_iPlayer)) - ++m_iPlayer; - sLoginQuestion = YOU_ARE_LOGGING_ON_AS.GetValue() + "\n" + GAMESTATE->GetPlayerDisplayName((PlayerNumber) m_iPlayer) + "\n" + ENTER_YOUR_PASSWORD.GetValue(); - ScreenTextEntry::Password(SM_PasswordDone, sLoginQuestion, NULL ); + if (!typeUsername) { + m_iPlayer = 0; + while (!GAMESTATE->IsPlayerEnabled((PlayerNumber)m_iPlayer)) + ++m_iPlayer; + sLoginQuestion = YOU_ARE_LOGGING_ON_AS.GetValue() + "\n" + GAMESTATE->GetPlayerDisplayName((PlayerNumber)m_iPlayer) + "\n" + ENTER_YOUR_PASSWORD.GetValue(); + ScreenTextEntry::Password(SM_PasswordDone, sLoginQuestion, NULL); + } + else { + sLoginQuestion = "Enter username"; + ScreenTextEntry::Password(SM_UsernameDone, NSMAN->loginResponse + "\n\n" + sLoginQuestion, NULL); + } } return; } @@ -211,9 +242,13 @@ RString ScreenSMOnlineLogin::GetSelectedProfileID() return vsProfiles[ Selection-1 ]; } -void ScreenSMOnlineLogin::SendLogin( RString sPassword ) +void ScreenSMOnlineLogin::SendLogin(RString sPassword) +{ + SendLogin(sPassword, GAMESTATE->GetPlayerDisplayName((PlayerNumber)this->m_iPlayer)); +} +void ScreenSMOnlineLogin::SendLogin( RString sPassword, RString user) { - NSMAN->Login(GAMESTATE->GetPlayerDisplayName((PlayerNumber)m_iPlayer), sPassword); + NSMAN->Login(user, sPassword); } #endif diff --git a/src/ScreenSMOnlineLogin.h b/src/ScreenSMOnlineLogin.h index 6f59845101..373670adbc 100644 --- a/src/ScreenSMOnlineLogin.h +++ b/src/ScreenSMOnlineLogin.h @@ -9,13 +9,16 @@ class ScreenSMOnlineLogin : public ScreenOptions void Init() override; void HandleScreenMessage(const ScreenMessage SM) override; bool MenuStart( const InputEventPlus &input ) override; - void SendLogin( RString sPassword ); + void SendLogin(RString sPassword); + void SendLogin( RString sPassword, RString user); private: void ImportOptions( int iRow, const vector &vpns ) override; void ExportOptions( int iRow, const vector &vpns ) override; RString GetSelectedProfileID(); int m_iPlayer; + bool typeUsername{ false }; + string username; }; #endif