Skip to content

Commit

Permalink
adds tutor (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Aug 20, 2023
1 parent affbf7f commit 2eb6a1c
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 18 deletions.
Binary file modified 1.4/Assemblies/AchtungMod.dll
Binary file not shown.
Binary file modified About/Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added About/Resources/01_Welcome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added About/Resources/02_Forcing.mp4
Binary file not shown.
Binary file added About/Resources/03_Formations.mp4
Binary file not shown.
Binary file added About/Resources/04_Cooperation.mp4
Binary file not shown.
Binary file added About/Resources/05_ThreeModes.mp4
Binary file not shown.
6 changes: 6 additions & 0 deletions Languages/Dutch/Keyed/Text.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>

<Topic_Welcome>Welkom bij Achtung!</Topic_Welcome>
<Topic_Forcing>Dwingen</Topic_Forcing>
<Topic_Formations>Formaties</Topic_Formations>
<Topic_Cooperation>Samenwerking</Topic_Cooperation>
<Topic_ThreeModes>Drie Modi</Topic_ThreeModes>

<PositioningEnabledTitle>Aangepaste muispositionering</PositioningEnabledTitle>
<PositioningEnabledExplained>Maakt gevechtspositionering mogelijk voor je muisklikken/slepen (zie onderstaande instellingen)</PositioningEnabledExplained>

Expand Down
7 changes: 3 additions & 4 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
<LanguageData>

<Topic_Welcome>Welcome to Achtung!</Topic_Welcome>
<Topic_ThreeModes>Three Modes</Topic_ThreeModes>
<Topic_DraftUndraft>Drafted &amp; Undrafted</Topic_DraftUndraft>
<Topic_Lineup>Lineup</Topic_Lineup>
<Topic_Forcing>Forcing</Topic_Forcing>
<Topic_ForceAdvanced>Advanced Forcing</Topic_ForceAdvanced>
<Topic_Formations>Formations</Topic_Formations>
<Topic_Cooperation>Cooperation</Topic_Cooperation>
<Topic_ThreeModes>Three Modes</Topic_ThreeModes>

<PositioningEnabledTitle>Custom mouse positioning</PositioningEnabledTitle>
<PositioningEnabledExplained>Enables combat positioning for your mouse clicks/drags (see settings below)</PositioningEnabledExplained>
Expand Down
6 changes: 6 additions & 0 deletions Languages/German/Keyed/Text.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>

<Topic_Welcome>Willkommen zu Achtung!</Topic_Welcome>
<Topic_Forcing>Erzwingen</Topic_Forcing>
<Topic_Formations>Formationen</Topic_Formations>
<Topic_Cooperation>Zusammenarbeit</Topic_Cooperation>
<Topic_ThreeModes>Drei Modi</Topic_ThreeModes>

<PositioningEnabledTitle>Benutzerdef. Positionierung via Maus</PositioningEnabledTitle>
<PositioningEnabledExplained>Aktiviert die Kampfpositionierung beim Klicken/Ziehen der Maus (siehe Einstellungen unten).</PositioningEnabledExplained>

Expand Down
6 changes: 6 additions & 0 deletions Languages/Spanish/Keyed/Text.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>

<Topic_Welcome>¡Bienvenido a Achtung!</Topic_Welcome>
<Topic_Forcing>Forzar</Topic_Forcing>
<Topic_Formations>Formaciones</Topic_Formations>
<Topic_Cooperation>Cooperación</Topic_Cooperation>
<Topic_ThreeModes>Tres Modos</Topic_ThreeModes>

<PositioningEnabledTitle>Posicionamiento del ratón personalizado</PositioningEnabledTitle>
<PositioningEnabledExplained>Permite el posicionamiento en combate con un click o arrastre de tu ratón (ver preferencias abajo)</PositioningEnabledExplained>

Expand Down
6 changes: 6 additions & 0 deletions Languages/Swedish/Keyed/Text.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>

<Topic_Welcome>Välkommen till Achtung!</Topic_Welcome>
<Topic_Forcing>Tvinga</Topic_Forcing>
<Topic_Formations>Formationer</Topic_Formations>
<Topic_Cooperation>Samarbete</Topic_Cooperation>
<Topic_ThreeModes>Tre Lägen</Topic_ThreeModes>

<PositioningEnabledTitle>Aktivera positioningen för kolonister</PositioningEnabledTitle>
<PositioningEnabledExplained>Aktiverar muskommandos för positioneringen av kolonister (se inställningar nere)</PositioningEnabledExplained>

Expand Down
86 changes: 83 additions & 3 deletions Source/Dialog_ModFeatures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using UnityEngine;
using UnityEngine.Video;
using Verse;

namespace AchtungMod
{
[DataContract]
class Configuration
{
[DataMember] string[] Dismissed { get; set; } = new string[0];

internal bool IsDismissed(string topic) => Dismissed.Contains(topic);

internal void MarkDismissed(string topic)
{
if (IsDismissed(topic) == false)
{
Dismissed = Dismissed.Concat(new[] { topic }).ToArray();
Dialog_ModFeatures.Save();
}
}
}

internal class Dialog_ModFeatures : Window
{
const float listWidth = 240;
Expand All @@ -22,9 +41,12 @@ internal class Dialog_ModFeatures : Window
VideoPlayer videoPlayer;
string title = "";

static readonly string configurationPath = Path.Combine(GenFilePaths.ConfigFolderPath, "ModFeatures.json");
static Configuration configuration = new Configuration();

readonly string resourceDir;
readonly string[] topicResources;
readonly Texture2D[] topicTextures;
string[] topicResources;
Texture2D[] topicTextures;

string TopicTranslated(int i) => $"Topic_{topicResources[i].Substring(3).Replace(".png", "").Replace(".mp4", "")}".Translate();
string TopicType(int i) => topicResources[i].EndsWith(".png") ? "image" : "video";
Expand All @@ -39,17 +61,56 @@ public Dialog_ModFeatures(Type type)
silenceAmbientSound = true;
closeOnClickedOutside = true;

Load();

var rootDir = LoadedModManager.RunningMods.FirstOrDefault(mod => mod.assemblies.loadedAssemblies.Contains(type.Assembly))?.RootDir;
if (rootDir == null)
throw new Exception($"Could not find root mod directory for {type.Assembly.FullName}");
resourceDir = $"{rootDir}{Path.DirectorySeparatorChar}{ModMetaData.AboutFolderName}{Path.DirectorySeparatorChar}Resources";

ReloadTextures();
}

internal void ReloadTextures()
{
topicResources = Directory.GetFiles(resourceDir)
.Select(f => Path.GetFileName(f))
.Where(topic => configuration.IsDismissed(topic) == false)
.ToArray();
topicTextures = new Texture2D[topicResources.Length];
}

static void Load()
{
try
{
if (File.Exists(configurationPath))
{
var serializer = new DataContractJsonSerializer(typeof(Configuration));
using var stream = new FileStream(configurationPath, FileMode.Open);
configuration = (Configuration)serializer.ReadObject(stream);
return;
}
}
catch
{
}
configuration = new Configuration();
}

internal static void Save()
{
try
{
var serializer = new DataContractJsonSerializer(typeof(Configuration));
using var stream = new FileStream(configurationPath, FileMode.OpenOrCreate);
serializer.WriteObject(stream, configuration);
}
finally
{
}
}

public override float Margin => margin;
public int TopicCount => topicResources.Length;

Expand Down Expand Up @@ -103,6 +164,8 @@ public void ShowTopic(int i)
videoPlayer.Play();
}

static readonly Color[] frameColors = new[] { Color.yellow.ToTransparent(0.2f), Color.yellow.ToTransparent(0.3f), };
static readonly Color[] bgColors = new[] { Color.yellow.ToTransparent(0.05f), Color.yellow.ToTransparent(0.1f), };
public override void DoWindowContents(Rect inRect)
{
var font = Text.Font;
Expand All @@ -119,7 +182,24 @@ public override void DoWindowContents(Rect inRect)
for (var i = 0; i < topicResources.Length; i++)
{
var r = new Rect(0f, (rowHeight + rowSpacing) * i, viewRect.width, rowHeight);
if (Widgets.ButtonText(r, TopicTranslated(i)))
var hover = Mouse.IsOver(r) ? 1 : 0;
Widgets.DrawBoxSolid(r, bgColors[hover]);
Widgets.DrawBox(r, 1, SolidColorMaterials.NewSolidColorTexture(frameColors[hover]));
var anchor = Text.Anchor;
Text.Anchor = TextAnchor.MiddleLeft;
Widgets.Label(r.RightPartPixels(r.width - margin), TopicTranslated(i));
Text.Anchor = anchor;
r = r.RightPartPixels(rowHeight).ExpandedBy(-titleHeight / 2);
if (Widgets.ButtonImage(r, MainTabWindow_Quests.DismissIcon))
{
configuration.MarkDismissed(topicResources[i]);
currentTexture = null;
title = "";
ReloadTextures();
if (TopicCount == 0)
Close();
}
else if (hover == 1 && Mouse.IsOver(r) == false && Input.GetMouseButton(0))
ShowTopic(i);
}
Widgets.EndScrollView();
Expand Down
65 changes: 54 additions & 11 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,17 @@ public static void Prefix()
}
}

