Ejemplo n.º 1
0
        public MenuUserIcon(PPDDevice device, PPDFramework.Resource.ResourceManager resourceManager, UserListComponent listComponent, User user) : base(device)
        {
            this.resourceManager = resourceManager;
            this.listComponent   = listComponent;
            User = user;

            this.AddChild((leaderIcon = new PictureObject(device, resourceManager, Utility.Path.Combine("leader.png"))));
            this.AddChild((userIcon = new PictureObject(device, resourceManager, PathObject.Absolute(currentUserIconPath), true)
            {
                Position = new SharpDX.Vector2(21, 21)
            }));
            this.AddChild((userNameString = new TextureString(device, "", 15, 140, PPDColors.White)
            {
                Position = new SharpDX.Vector2(42, 3)
            }));
            this.AddChild((accountIdString = new TextureString(device, "", 15, 140, PPDColors.White)
            {
                Position = new SharpDX.Vector2(42, 3)
            }));
            this.AddChild((readyIcon = new PictureObject(device, resourceManager, Utility.Path.Combine("user_state_ready.png"), true)
            {
                Position = new SharpDX.Vector2(187, 30)
            }));
            this.AddChild((notReadyIcon = new PictureObject(device, resourceManager, Utility.Path.Combine("user_state_notready.png"), true)
            {
                Position = new SharpDX.Vector2(187, 30)
            }));
            this.AddChild((playingIcon = new PictureObject(device, resourceManager, Utility.Path.Combine("user_state_playing.png"), true)
            {
                Position = new SharpDX.Vector2(187, 30)
            }));
            this.AddChild((watchIcon = new PictureObject(device, resourceManager, Utility.Path.Combine("user_state_watch.png"), true)
            {
                Position = new SharpDX.Vector2(187, 30)
            }));
            this.AddChild(hasSongIcon = new PictureObject(device, resourceManager, Utility.Path.Combine("hassong.png"), true)
            {
                Position = new SharpDX.Vector2(165, 30)
            });
            pingPictures = new PictureObject[5];
            for (int i = 0; i < 5; i++)
            {
                pingPictures[i] = new PictureObject(device, resourceManager, Utility.Path.Combine(String.Format("ping_{0}.png", i)))
                {
                    Position = new SharpDX.Vector2(42, 22)
                };
                this.AddChild(pingPictures[i]);
            }
            this.AddChild(pingString = new TextureString(device, "0", 12, PPDColors.White)
            {
                Position = new SharpDX.Vector2(60, 24)
            });
            this.AddChild(new PictureObject(device, resourceManager, Utility.Path.Combine("user_back.png")));

            AddBinding(new Binding(user, "Name", this, "UserName"));
            AddBinding(new Binding(user, "AccountId", this, "AccountId"));
            AddBinding(new Binding(user, "ImagePath", this, "UserImagePath"));
            AddBinding(new Binding(user, "CurrentState", this, "UserState"));
            AddBinding(new Binding(user, "HasSong", this, "HasSong"));
            AddBinding(new Binding(user, "Ping", this, "Ping"));
            AddBinding(new Binding(user, "IsLeader", this, "IsLeader"));

            ChangeUserIconScale();
        }
