Skip to content

Commit

Permalink
Roadmap (#307)
Browse files Browse the repository at this point in the history
* Окно, но не прототип

* Рабочий прототип роадмапа

* Контрол

* Потом доделаю

* Пустой Roadmap

* Готова

---------

Co-authored-by: BL02DL <[email protected]>
  • Loading branch information
Farrellka-dev and BL02DL authored Nov 1, 2024
1 parent 0394782 commit bb53a70
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Content.Client/Info/LinkBanner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Content.Client.Changelog;
using Content.Client._LostParadise.Roadmap;
using Content.Client.Changelog;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.EscapeMenu;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Shared.CCVar;
Expand Down Expand Up @@ -47,6 +49,14 @@ public LinkBanner()
changelogButton.OnPressed += args => UserInterfaceManager.GetUIController<ChangelogUIController>().ToggleWindow();
buttons.AddChild(changelogButton);

var roadmapButton = new Button
{
Text = Loc.GetString("server-info-roadmap-button"),
StyleClasses = { StyleBase.ButtonCaution },
};
roadmapButton.OnPressed += _ => UserInterfaceManager.GetUIController<RoadmapUI>().ToggleRoadmap();
buttons.AddChild(roadmapButton);

void AddInfoButton(string loc, CVarDef<string> cVar)
{
var button = new Button { Text = Loc.GetString(loc) };
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Options/UI/EscapeMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Resizable="False">

<BoxContainer Orientation="Vertical" SeparationOverride="4" MinWidth="150">
<Button Access="Public" Name="RoadmapButton" Text="{Loc 'ui-roadmap'}" StyleClasses="Caution" />
<changelog:ChangelogButton Access="Public" Name="ChangelogButton"/>
<ui:VoteCallMenuButton />
<Button Access="Public" Name="OptionsButton" Text="{Loc 'ui-escape-options'}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Client.Gameplay;
using Content.Client._LostParadise.Roadmap;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.Guidebook;
using Content.Client.UserInterface.Systems.Info;
Expand Down Expand Up @@ -63,6 +64,12 @@ public void OnStateEntered(GameplayState state)
_escapeWindow.OnClose += DeactivateButton;
_escapeWindow.OnOpen += ActivateButton;

_escapeWindow.RoadmapButton.OnPressed += _ =>
{
CloseEscapeWindow();
UIManager.GetUIController<RoadmapUI>().ToggleRoadmap();
};

_escapeWindow.ChangelogButton.OnPressed += _ =>
{
CloseEscapeWindow();
Expand Down
96 changes: 96 additions & 0 deletions Content.Client/_LostParadise/Roadmap/RoadmapControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Content.Shared._LostParadise.Roadmap;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface;
using System.Numerics;

namespace Content.Client._LostParadise.Roadmap
{
public class RoadmapControl : Control
{
private readonly RoadmapPrototype _prototype;
private readonly ProgressBar _progressBar;

public RoadmapControl(RoadmapPrototype prototype)
{
_prototype = prototype;
_progressBar = new ProgressBar
{
MinValue = 0,
MaxValue = 100,
Value = _prototype.Progress,
HorizontalExpand = true
};

SetupUI();
}

private void SetupUI()
{
Margin = new Thickness(0, 20, 0, 0);

var vBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical
};

var nameButton = new Button
{
Text = _prototype.Name,
StyleClasses = { "Caution" },
HorizontalExpand = true
};

vBox.AddChild(nameButton);

var descriptionLabel = new Label { Text = _prototype.Description, FontColorOverride = Color.LightGray };
var progressLabel = new Label
{
Text = Loc.GetString("roadmap-progress") + $": {_prototype.Progress}%",
FontColorOverride = Color.White
};

var statusBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalExpand = true,
SeparationOverride = 5
};

var statusLabel = new Label
{
Text = Loc.GetString("roadmap-status") + $": {Loc.GetString(_prototype.Status)}",
FontColorOverride = GetStatusColor(),
};

statusBox.AddChild(statusLabel);
statusBox.AddChild(new Control { HorizontalExpand = true });

vBox.AddChild(descriptionLabel);
vBox.AddChild(progressLabel);
vBox.AddChild(_progressBar);
vBox.AddChild(statusBox);

var separator = new PanelContainer
{
Modulate = new Color(0.5f, 0.5f, 0.5f, 1f),
MinSize = new Vector2(0, 2),
HorizontalExpand = true
};
vBox.AddChild(separator);

AddChild(vBox);
}

private Color GetStatusColor()
{
string status = _prototype.Status;
return status switch
{
"roadmap-goal-completed" => new Color(0.0f, 1.0f, 0.0f),
"roadmap-goal-progress" => new Color(1.0f, 1.0f, 0.0f),
"roadmap-goal-waiting" => new Color(1.0f, 0.5f, 0.0f),
_ => Color.White
};
}
}
}
81 changes: 81 additions & 0 deletions Content.Client/_LostParadise/Roadmap/RoadmapUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Content.Shared._LostParadise.Roadmap;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using System.Numerics;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.Controllers;
using System.Linq;

namespace Content.Client._LostParadise.Roadmap
{
public sealed class RoadmapUI : UIController
{
private DefaultWindow _roadmapWindow;

public RoadmapUI()
{
_roadmapWindow = new DefaultWindow
{
Title = Loc.GetString("roadmap-plan-LLP"),
SetSize = new Vector2(600, 600),
Resizable = false
};

var panelContainer = new PanelContainer
{
MinSize = new Vector2(580, 580),
ModulateSelfOverride = Color.Transparent,
Margin = new Thickness(10)
};

var scrollContainer = new ScrollContainer
{
HorizontalExpand = true,
VerticalExpand = true,
Margin = new Thickness(0, 20, 0, 0)
};

var phaseList = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
SeparationOverride = 10
};

scrollContainer.AddChild(phaseList);
panelContainer.AddChild(scrollContainer);
_roadmapWindow.AddChild(panelContainer);

RefreshUI(phaseList);
}

private void RefreshUI(BoxContainer phaseList)
{
phaseList.RemoveAllChildren();

var roadmapSystem = IoCManager.Resolve<IPrototypeManager>();

var roadmapPhases = roadmapSystem.EnumeratePrototypes<RoadmapPrototype>()
.OrderBy<RoadmapPrototype, int>(phase => phase.Order);

foreach (var phase in roadmapPhases)
{
var phaseControl = new RoadmapControl(phase);
phaseList.AddChild(phaseControl);
}
}

public void ToggleRoadmap()
{
if (_roadmapWindow.IsOpen)
{
_roadmapWindow.Close();
}
else
{
_roadmapWindow.OpenCentered();
}
}
}
}
34 changes: 34 additions & 0 deletions Content.Server/_LostParadise/Roadmap/RoadmapSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Content.Shared.Administration.Logs;
using Content.Shared._LostParadise.Roadmap;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;