[HarmonyPatch(typeof(UIRoot_Entry))]
[HarmonyPatch(nameof(UIRoot_Entry.Init))]
static class VideoPatch1
{
public static void Postfix()
{
var dialog = new Dialog_ModFeatures(typeof(Achtung));
if (dialog.TopicCount > 0)
Find.WindowStack.Add(dialog);
}
}
// [HarmonyPatch(typeof(UIRoot_Entry))]
// [HarmonyPatch(nameof(UIRoot_Entry.Init))]
// static class VideoPatch1
// {
// public static void Postfix()
// {
// var dialog = new Dialog_ModFeatures(typeof(Achtung));
// if (dialog.TopicCount > 0)
// Find.WindowStack.Add(dialog);
// }
// }

[HarmonyPatch(typeof(Map))]
[HarmonyPatch(nameof(Map.FinalizeInit))]
Expand Down Expand Up @@ -243,6 +243,23 @@ public static void Postfix(Pawn ___pawn, WorkTypeDef w, ref bool __result)
__result = ___pawn.workSettings.GetPriority(w) == 0;
}
}
//
[HarmonyPatch(typeof(Alert_HunterLacksRangedWeapon))]
[HarmonyPatch(nameof(Alert_HunterLacksRangedWeapon.HuntersWithoutRangedWeapon), MethodType.Getter)]
static class Alert_HunterLacksRangedWeapon_HuntersWithoutRangedWeapon_Patch
{
static bool WorkIsActive(Pawn_WorkSettings instance, WorkTypeDef w)
{
return instance.GetPriority(w) > 0; // "unpatch" it
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var fromMethod = SymbolExtensions.GetMethodInfo((Pawn_WorkSettings workSettings) => workSettings.WorkIsActive(null));
var toMethod = SymbolExtensions.GetMethodInfo(() => WorkIsActive(null, null));
return instructions.MethodReplacer(fromMethod, toMethod);
}
}

