Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add multi lang for the raid.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 29, 2024
1 parent 6146e87 commit 071c14b
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 117 deletions.
4 changes: 2 additions & 2 deletions Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ClickingCount": 87918,
"SayingHelloCount": 95,
"ClickingCount": 88321,
"SayingHelloCount": 96,
"SaidUsers": []
}
8 changes: 4 additions & 4 deletions RotationSolver.Basic/Actions/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public ActionConfig Config
{
Service.Config.RotationActionConfig[ID] = value
= Setting.CreateConfig?.Invoke() ?? new();
if (Setting.TargetStatusProvide != null)
{
value.TimeToKill = 10;
}
if (value.TimeToUntargetable == 0)
{
value.TimeToUntargetable = value.TimeToKill;
}
if (Setting.TargetStatusProvide != null)
{
value.TimeToKill = 10;
}
}
return value;
}
Expand Down
11 changes: 11 additions & 0 deletions RotationSolver.Basic/Data/RaidLangs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace RotationSolver.Basic.Data;
internal class RaidLangs
{
public Dictionary<string, Lang> langs { get; set; } = [];

internal class Lang
{
public Dictionary<string, string> replaceSync { get; set; } = [];
public Dictionary<string, string> replaceText { get; set; } = [];
}
}
46 changes: 41 additions & 5 deletions RotationSolver.Basic/Data/TimelineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,58 @@ internal enum TimelineType : byte
ActorControl,
}

internal readonly struct TimelineItem(float time, string name, TimelineType type, string[] ids, JObject? obj)
internal readonly struct TimelineItem(float time, string name, TimelineType type, string[] ids, JObject? obj, RaidLangs langs)
{
private RaidLangs.Lang Lang
{
get
{
var key = Svc.ClientState.ClientLanguage switch
{
Dalamud.ClientLanguage.English => "",
Dalamud.ClientLanguage.Japanese => "ja",
Dalamud.ClientLanguage.German => "de",
Dalamud.ClientLanguage.French => "fr",
(Dalamud.ClientLanguage)4 => "cn",
_ => "ko",
};

if (langs.langs.TryGetValue(key, out var lang)) return lang;
return new RaidLangs.Lang();
}
}
public TimelineType Type => type;

public float Time => time;

public JObject? Object => obj;

public string Name => name;
public string Name
{
get
{
if (Lang.replaceText.TryGetValue(name, out var lang)) return lang;
return name;
}
}

public bool IsShown => Name is not "--Reset--" and not "--sync--";

public string this[string propertyName] => Object?[propertyName]?.ToString() ?? string.Empty;
public string this[string propertyName]
{
get
{
var prop = Object?[propertyName]?.ToString() ?? string.Empty;
foreach (var pair in Lang.replaceSync)
{
prop = prop.Replace(pair.Key, pair.Value);
}
return prop;
}
}

public TimelineItem(float time, string name, string type, string[] ids, JObject? obj)
: this(time, name, GetTypeFromName(type), ids, obj)
public TimelineItem(float time, string name, string type, string[] ids, JObject? obj, RaidLangs langs)
: this(time, name, GetTypeFromName(type), ids, obj, langs)
{

}
Expand Down
1 change: 1 addition & 0 deletions RotationSolver.GameData/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lumina;
using Lumina.Data;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RotationSolver.GameData;
using RotationSolver.GameData.Getters;
Expand Down
53 changes: 4 additions & 49 deletions RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,52 +131,7 @@ public static bool DrawCondition(ICondition condition, ref int index)

internal static void SearchItemsReflection(string popId, string name, ref string searchTxt, MemberInfo[] actions, Action<MemberInfo> selectAction)
{
SearchItems(popId, name, ref searchTxt, actions, LocalizationManager.Local, selectAction, UiString.ConfigWindow_Actions_MemberName.Local());
}

internal static void SearchItems<T>(string popId, string name, ref string searchTxt, T[] items, Func<T, string> getSearchName, Action<T> selectAction, string searchingHint)
{
if (ImGuiHelper.SelectableButton(name + "##" + popId))
{
if (!ImGui.IsPopupOpen(popId)) ImGui.OpenPopup(popId);
}

using var popUp = ImRaii.Popup(popId);
if (!popUp.Success) return;

if (items == null || items.Length == 0)
{
ImGui.TextColored(ImGuiColors.DalamudRed, "ConfigWindow_Condition_NoItemsWarning".Loc("There are no items!"));
return;
}

var searchingKey = searchTxt;

var members = items.Select(m => (m, getSearchName(m)))
.OrderByDescending(s => SearchableCollection.Similarity(s.Item2, searchingKey));

ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, members.Max(i => ImGuiHelpers.GetButtonSize(i.Item2).X)));
ImGui.InputTextWithHint("##Searching the member", searchingHint, ref searchTxt, 128);