Ejemplo n.º 2
0
        public override bool Load()
        {
            PPDFramework.Web.WebModInfo[] webMods = null;
            Action[] actions =
            {
                () => { webMods = PPDFramework.Web.WebManager.Instance.GetMods(); },
                PPDScoreManager.Manager.Initialize,
            };
            Parallel.ForEach(actions, (action) => action());
            allowedModList = new AllowedModList
            {
                WebMods = webMods
            };

            logger = new Logger(String.Format("{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")));
            Sound.AddSound(notifySoundPath);

            version = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(this.GetType()).Location).FileVersion;

            userList              = new ChangableList <User>();
            userList.ItemChanged += userList_ItemChanged;

            movieManager = new MovieManager(device, GameHost);
            movieManager.MovieChanged      += MovieManager_MovieChanged;
            movieManager.MovieChangeFailed += MovieManager_MovieChangeFailed;

            clientHandledData = new Queue <NetworkData>();

            selfUser = new User
            {
                Name         = PPDFramework.Web.WebManager.Instance.CurrentUserName,
                AccountId    = PPDFramework.Web.WebManager.Instance.CurrentAccountId,
                CurrentState = UserState.NotReady,
                Color        = RandomColorGenerator.GetColor(),
                IsSelf       = true,
                IsHost       = (bool)this.Param["AsHost"]
            };

            this.AddChild(gameResultComponent = new GameResultComponent(device, GameHost, ResourceManager, Sound));
            this.AddChild(leftMenu            = new LeftMenu(device, GameHost, ResourceManager, Sound, movieManager, selfUser, userList, allowedModList));
            leftMenu.SongSelected            += leftMenu_SongSelected;
            leftMenu.ShowResult    += leftMenu_ShowResult;
            leftMenu.UpdateScoreDB += leftMenu_UpdateScoreDB;
            leftMenu.RuleChanged   += leftMenu_RuleChanged;
            leftMenu.TryToPlayGame += leftMenu_TryToPlayGame;
            leftMenu.ChangeLeader  += leftMenu_ChangeLeader;
            leftMenu.KickUser      += leftMenu_KickUser;
            this.AddChild(textBox   = new DxTextBox(device, GameHost, ResourceManager));

            this.AddChild((chatComponent = new ChatComponent(device, ResourceManager, GameHost)
            {
                Position = new SharpDX.Vector2(430, 0)
            }));
            this.AddChild(userListComponent = new UserListComponent(device, ResourceManager)
            {
                Position = new SharpDX.Vector2(10, 10)
            });

            PictureObject bottom;

            this.AddChild(bottom = new PictureObject(device, ResourceManager, Utility.Path.Combine("menu_bottom.png"))
            {
                Position = new SharpDX.Vector2(0, 421)
            });
            bottom.AddChild(new PictureObject(device, ResourceManager, Utility.Path.Combine("bottom_triangle.png"))
            {
                Position = new SharpDX.Vector2(7, 7)
            });
            bottom.AddChild(new TextureString(device, Utility.Language["Menu"], 16, PPDColors.White)
            {
                Position = new SharpDX.Vector2(30, 5)
            });
            bottom.AddChild(new PictureObject(device, ResourceManager, Utility.Path.Combine("bottom_circle.png"))
            {
                Position = new SharpDX.Vector2(157, 7)
            });
            bottom.AddChild(stateString = new TextureString(device, Utility.Language["ChangeReadyState"], 16, PPDColors.White)
            {
                Position = new SharpDX.Vector2(180, 5)
            });

            this.AddChild((bgd = new BackGroundDisplay(device, ResourceManager, "skins\\PPDMulti_BackGround.xml", "Menu")));

            focusManager = new FocusManager();
            focusManager.Focus(chatComponent);

            userList.Add(selfUser);

            chatComponent.Inputed += chatComponent_Inputed;
            textBox.LostFocused   += textBox_LostFocused;
            leftMenu.Closed       += leftMenu_Closed;

            if (selfUser.IsHost)
            {
                WebManager webManager = null;
                if (this.Param.ContainsKey("WebManager"))
                {
                    webManager = this.Param["WebManager"] as WebManager;
                }
                RoomInfo roomInfo = null;
                if (this.Param.ContainsKey("RoomInfo"))
                {
                    roomInfo = this.Param["RoomInfo"] as RoomInfo;
                }
                server = new PPDServer((int)Param["Port"], webManager, roomInfo, GameHost);
                server.FailedToCreateRoom += server_FailedToCreateRoom;
                client = new Client
                {
                    Address = "127.0.0.1",
                    Port    = (int)Param["Port"]
                };
                timer = new Timer(state =>
                {
                    server.Update();
                }, null, 0, 1);
            }
            else
            {
                client = new Client
                {
                    Address = (string)Param["IP"],
                    Port    = (int)Param["Port"]
                };
            }

            client.Closed         += client_Closed;
            client.Read           += client_Read;
            byteReader             = new TcpByteReader();
            byteReader.ByteReaded += TcpByteReader_ByteReaded;

            if (server != null)
            {
                server.Start();
            }
            client.Start();

            if (client.HasConnection)
            {
                // send login data
                client.Write(MessagePackSerializer.Serialize(new AddUserNetworkData
                {
                    UserName  = selfUser.Name,
                    AccountId = selfUser.AccountId,
                    State     = selfUser.CurrentState,
                    Version   = version
                }));
            }
            else
            {
                chatComponent.AddSystemMessage(Utility.Language["CannotConnectToHost"]);
            }

            // load
            SongInformation.All.ToArray();
            return(true);
        }