mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Move incompatibility tooltip logic to local player mod select overlays
This one turned out to be a bit more involved, due to tooltips being shared and having the potential of being used somewhere where it shouldn't be, due to the same content type matching. That's the reason I've defined a protected `TargetContentType`, to be able to separate "local player mod tooltips" and regular mod tooltips apart. Definitely unsure about the solution, but that's as far as I can think of right now.
This commit is contained in:
@ -65,5 +65,56 @@ namespace osu.Game.Overlays.Mods
|
|||||||
else
|
else
|
||||||
incompatibleIcon.Hide();
|
incompatibleIcon.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override ITooltip GetCustomTooltip() => new LocalPlayerModButtonTooltip();
|
||||||
|
|
||||||
|
private class LocalPlayerModButtonTooltip : ModButtonTooltip
|
||||||
|
{
|
||||||
|
private readonly OsuSpriteText incompatibleText;
|
||||||
|
|
||||||
|
private readonly Bindable<IReadOnlyList<Mod>> incompatibleMods = new Bindable<IReadOnlyList<Mod>>();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
|
public LocalPlayerModButtonTooltip()
|
||||||
|
{
|
||||||
|
AddRange(new Drawable[]
|
||||||
|
{
|
||||||
|
incompatibleText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Margin = new MarginPadding { Top = 5 },
|
||||||
|
Font = OsuFont.GetFont(weight: FontWeight.Regular),
|
||||||
|
Text = "Incompatible with:"
|
||||||
|
},
|
||||||
|
new ModDisplay
|
||||||
|
{
|
||||||
|
Current = incompatibleMods,
|
||||||
|
ExpansionMode = ExpansionMode.AlwaysExpanded,
|
||||||
|
Scale = new Vector2(0.7f)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours)
|
||||||
|
{
|
||||||
|
incompatibleText.Colour = colours.BlueLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Type TargetContentType => typeof(LocalPlayerModButton);
|
||||||
|
|
||||||
|
protected override void UpdateDisplay(Mod mod)
|
||||||
|
{
|
||||||
|
base.UpdateDisplay(mod);
|
||||||
|
|
||||||
|
var incompatibleTypes = mod.IncompatibleMods;
|
||||||
|
|
||||||
|
var allMods = ruleset.Value.CreateInstance().GetAllMods();
|
||||||
|
|
||||||
|
incompatibleMods.Value = allMods.Where(m => m.GetType() != mod.GetType() && incompatibleTypes.Any(t => t.IsInstanceOfType(m))).ToList();
|
||||||
|
incompatibleText.Text = incompatibleMods.Value.Any() ? "Incompatible with:" : "Compatible with all mods";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,6 +314,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
public virtual ITooltip GetCustomTooltip() => new ModButtonTooltip();
|
public virtual ITooltip GetCustomTooltip() => new ModButtonTooltip();
|
||||||
|
|
||||||
public object TooltipContent => SelectedMod ?? Mods.FirstOrDefault();
|
public object TooltipContent => this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Screens.Play.HUD;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods
|
namespace osu.Game.Overlays.Mods
|
||||||
@ -22,12 +19,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
private readonly OsuSpriteText descriptionText;
|
private readonly OsuSpriteText descriptionText;
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
private readonly OsuSpriteText incompatibleText;
|
|
||||||
|
|
||||||
private readonly Bindable<IReadOnlyList<Mod>> incompatibleMods = new Bindable<IReadOnlyList<Mod>>();
|
protected override Container<Drawable> Content { get; }
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private Bindable<RulesetInfo> ruleset { get; set; }
|
|
||||||
|
|
||||||
public ModButtonTooltip()
|
public ModButtonTooltip()
|
||||||
{
|
{
|
||||||
@ -35,13 +28,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Masking = true;
|
Masking = true;
|
||||||
CornerRadius = 5;
|
CornerRadius = 5;
|
||||||
|
|
||||||
Children = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
background = new Box
|
background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
},
|
},
|
||||||
new FillFlowContainer
|
Content = new FillFlowContainer
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
@ -51,19 +44,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
descriptionText = new OsuSpriteText
|
descriptionText = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Regular),
|
Font = OsuFont.GetFont(weight: FontWeight.Regular),
|
||||||
Margin = new MarginPadding { Bottom = 5 }
|
|
||||||
},
|
},
|
||||||
incompatibleText = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Regular),
|
|
||||||
Text = "Incompatible with:"
|
|
||||||
},
|
|
||||||
new ModDisplay
|
|
||||||
{
|
|
||||||
Current = incompatibleMods,
|
|
||||||
ExpansionMode = ExpansionMode.AlwaysExpanded,
|
|
||||||
Scale = new Vector2(0.7f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -74,7 +55,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
background.Colour = colours.Gray3;
|
background.Colour = colours.Gray3;
|
||||||
descriptionText.Colour = colours.BlueLighter;
|
descriptionText.Colour = colours.BlueLighter;
|
||||||
incompatibleText.Colour = colours.BlueLight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
|
protected override void PopIn() => this.FadeIn(200, Easing.OutQuint);
|
||||||
@ -82,32 +62,26 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
private Mod lastMod;
|
private Mod lastMod;
|
||||||
|
|
||||||
public bool SetContent(object content)
|
protected virtual Type TargetContentType => typeof(ModButton);
|
||||||
|
|
||||||
|
public virtual bool SetContent(object content)
|
||||||
{
|
{
|
||||||
if (!(content is Mod mod))
|
if (!(content is ModButton button) || content.GetType() != TargetContentType)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
var mod = button.SelectedMod ?? button.Mods.First();
|
||||||
|
|
||||||
if (mod.Equals(lastMod)) return true;
|
if (mod.Equals(lastMod)) return true;
|
||||||
|
|
||||||
lastMod = mod;
|
lastMod = mod;
|
||||||
|
|
||||||
descriptionText.Text = mod.Description;
|
UpdateDisplay(mod);
|
||||||
|
|
||||||
var incompatibleTypes = mod.IncompatibleMods;
|
|
||||||
|
|
||||||
var allMods = ruleset.Value.CreateInstance().GetAllMods();
|
|
||||||
|
|
||||||
incompatibleMods.Value = allMods.Where(m => m.GetType() != mod.GetType() && incompatibleTypes.Any(t => t.IsInstanceOfType(m))).ToList();
|
|
||||||
|
|
||||||
if (!incompatibleMods.Value.Any())
|
|
||||||
{
|
|
||||||
incompatibleText.Text = "Compatible with all mods";
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
incompatibleText.Text = "Incompatible with:";
|
protected virtual void UpdateDisplay(Mod mod)
|
||||||
|
{
|
||||||
return true;
|
descriptionText.Text = mod.Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Move(Vector2 pos) => Position = pos;
|
public void Move(Vector2 pos) => Position = pos;
|
||||||
|
Reference in New Issue
Block a user