ImGui.Spacing();

ImRaii.IEndObject? child = null;
if (members.Count() >= 15)
{
ImGui.SetNextWindowSizeConstraints(new Vector2(0, 300), new Vector2(500, 300));
child = ImRaii.Child(popId);
if (!child) return;
}

foreach (var member in members)
{
if (ImGui.Selectable(member.Item2))
{
selectAction?.Invoke(member.m);
ImGui.CloseCurrentPopup();
}
}
child?.Dispose();
ImGuiHelper.SearchCombo(popId, name, ref searchTxt, actions, LocalizationManager.Local, selectAction, UiString.ConfigWindow_Actions_MemberName.Local());
}

public static float IconSizeRaw => ImGuiHelpers.GetButtonSize("H").Y;
Expand Down Expand Up @@ -318,7 +273,7 @@ private static void DrawAfter(this ICondition condition, ICustomRotation rotatio

private static void DrawAfter(this NamedCondition namedCondition, ICustomRotation _)
{
SearchItems($"##Comparation{namedCondition.GetHashCode()}", namedCondition.ConditionName, ref searchTxt,
ImGuiHelper.SearchCombo($"##Comparation{namedCondition.GetHashCode()}", namedCondition.ConditionName, ref searchTxt,
DataCenter.RightSet.NamedConditions.Select(p => p.Name).ToArray(), i => i.ToString(), i =>
{
namedCondition.ConditionName = i;
Expand Down Expand Up @@ -968,7 +923,7 @@ private static void DrawAfter(this TerritoryCondition territoryCondition, ICusto
case TerritoryConditionType.TerritoryName:
ImGui.SameLine();

SearchItems($"##TerritoryName{territoryCondition.GetHashCode()}", territoryCondition.Name, ref searchTxt,
ImGuiHelper.SearchCombo($"##TerritoryName{territoryCondition.GetHashCode()}", territoryCondition.Name, ref searchTxt,
TerritoryNames, i => i.ToString(), i =>
{
territoryCondition.Name = i;
Expand All @@ -978,7 +933,7 @@ private static void DrawAfter(this TerritoryCondition territoryCondition, ICusto
case TerritoryConditionType.DutyName:
ImGui.SameLine();

SearchItems($"##DutyName{territoryCondition.GetHashCode()}", territoryCondition.Name, ref searchTxt,
ImGuiHelper.SearchCombo($"##DutyName{territoryCondition.GetHashCode()}", territoryCondition.Name, ref searchTxt,
DutyNames, i => i.ToString(), i =>
{
territoryCondition.Name = i;
Expand Down
85 changes: 67 additions & 18 deletions RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using Dalamud.Interface.Utility.Raii;
using ECommons.DalamudServices;
using ECommons.ImGuiMethods;
using ECommons.LanguageHelpers;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
using RotationSolver.Data;
using RotationSolver.Localization;
using RotationSolver.UI.SearchableConfigs;
using RotationSolver.UI.SearchableSettings;
using System.ComponentModel;

namespace RotationSolver.UI;

Expand Down Expand Up @@ -103,23 +101,64 @@ public unsafe static ImFontPtr GetFont(float size)
return font;
}

public static unsafe bool SelectableCombo(string popUp, string[] items, ref int index, ImFontPtr? font = null, Vector4? color = null)
public static void SearchCombo<T>(string popId, string name, ref string searchTxt, T[] items, Func<T, string> getSearchName, Action<T> selectAction, string searchingHint, ImFontPtr? font = null, Vector4? color = null)
{
var count = items.Length;
var name = items[index % count] + "##" + popUp;
if (SelectableButton(name + "##" + popId, font, color))
{
if (!ImGui.IsPopupOpen(popId)) ImGui.OpenPopup(popId);
}

var result = false;
if (ImGui.IsItemHovered())
{
ImGui.SetMouseCursor(ImGuiMouseCursor.Hand);
}

List<IDisposable> disposables = new(2);
if (font != null)
using var popUp = ImRaii.Popup(popId);
if (!popUp.Success) return;

if (items == null || items.Length == 0)
{
disposables.Add(ImRaii.PushFont(font.Value));
ImGui.TextColored(ImGuiColors.DalamudRed, "ConfigWindow_Condition_NoItemsWarning".Loc("There are no items!"));
return;
}
if(color != null)

var searchingKey = searchTxt;

var members = items.Select(m => (m, getSearchName(m)))
.OrderByDescending(s => SearchableCollection.Similarity(s.Item2, searchingKey));

ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, members.Max(i => ImGuiHelpers.GetButtonSize(i.Item2).X)));
ImGui.InputTextWithHint("##Searching the member", searchingHint, ref searchTxt, 128);

ImGui.Spacing();

ImRaii.IEndObject? child = null;
if (members.Count() >= 15)
{
disposables.Add(ImRaii.PushColor(ImGuiCol.Text, color.Value));
ImGui.SetNextWindowSizeConstraints(new Vector2(0, 300), new Vector2(500, 300));
child = ImRaii.Child(popId);
if (!child) return;
}
if (SelectableButton(name))

foreach (var member in members)
{
if (ImGui.Selectable(member.Item2))
{
selectAction?.Invoke(member.m);
ImGui.CloseCurrentPopup();
}
}
child?.Dispose();
}

public static unsafe bool SelectableCombo(string popUp, string[] items, ref int index, ImFontPtr? font = null, Vector4? color = null)
{
var count = items.Length;
var name = items[index % count] + "##" + popUp;

var result = false;

if (SelectableButton(name, font, color))
{
if (count < 3)
{
Expand All @@ -131,10 +170,6 @@ public static unsafe bool SelectableCombo(string popUp, string[] items, ref int
if (!ImGui.IsPopupOpen(popUp)) ImGui.OpenPopup(popUp);
}
}
foreach (var item in disposables)
{
item.Dispose();
}

if (ImGui.IsItemHovered())
{
Expand All @@ -157,13 +192,27 @@ public static unsafe bool SelectableCombo(string popUp, string[] items, ref int
return result;
}

public static unsafe bool SelectableButton(string name)
public static unsafe bool SelectableButton(string name, ImFontPtr? font = null, Vector4? color = null)
{
List<IDisposable> disposables = new(2);
if (font != null)
{
disposables.Add(ImRaii.PushFont(font.Value));
}
if (color != null)
{
disposables.Add(ImRaii.PushColor(ImGuiCol.Text, color.Value));
}
ImGui.PushStyleColor(ImGuiCol.ButtonActive, ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.HeaderActive)));
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ImGui.ColorConvertFloat4ToU32(*ImGui.GetStyleColorVec4(ImGuiCol.HeaderHovered)));
ImGui.PushStyleColor(ImGuiCol.Button, 0);
var result = ImGui.Button(name);
ImGui.PopStyleColor(3);
foreach (var item in disposables)
{
item.Dispose();
}

return result;
}

Expand Down
Loading

0 comments on commit 071c14b

Please sign in to comment.