public TitleWorld( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ISkin skin) : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin) { this.Title = this.AssetManager.Get<LanguageAsset>("language.TYCHAIA"); this.AddMenuItem( this.AssetManager.Get<LanguageAsset>("language.SINGLEPLAYER"), () => { this.TargetWorld = this.GameContext.CreateWorld<IWorldFactory>(x => x.CreateConnectWorld(true, GetLANIPAddress(), 9091)); }); this.AddMenuItem( this.AssetManager.Get<LanguageAsset>("language.MULTIPLAYER"), () => { this.TargetWorld = this.GameContext.CreateWorld<IWorldFactory>(x => x.CreateMultiplayerWorld()); }); this.AddMenuItem( this.AssetManager.Get<LanguageAsset>("language.EXIT"), () => { if (this.GameContext != null) this.GameContext.Game.Exit(); }); }
/// <summary> /// The update. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <param name="gameTime"> /// The game time. /// </param> /// <param name="stealFocus"> /// The steal focus. /// </param> public override void Update(ISkin skin, Rectangle layout, GameTime gameTime, ref bool stealFocus) { foreach (var kv in this.GetChildLocations(skin, layout)) { kv.Key.Update(skin, kv.Value, gameTime, ref stealFocus); } }
public InventoryUIEntity( IGameUIFactory gameUIFactory, IViewportMode viewportMode, ISkin skin) : base(skin) { this.m_ViewportMode = viewportMode; this.SidebarWidth = 300; this.m_InventoryManager = gameUIFactory.CreateInventoryManager(); this.m_SplitHorizontal = new HorizontalContainer(); this.m_LeftBar = gameUIFactory.CreateLeftBar(); this.m_CentreContainer = new VerticalContainer(); this.m_RightBar = gameUIFactory.CreateRightBar(); this.m_StatusBarSpacing = new HorizontalContainer(); this.m_StatusBar = gameUIFactory.CreateStatusBar(); this.m_RightBar.SetChild(this.m_InventoryManager); this.m_SplitHorizontal.AddChild(this.m_LeftBar, "0"); this.m_SplitHorizontal.AddChild(this.m_CentreContainer, "*"); this.m_SplitHorizontal.AddChild(this.m_RightBar, "0"); this.m_StatusBarSpacing.AddChild(new EmptyContainer(), "*"); this.m_StatusBarSpacing.AddChild(this.m_StatusBar, "640"); this.m_StatusBarSpacing.AddChild(new EmptyContainer(), "*"); this.m_CentreContainer.AddChild(new EmptyContainer(), "*"); this.m_CentreContainer.AddChild(this.m_StatusBarSpacing, "64"); this.Canvas = new Canvas(); this.Canvas.SetChild(this.m_SplitHorizontal); }
/// <summary> /// The draw. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> public void Draw(IRenderContext context, ISkin skin, Rectangle layout) { skin.DrawFixedContainer(context, layout, this); if (this.Child != null) { this.Child.Draw(context, skin, this.AbsoluteRectangle); } }
/// <summary> /// The draw. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> public override void Draw(IRenderContext context, ISkin skin, Rectangle layout) { skin.DrawHorizontalContainer(context, layout, this); foreach (var kv in this.ChildrenWithLayouts(layout).OrderByDescending(x => x.Key.Order)) { kv.Key.Draw(context, skin, kv.Value); } }
/// <summary> /// The draw. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> public override void Draw(IRenderContext context, ISkin skin, Rectangle layout) { skin.DrawMainMenu(context, layout, this); foreach (var kv in this.GetChildLocations(skin, layout)) { kv.Key.Draw(context, skin, kv.Value); } }
public MenuWorld(ISkin skin, IWorldFactory worldFactory, IAssetManagerProvider assetManagerProvider, I2DRenderUtilities twodRenderUtilities) { this.m_2DRenderUtilities = twodRenderUtilities; this.m_LogoTexture = assetManagerProvider.GetAssetManager().Get<TextureAsset>("texture.Logo"); this.m_WorldFactory = worldFactory; this.Entities = new List<IEntity>(); var startServer = new Button(); startServer.Text = "Start Server"; startServer.Click += (sender, e) => { this.m_LastGameContext.SwitchWorld<IWorldFactory>( x => x.CreateLobbyWorld(false, IPAddress.Any)); }; var ipAddressTextBox = new TextBox(); var joinGame = new Button(); joinGame.Text = "Join Game"; joinGame.Click += (sender, e) => { this.m_LastGameContext.SwitchWorld<IWorldFactory>( x => x.CreateLobbyWorld(true, IPAddress.Parse(ipAddressTextBox.Text))); }; var exitGame = new Button(); exitGame.Text = "Exit Game"; exitGame.Click += (sender, e) => { this.m_LastGameContext.Game.Exit(); }; var vertical = new VerticalContainer(); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(new Label { Text = "Perspective" }, "25"); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(startServer, "25"); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(new Label { Text = "Server IP address:" }, "20"); vertical.AddChild(ipAddressTextBox, "20"); vertical.AddChild(joinGame, "25"); vertical.AddChild(new EmptyContainer(), "*"); vertical.AddChild(exitGame, "25"); vertical.AddChild(new EmptyContainer(), "*"); var horizontal = new HorizontalContainer(); horizontal.AddChild(new EmptyContainer(), "*"); horizontal.AddChild(vertical, "250"); horizontal.AddChild(new EmptyContainer(), "*"); var canvas = new Canvas(); canvas.SetChild(horizontal); this.Entities.Add(new CanvasEntity(skin, canvas)); }
/// <summary> /// Requests that the UI container handle the specified event or return false. /// </summary> /// <param name="skin"> /// The UI skin. /// </param> /// <param name="layout"> /// The layout for the element. /// </param> /// <param name="context"> /// The current game context. /// </param> /// <param name="event"> /// The event that was raised. /// </param> /// <returns> /// Whether or not this UI element handled the event. /// </returns> public bool HandleEvent(ISkin skin, Rectangle layout, IGameContext context, Event @event) { if (this.Child != null) { return this.Child.HandleEvent(skin, this.AbsoluteRectangle, context, @event); } return false; }
public void Draw(IRenderContext context, ISkin skin, Rectangle layout) { if (context.Is3DContext) return; this.m_2DRenderUtilities.RenderRectangle( context, layout, Color.Yellow, filled: true); }
protected void CreateSkinTest(SkinInfo gameCurrentSkin, Func <ISkin> getBeatmapSkin) { CreateTest(() => { AddStep("setup skins", () => { skinManager.CurrentSkinInfo.Value = gameCurrentSkin.ToLiveUnmanaged(); currentBeatmapSkin = getBeatmapSkin(); }); }); }
private Drawable setupSkinHierarchy(Drawable child, ISkin skin) { var legacySkinProvider = new SkinProvidingContainer(skins.GetSkin(DefaultLegacySkin.Info)); var testSkinProvider = new SkinProvidingContainer(skin); var legacySkinTransformer = new SkinProvidingContainer(new CatchLegacySkinTransformer(testSkinProvider)); return(legacySkinProvider .WithChild(testSkinProvider .WithChild(legacySkinTransformer .WithChild(child)))); }
private static Texture getAnimationFrame(ISkin skin, TaikoMascotAnimationState state, int frameIndex) { var texture = skin.GetTexture($"pippidon{state.ToString().ToLower()}{frameIndex}"); if (frameIndex == 0 && texture == null) { texture = skin.GetTexture($"pippidon{state.ToString().ToLower()}"); } return(texture); }
/// <summary> /// Requests that the UI container handle the specified event or return false. /// </summary> /// <param name="skin"> /// The UI skin. /// </param> /// <param name="layout"> /// The layout for the element. /// </param> /// <param name="context"> /// The current game context. /// </param> /// <param name="event"> /// The event that was raised. /// </param> /// <returns> /// Whether or not this UI element handled the event. /// </returns> public bool HandleEvent(ISkin skin, Rectangle layout, IGameContext context, Event @event) { foreach (var kv in this.ChildrenWithLayouts(layout)) { if (kv.Key.HandleEvent(skin, kv.Value, context, @event)) { return(true); } } return(false); }
public ManiaLegacySkinTransformer(ISkin skin, IBeatmap beatmap) : base(skin) { this.beatmap = (ManiaBeatmap)beatmap; isLegacySkin = new Lazy <bool>(() => GetConfig <SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version) != null); hasKeyTexture = new Lazy <bool>(() => { string keyImage = this.GetManiaSkinConfig <string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value ?? "mania-key1"; return(this.GetAnimation(keyImage, true, true) != null); }); }
/// <summary> /// The update. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <param name="gameTime"> /// The game time. /// </param> /// <param name="stealFocus"> /// The steal focus. /// </param> public void Update(ISkin skin, Rectangle layout, GameTime gameTime, ref bool stealFocus) { if (this.m_Child != null) { this.m_Child.Update(skin, layout, gameTime, ref stealFocus); } if (this.Modal) { stealFocus = true; } }
public EditorBeatmap(IBeatmap playableBeatmap, ISkin beatmapSkin = null) { PlayableBeatmap = playableBeatmap; BeatmapSkin = beatmapSkin; beatmapProcessor = playableBeatmap.BeatmapInfo.Ruleset?.CreateInstance().CreateBeatmapProcessor(PlayableBeatmap); foreach (var obj in HitObjects) { trackStartTime(obj); } }
/// <summary> /// Creates a new <see cref="LegacyBeatmapEncoder"/>. /// </summary> /// <param name="beatmap">The beatmap to encode.</param> /// <param name="skin">The beatmap's skin, used for encoding combo colours.</param> public LegacyBeatmapEncoder(IBeatmap beatmap, [CanBeNull] ISkin skin) { this.beatmap = beatmap; this.skin = skin; onlineRulesetID = beatmap.BeatmapInfo.Ruleset.OnlineID; if (onlineRulesetID < 0 || onlineRulesetID > 3) { throw new ArgumentException("Only beatmaps in the osu, taiko, catch, or mania rulesets can be encoded to the legacy beatmap format.", nameof(beatmap)); } }
public TvControl(ISkin skin, IViewport viewport, TState initialState, string name = null) { _component = new TvComponent <TState>(initialState, name ?? $"TvControl_<$>"); Metadata = new TvControlMetadata(this, _component.ComponentId); var typename = GetType().Name.ToLowerInvariant(); var genericIdx = typename.IndexOf('`'); ControlType = genericIdx != -1 ? typename.Substring(0, genericIdx) : typename; CurrentStyle = skin.GetControlStyle(this); State = initialState; _component.AddViewport(viewport); AddElements(); }
public RulesetSkinProvidingContainer(Ruleset ruleset, IBeatmap beatmap, [CanBeNull] ISkin beatmapSkin) { Ruleset = ruleset; Beatmap = beatmap; InternalChild = new BeatmapSkinProvidingContainer(beatmapSkin is LegacySkin ? GetLegacyRulesetTransformedSkin(beatmapSkin) : beatmapSkin) { Child = Content = new Container { RelativeSizeAxes = Axes.Both, } }; }
public override void Draw(IRenderContext context, ISkin skin, Rectangle layout) { if (!context.Is3DContext) { this.m_2DRenderUtilities.RenderRectangle( context, layout, Color.Green, filled: true); } base.Draw(context, skin, layout); }
public Visualizer(ISkin actualSkin, AudioPlayer player, PlayerProperties properties) { this.actualSkin = actualSkin; this.player = player; this.properties = properties; player.actualSkin = this.actualSkin; player.properties = this.properties; player.playerStarted += Messenger; player.songListChanged += Messenger; player.songStarted += Messenger; player.properties.playerLocked += Messenger; player.properties.volumeChanged += Messenger; }
/// <summary> /// The draw. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> public void Draw(IRenderContext context, ISkin skin, Rectangle layout) { skin.DrawForm(context, layout, this); foreach (var kv in this.LabelsWithLayouts(layout)) { kv.Key.Draw(context, skin, kv.Value); } foreach (var kv in this.ChildrenWithLayouts(layout)) { kv.Key.Draw(context, skin, kv.Value); } }
public virtual void Delete(long id) { ISkin skin = skinService.GetById(id, ctx.owner.obj.Id); if (skin == null) { echoRedirect(lang("exDataNotFound")); return; } skinService.Delete(skin); redirect(My); }
public SkinProvidingContainer(ISkin skin) { this.skin = skin; RelativeSizeAxes = Axes.Both; noFallbackLookupProxy = new NoFallbackProxy(this); if (skin is ISkinSource source) { source.SourceChanged += TriggerSourceChanged; } }
public void Update(ISkin skin, Rectangle layout, GameTime gameTime, ref bool stealFocus) { var buttonLayout = new Rectangle( layout.Center.X - 100, layout.Bottom - (this.m_Children.Count * 75) - 30, 200, 50); foreach (var button in this.m_Children) { button.Update(skin, buttonLayout, gameTime, ref stealFocus); buttonLayout.Y += 75; } }
public void Draw(IRenderContext context, ISkin skin, Rectangle layout) { var buttonLayout = new Rectangle( layout.Center.X - 100, layout.Bottom - (this.m_Children.Count * 75) - 30, 200, 50); foreach (var button in this.m_Children) { button.Draw(context, skin, buttonLayout); buttonLayout.Y += 75; } }
public static Drawable GetAnimation(this ISkin source, string componentName, WrapMode wrapModeS, WrapMode wrapModeT, bool animatable, bool looping, bool applyConfigFrameRate = false, string animationSeparator = "-", bool startAtCurrentTime = true, double?frameLength = null) { Texture texture; if (animatable) { var textures = getTextures().ToArray(); if (textures.Length > 0) { var animation = new SkinnableTextureAnimation(startAtCurrentTime) { DefaultFrameLength = frameLength ?? getFrameLength(source, applyConfigFrameRate, textures), Loop = looping, }; foreach (var t in textures) { animation.AddFrame(t); } return(animation); } } // if an animation was not allowed or not found, fall back to a sprite retrieval. if ((texture = source.GetTexture(componentName, wrapModeS, wrapModeT)) != null) { return new Sprite { Texture = texture } } ; return(null); IEnumerable <Texture> getTextures() { for (int i = 0; true; i++) { if ((texture = source.GetTexture($"{componentName}{animationSeparator}{i}", wrapModeS, wrapModeT)) == null) { break; } yield return(texture); } } }
public static Drawable GetAnimation(this ISkin source, string componentName, bool animatable, bool looping, string animationSeparator = "-") { const double default_frame_time = 1000 / 60d; Texture texture; Texture getFrameTexture(int frame) => source.GetTexture($"{componentName}{animationSeparator}{frame}"); TextureAnimation animation = null; if (animatable) { for (int i = 0;; i++) { if ((texture = getFrameTexture(i)) == null) { break; } if (animation == null) { animation = new TextureAnimation { DefaultFrameLength = default_frame_time, Repeat = looping } } ; animation.AddFrame(texture); } } if (animation != null) { return(animation); } if ((texture = source.GetTexture(componentName)) != null) { return new Sprite { Texture = texture } } ; return(null); } } }
public LegacyScoreCounter(ISkin skin) : base(6) { Anchor = Anchor.TopRight; Origin = Anchor.TopRight; this.skin = skin; // base class uses int for display, but externally we bind to ScoreProcessor as a double for now. Current.BindValueChanged(v => base.Current.Value = (int)v.NewValue); Scale = new Vector2(0.96f); Margin = new MarginPadding(10); }
private LayerContainer createLayer(string name, ISkin skin, LegacyKaraokeSkinNoteLayer layer) { return(new LayerContainer { RelativeSizeAxes = Axes.Both, Name = name, Children = new[] { GetSpriteFromLookup(skin, LegacyKaraokeSkinConfigurationLookups.NoteHeadImage, layer).With(d => { if (d == null) { return; } d.Name = "Head"; d.Anchor = Anchor.CentreLeft; d.Origin = Anchor.Centre; }), GetSpriteFromLookup(skin, LegacyKaraokeSkinConfigurationLookups.NoteBodyImage, layer).With(d => { if (d == null) { return; } d.Name = "Body"; d.Anchor = Anchor.Centre; d.Origin = Anchor.Centre; d.Size = Vector2.One; d.FillMode = FillMode.Stretch; d.RelativeSizeAxes = Axes.X; d.Depth = 1; d.Height = d.Texture?.DisplayHeight ?? 0; }), GetSpriteFromLookup(skin, LegacyKaraokeSkinConfigurationLookups.NoteTailImage, layer).With(d => { if (d == null) { return; } d.Name = "Tail"; d.Anchor = Anchor.CentreRight; d.Origin = Anchor.Centre; }), } }); }
/// <summary> /// The update. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <param name="gameTime"> /// The game time. /// </param> /// <param name="stealFocus"> /// The steal focus. /// </param> public void Update(ISkin skin, Rectangle layout, GameTime gameTime, ref bool stealFocus) { this.m_ToggleButton.Update( skin, new Rectangle(layout.X, layout.Y, layout.Width, 24), gameTime, ref stealFocus); if (this.m_Instance != null && this.m_Instance.State == SoundState.Stopped) { this.m_ToggleButton.Text = "Play"; this.m_Instance.Stop(); this.m_Instance = null; } }
private static double getFrameLength(ISkin source, bool applyConfigFrameRate, Texture[] textures) { if (applyConfigFrameRate) { var iniRate = source.GetConfig<LegacySetting, int>(LegacySetting.AnimationFramerate); if (iniRate?.Value > 0) return 1000f / iniRate.Value; return 1000f / textures.Length; } return default_frame_time; }
//--------------------------------------------------------------------------------------- public void ApplySystemSkin(IMember member, int skinId) { member.TemplateId = skinId; db.update(member, "TemplateId"); // 清空自定义设置 ISkin customSkin = getByMember(member.Id); if (customSkin != null) { customSkin.Body = ""; db.update(customSkin, "Body"); } }
public void InitTiles(int[,] data, ISkin skin) { List <TileUserControl> list = new List <TileUserControl>(); for (int i = 0; i < data.Length; i++) { TileUserControl con = new TileUserControl(skin) { Dock = DockStyle.Fill }; list.Add(con); } controls = list.ToArray(); tableLayoutPanel1.Controls.AddRange(controls); }
/// <summary> /// The get children with layouts. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <returns> /// The <see cref="IEnumerable{TreeEntry}"/>. /// </returns> public IEnumerable <TreeEntry> GetChildrenWithLayouts(ISkin skin, Rectangle layout) { var tree = this.BuildEntryGraph(layout); var list = this.NormalizeTree(tree, true); for (var i = 0; i < list.Count; i++) { list[i].Layout = new Rectangle( layout.X + (list[i].SegmentCount - 1) * skin.HeightForTreeItem, layout.Y + i * skin.HeightForTreeItem, layout.Width - (list[i].SegmentCount - 1) * skin.HeightForTreeItem, skin.HeightForTreeItem); yield return(list[i]); } }
public static Piece GetPiece(this ISkin skin, TileType type) { if (type == TileType.Empty) { return(null); } var res = skin.Pieces.FirstOrDefault(x => x != null && x.TileTypes.Contains(type));//?.First(); if (res == null) { Debug.LogWarning(Enum.GetName(typeof(TileType), type) + " does not exist in " + skin.Name); } return(res); }
/// <summary> /// The draw. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> public virtual void Draw(IRenderContext context, ISkin skin, Rectangle layout) { this.TextWidth = (int)Math.Ceiling(skin.MeasureText(context, this.Text).X); skin.DrawMenuItem(context, layout, this); var childrenLayout = this.GetMenuListLayout(skin, layout); if (this.Active && childrenLayout != null) { skin.DrawMenuList(context, childrenLayout.Value, this); foreach (var kv in this.GetMenuChildren(skin, layout)) { kv.Key.Draw(context, skin, kv.Value); } } }
private static double getFrameLength(ISkin source, bool applyConfigFrameRate, Texture[] textures) { if (applyConfigFrameRate) { var iniRate = source.GetConfig <GlobalSkinConfiguration, int>(GlobalSkinConfiguration.AnimationFramerate); if (iniRate?.Value > 0) { return(1000f / iniRate.Value); } return(1000f / textures.Length); } return(default_frame_time); }
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin) { if (legacySkin == null) { return(null); } var rulesetTransformed = Ruleset.CreateLegacySkinProvider(legacySkin, Beatmap); if (rulesetTransformed != null) { return(rulesetTransformed); } return(legacySkin); }
public String GetUserSkin(IMember user, int queryStringSkinId, String cssVersion) { int skinId = getSkinId(user, queryStringSkinId); ISkin skin = GetById(skinId); String skinPath = skin.GetSkinPath() + "?v=" + cssVersion; String result = string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", skinPath); if (skin.MemberId > 0) { result += Environment.NewLine; result += string.Format("<style>{0}</style>", skin.Body); result += Environment.NewLine; } return(result); }
public virtual void Create() { ISkin skin = validate(null); if (ctx.HasErrors) { run(Add); return; } skin.MemberId = ctx.owner.obj.Id; //skin.MemberUrl = ctx.owner.obj.Url; //skin.MemberName = ctx.owner.obj.Name; skinService.Insert(skin); redirect(My); }
public virtual void Edit(long id) { target(Update, id); set("lnkList", to(My)); ISkin skin = skinService.GetById(id, ctx.owner.obj.Id); if (skin == null) { echoRedirect(lang("exDataNotFound")); return; } set("skin.Name", skin.Name); set("skin.Body", skin.Body); }
public void Draw(IRenderContext context, ISkin skin, Rectangle layout) { if (context.Is3DContext) return; this.m_2DRenderUtilities.RenderRectangle( context, layout, Color.Black, filled: true); if (this.Player == null) return; this.RenderBar( context, layout, 0, this.Player.MaxHealth, this.Player.Health, Color.Red, "No Health"); this.RenderBar( context, layout, 14, this.Player.MaxStamina, this.Player.Stamina, Color.Yellow, "No Stamina"); this.RenderBar( context, layout, 28, this.Player.MaxMana, this.Player.Mana, Color.Blue, "No Mana"); }
public MenuWorld( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ISkin skin) { this.m_2DRenderUtilities = twodRenderUtilities; this.AssetManager = assetManagerProvider.GetAssetManager(); this.m_BackgroundCubeEntityFactory = backgroundCubeEntityFactory; this.m_TitleFont = this.AssetManager.Get<FontAsset>("font.Title"); this.m_PlayerModel = this.AssetManager.Get<ModelAsset>("model.Character"); this.m_PlayerModelTexture = this.AssetManager.Get<TextureAsset>("model.CharacterTex"); this.Entities = new List<IEntity>(); this.m_CanvasEntity = new CanvasEntity(skin) { Canvas = new Canvas() }; this.m_CanvasEntity.Canvas.SetChild(this.m_TitleMenu = new TitleMenu()); // Don't add the canvas to the entities list; that way we can explicitly // order it's depth. }
public LoadWorld( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ILevelAPI levelAPI, ISkin skin) : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin) { var assetManager = assetManagerProvider.GetAssetManager(); var returnText = assetManager.Get<LanguageAsset>("language.RETURN"); this.AddMenuItem(returnText, () => { this.TargetWorld = this.GameContext.CreateWorld<TitleWorld>(); }); // Get all available levels. foreach (var levelRef in levelAPI.GetAvailableLevels()) { this.AddMenuItem( new LanguageAsset(levelRef, levelRef), () => { this.TargetWorld = this.GameContext.CreateWorld<TychaiaGameWorld>(); }); } }
public MultiplayerWorld(ISkin skin) { this.Entities = new List<IEntity>(); this.m_ServersListView = new ListView(); this.m_ServersListView.AddChild(new ServerListItem { Text = "Loading servers...", Valid = false }); this.m_ServersListView.SelectedItemChanged += this.ServersListViewOnSelectedItemChanged; var backButton = new Button { Text = "Back" }; backButton.Click += (sender, args) => this.m_GameContext.SwitchWorld<TitleWorld>(); var buttonContainer = new HorizontalContainer(); buttonContainer.AddChild(new EmptyContainer(), "*"); buttonContainer.AddChild(backButton, "100"); buttonContainer.AddChild(new EmptyContainer(), "*"); var verticalContainer = new VerticalContainer(); verticalContainer.AddChild(new EmptyContainer(), "*"); verticalContainer.AddChild(this.m_ServersListView, "370"); verticalContainer.AddChild(new EmptyContainer(), "10"); verticalContainer.AddChild(buttonContainer, "24"); verticalContainer.AddChild(new EmptyContainer(), "*"); var horizontalContainer = new HorizontalContainer(); horizontalContainer.AddChild(new EmptyContainer(), "*"); horizontalContainer.AddChild(verticalContainer, "300"); horizontalContainer.AddChild(new EmptyContainer(), "*"); var canvas = new Canvas(); canvas.SetChild(horizontalContainer); this.m_CanvasEntity = new CanvasEntity(skin, canvas); this.m_QueryServersThread = new Thread(this.QueryServers) { Name = "Query Servers", IsBackground = true }; this.m_QueryServersThread.Start(); }
/// <summary> /// The update. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <param name="gameTime"> /// The game time. /// </param> /// <param name="stealFocus"> /// The steal focus. /// </param> public void Update(ISkin skin, Rectangle layout, GameTime gameTime, ref bool stealFocus) { foreach (var kv in this.GetChildrenWithLayouts(skin, layout)) { kv.Item.Update(skin, kv.Layout.Value, gameTime, ref stealFocus); } }
public int? GetDesiredWidth(ISkin skin) { return null; }
/// <summary> /// Requests that the UI container handle the specified event or return false. /// </summary> /// <param name="skin"> /// The UI skin. /// </param> /// <param name="layout"> /// The layout for the element. /// </param> /// <param name="context"> /// The current game context. /// </param> /// <param name="event"> /// The event that was raised. /// </param> /// <returns> /// Whether or not this UI element handled the event. /// </returns> public bool HandleEvent(ISkin skin, Rectangle layout, IGameContext context, Event @event) { foreach (var kv in this.GetChildrenWithLayouts(skin, layout)) { if (kv.Item.HandleEvent(skin, kv.Layout.Value, context, @event)) { return true; } } var keyPressEvent = @event as KeyPressEvent; if (keyPressEvent != null) { var upPressed = keyPressEvent.Key == Keys.Up; var downPressed = keyPressEvent.Key == Keys.Down; if (this.SelectedItem != null && (upPressed || downPressed)) { var list = this.m_Items.Select(x => new ListEntry { Item = x }).ToList(); var current = list.IndexOf(list.First(x => this.SelectedItem == x.Item)); if (upPressed) { current -= 1; } else if (downPressed) { current += 1; } if (current >= 0 && current < list.Count) { this.SelectedItem = list[current].Item; return true; } } } return false; }
/// <summary> /// The get children with layouts. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> public IEnumerable<ListEntry> GetChildrenWithLayouts(ISkin skin, Rectangle layout) { var list = this.m_Items.Select(x => new ListEntry { Item = x }).ToList(); var current = layout.Y; for (var i = 0; i < list.Count; i++) { list[i].Layout = new Rectangle( layout.X + skin.ListHorizontalPadding, current + skin.ListVerticalPadding, layout.Width - skin.ListHorizontalPadding * 2, skin.HeightForTreeItem); yield return list[i]; var desiredSize = list[i].Item as IHasDesiredSize; if (desiredSize != null && desiredSize.GetDesiredHeight(skin) != null) { current += desiredSize.GetDesiredHeight(skin).Value; } else { current += skin.HeightForTreeItem; } } }
public int? GetDesiredHeight(ISkin skin) { var current = 0; foreach (var item in this.m_Items) { var desiredSize = item as IHasDesiredSize; if (desiredSize != null && desiredSize.GetDesiredHeight(skin) != null) { current += desiredSize.GetDesiredHeight(skin).Value; } else { current += skin.HeightForTreeItem; } } return current; }
/// <summary> /// The get children with layouts. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <returns> /// The <see cref="IEnumerable{TreeEntry}"/>. /// </returns> public IEnumerable<TreeEntry> GetChildrenWithLayouts(ISkin skin, Rectangle layout) { var tree = this.BuildEntryGraph(layout); var list = this.NormalizeTree(tree, true); for (var i = 0; i < list.Count; i++) { list[i].Layout = new Rectangle( layout.X + (list[i].SegmentCount - 1) * skin.HeightForTreeItem, layout.Y + i * skin.HeightForTreeItem, layout.Width - (list[i].SegmentCount - 1) * skin.HeightForTreeItem, skin.HeightForTreeItem); yield return list[i]; } }
/// <summary> /// The draw. /// </summary> /// <param name="context"> /// The context. /// </param> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> public void Draw(IRenderContext context, ISkin skin, Rectangle layout) { skin.DrawListView(context, layout, this); foreach (var kv in this.GetChildrenWithLayouts(skin, layout)) { kv.Item.Draw(context, skin, kv.Layout.Value); } }
/// <summary> /// The get active children layouts. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> public IEnumerable<Rectangle> GetActiveChildrenLayouts(ISkin skin, Rectangle layout) { yield return layout; if (!this.Active) { yield break; } var childrenLayout = this.GetMenuListLayout(skin, layout); if (childrenLayout == null) { yield break; } yield return childrenLayout.Value; foreach (var kv in this.GetMenuChildren(skin, layout)) { foreach (var childLayout in kv.Key.GetActiveChildrenLayouts(skin, kv.Value)) { yield return childLayout; } } }
/// <summary> /// The get menu children. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> public IEnumerable<KeyValuePair<MenuItem, Rectangle>> GetMenuChildren(ISkin skin, Rectangle layout) { var childLayout = this.GetMenuListLayout(skin, layout); if (childLayout == null) { yield break; } var accumulated = 0; foreach (var child in this.m_Items) { yield return new KeyValuePair<MenuItem, Rectangle>( child, new Rectangle( childLayout.Value.X, childLayout.Value.Y + accumulated, childLayout.Value.Width, skin.MenuItemHeight)); accumulated += skin.MenuItemHeight; } }
/// <summary> /// The get menu list layout. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <returns> /// The <see cref="Rectangle?"/>. /// </returns> public Rectangle? GetMenuListLayout(ISkin skin, Rectangle layout) { // The location of the child items depends on whether we're owned // by a main menu or not. if (this.m_Items.Count == 0) { return null; } var maxWidth = this.m_Items.Max(x => x.TextWidth) + skin.AdditionalMenuItemWidth; var maxHeight = this.m_Items.Count * skin.MenuItemHeight; if (this.Parent is MainMenu) { return new Rectangle(layout.X, layout.Y + layout.Height, maxWidth, maxHeight); } return new Rectangle(layout.X + layout.Width, layout.Y, maxWidth, maxHeight); }
/// <summary> /// Requests that the UI container handle the specified event or return false. /// </summary> /// <param name="skin"> /// The UI skin. /// </param> /// <param name="layout"> /// The layout for the element. /// </param> /// <param name="context"> /// The current game context. /// </param> /// <param name="event"> /// The event that was raised. /// </param> /// <returns> /// Whether or not this UI element handled the event. /// </returns> public bool HandleEvent(ISkin skin, Rectangle layout, IGameContext context, Event @event) { return this.Active; }
/// <summary> /// The update. /// </summary> /// <param name="skin"> /// The skin. /// </param> /// <param name="layout"> /// The layout. /// </param> /// <param name="gameTime"> /// The game time. /// </param> /// <param name="stealFocus"> /// The steal focus. /// </param> public virtual void Update(ISkin skin, Rectangle layout, GameTime gameTime, ref bool stealFocus) { var mouse = Mouse.GetState(); var leftPressed = mouse.LeftChanged(this) == ButtonState.Pressed; if (layout.Contains(mouse.X, mouse.Y)) { this.Hovered = true; this.HoverCountdown = 5; if (leftPressed) { if (this.Click != null) { this.Click(this, new EventArgs()); } this.Active = true; } } var deactivate = true; foreach (var activeLayout in this.GetActiveChildrenLayouts(skin, layout)) { if (activeLayout.Contains(mouse.X, mouse.Y)) { deactivate = false; break; } } this.Hovered = !deactivate; if (leftPressed) { this.Active = !deactivate; } if (this.HoverCountdown == 0) { this.Hovered = false; } if (!(this.Parent is MainMenu)) { this.Active = this.Hovered; } if (this.Active) { foreach (var kv in this.GetMenuChildren(skin, layout)) { kv.Key.Update(skin, kv.Value, gameTime, ref stealFocus); } this.Focus(); } // If the menu item is active, we steal focus from any further updating by our parent. if (this.Active) { stealFocus = true; } }
public ConnectWorld( IKernel kernel, I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ISkin skin, IProfiler profiler, IPersistentStorage persistentStorage, bool startServer, IPAddress address, int port) : base(twodRenderUtilities, assetManagerProvider, backgroundCubeEntityFactory, skin) { this.m_2DRenderUtilities = twodRenderUtilities; this.m_PersistentStorage = persistentStorage; this.m_DefaultFont = assetManagerProvider.GetAssetManager().Get<FontAsset>("font.Default"); this.m_Address = address; this.m_Port = port; TychaiaClient client = null; byte[] initial = null; Action cleanup = () => { kernel.Unbind<INetworkAPI>(); kernel.Unbind<IClientNetworkAPI>(); if (client != null) { client.Close(); } this.TerminateExistingProcess(); }; if (startServer) { this.m_Actions = new Action[] { () => this.m_Message = "Closing old process...", () => this.TerminateExistingProcess(), () => this.m_Message = "Starting server...", () => this.StartServer(), () => this.m_Message = "Creating client...", () => client = new TychaiaClient(port + 2, port + 3), () => client.AttachProfiler(profiler), () => this.m_Message = "Connecting to server...", () => client.Connect(new DualIPEndPoint(address, port, port + 1)), () => this.m_Message = "Binding node to kernel...", () => kernel.Bind<INetworkAPI>().ToMethod(x => client), () => kernel.Bind<IClientNetworkAPI>().ToMethod(x => client), () => this.m_Message = "Joining game...", () => this.m_UniqueClientIdentifier = this.JoinGame(client), () => this.m_Message = "Retrieving initial game state...", () => initial = client.LoadInitialState(), () => this.m_Message = "Starting client...", () => this.m_PerformFinalAction = true }; } else { this.m_Actions = new Action[] { () => this.m_Message = "Creating client...", () => client = new TychaiaClient(port + 2, port + 3), () => client.AttachProfiler(profiler), () => this.m_Message = "Connecting to server...", () => client.Connect(new DualIPEndPoint(address, port, port + 1)), () => this.m_Message = "Binding node to kernel...", () => kernel.Bind<INetworkAPI>().ToMethod(x => client), () => kernel.Bind<IClientNetworkAPI>().ToMethod(x => client), () => this.m_Message = "Joining game...", () => this.m_UniqueClientIdentifier = this.JoinGame(client), () => this.m_Message = "Retrieving initial game state...", () => initial = client.LoadInitialState(), () => this.m_Message = "Starting client...", () => this.m_PerformFinalAction = true }; } this.m_FinalAction = () => this.TargetWorld = this.GameContext.CreateWorld<IWorldFactory>(x => x.CreateTychaiaGameWorld(this.m_UniqueClientIdentifier, cleanup)); var thread = new Thread(this.Run) { IsBackground = true }; thread.Start(); AppDomain.CurrentDomain.ProcessExit += (sender, e) => { if (this.m_Process != null) { try { this.m_Process.Kill(); this.m_Process = null; } catch (InvalidOperationException) { } } }; AppDomain.CurrentDomain.UnhandledException += (sender, e) => { if (this.m_Process != null) { try { this.m_Process.Kill(); this.m_Process = null; } catch (InvalidOperationException) { } } }; }