// forced hauling outside of allowed area
//
Expand Down Expand Up @@ -404,6 +421,32 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
}
}

[HarmonyPatch(typeof(BeautyDrawer))]
[HarmonyPatch(nameof(BeautyDrawer.ShouldShow))]
static class BeautyDrawer_ShouldShow_Patch
{
public static void Postfix(ref bool __result)
{
if (__result == false)
return;
if (Find.Selector.SelectedPawns.Count(pawn => pawn.IsColonist && pawn.Drafted) > 1)
__result = false;
}
}
//
[HarmonyPatch(typeof(CellInspectorDrawer))]
[HarmonyPatch(nameof(CellInspectorDrawer.ShouldShow))]
static class CellInspectorDrawer_ShouldShow_Patch
{
public static void Postfix(ref bool __result)
{
if (__result == false)
return;
if (Find.Selector.SelectedPawns.Count(pawn => pawn.IsColonist && pawn.Drafted) > 1)
__result = false;
}
}

// allow multiple colonists by reserving the exit path from a build place
/*
* ### ENABLE AGAIN FOR SMART BUILDING
Expand Down
Binary file added Source/Originals/QuickTutorial.afphoto
Binary file not shown.
Binary file added Source/Originals/Screenshot.afphoto
Binary file not shown.
Binary file removed Source/Originals/Screenshot.psd
Binary file not shown.

0 comments on commit 2eb6a1c

Please sign in to comment.