namespace Content.Server._LostParadise.Roadmap
{
public class RoadmapSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoadmapComponent, RoadmapUpdateEvent>(OnPhaseUpdate);
}

private void OnPhaseUpdate(EntityUid uid, RoadmapComponent component, RoadmapUpdateEvent args)
{
if (!_protoManager.TryIndex<RoadmapPrototype>(args.RoadmapId, out var phase))
{
Logger.ErrorS("roadmap", $"Roadmap {args.RoadmapId} not found.");
return;
}

component.CurrentPhase = phase.ID;
component.Progress = args.NewProgress;

Dirty(uid, component);
}
}
}
18 changes: 18 additions & 0 deletions Content.Shared/_LostParadise/Roadmap/RoadmapComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;

namespace Content.Shared._LostParadise.Roadmap
{
[RegisterComponent]
public sealed partial class RoadmapComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
[DataField("roadmap")]
public string CurrentPhase { get; set; } = string.Empty;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("progress")]
public float Progress { get; set; } = 0.0f;
}
}
26 changes: 26 additions & 0 deletions Content.Shared/_LostParadise/Roadmap/RoadmapPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;

namespace Content.Shared._LostParadise.Roadmap
{
[Prototype("roadmap")]
public class RoadmapPrototype : IPrototype
{
[IdDataField]
public string ID { get; } = default!;

[DataField("name")]
public string Name { get; } = string.Empty;

[DataField("description")]
public string Description { get; } = string.Empty;

[DataField("progress")]
public float Progress { get; set; } = 0.0f;

[DataField("status")]
public string Status { get; set; } = "roadmap-goal-waiting";
[DataField("order")]
public int Order { get; set; }
}
}
16 changes: 16 additions & 0 deletions Content.Shared/_LostParadise/Roadmap/RoadmapUpdateEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Robust.Shared.GameObjects;

namespace Content.Shared._LostParadise.Roadmap
{
public sealed class RoadmapUpdateEvent : EntityEventArgs
{
public string RoadmapId { get; }
public float NewProgress { get; }

public RoadmapUpdateEvent(string roadmapId, float newProgress)
{
RoadmapId = roadmapId;
NewProgress = newProgress;
}
}
}
7 changes: 7 additions & 0 deletions Resources/Locale/ru-RU/_LostParadise/roadmap/roadmap.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ui-roadmap = План разработки
roadmap-plan-LLP = План разработки Lost Paradise
roadmap-goal-completed = Завершено
roadmap-goal-progress = В процессе
roadmap-goal-waiting = В ожидании
roadmap-progress = Прогресс
roadmap-status = Статус
27 changes: 27 additions & 0 deletions Resources/Prototypes/_LostParadise/Roadmap/roadmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Короче, думаю тут всё понятно, однако в status
# пихайте: roadmap-goal-completed, roadmap-goal-progress, roadmap-goal-waiting
# Order нужен, чтоб выставить в правильном порядке, так что вот, пользуйтесь

- type: roadmap
id: "helloworld"
name: "Версия 2.0 - Дивный новый мир!"
description: "Новая сборка и механики!"
progress: 100
status: roadmap-goal-completed
order: 0

- type: roadmap
id: "centcom"
name: "Обновление 2.1 - Центком важен!"
description: "Обновление Центкома!"
progress: 50
status: roadmap-goal-progress
order: 1

- type: roadmap
id: "blusec"
name: "Обновление 2.2 - BLUSEC!"
description: "Перекрас СБ в новый модный цвет!"
progress: 37
status: roadmap-goal-progress
order: 2

0 comments on commit bb53a70

Please sign in to comment.